publicclassMain{ publicstaticvoidmain(String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (in.ready()) { int res = 0; int count = Integer.parseInt(in.readLine()); if (count == 0) { System.out.println(res); break; } String[] strings1 = in.readLine().split(" "); int[] nums1 = newint[count * 2]; for (int i = 0; i < count; i++) { nums1[i] = Integer.parseInt(strings1[i]); } String[] strings2 = in.readLine().split(" "); for (int i = 0; i < count; i++) { nums1[i + count] = Integer.parseInt(strings2[i]); } res = merge(nums1, 0, count - 1, 2 * count - 1); System.out.println(res);
}
in.close(); }
privatestaticintmerge(int[] a, int start, int mid, int end){ int res = 0; int i = start, j = mid + 1; while (i <= mid && j <= end) { if (a[i] <= a[j]) i++; else { j++; res += mid - i + 1; } } return res; } }