malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, a[200000], x[200000];     cin >> n;     cin >> b;     x[0] = 0;     a[0] = b;     for (int i = 1; i < n; i++) {       cin >> b;       x[i] = max(x[i - 1], a[i - 1]);       a[i] = b + x[i];     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   ll mod=1e9+7;   ll get(ll x,ll y)   {       ll z;       cout<< ?  <<x<<   <<y<<endl;       cin>>z;       return z;   }   int main()   {       #ifndef ONLINE_JUDGE           freopen( input.txt , r ,stdin);           freopen( output.txt , w ,stdout);       #endif         int i,j,k,n,m,t,l,r,h;         cin>>t;         while(t--)         {           ll x,y,w,b;           cin>>n>>x>>y;           ll flag1=0,flag2=0;            cin>>w>>b;            ll temp1=x+y;            ll temp2=2*n-x-y;             if(w<=(temp1/2)){flag1=1;}             if(b<=(temp2/2)){flag2=1;}             if(flag1+flag2==2){cout<< YES <<endl;}             else{cout<< NO <<endl;}         }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   void uin(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   void uax(T &a, T b) {     if (b > a) a = b;   }   const long long maxn = 1000 * 1000 + 228;   long long n, k;   long long dp[maxn], p[maxn];   long long dpret[maxn], hret[maxn];   vector<long long> g[maxn];   void dfs(long long v, long long deep = 0) {     hret[v] = deep;     if ((long long)g[v].size() == 1 && v != 1) {       dp[v] = 1;       dpret[v] = 1;       hret[v] = max(0LL, deep - k);     } else {       for (long long to : g[v]) {         if (to != p[v]) {           dfs(to, deep + 1);           if (hret[to] <= deep) {             dpret[v] += dpret[to];             uin(hret[v], hret[to]);           }         }       }       dp[v] = dpret[v];       for (long long to : g[v]) {         if (to != p[v]) {           if (hret[to] <= deep) {             uax(dp[v], dp[to] + dpret[v] - dpret[to]);           } else {             uax(dp[v], dp[to] + dpret[v]);           }         }       }     }   }   void solve() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (long long i = 2; i <= n; ++i) {       cin >> p[i];       g[i].push_back(p[i]);       g[p[i]].push_back(i);     }     dfs(1);     cout << dp[1] <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int K = 105;   const int N = (int)1e4 + 100;   int c[N];   long double dp[K][N];   long double C[K][K];   long double fact[K];   int main(int, char **) {     fact[0] = 1;     for (int i = 0; i < K; i++) {       if (i != 0) fact[i] = fact[i - 1] * i;       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     int n, x;     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) scanf( %d , &c[i]);     dp[0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = i; j >= 0; j--)         for (int s = 0; s + c[i] < N; s++) {           dp[j + 1][s + c[i]] += dp[j][s];         }     long double ans = 0;     for (int k = 1; k <= n; k++) {       long double xx = x;       xx += ((long double)n / (long double)k - 1.) * (long double)x / 2.;       long double value = 0;       for (int s = 0; s < N; s++) {         long double cur = dp[k][s];         if (cur < 0.5) continue;         long double A = xx;         long double B = (long double)s / (long double)k;         value += cur * min(A, B);       }       value /= C[n][k];       ans += value;     }     printf( %.14lf n , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt1[5001] = {0};   int cnt2[5001][5001] = {0};   vector<int> p[5001];   int cnt[5001] = {0};   int solve() {     int n, q;     cin >> n >> q;     vector<pair<int, int>> v;     for (int j = 0; j < q; j++) {       int l, r;       cin >> l >> r;       v.push_back({l, r});     }     sort(v.begin(), v.end());     for (int j = 0; j < q; j++) {       for (int i = v[j].first; i <= v[j].second; i++) {         cnt[i]++;         if (cnt[i] <= 2) {           p[i].push_back(j);         }       }     }     int s = 0;     for (int j = 1; j <= n; j++) {       int k = cnt[j];       if (k) {         s++;       }       if (k == 1) {         cnt1[p[j][0]]++;       } else if (k == 2) {         cnt2[p[j][0]][p[j][1]]++;         cnt2[p[j][1]][p[j][0]]++;       }     }     int ans = 0;     for (int j = 0; j < q; j++) {       for (int i = j + 1; i < q; i++) {         ans = max(ans, s - cnt1[j] - cnt1[i] - cnt2[i][j]);       }     }     cout << ans <<   n ;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   long long M[maxn << 2], tag[maxn << 2];   void gather(int p) { M[p] = max(M[p << 1], M[p << 1 | 1]); }   void push(int p) {     if (tag[p]) {       tag[p << 1] += tag[p];       tag[p << 1 | 1] += tag[p];       M[p << 1] += tag[p];       M[p << 1 | 1] += tag[p];       tag[p] = 0;     }   }   void modify(int p, int tl, int tr, int l, int r, long long v) {     if (tr < l || r < tl) return;     if (l <= tl && tr <= r) {       tag[p] += v;       M[p] += v;       return;     }     push(p);     int mid = (tl + tr) >> 1;     modify(p << 1, tl, mid, l, r, v);     modify(p << 1 | 1, mid + 1, tr, l, r, v);     gather(p);   }   long long query(int p, int tl, int tr, int l, int r) {     if (tr < l || r < tl) return 0ll;     if (l <= tl && tr <= r) return M[p];     push(p);     int mid = (tl + tr) >> 1;     long long ret = query(p << 1, tl, mid, l, r);     ret = max(ret, query(p << 1 | 1, mid + 1, tr, l, r));     return ret;   }   long long c[maxn];   inline int lowbit(int s) { return s & (-s); }   inline void modify(int i, long long x) {     while (i < maxn) c[i] += x, i += lowbit(i);   }   inline long long query(int i) {     long long ret = 0;     while (i > 0) ret += c[i], i -= lowbit(i);     return ret;   }   long long x[maxn], y[maxn];   int main() {     int q;     scanf( %d , &q);     for (int t = 1; t <= q; ++t) {       char op[11];       scanf( %s %lld , op, x + t);       if (op[0] ==  + ) {         scanf( %lld , y + t);         modify(1, 1, 1000000, x[t], x[t], x[t]);         modify(1, 1, 1000000, 1, x[t], y[t]);         modify(x[t], y[t]);       } else if (op[0] ==  - ) {         modify(1, 1, 1000000, x[x[t]], x[x[t]], -x[x[t]]);         modify(1, 1, 1000000, 1, x[x[t]], -y[x[t]]);         modify(x[x[t]], -y[x[t]]);       } else {         long long tmp =             query(1, 1, 1000000, 1, x[t]) - (query(1000000) - query(x[t]));         printf( %lld n , max(x[t], tmp) - x[t]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void draw(int k) {     for (int i = 0; i < n - k; i++) {       cout <<     ;     }     for (int i = 0; i < k; i++) {       cout << i <<    ;     }     for (int i = k; ~i; i--) {       cout << i << (i ?     :   n );     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       draw(i);     }     for (int i = n; ~i; i--) {       draw(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MM = 2e4 + 5;   struct Node {     int l, r, lz, mx;   } seg[MM * 4];   int n, m, k, dp[55][MM], a[55][MM], b[55][MM];   void build(int u, int l, int r, int i) {     seg[u].l = l;     seg[u].r = r;     seg[u].lz = 0;     if (l == r) {       seg[u].mx = dp[i - 1][l];       return;     }     int mid = (l + r) / 2;     build(u * 2, l, mid, i);     build(u * 2 + 1, mid + 1, r, i);     seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);   }   void upd(int u, int l, int r, int v);   void push(int u) {     if (seg[u].lz == 0) return;     for (int i = 0; i < 2; i++) {       upd(u * 2 + i, seg[u * 2 + i].l, seg[u * 2 + i].r, seg[u].lz);     }     seg[u].lz = 0;   }   void upd(int u, int l, int r, int v) {     if (seg[u].l == l && seg[u].r == r) {       seg[u].mx += v;       seg[u].lz += v;       return;     }     push(u);     int mid = (seg[u].l + seg[u].r) / 2;     if (r <= mid)       upd(u * 2, l, r, v);     else if (l > mid)       upd(u * 2 + 1, l, r, v);     else       upd(u * 2, l, mid, v), upd(u * 2 + 1, mid + 1, r, v);     seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         b[i][j] = a[i][j];         a[i][j] += a[i][j - 1];       }     }     for (int i = 1; i + k - 1 <= m; i++) {       dp[1][i] = a[1][i + k - 1] - a[1][i - 1] + a[2][i + k - 1] - a[2][i - 1];     }     for (int i = 2; i <= n; i++) {       build(1, 1, m, i);       auto get_sum = [&](int l, int r) {         int val = a[i][r] - a[i][l - 1];         if (i != n) val += a[i + 1][r] - a[i + 1][l - 1];         return val;       };       for (int j = 1; j <= k; j++) {         int l = max(j - k + 1, 1), r = j;         if (l <= r) upd(1, l, r, -b[i][j]);       }       dp[i][1] = seg[1].mx + get_sum(1, k);       for (int j = k + 1; j <= m; j++) {         int st = j - k + 1;         int pos = j - k;         int l = max(pos - k + 1, 1), r = pos;         if (l <= r) upd(1, l, r, b[i][pos]);         pos = j;         l = max(pos - k + 1, 1), r = pos;         if (l <= r) upd(1, l, r, -b[i][pos]);         dp[i][st] = seg[1].mx + get_sum(st, st + k - 1);       }     }     int ans = 0;     for (int i = 1; i + k - 1 <= m; i++) ans = max(ans, dp[n][i]);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9, N = 101;   int n, m, q, tot, a[N], b[N];   int vis[N];   bool solve(int pos) {     memset(vis, 0, sizeof(vis));     for (int i = pos; i < pos + tot; i++) vis[a[i]]++;     for (int i = 1; i < m + 1; i++)       if (vis[i] != b[i]) return 0;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < m + 1; i++) {       cin >> b[i];       tot += b[i];     }     for (int i = 0; i < n - tot + 1; i++)       if (solve(i)) return !(cout <<  YES  << endl);     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxx = 2e5 + 10;   char s[maxx], t[maxx];   int l[maxx], r[maxx];   int main() {     cin >> s >> t;     int m = strlen(s);     int n = strlen(t);     int a = 0, b = 0;     for (int i = 0; i < m; i++) {       if (s[i] == t[a]) {         l[a] = i;         a++;       }       if (a == n) break;     }     for (int i = m - 1; i >= 0; i--) {       if (s[i] == t[n - b - 1]) {         r[b] = i;         b++;       }       if (b == n) break;     }     int ans = max(r[n - 1], m - l[n - 1] - 1);     for (int i = 0; i < n; i++) ans = max(ans, r[i] - l[n - i - 2] - 1);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int dx[4] = {1, -1, 0, 0};   const int dy[4] = {0, 0, 1, -1};   int read() {     int s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x +  0 );     else       write(x / 10), putchar(x % 10 +  0 );   }   void print(int x, char c =   n ) {     write(x);     putchar(c);   }   void error() { puts( -1 ), exit(0); }   pair<int, int> q[N];   int dis[N], tot[N], tt, a[N];   int id(int n, int m, int x, int y) { return (x - 1) * m + y; }   void check(int n, int m, int x, int y) {     if (x > n || y > m) return;     for (int i = 1; i <= tt; i++) dis[i] = -1, tot[i] = 0;     dis[id(n, m, x, y)] = 0;     int h = 1, t = 1;     q[1] = make_pair(x, y);     while (h <= t) {       int x = q[h].first, y = q[h++].second;       for (int i = 0; i < 4; i++)         if (1 <= x + dx[i] && x + dx[i] <= n)           if (1 <= y + dy[i] && y + dy[i] <= m)             if (!~dis[id(n, m, x + dx[i], y + dy[i])]) {               dis[id(n, m, x + dx[i], y + dy[i])] = dis[id(n, m, x, y)] + 1;               q[++t] = make_pair(x + dx[i], y + dy[i]);             }     }     for (int i = 1; i <= tt; i++) tot[dis[i]]++;     for (int i = 1; i <= tt; i++)       if (tot[i] != a[i]) return;     print(n,    ), print(m);     print(x,    ), print(y);     exit(0);   }   signed main(signed Recall, char *_902_[]) {     (void)Recall, (void)_902_;     tt = read();     for (int i = 1; i <= tt; i++) a[read()]++;     int x = 0, mx = 0;     for (int i = 0; i <= tt; i++)       if (a[i]) mx = i;     for (int i = 0; i <= tt; i++) {       if (a[i] > i * 4 + !i) error();       if (a[i] < i * 4 + !i) {         x = i;         break;       }     }     if (x == 0) error();     for (int i = 1; i <= tt; i++)       if (tt % i == 0) check(i, tt / i, x, i + tt / i - x - mx);     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 212345, MAXL = 20, INF = 1123456789;   vector<int> grafo[MAXN], peso[MAXN];   int dp[MAXN][MAXL], mx[MAXN][MAXL], dist[MAXN], prof[MAXN];   long long int pmst;   pair<int, pair<int, int> > ar[MAXN];   int lca(int a, int b) {     int resp = 0;     if (prof[a] < prof[b]) swap(a, b);     int d = prof[a] - prof[b];     for (int i = MAXL - 1; i >= 0; i--) {       if (d & (1 << i)) {         resp = max(resp, mx[a][i]);         a = dp[a][i];       }     }     if (a == b) return resp;     for (int i = MAXL - 1; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         resp = max(resp, max(mx[a][i], mx[b][i]));         a = dp[a][i];         b = dp[b][i];       }     }     resp = max(resp, max(mx[a][0], mx[b][0]));     return resp;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, p;       scanf( %d %d %d , &a, &b, &p);       a--;       b--;       grafo[a].push_back(b);       grafo[b].push_back(a);       peso[a].push_back(p);       peso[b].push_back(p);       ar[i] = make_pair(p, make_pair(a, b));     }     set<pair<int, int> > s;     dist[0] = 0;     s.insert(make_pair(0, 0));     for (int i = 1; i < n; i++) {       dist[i] = INF;       s.insert(make_pair(INF, i));     }     dp[0][0] = 0;     prof[0] = 0;     while (!s.empty()) {       int cur = (*s.begin()).second;       s.erase(s.begin());       pmst += dist[cur];       dist[cur] = 0;       for (int i = 0; i < grafo[cur].size(); i++) {         int viz = grafo[cur][i], p = peso[cur][i];         if (dist[viz] > p) {           s.erase(make_pair(dist[viz], viz));           dist[viz] = p;           s.insert(make_pair(dist[viz], viz));           dp[viz][0] = cur;           mx[viz][0] = p;           prof[viz] = prof[cur] + 1;         }       }     }     for (int j = 1; j < MAXL; j++) {       for (int i = 0; i < n; i++) {         dp[i][j] = dp[dp[i][j - 1]][j - 1];         mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);       }     }     for (int i = 0; i < m; i++) {       printf( %lld n ,              pmst - lca(ar[i].second.first, ar[i].second.second) + ar[i].first);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[500005 << 2];   struct P {     int x, y, z;     int id;   } p[500005];   bool cmp1(P a, P b) {     if (a.x != b.x)       return a.x > b.x;     else if (a.y != b.y)       return a.y > b.y;     else       return a.z > b.z;   }   bool cmp2(P a, P b) { return a.y < b.y; }   void push_up(int rt) { tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]); }   void update(int pos, int x, int l, int r, int rt) {     if (l == r) {       tree[rt] = max(tree[rt], x);       return;     }     int m = (l + r) >> 1;     if (pos <= m)       update(pos, x, l, m, rt << 1);     else       update(pos, x, m + 1, r, rt << 1 | 1);     push_up(rt);   }   int query(int L, int R, int l, int r, int rt) {     if (L <= l && R >= r) return tree[rt];     int m = (l + r) >> 1;     int ans = 0;     if (L <= m) ans = max(ans, query(L, R, l, m, rt << 1));     if (R > m) ans = max(ans, query(L, R, m + 1, r, rt << 1 | 1));     return ans;   }   int main() {     int i, j, n, ans, cnt, pre;     while (~scanf( %d , &n)) {       ans = 0;       cnt = 1;       memset(tree, 0, sizeof(tree));       for (i = 0; i < n; i++) scanf( %d , &p[i].x), p[i].id = i;       for (i = 0; i < n; i++) scanf( %d , &p[i].y);       for (i = 0; i < n; i++) scanf( %d , &p[i].z);       sort(p, p + n, cmp2);       pre = p[0].y;       p[0].y = 1;       for (i = 1; i < n; i++)         if (p[i].y == pre) {           pre = p[i].y;           p[i].y = cnt;         } else {           pre = p[i].y;           p[i].y = ++cnt;         }       sort(p, p + n, cmp1);       for (i = 0; i < n;) {         for (j = i; j < n && p[i].x == p[j].x; j++) {           if (query(p[j].y + 1, cnt, 1, cnt, 1) > p[j].z) ans++;         }         for (; i < j; i++) update(p[i].y, p[i].z, 1, cnt, 1);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   int a[N], pos[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       pos[x] = i;     }     for (int i = 1; i <= n; i++) a[i] = pos[a[i]];     int ans = 0;     for (int i = 2; i <= n; i++) {       if (a[i] < a[i - 1]) {         i--;         cout << n - i << endl;         return 0;       }     }     cout << 0 << endl;   }
#include <bits/stdc++.h>   const int MAX = 1e6 + 105;   const int INF = 1e9 + 5;   const double M = 4e18;   using namespace std;   const int MOD = 1e9 + 7;   const double eps = 0.000000001;   int n, k;   bool query(int x, int y) {     if (x < 0 || y > n) return false;     string re;     cout << 1 <<     << x <<     << y <<   n ;     cin >> re;     return re ==  TAK ;   }   int get(int l, int r) {     if (l > r) return -1;     while (l < r) {       int mid = (l + r) / 2;       if (query(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     scanf( %d%d , &n, &k);     int x, y;     x = get(1, n);     y = get(1, x - 1);     if (!query(y, x)) y = get(x + 1, n);     printf( 2 %d %d n , x, y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   signed main() {     cin.tie(0);     std::ios_base::sync_with_stdio(0);     long long n;     cin >> n;     long long cnt = 10;     vector<long long> ans;     ans.push_back(10);     if (n < 2) {       cout << 10;       return 0;     }     ans.push_back(180);     long long one_neigh = 1800, two_neighs = 810;     for (long long ii = 2; ii < n; ++ii) {       long long cnt = 1LL * one_neigh;       cnt += 1LL * two_neighs * (ii - 1LL);       one_neigh *= 10;       two_neighs *= 10;       two_neighs %= mod;       one_neigh %= mod;       cnt %= mod;       ans.push_back(cnt);     }     for (long long ii = n - 1; ii >= 0; --ii) {       cout << ans[ii] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long data = 0, w = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 )       data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();     return data * w;   }   long long st1[1000005], st2[1000005], top1, top2, js[1000005], mi[1000005],       ans[1000005], ti[1000005], ad[1000005];   void pushup(long long x) {     long long l = x << 1, r = x << 1 | 1;     ans[x] = ans[l] + ans[r];     mi[x] = min(mi[l], mi[r]);     js[x] = 0;     if (mi[l] == mi[x]) js[x] += js[l];     if (mi[r] == mi[x]) js[x] += js[r];   }   void add(long long x, long long v) {     mi[x] += v;     ad[x] += v;   }   void addti(long long x, long long v) {     ans[x] += v * js[x];     ti[x] += v;   }   void pushdown(long long x) {     if (ad[x]) add(x << 1, ad[x]), add(x << 1 | 1, ad[x]);     if (ti[x]) {       if (mi[x << 1] == mi[x]) addti(x << 1, ti[x]);       if (mi[x << 1 | 1] == mi[x]) addti(x << 1 | 1, ti[x]);     }     ad[x] = ti[x] = 0;   }   void build(long long x, long long l, long long r) {     js[x] = 1;     mi[x] = l;     if (l == r) return;     long long mid = l + r >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   void add(long long x, long long l, long long r, long long ql, long long qr,            long long v) {     if (ql <= l && r <= qr) return add(x, v);     long long mid = l + r >> 1;     pushdown(x);     if (ql <= mid) add(x << 1, l, mid, ql, qr, v);     if (mid < qr) add(x << 1 | 1, mid + 1, r, ql, qr, v);     pushup(x);   }   long long ask(long long x, long long l, long long r, long long ql,                 long long qr) {     if (ql > r || qr < l) return 0;     if (ql <= l && r <= qr) return ans[x];     pushdown(x);     long long mid = l + r >> 1;     return ask(x << 1, l, mid, ql, qr) + ask(x << 1 | 1, mid + 1, r, ql, qr);   }   long long a[1000005], Ans[1000005];   struct que {     long long l, r, id;   } q[1000005];   int main() {     long long n = read();     for (long long i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     long long Q = read();     for (long long i = 1; i <= Q; i++)       q[i].l = read(), q[i].r = read(), q[i].id = i;     sort(q + 1, q + Q + 1, [](que A, que B) { return A.r < B.r; });     long long j = 1;     for (long long i = 1; i <= n; i++) {       add(1, -1);       while (top1 && a[i] > a[st1[top1]])         add(1, 1, n, st1[top1 - 1] + 1, st1[top1], a[i] - a[st1[top1]]), --top1;       st1[++top1] = i;       while (top2 && a[i] < a[st2[top2]])         add(1, 1, n, st2[top2 - 1] + 1, st2[top2], a[st2[top2]] - a[i]), --top2;       st2[++top2] = i;       addti(1, 1);       while (j <= Q && q[j].r == i)         Ans[q[j].id] = ask(1, 1, n, q[j].l, q[j].r), ++j;     }     for (long long i = 1; i <= Q; i++) cout << Ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, l;     cin >> n >> k;     string s;     cin >> s;     long long max = 0;     for (i = 1; i < n; i++) {       long long temp = 0;       for (l = 0; l < n; l++) {         if (i + l < n) {           if (s[i + l] == s[l]) {             temp++;           }         } else           break;       }       if (temp == n - i) {         max = n - i;         break;       }     }     string ans = s;     for (i = 1; i < k; i++) {       ans += s.substr(max, n - max);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void speed() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int compare(pair<long long int, long long int> a,               pair<long long int, long long int> b) {     return a.first > b.first;   }   int main() {     speed();     long long int n;     cin >> n;     vector<pair<long long int, long long int> > a;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       a.push_back({temp, i});     }     sort(a.begin(), a.end(), compare);     long long int k = 0;     long long int tk = 0;     for (long long int i = 0; i < n; i++) {       k = (a[i].first) * i + 1;       tk += k;     }     cout << tk <<   n ;     for (long long int i = 0; i < n; i++) {       cout << a[i].second + 1 <<    ;     }     return 0;   }