malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, parent[100002];   long long pl[100002], ans, dp[100002][22][5];   vector<long long> gr[100002];   long long ast[65];   void dfs(long long v) {     for (long long i = 0; i <= 20; i++) {       long long x = ((pl[v] >> i) & 1);       dp[v][i][x]++;     }     long long klir[22][5];     for (long long i = 0; i <= 20; i++) {       klir[i][0] = 0;       klir[i][1] = 0;     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       parent[gr[v][i]] = v;       dfs(gr[v][i]);       for (long long j = 0; j <= 20; j++) {         klir[j][0] += dp[gr[v][i]][j][0];         klir[j][1] += dp[gr[v][i]][j][1];       }     }     for (long long i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == parent[v]) continue;       for (long long j = 0; j <= 20; j++) {         long long x = ((pl[v] >> j) & 1);         dp[v][j][x] += dp[gr[v][i]][j][0];         dp[v][j][x ^ 1] += dp[gr[v][i]][j][1];         klir[j][0] -= dp[gr[v][i]][j][0];         klir[j][1] -= dp[gr[v][i]][j][1];         if (x == 1) {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][0];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][1];         } else {           ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][1];           ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][0];         }       }     }     for (long long i = 0; i <= 20; i++) ans += dp[v][i][1] * (ast[i]);   }   int main() {     cin >> n;     ast[0] = 1;     for (long long i = 1; i < 64; i++) ast[i] = 2 * ast[i - 1];     for (long long i = 1; i <= n; i++) scanf( %lld , &pl[i]);     for (long long i = 1; i < n; i++) {       long long k, l;       scanf( %lld%lld , &k, &l);       gr[k].push_back(l);       gr[l].push_back(k);     }     dfs(1);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 7;   int main() {     string s;     cin >> s;     int ans = 0;     int t = 0;     for (int i = s.length() - 1; i >= 0; i--) {       if (s[i] ==  b )         t = (t + 1) % N;       else {         ans = (ans + t) % N;         t = (t * 2) % N;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read(void) {     int x = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + (c -  0 ), c = getchar();     return x;   }   const int N = 150010, M = 300010;   int n, m, c;   int loc[N], p[N];   struct xint {     double max_left, max_right, sum, res;     xint() {}     xint(double A) : max_left(A), max_right(A), sum(A), res(A) {}     inline void print(void) {       printf( %.2lf %.2lf %.2lf %.2lf n , sum, max_left, max_right, res);       puts(  );     }   } tr[N * 5];   xint update(xint lc, xint rc) {     xint k;     k.sum = lc.sum + rc.sum;     k.max_left = max(lc.max_left, lc.sum + rc.max_left);     k.max_right = max(rc.max_right, lc.max_right + rc.sum);     k.res = max(lc.res, rc.res);     k.res = max(k.res, lc.max_right + rc.max_left);     return k;   }   void build(int k, int l, int r) {     if (l == r) {       double P = (double)p[l] / 100.0;       double tmp = (double)(loc[l + 1] - loc[l]) / 2 - P * c;       tr[k] = xint(tmp);       return;     }     int mid = (l + r) >> 1;     int lc = k << 1, rc = k << 1 | 1;     build(lc, l, mid);     build(rc, mid + 1, r);     tr[k] = update(tr[lc], tr[rc]);   }   xint query(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) return tr[k];     if (l > r) return 0;     int mid = (l + r) >> 1;     int lc = k << 1, rc = k << 1 | 1;     if (y <= mid) return query(lc, l, mid, x, y);     if (x > mid) return query(rc, mid + 1, r, x, y);     xint tmp1 = query(lc, l, mid, x, y);     xint tmp2 = query(rc, mid + 1, r, x, y);     return update(tmp1, tmp2);   }   int main(void) {     n = read(), m = read(), c = read();     for (int i = 1; i <= n; ++i) loc[i] = read();     for (int i = 1; i < n; ++i) p[i] = read();     build(1, 1, n - 1);     double ans = 0;     for (int i = 1; i <= m; ++i) {       int l = read(), r = read();       xint tmp = query(1, 1, n - 1, l, r - 1);       ans += max(tmp.res, 0.0);     }     printf( %.8lf n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   template <typename T, typename U>   static void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static void amax(T &x, U y) {     if (x < y) x = y;   }   inline uint32_t ifzero(int num) { return (num - 1) >> 31; }   inline int ifnotzero(int num) { return ~((num - 1) >> 31); }   int main() {     int Q;     while (~scanf( %d , &Q)) {       vector<uint32_t> pos(100000), neg(100000);       for (int ii = 0; ii < Q; ++ii) {         int ty;         scanf( %d , &ty);         if (ty == 1) {           int L;           int R;           int k;           scanf( %d%d%d , &L, &R, &k), --L, --R;           uint32_t *data = k > 0 ? pos.data() : neg.data();           uint32_t b = abs(k) - 1;           for (int(x) = (int)(L); (x) < (int)(R); ++(x)) {             auto a = data[x] - 1;             data[x] = (a < b ? a : b) + 1;           }         } else if (ty == 2) {           int L;           int R;           scanf( %d%d , &L, &R), --L, --R;           long long ans = 0;           for (int(x) = (int)(L); (x) < (int)(R); ++(x)) {             ans += (pos[x] + neg[x]) & ifnotzero(pos[x]) & ifnotzero(neg[x]);           }           printf( %lld n , ans);         } else           abort();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<pair<int, int> > V;   int main(int argc, const char *argv[]) {     cin >> N >> M;     for (int i = 0, x, y; i < M; i++) {       cin >> x >> y;       V.push_back(pair<int, int>(x, y));     }     sort(V.begin(), V.end());     vector<pair<int, int> > currI;     currI.push_back(pair<int, int>(1, 1));     int currRow = 0;     for (int i = 0; i < V.size();) {       pair<int, int> p = V[i];       vector<pair<int, int> > newI;       if (p.first > currRow + 1 && currI.size()) {         int left = currI[0].first;         currI.clear();         currI.push_back(pair<int, int>(left, N));       }       currRow = p.first;       vector<pair<int, int> > temp;       int last = 0;       while (i < V.size() && V[i].first == p.first) {         temp.push_back(pair<int, int>(last + 1, V[i].second - 1));         last = V[i].second;         i++;       }       temp.push_back(pair<int, int>(last + 1, N));       int j = 0;       for (auto x : temp) {         while (j < currI.size() && currI[j].second < x.first) j++;         if (j < currI.size()) {           int x1 = max(x.first, currI[j].first), x2 = x.second;           if (x2 >= x1) {             newI.push_back(pair<int, int>(x1, x2));           }         }       }       currI = newI;     }     bool poss = false;     if (currI.size() > 0) {       pair<int, int> l = currI[currI.size() - 1];       poss = (currRow < N && l.second <= N);       poss = poss || (currRow == N && l.second == N);     }     if (poss) {       cout << 2 * (N - 1) << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = n - 1; i >= 0; i--) cout << a[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000];     cin >> a;     int n = strlen(a), i, up = 1;     for (i = 1; i < n; i++)       if (a[i] >=  a  && a[i] <=  z ) up = 0;     if (up) {       for (i = 1; i < n; i++) a[i] = a[i] +  a  -  A ;       if (a[0] >=  A  && a[0] <=  Z )         a[0] = a[0] +  a  -  A ;       else         a[0] = a[0] +  A  -  a ;     }     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 102400;   long long n, ans, c00, c01, c10, c11;   string a, b;   int main() {     cin >> n >> a >> b;     for (int i = 0; i < n; i++) {       if (a[i] ==  0  && b[i] ==  0 )         c00++;       else if (a[i] ==  0  && b[i] ==  1 )         c01++;       else if (a[i] ==  1  && b[i] ==  0 )         c10++;       else if (a[i] ==  1  && b[i] ==  1 )         c11++;     }     for (int i = 0; i < n; i++) {       if (a[i] ==  0  && b[i] ==  0 )         ans += (c10 + c11);       else if (a[i] ==  0  && b[i] ==  1 )         ans += c10;       else if (a[i] ==  1  && b[i] ==  0 )         ans += (c00 + c01);       else if (a[i] ==  1  && b[i] ==  1 )         ans += c00;     }     cout << ans / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   char s[5010];   int mat[5010][5010];   int dp[5010][5010];   int n;   void findAllPalindromes() {     for (int i = 0; i < n; i++) {       for (int j = 0; i - j >= 0 && i + j < n; j++) {         if (s[i - j] == s[i + j])           mat[i - j][i + j] = 1;         else           break;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; i - j >= 0 && i + j + 1 < n; j++) {         if (s[i - j] == s[i + j + 1])           mat[i - j][i + j + 1] = 1;         else           break;       }     }   }   void filldp() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         dp[i][j] =             dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mat[i - 1][j - 1];       }   }   inline int sum(int l, int r) {     int ans = dp[n][r];     if (l > 0) ans -= dp[l - 1][r];     return ans;   }   int main() {     scanf(  %s , s);     n = strlen(s);     findAllPalindromes();     filldp();     int q;     scanf(  %d , &q);     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       printf( %d n , sum(l, r));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int id, v;   } tree[4 * 100005];   int in[100005];   void build(int nod, int s, int e) {     if (s == e) {       tree[nod].id = s;       tree[nod].v = in[s];       return;     }     int mid = (s + e) / 2, l = 2 * nod, r = l + 1;     build(l, s, mid);     build(r, mid + 1, e);     if (tree[l].v > tree[r].v) {       tree[nod].v = tree[l].v;       tree[nod].id = tree[l].id;     } else {       tree[nod].v = tree[r].v;       tree[nod].id = tree[r].id;     }   }   pair<int, int> query(int nod, int s, int e, int i, int j) {     if (s > j || e < i) return {-1, -1};     if (s >= i && e <= j) return {tree[nod].v, tree[nod].id};     int mid = (s + e) / 2, l = 2 * nod, r = l + 1;     pair<int, int> a = query(l, s, mid, i, j);     pair<int, int> b = query(r, mid + 1, e, i, j);     if (a.first > b.first)       return a;     else       return b;   }   long long save[100005];   long long ans[100005];   int main() {     int n, i;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d , &in[i]);     }     build(1, 1, n);     save[n - 1] = 1;     ans[n - 1] = 1;     pair<int, int> a = query(1, 1, n, 6, 8);     for (i = n - 2; i >= 1; i--) {       pair<int, int> pp = query(1, 1, n, i + 1, in[i]);       save[i] = pp.second - i + save[pp.second] + n - in[i];       ans[i] = ans[i + 1] + save[i];     }     printf( %I64d n , ans[1]);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, const T &b) {     if (b > a) a = b;   }   const int maxn = 1e3 + 10;   const int inf = 1e9 + 10;   const long long mod = 1e9 + 7;   int dp[maxn][maxn][4], g[maxn];   int n, k;   long long fac[maxn], c[maxn][maxn];   int main() {     scanf( %d%d , &n, &k);     dp[0][0][2] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j <= n; j++)         for (int mask = 0; mask < 4; mask++) {           if (dp[i][j][mask] == 0) continue;           int mask2 = (mask & 1) << 1;           dp[i + 1][j][mask2] += dp[i][j][mask];           dp[i + 1][j][mask2] %= mod;           if (!((mask >> 1) & 1))             dp[i + 1][j + 1][mask2] += dp[i][j][mask],                 dp[i + 1][j + 1][mask2] %= mod;           if (i == n - 1) continue;           mask2 |= 1;           dp[i + 1][j + 1][mask2] += dp[i][j][mask];           dp[i + 1][j + 1][mask2] %= mod;         }     fac[0] = 1;     for (long long i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;     for (int i = k; i <= n; i++) {       long long now = 0;       for (int mask = 0; mask < 4; mask++) now += dp[n][i][mask], now %= mod;       g[i] = now * fac[n - i] % mod;     }     c[0][0] = 1;     for (int i = 1; i < maxn; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;     }     long long ans = 0;     for (int i = k; i <= n; i++) {       if ((i - k) & 1)         ans -= c[i][k] * g[i] % mod, ans += mod;       else         ans += c[i][k] * g[i] % mod;       ans %= mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   template <class T>   bool get_max(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   bool get_min(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   const int maxn = 1000000 + 5;   int n, m, r1, r2, sv[maxn];   void output() {     for (int i = n; i >= 0; i--) {       for (int j = 0; j < sv[i]; j++) {         printf( 7 );       }       if (i) printf( 4 );     }     printf(  n );   }   int main() {     scanf( %d%d%d%d , &n, &m, &r1, &r2);     memset(sv, 0, sizeof(sv));     for (int i = 1; i < n; i++) {       if (r1 && r2) {         if (!m) {           printf( -1 n );           return 0;         } else {           r1--;           r2--;           sv[i]++;           m--;         }       }     }     if (r1) {       if (!m) {         printf( -1 n );         return 0;       } else {         r1--;         sv[0]++;         m--;       }     }     if (r2) {       if (!m) {         printf( -1 n );         return 0;       } else {         r2--;         sv[n]++;         m--;       }     }     if (r1 + r2 != 0) {       printf( -1 n );       return 0;     }     if (sv[0]) {       sv[0] += m;     } else {       sv[1] += m;     }     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn], b[maxn];   int main() {     int n, m;     cin >> n >> m;     int t;     long long sum_n = 0, sum_m = 0;     long long cnt_n = 0, cnt_m = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       cin >> b[i];     }     sum_n = accumulate(a, a + n, 0LL);     sum_m = accumulate(b, b + m, 0LL);     sort(a, a + n);     sort(b, b + m);     for (int i = 0; i < n; i++) {       if (a[i] < sum_m && i < n - 1) {         cnt_n += a[i];       } else {         cnt_n += sum_m;       }     }     for (int i = 0; i < m; i++) {       if (b[i] < sum_n && i < m - 1) {         cnt_m += b[i];       } else {         cnt_m += sum_n;       }     }     printf( %lld n , min(cnt_n, cnt_m));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int a[455];   int b[455];   vector<int> G[455];   int boss[455];   void init() {     for (int i = 1; i < 455; i++) boss[i] = i;   }   int find_boss(int x) {     return boss[x] = (boss[x] == x ? x : find_boss(boss[x]));   }   bool unite(int x, int y) {     int bx = find_boss(x);     int by = find_boss(y);     if (bx == by) return false;     boss[bx] = by;     return true;   }   vector<pair<pair<int, int>, int> > res;   int pour(int from, int to, int d) {     int flow = min(d, max(a[to] - b[to], 0));     a[to] -= flow;     int pos = ((int)(res).size());     for (int i = 0; flow < d && i < ((int)(G[to]).size()); i++) {       int v = G[to][i];       if (v == from) continue;       flow += pour(to, v, d - flow);     }     if (from != -1) {       int po = min(a[to], flow);       if (po > 0)         res.insert(res.begin() + pos, make_pair(make_pair(to, from), po));       if (po < flow) res.push_back(make_pair(make_pair(to, from), flow - po));     }     return flow;   }   int main() {     int n, v, e;     scanf( %d %d %d , &n, &v, &e);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     init();     while (e--) {       int x, y;       scanf( %d %d , &x, &y);       if (unite(x, y)) {         G[x].push_back(y);         G[y].push_back(x);       }     }     for (int i = 1; i <= n; i++)       if (a[i] < b[i]) a[i] += pour(-1, i, b[i] - a[i]);     for (int i = 1; i <= n; i++)       if (a[i] != b[i]) return puts( NO ), 0;     printf( %d n , ((int)(res).size()));     for (__typeof((res).begin()) itr = (res).begin(); itr != (res).end(); itr++)       printf( %d %d %d n , itr->first.first, itr->first.second, itr->second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double t0;   double error(long long t1, long long t2, long long x1, long long x2) {     double c = (t1 * x1 + t2 * x2) / double(x1 + x2);     if (c >= t0) return c - t0;     return 1e9;   }   int main() {     long long t1, t2, x1, x2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     double ER = 1e8;     long long a1 = -1, a2 = -1;     for (int y1 = 0; y1 <= x1; y1++) {       long long mi = (t0 != t2) ? (t1 * y1 - t0 * y1) / (t0 - t2) : 1000000000;       for (long long y2 = min(max(mi - 10, 0LL), x2);            y2 <= max(min(mi + 10, x2), 0LL); ++y2) {         if (y1 == 0 && y2 == 0) continue;         double calc = error(t1, t2, y1, y2);         if (ER > calc) {           ER = calc;           a1 = y1;           a2 = y2;         } else if (ER == calc) {           if (a1 + a2 < y1 + y2) a1 = y1, a2 = y2;         }       }     }     cout << a1 <<     << a2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll A[19], cnt, dp[19][4][3][2][2][504][2];   const int p3[]{1, 3, 9};   ll dfs(int pos, int level2, int level3, int level5, int level7, int sum,          bool limit) {     ll ans = 0;     if (dp[pos][level2][level3][level5][level7][sum][limit] != -1)       return dp[pos][level2][level3][level5][level7][sum][limit];     for (int v = 0; v <= (limit ? A[pos] : 9); ++v) {       int l2 = level2, l3 = level3, l5 = level5, l7 = level7;       int cur = (sum * 10 + v) % 504;       if (v == 2) l2 = max(l2, 1);       if (v == 3) l3 = max(l3, 1);       if (v == 4) l2 = max(l2, 2);       if (v == 5) l5 = 1;       if (v == 6) l2 = max(l2, 1), l3 = max(l3, 1);       if (v == 7) l7 = 1;       if (v == 8) l2 = 3;       if (v == 9) l3 = 2;       if (pos == cnt - 1)         ans += cur % (1 << l2) == 0 && cur % p3[l3] == 0 &&                cur % (l7 ? 7 : 1) == 0 && (!l5 || v == 5 || v == 0);       else         ans += dfs(pos + 1, l2, l3, l5, l7, cur, limit && v == A[pos]);     }     if (!limit) dp[pos][level2][level3][level5][level7][sum][limit] = ans;     return ans;   }   ll f(ll x) {     if (x == 0) return 1;     cnt = 0;     while (x) A[cnt++] = x % 10, x /= 10;     reverse(A, A + cnt);     memset(dp, -1, sizeof(dp));     return dfs(0, 0, 0, 0, 0, 0, true);   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       ll x, y;       cin >> x >> y;       ll l = f(x - 1), r = f(y);       cout << r - l <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1100;   char str[N];   int G[N][N];   int sum_r[N], sum_c[N];   int n, m;   bool vis[N][N];   bool no() {     int r0 = n, c0 = m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sum_r[i] += G[i][j];       }       if (sum_r[i]) r0--;     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         sum_c[j] += G[i][j];       }       if (sum_c[j]) c0--;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j]) {           int k = j;           while (k <= m && G[i][k]) k++;           if (k - j != sum_r[i]) return true;           break;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         if (G[i][j]) {           int k = i;           while (k <= n && G[k][j]) k++;           if (k - i != sum_c[j]) return true;           break;         }       }     }     for (int i = 1; i <= n; i++) {       if (sum_r[i] == 0) {         if (c0 == 0) return true;       }     }     for (int j = 1; j <= m; j++) {       if (sum_c[j] == 0) {         if (r0 == 0) return true;       }     }     return false;   }   vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   void dfs(int x, int y) {     vis[x][y] = 1;     for (auto [dx, dy] : dir) {       int nx = x + dx, ny = y + dy;       if (vis[nx][ny]) continue;       if (G[nx][ny] && 0 < nx && nx <= n && 0 < ny && ny <= m) dfs(nx, ny);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str + 1);       for (int j = 1; j <= m; j++) {         G[i][j] = str[j] ==  #  ? 1 : 0;       }     }     if (no()) {       puts( -1 );       return 0;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j] && !vis[i][j]) {           dfs(i, j);           ans++;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     stack<int> q;     string str;     cin >> str;     int open = 0, count = 0, rcount = 0;     for (int i = 0; i < str.length(); ++i) {       if (str[i] ==  ( )         open++;       else if (str[i] ==  ) ) {         if (open != 0)           open--;         else           count--;       }       if (str[i] ==  # ) {         count += open - 1;         open = 0;         rcount++;       }       if (count < 0) {         cout << -1;         return 0;       }     }     if (open > 0) {       cout << -1;       return 0;     }     for (int i = 0; i < rcount - 1; i++) cout <<  1  ;     cout << count + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = int(2.1e5);   vector<pair<int, int>> g[N];   int n, q;   ll res = 0;   class dsu {    public:     using T = int;     vector<int> p;     vector<ll> sz;     int n;     dsu(int _n) : n(_n) {       p.resize(n);       sz.resize(n);       iota(p.begin(), p.end(), 0);       fill(sz.begin(), sz.end(), 1);     }     inline T get(T x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }     inline bool unite(T x, T y) {       T px = get(x);       T py = get(y);       if (px != py) {         if (sz[px] < sz[py]) {           swap(px, py);         }         p[py] = px;         res -= (sz[px] * (sz[px] - 1)) / 2;         res -= (sz[py] * (sz[py] - 1)) / 2;         sz[px] += sz[py];         res += (sz[px] * (sz[px] - 1)) / 2;         return true;       }       return false;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> q;     vector<pair<int, pair<int, int>>> ed(n - 1);     for (int i = 0; i < n - 1; ++i) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       ed[i] = {w, {u, v}};     }     sort(ed.begin(), ed.end());     vector<pair<int, int>> qr(q);     for (int i = 0; i < q; ++i) {       int x;       cin >> x;       qr[i] = {x, i};     }     sort(qr.begin(), qr.end());     vector<ll> ans(q);     int j = 0;     dsu d(n + 1);     for (int i = 0; i < q; ++i) {       while (j < n - 1 && ed[j].first <= qr[i].first) {         d.unite(ed[j].second.first, ed[j].second.second);         j++;       }       ans[qr[i].second] = res;     }     for (ll x : ans) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     k = min(k, 26);     string s =  ab ;     for (int i = 0; i < k - 2; i++) {       s += char(99 + i);     }     string s1 =   ;     for (int i = 0; i < n / k; i++) {       s1 += s;     }     for (int i = 0; i < n % k; i++) {       s1 = s1 + s[i];     }     cout << s1 << endl;     return 0;   }