#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template V compress(V vs){ sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); return vs; } template map dict(const vector &vs){ map res; for(int i=0;i<(int)vs.size();i++) res[vs[i]]=i; return res; } map dict(const string &s){ return dict(vector(s.begin(),s.end())); } template vector fusion(vector bs,Ts... ts){ auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);}; initializer_list{(void(append(ts)),0)...}; return bs; } //INSERT ABOVE HERE template struct Slope{ using P = pair; priority_queue, less

> L; priority_queue, greater

> R; T offL,offR,entire; Slope():offL(0),offR(0),entire(0){} inline T relu(T x){return max(0,x);} void pushL(T pos,T num){if(num>T(0)) L.emplace(pos-offL,num);} void pushR(T pos,T num){if(num>T(0)) R.emplace(pos-offR,num);} T posL(){return L.top().first+offL;} T posR(){return R.top().first+offR;} void add_x_minus_a(T a,T cnt=T(1)){ T use(0); while(use vp; while(!pq.empty()) vp.emplace_back(pq.top()),pq.pop(); return vp; }; for(auto[pos,num]:vectorize(L)) res+=relu((pos+offL)-x)*num; for(auto[pos,num]:vectorize(R)) res+=relu(x-(pos+offR))*num; return res; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int m,n; cin>>m>>n; auto as=read(m); auto bs=read(n); auto cs=compress(fusion(as,bs)); auto dc=dict(cs); for(int &a:as) a=dc[a]; for(int &b:bs) b=dc[b]; const int sz = cs.size(); vector num(sz,0); for(int a:as) num[a]--; for(int k=1;k<=m;k++){ for(int b:bs) num[b]++; int pos=0; Slope S; S.add_a_minus_x(pos,1e9); for(int i=0;i