malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 20;   vector<int> bad[N], comp[N];   int off[N], delta[N], col[N];   long long cnt_on[N];   long long ans = 0;   bool hatman[N];   long long ok(long long x) {     x += 10;     x %= 2;     return x;   }   inline void mer(int u, int v, int f) {     int c1 = col[v], c2 = col[u];     if (c1 == c2) return;     if ((int)comp[c1].size() > (int)comp[c2].size()) swap(c1, c2);     long long avaz = 0;     if (ok(off[u] + off[v] + delta[c1] + delta[c2]) != ok(f)) {       long long d1 = ((int)comp[c1].size() - cnt_on[c1]) - cnt_on[c1];       long long d2 = ((int)comp[c2].size() - cnt_on[c2]) - cnt_on[c2];       avaz = 1;       if (hatman[c1] || (d2 <= d1 && !hatman[c2])) {         cnt_on[c2] = (int)comp[c2].size() - cnt_on[c2] + cnt_on[c1];         delta[c2] = ok(delta[c2] + 1);         ans += d2;         avaz = 0;       } else {         ans += d1;         cnt_on[c2] = cnt_on[c2] + (int)comp[c1].size() - cnt_on[c1];         avaz = 1;       }     } else       cnt_on[c2] += cnt_on[c1];     for (auto x : comp[c1]) {       comp[c2].push_back(x);       col[x] = c2;       off[x] = ok(off[x] + delta[c1]);       if (avaz) off[x] = ok(off[x] + 1);       if (delta[c2]) off[x] = ok(off[x] + 1);     }     hatman[c2] = hatman[c2] || hatman[c1];     vector<int>().swap(comp[c1]);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < n; i++) s[i] = char(1 - (s[i] -  0 ) +  0 );     for (int i = 0; i < k; i++) {       int tt;       cin >> tt;       for (int j = 0; j < tt; j++) {         int x;         cin >> x;         x--;         bad[x].push_back(i);       }     }     for (int i = 0; i < k; i++) {       comp[i].push_back(i);       col[i] = i;       cnt_on[i] = 0;     }     for (int i = 0; i < n; i++) {       if ((int)bad[i].size() == 0) {         cout << ans <<   n ;         continue;       }       if ((int)bad[i].size() == 1) {         int u = bad[i].back();         hatman[col[u]] = true;         int x = s[i] -  0 ;         if (ok(off[u] + delta[col[u]]) == ok(x)) {           cout << ans <<   n ;           continue;         }         u = col[u];         delta[u] = ok(delta[u] + 1);         ans -= cnt_on[u];         cnt_on[u] = (int)comp[u].size() - cnt_on[u];         ans += cnt_on[u];         cout << ans <<   n ;         continue;       }       int x = s[i] -  0 ;       int u = bad[i][0], v = bad[i].back();       mer(u, v, x);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   static const int MAXN = 100005;   int n = 0, m, ans_len = 0;   char s[MAXN], ans[MAXN] = {  0 };   std::pair<char, int> p[MAXN];   std::set<int> marked;   std::multiset<int> distance;   int main() {     scanf( %d , &m);     getchar();     while ((s[n] = getchar()) >=  a  && s[n] <=  z ) ++n;     for (int i = 0; i < n; ++i) p[i] = std::make_pair(s[i], i);     std::sort(p, p + n);     marked.insert(-1);     marked.insert(n);     distance.insert(n + 1);     for (char c =  a ; c <=  z ; ++c) {       for (int i = 0; i < n; ++i)         if (p[i].first == c) {           std::set<int>::iterator prev = marked.lower_bound(p[i].second),                                   succ = prev--;           int j = i + 1;           while (j < n && p[j].first == c && p[j].second < *succ) ++j;           int last_marked = *prev;           if (*succ <= last_marked + m) continue;           for (int k = i; k < j; ++k) {             while (k < j && p[k].second <= last_marked + m) ++k;             --k;             if (k < i || p[k].second == last_marked) break;             prev = marked.lower_bound(p[k].second), succ = prev--;             ans[ans_len++] = p[k].first;             marked.insert(p[k].second);             distance.erase(distance.find(*succ - *prev));             distance.insert(*succ - p[k].second);             distance.insert(p[k].second - *prev);             last_marked = p[k].second;             if (*succ <= last_marked + m) break;           }           i = j - 1;         }       if (*(distance.rbegin()) <= m) break;       for (int i = 0; i < n; ++i)         if (p[i].first == c) {           if (marked.find(p[i].second) != marked.end()) continue;           std::set<int>::iterator prev = marked.lower_bound(p[i].second),                                   succ = prev--;           ans[ans_len++] = p[i].first;           marked.insert(p[i].second);           distance.erase(distance.find(*succ - *prev));           distance.insert(*succ - p[i].second);           distance.insert(p[i].second - *prev);         }     }     puts(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char vis[305][305];   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     char c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> vis[i][j];       }     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (vis[i][k] ==  1  && vis[k][j] ==  1 ) vis[i][j] =  1 ;         }       }     }     for (int i = 0; i < n; i++) {       int in = i;       for (int j = i + 1; j < n; j++) {         if (v[in] > v[j] && vis[in][j] ==  1 ) {           in = j;         }       }       swap(v[i], v[in]);     }     for (int i = 0; i < n; i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<vector<int>, int> mp;   map<int, int> dp[100050];   set<int> ans;   vector<int> vec[100050];   int n, cnt = 0;   int getid(vector<int> t) {     if (mp.find(t) == mp.end())       return mp[t] = ++cnt;     else       return mp[t];   }   int getv(int x, int y) {     if (dp[x].find(y) != dp[x].end()) return dp[x][y];     vector<int> tmp;     tmp.clear();     for (int i = 0; i <= (int)vec[x].size() - 1; i++) {       int t = vec[x][i];       if (t == y) continue;       tmp.push_back(getv(t, x));     }     sort(tmp.begin(), tmp.end());     return dp[x][y] = getid(tmp);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       vec[x].push_back(y), vec[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if ((int)vec[i].size() < 4) ans.insert(getv(i, 0));     printf( %d n , (int)ans.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct people {     int a, d, id;     bool operator<(people other) const {       if (a != other.a) return a > other.a;       return id < other.id;     }   };   people s[111];   int n;   int main() {     int i, j, ans = 0;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d%d , &s[i].a, &s[i].d);       s[i].id = i;     }     sort(s + 1, s + 1 + n);     vector<int> ret;     for (i = 1; i <= n; ++i) {       if (s[i].d < 0) {         ret.push_back(s[i].id);       }     }     for (auto v : ret) {       for (i = 1; i <= n; ++i) {         if (s[i].id == v) {           j = i;           while (j < n &&                  (s[j].a + s[j].d < s[j + 1].a ||                   (s[j].a + s[j].d == s[j + 1].a && s[j].id > s[j + 1].id))) {             swap(s[j], s[j + 1]);             ans++;             j++;           }           s[j].a = s[j].a + s[j].d;           break;         }       }     }     ret.clear();     for (i = n; i >= 1; --i) {       if (s[i].d > 0) {         ret.push_back(s[i].id);       }     }     for (auto v : ret) {       for (i = n; i >= 1; --i) {         if (s[i].id == v) {           j = i;           while (j > 1 &&                  (s[j].a + s[j].d > s[j - 1].a ||                   (s[j].a + s[j].d == s[j - 1].a && s[j].id < s[j - 1].id))) {             swap(s[j], s[j - 1]);             ans++;             j--;           }           s[j].a = s[j].a + s[j].d;           break;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5 + 5;   struct tree {     int l, r, add, lv, rv;     ll sum;   } tr[N << 2];   int n, q, a[N];   void Add(int rt, int x) {     tr[rt].lv = tr[rt].rv = tr[rt].add = x;     tr[rt].sum = 1ll * (tr[rt].r - tr[rt].l + 1) * x;   }   void Pushdown(int rt) {     if (tr[rt].add) {       Add(rt << 1, tr[rt].add);       Add(rt << 1 | 1, tr[rt].add);       tr[rt].add = 0;     }   }   void Pushup(int rt) {     tr[rt].lv = tr[rt << 1].lv;     tr[rt].rv = tr[rt << 1 | 1].rv;     tr[rt].sum = tr[rt << 1].sum + tr[rt << 1 | 1].sum;   }   void Build(int rt, int l, int r) {     tr[rt].l = l, tr[rt].r = r;     if (l == r) {       tr[rt].sum = tr[rt].lv = tr[rt].rv = a[l];       tr[rt].add = 0;       return;     }     int mid = (l + r) >> 1;     Build(rt << 1, l, mid), Build(rt << 1 | 1, mid + 1, r);     Pushup(rt);   }   void Modify(int rt, int x, int y) {     if (tr[rt].l > x) return;     if (tr[rt].rv >= y) return;     if (tr[rt].lv <= y && tr[rt].r <= x) return Add(rt, y);     Pushdown(rt);     Modify(rt << 1, x, y), Modify(rt << 1 | 1, x, y);     Pushup(rt);   }   int Ask(int rt, int x, int &y) {     if (y < tr[rt].rv || tr[rt].r < x) return 0;     int ret = 0;     if (tr[rt].l >= x && tr[rt].sum <= y)       return y -= tr[rt].sum, x = tr[rt].r + 1, tr[rt].r - tr[rt].l + 1;     if (tr[rt].l == tr[rt].r) return 0;     Pushdown(rt);     ret += Ask(rt << 1, x, y);     ret += Ask(rt << 1 | 1, x, y);     return ret;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     Build(1, 1, n);     while (q--) {       int op, x, y;       scanf( %d%d%d , &op, &x, &y);       if (op == 1)         Modify(1, x, y);       else         printf( %d n , Ask(1, x, y));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long const N = 35;   long long dp[N][2][2];   long long get(long long l, long long r) {     if (l < 0 || r < 0) return 0;     memset(dp, 0, sizeof dp);     dp[35][1][1] = 1;     for (long long i = 34; i >= 0; i--) {       for (long long j = 0; j <= 1; j++) {         for (long long k = 0; k <= 1; k++) {           long long x = (j && !((l >> i) & 1ll)), y = (k && !((r >> i) & 1ll));           dp[i][x][y] += dp[i + 1][j][k];           if (!j || ((l >> i) & 1ll)) dp[i][j][y] += dp[i + 1][j][k];           if (!k || ((r >> i) & 1ll)) dp[i][x][k] += dp[i + 1][j][k];         }       }     }     return dp[0][0][0] + dp[0][1][0] + dp[0][1][1] + dp[0][0][1];   }   signed main() {     long long T, l, r;     scanf( %lld , &T);     while (T--) {       scanf( %lld%lld , &l, &r);       long long ans = get(r, r) - get(l - 1, r) * 2 + get(l - 1, l - 1);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     task();     return 0;   }   const int N = 6400 + 2;   const int S = N - 2;   const int T = N - 1;   struct Rib {     int to;     int cap;     int flow;     int back;     int cost;   };   const int INF = 0x3f3f3f3f;   vector<Rib> g[N];   int n, m;   int a[81][81];   const int shift[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   pair<int, int> par[N];   int d[N];   int in[N];   int ok(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }   void add_rib(int a, int b, int cap, int cost) {     g[a].push_back(Rib{b, cap, 0, ((int)((g[b]).size())), cost});     g[b].push_back(Rib{a, 0, 0, ((int)((g[a]).size())) - 1, -cost});   }   int get_id(int i, int j) { return (i * m + j) / 2 + ((i + j) % 2) * n * m / 2; }   int spfa() {     memset(d, 0x3f, sizeof(d));     d[S] = 0;     deque<int> q;     q.push_back(S);     in[S] = 1;     while (!q.empty()) {       int v = q.front();       q.pop_front();       in[v] = 0;       int i = 0;       for (Rib& r : g[v]) {         if (r.cap - r.flow && d[v] + r.cost < d[r.to]) {           d[r.to] = d[v] + r.cost;           par[r.to] = pair<int, int>{v, i};           if (!in[r.to]) q.push_back(r.to);           in[r.to] = 1;         }         ++i;       }     }     return d[T] != INF;   }   int mcmf() {     int res = 0;     while (spfa()) {       ++res;       int v = T;       while (v != S) {         Rib& r = g[par[v].first][par[v].second];         r.flow++;         g[r.to][r.back].flow--;         v = par[v].first;       }     }     return res;   }   void task() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) scanf( %d , &a[i][j]);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if ((i + j) % 2) {           add_rib(get_id(i, j), T, 1, 0);         } else {           add_rib(S, get_id(i, j), 1, 0);           for (int h = 0; h < 4; ++h) {             int ii = i + shift[h][0];             int jj = j + shift[h][1];             if (!ok(ii, jj)) continue;             add_rib(get_id(i, j), get_id(ii, jj), 1, a[i][j] != a[ii][jj]);           }         }       }     mcmf();     int ans = 0;     for (int i = 0; i < n * m / 2; ++i)       for (Rib& r : g[i])         if (r.flow > 0) ans += r.cost;     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     bool fr;     int lb, rb;     Node *lc, *rc;   };   void buildSeg(Node *&p, int l, int r) {     p = new Node;     p->fr = true;     p->lb = l;     p->rb = r;     if (p->lb < p->rb) {       int mid = (p->lb + p->rb) / 2;       buildSeg(p->lc, p->lb, mid);       buildSeg(p->rc, mid + 1, p->rb);     }   }   void setVal(Node *p, int x, bool val) {     if (p->lb == p->rb)       p->fr = val;     else {       int mid = (p->lb + p->rb) / 2;       if (x <= mid)         setVal(p->lc, x, val);       else         setVal(p->rc, x, val);       p->fr = p->lc->fr | p->rc->fr;     }   }   int findFr(Node *p, int l, int r) {     if (p->fr) {       if (p->lb == p->rb)         return p->lb;       else {         int mid = (p->lb + p->rb) / 2, ret = -1;         if (l <= mid) ret = findFr(p->lc, l, r);         if ((mid + 1 <= r) && (ret == -1)) ret = findFr(p->rc, l, r);         return ret;       }     }     return -1;   }   const int _N = 200010;   int h, m, n, ptN, pt[_N];   long long cost;   pair<int, int> inP[_N];   Node *rt;   map<int, int> ps;   void initSeg() {     ptN = 0;     int cnt = 0;     for (int i = 0; i < h; i++) inP[i].first = -1;     for (int i = 0; i < h; i++)       if (inP[i].first == -1) {         pt[ptN] = cnt;         for (int j = i; inP[j].first == -1; j = (j + m) % h)           inP[j] = pair<int, int>(ptN, cnt++);         ptN++;       }     pt[ptN] = cnt;     buildSeg(rt, 0, cnt - 1);   }   void pushHash(int i, int v) {     int p = findFr(rt, inP[v].second, pt[inP[v].first + 1] - 1);     if (p == -1) p = findFr(rt, pt[inP[v].first], inP[v].second - 1);     setVal(rt, p, false);     ps.insert(pair<int, int>(i, p));     cost += (p >= inP[v].second)                 ? (p - inP[v].second)                 : (pt[inP[v].first + 1] - inP[v].second + p - pt[inP[v].first]);   }   void popHash(int i) {     map<int, int>::iterator x = ps.find(i);     setVal(rt, x->second, true);     ps.erase(x);   }   int main() {     ios::sync_with_stdio(false);     cin >> h >> m >> n;     initSeg();     cost = 0;     for (int k = 0; k < n; k++) {       char c;       int i;       cin >> c >> i;       if (c ==  + ) {         int v;         cin >> v;         pushHash(i, v);       } else         popHash(i);     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 10000000;   char c[200];   int a[200], n, dp[200][200][200][2];   bool vis[200][200][200][2];   int f(int i, int j, int l, bool t) {     if (i > j) return a[l];     int &ret = dp[i][j][l][t];     if (vis[i][j][l][t]) return ret;     ret = -INF;     vis[i][j][l][t] = true;     if (t) {       ret = max(ret, a[l] + f(i, j, 0, t));       if (c[i] == c[j]) ret = max(ret, f(i + 1, j - 1, l + 2 - (i == j), 1));     } else {       ret = max(f(i + 1, j, l, 0), f(i, j - 1, l, 0));       ret = max(ret, f(i, j, l, 1));     }     for (int k = i; k < j; ++k)       ret = max(ret, max(f(i, k, 0, t) + f(k + 1, j, l, t),                          f(i, k, l, t) + f(k + 1, j, 0, t)));     return ret;   }   int main() {     n = ({       int __t;       scanf( %d , &__t);       __t;     });     for (int i = 0; i < n; ++i)       a[i + 1] = ({         int __t;         scanf( %d , &__t);         __t;       }),             a[i + 1] = ((a[i + 1]) < 0 ? (-INF) : (a[i + 1]));     scanf( %s , c);     printf( %d n , f(0, n - 1, 0, 0));   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX;   const int mxn = 1011;   bool DEBUG = 0;   string s[mxn];   bool grid[mxn][mxn], chg[mxn][mxn];   long long dist[mxn][mxn];   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   int n, m;   bool check(int x, int y) {     if (0 <= x && x < n && 0 <= y && y < m) return 1;     return 0;   }   void init() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (chg[i][j]) continue;         bool f = 0;         for (int k = 0; k < 4 && !f; k++) {           int x = i + dx[k];           int y = j + dy[k];           if (!check(x, y)) continue;           if (grid[x][y] == grid[i][j]) {             f = 1;             chg[x][y] = 1;           }         }         if (f)           chg[i][j] = 1;         else           chg[i][j] = 0;       }     }   }   void bfs(int x, int y) {     queue<pair<int, int> > q;     q.push(pair<int, int>(x, y));     while (!q.empty()) {       pair<int, int> now = q.front();       x = now.first;       y = now.second;       q.pop();       for (int i = 0; i < 4; i++) {         int X = x + dx[i];         int Y = y + dy[i];         if (!check(X, Y)) continue;         if (dist[x][y] + 1 < dist[X][Y]) {           dist[X][Y] = dist[x][y] + 1;           q.push(pair<int, int>(X, Y));         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> n >> m >> q;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < m; j++) {         grid[i][j] = s[i][j] ==  1 ;       }     }     init();     vector<pair<int, int> > visit;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (chg[i][j]) {           dist[i][j] = 0;           visit.emplace_back(i, j);         } else {           dist[i][j] = 1e18 + 1;         }       }     }     for (auto cor : visit) {       bfs(cor.first, cor.second);     }     int a, b;     long long t;     while (q--) {       cin >> a >> b >> t;       a--;       b--;       if (t < dist[a][b]) {         cout << grid[a][b] <<   n ;       } else {         t -= dist[a][b];         if (t % 2)           cout << int(grid[a][b] ^ 1) <<   n ;         else           cout << grid[a][b] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       map<char, long long int> d;       string p;       int n, m;       cin >> n >> m;       cin >> p;       vector<map<char, long long int>> x(n + 2);       for (int i = 0; i < n; i++) {         x[i][p[i]]++;         for (char j =  a ; j <=  z ; j++) {           x[i + 1][j] = x[i][j];           if (i == n - 1) d[j] = x[i][j];         }       }       for (int i = 0; i < m; i++) {         int y;         cin >> y;         y--;         for (char j =  a ; j <=  z ; j++) {           d[j] += x[y][j];         }       }       for (char j =  a ; j <=  z ; j++) {         cout << d[j] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T sig = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) sig = -1;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= sig;   }   class Solution {    public:     void solve() {       int n;       read(n);       set<pair<int, int>> s;       for (int i = 0; i < n; ++i) {         string t;         cin >> t;         int b = 0;         for (char c : t) b += c ==  B ;         s.insert({b, t.size() - b});       };       vector<pair<int, int>> vs(s.begin(), s.end());       auto check = [&](int l, bool output) {         int xl = 0, xr = 5e5, yl = 0, yr = 5e5, zl = -5e5, zr = 5e5;         for (auto p : vs) {           xl = max(xl, p.first - l);           xr = min(xr, p.first + l);           yl = max(yl, p.second - l);           yr = min(yr, p.second + l);           zl = max(zl, p.first - p.second - l);           zr = min(zr, p.first - p.second + l);         }         if (xl > xr || yl > yr || zl > zr) return false;         int zl1 = xl - yr, zr1 = xr - yl;         if (output) {           int x = min(xr, zr + yr);           int y = min(yr, x - zl);           string s(x,  B ), t(y,  N );           printf( %s , (s + t).c_str());         }         return max(zl, zl1) <= min(zr, zr1);       };       int lo = 0, hi = 1e6;       while (lo <= hi) {         int mid = (lo + hi) >> 1;         if (check(mid, false))           hi = mid - 1;         else           lo = mid + 1;       }       printf( %d n , lo);       check(lo, true);     }   };   int main() {     Solution solution = Solution();     solution.solve();   }
#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     long long ans = a;     ans *= b;     return ((ans >= p) ? ans % p : ans);   }   long long add(long long a, long long b, long long p = 1000000007) {     long long ans = a + b;     return ((ans >= p) ? ans - p : ans);   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   int n;   map<int, vector<pair<int, int> > > store;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second != b.second)       return a.second < b.second;     else       return a.first < b.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     vector<int> arr(n);     vector<int> presum(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> arr[i];       presum[i + 1] = presum[i] + arr[i];     }     for (int i = 0; i < n + 1; i++) {       for (int j = i + 1; j < n + 1; j++) {         int sums = presum[j] - presum[i];         auto it = store.find(sums);         if (it == store.end()) {           vector<pair<int, int> > temp;           temp.push_back({i + 1, j});           store[sums] = temp;         } else           it->second.push_back({i + 1, j});       }     }     int maxans = 0, maxind = -1;     for (auto &e : store) {       int locmax = 0;       int curfirst = -1, cursecond = -1;       sort(e.second.begin(), e.second.end(), comp);       for (auto &ee : e.second) {         if (ee.first <= cursecond)           continue;         else {           locmax++;           curfirst = ee.first;           cursecond = ee.second;         }       }       if (locmax > maxans) {         maxans = locmax;         maxind = e.first;       }     }     cout << maxans << endl;     auto it = store.find(maxind);     int curfirst = -1, cursecond = -1;     for (auto &ee : it->second) {       if (ee.first <= cursecond)         continue;       else {         curfirst = ee.first;         cursecond = ee.second;         cout << curfirst <<     << cursecond << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int id;     int no;   } a[100001];   int n, tot = 1, minn = 2100000000;   bool cmp(node a, node b) {     if (a.no != b.no) return a.no < b.no;     return a.id < b.id;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].no);       a[i].id = i;     }     sort(a + 1, a + n + 1, cmp);     while (a[tot].no == a[tot + 1].no) {       minn = min(minn, a[tot + 1].id - a[tot].id);       tot++;     }     printf( %d , minn);     return 0;   }