malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long double add[3 * 100 * 1000];   const long double inf = 1e18;   long double max(long double a, long double b, long double c, long double d) {     return max(max(a, b), max(c, d));   }   struct rmq {     int l, r;     long double pref, suf, all, best;     rmq *left, *right;   };   rmq *build(int l, int r) {     rmq *root = (rmq *)malloc(sizeof(rmq));     root->l = l;     root->r = r;     if (l == r) {       root->left = root->right = NULL;       root->suf = max((long double)0, add[l]);       root->pref = root->suf;       root->all = add[l];       root->best = root->suf;     } else {       root->left = build(l, (l + r) / 2);       root->right = build((l + r) / 2 + 1, r);       root->all = root->left->all + root->right->all;       root->pref = max(root->left->pref, root->left->all + root->right->pref);       root->suf = max(root->right->suf, root->left->suf + root->right->all);       root->best = max(root->left->best, root->right->best,                        root->left->suf + root->right->pref, root->all);     }     return root;   }   void get(int l, int r, rmq *root, long double &pref, long double &suf,            long double &all, long double &best) {     if (root->l == l && root->r == r) {       pref = root->pref;       suf = root->suf;       all = root->all;       best = root->best;       return;     }     long double prefL = -inf, prefR = -inf, sufL = -inf, sufR = -inf, allL = -inf,                 allR = -inf, bestL = -inf, bestR = -inf;     if (root->left && root->left->r >= l)       get(l, min(r, root->left->r), root->left, prefL, sufL, allL, bestL);     if (root->right && root->right->l <= r)       get(max(root->right->l, l), r, root->right, prefR, sufR, allR, bestR);     pref = max(prefL, allL + prefR);     suf = max(sufR, allR + sufL);     all = allL + allR;     best = max(bestL, bestR, prefR + sufL, all);   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     int n, m, c;     cin >> n >> m >> c;     long long x[n];     for (int i = 0; i < n; ++i) cin >> x[i];     long double p[n];     for (int i = 1; i < n; ++i) {       cin >> p[i];       p[i] /= 100.0;     }     add[0] = 0;     for (int i = 1; i < n; ++i) add[i] = 0.5 * (x[i] - x[i - 1]) - c * p[i];     rmq *root = build(0, n - 1);     long double res = 0;     long double best, all, suf, pref;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --b;       get(a, b, root, pref, suf, all, best);       res += best;     }     cout << res;     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mod = 998244353;   const int inv2 = (mod + 1) / 2;   int n, m, k;   int row_one[N], row_zero[N], col_one[N], col_zero[N];   int all_one, all_zero;   int zero_r, zero_c, mul_r, mul_c;   map<pair<int, int>, int> Map;   int rval(int x) {     if (row_one[x] > 0 && row_zero[x] > 0) return 0;     if (row_one[x] == 0 && row_zero[x] == 0) return 2;     return 1;   }   int cval(int x) {     if (col_one[x] > 0 && col_zero[x] > 0) return 0;     if (col_one[x] == 0 && col_zero[x] == 0) return 2;     return 1;   }   void upd(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int Qpow(int x, int p) {     int ans = 1;     while (p) {       if (p & 1) ans = 1LL * x * ans % mod;       x = 1LL * x * x % mod;       p >>= 1;     }     return ans;   }   int main() {     cin >> n >> m >> k;     mul_r = Qpow(2, n);     mul_c = Qpow(2, m);     for (int i = 1; i <= k; ++i) {       int x, y, t;       scanf( %d%d%d , &x, &y, &t);       int v_c = cval(y);       int v_r = rval(x);       if (v_c == 0) --zero_c;       if (v_r == 0) --zero_r;       if (v_c == 2) mul_c = 1LL * mul_c * inv2 % mod;       if (v_r == 2) mul_r = 1LL * mul_r * inv2 % mod;       if (Map[make_pair(x, y)] != 0) {         int p = Map[make_pair(x, y)];         --p;         if ((x + y) % 2 == 1) p ^= 1;         if (p == 0)           --all_zero;         else           --all_one;         if ((x + y) % 2 == 1) p ^= 1;         if (y % 2 == 0) p ^= 1;         if (p == 0)           --row_zero[x];         else           --row_one[x];         if (y % 2 == 0) p ^= 1;         if (x % 2 == 0) p ^= 1;         if (p == 0)           --col_zero[y];         else           --col_one[y];         if (x % 2 == 0) p ^= 1;       }       if (t == -1) {         Map[make_pair(x, y)] = 0;       } else {         Map[make_pair(x, y)] = t + 1;         int p = t;         if ((x + y) % 2 == 1) p ^= 1;         if (p == 0)           ++all_zero;         else           ++all_one;         if ((x + y) % 2 == 1) p ^= 1;         if (y % 2 == 0) p ^= 1;         if (p == 0)           ++row_zero[x];         else           ++row_one[x];         if (y % 2 == 0) p ^= 1;         if (x % 2 == 0) p ^= 1;         if (p == 0)           ++col_zero[y];         else           ++col_one[y];         if (x % 2 == 0) p ^= 1;       }       v_c = cval(y);       v_r = rval(x);       if (v_c == 0) ++zero_c;       if (v_r == 0) ++zero_r;       if (v_c == 2) mul_c = 2LL * mul_c % mod;       if (v_r == 2) mul_r = 2LL * mul_r % mod;       int ans = 0;       if (zero_r == 0) upd(ans, mul_r);       if (zero_c == 0) upd(ans, mul_c);       if (zero_r == 0 && zero_c == 0) {         if (all_one == 0) --ans;         if (all_zero == 0) --ans;         upd(ans, mod);       }       printf( %d n , ans);     }     return 0;   }
#include <algorithm>   #include <cassert>   #include <cmath>   #include <cstdlib>   #include <cstring>   #include <iomanip>   #include <iostream>   #include <limits>   #include <map>   #include <numeric>   #include <queue>   #include <random>   #include <set>   #include <stack>   #include <unordered_map>   #include <unordered_set>   #include <vector>   using namespace std;      using LL = long long;      int Rev(int a, int k) {     vector<int> x;     while (a > 0) {       x.push_back((k - a % k) % k);       a /= k;     }     reverse(x.begin(), x.end());     int ans = 0;     for (int i : x) ans = ans * k + i;     return ans;   }      int Xor(int a, int b, int k) {     vector<int> x;     while (a > 0 || b > 0) {       x.push_back((a + b) % k);       a /= k;       b /= k;     }     reverse(x.begin(), x.end());     int ans = 0;     for (int i : x) ans = ans * k + i;     return ans;   }      int main() {     ios::sync_with_stdio(false);     int times;     cin >> times;     while (times--) {       int n, k;       cin >> n >> k;       vector<int> x {0, Rev(1, k)};       for (int i = 2; i < n; i += 2) {         x.push_back(Xor(i, Rev(i - 1, k), k));         x.push_back(Xor(i, Rev(i + 1, k), k));       }       for (int i = 0; i < n; ++i) {         cout << x[i] << endl;         int r;         cin >> r;         if (r == 1) break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long st(long long b, long long d) {     long long a, a1 = b, i;     for (i = 1, a = b; a <= d && d % a == 0; ++i) a1 = a, a *= b;     return a1;   }   long long type(long long b, long long d, long long& res) {     long long g = gcd(b, d), i, a;     if (g > 1) {       for (i = 1, a = g; a < 100500000000; ++i, a *= g)         if (a % d == 0) {           res = i;           return 2;         }     }     if (b % d == 1) return 3;     if ((b + 1) % d == 0) return 11;     return 0;   }   int main() {     long long i, n, j, a, b, d;     cin >> b >> d;     long long res, tp = type(b, d, res);     if (tp > 0) {       cout << tp <<  -type  << endl;       if (tp == 2) cout << res;       return 0;     }     for (i = 2; i <= d; ++i)       if (d % i == 0)         if (type(b, st(i, d), res) > 0) {           d /= st(i, d);         } else {         }     if (d == 1) {       cout <<  6-type ;       return 0;     }     cout <<  7-type ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const int maxm = 2005;   struct detail {     int c[maxm];     int len;     int p;     detail() { len = 0; }     void add(int i) {       c[len] = i;       ++len;     }   } details[maxn];   int order[maxn];   int n, m;   bool cmp(const int a, const int b) { return details[a].p > details[b].p; }   int main(int argc, const char* argv[]) {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       order[i] = i;       cin >> details[i].p;     }     for (int i = 0; i < m; ++i) {       int x = 1, y = 1;       cin >> x >> y;       x--;       y--;       details[x].add(y);       details[y].add(x);     }     sort(order, order + n, cmp);     long long a = 0;     for (int i = 0; i < n; ++i) {       int o = order[i];       for (int j = 0; j < details[o].len; ++j) {         a += details[details[o].c[j]].p;       }       details[o].p = 0;     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long a, b;     cin >> a >> b;     long long c = 1, i = 0;     while (1) {       if (i % 2 == 0 && a >= c)         a -= c;       else if (i & 1 && b >= c)         b -= c;       else         break;       c++;       i++;     }     if (i & 1)       cout <<  Valera n ;     else       cout <<  Vladik n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, N[5010], e, s, X[5010], A[5010], B[5010], C[5010], D[5010];   long long int total, t, selection;   long long int Dis(long long int x, long long int y) {     return labs(X[x] - X[y]) + (x > y ? C[x] + B[y] : D[x] + A[y]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> s >> e;     for (int i = 1; i <= n; i++) cin >> X[i];     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++) cin >> B[i];     for (int i = 1; i <= n; i++) cin >> C[i];     for (int i = 1; i <= n; i++) cin >> D[i];     N[s] = e;     total = Dis(s, e);     for (int i = 1; i <= n; i++) {       if (i == s || i == e) continue;       long long int l = LLONG_MAX;       for (int j = s; j != e; j = N[j]) {         t = Dis(j, i) + Dis(i, N[j]) - Dis(j, N[j]);         if (t < l) {           l = t;           selection = j;         }       }       total += l;       N[i] = N[selection];       N[selection] = i;     }     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct obj {     int x, y, ind;     obj(int x, int y, int ind) : x(x), y(y), ind(ind) {}     obj() {}   };   int main() {     vector<obj> s;     int n, x, y;     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       scanf( %d%d , &x, &y);       s.push_back(obj(x, y, i));     }     sort(s.begin(), s.end(), [](obj a, obj b) {       if (a.x / 1000 == b.x / 1000) {         if (a.x / 1000 % 2 == 0)           return a.y < b.y;         else           return a.y > b.y;       }       return a.x / 1000 < b.x / 1000;     });     for (auto v : s) printf( %d  , v.ind);     return 0;   }
#include <bits/stdc++.h>   void err() { std::cout <<   n ; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   void pt() { std::cout <<   n ; }   template <typename T, typename... Args>   void pt(T a, Args... args) {     std::cout << a <<    ;     pt(args...);   }   using namespace std;   const int N = 5000 + 5, MOD = 1e9 + 7;   int qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return res;   }   int inv(int x) { return qpow(x, MOD - 2); }   int n, m;   int a[N];   int f[N], h[N];   int x[N], y[N];   int l[N], r[N];   vector<int> v[N];   void run() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ++r[a[i]];     }     for (int i = 1; i <= m; i++) {       cin >> f[i] >> h[i];       v[f[i]].push_back(h[i]);     }     for (int i = 1; i <= n; i++) sort((v[i]).begin(), (v[i]).end());     pair<int, int> ans(0, 0);     auto upd = [&](int x, int y) {       if (x > ans.first) ans = make_pair(x, 0);       if (x == ans.first) ans.second = (ans.second + y) % MOD;     };     auto calc = [&](int i) {       int a = upper_bound((v[i]).begin(), (v[i]).end(), l[i]) - v[i].begin();       int b = upper_bound((v[i]).begin(), (v[i]).end(), r[i]) - v[i].begin();       if (a > b) swap(a, b);       int cnt1 = 1ll * a * (b - 1) % MOD, cnt2 = a + b;       if (cnt1 > 0) {         x[i] = 2;         y[i] = cnt1;       } else if (cnt2 > 0) {         x[i] = 1;         y[i] = cnt2;       } else {         x[i] = 0;         y[i] = 1;       }     };     int tx = 0, ty = 1;     for (int i = 1; i <= n; i++) {       calc(i);       tx += x[i];       ty = 1ll * ty * y[i] % MOD;     }     upd(tx, ty);     for (int i = 1; i <= n; i++) {       int now = a[i];       tx -= x[now];       ty = 1ll * ty * inv(y[now]) % MOD;       ++l[now], --r[now];       if (binary_search((v[now]).begin(), (v[now]).end(), l[now])) {         int t = upper_bound((v[now]).begin(), (v[now]).end(), r[now]) -                 v[now].begin();         if (r[now] >= l[now]) --t;         if (t > 0) {           x[now] = 2;           y[now] = t;         } else {           x[now] = y[now] = 1;         }         int nx = tx + x[now], ny = 1ll * ty * y[now] % MOD;         upd(nx, ny);       }       calc(now);       tx += x[now];       ty = 1ll * ty * y[now] % MOD;     }     cout << ans.first <<     << ans.second <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(20);     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e6;   int a[N];   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       a[tmp]++;     }     int res = 0;     for (int i = 0; i < N; ++i) {       if (a[i] % 2) ++res;       a[i + 1] += (a[i] / 2);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     int even = 0, odd = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) {         even++;       } else {         odd++;       }     }     if (even > odd) {       cout << odd << endl;     } else {       cout << even << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long>> a;   vector<long long> get_res(long long m) {     vector<long long> res;     for (long long i = 0; i < a.size(); ++i) {       long long el = a[i].second;       long long c = a[i].first;       long long t = 0;       while ((c / (t + 1)) >= m) {         t++;         res.push_back(el);       }     }     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> s(n);     for (long long i = 0; i < n; ++i) cin >> s[i];     vector<long long> cnt(2e5 + 10);     for (long long i = 0; i < n; ++i) cnt[s[i]]++;     vector<pair<long long, long long>> v;     for (long long i = 0; i < cnt.size(); ++i) v.emplace_back(cnt[i], i);     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (long long i = 0; i < v.size(); ++i) {       if (v[i].first > 0) {         a.push_back(v[i]);       }     }     long long l = 1;     long long r = n + 1;     while (l + 1 < r) {       long long m = (l + r) / 2;       if (get_res(m).size() >= k)         l = m;       else         r = m;     }     auto res = get_res(l);     for (long long i = 0; i < k; ++i) cout << res[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int a, b;     cin >> a >> b;     if (a == 9 and b == 1) {       cout << 9 <<     << 10;     } else if (a == b) {       cout << a * 10 <<     << a * 10 + 1;     } else if (b - a == 1) {       cout << a * 10 + 9 <<     << b * 10 << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};   int h, w;   string in[1000];   void put(int y1, int x1, int y2, int x2) {     bool use[10] = {};     for (int d = 0; d < 4; d++) {       int y = y1 + dy[d], x = x1 + dx[d];       if (y < 0 || x < 0 || y >= h || x >= w || !isdigit(in[y][x])) continue;       use[in[y][x] -  0 ] = 1;     }     for (int d = 0; d < 4; d++) {       int y = y2 + dy[d], x = x2 + dx[d];       if (y < 0 || x < 0 || y >= h || x >= w || !isdigit(in[y][x])) continue;       use[in[y][x] -  0 ] = 1;     }     for (int i = 0; i < 10; i++)       if (!use[(y1 + x1 * 3 + i) % 10]) {         in[y1][x1] = in[y2][x2] =  0  + (y1 + x1 * 3 + i) % 10;         break;       }   }   int get(int y, int x, int c, bool paint) {     if (paint)       in[y][x] =  0  + c;     else       in[y][x] =  - ;     for (int d = 0; d < 4; d++) {       int ny = y + dy[d], nx = x + dx[d];       if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;       if (!paint && isdigit(in[ny][nx])) c = in[ny][nx] -  0 ;       if (paint && in[ny][nx] ==  -  || !paint && in[ny][nx] ==  . )         get(ny, nx, c, paint);     }     return c;   }   void run() {     cin >> h >> w;     for (int i = 0; i < h; i++) cin >> in[i];     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++) {         if (j < w - 1 && in[i][j] ==  .  && in[i][j + 1] ==  . )           put(i, j, i, j + 1);         if (i < h - 1 && in[i][j] ==  .  && in[i + 1][j] ==  . )           put(i, j, i + 1, j);       }     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++)         if (in[i][j] ==  . ) {           int c = get(i, j, -1, 0);           if (c < 0) {             cout << -1 << endl;             return;           }           get(i, j, c, 1);         }     for (int i = 0; i < h; i++) cout << in[i] << endl;   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105], b[105], n, k;   bool f[105];   void dfs(int i) {     f[i] = true;     for (int k = 1; k <= n; k++) {       if (f[k]) continue;       if (a[i] > a[k] && a[i] < b[k])         dfs(k);       else if (b[i] > a[k] && b[i] < b[k])         dfs(k);     }   }   void setup() { cin >> k; }   void work() {     while (k--) {       int x, y, m;       cin >> m;       if (m == 1) {         n++;         cin >> a[n] >> b[n];       } else {         cin >> x >> y;         memset(f, 0, sizeof(f));         dfs(x);         if (f[y])           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     setup();     work();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010, LOG = 20;   long long n, m, k, u, v, x, y, t, l, r, ans;   long long S[MAXN], M[MAXN], R[MAXN], D[MAXN];   int Mn[MAXN << 2], Mx[MAXN << 2], lazy[MAXN << 2];   vector<pair<int, int> > seg[MAXN << 2];   vector<long long> ps1[MAXN << 2], ps2[MAXN << 2];   void Build(int id, int tl, int tr) {     if (tr - tl == 1) {       seg[id].push_back({D[tl], tl});       ps1[id].push_back(0);       ps1[id].push_back(R[tl]);       ps2[id].push_back(M[tl]);       ps2[id].push_back(0);       return;     }     int mid = (tl + tr) >> 1;     Build(id << 1, tl, mid);     Build(id << 1 | 1, mid, tr);     seg[id].resize(tr - tl);     ps1[id].resize(tr - tl + 1, 0);     ps2[id].resize(tr - tl + 1, 0);     merge(seg[id << 1].begin(), seg[id << 1].end(), seg[id << 1 | 1].begin(),           seg[id << 1 | 1].end(), seg[id].begin());     ps1[id][0] = ps2[id][tr - tl] = 0;     for (int i = 0; i < tr - tl; i++)       ps1[id][i + 1] = ps1[id][i] + M[seg[id][i].second];     for (int i = tr - tl; i; i--)       ps2[id][i - 1] = ps2[id][i] + R[seg[id][i - 1].second];   }   void add_lazy(int id, int val) { lazy[id] = Mn[id] = Mx[id] = val; }   void shift(int id) {     if (!lazy[id]) return;     add_lazy(id << 1, lazy[id]);     add_lazy(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   void query(int id, int tl, int tr, int l, int r, int t) {     if (tr <= l || r <= tl) return;     if (l <= tl && tr <= r && Mn[id] == Mx[id] &&         (Mn[id] != -1 || tr - tl == 1)) {       long long time = t - Mn[id];       int shit = (Mn[id] == -1);       add_lazy(id, t);       if (tr - tl == 1) {         time -= shit;         ans += min(M[tl], S[tl] + R[tl] * time);         S[tl] = 0;         return;       }       int pos = upper_bound(seg[id].begin(), seg[id].end(),                             pair<int, int>(time, inf + 1)) -                 seg[id].begin();       ans += ps1[id][pos];       ans += ps2[id][pos] * time;       return;     }     shift(id);     int mid = (tl + tr) >> 1;     query(id << 1, tl, mid, l, r, t);     query(id << 1 | 1, mid, tr, l, r, t);     Mn[id] = min(Mn[id << 1], Mn[id << 1 | 1]);     Mx[id] = max(Mx[id << 1], Mx[id << 1 | 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(Mn, -1, sizeof(Mn));     memset(Mx, -1, sizeof(Mx));     cin >> n;     for (int i = 1; i <= n; i++)       cin >> S[i] >> M[i] >> R[i], D[i] = (R[i] ? (M[i] + R[i] - 1) / R[i] : inf);     Build(1, 1, n + 1);     cin >> m;     while (m--) {       cin >> t >> l >> r;       ans = 0;       query(1, 1, n + 1, l, r + 1, t);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000404;   const long long MOD = 1000000007ll;   const long double PI = acos(-1.0);   const long double EPS = 1e-9;   template <typename t1, typename t2>   inline void upmax(t1 &a, t2 b) {     a = max(a, (t1)b);   }   template <typename t1, typename t2>   inline void upmin(t1 &a, t2 b) {     a = min(a, (t1)b);   }   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   template <typename T>   inline bool pal(T &x) {     int n = (int((x.size())));     for (int i = 0; i < n / 2; i++) {       if (x[i] != x[n - i - 1]) return 0;     }     return 1;   }   template <typename T>   inline void rev(T &x) {     int n = (int((x.size())));     for (int i = 0; i < n / 2; i++) swap(x[i], x[n - i - 1]);   }   int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};   int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};   inline long long mp(long long a, long long b) { return (a << 31) + b; }   class compare {    public:     bool operator()(const int a, const int b) const { return 1; }   };   int SQ = 400;   int l[211111];   int r[211111];   int m[211111];   int a[211111];   void solve() {     int n;     vector<int> st;     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> a[i];     }     for (int i = 1; i < n + 1; i++) {       while (!st.empty() && a[st.back()] >= a[i]) st.pop_back();       if (st.empty())         l[i] = 0;       else         l[i] = st.back();       st.push_back(i);     }     st.resize(0);     for (int i = n + 1 - 1; i >= 1; i--) {       while (!st.empty() && a[st.back()] >= a[i]) st.pop_back();       if (st.empty())         r[i] = n + 1;       else         r[i] = st.back();       st.push_back(i);     }     st.resize(0);     for (int i = 1; i < n + 1; i++) upmax(m[r[i] - l[i] - 1], a[i]);     for (int i = n + 1 - 1; i >= 1; i--) upmax(m[i], m[i + 1]);     for (int i = 1; i < n + 1; i++) cout << m[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     };     getchar();     getchar();     return 0;   }