package no270; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { IO io = new IO(); int n = io.nextInt(); int k = io.nextInt(); int[] p = io.nextIntArray(n); int[] b = io.nextIntArray(n); if (k == 0) { System.out.println(0); return; } long ans = 0; BIT bit = new BIT(n); for(int i=0;i=0;--a) { if(p[a]p[a]) { int l = a; int t = p[a]; p[a] = p[b]; p[b] = t; for(++a, b=p.length-1;a0) { s+=bit[i]; i-=i&-i; } return s; } public long get(int index) { return sum(index,index+1); } public void set(int index,long num) { accumulate(index,num-get(index)); } public String toString() { long[] value = new long[n]; for(int i=0;i Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public char nextChar() { if (!hasNext()) { throw new NoSuchElementException(); } return (char) readByte(); } public double nextDouble() { return Double.parseDouble(next());} public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i