#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>N>>K; if(K==0) return _P("0\n"); FOR(i,N) cin>>P[i], pre[P[i]]=i; FOR(i,N) cin>>B[i], ct+=abs(P[i]-B[i]); tot=ct; FOR(i,K-1) { next_permutation(P,P+N); int mi=N-1; for(j=mi;j>=mi;j--) { mi=min(mi,pre[P[j]]); ct += abs(P[j]-B[j])-abs(P[j]-B[pre[P[j]]]); pre[P[j]]=j; } tot += ct; } cout<