malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dadsadasda;   const int INF = 0x3f3f3f3f;   const long long LLINF = 1e18;   const int MAXN = 3e5;   int n;   int a[MAXN];   int ans[MAXN];   priority_queue<pair<int, int> > pq;   int father[MAXN], siz[MAXN], cnt[MAXN];   void makeSet(int nn, int m) {     for (int i = nn; i <= m; ++i) {       father[i] = -1;       siz[i] = 0;       cnt[i] = 1;     }   }   int find(int x) {     if (father[x] == -1) return x;     return father[x] = find(father[x]);   }   void unio(int x, int y) {     if (siz[x] > siz[y]) {       father[y] = x;       cnt[x] += cnt[y];     } else {       father[x] = y;       cnt[y] += cnt[x];       if (siz[x] == siz[y]) siz[y]++;     }   }   bool active[MAXN];   int main() {     dadsadasda = scanf( %d , &n);     for (int i = 0; i < n; i++) {       dadsadasda = scanf( %d , &a[i]);       pq.push({a[i], i});     }     makeSet(0, n - 1);     while (!pq.empty()) {       auto p = pq.top();       pq.pop();       active[p.second] = true;       if (p.second > 0 && find(p.second) != find(p.second - 1) &&           active[p.second - 1])         unio(find(p.second), find(p.second - 1));       if (p.second < n - 1 && find(p.second) != find(p.second + 1) &&           active[p.second + 1])         unio(find(p.second), find(p.second + 1));       int sz = cnt[find(p.second)];       ans[sz] = max(ans[sz], p.first);     }     for (int i = n - 1; i >= 1; i--) {       ans[i] = max(ans[i], ans[i + 1]);     }     for (int i = 1; i < n + 1; i++) {       printf( %d  , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   double const MOD = 1000000007;   double const N = 1000005;   double const LN = 20;   double const inf = 1e18 + 5;   using namespace std;   double a, b;   void mirror(double &x, double &z) {     if (x < 0) {       x = -x;       return;     }     if (z < 0) {       z = -z;       return;     }     if (x > a) {       x = 2 * a - x;       return;     }     if (z > b) {       z = 2 * b - z;       return;     }   }   int main() {     double m;     double vx, vy, vz;     cin >> a >> b >> m;     cin >> vx >> vy >> vz;     double ok = abs(m / vy);     double x = a / 2 + ok * vx;     double z = 0 + vz * ok;     while (1) {       if (x >= 0 && x <= a && z >= 0 && z <= b) break;       mirror(x, z);     }     printf( %.10f %.10f n , x, z);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ara[100010];   int segtree[20][100010 * 4];   int lazy[20][100010 * 4];   void build(int node, int l, int r, int po) {     if (l == r) {       segtree[po][node] = 0;       if ((ara[l] & (1 << po))) {         segtree[po][node] = 1;       }       return;     }     int mid = (l + r) >> 1;     int left = node << 1;     int right = left | 1;     build(left, l, mid, po);     build(right, mid + 1, r, po);     segtree[po][node] = segtree[po][left] + segtree[po][right];     return;   }   int query(int node, int l, int r, int ql, int qr, int po) {     if (lazy[po][node]) {       segtree[po][node] = (r - l + 1) - segtree[po][node];       if (l != r) {         lazy[po][(node << 1)] ^= 1;         lazy[po][1 + (node << 1)] ^= 1;       }       lazy[po][node] = 0;     }     if (l >= ql && qr >= r) {       return segtree[po][node];     }     if (l > qr || ql > r) return 0;     int mid = (l + r) >> 1;     int left = node << 1;     int right = left | 1;     int p = query(left, l, mid, ql, qr, po);     int q = query(right, mid + 1, r, ql, qr, po);     return p + q;   }   void update(int node, int l, int r, int ql, int qr, int po) {     if (lazy[po][node]) {       segtree[po][node] = (r - l + 1) - segtree[po][node];       if (l != r) {         lazy[po][node << 1] ^= 1;         lazy[po][1 + (node << 1)] ^= 1;       }       lazy[po][node] = 0;     }     if (l >= ql && qr >= r) {       segtree[po][node] = (r - l + 1) - segtree[po][node];       if (l != r) {         lazy[po][node << 1] ^= 1;         lazy[po][1 + (node << 1)] ^= 1;       }       lazy[po][node] = 0;       return;     }     if (l > qr || r < ql) return;     int mid = (l + r) >> 1;     int left = node << 1;     int right = left | 1;     update(left, l, mid, ql, qr, po);     update(right, mid + 1, r, ql, qr, po);     segtree[po][node] = segtree[po][left] + segtree[po][right];     return;   }   int main() {     long long n;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &ara[i]);     }     for (int i = 0; i < 20; i++) {       build(1, 1, n, i);     }     long long m;     scanf( %lld , &m);     while (m--) {       long long x;       scanf( %lld , &x);       if (x == 1) {         long long a, b;         scanf( %lld%lld , &a, &b);         long long sum = 0;         for (int i = 0; i < 20; i++) {           int y = query(1, 1, n, a, b, i);           sum += y * (1LL << i);         }         printf( %lld n , sum);       } else {         long long a, b, c;         scanf( %lld%lld , &a, &b);         scanf( %lld , &c);         for (int i = 0; i < 20; i++) {           if (c & (1 << i)) {             update(1, 1, n, a, b, i);           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct road {     int x, next;     double dis;   } r[305 * 305 * 2];   int N, M;   int st[305], w;   int vis[305];   double P[305];   double l1 = -1, r1 = 0, mid;   double dis[305];   void add(int x, int y, double dis) {     r[++w].x = y, r[w].next = st[x];     r[w].dis = dis;     st[x] = w;   }   bool work(int x) {     int i, j, tmp;     if (vis[x]) return true;     vis[x] = 1;     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (dis[tmp] > dis[x] + r[i].dis - mid) {         dis[tmp] = dis[x] + r[i].dis - mid;         if (work(tmp)) return true;       }     }     vis[x] = 0;     return false;   }   int main() {     int i, j;     int fr, to;     scanf( %d , &N);     for (i = 0; i <= N; i++) scanf( %lf , &P[i]);     M = N * 3;     for (i = 0; i <= M; i++)       for (j = N, fr = i; j >= -N; j -= 2) {         to = fr + j;         if (to > M || to < 0) continue;         add(fr, to, -P[(N - j) / 2]);       }     for (i = 1; i <= 21; i++) {       mid = (l1 + r1) / 2;       for (j = 1; j <= 20; j++) {         memset(dis, 63, sizeof(dis));         memset(vis, 0, sizeof(vis));         fr = rand() % M + 1, dis[fr] = 0;         if (work(fr)) break;       }       if (j <= 9)         r1 = mid;       else         l1 = mid;     }     printf( %.8lf n , -mid);     return 0;   }
#include <bits/stdc++.h>   char map[1005][1005];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int r = 0; r < n; r++) scanf( %s , map[r]);     int row[1005] = {0};     int col[1005] = {0};     for (int r = 0; r < n; r++) {       int count = 0;       for (int c = 0; c < m; c++)         if (map[r][c] ==  * ) count++;       row[r] = count;     }     for (int c = 0; c < m; c++) {       int count = 0;       for (int r = 0; r < n; r++)         if (map[r][c] ==  * ) count++;       col[c] = count;     }     long long answer = 0;     for (int r = 0; r < n; r++)       for (int c = 0; c < m; c++)         if (map[r][c] ==  * ) answer += (row[r] - 1) * (col[c] - 1);     printf( %I64d n , answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int mod = 1e9 + 7;   long double a[N];   int n, k;   long double dp[1 << N], out[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     int zeros = 0;     for (int i = 0; i < n; i++) cin >> a[i], zeros += fabs(a[i] < (1e-7));     k = min(k, n - zeros);     dp[0] = 1.0;     for (int i = 0; i < 1 << n; i++) {       double tmp = 1.0;       for (int j = 0; j < n; j++)         if (i >> j & 1) tmp -= a[j];       if (__builtin_popcount(i) == k)         for (int j = 0; j < n; j++)           if (i >> j & 1) out[j] += dp[i];       if (tmp == 0.0) continue;       cout << fixed << setprecision(6);       for (int j = 0; j < n; j++)         if (!(i >> j & 1)) dp[i | 1 << j] += a[j] * dp[i] / tmp;     }     for (int i = 0; i < n; i++) cout << out[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   const long long N = 1000000;   using namespace std;   long long n, k, l, i = 0, j, mn, mx = N, ans = 0, als, r1, r2, r3, t, q, v, m,                      ii, r4;   string d1, d3, d2, s;   char kl, km, mk, lk;   double fg;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     bool a[N];     for (i = 0; i < n * 2; i++) {       cin >> t;       a[t - 1] = !a[t - 1];       m += a[t - 1] * 2 - 1;       ans = max(ans, m);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     long long r1, r2, r3, d;     cin >> n >> r1 >> r2 >> r3 >> d;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<vector<long long>> dp(n, vector<long long>(2, LLONG_MAX));     dp[0][0] = r1 * a[0] + r3;     dp[0][1] = min(r1 * (a[0] + 2), r2 + r1);     for (int i = 1; i < n; i++) {       long long one = r1 * a[i] + r3;       long long two = min(r1 * (a[i] + 2), r2 + r1);       dp[i][0] = min(dp[i][0], dp[i - 1][0] + one);       dp[i][0] = min(dp[i][0], dp[i - 1][1] + min(one, two) + 2 * d);       if (i == n - 1) dp[i][0] = min(dp[i][0], dp[i - 1][1] + one + d);       dp[i][1] = min(dp[i][1], dp[i - 1][0] + two);     }     printf( %lld n , min(dp[n - 1][0], dp[n - 1][1] + 2 * d) + (n - 1) * d);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long MOD = 1000000007;   vector<vector<long long> > matrix_mul(vector<vector<long long> > a,                                         vector<vector<long long> > b) {     vector<vector<long long> > c(a.size(), vector<long long>(b[0].size()));     for (int i = 0; i < a.size(); i++)       for (int j = 0; j < b[0].size(); j++)         for (int k = 0; k < b.size(); k++) {           c[i][j] += (a[i][k] * b[k][j]) % MOD;           c[i][j] %= MOD;         }     return c;   }   vector<vector<long long> > matrix_pow(vector<vector<long long> > a,                                         long long p) {     if (p == 1) return a;     if (p % 2 == 1) return matrix_mul(a, matrix_pow(a, p - 1));     vector<vector<long long> > c = matrix_pow(a, p / 2);     return matrix_mul(c, c);   }   int N, B, K, X;   long long occ[10];   int main() {     cin >> N >> B >> K >> X;     for (int i = 0; i < N; i++) {       int d;       cin >> d;       occ[d]++;     }     vector<long long> f(X);     f[0] = 1;     vector<vector<long long> > T(X);     for (int i = 0; i < X; i++) {       T[i] = vector<long long>(X);     }     for (int i = 0; i < X; i++) {       for (int d = 1; d <= 9; d++)         if (occ[d]) {           int a = (i * 10 + d) % X;           T[a][i] += occ[d];         }     }     T = matrix_pow(T, B);     long long res = 0;     res = (T[K][0] * f[0] % MOD) % MOD;     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double eps = 1e-6;   vector<int> g[maxn];   vector<int> tree[maxn];   int deep[maxn], son[maxn];   int cnt, mx;   void dfs(int x, int y) {     int sz = g[x].size();     deep[x] = 0;     son[x] = -1;     for (int i = 0; i < sz; ++i) {       int to = g[x][i];       if (to == y) {         continue;       }       tree[x].push_back(to);       dfs(to, x);       if (son[x] == -1 || deep[son[x]] < deep[to]) {         son[x] = son[to];       }     }     if (son[x] == -1) {       son[x] = x;     } else {       deep[x] = deep[son[x]] + 1;     }   }   struct node {     int id, w;     bool operator<(const node& rhs) const { return w > rhs.w; }   } nd[maxn];   int solve(int x) {     int sz = tree[x].size();     for (int i = 0; i < sz; ++i) {       nd[i] = {tree[x][i], deep[tree[x][i]]};     }     sort(nd, nd + sz);     int hf = sz / 2;     for (int i = 0; i < hf; ++i) {       int a = nd[i * 2].id, b = nd[i * 2 + 1].id;       ++cnt;       printf( ? %d %d n , son[a], son[b]);       fflush(stdout);       int c;       scanf( %d , &c);       if (c != x) {         return solve(c);       }       if (cnt >= mx) break;     }     if ((sz & 1) == 1 && cnt < mx) {       ++cnt;       printf( ? %d %d n , x, son[nd[sz - 1].id]);       fflush(stdout);       int c;       scanf( %d , &c);       if (c != x) {         return solve(c);       }     }     return x;   }   int main() {     int n;     scanf( %d , &n);     cnt = 0, mx = n / 2;     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, -1);     printf( ! %d n , solve(1));     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   int main() {     cin >> N;     int dec[2 * N];     int all_round_down = 0;     int z = 0;     for (int i = 0; i < 2 * N; i++) {       double x;       cin >> x;       dec[i] = int((x + 0.0005 - int(x + 0.0005)) * 1000);       all_round_down += dec[i];       if (dec[i] == 0) z++;     }     int mi = max(0, N - z);     int ma = min(N, 2 * N - z);     int best = (all_round_down + 500) / 1000;     int ans;     if (best >= mi && best <= ma)       ans = abs(all_round_down - 1000 * best);     else       ans = min(abs(all_round_down - 1000 * mi), abs(all_round_down - 1000 * ma));     cout << ans / 1000 <<  .  << (ans % 1000) / 100 << (ans % 100) / 10          << ans % 10;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> edge[(1 << 18)];   int degree[(1 << 18)];   int DelNode;   int DFS(int iDeep, int iNode, int iParent) {     int iSons = edge[iNode].size();     if (iParent) iSons--;     if (iDeep > n) return -1;     if (iSons > 3) return -1;     if (iSons == 0) return 1;     if (iSons & 1) {       if (DelNode) return -1;       DelNode = iNode;       vector<int> RetList;       for (auto Iter : edge[iNode]) {         if (Iter == iParent) continue;         int iRet = DFS(iDeep + 1, Iter, iNode);         if (-1 == iRet) return iRet;         RetList.push_back(iRet);       }       sort(RetList.begin(), RetList.end());       if (iSons == 1) {         if (RetList[0] != 1) return -1;         return RetList[0] + 1;       } else {         if (RetList[0] != RetList[1] || RetList[0] + 1 != RetList[2]) return -1;         return RetList[2] + 1;       }     } else {       assert(iSons == 2);       int iDeepToButtom = -1;       for (auto Iter : edge[iNode]) {         if (Iter == iParent) continue;         int iRet = DFS(iDeep + 1, Iter, iNode);         if (-1 == iRet) return iRet;         if (iDeepToButtom == -1)           iDeepToButtom = iRet;         else if (iDeepToButtom != iRet)           return -1;       }       return iDeepToButtom + 1;     }   }   int main() {     scanf( %d , &n);     int k = (1 << n) - 2;     for (int i = 0; i < k - 1; ++i) {       int u, v;       scanf( %d %d , &u, &v);       edge[u].push_back(v);       edge[v].push_back(u);       degree[u]++;       degree[v]++;     }     vector<int> list;     for (int i = 1; i <= k; ++i)       if (degree[i] == 1) {         list.push_back(i);       }     for (int i = 0; i < list.size(); ++i) {       int iCur = list[i];       for (auto Iter : edge[iCur]) {         if (--degree[Iter] == 1) list.push_back(Iter);       }     }     assert(list.size() == k);     int i = 0;     vector<int> result;     for (auto Iter = list.rbegin(); i < 5 && Iter != list.rend(); Iter++, i++) {       DelNode = 0;       if (DFS(1, *Iter, 0) != -1) {         assert(DelNode);         result.push_back(DelNode);       }     }     sort(result.begin(), result.end());     result.resize(unique(result.begin(), result.end()) - result.begin());     printf( %d n , result.size());     for (int i = 0; i < result.size(); ++i) {       if (i) putchar(   );       printf( %d , result[i]);     }     putchar(  n );   }
#include <bits/stdc++.h>   using namespace std;   long long n, sz, i, ans, j, a[200001], t[531172], op;   void upd(int x) {     for (j = x / 2; j >= 1; j /= 2) t[j] = max(t[j * 2], t[j * 2 + 1]);   }   long long finds(int l, int r) {     long long sum = -1;     while (l <= r) {       if (l % 2 == 1) sum = max(sum, t[l]);       if (r % 2 == 0) sum = max(sum, t[r]);       l++, r--, l /= 2, r /= 2;     }     return sum;   }   int main() {     cin >> n;     sz = 1;     while (sz < n) sz *= 2;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) {       t[a[i] + sz - 1] = finds(sz, a[i] + sz - 1) + 1;       upd(a[i] + sz - 1);     }     cout << max(t[1], 1ll);   }
#include <bits/stdc++.h>   using namespace std;   int read() {     register int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int Size = 100005;   int n, top;   struct vec {     double x, y;   } w[Size], a[Size], O, stk[Size];   inline vec operator-(vec a, vec b) { return (vec){a.x - b.x, a.y - b.y}; }   inline vec operator+(vec a, vec b) { return (vec){a.x + b.x, a.y + b.y}; }   inline bool operator<(vec a, vec b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   inline double Xji(vec p, vec q) { return p.x * q.y - p.y * q.x; }   inline double dist(vec mhy) { return mhy.x * mhy.x + mhy.y * mhy.y; }   inline bool comp(vec jzm, vec xjp) {     double tmp = Xji(jzm, xjp);     if (fabs(tmp) > 1e-6) return tmp > 1e-6;     return dist(jzm) < dist(xjp);   }   inline double dist(vec mhy, vec zwt) {     return sqrt((mhy.x - zwt.x) * (mhy.x - zwt.x) +                 (mhy.y - zwt.y) * (mhy.y - zwt.y));   }   inline vec rotate(vec a, double rad) {     return (vec){a.x * cos(rad) - a.y * sin(rad),                  a.x * sin(rad) + a.y * cos(rad)};   }   int main() {     n = read();     for (register int i = 1; i <= n; i++) {       double x, y;       scanf( %lf %lf , &x, &y);       w[i].x = x;       w[i].y = y - x * x;     }     vec O = w[1];     int id = 1;     for (register int i = 2; i <= n; i++) {       if (w[i] < O) {         id = i;         O = w[i];       }     }     swap(w[id], w[1]);     for (register int i = 1; i <= n; i++) {       a[i] = w[i] - O;     }     sort(a + 2, a + 1 + n, comp);     for (register int i = 1; i <= n; i++) {       while (top > 1 && Xji(stk[top] - stk[top - 1], a[i] - stk[top - 1]) <= 0) {         top--;       }       stk[++top] = a[i];     }     for (register int i = 1; i <= top; i++) {       stk[i] = stk[i] + O;     }     int ans = 0;     for (register int i = 1; i <= top; i++) {       int pos = i % top + 1;       if (stk[i].x > stk[pos].x) {         ans++;       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1010];   long long b[1010];   long long c[2020];   long long d[1010];   long long mex(long long m) {     sort(b, b + m);     long long j = 0;     long long k = 0;     long long ans = m;     while (j < m) {       if (b[k] > j) {         ans = j;         break;       } else if (b[k] == j) {         k++;         j++;       } else {         k++;       }     }     return ans;   }   long long check(long long m) {     long long ct3 = 0;     for (long long i = 1; i < m; i++) {       if (a[i] < a[i - 1]) {         ct3 = 1;         break;       }     }     if (ct3 == 1)       return 0;     else       return 1;   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ct = 1;       long long ct1 = 0;       for (long long i = 0; i <= n; i++) {         a[i] = 0;         b[i] = 0;         c[i] = 0;         d[i] = 0;       }       for (long long i = n; i <= (n + n); i++) {         c[i] = 0;       }       for (long long i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         if (a[i] == i) d[i] = 1;       }       while (ct <= (2 * n)) {         if (check(n) == 1) break;         ct1 = mex(n);         if (ct1 == n) {           for (long long i = 0; i < n; i++) {             if (d[i] != 1) {               a[i] = n;               c[ct] = i;               break;             }           }         } else {           c[ct] = ct1;           a[ct1] = ct1;           d[ct1] = 1;         }         for (long long i = 0; i < n; i++) b[i] = a[i];         ct++;       }       cout << ct - 1 <<   n ;       for (long long i = 1; i < ct; i++) {         cout << c[i] + 1 <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class A>   ostream& operator<<(ostream& out, const vector<A>& v) {     for (long long i = 0; i < v.size(); i++) {       if (i) out <<    ;       out << v[i];     }     return out <<   n ;   }   const long long mod = 1000000007;   inline long long add(long long a, long long b) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline long long sub(long long a, long long b) {     a -= b;     if (a < 0) a += mod;     return a;   }   inline long long mul(long long a, long long b) { return (a * 1ll * b) % mod; }   inline long long powmod(long long a, long long b) {     long long rt = 1;     while (b > 0) {       if (b & 1) rt = mul(rt, a);       a = mul(a, a);       b >>= 1;     }     return rt;   }   inline long long inv(long long a) { return powmod(a, mod - 2); }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long n, k;   long long a[100005];   bool check(long long mid) {     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += min(mid, a[i]);     }     return sum <= k;   }   void solve() {     cin >> n >> k;     long long rt = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       rt += a[i];     }     if (rt < k) {       cout << -1 <<   n ;       return;     }     long long lo = 1;     long long hi = *max_element(a, a + n);     long long ans = 0;     while (hi - lo >= 0) {       long long mid = (hi + lo) >> 1;       if (check(mid)) {         lo = mid + 1;         ans = mid;       } else {         hi = mid - 1;       }     }     if (false) cerr << ans <<   n ;     for (long long i = 0; i < n; i++) {       k -= min(a[i], ans);       a[i] -= min(a[i], ans);     }     if (false) cerr << k <<   n ;     long long i = 0;     for (i = 0; i < n && k > 0; i++) {       if (a[i] <= 0)         continue;       else {         a[i]--;         k--;       }       if (false) cerr << a[i] <<    ;     }     if (false) cerr <<   n ;     long long y = 0;     for (long long j = i; j < i + n; j++) {       long long tmp = j % n;       if (false) cerr << a[tmp] <<    ;       if (a[tmp] <= 0) continue;       y = 1;       cout << tmp + 1 <<    ;     }     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL),         cout << setprecision(14);     ;     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   string in_name =  sample.in ;   string out_name =  sample.out ;   ifstream in;   ofstream out;   vector<int> v[1001];   int N;   int main() {     cin >> N;     int k, x;     for (int i = 0; i < N; i++) {       cin >> k;       for (int j = 0; j < k; j++) {         cin >> x;         v[i].push_back(x);       }       sort(v[i].begin(), v[i].end());     }     int res = 0;     for (int i = 0; i < N; i++) {       for (int j = 0; j < v[i].size() - 1; j++) {         std::vector<int>::iterator low, up;         int before = (i - 1 + N) % N;         int after = (i + 1) % N;         int left = 0, right = 0;         up = upper_bound(v[before].begin(), v[before].end(), v[i][j]);         low = lower_bound(v[before].begin(), v[before].end(), v[i][j + 1]);         int u = (int)(up - v[before].begin());         int l = (int)(low - v[before].begin());         if (u < v[before].size() && v[before][u] < v[i][j + 1])           left += (l - u) + 1;         up = upper_bound(v[after].begin(), v[after].end(), v[i][j]);         low = lower_bound(v[after].begin(), v[after].end(), v[i][j + 1]);         u = (int)(up - v[after].begin());         l = (int)(low - v[after].begin());         if (u < v[after].size() && v[after][u] < v[i][j + 1])           right += (l - u) + 1;         if (left != right) {           res++;         }       }     }     cout << res << endl;     return 0;   }