malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   const int mod = 1000000007;   inline string getstr(string &s, int l, int r) {     string ret =   ;     for (int i = l; i <= r; i++) ret.push_back(s[i]);     return ret;   }   int modpow(int x, int y, int md = mod) {     if (y == 0) return 1;     int ret = modpow(x, y >> 1, md);     ret = (long long)ret * ret % md;     if (y & 1) ret = (long long)ret * x % md;     return ret;   }   string s, t;   int n;   int main() {     cin >> n >> s >> t;     int l, r;     for (l = 0;; l++) {       if (s[l] != t[l]) {         break;       }     }     for (r = n - 1;; r--) {       if (s[r] != t[r]) {         break;       }     }     int lft = 1, rgt = 1;     for (int i = l; i < r; i++) {       if (s[i] != t[i + 1]) lft = 0;       if (s[i + 1] != t[i]) rgt = 0;     }     cout << lft + rgt << endl;     return 0;   }
#include <bits/stdc++.h>   const int nax = 1e5 + 5;   using namespace std;   int gcd(int x, int y) {     if (x % y == 0) return y;     return gcd(y, x % y);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m;     cin >> n >> m;     vector<int> a(n + 1), b(m + 1);     for (int i = 0; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i <= m; i++) {       cin >> b[i];     }     if (n != m) {       if (n > m) {         if ((a[0] > 0 && b[0] > 0) || (a[0] < 0 && b[0] < 0)) {           puts( Infinity );         } else {           puts( -Infinity );         }       } else {         cout <<  0/1               <<   n ;       }       return 0;     } else {       int ans = gcd(a[0], b[0]);       if ((a[0] > 0 && b[0] > 0) || (a[0] < 0 && b[0] < 0))         cout << a[0] / ans <<  /  << b[0] / ans <<   n ;       else         cout << -abs(a[0] / ans) <<  /  << abs(b[0] / ans) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(int p) {     if (p == 2) return 1;     if (p % 2 == 0) return 0;     for (long long int i = 3; i * i <= p; i += 2) {       if (p % i == 0) return 0;     }     if (p > 2) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       int n;       cin >> n;       if (check(n)) {         cout <<  1  <<   n ;         cout << n <<   n ;         continue;       }       if (check(n - 2)) {         cout <<  2  <<   n ;         cout <<  2  <<     << n - 2 <<   n ;         continue;       }       cout <<  3  <<   n ;       int a;       for (int i = n; i > 3; i--) {         if (check(i)) {           a = i;           n -= a;           break;         }       }       cout << a <<    ;       for (int i = 2; i <= n; i++) {         if (check(i) && check(n - i)) {           cout << i <<     << n - i <<   n ;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   bool fd(int x, int y) {     if (x == y) return m[y] >= 2;     return m.find(y) != m.end();   }   int main() {     int n;     cin >> n;     for (int i = 0; i < (n); i++) {       int x;       cin >> x;       m[x]++;     }     int cnt = 0;     for (auto& xp : m) {       int x = xp.first;       for (int s = 1; s <= 30; s++) {         if ((1 << s) <= x) continue;         if (fd(x, (1 << s) - x)) goto cont;       }       cnt += xp.second;     cont:;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, l, a, v, b, n, m;     string s;     while (cin >> s) {       k = 0;       j = 0;       l = s.size();       for (i = 0; i < l; i++) {         if (s[i] ==  W  && s[i + 1] ==  U  && s[i + 2] ==  B ) {           i = i + 2;           if (k > 0) {             if (j == 1) cout <<    ;             j = 0;           }         } else {           cout << s[i];           j = 1;         }         k = 1;       }     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read();   int a[14250];   unsigned long long ans;   bool cmp(int a, int b) { return a < b; }   int main() {     int n = read(), k = read();     for (int i = 1; i <= n; i++) {       a[i] = read();     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= k; i++) {       ans += a[i];     }     cout << ans;     return 0;   }   inline int read() {     int x = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * w;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1000009];   int in[1000009], out[1000009];   bool vs[22][1000009];   void dfs(int x, int n) {     vs[x][n] = 1;     for (auto& it : adj[n])       if (!vs[x][it]) dfs(x, it);   }   int main() {     int N, M;     scanf( %d%d , &N, &M);     while (M--) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       in[v]++;       out[u]++;     }     vector<int> src, snk;     for (int i = 1; i <= N; i++) {       if (in[i] == 0) src.push_back(i);       if (out[i] == 0) snk.push_back(i);     }     int s = src.size();     for (int i = 0; i < s; i++) {       dfs(i, src[i]);     }     for (int i = 1; i < (1 << s) - 1; i++) {       set<int> st;       int c = 0;       for (int j = 0; j < s; j++) {         if (i & (1 << j)) {           ++c;           for (auto& it : snk)             if (vs[j][it]) st.insert(it);         }       }       if (c >= (int)st.size()) return !printf( NO );     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char z[500005];   int Qs1[500005], b, Qs2[500005];   int f(char a) {     if (a ==  w ) return b + 1;     return 1;   }   int main() {     int i, j, n, a, t, Max = 0;     int *qs2 = Qs2 + 1, *qs1 = Qs1 + 1;     scanf( %d %d %d %d  , &n, &a, &b, &t);     gets(z);     qs1[0] = f(z[0]);     for (i = 1; i < n; i++) {       qs1[i] = a + f(z[i]) + qs1[i - 1];     }     for (i = n - 1; i >= 0; i--) {       qs2[n - 1 - i] = a + f(z[i]) + qs2[n - 2 - i];     }     for (i = 0; i < n; i++) {       if (qs1[i] <= t) Max = max(min(i + 1, n), Max);       if (qs2[i] + qs1[0] <= t) Max = max(min(i + 2, n), Max);     }     for (i = 0; i < n; i++) {       int tmp = lower_bound(qs2, qs2 + n, t - qs1[i] - a * i) - qs2;       if (t - qs1[i] - a * i < qs2[tmp]) tmp--;       if (tmp == -1) continue;       Max = max(min(tmp + i + 2, n), Max);     }     for (i = 0; i < n; i++) {       int tmp = lower_bound(qs1, qs1 + n, t - qs2[i] - a * i - a) - qs1;       if (t - qs2[i] - a * i - a < qs1[tmp]) tmp--;       if (tmp == -1) continue;       Max = max(min(tmp + i + 2, n), Max);     }     printf( %d , Max);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105][105], c[105], r[105];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         c[j] += a[i][j];         r[i] += a[i][j];       }     int co = 0;     set<int> sc, sr;     set<int>::iterator it;     while (co <= 10) {       for (int i = 1; i <= n; i++)         if (r[i] < 0) {           if (sr.find(i) != sr.end())             sr.erase(sr.find(i));           else             sr.insert(i);           r[i] = -r[i];           for (int j = 1; j <= m; j++) c[j] -= 2 * a[i][j];           for (int j = 1; j <= m; j++) a[i][j] = -a[i][j];         }       for (int j = 1; j <= m; j++)         if (c[j] < 0) {           if (sc.find(j) != sc.end())             sc.erase(sc.find(j));           else             sc.insert(j);           c[j] = -c[j];           for (int i = 1; i <= n; i++) r[i] -= 2 * a[i][j];           for (int i = 1; i <= n; i++) a[i][j] = -a[i][j];         }       co++;     }     cout << sr.size() <<    ;     for (it = sr.begin(); it != sr.end(); it++) cout << *it <<    ;     cout << endl;     cout << sc.size() <<    ;     for (it = sc.begin(); it != sc.end(); it++) cout << *it <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 5;   const double pi = acos(-1.0);   long long addM(long long a, long long b) { return (a + b) % MOD; }   long long multM(long long a, long long b) { return (a * b) % MOD; }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   long long ModInverse(long long n) { return binpow(n, MOD - 2); }   vector<long long> findFact() {     vector<long long> fact(N);     fact[0] = 1;     for (long long i = 1; i <= N; i++) {       fact[i] = multM(i, fact[i - 1]);     }     return fact;   }   long long ncr(long long n, long long r) {     vector<long long> fact = findFact();     return ((fact[n] * ModInverse(fact[n - r])) % MOD * ModInverse(fact[r])) %            MOD;   }   vector<bool> findPrime() {     vector<bool> is_prime(N + 1, true);     is_prime[0] = false;     is_prime[1] = false;     for (long long i = 2; i <= N; i++) {       if (is_prime[i] && i * i <= N) {         for (long long j = i * i; j <= N; j += i) is_prime[j] = false;       }     }     return is_prime;   }   vector<bool> segmentedSieveNoPreGen(long long L, long long R) {     vector<bool> isPrime(R - L + 1, true);     long long lim = sqrt(R);     for (long long i = 2; i <= lim; ++i)       for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)         isPrime[j - L] = false;     if (L == 1) isPrime[0] = false;     return isPrime;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       string x, y;       cin >> x >> y;       bool check = true;       for (long long i = 0; i < n; i++) {         if (x[i] > y[i]) {           check = false;         }       }       if (check) {         long long ans = 0;         for (char c =  a ; c <=  z ; c++) {           char mn =  z ;           bool check = false;           for (long long i = 0; i < n; i++) {             if (x[i] == c && x[i] != y[i]) {               check = true;               mn = min(mn, y[i]);             }           }           for (long long i = 0; i < n; i++) {             if (x[i] == c && x[i] != y[i]) {               x[i] = mn;             }           }           if (check) ans++;         }         cout << ans <<   n ;       } else {         cout <<  -1 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unrolled-loops )   using namespace std;   const long long mod = 1e9 + 7;   int test = 1;   const int N = 100100;   long long n;   int k = 1;   long long x = 1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n > 9) {       n -= 9;       k++;       x *= 10;     }     if (n > 180) {       n -= 180;       k++;       x *= 10;     }     if (n > 2700) {       n -= 2700;       k++;       x *= 10;     }     if (n > 36000) {       n -= 36000;       k++;       x *= 10;     }     if (n > 450000) {       n -= 450000;       k++;       x *= 10;     }     if (n > 5400000) {       n -= 5400000;       k++;       x *= 10;     }     if (n > 63000000) {       n -= 63000000;       k++;       x *= 10;     }     if (n > 720000000) {       n -= 720000000;       k++;       x *= 10;     }     if (n > 8100000000) {       n -= 8100000000;       k++;       x *= 10;     }     if (n > 90000000000) {       n -= 90000000000;       k++;       x *= 10;     }     if (n > 990000000000) {       n -= 990000000000;       k++;       x *= 10;     }     long long m, l;     m = n / k;     l = n % k;     x += m - 1;     if (l == 0)       cout << x % 10;     else {       x++;       while (k > l) {         k--;         x /= 10;       }       cout << x % 10;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   int a[N], nx[N];   long long pr[N];   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i + n] = a[i];     for (int i = 1; i <= n + n; i++) pr[i] = pr[i - 1] + a[i];     while (q--) {       long long b;       scanf( %lld , &b);       int now = 1;       int mx = n + n + 1, id;       for (int i = 1; i <= n + n; i++) {         while (now <= n + n && pr[i - 1] + b >= pr[now]) now++;         nx[i] = now;         if (nx[i] - i >= n) nx[i] = i + n;         if (nx[i] <= n + n && mx > nx[i] - i) {           mx = nx[i] - i;           id = i;         }       }       int ans = n + n;       for (int i = id; i < nx[id]; i++) {         int p = i;         int res = 0;         while (p < i + n) {           res++;           if (nx[p] > i + n && res > 1) {             if (pr[i + n - 1] - pr[p - 1] + pr[nx[i] - 1] - pr[i - 1] <= b) res--;           }           p = nx[p];         }         ans = min(ans, res);       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q;   char s[N];   struct node {     int s, x, z, xz, zy, d;   } tr[N << 2];   void upd(int o) {     int S = tr[(o << 1)].s, lx = tr[(o << 1)].x, lz = tr[(o << 1)].z,         lxz = tr[(o << 1)].xz, lzy = tr[(o << 1)].zy;     int rx = tr[(o << 1 | 1)].x + S, rz = tr[(o << 1 | 1)].z - 2 * S,         rxz = tr[(o << 1 | 1)].xz - S, rzy = tr[(o << 1 | 1)].zy - S;     tr[o].s = S + tr[(o << 1 | 1)].s;     tr[o].x = max(lx, rx), tr[o].z = max(lz, rz);     tr[o].xz = max(max(lxz, rxz), lx + rz);     tr[o].zy = max(max(lzy, rzy), lz + rx);     tr[o].d =         max(max(tr[(o << 1)].d, tr[(o << 1 | 1)].d), max(lxz + rx, lx + rzy));   }   void mdf(int o, int l, int r, int p, int c) {     if (l == r) {       tr[o] = {c, c, -2 * c, -c, -c, 0};       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       mdf((o << 1), l, mid, p, c);     else       mdf((o << 1 | 1), mid + 1, r, p, c);     upd(o);   }   int main() {     scanf( %d%d%s , &n, &q, s + 1);     for (int i = (1); i <= (2 * n - 2); ++i)       mdf(1, 1, 2 * n - 2, i, s[i] ==  (  ? 1 : -1);     printf( %d n , tr[1].d);     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       swap(s[x], s[y]);       mdf(1, 1, 2 * n - 2, x, s[x] ==  (  ? 1 : -1);       mdf(1, 1, 2 * n - 2, y, s[y] ==  (  ? 1 : -1);       printf( %d n , tr[1].d);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   long long n, k;   bool solveIt(long long d1, long long d2) {     if ((k - d1 + d2) % 3 != 0) return false;     long long Y = (k - d1 + d2) / 3;     long long X = d1 + Y;     long long Z = Y - d2;     if (X >= 0 && Y >= 0 && Z >= 0 && X <= k && Y <= k && Z <= k &&         X <= (n / 3) && Y <= (n / 3) && Z <= (n / 3) && abs(X - Y) == abs(d1) &&         abs(Y - Z) == abs(d2))       return true;     return false;   }   int main() {     std::ios_base::sync_with_stdio(0);     long long t, d2, d1;     cin >> t;     while (t--) {       bool flg = false;       cin >> n >> k >> d1 >> d2;       if (n % 3 != 0) {         cout <<  no  << endl;         continue;       }       if (solveIt(d1, d2)) flg = true;       if (solveIt(d1, -d2)) flg = true;       if (solveIt(-d1, d2)) flg = true;       if (solveIt(-d1, -d2)) flg = true;       if (flg)         cout <<  yes  << endl;       else         cout <<  no  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > v;     for (int i = 0; i < m; i++) {       long long a, b;       cin >> b >> a;       v.push_back(make_pair(a, b));     }     sort(v.rbegin(), v.rend());     long long total = 0, i = 0, count = 0;     while (i < m && (count + v[i].second) <= n) {       total += v[i].first * v[i].second;       count += v[i].second;       i++;     }     if (i != m) total += v[i].first * (n - count);     cout << total << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 1000005;   int SetBit(int n, int x) { return n | (1 << x); }   int ClearBit(int n, int x) { return n & ~(1 << x); }   int ToggleBit(int n, int x) { return n ^ (1 << x); }   bool CheckBit(int n, int x) { return (bool)(n & (1 << x)); }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int w, y, max;     cin >> w >> y;     int a;     if (w > y) {       max = w;     } else if (w == y) {       max = w;     } else {       max = y;     }     if ((w == 6 && y == 6)) {       cout <<  1             <<  /             <<  6  << endl;     } else if ((w == 6 && (y == 1 || y == 2 || y == 3 || y == 4 || y == 5))) {       cout <<  1             <<  /             <<  6  << endl;     } else if ((y == 6 && (w == 1 || w == 2 || w == 3 || w == 4 || w == 5))) {       cout <<  1             <<  /             <<  6  << endl;     } else {       a = 6 - max + 1;       if (a == 2) {         cout <<  1               <<  /               <<  3  << endl;       }       if (a == 3) {         cout <<  1               <<  /               <<  2  << endl;       }       if (a == 4) {         cout <<  2               <<  /               <<  3  << endl;       }       if (a == 5 || a == 1) {         cout << a <<  /               <<  6  << endl;       }       if (a == 6) {         cout <<  1               <<  /               <<  1  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max(int &a, int &b) { return (a > b ? a : b); }   unsigned long long max(unsigned long long &a, unsigned long long &b) {     return (a > b ? a : b);   }   int min(int &a, int &b) { return (a < b ? a : b); }   long long int bits_needed(long long int val) {     long long int count = 0;     while (val) count++, val >>= 1;     return count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 0, n = 0, i = 0;     long long int val = 0, prev = 0, ans = 0;     cin >> t;     while (t-- > 0) {       ans = 0;       cin >> n;       cin >> prev;       for (i = 1; i < n; i++) {         cin >> val;         if (val < prev) {           ans = max(ans, bits_needed(prev - val));         } else           prev = val;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d, sum, ans;   char s[105];   int main() {     scanf( %d %d , &n, &d);     for (int i = 0; i < d; i++) {       scanf( %s , s);       bool ok = true;       for (int j = 0; j < n; j++)         if (s[j] ==  0 ) ok = false;       if (ok)         sum = 0;       else         sum++, ans = max(ans, sum);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5000005;   using ll = long long;   ll f[N], pre[N];   int n, a[N];   vector<int> ans;   void move(int x) {     if (x == n || a[x] == 0 || a[x + 1] == 0) return;     ans.push_back(x);     int t = min(a[x], a[x + 1]);     a[x] -= t;     a[x + 1] -= t;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     f[2] = a[1];     for (int i = 3; i <= n + 1; i++)       if (f[i - 3] + max(a[i - 1], a[i - 2]) < f[i - 2] + a[i - 1])         f[i] = f[pre[i] = i - 3] + max(a[i - 1], a[i - 2]);       else         f[i] = f[pre[i] = i - 2] + a[i - 1];     for (int i = f[n] < f[n + 1] ? n : n + 1; i > 1; i = pre[i])       if (pre[i] == i - 3) {         move(i - 2), move(i - 1);         if (i > 3) move(i - 3);       } else {         move(i - 1);         if (i > 2) move(i - 2);       }     cout << ans.size() << endl;     for (auto &i : ans) cout << i << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int ReadInt() {     int i = 0;     char c = 0;     char flag = 1;     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       flag = 0;       c = getchar();     }     for (; c >=  0  && c <=  9 ; c = getchar()) i = i * 10 + c -  0 ;     if (!flag) i = -i;     return i;   }   inline void WriteInt(int n) {     if (n < 0) {       putchar( - );       WriteInt(-n);       return;     }     if (n < 10)       putchar(n +  0 );     else {       WriteInt(n / 10);       putchar(n % 10 +  0 );     }   }   int n, m;   int top;   long long ans, sum, last;   int A[100100];   int tmp;   int main() {     scanf( %i%i , &n, &m);     for (int i = 0; i < n; i++) scanf( %i , &A[i]), sum += A[i];     sort(A, A + n);     int top = 0;     for (int i = 0; i < n; i++)       if (A[i] > top)         ans++, top++;       else         ans++;     ans += A[n - 1] - top;     printf( %I64d , sum - ans);     putc(  n , stdout);   }
#include <bits/stdc++.h>   using namespace std;   int Matrix[1002][2002];   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int distance(int a, int b, int c) {     int first, second;     first = a < b ? b - a : a - b;     second = b < c ? c - b : b - c;     return first + second;   }   int main() {     int n, k, p;     int person[1005];     int key[2002];     cin >> n >> k >> p;     for (int i = 1; i <= n; i++) cin >> person[i];     for (int i = 1; i <= k; i++) cin >> key[i];     sort(person + 1, person + n + 1);     sort(key + 1, key + k + 1);     for (int i = 1; i <= n; i++) {       for (int j = i; j <= k; j++) {         if (i == j) {           Matrix[i][j] =               max(Matrix[i - 1][j - 1], distance(person[i], key[i], p));         } else {           Matrix[i][j] =               min(Matrix[i][j - 1],                   max(Matrix[i - 1][j - 1], distance(person[i], key[j], p)));         }       }     }     int ans = 2e9;     for (int i = n; i <= k; i++) ans = min(ans, Matrix[n][i]);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   void fun(int arr[], int n) {     stack<int> s;     int left[n + 1];     int right[n + 1];     for (int i = 0; i < n; i++) {       left[i] = -1;       right[i] = n;     }     for (int i = 0; i < n; i++) {       while (!s.empty() && arr[s.top()] >= arr[i]) s.pop();       if (!s.empty()) left[i] = s.top();       s.push(i);     }     while (!s.empty()) s.pop();     for (int i = n - 1; i >= 0; i--) {       while (!s.empty() && arr[s.top()] >= arr[i]) s.pop();       if (!s.empty()) right[i] = s.top();       s.push(i);     }     int ans[n + 1];     for (int i = 0; i <= n; i++) ans[i] = 0;     for (int i = 0; i < n; i++) {       int len = right[i] - left[i] - 1;       ans[len] = max(ans[len], arr[i]);     }     for (int i = n - 1; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t, n, k;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     fun(arr, n);     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   int K;   int main() {     scanf( %d , &K);     if (K % 2) {       puts( YES );       if (K == 1) {         puts( 2 1 n1 2 );         return 0;       }       int i, j, N = (K << 1) + 4,                 M = (3 * K - 2 + (K - 1) * (K - 2) / 2 - K / 2) * 2 + 1,                 tmp1 = K + 1, tmp2 = K + 2;       printf( %d %d n , N, M);       for (i = 1; i < K; i++)         printf( %d %d n%d %d n%d %d n%d %d n%d %d n%d %d n , K, i, K + tmp2,                i + tmp2, tmp1, i, tmp1 + tmp2, i + tmp2, tmp2, i, tmp2 << 1,                i + tmp2);       printf( %d %d n%d %d n , tmp1, tmp2, tmp1 + tmp2, tmp2 << 1);       int lim = K - 1;       for (i = 1, tmp1 = K >> 1; i < lim; i++)         for (j = i + 1; j < K; j++)           if (j != i + tmp1) printf( %d %d n%d %d n , i, j, i + tmp2, j + tmp2);       printf( %d %d n , K, K + tmp2);     } else       puts( NO );     return 0;   }