malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k;     cin >> n >> k;     string a;     cin >> a;     bool no = false;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  N  && (i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) {         int count = 0;         int j;         for (j = i; j < i + k; j++) {           if (a[j] ==  N )             count++;           else             break;         }         if (count == k && j < a.size() && a[j] ==  N ) {           cout <<  NO ;           return 0;         }       }     }     for (int i = 0; i < a.size(); i++) {       if ((i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) {         int count = 0;         int j;         for (j = i; j < i + k; j++) {           if (a[j] ==  ?  || a[j] ==  N )             count++;           else             break;         }         if (count == k && (i + k == a.size() || a[j] !=  N )) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   int a, n, m, k, p;   int main() {     std::cin >> n >> m, a = 0, p = 1;     for (int i = 1; i <= n; ++i) {       std::cin >> k;       if (a + k <= m)         a += k;       else         a = k, ++p;     }     std::cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long a[(long long)1e5 + 10];   long long b[(long long)1e5 + 10];   long long c[(long long)1e5 + 10];   long long d[(long long)1e5 + 10];   int main() {     cin >> n >> m >> k;     for (long long i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> c[i];     }     for (long long i = 0; i < k; i++) {       cin >> d[i];     }     long long sum = 0;     for (long long i = 0; i < k; i++) {       for (long long j = 0; j < m; j++) {         if (a[j] <= d[i] && d[i] <= b[j]) {           sum += c[j] + d[i] - a[j];         }       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char s[711];   const int mod = 1e9 + 7;   int kk[711][12], f[711][711][2];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int j = 0; j <= 9; j++) {       int num = s[n] -  0 ;       if (j > num) {         f[n][0][0] = num + 1;         f[n][1][0] = 0;         f[n][0][1] = j - num - 1;         f[n][1][1] = 10 - j;       } else {         f[n][0][0] = j;         f[n][1][0] = num - j + 1;         f[n][0][1] = 0;         f[n][1][1] = 10 - num - 1;       }       for (int a = n - 1; a; a--) {         int num = s[a] -  0 ;         if (j > num) {           f[a][0][0] =               (1ll * (f[a + 1][0][0] + f[a + 1][0][1]) * num + f[a + 1][0][0]) %               mod;           f[a][0][1] = (1ll * (f[a + 1][0][0] + f[a + 1][0][1]) * (j - num - 1) +                         f[a + 1][0][1]) %                        mod;           for (int b = 1, to = n - a + 1; b <= to; b++) {             f[a][b][0] =                 (1ll * (f[a + 1][b][0] + f[a + 1][b][1]) * num + f[a + 1][b][0]) %                 mod;             f[a][b][1] =                 (1ll * (f[a + 1][b - 1][0] + f[a + 1][b - 1][1]) * (10 - j) +                  1ll * (f[a + 1][b][0] + f[a + 1][b][1]) * (j - num - 1) +                  f[a + 1][b][1]) %                 mod;           }         } else {           f[a][0][0] = (1ll * (f[a + 1][0][0] + f[a + 1][0][1]) * j) % mod;           f[a][0][1] = 0;           for (int b = 1, to = n - a + 1; b <= to; b++) {             f[a][b][0] =                 (1ll * (f[a + 1][b][0] + f[a + 1][b][1]) * j +                  1ll * (f[a + 1][b - 1][0] + f[a + 1][b - 1][1]) * (num - j) +                  f[a + 1][b - 1][0]) %                 mod;             f[a][b][1] = (1ll * (f[a + 1][b - 1][0] + f[a + 1][b - 1][1]) *                               (10 - num - 1) +                           f[a + 1][b - 1][1]) %                          mod;           }         }       }       for (int i = n; i; i--)         f[1][i][0] += f[1][i + 1][0], f[1][i][0] -= f[1][i][0] >= mod ? mod : 0,             kk[i][j] = f[1][i][0];     }     int ans = 0;     for (int i = 1, ten = 1; i <= n; i++) {       for (int j = 0; j <= 9; j++)         ans += 1ll * (kk[i][j] - kk[i][j + 1] + mod) * ten % mod * j % mod,             ans -= ans >= mod ? mod : 0, ans += ans < 0 ? mod : 0;       ten = 1ll * ten * 10 % mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXK = 1 << 12;   const int P = 7340033;   const int G = 3;   const int MAXH = 30;   int dp[MAXH + 7][MAXK + 7], buff[MAXK + 7];   int qpow(int a, int b) {     if (b == 0) return 1;     if (a == 0) return 0;     int aux = qpow(1LL * a * a % P, b >> 1);     if (b & 1) aux = 1LL * aux * a % P;     return aux;   }   inline int inv(int x) { return qpow(x, P - 2); }   void NTT(int *a, int N, int dir) {     int t = 0;     for (int i = (0); i <= (N - 1); ++i) {       if (t < i) swap(a[t], a[i]);       for (int j = (N >> 1); (t ^= j) < j; j >>= 1)         ;     }     for (int i = 2; i <= N; i <<= 1) {       int wn = qpow(G, (P - 1) / i);       for (int j = 0; j < N; j += i) {         int w = 1, t;         for (int k = 0; k < (i >> 1); k++, w = 1LL * w * wn % P) {           t = 1LL * w * a[j + k + (i >> 1)] % P;           a[j + k + (i >> 1)] = a[j + k] - t;           a[j + k] = a[j + k] + t;           if (a[j + k + (i >> 1)] < 0) a[j + k + (i >> 1)] += P;           if (a[j + k] >= P) a[j + k] -= P;         }       }     }     if (dir == -1) {       for (int i = 1; i < (N >> 1); i++) swap(a[i], a[N - i]);       int INV_N = inv(N);       for (int i = (0); i <= (N - 1); ++i) a[i] = 1LL * a[i] * INV_N % P;     }   }   void pre() {     dp[0][0] = 1;     for (int i = (1); i <= (MAXH); ++i) {       memset(buff, 0, sizeof(buff));       for (int j = (0); j <= (1000); ++j) buff[j] = dp[i - 1][j];       NTT(buff, MAXK, 1);       for (int j = (0); j <= (MAXK); ++j) buff[j] = qpow(buff[j], 4);       NTT(buff, MAXK, -1);       for (int j = (1); j <= (1000); ++j) dp[i][j] = buff[j - 1];       dp[i][0] = 1;     }   }   inline int height(int N) {     int h = 0;     while (N > 1 && N & 1) {       ++h;       N = (N - 1) >> 1;     }     return h;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     int Q;     cin >> Q;     while (Q--) {       int n, k;       cin >> n >> k;       cout << dp[height(n)][k] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int inf = 1e5 + 10;   using namespace std;   int main() {     int to[5][5];     int a[5];     memset(a, 0, sizeof(a));     memset(to, 0, sizeof(to));     ios::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 )         a[0]++;       else if (s[i] ==  1 )         a[1]++;       else if (s[i] ==  2 )         a[2]++;     }     n /= 3;     for (int i = 1; i <= 2; i++) {       for (int j = 0; j < i; j++) {         if (a[j] < a[i] && a[i] > n && a[j] < n) {           to[i][j] = min(n - a[j], a[i] - n);           int p = a[i];           int q = a[j];           a[i] -= min(n - q, p - n);           a[j] += min(n - q, p - n);         } else if (a[j] > a[i] && a[i] < n && a[j] > n) {           int p = a[i];           int q = a[j];           to[j][i] = min(n - p, q - n);           a[j] -= min(n - p, q - n);           a[i] += min(n - p, q - n);         }       }     }     for (int i = 0; i < 2; i++) {       for (int j = 2; j > i; j--) {         int v = 3 * n - 1;         while (to[i][j] && v >= 0) {           if (s[v] -  0  == i) {             s[v] =  0  + j;             to[i][j]--;           }           v--;         }       }     }     for (int i = 1; i <= 2; i++) {       for (int j = 0; j < i; j++) {         int v = 0;         while (to[i][j] && v < 3 * n) {           if (s[v] -  0  == i) {             s[v] =  0  + j;             to[i][j]--;           }           v++;         }       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0;     string s;     cin >> n;     cin.ignore();     for (int i = 1; i <= n; i++) {       getline(cin, s);       if (s[1] ==  + ) {         x++;         continue;       }       if (s[1] ==  - ) {         x--;         continue;       }     }     cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long POW(long long a, long long b, long long MMM = MOD) {     long long ret = 1;     for (; b; b >>= 1, a = (a * a) % MMM)       if (b & 1) ret = (ret * a) % MMM;     return ret;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) {     if (a == 0 || b == 0) return a + b;     return a * (b / gcd(a, b));   }   int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1};   int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};   int main() {     int n;     scanf( %d , &n);     puts( YES );     while (n--) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       printf( %d n , (x1 & 1) % 2 + ((y1 & 1) % 2) * 2 + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, n, day, ans, flag;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     day = 1;     ans = 0;     j = 0;     while (1) {       flag = 0;       for (i = j; i < n; i++) {         if (a[i] >= day) {           j = i + 1;           flag = 1;           ans++;           break;         }       }       if (flag == 0) break;       day++;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long t = bin_pow(a, b / 2);       return t * t % 1000000007;     } else       return a * bin_pow(a, b - 1) % 1000000007;   }   vector<long long> graph[500000];   bool used[500000];   long long w[500000], comp;   map<pair<long long, long long>, long long> mp1;   void dfs(long long v) {     used[v] = 1;     comp++;     for (auto u : graph[v]) {       if (w[u] == 0 || used[u] || mp1[{u, v}] == 0) continue;       dfs(u);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0,               ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;     cin >> n >> m >> k;     vector<long long> a(n), b;     map<long long, vector<pair<long long, long long>>> mp;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       z = a[x] ^ a[y];       b.push_back(z);       mp[z].push_back({x, y});       graph[x].push_back(y);       graph[y].push_back(x);     }     sort(b.begin(), b.end());     b.erase(unique(b.begin(), b.end()), b.end());     for (int i = 0; i < b.size(); i++) {       z = b[i];       long long k1 = 0;       l = 0;       for (auto u : mp[z]) {         x = u.first, y = u.second;         w[x] = w[y] = 1;         mp1[{x, y}] = mp1[{y, x}] = 1;       }       for (auto u : mp[z]) {         x = u.first, y = u.second;         if (used[x]) continue;         comp = 0;         dfs(x);         l += comp;         k1++;       }       x = bin_pow(2, n - l) * bin_pow(2, k1) % 1000000007;       ans += x;       ans %= 1000000007;       for (auto u : mp[z]) {         x = u.first, y = u.second;         w[x] = w[y] = used[x] = used[y] = 0;         mp1[{x, y}] = mp1[{y, x}] = 0;       }     }     t = ((bin_pow(2, k) - (long long)b.size()) % 1000000007 + 1000000007) %         1000000007;     t *= bin_pow(2, n);     t %= 1000000007;     ans += t;     ans %= 1000000007;     cout << ans;     return 0;   }
#include <iostream>      using namespace std;      long long n,mod;   long long cnt[55][2505];   long long cntS[55][2505];   long long per[55];   long long ans[55];      void calcCnt()   {       cnt[0][0]=1;          for(int i=1;i<=n;i++)       {           for(int inv=0;inv<=i*i;inv++)               for(int nval=1;nval<=i;nval++)               {                   if(inv>=i-nval)                   {                       cnt[i][inv]+=cnt[i-1][inv-(i-nval)];                       cnt[i][inv]%=mod;                   }               }              cntS[i][0]=cnt[i][0];           for(int inv=1;inv<=i*i;inv++)               cntS[i][inv]=(cntS[i][inv-1]+cnt[i][inv])%mod;       }   }      void calcPer()   {       for(int i=1;i<=n;i++)           for(int dif=1;dif<i;dif++)           {               long long nr=i-dif;               for(int invP=dif+1;invP<=i*i;invP++)               {                   long long nans=cnt[i-1][invP]*cntS[i-1][invP-dif-1];                   nans%=mod;                   nans*=nr;                   nans%=mod;                      per[i]+=nans;                   per[i]%=mod;               }           }   }   void calcAns()   {       for(int i=1;i<=n;i++)       {           ans[i]=i*ans[i-1]+per[i];           ans[i]%=mod;       }   }   int main()   {       cin>>n>>mod;          calcCnt();       calcPer();       calcAns();          cout<<ans[n];       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, k, p, len, n;     cin >> n >> k >> s;     int arr[30] = {0};     char x =  a ;     for (i = 0; i < 26; i++) {       x =  a  + i;       p = 0;       for (j = 0; j < n; j++) {         if (s[j] == x)           p++;         else           p = 0;         if (p == k) {           arr[i]++;           p = 0;         }       }     }     p = 0;     for (i = 0; i < 26; i++) {       p = max(p, arr[i]);     }     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n;   int f[MAXN];   bool read() {     if (scanf( %d , &n) < 1) {       return 0;     }     for (int i = 0; i < int(n); ++i) {       scanf( %d , &f[i]);       --f[i];     }     return 1;   }   vector<int> inv_f[MAXN];   int g[MAXN];   int h[MAXN];   bool solve() {     for (int i = 0; i < int(n); ++i) {       inv_f[i].clear();     }     for (int i = 0; i < int(n); ++i) {       inv_f[f[i]].push_back(i);     }     memset(g, -1, sizeof g);     int m = 0;     for (int i = 0; i < int(n); ++i) {       if (inv_f[i].empty()) {         continue;       }       if (f[i] != i) {         return 0;       }       for (int j : inv_f[i]) {         g[j] = m;       }       h[m] = i;       ++m;     }     for (int x = 0; x < int(m); ++x) {       assert(g[h[x]] == x);     }     for (int x = 0; x < int(n); ++x) {       assert(h[g[x]] == f[x]);     }     printf( %d n , m);     for (int i = 0; i < int(n); ++i) {       printf( %d  , g[i] + 1);     }     puts(  );     for (int i = 0; i < int(m); ++i) {       printf( %d  , h[i] + 1);     }     puts(  );     return 1;   }   int main() {     while (read()) {       if (!solve()) {         puts( -1 );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = (1 << 22) + 5;   int full, n, m;   bool v[MAX], b[MAX], h[MAX];   void dfsans(int now);   void dfs(int now) {     if (v[now]) return;     v[now] = true;     if (h[now]) dfsans(now);     for (int i = 0; i < n; i++) {       if (!(now & (1 << i))) continue;       dfs(now ^ (1 << i));     }   }   void dfsans(int now) {     if (b[now]) return;     b[now] = true;     dfs(now ^ full);   }   int main() {     scanf( %d%d , &n, &m);     full = (1 << n) - 1;     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       h[x] = true;     }     int ans = 0;     for (int i = 0; i < (full + 1); i++) {       if (!h[i] || b[i]) continue;       ans++;       dfsans(i);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];         a[i]--;       }       vector<long long int> pos(n);       for (long long int i = 0; i < n; i++) {         pos[a[i]] = i;       }       long long int mnpos = pos[0];       long long int mx = pos[0];       vector<long long int> ans(n);       for (long long int i = 0; i < n; i++) {         mnpos = min(mnpos, pos[i]);         mx = max(mx, pos[i]);         if (mx - mnpos == i) {           ans[i] = 1;         } else {           ans[i] = 0;         }       }       for (long long int x : ans) cout << x;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (1) {       if (a == b) {         cout <<  YES n ;         return 0;       }       if (a == x || b == y) {         break;       }       if (++a > n) {         a = 1;       }       if (--b < 1) {         b = n;       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tmp1 = 0, tmp2 = 0, i, j, n, t, p[2 * 1000001] = {};     cin >> n;     set<int> a;     for (i = 0; i < n; i++) {       cin >> t;       a.insert(t);     }     for (i = 0; i < 2 * 1000001; i++) p[i] = 1000001;     for (int v : a) p[v] = 0;     for (i = 1; i < 2 * 1000001; i++)       if (p[i]) p[i] = p[i - 1] + 1;     for (int v : a)       for (j = 2 * v; j < 2 * 1000001; j += v)         tmp1 = max(tmp1,                    (j - 1 - p[j - 1] < v) ? 0 : (v - ((p[j - 1] + 1) % v)) % v);     cout << tmp1;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000;   int c[MAXN + 10], d[MAXN + 10], l[MAXN + 10], r[MAXN + 10];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; ++i) {       cin >> x[i];       ++c[x[i]];     }     for (int i = 1; i <= MAXN; ++i) {       if (c[i] == 0) continue;       if (c[i] == 1) {         d[i] = 0;         l[i] = 1;       } else {         d[i] = c[i];         l[i] = d[i] + l[i - 1];       }     }     memset(d, 0, sizeof(d));     for (int i = MAXN; i >= 1; --i) {       if (c[i] == 0) continue;       if (c[i] == 1) {         d[i] = 0;         r[i] = 1;       } else {         d[i] = c[i];         r[i] = d[i] + r[i + 1];       }     }     int ans = 0, p = -1;     for (int i = 1; i <= MAXN; ++i) {       if (l[i] + r[i] - c[i] > ans) {         ans = l[i] + r[i] - c[i];         p = i;       }     }     if (ans == 1) {       for (int i = 1; i + 1 <= MAXN; ++i) {         if (c[i] > 0 && c[i + 1] > 0) {           cout << 2 << endl;           cout << i <<     << i + 1 << endl;           return 0;         }       }       cout << ans << endl;       cout << p << endl;       return 0;     }     vector<int> cir;     int q = p;     while (c[p] > 1) {       cir.push_back(p);       --c[p];       ++p;     }     while (p > q) {       while (c[p] > 0) {         cir.push_back(p);         --c[p];       }       --p;     }     cir.push_back(p);     --c[p];     --p;     while (c[p] > 1) {       cir.push_back(p);       --c[p];       --p;     }     while (p <= q) {       while (c[p] > 0) {         cir.push_back(p);         --c[p];       }       ++p;     }     cout << ans << endl;     for (int i : cir) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p, q;   pair<int, int> pro[100010];   long long cross(int x1, int y1, int x2, int y2) {     return x1 * (long long)y2 - x2 * (long long)y1;   }   double cross2(double x1, double y1, double x2, double y2) {     return x1 * y2 - x2 * y1;   }   bool check(pair<int, int> c, pair<int, int> b, pair<int, int> a) {     return cross(b.first - a.first, b.second - a.second, c.first - b.first,                  c.second - b.second) >= 0;   }   pair<int, int> st[100010];   int tp = -1;   int main() {     scanf( %d%d%d , &n, &p, &q);     int maxa = 0, maxb = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &pro[i].first, &pro[i].second);       maxa = max(maxa, pro[i].first);       maxb = max(maxb, pro[i].second);     }     sort(pro + 1, pro + n + 1);     st[++tp] = make_pair(0, maxb);     for (int i = 1; i <= n; i++) {       while (tp > 0 && check(pro[i], st[tp], st[tp - 1])) tp--;       st[++tp] = pro[i];     }     st[++tp] = make_pair(maxa, 0);     int line;     for (int i = 0; i < tp; i++) {       if ((atan2(q, p) - atan2(st[i + 1].second, st[i + 1].first) >= -1e-9) &&           (atan2(st[i].second, st[i].first) - atan2(q, p) >= -1e-9))         line = i;     }     double lo = 0, hi = 1e6;     while (lo < hi - 1e-9) {       double mi = (lo + hi) / 2;       if ((0 - cross2(p / mi - st[line].first, q / mi - st[line].second,                       p / mi - st[line + 1].first,                       q / mi - st[line + 1].second) >=            -1e-9))         hi = mi;       else         lo = mi;     }     printf( %.10f n , lo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, x, c = 0, value[1000001], sign[1000001];   stack<int> s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &value[i]);       sign[i] = 1;     }     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       scanf( %d , &x);       sign[x] = -1;     }     for (int i = n; i >= 1; i--) {       if (sign[i] == -1) {         s.push(i);       } else {         if (!s.empty() && value[i] == value[s.top()]) {           s.pop();         } else {           s.push(i);           sign[i] = -1;         }       }     }     if (!s.empty()) {       printf( NO );     } else {       printf( YES n );       for (int i = 1; i <= n; i++) {         printf( %d  , value[i] * sign[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   long double PI = 3.141592653589793238462643383279502884197;   using namespace std;   int b[1001][1001];   int r[1001][1001], rn[1001][1001];   int c[1001][1001], cn[1001][1001];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &b[i][j]);         r[i][j] = c[j][i] = b[i][j];       }     }     for (int i = 0; i < n; i++) {       sort(r[i], r[i] + m);       rn[i][0] = 1;       for (int j = 1; j < m; j++)         rn[i][j] = rn[i][j - 1] + (r[i][j] == r[i][j - 1] ? 0 : 1);     }     for (int i = 0; i < m; i++) {       sort(c[i], c[i] + n);       cn[i][0] = 1;       for (int j = 1; j < n; j++)         cn[i][j] = cn[i][j - 1] + (c[i][j] == c[i][j - 1] ? 0 : 1);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int ii = lower_bound(r[i], r[i] + m, b[i][j]) - r[i];         int jj = lower_bound(c[j], c[j] + n, b[i][j]) - c[j];         if (rn[i][ii] > cn[j][jj])           printf( %d  , max(rn[i][m - 1], cn[j][n - 1] + rn[i][ii] - cn[j][jj]));         else           printf( %d  , max(cn[j][n - 1], rn[i][m - 1] + cn[j][jj] - rn[i][ii]));       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, j, a = 0, b = 0, c, k, n;     std::vector<int> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> k;       for (j = 0; j < k / 2; j++) cin >> c, a += c;       if (k & 1) cin >> c, v.push_back(c);       for (j = 0; j < k / 2; j++) cin >> c, b += c;     }     sort(v.begin(), v.end(), greater<int>());     for (i = 0; i < v.size(); i++)       if (i & 1)         b += v[i];       else         a += v[i];     cout << a <<     << b;   }