malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using ll = long long;   void solve() {     string s;     cin >> s;     int m = ((int)(s).size());     vi a(m);     a[0] = ((s[0] ==  - ) ? -1 : 1);     for (__typeof(m) i = (1) - ((1) > (m)); i != (m) - ((1) > (m));          i += 1 - 2 * ((1) > (m))) {       if (s[i] ==  - ) {         a[i] = a[i - 1] - 1;       } else {         a[i] = a[i - 1] + 1;       }     }     ll res = m;     int i = 0, t = -1;     while (i < m) {       if (a[i] != t) {         i++;       } else {         t--;         res += (i + 1);       }     }     cout << res <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 100010;   int N;   int A[MAXN];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> N;     for (int i = 0; i < N; i++) {       cin >> A[i];     }     ll ans = 0;     for (int i = 0; i < N; i++) {       ans += ll(A[i]) * (N + 1 - A[i]);     }     for (int i = 0; i < N - 1; i++) {       ans -= ll(min(A[i], A[i + 1])) * (N + 1 - max(A[i], A[i + 1]));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[101];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, cnt = 0;       scanf( %d , &n);       for (int i = 1; i <= n; i *= 2) {         ans[++cnt] = i;         n -= i;       }       if (n > 0) {         ans[++cnt] = n;         sort(ans + 1, ans + cnt + 1);       }       printf( %d n , cnt - 1);       for (int i = 2; i <= cnt; i++) printf( %d  , ans[i] - ans[i - 1]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ans = 0, fh = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + ch -  0 , ch = getchar();     return ans * fh;   }   const int maxn = 2e5 + 100;   const long long inf = 1e18;   int n, m, head[maxn], nex[maxn], v[maxn], num = 1;   long long p[maxn << 2], la[maxn << 2];   long long a[maxn], b[maxn], w[maxn];   inline void updata(int o) { p[o] = min(p[o << 1], p[o << 1 | 1]); }   inline void pushdown(int o) {     if (!la[o]) return;     p[o << 1] += la[o], p[o << 1 | 1] += la[o];     la[o << 1] += la[o], la[o << 1 | 1] += la[o];     la[o] = 0;   }   void revise(int o, int l, int r, int ql, int qr, long long qz) {     if (ql == l && qr == r) {       p[o] += qz, la[o] += qz;       return;     }     int mid = l + r >> 1;     pushdown(o);     if (ql <= mid) revise(o << 1, l, mid, ql, min(qr, mid), qz);     if (qr > mid) revise(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr, qz);     updata(o);   }   long long query(int o, int l, int r, int ql, int qr) {     if (ql == l && qr == r) return p[o];     int mid = l + r >> 1;     pushdown(o);     long long ans = inf;     if (ql <= mid) ans = query(o << 1, l, mid, ql, min(qr, mid));     if (qr > mid)       ans = min(ans, query(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr));     return ans;   }   void build(int o, int l, int r) {     la[o] = 0;     if (l == r) {       p[o] = b[l];       return;     }     int mid = l + r >> 1;     build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);     updata(o);   }   inline void add(int x, int y, long long z) {     v[++num] = y;     w[num] = z;     nex[num] = head[x];     head[x] = num;   }   int main() {     n = read(), m = read();     int T = read();     for (int i = 1; i < n; i++) a[i] = read(), b[i] = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       add(x, y, read());     }     build(1, 0, n - 1);     for (int x = 1; x <= n; x++) {       for (int i = head[x]; i; i = nex[i]) revise(1, 0, n - 1, 0, v[i] - 1, w[i]);       b[x] = a[x] + p[1];     }     build(1, 1, n);     printf( %I64d n , p[1]);     while (T--) {       int x = read(), y = read();       revise(1, 1, n, x, x, y - a[x]), a[x] = y;       printf( %I64d n , p[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int num = pow(10, 9) + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int c[n];     for (int i = 0; i < n; ++i) {       cin >> c[i];     }     long long int max_diff = -1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; j++) {         if (abs(c[i] - c[j]) > max_diff) max_diff = abs(c[i] - c[j]);       }     }     if (max_diff > k) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       for (int i = 0; i < n; ++i) {         for (int j = 1; j <= c[i]; j++) {           if (j % k == 0)             cout << k <<    ;           else             cout << j % k <<    ;         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 100;   vector<int> g[N];   vector<pair<int, int> > G[N];   map<int, long long> vToMinCost[N];   multiset<long long> costs[N];   long long addToAll[N];   int ansAt[N];   void upd(int id, int v, long long x) {     x -= addToAll[id];     if (vToMinCost[id].count(v) == 0 || vToMinCost[id][v] > x) {       if (vToMinCost[id].count(v) != 0)         costs[id].erase(costs[id].find(vToMinCost[id][v]));       vToMinCost[id][v] = x;       costs[id].insert(x);     }   }   void del(int id, int v) {     if (vToMinCost[id].count(v)) {       costs[id].erase(costs[id].find(vToMinCost[id][v]));       vToMinCost[id].erase(v);     }   }   void solve(int v, int par) {     ansAt[v] = v;     for (auto p : G[v]) upd(v, p.first, p.second);     for (int to : g[v]) {       if (to == par) continue;       solve(to, v);       int a = ansAt[v], b = ansAt[to];       if (vToMinCost[a].size() < vToMinCost[b].size()) swap(a, b);       del(a, to);       del(b, to);       if (vToMinCost[a].empty() || vToMinCost[b].empty()) {         printf( -1 n );         exit(0);       }       long long mn = *costs[b].begin() + addToAll[b];       long long mna = *costs[a].begin() + addToAll[a];       addToAll[a] += mn;       addToAll[b] += mna;       for (auto p : vToMinCost[b]) upd(a, p.first, p.second + addToAll[b]);       ansAt[v] = a;     }   }   int main(int, char **) {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++) G[i].push_back(make_pair(i, 0));     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       G[a].push_back(make_pair(b, c));     }     solve(0, -1);     int id = ansAt[0];     long long ans = *costs[id].begin() + addToAll[id];     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, qu, f[100005], v[100005 + 100005], o[100005 + 100005], p, s[100005],       r, fr[100005], to[100005], si[100005], curm, grp[100005], gr, rt[100005];   bool u[100005], vis[100005];   vector<int> b[100005], c[100005], q[100005], ans[100005];   void bd(int a, int b) {     v[++p] = b;     o[p] = f[a];     f[a] = p;   }   void merge(vector<int> &a, vector<int> b) {     vector<int> c;     int l = 0, r = 0;     while (l < a.size() || r < b.size()) {       if (l == a.size())         c.push_back(b[r++]);       else if (r == b.size())         c.push_back(a[l++]);       else if (a[l] < b[r])         c.push_back(a[l++]);       else         c.push_back(b[r++]);     }     a = c;     if (a.size() > 11) a.resize(11);   }   void size(int x, int y) {     s[x] = vis[x] = 1;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) {         size(v[i], x);         s[x] += s[v[i]];       }   }   void pick(int x, int y, int z) {     int m = s[z] - s[x];     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) {         pick(v[i], x, z);         m = max(m, s[v[i]]);       }     if (m < curm) {       curm = m;       r = x;     }   }   void group(int x, int y, int z) {     grp[x] = z;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) group(v[i], x, z);   }   void dfs(int x, int y) {     c[x] = c[y];     merge(c[x], b[x]);     for (int i = (0); i < (q[x].size()); i++) {       int d = q[x][i];       if (vis[fr[d]] && vis[to[d]] && grp[fr[d]] != grp[to[d]]) {         merge(ans[d], c[x]);         rt[d] = r;       }     }     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) dfs(v[i], x);   }   void reset(int x, int y) {     vis[x] = 0;     for (int i = (f[x]); i; i = o[i])       if (v[i] != y && !u[v[i]]) reset(v[i], x);   }   void root(int x) {     size(x, 0);     curm = 100005;     pick(x, 0, x);     grp[r] = 0;     gr = 1;     u[r] = 1;     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) group(v[i], r, gr++);     for (int i = (0); i < (q[r].size()); i++) {       int d = q[r][i];       if (vis[fr[d]] && vis[to[d]]) rt[d] = r;     }     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) dfs(v[i], 0);     reset(r, 0);     for (int i = (f[r]); i; i = o[i])       if (!u[v[i]]) root(v[i]);   }   int main() {     scanf( %d %d %d , &n, &m, &qu);     for (int i = (1); i < (n); i++) {       int a, b;       scanf( %d %d , &a, &b);       bd(a, b);       bd(b, a);     }     for (int i = (1); i <= (m); i++) {       int t;       scanf( %d , &t);       b[t].push_back(i);     }     for (int i = (1); i <= (n); i++)       if (b[i].size() > 11) b[i].resize(11);     for (int i = (1); i <= (qu); i++) {       scanf( %d %d %d , &fr[i], &to[i], &si[i]);       q[fr[i]].push_back(i);       q[to[i]].push_back(i);     }     root(1);     for (int i = (1); i <= (qu); i++) {       merge(ans[i], b[rt[i]]);       if (ans[i].size() > si[i]) ans[i].resize(si[i]);       printf( %d , ans[i].size());       for (int j = (0); j < (ans[i].size()); j++) printf(  %d , ans[i][j]);       puts(  );     }     scanf(  n );   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, l, r, s, t;   long long modpow(long long x, long long y) {     if (y == 0) return 1 % 1000000009;     long long u = modpow(x, y / 2);     u = u * u % 1000000009;     if (y % 2) u = u * x % 1000000009;     return u;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     l = (n / k) * (k - 1) + n % k;     r = m - l;     if (r <= 0) {       cout << m << endl;       return 0;     }     s = m - r * (k);     if (s <= 0) s = 0;     t = modpow(2, r + 1);     t = (t + 1000000009 - 2) % 1000000009;     t = t * k % 1000000009;     s = s + t;     cout << s % 1000000009 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool is_prime(long long n) {     if (n == 2) return true;     if (n < 2) return false;     for (long long i = 3; i * i <= n; ++i)       if (!(n % i)) return false;     return true;   }   vector<long long> divison(long long n) {     vector<long long> v;     for (long long i = 1; i * i <= n; ++i)       if (!(n % i)) v.push_back(i), v.push_back(n / i);     return v;   }   void printnumberinbinary(unsigned long long t) {     if (!t) return;     printnumberinbinary(t >> 1);     cout << (t & 1);   }   int numberofdiv(int t) {     int ans = 0, x;     for (x = 1; x * x < t; x++) {       if (!(t % x)) ans += 2;     }     if (x * x == t) ans++;     return ans;   }   vector<set<int>> adj(1e5 + 1);   vector<bool> vis(1e5 + 1);   void dfs(int t) {     cout << t <<    ;     vis[t] = true;     for (auto f : adj[t])       if (!vis[f]) dfs(f);   }   int main() {     int t;     cin >> t;     while (t--) {       int a, y = 0;       cin >> a;       vector<int> v(a + 1, 0);       for (int x = 0; x < a; x++) {         int s;         cin >> s;         int flag = 0;         while (s--) {           int y;           cin >> y;           if (!v[y] && !flag) {             v[y]++;             flag++;           }         }         if (!flag) y = x + 1;       }       if (!y)         cout <<  OPTIMAL ;       else {         cout <<  IMPROVE n ;         for (int x = 1; x < v.size(); x++) {           if (!v[x]) {             cout << y <<     << x;             break;           }         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   bool w, w1;   int main() {     srand(time(NULL));     int n, m, mn, mx;     cin >> n >> m >> mn >> mx;     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       if (mn > x || mx < x) cout <<  Incorrect , exit(0);       if (x == mn) w = true;       if (x == mx) w1 = true;     }     if (w && w1) cout <<  Correct , exit(0);     if (w || w1)       if (n - m > 0)         cout <<  Correct , exit(0);       else         cout <<  Incorrect , exit(0);     if (n - m > 1)       cout <<  Correct , exit(0);     else       cout <<  Incorrect , exit(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   int n, a[N][N];   char s[N];   bool vis[N];   void dfs(int x, int fa) {     vis[x] = 1;     for (int i = 1; i <= n; i++) {       if (!a[x][i] || i == fa || i == x) continue;       if (a[i][fa]) printf( %d %d %d n , x, i, fa), exit(0);       if (!vis[i]) dfs(i, x);     }   }   signed main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n; j++) a[i][j] = s[j] -  0 ;     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     if (arr[n - 1] < arr[n - 2] + arr[n - 3]) {       cout <<  YES  << endl;       for (int i = 0; i < n - 2; i++) {         cout << arr[i] <<    ;       }       cout << arr[n - 1] <<     << arr[n - 2];     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   int main() {     int n, m;     int r = 0, a = 0, v = 0;     double es = 0.0;     scanf( %d%d , &n, &m);     r = 2 * n;     v = 5 * n;     a = 8 * n;     es = (double)r / m;     r = r / m;     if (es - r != 0.00) {       r++;     }     es = (double)v / m;     v = v / m;     if (es - v != 0.00) {       v++;     }     es = (double)a / m;     a = a / m;     if (es - a != 0.00) {       a++;     }     printf( %d , a + v + r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int c[n];     for (int i = 0; i < n; i++) c[i] = a[i];     int b[n];     b[0] = a[0];     for (int i = 0; i < n - 1; i++) {       if (a[i] + a[i + 1] >= k)         b[i + 1] = a[i + 1];       else {         b[i + 1] = k - a[i];         a[i + 1] = b[i + 1];       }     }     int sum = 0;     for (int i = 0; i < n; i++) {       sum = sum + b[i] - c[i];     }     cout << sum << endl;     for (int i = 0; i < n; i++) cout << b[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9;   int n, a[N6], ans;   bool ok;   int main() {     ios_base ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       if (!a[i]) {         int cnt = 0;         while (!a[i] && i <= n) {           ++i;           ++cnt;         }         if ((cnt == 1 && !ok) || (cnt > 1) || (i > n && cnt == 1)) ans += cnt;       }       if (a[i]) ok = 1;     }     cout << abs(n - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       int k;       cin >> n >> k;       int octr = 0;       int a[n];       int sum = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] % 2 != 0) octr++;         sum = sum + a[i];       }       if (octr >= k) {         if ((sum % 2 != 0 && k % 2 != 0) || (sum % 2 == 0 && k % 2 == 0)) {           cout <<  YES  << endl;           int f = 0;           while (k > 1) {             if (a[f] % 2 != 0) {               cout << f + 1 <<    ;               k--;             }             f++;           }           cout << n <<    ;           cout << endl;         } else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int llINF = (long long)(1e18) + 100;   const long long int MAXN = 1e6 + 10;   int lp[MAXN];   vector<int> pr;   void crivo() {     for (long long int i = 2; i < MAXN; i++) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (long long int j = 0;            j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN; ++j)         lp[i * pr[j]] = pr[j];     }   }   int n, dist[MAXN];   vector<int> adj[MAXN], dcp[MAXN];   vector<pair<int, int> > edge;   int other(int idx, int u) {     return edge[idx].first == u ? edge[idx].second : edge[idx].first;   }   int bfs(int p) {     memset(dist, 0, sizeof(dist));     queue<pair<int, int> > fila;     for (int x : adj[p]) {       fila.push({x, other(x, p)});       dist[other(x, p)] = 1;     }     int u, v, ans = INF;     pair<int, int> aux;     while (!fila.empty()) {       aux = fila.front();       fila.pop();       u = aux.second;       for (int w : adj[u]) {         if (w != aux.first) {           v = other(w, u);           if (dist[v] == 0 and v != p) {             fila.push({w, v});             dist[v] = dist[u] + 1;           } else             ans = min(ans, dist[u] + dist[v] + 1);         }       }     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     crivo();     lp[1] = 1;     cin >> n;     for (int i = 2; i < MAXN; i++) {       dcp[i] = dcp[i / lp[i]];       auto it = find(dcp[i].begin(), dcp[i].end(), lp[i]);       if (it != dcp[i].end())         dcp[i].erase(it);       else         dcp[i].push_back(lp[i]);     }     int a;     for (int i = 0; i < n; i++) {       cin >> a;       if (dcp[a].empty()) {         cout << 1 <<   n ;         return 0;       }       if (dcp[a].size() == 1) dcp[a].push_back(1);       edge.push_back({dcp[a][0], dcp[a][1]});       adj[dcp[a][0]].push_back(i);       adj[dcp[a][1]].push_back(i);     }     int ans = INF;     pr.insert(pr.begin(), 1);     for (int p : pr) {       if (p * p > MAXN) break;       ans = min(ans, bfs(p));     }     cout << (ans == INF ? -1 : ans) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct obj {     int id;     int f, t;     obj(int a, int b, int c) {       id = a;       f = b;       t = c;     }   };   bool cmpup(obj a, obj b) {     if (a.f == b.f) {       return a.id > b.id;     }     return a.f < b.f;   }   bool cmpdown(obj a, obj b) {     if (a.f == b.f) {       return a.id < b.id;     }     return a.f > b.f;   }   int n;   vector<obj> up;   vector<obj> down;   int a[105], d[105];   int now[105];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i], &d[i]);       now[i] = a[i];       if (d[i] > 0)         up.push_back(obj(i, a[i], a[i] + d[i]));       else if (d[i] < 0)         down.push_back(obj(i, a[i], a[i] + d[i]));     }     sort(up.begin(), up.end(), cmpup);     sort(down.begin(), down.end(), cmpdown);     int ans = 0;     for (int i = 0; i < up.size(); i++) {       for (int j = 0; j < n; j++) {         if (j == up[i].id) continue;         if (now[j] < up[i].f || now[j] > up[i].t) continue;         if (now[j] == up[i].f) {           if (j < up[i].id) ans++;         } else if (now[j] == up[i].t) {           if (j > up[i].id) ans++;         } else {           ans++;         }       }       now[up[i].id] = up[i].t;     }     for (int i = 0; i < down.size(); i++) {       for (int j = 0; j < n; j++) {         if (j == down[i].id) continue;         if (now[j] < down[i].t || now[j] > down[i].f) continue;         if (now[j] == down[i].f) {           if (j > down[i].id) ans++;         } else if (now[j] == down[i].t) {           if (j < down[i].id) ans++;         } else {           ans++;         }       }       now[down[i].id] = down[i].t;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   struct Input {     int n, k;     bool read() {       if (!(cin >> n >> k)) {         return false;       }       return true;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     long long ans;     void write() { cout << ans <<   n ; }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     void solve() {       ans = 0;       while (n > 1 && k > 0) {         ans += 2 * (n - 1) - 1;         n -= 2;         --k;       }     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     sol.read();     sol.solve();     sol.write();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k <= (n + 1) / 2) {       cout << k * 2 - 1 <<   n ;     } else       cout << (k - (n + 1) / 2) * 2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int find(vector<long long int> &p, long long int i) {     if (p[i] == -1) return i;     return find(p, p[i]);   }   void solve() {     string st;     cin >> st;     long long int c = 0;     for (long long int i = 0; i < st.size(); i++) {       if (st[i] ==  >  or st[i] ==  < ) {         continue;       }       if (st[i] ==  / ) {         c--;         for (long long int j = 0; j < 2 * c; j++) {           cout <<    ;         }         cout <<  </  << st[i + 1] <<  >  << endl;       } else if (st[i - 1] !=  / ) {         for (long long int j = 0; j < 2 * c; j++) {           cout <<    ;         }         cout <<  <  << st[i] <<  >  << endl;         c++;       }     }   }   int main() {     { solve(); }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int xx[] = {0, 0, -1, 1}, yy[] = {-1, 1, 0, 0};   using ll = long long;   using ppi = pair<int, int>;   using ppl = pair<ll, ll>;   ll d[3001][3001];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       vector<int> v(N);       for (long long i = (0); i < (N); ++i) {         cin >> v[i];       }       memset(d, 0, sizeof(d));       for (int i = N - 1; 0 <= i; --i) {         d[i][v[i]] = 1;         if (i + 1 < N) {           for (long long x = (1); x <= (N); ++x) {             d[i][x] += d[i + 1][x];           }         }       }       ll ans = 0;       for (long long j = (1); j < (N - 2); ++j) {         for (long long k = (j + 1); k < (N - 1); ++k) {           ans += (d[0][v[k]] - d[j][v[k]]) * (d[k + 1][v[j]]);         }       }       cout << ans << ((char)10);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   long long a[300100], sum[300100];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i];     long long ans = sum[0];     sort(sum + 1, sum + n);     for (int i = 0; i < k - 1; i++) ans += sum[n - 1 - i];     printf( %lld , ans);     return 0;   }