text: = 0) { if (p % 2 == 1) result *= n; p >>= 1; n *= n; } return result; } static class Pair implements Comparable<Pair> { int a, b; Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair o) { // TODO Auto-generated method stub if (this.a != o.a) return Integer.compare(this.a, o.a); else return Integer.compare(this.b, o.b); //return 0; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair) o; return p.a == a && p.b == b; } return false; } public int hashCode() { return new Integer(a).hashCode() * 31 + new Integer(b).hashCode(); } public String toString() { return a + " " + b; } } static long sort(int a[]) { int n = a.length; int b[] = new int[n]; return mergeSort(a, b, 0, n - 1); } static long mergeSort(int a[], int b[], long left, long right) { long c = 0; if (left < right) { long mid = left + (right - left) / 2; c = mergeSort(a, b, left, mid); c += mergeSort(a, b, mid + 1, right); c += merge(a, b, left, mid + 1, right); } return c; } static long merge(int a[], int b[], long left, long mid, long right) { long c = 0; int i = (int) left; int j = (int) mid; int k = (int) left; while (i <= (int) mid - 1 && j <= (int) right) { if (a[i] <= a[j]) { b[k++] = a[i++]; } else { b[k++] = a[j++]; c += mid - i; } } while (i <= (int) mid - 1) b[k++] = a[i++]; while (j <= (int) right) b[k++] = a[j++]; for (i = (int) left; i <= (int) right; i++) a[i] = b[i]; return c; } public static int[] radixSort(int[] f) { int[] to = new int[f.length]; { int[] b = new int[65537]; for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++; for (int i = 1; i <= 65536; i++) b[i] += b[i - 1]; for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i]; int[] d = f; f = to; to = d; } { int[] b = new int[65537]; for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++; for (int i = 1; i <= 65536; i++) b[i] += b[i - 1]; for (int i = 0; i < f.