malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, to[N << 1], nxt[N << 1], head[N], cnt;   int len[N], son[N], tmp[N], *f[N], *id = tmp, ans[N];   void link(int u, int v) {     to[++cnt] = v;     nxt[cnt] = head[u];     head[u] = cnt;     to[++cnt] = u;     nxt[cnt] = head[v];     head[v] = cnt;   }   void dfs(int u, int ff) {     for (int e = head[u]; e; e = nxt[e])       if (to[e] != ff) {         dfs(to[e], u);         if (len[to[e]] > len[son[u]]) son[u] = to[e];       }     len[u] = len[son[u]] + 1;   }   void dp(int u, int ff) {     f[u][0] = 1;     if (son[u]) f[son[u]] = f[u] + 1, dp(son[u], u), ans[u] = ans[son[u]] + 1;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == ff || v == son[u]) continue;       f[v] = id;       id += len[v];       dp(v, u);       for (int j = 1; j <= len[v]; ++j) {         f[u][j] += f[v][j - 1];         if ((j < ans[u] && f[u][j] >= f[u][ans[u]]) ||             (j > ans[u] && f[u][j] > f[u][ans[u]]))           ans[u] = j;       }     }     if (f[u][ans[u]] == 1) ans[u] = 0;   }   int main() {     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       link(u, v);     }     dfs(1, 0);     f[1] = id;     id += len[1];     dp(1, 0);     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int n, long long int k) {     long long int ans = 1;     long long int mod = 1000000007;     while (k) {       if (k & 1) ans = (ans * n) % mod, k--;       n = (n * n) % mod, k >>= 2;     }     return ans;   }   long long int mod(long long int n, long long int k) {     long long int ans = n % k;     if (n < 0) ans += k;     return ans;   }   string cins() {     char ss[1000000];     fgets(ss, 1000000, stdin);     string s;     for (int i = 0; i < strlen(ss); i++) s += ss[i];     return s;   }   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int tt;     cin >> tt;     for (int T = 1; T < tt + 1; T++) solve();     return 0;   }   void solve() {     int n;     cin >> n;     int ans = 0;     for (int i = 1; i < n + 1; i++) {       int x;       cin >> x;       if (x > i + ans) ans += x - (i + ans);     }     {       cout << ans <<   n ;       return;     };     ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ar[110];     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> ar[i];       }       if ((n % 2 == 1) && (ar[0] % 2 == 1) && (ar[n - 1] % 2 == 1))         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   static const int N = 500005;   long long l[N];   long long d[N];   char s[N];   int main() {     int a, b, t, n;     cin >> n >> a >> b >> t;     scanf( %s , &s);     l[0] = 1 + b * (s[0] ==  w );     for (int i = 1; i < n; i++) l[i] = 1 + l[i - 1] + a + b * (s[i] ==  w );     for (int i = n - 1; i >= 0; i--) d[i] = 1 + d[i + 1] + a + b * (s[i] ==  w );     int j = 1;     int m = 0;     for (int i = 0; i < n; i++) {       while (j < n && l[i] + d[j] + i * a > t) j++;       if ((j < n || l[i] <= t) && i + 1 + n - j > m) m = i + 1 + n - j;     }     int m1 = m;     int i = 1;     j = n - 1;     while (i < j) {       swap(s[i], s[j]);       i++;       j--;     }     l[0] = 1 + b * (s[0] ==  w );     for (int i = 1; i < n; i++) l[i] = 1 + l[i - 1] + a + b * (s[i] ==  w );     for (int i = n - 1; i >= 0; i--) d[i] = 1 + d[i + 1] + a + b * (s[i] ==  w );     j = 1;     m = 0;     for (int i = 0; i < n; i++) {       while (j < n && l[i] + d[j] + i * a > t) j++;       if ((j < n || l[i] <= t) && i + 1 + n - j > m) m = i + 1 + n - j;     }     m = max(m, m1);     cout << min(m, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nod = 1e9 + 7;   const int modulo = (119 << 23) + 1;   const int maxn = 3e5 + 1;   int n, m;   vector<int> a(maxn);   int test() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     int l = 0, r = m;     while (l < r) {       bool flag = false;       int mid = (l + r) / 2;       int now = 0;       for (int i = 0; i < n; i++) {         int x = a[i], y = a[i] + mid;         if (x <= now && y >= now || x <= now + m && y >= now + m) continue;         if (now >= x) {           flag = true;           break;         }         now = a[i];       }       if (flag)         l = mid + 1;       else         r = mid;     }     cout << l;     return 0;   }   int solve(int tmp[], int a, int b, int n) {     int cnt = 0;     int div = tmp[b] - tmp[a];     int now = 2;     for (int i = b + 1; i < n; i++) {       if (tmp[i] == tmp[a] + div * now) {         cnt++, now++;       }     }     return cnt;   }   static int search(int num, int b[], int n) {     for (int i = 0; i < n; i++) {       if (b[i] == num) {         i + 1;         return 0;       }     }     return 1;   }   int donot() { return 0; }   int hack() { return 1; }   string me() {     const char* s =  do not hack me ;     return s;   }   class havenoidea {     int ameaninglessnum = 49935;     bool iamanaduit = 1;       public:     int iwillsolvefiveproblems(int x) { return x; }   };   int main() {     if (hack()) donot();     int tmp[6] = {1, 1, 4, 5, 1, 4};     solve(tmp, search(114514, tmp, 6), 1, 6);     int a, b, c, d;     havenoidea fuck;     fuck.iwillsolvefiveproblems(hack());     test();     if (me() ==  do not fack me )       if (me() ==  do not hack me ) hack() == donot();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[200000], b[200000];   int kmp[200000];   int n, m, i, j, first, curr, val[200000], l;   int dyn[200000];   int sum[200000];   int MOD = 1000000007;   int main(void) {     cin >> b >> a;     n = strlen(a);     m = strlen(b);     kmp[0] = 1;     if (n == 1) {       for (i = 0; i <= m - 1; i++) {         if (a[0] == b[i]) {           l++;           val[l] = i;         }       }     } else {       for (i = 1; i <= n - 1; i++) {         j = kmp[i - 1];         while (j < i && a[i] != a[i - j]) j += kmp[i - 1 - j];         if (j == i) {           if (a[i] == a[0])             kmp[i] = i;           else             kmp[i] = i + 1;         } else           kmp[i] = j;       }       if (a[0] == b[0]) {         first = 0;       } else {         first = 1;       }       for (i = 1; i <= m - 1; i++) {         while (first < i && b[i] != a[i - first]) first += kmp[i - 1 - first];         if (first == i) {           if (b[i] == a[0])             first = i;           else             first = i + 1;         }         if (i - first == n - 1) {           l++;           val[l] = first;           first += kmp[n - 1];         }       }     }     val[0] = -1;     dyn[m] = 0;     sum[m] = 1;     for (i = m - 1; i >= 0; i--) {       while (l > 1 && val[l - 1] >= i) l--;       if (val[l] >= i) {         dyn[i] = dyn[i + 1] + sum[val[l] + n];         if (dyn[i] >= MOD) dyn[i] -= MOD;         sum[i] = sum[i + 1] + dyn[i] + 1;         if (sum[i] >= MOD) sum[i] -= MOD;       } else {         dyn[i] = 0;         sum[i] = sum[i + 1] + 1;       }     }     cout << dyn[0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MOD = INF + 7;   const int N = 1e5 + 5;   int n, a[N], nxt[N], lucky[N];   struct Node {     int mn = INF, cnt = 0, idx = -1, lazy = 0;   } seg[4 * N];   int doLuck(int i, int x) {     if (x > 1e4) return i;     if (x) lucky[i] = x, i++;     i = doLuck(i, 10 * x + 4);     return doLuck(i, 10 * x + 7);   }   void apply(int id, int x) {     seg[id].mn += x;     seg[id].lazy += x;   }   void shift(int id) {     if (seg[id].lazy == 0) return;     apply(2 * id, seg[id].lazy);     apply(2 * id + 1, seg[id].lazy);     seg[id].lazy = 0;   }   Node merge(const Node &x, const Node &y) {     Node z;     z.mn = min(x.mn, y.mn);     if (z.mn == y.mn) z.cnt += y.cnt, z.idx = y.idx;     if (z.mn == x.mn) z.cnt += x.cnt, z.idx = x.idx;     return z;   }   void build(int id = 1, int s = 0, int e = n) {     if (e - s < 2) {       int d = lucky[0] - a[s];       seg[id].mn = d;       seg[id].cnt = 1;       seg[id].idx = s;       return;     }     int md = (s + e) / 2;     build(2 * id, s, md);     build(2 * id + 1, md, e);     seg[id] = merge(seg[2 * id], seg[2 * id + 1]);   }   void update(int l, int r, int x, int id = 1, int s = 0, int e = n) {     if (l >= e || s >= r) return;     if (l <= s && e <= r) {       apply(id, x);       return;     }     shift(id);     int md = (s + e) / 2;     update(l, r, x, 2 * id, s, md);     update(l, r, x, 2 * id + 1, md, e);     seg[id] = merge(seg[2 * id], seg[2 * id + 1]);   }   Node get(int l, int r, int id = 1, int s = 0, int e = n) {     if (l >= e || s >= r) return Node();     if (l <= s && e <= r) return seg[id];     shift(id);     int md = (s + e) / 2;     return merge(get(l, r, 2 * id, s, md), get(l, r, 2 * id + 1, md, e));   }   void recheck() {     if (seg[1].mn >= 0) return;     int x = seg[1].idx;     update(x, x + 1, lucky[nxt[x] + 1] - lucky[nxt[x]]);     nxt[x]++;     recheck();   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int m = doLuck(0, 0);     sort(lucky, lucky + m);     lucky[m] = INF;     int q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     build();     while (q--) {       recheck();       string s;       cin >> s;       int l, r;       cin >> l >> r;       l--;       if (s ==  add ) {         int d;         cin >> d;         update(l, r, -d);       } else {         Node x = get(l, r);         cout << (x.mn == 0) * x.cnt <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long qpow(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % MOD;       y >>= 1;       x = x * x % MOD;     }     return ret % MOD;   }   int main() {     long long n, sum = 0, C = 1;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       C = C * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;       if (i & 1)         sum = (sum + C * qpow(3, i) % MOD * qpow(3, n * (n - i))) % MOD;       else         sum = ((sum - C * qpow(3, i) % MOD * qpow(3, n * (n - i))) % MOD + MOD) %               MOD;     }     sum = sum * 2 % MOD;     C = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i) C = C * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;       long long tmp = qpow(((1 - qpow(3, i)) % MOD + MOD) % MOD, n);       if (n & 1)         tmp = (tmp + qpow(3, i * n)) % MOD;       else         tmp = (tmp - qpow(3, i * n) + MOD) % MOD;       if (i & 1)         ans = (ans + tmp * C) % MOD;       else         ans = ((ans - tmp * C) % MOD + MOD) % MOD;     }     cout << (sum + ans * 3) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mp[200005];   int a[200005];   int n;   int main() {     int y, T, n, m, i, t, j, k, x;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       mp[x] = i + 1;     }     for (i = 0; i < n; i++) {       scanf( %d , &x);       a[i] = mp[x];     }     int c = 1;     int ans = 0;     for (i = 0; i < n; i++) {       if (a[i] == c) {         c++;         ans++;       }     }     printf( %d n , n - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void equalse(int arr[], int n) {     int m = 0, c = 0;     for (int i = 0; i < n; i += 2) {       if (arr[i] > arr[i + 1]) m++;       if (arr[i] < arr[i + 1]) c++;     }     if (c > m) cout <<  Chris ;     if (m > c) cout <<  Mishka ;     if (m == c) cout <<  Friendship is magic!^^ ;   }   void input(int arr[], int n) {     for (int i = 0; i < n; i++) cin >> arr[i];   }   int main() {     int n;     cin >> n;     n *= 2;     int arr[n];     input(arr, n);     equalse(arr, n);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, i, j;     cin >> n;     int x[n], y[n];     for (i = 0; i < n; ++i) {       cin >> x[i] >> y[i];     }     long long int c1 = 0, c2 = 0;     std::map<pair<double, double>, int> d;     std::map<double, int> k, pa;     for (i = 0; i < n - 1; ++i) {       for (j = i + 1; j < n; ++j) {         double p, c;         if (x[i] != x[j]) {           p = (y[j] - y[i]) * 1.000 / (x[j] - x[i]);           c = (x[j] * y[i] - x[i] * y[j]) * 1.000 / (x[j] - x[i]);           if (!d[make_pair(p, c)]) {             d[make_pair(p, c)]++;             c1++;             pa[p]++;           }         } else {           if (!k[x[i]]) {             k[x[i]]++;             c2++;           }         }       }     }     long long int ans = 0;     map<double, int>::iterator it;     for (it = pa.begin(); it != pa.end(); ++it) {       ans += (c1 - (it->second)) * (it->second);     }     ans = ans / 2;     for (it = pa.begin(); it != pa.end(); ++it) {       ans += c2 * (it->second);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> f;   long long n, mm, ret, cur;   long long a[200005], sum[200005];   long long calc(long long m) {     f.clear();     ret = cur = 0;     for (long long i = 0; i < n; i++) {       sum[i + 1] = sum[i] + (a[i] < m ? -1 : 1);       f[sum[i + 1]]++;     }     for (auto it : f)       if (it.first > 0) cur += it.second;     for (long long i = 0; i < n; i++) {       ret += cur;       f[sum[i + 1]]--;       if (sum[i + 1] > sum[i]) cur--;       if (sum[i + 1] > sum[i])         cur -= f[sum[i + 1]];       else         cur += f[sum[i]];     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     vector<long long> v;     cin >> n >> mm;     for (long long i = 0; i < n; i++) cin >> a[i];     cout << calc(mm) - calc(mm + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m;     scanf( %d:%d , &h, &m);     int tmp = 0;     int htmp = h;     tmp = h % 10;     tmp = tmp * 10;     tmp = tmp + h / 10;     if (tmp >= m && tmp < 60)       printf( %d n , tmp - m);     else {       h++;       while (true) {         tmp = 0;         tmp = h % 10;         tmp = tmp * 10;         tmp = tmp + h / 10;         if (tmp < 60) break;         h++;       }       tmp = (h - htmp - 1) * 60 + tmp + (60 - m);       if (h == 24) {         tmp = 0;         printf( %d n , 60 - m);       } else         printf( %d n , tmp);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200010], pos[200010][3], tag[200010][3];   long long ans, num1, num2, cnt1, cnt2;   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n * 2; i++) {       scanf( %d , &a[i]);       pos[a[i]][0]++;       pos[a[i]][pos[a[i]][0]] = i;     }     pos[0][1] = pos[0][2] = 1;     for (i = 1; i <= n; i++) {       cnt1 = fabs(pos[i][1] - pos[i - 1][1]) + fabs(pos[i][2] - pos[i - 1][2]);       cnt2 = fabs(pos[i][1] - pos[i - 1][2]) + fabs(pos[i][2] - pos[i - 1][1]);       if (cnt1 < cnt2)         ans += cnt1;       else         ans += cnt2;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 3e5 + 10;   const long long INF = 1e18;   const long long M = 1e6 + 10;   int main() {     int n, i, j, k, l, p, q;     string s;     cin >> n >> s;     set<char> a;     char st[3] = { R ,  G ,  B };     for (i = 0; i < n; i++) a.insert(s[i]);     if (a.size() == 1) {       cout << *a.begin();       return 0;     }     if (n == 2) {       if (s[i] == s[i + 1])         cout << s[i];       else {         for (i = 0; i < 3; i++) {           if (a.find(st[i]) == a.end()) cout << st[i];         }       }     } else {       if (a.size() == 3)         cout <<  BGR ;       else {         char ch;         string s2 =   ;         for (i = 0; i < 3; i++) {           if (a.find(st[i]) == a.end()) ch = st[i];         }         for (i = 0; i < 3; i++) {           l = 0;           for (j = 0; j < n; j++) {             if (s[j] == st[i]) l++;           }           if (l == 1) {             s2 += ch;             s2 += st[i];             sort(s2.begin(), s2.end());             cout << s2;             break;           }         }         if (l != 1) cout <<  BGR ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void _IOS() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);   }   long long a[500009], b[500009];   long long n, m, k;   map<long long, bool> pg;   long long dp[100009][3];   int main() {     _IOS();     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int i = n - 2;       while (i >= 0 && k--) {         a[n - 1] += a[i];         a[i] = 0;         i--;       }       long long mn = (long long)1e10, mx = 0;       for (int i = 0; i < n; i++) {         mn = min(a[i], mn);         mx = max(a[i], mx);       }       cout << abs(mx - mn) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int len, S, T;   bool o[N * 40][15];   char str[N];   long long n, Ans;   struct matrix {     long long f[4][4];     matrix() { memset(f, 63, sizeof(f)); }   } Trans, bin[70], X;   void cmin(long long& x, long long y) { x = x < y ? x : y; }   matrix operator*(matrix a, matrix b) {     matrix c;     for (int i = 0; i < 4; ++i)       for (int j = 0; j < 4; ++j)         for (int k = 0; k < 4; ++k) cmin(c.f[i][j], a.f[i][k] + b.f[k][j]);     return c;   }   int bfs() {     queue<int> q, d;     q.push(S), d.push(1);     while (!q.empty()) {       int u = q.front(), dis = d.front();       q.pop(), d.pop();       if (!o[u * 4 + T][dis + 1]) return dis + 1;       for (int i = 0; i < 4; ++i) {         int v = u * 4 + i;         q.push(v), d.push(dis + 1);       }     }     return 233;   }   int main() {     scanf( %lld , &n);     scanf( %s , str + 1);     len = strlen(str + 1);     for (int i = 1; i <= len; ++i)       for (int k = 1, tp = 0; i + k - 1 <= len && k <= 10; ++k)         tp = tp * 4 + str[i + k - 1] -  A , o[tp][k] = 1;     for (int i = 0; i < 4; ++i)       for (int j = 0; j < 4; ++j) S = i, T = j, Trans.f[i][j] = bfs() - 1;     bin[0] = Trans;     for (int i = 1; i < 62; ++i) bin[i] = bin[i - 1] * bin[i - 1];     memset(X.f, 0, sizeof(X.f));     for (int i = 61; ~i; --i) {       matrix tmp = X * bin[i];       long long mn = 2e18;       for (int j = 0; j < 4; ++j)         for (int k = 0; k < 4; ++k) cmin(mn, tmp.f[j][k]);       if (mn < n) X = tmp, Ans += 1ll << i;     }     ++Ans;     printf( %lld , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q, t, v, u, w;     map<long long, long long> cost;     cin >> q;     while (q--) {       cin >> t;       if (t == 1) {         cin >> v >> u >> w;         while (v != u) {           while (u > v) {             cost[u] += w;             u >>= 1;           }           while (v > u) {             cost[v] += w;             v >>= 1;           }         }       } else {         cin >> v >> u;         long long res = 0;         while (v != u) {           while (u > v) {             res += cost[u];             u >>= 1;           }           while (v > u) {             res += cost[v];             v >>= 1;           }         }         cout << res << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e17;   const double DINF = numeric_limits<double>::max();   const int ITER = 300;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const int MAXN = 1e5 + 10;   int n, m;   vector<pair<int, int> > v;   void solve() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int q, w;       cin >> q >> w;       v.push_back({w, q});     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long ans = 0;     for (int i = 0; i < v.size(); i++) {       long long cnt = i + 1;       long long need =           (cnt & 1) ? cnt * (cnt - 1) / 2 : cnt * (cnt - 1) / 2 + cnt / 2 - 1;       if (need + 1 <= n) {         ans += v[i].first;       }     }     cout << ans << endl;   }   int main() {     cout << setprecision(12) << fixed;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   int n, root = 0;   vector<vector<int>> adj;   vector<int> d;   void dfs() {     d.assign(n, INF);     d[root] = 0;     queue<int> q;     q.push(root);     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto nxt : adj[cur])         if (d[nxt] == INF) {           d[nxt] = 1 + d[cur];           q.push(nxt);         }     }   }   int main() {     cin >> n;     adj.resize(n);     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p -= 1;       adj[i].push_back(p);       adj[p].push_back(i);     }     dfs();     vector<int> cnt(n, 0);     for (int i = 0; i < n; i++) cnt[d[i]] += 1;     int res = 0;     for (int i = 0; i < n; i++) res += (cnt[i] & 1);     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, dx[]{-1, 0, 0, 1}, dy[]{0, -1, 1, 0};   vector<string> tab;   vector<vector<int>> dist;   priority_queue<pair<int, pair<int, int>>> PQ;   int dijkstra(int x, int y) {     dist.assign(n, vector<int>(m, INT_MAX / 2));     dist[x][y] = 1;     PQ.push({0, {x, y}});     while (!PQ.empty()) {       int d = -PQ.top().first;       x = PQ.top().second.first;       y = PQ.top().second.second;       PQ.pop();       if (d > dist[x][y]) continue;       for (int i = 0; i < 4; i++) {         int x2 = x + dx[i], y2 = y + dy[i];         if (x2 < 0 or x2 >= n or y2 < 0 or y2 >= m) continue;         d = dist[x][y] + (tab[x][y] != tab[x2][y2]);         if (dist[x2][y2] > d) {           dist[x2][y2] = d;           PQ.push({-d, {x2, y2}});         }       }     }     int maxi = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (tab[i][j] ==  B ) maxi = max(maxi, dist[i][j]);     return maxi;   }   int main() {     cin >> n >> m;     tab.resize(n);     for (int i = 0; i < n; i++) cin >> tab[i];     int ans = INT_MAX;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) ans = min(ans, dijkstra(i, j));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp1[101010] = {0}, dp2[101010] = {0};   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int h[101010];     for (int i = 0; i < n; i++) cin >> h[i];     dp1[0] = 1;     for (int i = 1; i < n - 1; i++) {       dp1[i] = dp1[i - 1] + 1;       dp1[i] = min(h[i], dp1[i]);       if (h[i] > h[i - 1]) {         dp1[i] = min(dp1[i], h[i - 1] + 1);       }       if (h[i] > h[i + 1]) {         dp1[i] = min(dp1[i], h[i + 1] + 1);       }     }     dp2[n - 1] = 1;     for (int i = n - 2; i >= 1; i--) {       dp2[i] = dp2[i + 1] + 1;       dp2[i] = min(h[i], dp2[i]);       if (h[i] > h[i - 1]) {         dp2[i] = min(dp2[i], h[i - 1] + 1);       }       if (h[i] > h[i + 1]) {         dp2[i] = min(dp2[i], h[i + 1] + 1);       }     }     int ma = 1;     for (int i = 0; i < n; i++) {       ma = max(ma, min(dp1[i], dp2[i]));     }     cout << ma << endl;     return 0;   }