malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <typename T>   T gcd(T a, T b) {     T c;     while (b) {       c = b;       b = a % b;       a = c;     }     return a;   }   template <typename T>   T powmod(T a, T b) {     T res = 1;     a %= mod;     while (b) {       if (b & 1) res = res * (a % mod);       a = a * (a % mod);       b >>= 1;     }     return res;   }   void Solve() {     int n, m;     cin >> n >> m;     char grid[120][120];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> grid[i][j];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (grid[i][j] ==  B ) {           if (j + 1 == m) {             cout << i + 1 <<     << j + 1 <<   n ;             return;           } else {             int k;             for (k = j + 1; k < m; ++k) {               if (grid[i][k] !=  B ) break;             }             int a = k - j + 1;             cout << i + (a / 2) <<     << j + (a / 2) <<   n ;             return;           }         }       }     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     Solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<long long, long long> res;   long long a[N];   void dfs(long long cur, long long cnt, long long sum) {     if (!cur) {       res = max(res, {cnt, sum});       return;     } else {       int p = upper_bound(a + 1, a + N, cur) - a;       --p;       dfs(cur - a[p], cnt + 1, sum + a[p]);       if (p > 1) dfs(a[p] - 1 - a[p - 1], cnt + 1, sum + a[p - 1]);     }   }   int main() {     for (int i = 1; i <= N - 1; ++i) a[i] = 1ll * i * i * i;     long long m;     scanf( %lld , &m);     dfs(m, 0, 0);     printf( %lld %lld n , res.first, res.second);     return 0;   }
#include <bits/stdc++.h>   int cmpfnc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int i, n;     scanf( %d , &n);     int arr[300005];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     qsort(arr, n, sizeof(int), cmpfnc);     long long int sum = arr[0];     long long int count = 1;     long long int t2 = 0;     for (i = 1; i < n; i++) {       long long int t3 =           ((count % 1000000007) * (arr[i] % 1000000007)) % 1000000007;       t2 = (t2 + (t3 - sum + 1000000007) % 1000000007) % 1000000007;       sum = (sum * 2 + arr[i]) % 1000000007;       count = (count * 2 + 1) % 1000000007;     }     printf( %lld n , t2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str, s1, s2 =  < ;     stack<char> delm;     vector<string> re;     getline(cin, str);     for (int i = 0; i < str.size(); i++) {       if (str[i] ==     && delm.empty()) {         s1 =  < ;         delm.push(str[i]);       } else if (!delm.empty()) {         char ch = delm.top();         if (ch == str[i]) {           s1 +=  *> ;           re.push_back(s1);           delm.pop();         } else           s1 += str[i];       } else if (delm.empty()) {         if (str[i] ==     && s2.size() > 1) {           s2 +=  *> ;           re.push_back(s2);           s2 =  < ;         } else if (str[i] !=    ) {           s2 += str[i];         }         if (i == str.size() - 1 && str[str.size() - 1] !=    ) {           s2 +=  *> ;           re.push_back(s2);           s2 =  < ;           continue;         }       }     }     for (int i = 0; i < re.size(); i++) {       bool flag = false;       for (int j = 1; j < re[i].size() - 1; j++)         if (re[i][j] !=     || re[i][re[i].size() - 1] ==  * ) {           flag = true;           re[i] =               re[i].substr(0, re[i].size() - 2) + re[i].substr(re[i].size() - 1);           break;         }       if (flag) cout << re[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   inline void read(int &x) { scanf( %d , &x); }   inline void read(long long &x) { scanf( %I64d , &x); }   inline void read(double &x) { scanf( %lf , &x); }   inline void read(long double &x) {     double tmp;     read(tmp);     x = tmp;   }   template <class T>   inline void read(T *a, int n) {     for (int i = (0); i < (n); ++i) read(a[i]);   }   inline void write(int x) { printf( %d , x); }   inline void write(long long x) { printf( %I64d , x); }   inline void write(double x) { printf( %.10lf , x); }   inline void write(long double x) { printf( %.10lf , (double)x); }   template <class T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   template <class T>   inline void writeln(T *a, int n) {     for (int i = (0); i < (n); ++i) {       write(a[i]);       putchar(   );     }     putchar(  n );   }   template <class T>   inline void writelnln(T *a, int n) {     for (int i = (0); i < (n); ++i) writeln(a[i]);   }   int A[5];   std::set<int> res[5][5];   inline void calc(int l, int r) {     std::set<int> &S = res[l][r];     S.clear();     if (l == r) {       S.insert(A[l]);       S.insert(-A[l]);     } else {       for (int m = (l); m < (r); ++m) {         std::set<int> &a = res[l][m], &b = res[m + 1][r];         for (__typeof(a.begin()) aa = a.begin(); aa != a.end(); ++aa)           for (__typeof(b.begin()) bb = b.begin(); bb != b.end(); ++bb) {             S.insert(*aa + *bb);             S.insert(*aa - *bb);             S.insert(*aa * *bb);             S.insert(-*aa + *bb);             S.insert(-*aa - *bb);             S.insert(-*aa * *bb);           }       }     }   }   std::set<int> ANS;   char buf[3000007], *cb = buf;   int main() {     int k, m;     read(k);     read(m);     for (int ls = (0); ls < (10000); ++ls) {       A[0] = ls / 1000;       A[1] = ls / 100 % 10;       A[2] = ls / 10 % 10;       A[3] = ls % 10;       calc(0, 0);       calc(1, 1);       calc(2, 2);       calc(3, 3);       calc(0, 1);       calc(1, 2);       calc(2, 3);       calc(0, 2);       calc(1, 3);       calc(0, 3);       std::set<int> &ans = res[0][3];       for (__typeof(ans.begin()) x = ans.begin(); x != ans.end(); ++x) {         int ttt = abs(k - *x);         if (ttt < 10000) {           ANS.insert(ls * 10000 + ttt);           if (ANS.size() == m) {             for (__typeof(ANS.begin()) it = ANS.begin(); it != ANS.end(); ++it) {               int x = *it;               *(cb++) = x / 10000000 +  0 ;               *(cb++) = x / 1000000 % 10 +  0 ;               *(cb++) = x / 100000 % 10 +  0 ;               *(cb++) = x / 10000 % 10 +  0 ;               *(cb++) = x / 1000 % 10 +  0 ;               *(cb++) = x / 100 % 10 +  0 ;               *(cb++) = x / 10 % 10 +  0 ;               *(cb++) = x % 10 +  0 ;               *(cb++) =   n ;             }             fwrite(buf, 1, cb - buf, stdout);             return 0;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   signed long long W[303030];   vector<pair<int, int>> E[303030];   signed long long best[303030];   signed long long ma;   void dfs(int cur, int pre) {     vector<signed long long> C;     for (auto& e : E[cur])       if (e.first != pre) {         dfs(e.first, cur);         if (best[e.first] - e.second > 0) C.push_back(best[e.first] - e.second);       }     C.push_back(0);     C.push_back(0);     sort((C.begin()), (C.end()));     reverse((C.begin()), (C.end()));     ma = max(ma, W[cur] + C[0] + C[1]);     best[cur] = W[cur] + C[0];   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 0; i < (N); i++) cin >> W[i];     for (i = 0; i < (N - 1); i++) {       cin >> x >> y >> r;       E[x - 1].push_back({y - 1, r});       E[y - 1].push_back({x - 1, r});     }     dfs(0, -1);     cout << ma << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int sum[maxn], t, n, q, l, r;   char s[maxn];   set<int> v[4 * maxn + 10];   int main() {     scanf( %d , &t);     while (t--) {       sum[0] = 0;       scanf( %d%d%s , &n, &q, (s + 1));       for (int i = 1; i <= n; i++) {         sum[i] = sum[i - 1] + (s[i] ==  +  ? 1 : -1) * (i & 1 ? 1 : -1);         v[sum[i - 1] + sum[i] + 2 * maxn].clear();       }       for (int i = 1; i <= n; i++) v[sum[i - 1] + sum[i] + 2 * maxn].insert(i);       while (q--) {         scanf( %d%d , &l, &r);         if (sum[r] == sum[l - 1])           printf( 0 n );         else {           int k = r - l + 1;           if (k % 2 == 0)             printf( 2 n%d  , l), l++;           else             printf( 1 n );           printf( %d n , *v[sum[r] + sum[l - 1] + 2 * maxn].lower_bound(l));         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int base = 1e9;   const int maxn = 1e3;   const int logn = 20;   const int inf = 2e9;   const int alpha = 26;   const int my_hash = 29;   const long long l_inf = 4e18;   const long long mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-9;   int n;   long long x, sum = 0;   vector<long long> a, b;   long long binpow(long long a, long long b) {     if (!b) return 1;     if (b % 2) return (binpow(a, b - 1) * a) % mod;     long long k = binpow(a, b / 2);     return (k * k) % mod;   }   int main() {     ios_base::sync_with_stdio();     cin >> n >> x;     a = vector<long long>(n);     for (int i = int(0); i < int(n); i++) {       cin >> a[i];       sum += a[i];     }     for (int i = int(0); i < int(n); i++) b.push_back(sum - a[i]);     sort(b.rbegin(), b.rend());     while (true) {       long long cnt = 0, v = b.back();       while (!b.empty() && b.back() == v) {         cnt++;         b.pop_back();       }       if (cnt % x) {         cout << binpow(x, min(v, sum));         exit(0);       } else {         cnt /= x;         for (int i = int(0); i < int(cnt); i++) b.push_back(v + 1);       }     }   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   void fil() {}   long long int ipow(long long int base, long long int k, long long int M) {     base %= M;     k = k % (M - 1);     long long int total = 1;     while (k) {       if (k & 1) {         total = (total * base) % M;       }       base = (base * base) % M;       k >>= 1;     }     return total;   }   void solve();   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     fil();     long long int t = 1;     cin >> t;     for (int i = 1; i < t + 1; i++) {       solve();     }   }   void solve() {     int n, m, ix, iy, fx, fy;     cin >> n >> m >> ix >> iy >> fx >> fy;     int dx = 1, dy = 1;     int cnt = 0;     while (1) {       if (ix == fx || iy == fy) {         cout << cnt <<   n ;         return;       }       if (!(ix + dx <= n && ix + dx >= 1)) {         dx *= -1;       }       if (!(iy + dy <= m && iy + dy >= 1)) {         dy *= -1;       }       ix += dx;       iy += dy;       cnt++;     }   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     LL sum = 0;     for (int i = 0; i < n; ++i) {       LL a;       cin >> a;       sum += a;     }     LL base = 1LL * (1 + n) * n / 2;     LL add = (sum - base) / n;     sum -= base + add * n;     for (int i = 0; i < sum; ++i) cout << i + 1 + add + 1 <<    ;     for (int i = sum; i < n; ++i) cout << i + 1 + add <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T;   int N, X, Y, Ord[100005];   bool print;   int A[100005], Freq[100005], Freq2[100005], F[100005];   vector<int> V;   vector<int> Ap[100005];   set<pair<int, int> > S1, S2;   int Res[100005];   void Read() {     scanf( %d%d%d , &N, &X, &Y);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       F[A[i]]++;       Ord[i] = i;     }   }   int missing() {     for (int i = 1; i <= N + 1; i++)       if (F[i] == 0) return i;     return -1;   }   bool cmp(int a, int b) { return F[A[a]] < F[A[b]]; }   void Solve() {     sort(Ord + 1, Ord + N + 1, cmp);     int miss = missing();     Freq[miss] = N - Y;     int cnt = 0, pos = 0, cnt2 = 0;     for (int i = 1; i <= N && cnt < Y - X; i++) {       pos = i;       if ((Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 2) > N - X) {         if (cnt2 == N - Y || (Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 1) > N - X)           continue;         Freq2[A[Ord[i]]]++;         cnt2++;         continue;       }       Freq[A[Ord[i]]]++;       Freq2[A[Ord[i]]]++;       cnt++;     }     if (cnt < Y - X) {       printf( NO n );       return;     }     for (int i = pos + 1; i <= N && cnt2 < N - Y; i++) {       if (Freq2[A[Ord[i]]] + 1 + Freq[A[Ord[i]]] > N - X) {         continue;       }       Freq2[A[Ord[i]]]++;       cnt2++;     }     if (cnt2 < N - Y) {       if (print) printf( NO n );       return;     }     if (print) printf( YES n );     for (int i = 1; i <= N + 1; i++) {       if (Freq[i] > 0) {         S1.insert(make_pair(Freq[i], i));       }       if (Freq2[i] > 0) S2.insert(make_pair(Freq2[i], i));     }     int total = N - X;     while (S1.size() > 0) {       set<pair<int, int> >::iterator it = S1.end();       --it;       set<pair<int, int> >::iterator it2 = S2.end();       --it2;       if ((it->first) * 2 == (it2->first) * 2 && (it->first) * 2 == total) {         --it;         --it2;         if (((it->second) != (it2->second)) ||             ((it->first) * 2 != total || (it2->first) * 2 != total)) {           ++it;           ++it2;         } else           ++it;       }       if ((it2->second) == (it->second)) --it2;       Ap[it2->second].push_back(it->second);       pair<int, int> a = *it;       pair<int, int> b = *it2;       --a.first;       --b.first;       S1.erase(it);       S2.erase(it2);       if (a.first > 0) S1.insert(a);       if (b.first > 0) S2.insert(b);       --total;     }     for (int i = 1; i <= N; i++) {       if (Ap[A[i]].size() > 0) {         int val = Ap[A[i]].back();         Res[i] = val;         Ap[A[i]].pop_back();       }     }     cnt = 0;     for (int i = 1; i <= N; i++) {       if (Res[i] == 0) {         Res[i] = A[i];       }       if (print) printf( %d  , Res[i]);     }     if (print) printf(  n );   }   int main() {     int T;     int ind = 0;     scanf( %d , &T);     print = true;     while (T--) {       ++ind;       Read();       Solve();       for (int i = 1; i <= N + 1; i++) {         Ap[i].clear();         Freq[i] = 0;         F[i] = 0;         Freq2[i] = 0;         Res[i] = 0;       }       S1.clear();       S2.clear();       V.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, t;   long long l, r = 1e14, md, res = 1e18, a[200500], b[200500];   struct sb {     long long x, y;     double t;     bool operator<(const sb a) const { return t > a.t; }   } s;   bool chk(long long sb) {     priority_queue<struct sb> q;     int i, j, k;     long long tmp;     for (i = 1; i <= n; i++) {       s.x = a[i];       s.y = b[i];       s.t = s.x * 1.0 / s.y;       q.push(s);     }     for (i = 0; i < m; i++) {       s = q.top();       q.pop();       tmp = s.x / s.y;       if (tmp < i) {         return 0;       }       s.x += sb;       s.t = s.x * 1.0 / s.y;       q.push(s);     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (i = 1; i <= n; i++) {       scanf( %lld , &b[i]);     }     while (l <= r) {       md = (l + r) / 2;       if (chk(md)) {         res = min(res, md);         r = md - 1;       } else {         l = md + 1;       }     }     if (res == 1e18) {       puts( -1 );       return 0;     }     printf( %lld , res);   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long a = 0;   long long b = 0;   void dfs(vector<vector<int>> &g, vector<bool> was, int v, int lvl) {     was[v] = true;     if (lvl % 2 == 0)       a++;     else       b++;     for (int x : g[v]) {       if (!was[x]) dfs(g, was, x, lvl + 1);     }   }   int main() {     int n;     cin >> n;     unordered_set<string> names;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (names.find(s) == names.end())         cout <<  NO  << endl;       else         cout <<  YES  << endl;       names.insert(s);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char t[100][100];   int main(int argc, char* argv[]) {     unsigned int n;     cin >> n;     for (unsigned int i = 0; i < n; ++i)       for (unsigned int j = 0; j < n; ++j) cin >> t[i][j];     unsigned int r = 0;     for (unsigned int i = 0; i < n; ++i) {       for (unsigned int j = 0; j < n; ++j) {         if (t[i][j] ==  . ) {           ++r;           break;         }       }     }     if (r < n) {       unsigned int c = 0;       for (unsigned int i = 0; i < n; ++i) {         for (unsigned int j = 0; j < n; ++j) {           if (t[j][i] ==  . ) {             ++c;             break;           }         }       }       if (c < n)         cout << -1 << endl;       else {         for (unsigned int i = 0; i < n; ++i) {           for (unsigned int j = 0; j < n; ++j) {             if (t[j][i] ==  . ) {               cout << j + 1 <<     << i + 1 << endl;               break;             }           }         }       }     } else {       for (unsigned int i = 0; i < n; ++i) {         for (unsigned int j = 0; j < n; ++j) {           if (t[i][j] ==  . ) {             cout << i + 1 <<     << j + 1 << endl;             break;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct V {     int x, y;   };   bool conf(V left, V right) {     if (left.x != right.x) return left.x < right.x;     return left.y < right.y;   }   int main() {     V arr[9];     for (int i = 0; i <= 7; i++) scanf( %d %d , &arr[i].x, &arr[i].y);     sort(arr, arr + 8, conf);     if ((arr[0].x != arr[1].x) || (arr[0].x != arr[2].x) ||         (arr[0].x == arr[3].x) || (arr[3].x != arr[4].x) ||         (arr[0].x == arr[5].x) || (arr[3].x == arr[5].x) ||         (arr[5].x != arr[6].x) || (arr[5].x != arr[7].x)) {       printf( ugly );       return 0;     }     if ((arr[0].y == arr[1].y) || (arr[0].y == arr[2].y) ||         (arr[1].y == arr[2].y) || (arr[0].y != arr[3].y) ||         (arr[0].y != arr[5].y) || (arr[1].y != arr[6].y) ||         (arr[2].y != arr[4].y) || (arr[2].y != arr[7].y)) {       printf( ugly );       return 0;     }     printf( respectable );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   void transform(int input) {     if (input) {       transform((input - 1) / 26);       putchar(65 + (input - 1) % 26);     }   }   int main() {     int n, x, y;     string input;     for (scanf( %d  , &n); n--;) {       cin >> input;       if (sscanf(input.c_str(),  %*c%d%*c%d , &x, &y) == 2) {         transform(y);         printf( %d n , x);       } else {         x = 0;         for (int j = 0; j < input.size() && input[j] > 64 && input[j] < 91; j++) {           x = x * 26 + input[j] - 64;         }         string digits = input.c_str();         digits.erase(remove_if((digits).begin(), (digits).end(),                                [](char c) { return isalpha(c); }),                      digits.end());         printf( R%sC%d n , digits.c_str(), x);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 105;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int x;     cin >> x;     for (int i = 0; i < n; i++) {       x = 7 - x;       int a, b;       cin >> a >> b;       if (a == x || b == x || 7 - a == x || 7 - b == x) {         cout <<  NO n ;         return 0;       }       for (int j = 1; j <= 6; j++)         if (a != j && b != j && 7 - a != j && 7 - b != j) x = j;     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     char x =  a ;     int y;     set<int> arr[26];     for (int i = 0; i < s.length(); i++) {       y = s[i] - x;       arr[y].insert(i);     }     int q;     cin >> q;     int n, ans = 0;     for (int i = 0; i < q; i++) {       cin >> n;       if (n == 1) {         int pos;         char c;         cin >> pos >> c;         y = s[pos - 1] - x;         arr[y].erase(pos - 1);         s[pos - 1] = c;         y = c - x;         arr[y].insert(pos - 1);       }       if (n == 2) {         int l, r;         cin >> l >> r;         l--;         r--;         for (int i = 0; i < 26; i++) {           auto it = arr[i].lower_bound(l);           if (it == arr[i].end())             continue;           else if (*it <= r)             ans++;         }         cout << ans << endl;         ans = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       if (n == 1) {         printf( YES n%d n , m);       } else if (n == 2) {         if (m == 0) {           printf( NO n );         } else {           printf( YES n0 %d n , m);         }       } else {         int x = 1 << 18, y = 1 << 19, z = 0;         printf( YES n );         for (int i = 1; i <= n - 3; i++) {           printf( %d  , i);           z = z ^ i;         }         printf( %d %d %d n , x, y, (x ^ y ^ z ^ m));       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int expo(long long int base, long long int exponent,                      long long int mod) {     long long int ans = 1;     while (exponent > 0) {       if (exponent % 2 == 1) {         ans *= base;         ans %= mod;       }       base *= base;       base %= mod;       exponent /= 2;     }     return ans;   }   const long long int M = 3000006;   long long int f[M], inv[M];   void compute() {     f[0] = 1;     for (long long int i = 1; i <= M - 1; i++) {       f[i] = (1LL * i * f[i - 1]) % mod;     }     inv[M - 1] = expo(f[M - 1], mod - 2, mod);     for (long long int i = M - 2; i >= 0; i--) {       inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod;     }   }   long long int C(long long int n, long long int r) {     return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod;   }   long long int h[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1;     while (tests--) {       long long int i, j, n;       cin >> n;       for (long long int i = 1; i <= n; i++) cin >> h[i];       long long int tmp = 0;       vector<long long int> res(n + 1);       for (long long int i = 1; i <= n; i++) {         tmp = min(tmp, h[i] - i);         res[i] = tmp + i;       }       tmp = 0;       for (i = n; i >= 1; i--) {         tmp = min(tmp, h[i] - (n + 1 - i));         res[i] = min(res[i], tmp + (n + 1 - i));       }       long long int ans = 0;       for (long long int i = 1; i <= n; i++) ans = max(ans, res[i]);       cout << ans;     }     return 0;   }