malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265359;   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T sqr(T x) {     return x * x;   }   const long long mod = 1000000007;   struct matr {     int maxn;     int n;     long long a[1 << 7][1 << 7];     matr(int _n) {       maxn = 1 << _n;       n = _n;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) a[i][j] = 0;     }     matr operator*(const matr &other) const {       matr res(n);       long long mod2 = mod * mod;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) {           for (int h = 0; h < maxn; h++) {             res.a[i][j] += (a[i][h] * other.a[h][j]);             if (res.a[i][j] >= mod2) res.a[i][j] -= mod2;           }           res.a[i][j] %= mod;         }       return res;     }     vector<long long> operator*(const vector<long long> &row) {       vector<long long> res(maxn);       for (int i = 0; i < maxn; i++) {         for (int j = 0; j < maxn; j++) {           res[i] += (a[i][j] * row[j]) % mod;         }         res[i] %= mod;       }       return res;     }   };   matr gen(int n) {     if (n == 1) {       matr res(n);       res.a[0][1] = 1;       res.a[0][0] = 1;       res.a[1][0] = 1;       return res;     }     matr res(7);     for (int _left = 0; _left < (1 << n); _left++) {       for (int mid = 0; mid < (1 << (n - 1)); mid++) {         int cmid = (mid << 1) | 1 | (1 << n);         for (int _right = 0; _right < (1 << n); _right++) {           bool bad = false;           for (int j = 0; j < n && !bad; j++) {             bad |= bool(_left & (1 << j)) && bool(_right & (1 << j)) &&                    bool(cmid & (1 << j)) && bool(cmid & (1 << (j + 1)));           }           if (!bad) {             res.a[_right][_left]++;           }         }       }     }     return res;   }   int main() {     vector<long long> ans(1 << 7);     ans[1] = 1;     for (int i = 1; i <= 7; i++) {       int n;       cin >> n;       matr x(7), res(7);       x = gen(i);       for (int j = 0; j < (1 << i); j++)         for (int h = 0; h < (1 << i); h++) res.a[j][h] = j == h;       while (n) {         if (n & 1) res = res * x;         x = x * x;         n >>= 1;       }       ans = res * ans;       if (i == 7) break;       for (int j = 0; j < (1 << i); j++) {         ans[j | (1 << i)] = ans[j];         ans[j] = 0;       }     }     cout << ans[(1 << 7) - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Inf = 1000000000000000000ll;   const int inf = 1000000000;   vector<long long> pri, fac;   long long m, x, ans;   void getpri(long long t, vector<long long>& v) {     v.clear();     for (long long i = 2; i * i <= t; ++i) {       if (t % i) continue;       v.push_back(i);       while (t % i == 0) t /= i;     }     if (t != 1) v.push_back(t);     sort(v.begin(), v.end());   }   long long Euler(long long t) {     long long res = t;     for (int i = 0; i < pri.size(); ++i)       if (t % pri[i] == 0) res = res / pri[i] * (pri[i] - 1);     return res;   }   long long mul(long long x, long long y, long long mod) {     long long res = 0;     while (y) {       if (y & 1) (res += x) >= mod && (res -= mod);       (x <<= 1) >= mod && (x -= mod);       y >>= 1ll;     }     return res;   }   long long qpow(long long b, long long p, long long mod) {     long long res = 1ll;     b %= mod;     while (p) {       if (p & 1ll) res = mul(b, res, mod);       b = mul(b, b, mod);       p >>= 1ll;     }     return res;   }   void work(long long md) {     long long f_d = Euler(md);     long long l_d = f_d;     if (l_d > 1) {       for (int j = 0; j < fac.size(); ++j)         while (l_d % fac[j] == 0 && qpow(x, l_d / fac[j], md) == 1) l_d /= fac[j];     }     ans += f_d / l_d;   }   int main() {     scanf( %lld%lld , &m, &x);     getpri(m, pri);     long long eul = Euler(m);     if (eul > 1)       getpri(eul, fac);     else       fac.push_back(1);     for (long long i = 1; i * i <= m; ++i) {       if (m % i) continue;       work(i);       if (i * i != m) work(m / i);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class V>   ostream& operator<<(ostream& s, pair<T, V> a) {     s << a.first <<     << a.second;     return s;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     cin >> T;     for (long long int qq = 1; qq <= T; qq++) {       long long int n;       string a, b;       cin >> n >> a >> b;       vector<long long int> ans;       long long int f = 0, l = n - 1, r = 0;       for (int i = n - 1; i >= 0; i--) {         if (b[i] -  0  != ((a[l] -  0 ) ^ f)) {           if (a[l] != a[r]) a[r] = (a[r] -  0 ) ^ 1 +  0 , ans.push_back(1);           f ^= 1;           ans.push_back(i + 1);           swap(l, r);         }         if (l > r)           l--;         else           l++;       }       cout << ans.size();       for (auto x : ans) cout <<     << x;       cout << endl;     }   }
#include<bits/stdc++.h>   using namespace std;   #define int      long long   #define f(i,n)         for(int i=0;i<(n);++i)   #define fa(i,a,n)      for(int i=a;i<=(n);++i)   #define fd(i,a,n)      for(int i=a;i>=(n);--i)   #define tc       int t;cin>>t;f(testcase,t)   #define ld    long double   #define pii             pair<int,int>   #define mem(a,i)  memset(a,i,sizeof(a))   #define all(x)    x.begin(),x.end()   #define tr(c,i)   for(auto i = c.begin(); i != c.end(); i++)   #define present(c,x)  (c.find(x) != c.end())   #define cpresent(c,x)  (find(allc,x) != c.end())   #define PI 3.1415926535897932   void c_p_c() {    ios_base::sync_with_stdio(false);    cin.tie(0); cout.tie(0);   }      void solve() {    int n;    cin >> n;    int a[n];       map<int, int> m;    f(i, n) {     cin >> a[i];     m[a[i]]++;       }    cout << n - m.begin()->second <<   n ;   }   int32_t main() {       c_p_c();    tc    solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   void c() {     int n;     cin >> n;     vector<long long> a(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i];     vector<long long> pf(n, a[0]);     for (int(i) = (1); (i) < (n); ++(i)) pf[i] = pf[i - 1] ^ a[i];     map<long long, vector<pair<long long, long long>>> mp;   }   void b() {     int n;     cin >> n;     vector<int> a(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i];     int sum = accumulate((a).begin(), (a).end(), 0);     int best = sum;     sort((a).begin(), (a).end());     for (int(r) = (1); (r) < (n); ++(r)) {       sum -= a[r];       sum -= a[0];       for (int d = 1; d * d <= a[r]; d++) {         if (a[r] % d == 0) {           best = min(best, sum + a[r] / d + a[0] * d);           best = min(best, sum + a[r] / (a[r] / d) + a[0] * (a[r] / d));         }       }       sum += a[r];       sum += a[0];     }     cout << best;   }   int main() {     b();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double mar[100000];   int main() {     double ml, rl;     cin >> ml >> rl;     double m = ml, r = rl;     double save = 0;     if (ml >= 3)       save += 2 * m * (m - 3) + 2 * (m - 2) + 6;     else if (ml == 2)       save += 2;     save *= (sqrt(2) - 2);     double ans = m * (m + 1) + m * (m + 1) * (2 * m + 1) / 3 - 2 * (m);     ans += save;     ans *= r;     ans /= (m * m);     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int n, x;     cin >> n;     vector<vector<int>> adj(n);     for (int i = 1; i < n; i++)       cin >> x, x--, adj[x].push_back(i), adj[i].push_back(x);     queue<int> q;     q.push(0);     map<int, int> depth, count;     depth[0] = 0;     count[0]++;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto nxt : adj[cur])         if (depth.find(nxt) == depth.end())           depth[nxt] = depth[cur] + 1, count[depth[nxt]]++, q.push(nxt);     }     int ret = 0;     for (auto it : count) ret += it.second % 2;     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, j, n, k;     while (scanf( %d %d , &n, &k) == 2) {       int f, t, max = -2000000000;       for (i = 0; i < n; i++) {         scanf( %d %d , &f, &t);         if (t > k) {           if ((f - t + k) > max) max = f - t + k;         } else {           if (f > max) max = f;         }       }       printf( %d n , max);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       int n, k, d;       cin >> n >> k >> d;       int mn = n;       int a[n + 10];       for (int j = 1; j <= n; j++) cin >> a[j];       for (int j = 1; j <= n - d + 1; j++) {         set<int> s;         for (int q = j; q <= j + d - 1; q++) s.insert(a[q]);         int z = s.size();         mn = min(mn, z);       }       cout << mn <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, numa, numb, ans;     bool f = 0;     cin >> n >> a >> b;     for (int i = 2, cnt = 1; i <= n; i *= 2) {       numa = a / i;       if (a % i != 0) numa++;       numb = b / i;       if (b % i != 0) numb++;       if (numa == numb) {         if (i == n) f = 1;         ans = cnt;         break;       }       cnt++;     }     if (f == 1)       cout <<  Final!  << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x[100005], y[112345];   set<long long> stx, sty;   int main() {     long long n, m, a, b;     scanf( %lld %lld , &n, &m);     long long total = n * n;     while (m--) {       scanf( %lld %lld , &a, &b);       if (x[a] == 0 && y[b] == 0) {         total = total - 2 * n + stx.size() + sty.size() + 1;       } else if (x[a] && y[b] == 0) {         total = total - n + stx.size();       } else if (y[b] && x[a] == 0)         total = total - n + sty.size();       x[a] = y[b] = 1;       stx.insert(a);       sty.insert(b);       printf( %lld  , total);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   double a[22][22], p[20][(1 << 18) + 10], pc[(1 << 18) + 10],       sm[20][(1 << 18) + 10];   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           scanf( %lf , &a[i][j]);         }       memset(sm, 0, sizeof(sm));       for (int mask = 0; mask < (1 << n); mask++) {         pc[mask] = 0.0;         for (int bit = 0; bit < n; bit++) {           if (mask & (1 << bit)) {             pc[mask]++;             for (int cara = 0; cara < n; cara++) {               sm[cara][mask] += a[bit][cara];             }           }         }       }       for (int niv = 0; niv < n; niv++) {         for (int mask = 0; mask < (1 << n); mask++) {           if (niv == 0) {             if (mask == ((1 << n) - 1)) {               p[niv][mask] = 1.0;             } else {               p[niv][mask] = 0.0;             }           } else {             double sum = 0.0;             for (int bit = 0; bit < n; bit++) {               if ((mask & (1 << bit)) == 0) {                 sum += p[niv - 1][mask | (1 << bit)] * sm[bit][mask];               }             }             p[niv][mask] = 2.0 * sum / (pc[mask] * (pc[mask] + 1));           }         }       }       for (int i = 0; i < n; i++) {         printf( %lf%c , p[n - 1][1 << i],    n [i == (n - 1)]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int main(void) {     int n;     scanf( %d , &n);     int d;     scanf( %d , &d);     int h;     scanf( %d , &h);     if (d > 2 * h || d < h || (n > 2 && (d <= 1)) || (h < 1)) {       cout <<  -1 n ;       return 0;     } else {       int it = 1;       int c = 0;       while (it <= h) {         cout << it <<     << it + 1 << endl;         it++;         c++;       }       if (d != h) {         if (c < n - 1) {           cout << 1 <<     << it + 1 << endl;           c++;           it += 1;           d = d - h - 1;           while (d > 0 && c < n - 1) {             cout << it <<     << it + 1 << endl;             it++;             d--;             c++;           }           while (c < n - 1) {             cout << 1 <<     << it + 1 << endl;             it++;             c++;           }         }       } else {         if (c < n - 1) {           cout << 2 <<     << it + 1 << endl;           c++;           it += 1;           d = d - h - 1;           while (d > 0 && c < n - 1) {             cout << it <<     << it + 1 << endl;             it++;             d--;             c++;           }           while (c < n - 1) {             cout << 2 <<     << it + 1 << endl;             it++;             c++;           }         }       }     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long INF = 1e18;   struct node {     int u, v, w;     node(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}   } a[2 * N];   int fst[N], nxt[2 * N], tot, n, size[N];   bool vis[N];   long long ans, sum[N], ans0, mn;   void build(int x, int y, int z) {     a[tot] = node(x, y, z);     nxt[tot] = fst[x];     fst[x] = tot++;   }   void calc(int x) {     int y;     size[x] = 1;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       calc(y);       size[x] += size[y];       ans += (long long)a[p].w * size[y] * (n - size[y]);     }   }   void dfs1(int x) {     int y;     sum[x] = 0;     size[x] = 1;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       dfs1(y);       sum[x] = (long long)sum[y] + (long long)size[y] * a[p].w;       size[x] += size[y];     }   }   void dfs2(int x, int all) {     int y;     for (int p = fst[x]; ~p; p = nxt[p]) {       if (vis[p / 2]) continue;       vis[p / 2] = 1;       y = a[p].v;       sum[y] = sum[x] - (long long)size[y] * a[p].w +                (long long)(all - size[y]) * a[p].w;       mn = min(mn, sum[y]);       dfs2(y, all);     }   }   long long work(int x, int i) {     for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;     dfs1(x);     for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;     mn = sum[x];     dfs2(x, size[x]);     return (long long)(mn - sum[x]) * (n - size[x]);   }   int main() {     int x, y, z;     scanf( %d , &n);     tot = 0;     memset(fst, -1, sizeof(fst));     for (int i = 0; i < n - 1; i++) {       scanf( %d%d%d , &x, &y, &z);       x--;       y--;       build(x, y, z);       build(y, x, z);     }     ans = 0;     calc(0);     ans0 = ans;     long long tmp;     for (int i = 0; i < n - 1; i++) {       tmp = ans0 + work(a[i * 2].u, i) + work(a[i * 2].v, i);       ans = min(ans, tmp);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class DSU {    public:     vector<long long> p;     DSU() {}     DSU(long long n) {       p.resize(n + 1);       for (long long i = 1; i <= n; i++) p[i] = i;     }     void join(long long a, long long b) { p[find(b)] = find(a); }     long long find(long long a) { return a == p[a] ? a : p[a] = find(p[a]); }     bool check(long long a, long long b) { return find(a) == find(b); }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     DSU d(n);     vector<DSU> D;     for (long long i = 0; i <= m; i++) D.push_back(d);     for (long long i = 0; i < m; i++) {       long long u, v, c;       cin >> u >> v >> c;       D[c].join(u, v);     }     long long q;     cin >> q;     while (q--) {       long long u, v;       cin >> u >> v;       long long ans = 0;       for (long long i = 1; i <= m; i++)         if (D[i].check(u, v)) ans++;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500004;   int a[N], m, k, s, t, n, sz = 0;   map<int, int> mp, mq;   void add(int n, int val) {     if (n == -1) return;     if (val == 1) {       ++mq[n];       if (mq[n] == mp[n]) ++sz;     } else {       if (mq[n] == mp[n]) --sz;       --mq[n];     }   }   int main() {     scanf( %d %d %d %d , &m, &k, &n, &s);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= s; i++) {       scanf( %d , &t);       ++mp[t];     }     for (int i = 1; i <= m; i++)       if (!mp.count(a[i])) a[i] = -1;     bool ok = 0;     vector<int> v;     for (int l = 1, r = 1; l <= m && !ok; l++) {       for (; r <= m && sz < mp.size(); r++) add(a[r], 1);       if (sz >= mp.size()) {         if ((l - 1) / k + (m - r + 1) / k >= n - 1) {           ok = 1;           for (int i = l; i < r; i++) {             if (a[i] != -1 && mp[a[i]] > 0) {               --mp[a[i]];               a[i] = -2;             }           }           for (int i = l; i < r; i++) {             if (a[i] != -2 && (int)v.size() < r - l - k) v.push_back(i);           }           int cnt = (l - 1) % k;           for (int i = 1; i <= cnt; i++) v.push_back(i);         }       }       add(a[l], -1);     }     if (!ok)       puts( -1 );     else {       printf( %d n , v.size());       for (int x : v) printf( %d  , x);     }   }
#include <bits/stdc++.h>   using namespace std;   string s[] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM ,                  SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE };   int main() {     int n;     scanf( %d , &n);     string ss;     int sol = 0;     for (int i = 0; i < n; i++) {       cin >> ss;       if (isalpha(ss[0])) {         for (int j = 0; j < 11; j++)           if (ss == s[j]) {             sol++;             break;           }       } else {         int age = 0;         for (int j = 0; j < ss.length(); j++) {           age *= 10;           age += (ss[j] -  0 );         }         if (age < 18) sol++;       }     }     printf( %d n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int N = 100005;   long long ans;   int n, a[N], pi;   vector<int> G[N];   int s[2], flag, cnt[2];   map<int, int> mp[2];   void upd(int u, int dep) {     if ((dep % 2) != (flag % 2)) {       s[flag ^ 1] ^= a[u];       mp[flag ^ 1][a[u]]++;       ++cnt[flag ^ 1];     } else {       s[flag] ^= a[u];       mp[flag][a[u]]++;       ++cnt[flag];     }   }   void dfs(int u, int fa, int dep) {     if (G[u].size() == 1 && u != 1) {       if ((dep & 1) && flag == 0) flag ^= 1;     }     for (auto to : G[u])       if (to != fa) dfs(to, u, dep + 1);     upd(u, dep);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 2; i <= n; ++i) {       scanf( %d , &pi);       G[pi].push_back(i);       G[i].push_back(pi);     }     dfs(1, 0, 0);     if (s[flag] == 0) {       if (cnt[flag] > 1) ans += 1LL * cnt[flag] * (cnt[flag] - 1) / 2;       if (cnt[flag ^ 1] > 1) ans += 1LL * cnt[flag ^ 1] * (cnt[flag ^ 1] - 1) / 2;       for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) {         int tmp1 = it->first, tmp2 = it->second, tmp3 = mp[flag ^ 1][tmp1];         ans += 1LL * tmp2 * tmp3;       }     } else {       for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) {         int tmp1 = it->first, tmp2 = it->second,             tmp3 = mp[flag ^ 1][s[flag] ^ tmp1];         ans += 1LL * tmp2 * tmp3;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class data {    public:     long long k, b;     bool operator<(const data a) const {       if (k * a.k < 0)         return (b * a.k < a.b * k);       else         return (b * a.k > a.b * k);     }     bool operator==(const data a) const { return b * a.k == a.b * k; }   } d[100010];   long long n, tot = 0;   int main() {     long long x, y, cnt = 0;     scanf( %I64d , &n);     for (long long i = 1; i <= n; ++i) {       ++tot;       scanf( %I64d%I64d , &d[tot].k, &d[tot].b);       if (d[tot].k == 0) {         --tot;         continue;       }     }     n = tot;     sort(d + 1, d + tot + 1);     long long nowk = 0;     for (long long i = 1; i <= n; ++i)       if ((d[i - 1] == d[i]) && (i > 1)) {         nowk += abs(d[i].k);       } else {         if (nowk > 0) cnt++;         nowk = abs(d[i].k);       }     if (nowk) cnt++;     printf( %I64d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 1) {       cout << -1 << endl;     } else {       cout <<  2 1 ;       for (int i = 3; i < n; i += 2) {         cout <<     << i + 1 <<     << i;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   int a[15][200000][15];   int b[15] = {0};   int main() {     a[1][0][0] = 0;     b[1] = 1;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < b[i]; j++) {         int m = 0;         for (int k = 0; k <= i; k++)           if (a[i][j][k] > m) m = a[i][j][k];         m++;         if (j % 2 == 0) {           for (int k = 0; k <= i; k++) a[i + 1][b[i + 1]][k] = a[i][j][k];           a[i + 1][b[i + 1]][i + 1] = 0;           b[i + 1]++;           for (int r = m; r > 0; r--) {             for (int k = 0; k <= i; k++) a[i + 1][b[i + 1]][k] = a[i][j][k];             a[i + 1][b[i + 1]][i + 1] = r;             b[i + 1]++;           }         } else {           for (int r = 1; r <= m; r++) {             for (int k = 0; k <= i; k++) a[i + 1][b[i + 1]][k] = a[i][j][k];             a[i + 1][b[i + 1]][i + 1] = r;             b[i + 1]++;           }           for (int k = 0; k <= i; k++) a[i + 1][b[i + 1]][k] = a[i][j][k];           a[i + 1][b[i + 1]][i + 1] = 0;           b[i + 1]++;         }       }     }     printf( %d n , b[n]);     for (int i = 0; i < b[n]; i++) {       int m = 0;       for (int j = 1; j <= n; j++)         if (a[n][i][j] > m) m = a[n][i][j];       for (int j = 0; j <= m; j++) {         if (j > 0) printf( , );         printf( { );         bool first = true;         for (int k = 1; k <= n; k++)           if (a[n][i][k] == j) {             if (first)               first = false;             else               printf( , );             printf( %d , k);           }         printf( } );       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> name, name2;   const int maxn = 1e3 + 10;   string s[maxn];   int A[maxn];   int main() {     int n;     cin >> n;     int maxx = -999999999;     for (int i = 0; i < n; i++) {       cin >> s[i] >> A[i];       name[s[i]] += A[i];     }     for (int i = 0; i < n; i++) maxx = max(maxx, name[s[i]]);     for (int i = 0; i < n; i++) {       name2[s[i]] += A[i];       if (name2[s[i]] >= maxx && name[s[i]] == maxx) {         cout << s[i];         return 0;       }     }     return 0;   }