malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   queue<int> q1, q2, q3, q4, q5, q6;   int main() {     int n, x, ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x == 4)         q1.push(i);       else if (x == 8)         q2.push(i);       else if (x == 15)         q3.push(i);       else if (x == 16)         q4.push(i);       else if (x == 23)         q5.push(i);       else         q6.push(i);     }     if (q1.empty() || q2.empty() || q3.empty() || q4.empty() || q5.empty() ||         q6.empty()) {       printf( %d n , n - ans);       return 0;     }     while (1) {       if (q2.front() > q1.front()) {         if (q3.front() > q2.front()) {           if (q4.front() > q3.front()) {             if (q5.front() > q4.front()) {               if (q6.front() > q5.front()) {                 ans += 6;                 q1.pop();                 q2.pop();                 q3.pop();                 q4.pop();                 q5.pop();                 q6.pop();               } else                 q6.pop();             } else               q5.pop();           } else             q4.pop();         } else           q3.pop();       } else         q2.pop();       if (q1.empty() || q2.empty() || q3.empty() || q4.empty() || q5.empty() ||           q6.empty())         break;     }     printf( %d n , n - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   point moves[2020];   queue<int> Q;   const int lin[] = {1, -1, 0, 0};   const int col[] = {0, 0, 1, -1};   int A[2020][2020];   int X[3 * 2020], Y[3 * 2020];   int n;   void new_point(int x, int y) {     X[++X[0]] = x;     Y[++Y[0]] = y;   }   void normalizare(int X[]) {     sort(X + 1, X + X[0] + 1);     int c = 1;     for (int i = 2; i <= X[0]; i++) {       if (X[c] != X[i]) {         X[++c] = X[i];       }     }     X[0] = c;   }   void precomp() {     normalizare(X);     normalizare(Y);   }   void find(int x, int X[], int &poz) {     int step = 0;     for (; (1 << step) <= X[0]; step++)       ;     step--;     poz = 0;     for (int i = step; i >= 0; i--) {       if (poz + (1 << i) <= X[0] && X[poz + (1 << i)] < x) {         poz += (1 << i);       }     }     poz++;   }   void vecini(int x, int y) {     for (int t = 0; t < 4; t++) {       int xx = x + lin[t], yy = y + col[t];       if (xx >= 0 && xx <= X[0] && yy >= 0 && yy <= Y[0] && A[xx][yy] == 0) {         A[xx][yy] = 2;         Q.push(xx + (yy << 13));       }     }   }   void bf() {     Q.push(0);     A[0][0] = 2;     while (!Q.empty()) {       int x = Q.front() & ((1 << 13) - 1), y = Q.front() >> 13;       Q.pop();       vecini(x, y);     }   }   void solve() {     precomp();     int x1, y1;     find(moves[0].x, X, x1);     find(moves[0].y, Y, y1);     for (int i = 1; i <= n; i++) {       int x2, y2, chg;       if (moves[i].x == moves[i - 1].x) {         x2 = x1;         chg = 2 * (moves[i].y > moves[i - 1].y) - 1;         find(moves[i].y, Y, y2);         for (int j = y1; j != y2; j += chg) {           A[x1][j] = 1;         }         A[x1][y2] = 1;       } else {         y2 = y1;         chg = 2 * (moves[i].x > moves[i - 1].x) - 1;         find(moves[i].x, X, x2);         for (int j = x1; j != x2; j += chg) {           A[j][y1] = 1;         }         A[x2][y1] = 1;       }       x1 = x2;       y1 = y2;     }     bf();     long long sol = 0;     for (int i = 1; i < X[0]; i++) {       for (int j = 1; j < Y[0]; j++) {         if (A[i][j] <= 1) {           sol += (long long)(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);         }       }     }     cout << sol;   }   int main() {     scanf( %d n , &n);     int x = 0, y = 0;     X[++X[0]] = x;     Y[++Y[0]] = y;     new_point(1, 1);     for (int i = 1; i <= n; i++) {       char c;       int val;       scanf( %c %d n , &c, &val);       if (c ==  R ) {         x += val;       } else if (c ==  L ) {         x -= val;       } else if (c ==  D ) {         y += val;       } else {         y -= val;       }       moves[i].x = x;       moves[i].y = y;       new_point(x, y);       new_point(x + 1, y + 1);     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n, m;     cin >> n >> m;     vector<long long> v, h;     for (long long idx = 0; idx < n; ++idx) {       long long x;       cin >> x;       v.push_back(x);     }     for (long long idx = 0; idx < m; ++idx) {       long long x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 > 1) continue;       h.push_back(x2);     }     sort(v.begin(), v.end());     sort(h.begin(), h.end());     long long res = n + m;     for (long long idx = 0; idx <= v.size(); ++idx) {       long long lim = idx == v.size() ? 1000000000 : v[idx];       auto it = lower_bound(h.begin(), h.end(), lim);       res = min(res, distance(it, h.end()) + idx);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     long long mini = n - 1, maxi = -1;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         mini = i;         break;       }     }     for (long long i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         maxi = i;         break;       }     }     if (maxi == -1) {       cout << n << endl;       return;     }     cout << 2 * max(maxi + 1, n - mini) << endl;   }   int main() {     long long t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x1, y1, x2, y2, x, y;     cin >> x1 >> y1 >> x2 >> y2;     cin >> x >> y;     x2 = x2 - x1;     y2 = y2 - y1;     if (x2 % x != 0 || y2 % y != 0)       cout <<  NO  << endl;     else {       if (((x2 / x) & 1) == ((y2 / y) & 1))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int P = 1000000007;   int n, m;   const int V = 5010;   int main() {     while (~scanf( %d%d , &n, &m)) {       int mx = 0;       for (int i = 1; i <= n; ++i) mx += (i - 1) / 2;       if (mx < m) {         puts( -1 );         continue;       }       int pr = 0, pre = 0;       for (int i = 0; i <= n; ++i) {         if (pre + (i - 1) / 2 > m) break;         pre += (i - 1) / 2;         pr = i;       }       int need = m - pre;       for (int i = 1; i <= pr; ++i) printf( %d  , i);       int remain = n - pr;       if (need != 0) {         int np = -1;         for (int i = pr + 1;; ++i) {           int tc = 0;           for (int j = 1; j <= pr; ++j) {             if (i - j > j && i - j <= pr) tc++;           }           if (tc == need) {             np = i;             break;           }         }         --remain;         printf( %d  , np);       }       for (int i = remain; i > 0; --i) printf( %d  , 1000000000 - 30000 * i);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e6 + 10;   const int p = 1009;   int raw[maxn], cnt[maxn];   complex<double> F1[maxn], F2[maxn];   const double PI = acos(-1.0);   int rev[maxn];   void init(vector<complex<double> >& A, int n) {     A.clear();     A.shrink_to_fit();     int size = 1;     while (size <= n) size *= 2;     A.assign(size * 2, 0);   }   void FFT_init(int n) {     int S = log2(n);     for (int i = 0; i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (S - 1));   }   void FFT(complex<double>* A, int siz, int type) {     int n = siz;     FFT_init(n);     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(A[i], A[rev[i]]);     for (int i = 1; i < n; i *= 2) {       complex<double> Wn(cos(PI / i), type * sin(PI / i));       for (int j = 0; j < n; j += i * 2) {         complex<double> W(1, 0);         for (int k = 0; k < i; k++) {           complex<double> facx = A[j + k], facy = W * A[j + k + i];           A[j + k] = facx + facy;           A[j + k + i] = facx - facy;           W *= Wn;         }       }     }     if (type == -1)       for (int i = 0; i < n; i++) A[i].real((A[i].real() / n + 0.5));   }   vector<complex<double> > mul(vector<complex<double> > A,                                vector<complex<double> > B) {     int n = A.size(), m = B.size();     int siz = n + m - 1;     vector<complex<double> > C(siz);     int fsiz = 1;     while (fsiz <= siz) fsiz *= 2;     fsiz *= 2;     for (int i = 0; i < fsiz; i++) F1[i] = F2[i] = 0;     for (int i = 0; i < n; i++) F1[i] = A[i];     for (int i = 0; i < m; i++) F2[i] = B[i];     FFT(F1, fsiz, 1);     FFT(F2, fsiz, 1);     for (int i = 0; i < fsiz; i++) F1[i] *= F2[i];     FFT(F1, fsiz, -1);     for (int i = 0; i < siz; i++) {       C[i] = ((long long)F1[i].real()) % p;     }     return C;   }   vector<complex<double> > solve(int l, int r) {     if (l == r) {       return vector<complex<double> >(cnt[l] + 1, 1);     }     int m = (l + r) / 2;     return mul(solve(l, m), solve(m + 1, r));   }   struct Node {     int w;     vector<complex<double> > P;     Node(int w = 0, vector<complex<double> > P = {}) : w(w), P(P) {}     bool operator<(const Node& X) const { return w > X.w; }   };   priority_queue<Node> pq;   vector<complex<double> > ans;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;     }     vector<complex<double> > ans = solve(1, m);     cout << ((int)ans[k].real() + p) % p <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const double eps = 1e-8;   const int INF = 1e9 + 7;   const long long inf = (1LL << 62);   const int MOD = 1e9 + 7;   const int M = 100010;   const int maxn = 1001;   const int lowbit(int x) { return x & -x; }   int read() {     int v = 0, f = 1;     char c = getchar();     while (c < 48 || 57 < c) {       if (c ==  - ) f = -1;       c = getchar();     }     while (48 <= c && c <= 57) v = v * 10 + c - 48, c = getchar();     return v * f;   }   struct timer {     double t;     timer() { t = clock(); }     ~timer() { printf(  nruntime %.3f s n , get_time()); }     double get_time() { return (clock() - t) / CLOCKS_PER_SEC; }   };   int N;   int A[1100010], B[1100010];   int inv2 = 500000004;   void fwt(int *a) {     int i, j, k, l, t, x, y;     for (i = 1; i < N; i <<= 1) {       for (j = 0, l = N / (i << 1); j < N; j += i << 1) {         for (k = 0, l = 0; k < i; ++k, l += t) {           x = a[j + k];           y = a[j + k + i];           a[j + k] = (x + y) % MOD;           a[j + k + i] = (x - y + MOD) % MOD;         }       }     }   }   void wfwt(int *a) {     int i, j, k, l, t, x, y;     for (i = 1; i < N; i <<= 1) {       for (j = 0, l = N / (i << 1); j < N; j += i << 1) {         for (k = 0, l = 0; k < i; ++k, l += t) {           x = a[j + k];           y = a[j + k + i];           a[j + k] = 1ll * (x + y) * inv2 % MOD;           a[j + k + i] = 1ll * (x - y + MOD) * inv2 % MOD;         }       }     }   }   int solve(int x) {     int res = 0;     while (x) {       res += (x & 1);       x >>= 1;     }     return res;   }   int qpower(int x, int y) {     int res = 1;     while (y) {       if (y & 1) res = 1LL * res * x % MOD;       x = 1LL * x * x % MOD;       y >>= 1;     }     return res;   }   int ans = 0;   char s[1100010];   int main() {     int n;     n = read();     scanf( %s , s);     for (int i = 0; i < (1 << n); i++) {       A[i] = s[i] -  0 ;     }     for (int i = 0; i < (1 << n); i++) {       B[i] = 1 - A[i];     }     N = 1 << n;     fwt(A);     fwt(B);     for (int i = 0; i < (1 << n); i++) {       A[i] = 1LL * A[i] * B[i] % MOD;     }     wfwt(A);     for (int i = 0; i < (1 << n); i++) {       ans += 3LL * A[i] * qpower(2, solve(i)) % MOD;       ans %= MOD;     }     printf( %d n , ans);     return 0;   }
//zxggtxdy!   #include<bits/stdc++.h>   using namespace std;   const int M=52,N=2e3+7,p=998244353;   int n,k,D,l[M],f1[N],f2[N],s[N],G[M][N],Q[M][N],dp[2][N];   inline long long pows(long long u,int v){    long long ans=1; while(v>0) {if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;} return ans;   }   inline int binom(int a,int b){    if(a<b||b<0) return 0; return 1ll*f1[a]*f2[a-b]%p*f2[b]%p;   }   inline int getval(int u,int q){    int A=0,B=0; if(u<0) return 1; if(u==0) return pows(1-q+p,p-2);    for(int i=1;i<=u+2;i++) s[i]=(s[i-1]+binom(i,u)*pows(q,i))%p; int v=pows(q,p-2);    for(int i=1;i<=u+2;i++){     int k=pows(v,i),b=s[i]*pows(v,i)%p,W=1ll*f1[u+2]*pows(i,p-2)%p;     W=1ll*W*f2[i-1]%p*f2[u+2-i]%p; if((i+u)&1) W=p-W;     A=(A+1ll*k*W)%p,B=(B+1ll*b*W)%p;    }    return pows(A-1+p,p-2)*B%p*pows(v,u)%p;   }   inline int getans(int u,int q){    return pows(pows(D,p-2)*(u-q*k)%p,q)*f2[q]%p;    }   signed main(){    cin>>n>>k,f1[0]=f2[0]=1,G[0][0]=1;    for(int i=1;i<=n;i++) cin>>l[i],D+=l[i];    for(int i=1;i<=2005;i++) f1[i]=1ll*f1[i-1]*i%p,f2[i]=pows(f1[i],p-2);    for(int i=1;i<=n;i++){     memset(dp,0,sizeof(dp)),dp[0][0]=1,dp[1][0]=(l[i]>k);     for(int j=1;j<=l[i]/k;j++) dp[0][j]=getans(l[i],j);     for(int j=1;j<l[i]/k;j++) dp[1][j]=getans(l[i]-k,j);     memset(Q,0,sizeof(Q));     for(int a=0;a<=i;a++)      for(int b=0;b<=D-l[i];b++)       for(int c=0;c<=1;c++)        for(int d=0;d<=l[i];d++)         Q[a+c][b+d]=(Q[a+c][b+d]+1ll*G[a][b]*dp[c][d])%p;     for(int a=0;a<=i;a++)      for(int b=0;b<=D;b++) G[a][b]=Q[a][b];    }    int ans=0;    for(int a=n;a>=0;a--)     for(int b=0;b<=D;b++){      if(a+b>0&&G[a][b]){       int Q=(D-(a+b)*k+p)%p*pows(D,p-2)%p,T=pows(1-Q+p,p-2-b)*f1[b]%p;       ans=(ans+pows(p-1,a+b+1)*G[a][b]%p*T%p)%p;      }     }    cout<<ans<<endl;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   char A[100 + 3], B[100 + 3], C[100 + 3], Ans[100 + 3];   int f[100 + 3][100 + 3][100 + 3], prei[100 + 3][100 + 3][100 + 3],       prej[100 + 3][100 + 3][100 + 3], prek[100 + 3][100 + 3][100 + 3];   int Go[100 + 3][26], fail[100 + 3], la, lb, lc, len, ansi, ansj, ansk;   int main() {     scanf( %s%s%s , A + 1, B + 1, C + 1);     la = strlen(A + 1);     lb = strlen(B + 1);     lc = strlen(C + 1);     Go[0][C[1] -  A ] = 1;     Go[1][C[1] -  A ] = 1;     Go[1][C[2] -  A ] = 2;     for (int i = 2; i <= lc; i++) {       int w = fail[i - 1];       for (; w && C[w + 1] != C[i]; w = fail[w])         ;       if (C[i] == C[w + 1]) w++;       fail[i] = w;       for (int j = 0; j < 26; j++) {         int w = i;         for (; w && C[w + 1] -  A  != j; w = fail[w])           ;         if (C[w + 1] -  A  == j) w++;         Go[i][j] = w;       }     }     memset(f, 130, sizeof(f));     f[0][0][0] = 0;     for (int i = 0; i < la; i++)       for (int j = 0; j < lb; j++)         for (int k = 0; k < lc; k++) {           if (f[i][j][k] < 0) continue;           if (f[i + 1][j][k] < f[i][j][k]) {             f[i + 1][j][k] = f[i][j][k];             prei[i + 1][j][k] = i;             prej[i + 1][j][k] = j;             prek[i + 1][j][k] = k;           }           if (f[i][j + 1][k] < f[i][j][k]) {             f[i][j + 1][k] = f[i][j][k];             prei[i][j + 1][k] = i;             prej[i][j + 1][k] = j;             prek[i][j + 1][k] = k;           }           if (A[i + 1] == B[j + 1]) {             int tk = Go[k][A[i + 1] -  A ];             if (f[i + 1][j + 1][tk] < f[i][j][k] + 1) {               f[i + 1][j + 1][tk] = f[i][j][k] + 1;               prei[i + 1][j + 1][tk] = i;               prej[i + 1][j + 1][tk] = j;               prek[i + 1][j + 1][tk] = k;             }           }         }     for (int i = 1; i <= la; i++)       for (int j = 1; j <= lb; j++)         for (int k = 0; k < lc; k++)           if (f[i][j][k] > f[ansi][ansj][ansk]) {             ansi = i, ansj = j, ansk = k;           }     len = f[ansi][ansj][ansk];     if (!len) {       printf( 0 );       return 0;     }     for (int w = len; w;) {       int ti = prei[ansi][ansj][ansk], tj = prej[ansi][ansj][ansk],           tk = prek[ansi][ansj][ansk];       if (f[ti][tj][tk] < f[ansi][ansj][ansk]) Ans[w--] = A[ansi];       ansi = ti, ansj = tj, ansk = tk;     }     printf( %s , Ans + 1);   }
#include <bits/stdc++.h>   using namespace std;   map<long long, bool> isMark;   int main() {     long long n, x, y, l;     cin >> n >> l >> x >> y;     bool b = 0, g = 0, d = 0, bd = 0;     long long diff = y - x, B = y + x;     long long tmp;     long long mark = -1, mark2 = -1;     bool n1 = 1, n2 = 1;     for (int i = 0; i < n; i++) {       cin >> tmp;       isMark[tmp] = 1;       b |= isMark.count(tmp - x);       g |= isMark.count(tmp - y);       d |= isMark.count(tmp - diff);       bd |= isMark.count(tmp - B);       if (b && g) {         cout <<  0 ;         return 0;       }       if (d && n1) {         long long idx = tmp + x;         if (idx > l) {           idx = tmp - y;           if (idx >= 0) {             mark = idx;           }         } else {           mark = idx;         }         if (mark == -1) {           d = 0;         } else {           n1 = 0;         }       }       if (bd && n2) {         mark2 = tmp - y;         n2 = 0;       }     }     if (b & !g) {       cout <<  1 n  << y;     } else if (g & !b) {       cout <<  1 n  << x;     } else if (d) {       cout <<  1 n ;       cout << mark;     } else if (bd) {       cout <<  1 n  << mark2 <<   n ;     } else {       cout <<  2 n ;       cout << x <<     << y;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) -  0  + ch;       ch = getchar();     }     return x * f;   }   struct node {     int x, y, z;     bool operator<(const node W) const { return y < W.y; }   } a[N];   int n;   long long b[N];   int cnt;   pair<long long, int> tr[N << 2];   long long lazy[N << 2];   long long ans;   void pushup(int rt) {     if (tr[rt << 1].first > tr[rt << 1 | 1].first)       tr[rt] = tr[rt << 1];     else       tr[rt] = tr[rt << 1 | 1];     tr[rt].first += lazy[rt];   }   void build(int rt, int l, int r) {     if (l == r) {       tr[rt] = {b[l], l};       return;     }     int mid = l + r >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   void update(int rt, int L, int R, int C, int l, int r) {     if (L <= l && R >= r) {       tr[rt].first += C;       lazy[rt] += C;       return;     }     int mid = l + r >> 1;     if (L <= mid) update(rt << 1, L, R, C, l, mid);     if (R > mid) update(rt << 1 | 1, L, R, C, mid + 1, r);     pushup(rt);   }   pair<long long, int> query(int rt, int L, int R, long long tg, int l, int r) {     if (L <= l && R >= r) {       return {tr[rt].first + tg, tr[rt].second};     }     int mid = l + r >> 1;     if (L > mid) {       return query(rt << 1 | 1, L, R, tg + lazy[rt], mid + 1, r);     } else if (R <= mid) {       return query(rt << 1, L, R, tg + lazy[rt], l, mid);     } else {       return max(query(rt << 1 | 1, mid + 1, R, tg + lazy[rt], mid + 1, r),                  query(rt << 1, L, mid, tg + lazy[rt], l, mid));     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].z);       if (a[i].x > a[i].y) swap(a[i].x, a[i].y);       b[++cnt] = a[i].x;       b[++cnt] = a[i].y;     }     sort(b + 1, b + cnt + 1);     cnt = unique(b + 1, b + cnt + 1) - (b + 1);     for (int i = 1; i <= n; i++) {       a[i].x = lower_bound(b + 1, b + cnt + 1, a[i].x) - b;       a[i].y = lower_bound(b + 1, b + cnt + 1, a[i].y) - b;     }     build(1, 1, cnt);     sort(a + 1, a + n + 1);     long long tx = 2e9, ty = 2e9;     for (int i = 1; i <= n; i++) {       update(1, 1, a[i].x, a[i].z, 1, cnt);       if (i < n && a[i].y == a[i + 1].y) continue;       pair<long long, int> tmp = query(1, 1, a[i].y, 0, 1, cnt);       if (tmp.first - b[a[i].y] > ans) {         ans = tmp.first - b[a[i].y];         tx = b[tmp.second];         ty = b[a[i].y];       }     }     printf( %lld n , ans);     printf( %lld %lld %lld %lld n , tx, tx, ty, ty);   }
#include <bits/stdc++.h>   using namespace std;   long long n, l, r, k;   bool checks(long long s) {     long long x = (k - r + l - 1) / (n + s);     long long sp = k - r + l - 1 - x * (n + s);     if (sp < r - l + 1) sp++;     if (sp > r - l + 1) {       return false;     }     if (s - sp > n - r + l - 1) {       return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> l >> r >> k;     if (l > r) r += n;     if (k < r - l + 1) {       cout <<  -1 ;       return 0;     }     if (n < 1e6) {       long long res = -1;       long long s = 0, sp = 0;       for (s = 0; s <= n; s++) {         if (checks(s)) res = s;       }       cout << res <<   n ;     } else {       long long res = -1;       long long m = k - r + l - 1;       for (long long x = 1; x < 1e6; x++) {         long long a, b;         a = (m - x * n - r + l - 1) / x;         b = (m - x * n + n - r + l) / (x + 1);         b = min(b, n);         if (a <= b && checks(b)) res = max(res, b);       }       long long sp = k - r + l - 1;       if (sp < r - l + 1) sp++;       if (sp >= 0 && sp <= r - l + 1) {         res = max(res, n - r + l - 1 + sp);       }       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      int num[26][5] = {       {1,0,0,1,0}, // a       {1,1,0,2,0}, // b       {2,0,0,1,1}, // c       {2,1,0,1,2}, // d       {1,1,0,1,1}, // e       {2,1,0,2,1}, // f       {2,2,0,2,2}, // g       {1,2,0,2,1}, // h       {1,1,0,1,1}, // i       {1,2,0,1,2}, // j       {1,0,1,2,0}, // k       {1,1,1,3,0}, // l       {2,0,1,2,1}, // m       {2,1,1,2,2}, // n       {1,1,1,2,1}, // o       {2,1,1,3,1}, // p       {2,2,1,3,2}, // q       {1,2,1,3,1}, // r       {1,1,1,2,1}, // s       {1,2,1,2,2}, // t       {1,0,2,2,1}, // u       {1,1,2,3,1}, // v       {1,2,1,1,3}, // w       {2,0,2,2,2}, // x       {2,1,2,2,3}, // y       {1,1,2,2,2}  // z   };      int main() {       int n;       cin >> n;       while (n--) {           int a, b, c, d, e;           cin >> a >> b >> c >> d >> e;           for (int i = 0; i < 26; ++i) {               if (a == num[i][0] && b == num[i][1] && c == num[i][2] && d == num[i][3] && e == num[i][4]) {                   cout << char(i +  a );                   break;               }           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long w, id;     bool friend operator<(node a, node b) {       if (a.w == b.w)         return a.id < b.id;       else         return a.w < b.w;     }   } a[1000004];   long long b[1000004][4];   long long l[1000004];   long long r[1000004];   int main() {     long long n, x;     cin >> n >> x;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i].w);       a[i].id = i;     }     sort(a + 1, a + 1 + n);     long long cnt = 1;     b[cnt][0] = b[cnt][1] = a[1].id;     b[cnt][3] = a[1].w;     for (int i = 2; i <= n; ++i) {       if (a[i].w == a[i - 1].w)         b[cnt][1] = a[i].id;       else {         cnt++;         b[cnt][0] = b[cnt][1] = a[i].id;         b[cnt][3] = a[i].w;       }     }     long long ans = 0;     long long base = 0;     long long lmax = 1;     long long rmin = cnt;     for (int i = 1; i <= cnt; ++i) {       if (b[i][0] > base) {         base = b[i][1];         l[i] = base;         lmax = i;       } else         break;     }     base = 1e9;     for (int i = cnt; i >= 1; --i) {       if (b[i][1] < base) {         base = b[i][0];         r[i] = base;         rmin = i;       } else         break;     }     if (lmax < rmin) {       for (int i = 1; i <= lmax; ++i) {         int pos = upper_bound(r + (int)rmin, r + (int)cnt + 1, l[i]) - r;         if (pos < cnt + 1)           ans += (b[cnt][3] - b[pos - 1][3]) * (b[i + 1][3] - b[i][3]);       }       cout << ans + (x - b[cnt][3] + 1) * b[lmax + 1][3] +                   (b[cnt][3] - b[rmin - 1][3]) * b[1][3];     } else {       cout << x * (x + 1) / 2 << endl;     }   }