malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   using namespace std;   const int N=3e5+10;   int n,m,mx;   int dif[N],b[N];    vector <int> a[N];   void end(){    puts( No ); exit(0);    }   int main(){    scanf( %d%d ,&n,&m);    for(int i=1;i<=n;i++){     a[i].push_back(0);     for(int j=1;j<=m;j++){ int x; scanf( %d ,&x); a[i].push_back(x); }     }    for(int i=2;i<=n;i++){     for(int j=1;j<=m;j++) if(a[1][j]!=a[i][j]) dif[i]++;       mx=max(mx,dif[i]);     }    if(mx>4) end();     if(mx<=2){     puts( Yes );     for(int i=1;i<=m;i++) printf( %d  ,a[1][i]); exit(0);     }    if(mx==4){     int ps=0,now=0,cur[4]={};      for(int i=2;i<=n;i++) if(dif[i]==4){ ps=i; break; }     for(int i=1;i<=m;i++) if(a[1][i]!=a[ps][i]) cur[now++]=i;           for(int i=0;i<4;i++)      for(int j=i+1;j<4;j++){        for(int k=1;k<=m;k++) b[k]=a[1][k];       for(int k=0;k<4;k++){        if(k!=i && k!=j) b[cur[k]]=a[ps][cur[k]];        }              int pd=0;       for(int k=1;k<=n;k++){        int sum=0; for(int p=1;p<=m;p++) if(a[k][p]!=b[p]) sum++;         if(sum>2){ pd=1; break; }       }       if(!pd){        puts( Yes );        for(int k=1;k<=m;k++) printf( %d  ,b[k]); exit(0);        }      }      end();     }    else if(mx==3){      int ps=0,now=0,cur[3]={};     for(int i=2;i<=n;i++) if(dif[i]==3){ ps=i; break; }     for(int i=1;i<=m;i++) if(a[1][i]!=a[ps][i]) cur[now++]=i;           for(int p=0;p<3;p++)      for(int q=p+1;q<3;q++){       for(int d=0;d<2;d++){        for(int i=1;i<=m;i++) b[i]=a[1][i];         if(d==0){         b[cur[q]]=a[ps][cur[q]];         }        else{         b[cur[p]]=a[ps][cur[p]];          }                int pd=0,vis=0,at=0;        for(int i=2;i<=n;i++){         int sum=0; for(int j=1;j<=m;j++) if(a[i][j]!=b[j]) sum++;         if(sum>=3){ vis=1; at=i; break; }        }        if(!vis){         puts( Yes );          for(int i=1;i<=m;i++) printf( %d  ,b[i]); exit(0);        }        else{         b[cur[3-p-q]]=a[at][cur[3-p-q]];          for(int i=2;i<=n;i++){          int sum=0; for(int j=1;j<=m;j++) if(a[i][j]!=b[j]) sum++;           if(sum==3){ pd=1; break; }         }         if(!pd){          puts( Yes );           for(int i=1;i<=m;i++) printf( %d  ,b[i]); exit(0);                }        }       }      }          end();     }        }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int uppery = y2 + 1;     int lowery = y2 - 1;     int upperx = x2 + 1;     int lowerx = x2 - 1;     int ans = 4;     ans +=         abs(x1 - upperx) + abs(y1 - lowery) + abs(x1 - lowerx) + abs(y1 - uppery);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a) {     long long int pdt = 1, i = 0, t = 19;     while (i++ < min(a, t)) pdt *= 2;     return pdt;   }   int main() {     long long int n, b, i, j, cnt = 0, k = 0;     cin >> n >> b;     long long int a[n], c[n];     b = power((b * 8) / n);     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) {       j = i + 1;       while (j < n && a[j] == a[i]) j++;       cnt++;       c[k++] = j - i;       i = j - 1;     }     if (cnt < b)       cout << 0;     else {       long long int maxi = 0;       for (i = 0; i < k; i++) {         if (i > 0) c[i] += c[i - 1];         if (i - b >= 0)           maxi = max(maxi, c[i] - c[i - b]);         else if (!(i - b + 1))           maxi = max(maxi, c[i]);       }       cout << n - maxi << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200005], s1[200005];   void sol() {     int i, l, xp;     l = strlen(s);     memset(s1, 0, sizeof(s1));     xp = -1;     for (i = 0; i < l; i++) {       if (xp == -1) {         xp++;         s1[xp] = s[i];         continue;       }       if (s1[xp] == s[i])         xp--;       else {         xp++;         s1[xp] = s[i];       }     }     xp++;     s1[xp] = 0;     printf( %s n , s1);   }   int main() {     while (gets(s)) sol();     return 0;   }
#include <bits/stdc++.h>    using namespace std;   typedef long long ll;   int main()    {    ll t;    cin>>t;    while(t--){     ll n,k;     cin>>n>>k;     ll ans;     if(n%2==0)     {      if(k%n==0)      ans=n;      else      ans=k%n;     }     else {      ll x1=k%n;      if(x1==0)      x1=n;      ll x2=(k/n);      if(k%n!=0)      x2++;      ll x3=x2%(n/2);      if(x3==0)      x3=n/2;      ll x4=(x3-1)*n+x1;      ll x5=x4/(n/2);      if(x4%(n/2)==0)      x5--;      ans=(x1+x5)%n;      if(ans==0)      ans=n;     }     cout<<ans<<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LLINF = 1e18;   const int MAXN = 1e5;   int v, q;   vector<int> G[MAXN];   int min_dist[MAXN];   bool is_centroid[MAXN];   int sz[MAXN];   int father[MAXN];   int dfs_sz(int x, int f = -1) {     sz[x] = 1;     for (auto y : G[x]) {       if (y == f || is_centroid[y]) continue;       sz[x] += dfs_sz(y, x);     }     return sz[x];   }   int dfs_cd(int x, int cent_sz, int f = -1) {     for (auto y : G[x]) {       if (y == f || is_centroid[y]) continue;       if (sz[y] > cent_sz / 2) return dfs_cd(y, cent_sz, x);     }     return x;   }   void cent_descomp(int x, int f = -1) {     int cent_sz = dfs_sz(x);     int centroid = dfs_cd(x, cent_sz);     is_centroid[centroid] = true;     father[centroid] = f;     for (auto y : G[centroid]) {       if (is_centroid[y]) continue;       cent_descomp(y, centroid);     }   }   int height[MAXN];   void dfs_h(int x, int f = -1) {     for (auto y : G[x]) {       if (f == y) continue;       height[y] = height[x] + 1;       dfs_h(y, x);     }   }   int l;   int timer;   int tin[MAXN], tout[MAXN];   int up[MAXN][25];   void dfs(int v, int p) {     tin[v] = ++timer;     up[v][0] = p;     for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];     for (int u : G[v]) {       if (u != p) dfs(u, v);     }     tout[v] = ++timer;   }   bool is_ancestor(int u, int v) {     return tin[u] <= tin[v] && tout[u] >= tout[v];   }   int lca(int u, int v) {     if (is_ancestor(u, v)) return u;     if (is_ancestor(v, u)) return v;     for (int i = l; i >= 0; --i) {       if (!is_ancestor(up[u][i], v)) u = up[u][i];     }     return up[u][0];   }   void preprocess(int root) {     timer = 0;     l = ceil(log2(v));     dfs(root, root);   }   int get_d(int x, int y) {     return abs(height[x] + height[y] - 2 * height[lca(x, y)]);   }   void upd(int x) {     int y = x;     while (true) {       min_dist[y] = min(min_dist[y], get_d(x, y));       if (-1 == father[y]) break;       y = father[y];     }   }   int query(int x) {     int y = x;     int ans = INF;     while (true) {       ans = min(ans, min_dist[y] + get_d(x, y));       if (-1 == father[y]) break;       y = father[y];     }     return ans;   }   int main() {     scanf( %d %d , &v, &q);     for (int i = 1; i < v; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--, y--;       G[x].push_back(y);       G[y].push_back(x);       min_dist[i - 1] = INF;     }     min_dist[v - 1] = INF;     cent_descomp(0);     for (int i = 0; i < v; i++) {       if (father[i] == -1) {         dfs_h(i);         preprocess(i);       }     }     upd(0);     for (int _ = 0; _ < q; _++) {       int t, x;       scanf( %d %d , &t, &x);       x--;       if (t == 1)         upd(x);       else         printf( %d n , query(x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int RLEN = 1 << 18 | 1;   inline char nc() {     static char ibuf[RLEN], *ib, *ob;     (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));     return (ib == ob) ? -1 : *ib++;   }   inline int rd() {     char ch = nc();     int i = 0, f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = nc();     }     while (isdigit(ch)) {       i = (i << 1) + (i << 3) + ch -  0 ;       ch = nc();     }     return i * f;   }   const int N = 1e5 + 50;   char ch[N];   int n, a[N], pre[N][26], suf[N][26];   int f[N][26], g[N], mem[27];   inline int mex(int sta) { return __builtin_ctz(~sta); }   inline int calc(int l, int r, int c, int flag) {     if (l > r) return 0;     if (~mem[c]) return mem[c];     int sta = 0;     for (int j = 0; j < 26; ++j) {       int _l = suf[l][j], _r = pre[r][j];       if (_r >= l)         sta |=             1 << (g[_r] ^ g[_l] ^ (!flag ? f[_l - 1][c] : calc(l, _l - 1, j, 1)) ^                   (flag ? f[r][j] : calc(_r + 1, r, j, 0)));     }     return mem[c] = mex(sta);   }   int main() {     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (int i = 1; i <= n; i++) a[i] = ch[i] -  a ;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; ++j) pre[i][j] = pre[i - 1][j];       pre[i][a[i]] = i;     }     for (int j = 0; j < 26; ++j) suf[n + 1][j] = n + 1;     for (int i = n; i >= 1; i--) {       for (int j = 0; j < 26; ++j) suf[i][j] = suf[i + 1][j];       suf[i][a[i]] = i;     }     for (int i = 1; i <= n; i++) {       g[i] = f[i - 1][a[i]] ^ g[pre[i - 1][a[i]]];       memset(mem, -1, sizeof(mem));       for (int j = 0; j < 26; ++j) f[i][j] = calc(pre[i][j] + 1, i, j, 0);     }     int q = rd();     for (int i = 1; i <= q; i++) {       int l = rd(), r = rd();       memset(mem, -1, sizeof(mem));       if (calc(l, r, 26, 1))         puts( Alice );       else         puts( Bob );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       string x;       cin >> x;       long long c = 0;       long long arr[n + 5];       memset(arr, 0, sizeof(arr));       for (long long i = 0; i < n; i++) {         if (x[i] ==  < ) {           if ((i - 1) < 0 || arr[i - 1] == 1) arr[i] = 1;         } else if (x[i] ==  > ) {           long long lft = i;           while (i < n && x[i] ==  > ) i++;           if (i >= n) {             long long rgt = i;             c += (rgt - lft);           } else             i--;         }       }       for (long long i = 0; i < n; i++)         if (arr[i] == 1) c++;       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sum;   vector<int> x;   int main() {     int n;     cin >> n;     x.push_back(-2099999999);     for (int i = 0; i < n; i++) {       int a;       cin >> a;       x.push_back(a);     }     sort(x.begin(), x.end());     for (int i = 1; i <= n; i++) sum += abs(i - x[i]);     cout << sum << endl;   }
#include <bits/stdc++.h>   int b;   struct Matrix {     long long int x[110][110];   } A, B, C;   Matrix operator*(Matrix A, Matrix B) {     Matrix C;     for (int i = 1; i <= b; i++) {       for (int j = 1; j <= b; j++) {         C.x[i][j] = 0;         for (int k = 1; k <= b; k++) {           C.x[i][j] += A.x[i][k] * B.x[k][j];           C.x[i][j] %= 1000000007;         }       }     }     return C;   }   void func(long long int k) {     for (int i = 1; i <= b; i++)       for (int j = 1; j <= b; j++) B.x[i][j] = C.x[i][j] = 0;     for (int i = 1; i <= b; i++) B.x[i][i] = C.x[i][i] = 1;     C = A;     while (k) {       if (k % 2 == 1) B = B * C;       k /= 2;       C = C * C;     }   }   int main() {     long long int a;     scanf( %lld%d , &a, &b);     for (int i = 1; i <= b; i++)       for (int j = 1; j <= b; j++) A.x[i][j] = 0;     A.x[1][1] = 1, A.x[1][b] = 1;     for (int i = 2; i <= b; i++) A.x[i][i - 1] = 1;     if (a < b) {       printf( 1 );       return 0;     }     func(a - b);     long long int s = 0;     for (int i = 1; i <= b; i++) s += B.x[1][i], s %= 1000000007;     s += B.x[1][1], s %= 1000000007;     printf( %lld , s);   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     return y == 0 ? x : gcd(y, x % y);   }   int main() {     long long int a;     cin >> a;     if (a > 2) {       if (a * a % 2)         cout << (a * a - 1) / 2 <<     << (a * a + 1) / 2;       else         cout << (a * a / 2 - 2) / 2 <<     << (a * a / 2 + 2) / 2;     } else {       cout << -1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long holes[14];   int main() {     long long zeroes = 0;     for (long long i = 0; i < 14; i++) {       cin >> holes[i];       if (holes[i] == 0) zeroes++;     }     zeroes++;     long long mx = 0;     for (long long i = 0; i < 14; i++) {       long long cnt = 0;       if (holes[i] != 0) {         long long a = holes[i] / 14;         long long b = holes[i] % 14;         if (a % 2 == 0) {           cnt = zeroes * a;           while (b) {             if (holes[(i + b) % 14] == 0)               cnt -= a;             else               cnt += (a + holes[(i + b) % 14] + 1);             b--;           }         } else {           cnt = a * (14 - zeroes);           for (long long j = 0; j < 14; j++)             if (i != j) cnt += holes[j];           while (b) {             if (holes[(i + b) % 14] == 0)               cnt += a + 1;             else               cnt -= (a + holes[(i + b) % 14]);             b--;           }         }       }       mx = max(cnt, mx);     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <class A>   void read(vector<A>& v);   template <class A, size_t S>   void read(array<A, S>& a);   template <class T>   void read(T& x) {     cin >> x;   }   void read(double& d) {     string t;     read(t);     d = stod(t);   }   void read(long double& d) {     string t;     read(t);     d = stold(t);   }   template <class H, class... T>   void read(H& h, T&... t) {     read(h);     read(t...);   }   template <class A>   void read(vector<A>& x) {     for (auto& a : x) read(a);   }   template <class A, size_t S>   void read(array<A, S>& x) {     for (auto& a : x) read(a);   }   const int MAXN = 2e5 + 5;   long long mod = 1e9 + 7;   vector<long long> gr[200005];   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long val = (b * b) - (4 * a * c);     cout << setprecision(8);     if (a == 0) {       if ((b == 0)) {         if (c == 0) {           cout << -1 <<   n ;           return;         }         cout << 0 <<   n ;       } else {         cout << 1 <<   n ;         long double ans = -(c * 1.0) / (b * 1.0);         cout << ans <<   n ;       }       return;     }     if (val < 0) {       cout << 0 <<   n ;       return;     } else {       long double root1 = -b + sqrt(val);       root1 /= 2.0 * a;       long double root2 = -b - sqrt(val);       root2 /= 2.0 * a;       if (root1 == root2) {         cout << 1 <<   n ;         cout << root1 <<   n ;       } else {         cout << 2 <<   n ;         if (root1 < root2) {           cout << root1 <<   n  << root2 <<   n ;         } else {           cout << root2 <<   n  << root1 <<   n ;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     test = 1;     while (test--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e13;   const int MAGIC = 3500000;   long long add(long long x, long long y) { return (x + y) % MOD; }   long long mul(long long x, long long y) {     long long coef = (long double)(x)*y / MOD + 0.5;     long long ret = x * y - coef * MOD;     ret += ret < 0 ? MOD : 0;     return ret;   }   struct mat {     long long dat[2][2];     mat() { memset(dat, 0, sizeof(dat)); }   } I, J;   mat operator*(const mat& A, const mat& B) {     mat ret;     for (int i = 0; i < (int)(2); i++)       for (int j = 0; j < (int)(2); j++)         ret.dat[i][j] =             add(mul(A.dat[i][0], B.dat[0][j]), mul(A.dat[i][1], B.dat[1][j]));     return ret;   }   void init() {     I.dat[0][0] = I.dat[1][1] = 1;     J.dat[1][0] = J.dat[0][1] = J.dat[1][1] = 1;   }   long long calc(long long pos) {     mat ans = I, cur = J;     while (pos > 0) {       if (pos & 1) ans = ans * cur;       cur = cur * cur;       pos >>= 1;     }     return ans.dat[1][0];   }   long long pw[14], cyc[14];   long long X;   int main() {     init();     scanf( %lld , &X);     pw[0] = 1;     for (int i = 1; i <= (int)(13); i++) pw[i] = 10 * pw[i - 1];     cyc[0] = 1;     cyc[1] = 60;     cyc[2] = 300;     cyc[3] = 1500;     for (int i = 4; i <= 13; i++) cyc[i] = 10 * cyc[i - 1];     vector<long long> occ, nocc;     occ.push_back(0);     for (int i = 1; i <= (int)(13); i++) {       int wt = cyc[i] / cyc[i - 1];       nocc.clear();       for (int j = 0; j < (int)(occ.size()); j++)         for (int k = 0; k < (int)(wt); k++)           if (calc(occ[j] + k * cyc[i - 1]) % pw[i] == X % pw[i])             nocc.push_back(occ[j] + k * cyc[i - 1]);       occ = nocc;     }     sort(occ.begin(), occ.end());     printf( %lld n , occ.empty() ? -1 : occ[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, mod = 1e9 + 7;   const long long inf = 1e18;   int x[maxn], frs[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, z;     cin >> n >> z;     for (int i = 0; i < n; i++) {       cin >> x[i];     }     sort(x, x + n);     int pt = 0;     for (int i = 0; i < n; i++) {       pt = max(pt, i + 1);       while (pt < n && x[pt] - x[i] < z) pt++;       frs[i] = pt;     }     int l = 0, r = (n / 2) + 1;     while (r - l > 1) {       int mid = (l + r) >> 1;       int pt = mid - 1;       for (int i = 0; i < mid; i++) {         pt = max(pt + 1, frs[i]);       }       if (pt >= n)         r = mid;       else         l = mid;     }     return cout << l << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   vector<vector<int> > dp;   vector<int> res;   void recalc(char col) {     dp = vector<vector<int> >(n + 1, vector<int>(n + 1, 0));     res = vector<int>(n, 0);     for (int(i) = 0; (i) < (n + 1); ++(i)) dp[i][0] = 0;     for (int(ncur) = (1); (ncur) < (n + 1); ++(ncur)) {       for (int(mcur) = (0); (mcur) < (n + 1); ++(mcur)) {         if (s[ncur - 1] == col) {           dp[mcur][ncur] = dp[mcur][ncur - 1] + 1;           continue;         }         if (mcur == 0) {           dp[mcur][ncur] = 0;         } else {           dp[mcur][ncur] = dp[mcur - 1][ncur - 1] + 1;         }       }     }     for (int(i) = 0; (i) < (n); ++(i)) {       for (int(j) = (1); (j) < (n + 1); ++(j)) {         res[i] = max(res[i], dp[i + 1][j]);       }     }   }   void solve() {     cin >> n;     cin >> s;     int q;     cin >> q;     vector<pair<pair<char, int>, int> > qrs(q);     for (int(i) = 0; (i) < (q); ++(i)) {       cin >> qrs[i].first.second >> qrs[i].first.first;       qrs[i].second = i;     }     sort(qrs.begin(), qrs.end());     vector<pair<int, int> > ans(q);     char lastcol = -1;     for (int(i) = 0; (i) < (q); ++(i)) {       char col = qrs[i].first.first;       int m = qrs[i].first.second;       if (col != lastcol) {         lastcol = col;         recalc(col);       }       ans[i].first = qrs[i].second;       ans[i].second = res[m - 1];     }     sort(ans.begin(), ans.end());     for (int(i) = 0; (i) < (q); ++(i)) cout << ans[i].second << endl;   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1000010;   long long fact[N];   int main(int argc, char const *argv[]) {     long long n, m;     cin >> n >> m;     if (n == 1 && m == 1) {       cout <<  1 n ;       return 0;     }     double ans = 1.0 / (double)n +                  (((n - 1.0) / (double)n) * (m - 1.0) / (n * 1.0 * m - 1.0));     printf( %.9lf n , ans);     return 0;   }
#include <bits/stdc++.h>    using namespace std;      using ll = long long;   using ld = long double;   #define fi first   #define se second      void solve(){    ll n;    cin>>n;    vector<ll>d(n);    for(int i=0;i<n;i++)     cin>>d[i];    ll ans=0,curr=0;    sort(d.begin(),d.end());    for(int i=1;i<d.size()-1;i++){     ans+=(i*d[i])-curr;     curr+=d[i];    }    ll l = d.size();    if(l>=3)     ans+=((l-2)*d[l-1])-curr;    cout<<-1*ans<<  n ;   }      int main()    {     ios::sync_with_stdio(false);    cin.tie(0);       int t;    cin>>t;    while(t--){     solve();    }        return 0;    }
#include <bits/stdc++.h>   using namespace std;   bool check(vector<long long> a, long long m, long long n) {     vector<long long> v(n + 1, 0);     for (long long i = 0; i < n; i++) {       v[a[i]] += 1;     }     set<pair<long long, long long>, greater<pair<long long, long long>>> s;     for (long long i = 1; i < n + 1; i++) {       if (v[i]) {         s.insert({v[i], i});       }     }     vector<long long> b;     for (long long i = 0; i < n; i++) {       if (i >= m and v[b[i - m]]) {         s.insert({v[b[i - m]], b[i - m]});       }       if (s.empty()) return false;       pair<long long, long long> p = *(s.begin());       b.push_back(p.second);       s.erase(p);       v[p.second] -= 1;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < m; i++) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (a[n - 1] > b[0]) {       cout <<  -1 n ;       return 0;     }     long long ans = 0;     for (long long i = 0; i < n; i++) ans += a[i] * m;     long long g = n - 1, h = m - 1;     bool is = false;     for (long long i = m - 1; i >= 0; i--) {       while (g >= 0 && h == 0) {         g--;         h = m - 1;       }       if (b[i] == a[n - 1]) {         break;       }       if (g < 0) {         cout <<  -1 n ;         return 0;       }       ans += b[i] - a[g];       h--;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     int a[100000];     int l0, l1;     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     l0 = 0;     l1 = 0;     for (i = 1; i < n; i++) {       if (a[i] >= a[i - 1]) {         l1++;       }       if (a[i] < a[i - 1]) {         if (l0 < l1) {           l0 = l1;         }         l1 = 0;       }     }     if (l0 < l1) {       l0 = l1;     }     printf( %d , l0 + 1);     return 0;   }
#include <bits/stdc++.h>   int t, n, a[200010], tot, cnt[200010];   int f[200010];   int find_f(int x) { return f[x] ^ x ? f[x] = find_f(f[x]) : x; }   int main() {     scanf( %d , &t);     for (int _ = 0; _ < t; ++_) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , a + i);       for (int i = 1; i <= n; ++i) f[i] = i, cnt[i] = 0;       for (int i = 1; i <= n; ++i)         if (find_f(i) != find_f(a[i])) f[find_f(i)] = find_f(a[i]);       for (int i = 1; i <= n; ++i) ++cnt[find_f(i)];       for (int i = 1; i <= n; ++i) printf( %d  , cnt[find_f(i)]);       puts(  );     }     return 0;   }