malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 0;   const int MOD = 1000000007;   template <class T>   inline void CLR(T &g) {     T t;     swap(t, g);   }   template <class T>   inline void CLR(T &g, int a) {     memset(g, a, sizeof g);   }   template <class T>   inline void CPY(T &a, T &b) {     memcpy(a, b, sizeof a);   }   template <class T>   inline bool inr(T a, T b, T c) {     return (a >= b && a <= c);   }   inline int acc(int a, int b) { return !!(a & (1 << b - 1)); }   inline int fil(int a, int b, int c) {     return a & ~(1 << b - 1) | (c ? (1 << b - 1) : 0);   }   int N, M, K, Q;   int a, b, c, l;   long long calc1(int p, int x1, int x2, int y1, int y2) {     int dx = x2 - x1 + 1, dy = y2 - y1 + 1;     if (dx <= dy) {       if (p - x1 < y1)         return 0;       else if (p - x2 < y1)         return (1ll * (p - x1 - y1 + 1 + 1) * (p - x1 - y1 + 1) / 2);       else if (p - x1 < y2)         return (1ll * (p - x1 - y1 + 1 + 1) * (p - x1 - y1 + 1) / 2) -                (1ll * (p - x2 - y1 + 1) * (p - x2 - y1) / 2);       else if (p - x2 <= y2)         return (1ll * (p - x1 - y1 + 1 + 1) * (p - x1 - y1 + 1) / 2) -                (1ll * (p - x2 - y1 + 1) * (p - x2 - y1) / 2) -                (1ll * (p - x1 - y2 + 1) * (p - x1 - y2) / 2);       else         return 1ll * (x2 - x1 + 1) * (y2 - y1 + 1);     } else       return calc1(p, y1, y2, x1, x2);   }   long long calc(int p, int x1, int x2, int y1, int y2) {     if (l + a + b + c - p <= p) return 0;     if (x1 > x2 || y1 > y2) return 0;     return -calc1(p, x1, x2, y1, y2) + calc1(l + a + b + c - p, x1, x2, y1, y2);   }   int main() {     int T, o = 0;     scanf( %d%d%d%d , &a, &b, &c, &l);     long long sum = 0;     for (register int(i) = a, _end_ = (a + l); (i) <= _end_; ++(i))       sum += calc(i, b, i, c, i);     for (register int(i) = b, _end_ = (b + l); (i) <= _end_; ++(i))       sum += calc(i, a, i - 1, c, i);     for (register int(i) = c, _end_ = (c + l); (i) <= _end_; ++(i))       sum += calc(i, a, i - 1, b, i - 1);     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000], d[100000];   int main() {     int n, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     vector<int> p;     for (int i = 0; i < n; i++) {       if (a[i] == 1) ans = max(ans, 1);       p.clear();       int x = a[i];       int k = 0;       for (int j = 2; j <= sqrt(x); j++)         if (x % j == 0) {           p.push_back(j);           k = max(k, d[j] + 1);           while (x % j == 0) x /= j;         }       if (x > 1) {         p.push_back(x);         k = max(k, d[x] + 1);       }       ans = max(ans, k);       for (int j = 0; j < p.size(); j++) d[p[j]] = max(d[p[j]], k);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1010, mod = 1000000007;   vector<vector<int> > lst[M];   vector<vector<int> > flag[M];   vector<int> sz[M];   vector<int> tmp, bmp;   vector<pair<int, int> > edge;   int id[M][M];   int pos[M][M];   int visited[M];   string s, t;   void make_list(int u, string &a) {     int i = 0, j = 0;     char d[10];     tmp.clear();     a +=  , ;     while (a[i] !=  : ) i++;     i++;     while (i < a.size()) {       if (a[i] ==  , ) {         d[j++] =   0 ;         if (atoi(d) > 0) tmp.push_back(atoi(d));         j = 0;       } else         d[j++] = a[i];       i++;     }     bmp.resize(tmp.size());     for (i = 0; i < tmp.size(); i++) {       int v = tmp[i];       id[v][u] = lst[u].size();       pos[v][u] = i;     }     lst[u].push_back(tmp);     flag[u].push_back(bmp);     sz[u].push_back(tmp.size());   }   void dec(int u, int v) {     for (int i = 0; i < lst[u].size(); i++) {       for (int j = 0; j < lst[u][i].size(); j++) {         if (lst[u][i][j] == v) {           sz[u][i]--;           flag[u][i][j] = 1;           return;         }       }     }   }   bool isinsane(int u) {     int i, j, k, cnt = 0;     for (i = 0; i < lst[u].size(); i++) cnt += (sz[u][i] > 0);     return cnt != 1;   }   pair<int, int> find_leaf(int n) {     int i, j, k;     vector<int> r;     for (i = 1; i <= n; i++) r.push_back(i);     random_shuffle((r).begin(), (r).end());     for (int first = 0; first < r.size(); first++) {       i = r[first];       if (visited[i]) continue;       for (j = 0; j < lst[i].size(); j++) {         if (sz[i][j] == 1) {           for (k = 0; k < flag[i][j].size(); k++) {             if (flag[i][j][k] == 0) return make_pair(i, lst[i][j][k]);           }         }       }     }     return make_pair(-1, -1);   }   int main() {     ios_base::sync_with_stdio(false);     int n, i, j, k;     srand(time(NULL));     memset((id), (-1), sizeof(id));     cin >> n;     for (j = 1; j <= n; j++) {       cin >> s;       s +=  - ;       for (i = 0; i < s.size(); i++) {         if (s[i] ==  - ) {           make_list(j, t);           t.clear();         } else           t += s[i];       }     }     while (true) {       pair<int, int> g = find_leaf(n);       if (g.first == -1) break;       edge.push_back(g);       int u = g.second, v = g.first;       visited[u] = 1;       if (isinsane(u)) {         printf( %d n , -1);         return 0;       }       for (i = 1; i <= n; i++) {         if (visited[i]) continue;         int l = id[u][i], r = id[v][i], p = pos[u][i];         if (l == -1) continue;         if (i != v && l != r) {           printf( %d n , -1);           return 0;         }         flag[i][l][p] = 1;         sz[i][l]--;       }       dec(u, g.first);     }     if (edge.size() != n - 1)       printf( %d n , -1);     else {       printf( %d n , edge.size());       for (pair<int, int> e : edge) printf( %d %d n , e.first, e.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void checkMAX(int& a, int b) {     if (a < b) a = b;   }   inline void checkMIN(int& a, int b) {     if (a > b) a = b;   }   int main() {     char s[333] = {};     cin >> s;     int mn = 0, mx = 0, curr = 0;     for (int i = 0; s[i]; i++) {       if (s[i] ==  + )         curr++;       else         curr--;       checkMIN(mn, curr);       checkMAX(mx, curr);     }     cout << (mx - mn) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char str[25];     gets(str);     int let[26];     for (int i = 0; i < 26; i++) {       let[i] = 0;     }     int len = 0;     for (int i = 0; str[i]; i++) {       let[str[i] -  a ]++;       len++;     }     long long c = 0;     for (int i = 0; i < 26; i++) {       c = c + (len + 1) - let[i];     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int ans = (i * (i + 1)) / 2;       if (ans == n) {         cnt = 1;         break;       }     }     if (cnt == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   #define For(i, a, b) for(int i = a; i <= b; i++)   #define Ford(i, a, b) for(int i = a; i >= b; i--)   #define make_pair(a,b) mp(a, b)       using namespace std;   const int N= 2e5 + 1067, K = 17, md=1e9 + 7;   int n, k;   int f[N][30], g[1 << K], dem[30];   string s;      bool check(int x) {       int en = n - 1;       for(char j =  a ; j <  a  + k; j++) f[n][j] = f[n + 1][j] = n, dem[j] = 0;       Ford(i, n - 1, 0) {           for(char j =  a ; j <  a  + k; j++)                f[i][j] = f[i + 1][j];           ++dem[s[i]];           if (en >= i + x) {               --dem[s[en]];               en -= 1;           }           char c =  - ;           int diversity = 0;           for(char j =  a ; j <  a  + k; j++) {               if (dem[j]) {                   diversity += 1;                   c = j;               }           }           if (diversity == 0) {               for(char j =  a ; j <  a  + k; j++)                    f[i][j] = i + x - 1;           } else if (diversity == 1) {               f[i][c] = i + x - 1;           }       }              For(mask, 0, (1 << k) - 1) g[mask] = n;       g[0] = -1;       For(mask, 0, (1 << k) - 1) {           For(i, 0, k - 1) if (!(mask & (1 << i))) {               g[mask ^ (1 << i)] = min(g[mask ^ (1 << i)], f[g[mask] + 1][(char)( a  + i)]);            }       }              return g[(1 << k) - 1] < n;   }      int bs(int l, int r) {       while (l < r) {           if (l == r - 1) {               if (check(r))                    return r;               else                    return l;           }           int mid = (l + r) / 2;           if (check(mid))                l = mid;           else                r = mid - 1;       }       return l;   }       int main() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cin >> n >> k;       cin >> s;       cout << bs(0, n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[150005];   vector<int> v;   set<pair<int, int> > ans;   int compute() {     int problem = 0;     for (int i = 1; i <= n; i = i + 2) {       if (a[i] >= a[i + 1]) {         problem++;       }     }     for (int i = 2; i <= n; i = i + 2) {       if (a[i] <= a[i + 1]) {         problem++;       }     }     return problem;   }   vector<int> findproblems() {     vector<int> q;     for (int i = 1; i <= n; i = i + 2) {       if (a[i] >= a[i + 1]) {         q.push_back(i);         if (i >= 1 && i <= n) {           q.push_back(i + 1);         }       }     }     for (int i = 2; i <= n; i = i + 2) {       if (a[i] <= a[i + 1]) {         q.push_back(i);         if (i >= 1 && i <= n) {           q.push_back(i + 1);         }       }     }     sort(q.begin(), q.end());     return q;   }   void swap(int i, int j) {     int tempa = a[i];     a[i] = a[j];     a[j] = tempa;   }   int check(int e) {     if (e % 2 == 0) {       if (a[e] > a[e - 1] && a[e] > a[e + 1]) {         return 0;       }       return 1;     }     if (a[e] < a[e - 1] && a[e] < a[e + 1]) {       return 0;     }     return 1;   }   int threeandfour(int i, int j, vector<int> q) {     swap(i, j);     int flag = 0;     for (int i = 0; i < q.size(); i++) {       flag += check(q[i]);     }     flag += check(i);     flag += check(j);     swap(i, j);     return flag;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     a[0] = 150005;     if (n % 2 == 0) {       a[n + 1] = -10;     } else {       a[n + 1] = 150005;     }     int problem = compute();     if (problem > 4) {       cout <<  0  << endl;     } else {       v = findproblems();       for (int i = 0; i < v.size(); i++) {         for (int j = 1; j <= n; j++) {           if (threeandfour(v[i], j, v) == 0) {             ans.insert(make_pair(v[i], j));             ans.insert(make_pair(j, v[i]));           }         }       }       cout << ans.size() / 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.second < b.second) return true;     return false;   }   bool com(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, k;     cin >> n >> k;     vector<long long> ar(n);     vector<pair<long long, long long> > br(n);     for (long long i = 0; i < n; ++i) cin >> ar[i], br[i] = {ar[i], i};     sort(br.begin(), br.end(), com);     br.resize(k);     sort(br.begin(), br.end(), comp);     long long mx = br[0].first, sec = 1;     for (long long i = 1; i < br.size(); ++i) {       mx += br[i].first;       sec = (sec * (br[i].second - br[i - 1].second)) % 998244353;     }     cout << mx <<     << sec;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   long long n, ans, f[N], now, sum;   char s[N];   signed main() {     scanf( %lld , &n);     scanf( %s , s + 1);     for (long long i = 1; i <= n; i++) f[i] = n + 1;     for (long long i = n; i >= 1; i--) {       if (s[i] -  0 )         sum += f[++now] - i;       else {         while (now) f[now] = now + i, now--;       }       ans += sum;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int t;   struct node {     char id;     int num;   } ans[N];   string a;   int cot;   int main() {     cin >> a;     if (a.length() == 1) {       cout << 0 << endl;       return 0;     }     cot = 1;     ans[cot].id = a[0];     ans[cot].num = 1;     for (register int i = 0; i <= a.length() - 2; ++i) {       if (a[i + 1] == a[i])         ans[cot].num++;       else {         ans[++cot].id = a[i + 1];         ans[cot].num = 1;       }     }     if (cot % 2 == 0 || ans[cot / 2 + 1].num < 2) {       cout << 0 << endl;       return 0;     }     int now = 1;     int fg = 0;     while (now != cot / 2 + 1) {       if (ans[now].id != ans[cot - now + 1].id ||           ans[now].num + ans[cot - now + 1].num < 3) {         fg = 1;         break;       }       now++;     }     if (!fg)       cout << ans[cot / 2 + 1].num + 1 << endl;     else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   vector<long long> v(10);   string s;   set<string> st;   void call(string s, long long pos) {     if (pos == 10) {       sort(s.begin(), s.end());       st.insert(s);       return;     }     if (v[pos] == 0) {       call(s, pos + 1);       return;     }     for (long long i = 1; i <= v[pos]; i++) {       char c =  0  + pos;       string x = string(i, c);       call(s + x, pos + 1);     }   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     vector<long long> f(20);     f[0] = f[1] = 1;     for (long long i = 2; i < 20; i++) {       f[i] = f[i - 1] * i;     }     cin >> s;     for (long long i = 0; i < s.size(); i++) v[s[i] -  0 ]++;     string x =   ;     call(x, 0);     long long ans = 0;     for (auto i : st) {       string &x = i;       vector<long long> cnt(10);       for (long long i = 0; i < x.size(); i++) {         cnt[x[i] -  0 ]++;       }       long long val = f[x.size()];       for (long long i = 0; i < 10; i++) {         val = val / f[cnt[i]];       }       ans += val;       if (v[0] > 0) {         long long val1 = f[x.size() - 1];         cnt[0]--;         for (long long i = 0; i < 10; i++) val1 = val1 / f[cnt[i]];         ans -= val1;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   int n;   int a[1001000];   int b[1001000];   int c[1001000];   int ans;   int main() {     int i, j;     scanf( %d , &n);     n++;     for (i = 2; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = 1;       c[i] = 0;       j = i;       if (ans < b[j]) ans = b[j];       while (a[j] != 1) {         if (ans < b[j]) ans = b[j];         if (ans < b[a[j]]) ans = b[a[j]];         if (b[a[j]] < b[j]) {           b[a[j]] = b[j];           c[a[j]] = 1;         } else if (c[a[j]] == 1 && b[a[j]] == b[j]) {           b[a[j]] = b[j] + 1;           c[a[j]] = 0;         } else if (c[a[j]] == 0 && b[a[j]] == b[j]) {           c[a[j]] = 1;           break;         } else           break;         if (ans < b[a[j]]) ans = b[a[j]];         j = a[j];       }       printf( %d  , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(pair<int, string> a, pair<int, string> b) {     if (a.first != b.first)       return a.first > b.first;     else       return a.second < b.second;   }   int binarySearch(vector<int> a, int n, int key) {     int low = 0;     int high = n, mid;     while (low <= high) {       mid = (low + high) / 2;       if (a[mid] <= key) {         low = mid + 1;       } else if (a[mid] > key) {         high = mid - 1;       }     }     if (high - low == 1) {       if (a[low] >= key)         return low;       else         return high;     } else       return mid;   }   vector<int> SieveOfEratosthenes(int n) {     vector<int> prime(n + 1, 1);     for (int p = 2; p * p <= n; p++) {       if (prime[p] == 1) {         for (int i = p * p; i <= n; i += p) prime[i] = 0;       }     }     return prime;   }   vector<pair<long long, long long>> v;   void primeFactors(long long n) {     v.clear();     long long k = 0;     while (n % 2 == 0) {       k++;       n = n / 2;     }     if (k != 0) v.push_back({2, k});     for (long long i = 3; i <= sqrt(n); i = i + 2) {       k = 0;       while (n % i == 0) {         k++;         n = n / i;       }       if (k != 0) v.push_back({i, k});     }     if (n > 2) v.push_back({n, 1});   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       long long n;       cin >> n;       long long ans = n;       long long a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];         ans += (i + 1) * (a[i] - 1);       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     cin >> n >> a;     if (a % 2 != 0) {       cout << (((a - 1) / 2) + 1) <<   n ;     } else {       cout << ((n / 2) - ((a - 2) / 2)) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, x, _, a, d, t[100001], ans;   long long rua(long long l, long long r) {     if (r < l) return _;     if (_ >= n * a) {       ans++;       return r + d;     }     if (l % a && l / a == r / a) {       ans++;       return r + d;     }     long long f = min((l - 1) / a + 1, n);     long long la = min(r / a, n);     long long k = (la - f) / x + 1;     ans += k;     f += (k - 1) * x;     f *= a;     if (f + d >= r) {       return f + d;     }     ans++;     return r + d;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &m, &a, &d), x = d / a + 1;     for (long long i = 1; i <= m; i++)       scanf( %I64d , &t[i]), _ = rua(_ + 1, t[i]);     rua(_ + 1, n * a);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100001], q, sum;   int b[1000001];   int main() {     int n, m, q, sum = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i] + sum] = i;       b[1 + sum] = i;       sum += a[i];     }     cin >> m;     for (int j = 1; j <= m; j++) {       cin >> q;       if (b[q]) {         cout << b[q] << endl;         continue;       }       for (int k = 1; k <= 1000; k++) {         if (b[q + k]) {           cout << b[q + k] << endl;           break;         }         if (b[q - k]) {           cout << b[q - k] << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long int sum = 0;     cin >> n;     int a, b;     int max = INT_MIN;     for (int i = 0; i < n; i++) {       cin >> a >> b;       sum = sum - a + b;       if (max < sum) max = sum;     }     cout << max;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   const int mod = 1e9 + 7;   using namespace std;   template <class T>   void cinn(T& x) {     cin >> x;   }   template <class H, class... T>   void cinn(H& h, T&... t) {     cinn(h);     cinn(t...);   }   template <class A>   void cinn(vector<A>& x) {     for (auto& a : x) cinn(a);   }   void Shazam() {     long long n, k;     cinn(n, k);     vector<long long> a(n);     cinn(a);     long long ans = 0;     for (long long i = k; i < 101; i++) {       long long cnt = 0;       for (long long j = 0; j < n; j++) {         cnt += (a[j] / i);       }       ans = max(ans, cnt * i);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t = 1;     while (t--) Shazam();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   long long extended(long long a, long long b, long long &x, long long &y) {     a = abs(a);     b = abs(b);     long long g, x1, y1;     if (!b) {       x = 1;       y = 0;       g = a;       return g;     }     g = extended(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }   long long bpow(long long p, long long e) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return ret;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   string convertInt(long long number) {     if (number == 0) return  0 ;     string temp =   ;     string returnvalue =   ;     while (number > 0) {       temp += number % 10 + 48;       number /= 10;     }     for (int i = 0; i < temp.length(); i++)       returnvalue += temp[temp.length() - i - 1];     return returnvalue;   }   long long ar[550], n, m, b, modd;   long long dp[550][550];   int main() {     long long n, m, b, modd;     cin >> n >> m >> b >> modd;     for (int i = 1; i <= n; i++) {       cin >> ar[i];     }     for (int i = 1; i <= n; i++) {       if (ar[i] <= b) dp[1][ar[i]]++;       dp[1][ar[i]] %= 1000000007;       for (int j = 0; j <= b; j++) {         for (int k = 1; k <= m; k++) {           if (ar[i] + j > b) continue;           dp[k][ar[i] + j] += dp[k - 1][j];           dp[k][ar[i] + j] %= modd;         }       }     }     long long ans = 0;     for (int i = 0; i <= b; i++) {       ans += dp[m][i];       ans %= modd;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   class node {    public:     int lo, hi, value;     node *left, *right;     node(const int _lo, const int _hi) {       left = right = NULL;       lo = _lo, hi = _hi, value = 0;     }     void build() {       if (lo == hi) return;       const int mid = (lo + hi) >> 1;       left = new node(lo, mid), left->build();       right = new node(mid + 1, hi), right->build();     }     void update(const int idx) {       if (lo > idx or hi < idx) return;       if (lo == idx and hi == idx) {         ++value;         return;       }       left->update(idx);       right->update(idx);       value = left->value + right->value;     }     int query(const int _lo, const int _hi) {       if (lo > _hi or hi < _lo) return 0;       if (lo >= _lo and hi <= _hi) return value;       int a = left->query(_lo, _hi);       int b = right->query(_lo, _hi);       return a + b;     }     int leftmost() {       if (lo == hi) return lo;       if (left->value) return left->leftmost();       return right->leftmost();     }     int rightmost() {       if (value == hi - lo + 1) return lo - 1;       if (lo == hi) return lo;       if (right->value < right->hi - right->lo + 1) return right->rightmost();       return left->rightmost();     }   };   int main() {     printf( 1 );     int n;     scanf( %d , &n);     node root = node(1, n);     root.build();     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       root.update(x);       printf(  %d , root.query(root.leftmost(), root.rightmost()) + 1);     }     return !printf(  n );   };