malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int N = 1e6 + 10;   using namespace std;   inline int min(int a, int b) { return a < b ? a : b; }   int main() {     int a, b, c;     while (~scanf( %d%d%d , &a, &b, &c)) {       int k = min(min(a / 3, b / 2), c / 2);       a -= 3 * k;       b -= 2 * k;       c -= 2 * k;       if (a == 0 && b == 0 && c == 0) {         printf( %d n , k * 7);       } else {         if (a == 0) {           if (b == 0 || c == 0) {             printf( %d n , k * 7 + 1);           } else {             printf( %d n , k * 7 + 2);           }         } else if (b == 0) {           if (c == 0) {             if (a > 2) {               printf( %d n , k * 7 + 2);             } else {               printf( %d n , k * 7 + 1);             }           } else {             if (c >= 2) {               printf( %d n , k * 7 + 3);             } else {               printf( %d n , k * 7 + 2);             }           }         } else if (c == 0) {           if (a >= 2 && b >= 2) {             printf( %d n , k * 7 + 4);           } else if (b < 2 && a >= 2) {             printf( %d n , k * 7 + 3);           } else if (a < 2) {             printf( %d n , k * 7 + 2);           }         } else {           int kk = min(min(a, b), c), sum = 0;           if (kk == a) {             if (a == 1) {               if (c >= 2) {                 if (b >= 2) {                   b = 2;                 }                 printf( %d n , k * 7 + a + b + 2);               } else {                 printf( %d n , k * 7 + 3);               }             } else {               printf( %d n , k * 7 + 6);             }           } else {             if (b == 1) {               if (c >= 2) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 3);               } else if (c == 1) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 2);               }             } else if (c == 1) {               if (b >= 2) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 3);               } else if (b == 1) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 2);               }             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   bool isV(char x) {     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) {       return 1;     }     return 0;   }   bool isP(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   void fio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void print(long long* a, long long n) {     long long i;     for (i = 0; i < (long long)n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void print2d(long long a[][1000], long long m, long long n) {     long long i, j;     for (i = 0; i < (long long)m; i++) {       for (j = 0; j < (long long)n; j++) {         cout << setw(2) << a[i][j];       }       cout << endl;     }   }   int32_t main() {     fio();     long long n;     cin >> n;     long long* a = new long long[n];     long long i;     for (i = 0; i < (long long)n; i++) {       cin >> a[i];     }     long long* suf = new long long[n];     suf[n - 1] = 0;     stack<long long> s;     for (i = n - 1; i >= (long long)0; i--) {       while (s.size() > 0 && a[i] <= a[s.top()]) s.pop();       if (s.size() != 0) {         suf[i] = suf[s.top()] + (s.top() - i - 1) * a[i] + a[s.top()];       } else {         suf[i] = (n - (i + 1)) * a[i];       }       s.push(i);     }     long long* temp = new long long[n];     long long* pref = new long long[n];     pref[0] = 0;     long long m = 0, mi = -1;     stack<long long> x;     for (i = 0; i < (long long)n; i++) {       while (x.size() > 0 && a[x.top()] > a[i]) x.pop();       if (x.size() == 0)         pref[i] = i * a[i];       else         pref[i] = pref[x.top()] + (i - x.top() - 1) * a[i] + a[x.top()];       x.push(i);       if (m < pref[i] + suf[i] + a[i]) {         m = pref[i] + suf[i] + a[i];         mi = i;       }     }     for (i = mi + 1; i < (long long)n; i++) {       if (a[i] > a[i - 1]) a[i] = a[i - 1];     }     for (i = mi - 1; i >= (long long)0; i--) {       if (a[i] > a[i + 1]) a[i] = a[i + 1];     }     for (i = 0; i < (long long)n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, ans, h[5010], a[5010][5010], b[5010][5010];   int main() {     scanf( %d , &n);     m = (n + 1) / 2;     for (int i = (1); i <= (n); i++) scanf( %d , &h[i]);     for (int i = (0); i <= (n); i++)       for (int j = (0); j <= (m); j++) a[i][j] = b[i][j] = 1000000000;     for (int i = (0); i <= (n); i++) b[i][0] = 0;     for (int i = (2); i <= (n + 1); i++)       for (int j = (1); j <= (m); j++) {         x = ((h[i] - h[i - 1] + 1) > (0) ? (h[i] - h[i - 1] + 1) : (0));         a[i][j] =             x +             ((((h[i - 3] - 1) < (h[i - 2]) ? (h[i - 3] - 1) : (h[i - 2])) -               h[i - 1] + 1) > (0)                  ? (((h[i - 3] - 1) < (h[i - 2]) ? (h[i - 3] - 1) : (h[i - 2])) -                     h[i - 1] + 1)                  : (0)) +             a[i - 2][j - 1];         a[i][j] =             ((a[i][j]) <                      (x +                       ((h[i - 2] - h[i - 1] + 1) > (0) ? (h[i - 2] - h[i - 1] + 1)                                                        : (0)) +                       b[i - 2][j - 1])                  ? (a[i][j])                  : (x +                     ((h[i - 2] - h[i - 1] + 1) > (0) ? (h[i - 2] - h[i - 1] + 1)                                                      : (0)) +                     b[i - 2][j - 1]));         b[i][j] = ((a[i - 1][j]) < (b[i - 1][j]) ? (a[i - 1][j]) : (b[i - 1][j]));       }     for (int i = (1); i <= (m); i++) {       ans = 1000000000;       for (int j = (1); j <= (n + 1); j++)         ans = ((ans) < (((a[j][i]) < (b[j][i]) ? (a[j][i]) : (b[j][i])))                    ? (ans)                    : (((a[j][i]) < (b[j][i]) ? (a[j][i]) : (b[j][i]))));       printf( %d  , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   queue<int> q;   priority_queue<pair<int, int> > Q;   vector<pair<int, int> > V[maxn];   struct edge {     int obj, last;   } e[maxn];   int n, N, m, p, top, cnt, point[maxn], in[maxn], ord[maxn], L[maxn], H[maxn],       ans[maxn];   bool vis[maxn];   void add(int x, int y) {     cnt++;     e[cnt].obj = y;     e[cnt].last = point[x];     point[x] = cnt;   }   void Bye() {     puts( -1 );     exit(0);   }   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       if (x)         L[i] = x, H[i] = x;       else         L[i] = 1, H[i] = p;     }     for (int i = 1, x, y; i <= m; i++) {       scanf( %d%d , &x, &y);       add(x, y);       in[y]++;     }     for (int i = 1; i <= n; i++)       if (!in[i]) q.push(i), ord[++N] = i, vis[i] = true;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = point[u], v; i; i = e[i].last) {         v = e[i].obj;         in[v]--;         if (!in[v]) q.push(v), ord[++N] = v, vis[v] = true;       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) Bye();     for (int i = 1, u; i <= n; i++) {       u = ord[i];       for (int j = point[u], v; j; j = e[j].last) {         v = e[j].obj;         H[v] = min(H[v], H[u] - 1);       }     }     for (int i = n, u; i >= 1; i--) {       u = ord[i];       for (int j = point[u], v; j; j = e[j].last) {         v = e[j].obj;         L[u] = max(L[u], L[v] + 1);       }     }     for (int i = 1; i <= n; i++)       if (L[i] > H[i]) Bye();     for (int i = 1; i <= n; i++) V[H[i]].push_back(pair<int, int>(L[i], i));     top = p;     while (top) {       for (int i = 0, I = V[top].size(); i < I; i++) Q.push(V[top][i]);       if (Q.empty()) Bye();       ans[Q.top().second] = top;       Q.pop();       while (!Q.empty() && Q.top().first == top) {         ans[Q.top().second] = top;         Q.pop();       }       top--;     }     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     printf( %d n , ans[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {0, 0, -1, -1, -1, 1, 1, 1};   const int dy[8] = {-1, 1, -1, 0, 1, -1, 0, 1};   int r, c, n, res, a, b, f[18000005];   bool vis[3001][6001], g[3001][6001];   stack<pair<int, int> > stk;   void init() {     for (int i = 0; i < r * c; ++i) f[i] = i;   }   int F(int x) {     if (f[x] == x) return x;     stk.push(pair<int, int>(x, f[x]));     return f[x] = F(f[x]);   }   void U(int a, int b) {     int fa = F(a), fb = F(b);     stk.push(pair<int, int>(fa, f[fa]));     f[fa] = fb;   }   int main() {     scanf( %d%d%d , &r, &c, &n);     c <<= 1;     init();     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       --a;       --b;       while (!stk.empty()) stk.pop();       vis[a][b] = vis[a][b + c / 2] = true;       for (int i = 0; i < 8; ++i) {         int tx = a + dx[i], ty = b + dy[i];         if (ty == -1) ty = c - 1;         if (ty == c) ty = 0;         if (tx < 0 || tx >= r || !vis[tx][ty]) continue;         U(tx * c + ty, a * c + b);       }       b += c / 2;       for (int i = 0; i < 8; ++i) {         int tx = a + dx[i], ty = b + dy[i];         if (ty == -1) ty = c - 1;         if (ty == c) ty = 0;         if (tx < 0 || tx >= r || !vis[tx][ty]) continue;         U(tx * c + ty, a * c + b);       }       b -= c / 2;       if (F(a * c + b) == F(a * c + b + c / 2)) {         vis[a][b] = vis[a][b + c / 2] = false;         while (!stk.empty()) {           f[stk.top().first] = stk.top().second;           stk.pop();         }       } else {         vis[a][b] = vis[a][b + c / 2] = true;         ++res;       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline bool check_diags(int x0, int y0, int x, int y) {     return abs(x0 - x) == abs(y0 - y);   }   inline bool check_lines(int x0, int y0, int x, int y) {     return x - x0 == 0 || y - y0 == 0;   }   vector<int> a, b, c, d;   int n, x, s, m, k;   void read() {     for (int i = 0; i < m; ++i) {       int t;       scanf(  %d , &t);       a.push_back(t);     }     for (int i = 0; i < m; ++i) {       int t;       scanf(  %d , &t);       b.push_back(t);     }     a.push_back(x);     b.push_back(0);     c.push_back(0);     d.push_back(0);     for (int i = 0; i < k; ++i) {       int t;       scanf(  %d , &t);       c.push_back(t);     }     for (int i = 0; i < k; ++i) {       int t;       scanf(  %d , &t);       d.push_back(t);     }   }   int main() {     scanf( %d %d %d %d %d , &n, &m, &k, &x, &s);     read();     int64_t ans = numeric_limits<int64_t>::max();     for (int i = 0; i < m + 1; ++i) {       int avail = s - b[i];       if (avail < 0) continue;       auto pos = upper_bound(d.begin(), d.end(), avail);       if (pos != d.begin()) {         int j = distance(d.begin(), pos - 1);         int64_t val = ((int64_t)a[i]) * (n - c[j]);         ans = min(ans, val);       }     }     printf( %lld n , ans);     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 3333;   const int mod = 998244353;   long long dp[M][M];   char s[M], t[M];   int main() {     scanf( %s%s , s + 1, t + 1);     int n = strlen(s + 1), m = strlen(t + 1);     for (int i = 1; i <= n + 1; i++) dp[i][i - 1] = 1;     for (int i = 1; i <= n; i++) {       for (int l = 1, r = l + i - 1; r <= n; l++, r++) {         if (l > m || s[i] == t[l]) dp[l][r] += dp[l + 1][r] % mod;         if (r > m || s[i] == t[r]) dp[l][r] += dp[l][r - 1] % mod;       }     }     long long ans = 0;     for (int i = m; i <= n; i++) ans += dp[1][i], ans %= mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   struct Edge {     int to, w;   };   const int N = 3e5 + 5, L = 20;   vector<Edge> v[N];   int a[N], tin[N], tout[N], p[N][L];   long long maxPath[N], maxUpPath[N], sum[N], pt[N], ancw[N];   int timer = 0;   bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   int getBeforeLca(int a, int b) {     if (upper(a, b)) return -1;     for (int i = L - 1; i >= 0; i--) {       if (!upper(p[a][i], b)) a = p[a][i];     }     return a;   }   void dfs(int node, int anc) {     p[node][0] = anc;     for (int i = 1; i < L; i++) {       p[node][i] = p[p[node][i - 1]][i - 1];     }     tin[node] = timer++;     sum[node] = maxPath[node] = a[node];     for (auto e : v[node]) {       if (e.to != anc) {         ancw[e.to] = e.w;         dfs(e.to, node);         maxPath[e.to] = max(0ll, maxPath[e.to] - e.w * 2);         maxPath[node] += maxPath[e.to];         sum[node] += maxPath[e.to];       }     }     tout[node] = timer;   }   void deep(int node, long long x, long long y, int anc) {     maxUpPath[node] = x - y;     x += sum[node];     for (auto e : v[node]) {       if (e.to != anc) {         pt[e.to] = pt[node] - e.w + sum[node] - maxPath[e.to];         long long nx = x - e.w * 2 - maxPath[e.to];         deep(e.to, nx, min(y, nx), node);       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       int a, b, w;       cin >> a >> b >> w;       a--, b--;       v[a].push_back({b, w});       v[b].push_back({a, w});     }     dfs(0, 0);     deep(0, 0, 0, -1);     for (int i = 0; i < q; i++) {       int x, y, xx, yy, lca;       cin >> x >> y;       x--, y--;       xx = getBeforeLca(x, y);       yy = getBeforeLca(y, x);       lca = xx == -1 ? x : p[xx][0];       long long ans = maxUpPath[lca] + sum[lca];       if (x != lca) {         ans += sum[x] - maxPath[xx] + pt[x] - pt[xx] - ancw[xx];       }       if (y != lca) {         ans += sum[y] - maxPath[yy] + pt[y] - pt[yy] - ancw[yy];       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, sum, a, b, c;   int main() {     for (i = 0; i < 4; i++) {       cin >> a;       if (i == 0) {         b = a;         c = a;       }       if (a < b) {         b = a;       }       if (a > c) {         c = a;       }       sum += a;     }     if (sum % 2 == 1) {       cout <<  NO ;     } else if (c + b == sum / 2 || c == sum / 2) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int l;     cin >> l;     string s;     cin >> s;     if (l < 26) {       cout <<  NO n ;       return 0;     }     int f[26] = {};     for (int i = 0; i < l; i++) f[tolower(s[i]) -  a ]++;     for (int i = 0; i < 26; i++)       if (f[i] == 0) {         cout <<  NO n ;         return 0;       }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long sqr(int a) { return a * 1ll * a; }   int main() {     int k;     cin >> k;     int len = k;     int cnt = 0;     int x = 0;     long long res = 0;     while (x <= 2 * k) {       if (!(cnt & 1)) {         int best = 0;         int l = 1, r = k;         while (l <= r) {           int m = (l + r) / 2;           if ((sqr(x + 2) + sqr(m - 1) * 12 <= sqr(k) * 4) &&               (sqr(x + 1) + sqr(2 * m - 1) * 3 <= sqr(k) * 4)) {             best = m;             l = m + 1;           } else             r = m - 1;         }         if (best) {           if (x) res += best * 2 - 1;           res += best * 2 - 1;         }       } else {         int best = 0;         int l = 1, r = k;         while (l <= r) {           int m = (l + r) / 2;           if ((sqr(x + 2) + sqr(2 * m - 1) * 3 <= sqr(k) * 4) &&               (sqr(x + 1) + sqr(m) * 12 <= sqr(k) * 4)) {             best = m;             l = m + 1;           } else             r = m - 1;         }         if (x) res += best * 2;         res += best * 2;       }       x += 3;       cnt++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(string a, string b) { return a.size() < b.size(); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string arr[n];     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n, comp);     string st = arr[0];     vector<string> ans;     set<int> chosen;     chosen.insert(0);     while (ans.size() < n) {       if (ans.size() > 0) {         int mini = INT_MAX;         for (int j = 0; j < n; ++j) {           if (arr[j].find(st) != string::npos) {             if (arr[j].size() < mini && chosen.find(j) == chosen.end()) {               chosen.insert(j);               mini = arr[j].size();               st = arr[j];             }           }         }         if (mini == INT_MAX) {           return cout <<  NO n , 0;         }       }       ans.push_back(st);     }     cout <<  YES  << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] << endl;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct Hash {     const long long int mod = 1791791791;     const long long int base = 255;     vector<long long int> h, p;     Hash(const string& s) {       long long int n = s.size();       h.resize(n + 1);       p.resize(n + 1, 1);       for (long long int i = 1; i <= n; i++) {         h[i] = (h[i - 1] * base + s[i - 1]) % mod;         p[i] = (p[i - 1] * base) % mod;       }     }     long long int getSub(long long int l, long long int r) {       return (h[r] - (h[l - 1] * p[r - l + 1]) % mod + mod) % mod;     }     ~Hash(){};   };   void rev(string& s) {     for (auto& i : s) {       if (i ==  0 )         i =  1 ;       else         i =  0 ;     }   }   signed main() {     string s, t;     cin >> s >> t;     long long int n = t.size();     Hash h(t);     long long int cnt0 = 0, cnt1 = 0;     for (auto i : s) {       cnt0 += (i ==  0 );       cnt1 += (i ==  1 );     }     if (cnt0 < cnt1) {       swap(cnt0, cnt1);       rev(s);     }     long long int ans = 0;     for (long long int len0 = 1; len0 < t.size() / cnt0; len0++) {       if (cnt1 == 0 || (n - len0 * cnt0) % cnt1 == 0) {         long long int len1 = 0;         if (cnt1 > 0) len1 = (n - len0 * cnt0) / cnt1;         long long int last = 1;         unordered_set<long long int> se0, se1;         for (long long int j = 0; j < s.size(); j++) {           if (s[j] ==  0 ) {             se0.insert(h.getSub(last, last + len0 - 1));             last += len0;           } else {             se1.insert(h.getSub(last, last + len1 - 1));             last += len1;           }         }         if (se0.size() <= 1 && se1.size() <= 1) ans++;         if (se0.size() == 1 && se1.size() == 1 &&             (*se1.begin()) == (*se0.begin()))           ans--;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   int n, m, tot, ans;   int mx[maxn], mn[maxn], fir[maxn];   struct edge {     int a, b, l, r;   } p[maxn << 1];   queue<int> q;   vector<int> v[maxn];   inline void add(int a, int b, int c, int d) {     p[++tot].a = a, p[tot].b = b, p[tot].l = c + ((c ^ a) & 1),     p[tot].r = d - ((d ^ b) & 1);   }   bool cmp(const edge &a, const edge &b) { return a.l < b.l; }   inline void solve(int x) {     int a = p[x].a, b = p[x].b, l = p[x].l = max(p[x].l, mn[a]), r = p[x].r;     if (mx[a] < l) {       v[a].push_back(x);       return;     }     q.push(x);     while (!q.empty()) {       x = q.front(), q.pop(), a = p[x].a, b = p[x].b, l = p[x].l, r = p[x].r;       if (l >= r) continue;       if (mx[b] + 2 < l)         mn[b] = l + 1, mx[b] = r;       else         mx[b] = max(mx[b], r);       if ((b >> 1) == n) ans = min(ans, mn[b]);       while (fir[b] < (int)v[b].size()) {         int t = v[b][fir[b]];         if (mx[b] >= p[t].l)           fir[b]++, q.push(t), p[t].l = mn[b];         else           break;       }     }   }   inline int rd() {     int ret = 0, f = 1;     char gc = getchar();     while (gc <  0  || gc >  9 ) {       if (gc ==  - ) f = -f;       gc = getchar();     }     while (gc >=  0  && gc <=  9 ) ret = ret * 10 + (gc ^  0 ), gc = getchar();     return ret * f;   }   int main() {     n = rd(), m = rd();     if (n == 1) {       puts( 0 );       return 0;     }     int i, a, b, c, d;     for (i = 1; i <= m; i++) {       a = rd(), b = rd(), c = rd(), d = rd();       add(a << 1, b << 1 | 1, c, d);       add(a << 1 | 1, b << 1, c, d);       add(b << 1, a << 1 | 1, c, d);       add(b << 1 | 1, a << 1, c, d);     }     sort(p + 1, p + tot + 1, cmp);     memset(mx, 0xc0, sizeof(mx)), memset(mn, 0xc0, sizeof(mn));     mn[2] = mx[2] = 0, ans = 1 << 30;     for (i = 1; i <= tot; i++) solve(i);     if (ans == (1 << 30))       puts( -1 );     else       printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   const int MAX_CITIES = 1e5;   int n, m, c, q;   int dsu[MAX_CITIES + 1] = {0};   std::set<int> adj[MAX_CITIES + 1];   std::map<int, int>* city_rainbows;   int getDsuRoot(int v) {     int root = v;     while (dsu[root] != 0) {       root = dsu[root];     }     while (v != root) {       int p = dsu[v];       dsu[v] = root;       v = p;     }     return root;   }   int mergeDsu(int x, int y) {     int rootx = getDsuRoot(x);     int rooty = getDsuRoot(y);     if (adj[rootx].size() < adj[rooty].size()) std::swap(rootx, rooty);     if (rootx != rooty) {       dsu[rooty] = rootx;       adj[rootx].insert(adj[rooty].begin(), adj[rooty].end());       adj[rooty].clear();     }     return rootx;   }   bool isReachable(int x, int y) {     bool ans = false;     int rootx = getDsuRoot(x), rooty = getDsuRoot(y);     if (rootx == rooty || adj[rootx].find(y) != adj[rootx].end()) ans = true;     return ans;   }   void addEdge(int x, int y, int z) {     std::map<int, int>&r1 = city_rainbows[x], &r2 = city_rainbows[y];     if (r1.find(z) == r1.end()) {       r1.emplace(std::make_pair(z, y));     } else {       mergeDsu(r1[z], y);     }     if (r2.find(z) == r2.end()) {       r2.emplace(std::make_pair(z, x));     } else {       mergeDsu(r2[z], x);     }     int rootx = getDsuRoot(x);     int rooty = getDsuRoot(y);     if (rootx != rooty) {       adj[rootx].insert(y);       adj[rooty].insert(x);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &c, &q);     city_rainbows = new std::map<int, int>[n + 1];     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       addEdge(x, y, z);     }     for (int i = 0; i < q; i++) {       char type;       int x, y, z;       std::cin >> type;       if (type ==  + ) {         scanf( %d%d%d , &x, &y, &z);         addEdge(x, y, z);       } else if (type ==  ? ) {         scanf( %d%d , &x, &y);         if (isReachable(x, y)) {           printf( Yes n );         } else {           printf( No n );         }       }     }     delete[] city_rainbows;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<char, long long> store;   class thisway {    public:     bool operator()(const char& a, const char& b) {       if (store[a] > store[b]) return true;       return false;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     for (long long i = 0; i < n; i++) {       store[s[i]]++;     }     multiset<char, thisway> ss;     for (auto x : store) ss.insert(x.first);     long long sum = 0;     while (!ss.empty() && k > 0) {       long long pp = store[*(ss.begin())];       ss.erase(ss.begin());       long long req = min(k, pp);       sum += req * req;       pp -= req;       k -= req;       if (pp == 0) store.erase(pp);     }     cout << sum <<   n ;     return 0;   }