malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 1;   const long long nol = 0;   long long n, k, a, cnt, ans, j, mx;   deque<long long> v, vc;   void vkoshp() {     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     for (long long i = 0; i < n; i++) {       cin >> a;       if (a == 1)         cnt += v[i], vc.push_back(0);       else         ans += v[i], vc.push_back(v[i]);       mx = max(mx, ans);       if (vc.size() == k) {         ans -= vc[0];         vc.pop_front();       }     }     cout << cnt + mx << endl;   }   int main() {     cout.tie(NULL);     cin.tie(NULL);     ios_base::sync_with_stdio(0);     long long t = 1;     while (t--) vkoshp();   }
#include <bits/stdc++.h>   using namespace std;   int f[10000001];   int main() {     int n, m, l, r;     scanf( %d%d , &n, &m);     long long ans = 0;     int Max0 = max(n * 2, m);     for (long long b = 1; b <= n; ++b) {       ans += 2 * min(b * b, (long long)m);       l = max(0, int(ceil(sqrt(b * b - m))));       r = int(floor(sqrt(b * b - 1)));       ++f[-b - r + Max0], --f[-b - l + 1 + Max0], ++f[-b + l + Max0],           --f[-b + r + 1 + Max0];     }     int s = 0;     for (int i = 0; i < Max0; ++i) {       s += f[i];       if (s > 1) ans -= s - 1;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t = 0;   int ans = 1;   long long int prime(long long int n) {     while (n % 2 == 0) {       if (t == 2) break;       n = n / 2;       t++;       ans *= 2;     }     for (int i = 3; i <= sqrt(n); i += 2) {       while (n % i == 0) {         if (t == 2) break;         n = n / i;         t++;         ans *= i;       }       if (t == 2) break;     }     if (n > 2 && t != 2) {       ans *= n;       t++;       n = 1;     }     return n;   }   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     long long int n;     cin >> n;     if (n == 1)       cout << 1 <<   n  << 0;     else {       long long int final = prime(n);       if (final == 1 && t == 1)         cout << 1 << endl << 0;       else if (final == 1 && t == 2)         cout << 2;       else if (t == 2)         cout << 1 <<   n  << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &a) {     return os <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &a) {     os <<  [ ;     for (unsigned long long i = 0; i < a.size(); i++)       os << a[i] << (i < a.size() - 1 ?  ,   :   );     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &a) {     os <<  { ;     for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {       typename set<T>::iterator jt = it;       os << *it << (++jt != a.end() ?  ,   :   );     }     os <<  } ;     return os;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, map<T1, T2> &a) {     os <<  { n ;     for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {       typename map<T1, T2>::iterator jt = it;       os <<      << it->first <<  :   << it->second          << (++jt != a.end() ?  , n  :   n );     }     os <<  } ;     return os;   }   long long n, m;   long long a[2005];   long long dp[2005][2];   bool check(long long lim) {     memset(dp, 127, sizeof(dp));     dp[0][0] = dp[0][1] = 0;     for (long long i = 1; i <= n; i++) {       dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + 1;       dp[i][1] = min(dp[i][1], i - 1);       for (long long j = 1; j < i; j++) {         long long diff = abs(a[i] - a[j]);         if (diff > lim * (i - j)) continue;         dp[i][1] = min(dp[i][1], dp[j][1] + (i - j - 1));       }     }     if (min(dp[n][0], dp[n][1]) <= m) return true;     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     long long l = 0, r = 2e9;     while (l != r) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid + 1;     }     cout << l <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX - 10000000;   const double eps = 1e-8;   long long t1, t2, x1, x2, t0;   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2) {       cout << x1 <<     << x2 << endl;       return 0;     }     long long minp = 12345678, minq = 1;     long long y2, ans = 0;     for (long long y1 = 0; y1 <= x1; y1++) {       long long Left = 0, Right = x2, Mid;       if (y1)         while (Left <= Right) {           Mid = Left + Right >> 1;           if ((t2 - t1) * Mid < (t0 - t1) * (Mid + y1))             Left = Mid + 1;           else             Right = Mid - 1;         }       else         Left = x2;       if ((t2 - t1) * Left < (t0 - t1) * (Left + y1) || Left > x2) continue;       if (Left * (t2 - t1) * minq - minq * (t0 - t1) * (Left + y1) <           minp * (Left + y1)) {         y2 = Left;         ans = y1 + y2;         minp = Left * (t2 - t1) - (t0 - t1) * (Left + y1);         minq = Left + y1;       } else if (Left * (t2 - t1) * minq - minq * (t0 - t1) * (Left + y1) ==                  minp * (Left + y1)) {         if (Left + y1 > ans) {           y2 = Left;           ans = y1 + y2;         }       }     }     cout << ans - y2 <<     << y2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int A[310000];   int dp[31000][210][4][2];   int ins(int i, int k, int bit) {     if (k == 1) {       if (bit % 2 == 0) return A[i];       return -A[i];     }     if (k == K) {       if (bit / 2 == 0) return -A[i];       return A[i];     }     int res = 0;     if (bit % 2 == 0)       res += A[i];     else       res -= A[i];     if (bit / 2 == 0)       res -= A[i];     else       res += A[i];     return res;   }   int main() {     for (int(i) = 0; (i) < (31000); (i)++)       for (int(j) = 0; (j) < (210); (j)++)         for (int(k) = 0; (k) < (4); (k)++)           for (int(l) = 0; (l) < (2); (l)++) dp[i][j][k][l] = -(1 << 30);     scanf( %d%d , &N, &K);     for (int(i) = 0; (i) < (N); (i)++) scanf( %d , &A[i]);     dp[0][0][0][0] = 0;     for (int(i) = 0; (i) < (N); (i)++) {       for (int(j) = 0; (j) < (K + 1); (j)++)         for (int(b) = 0; (b) < (4); (b)++) {           dp[i + 1][j][b][0] = max(dp[i + 1][j][b][0], dp[i][j][b][0]);           dp[i + 1][j + 1][b % 2 * 2][1] =               max(dp[i + 1][j + 1][b % 2 * 2][1],                   dp[i][j][b][0] + ins(i, j + 1, b % 2 * 2));           dp[i + 1][j + 1][b % 2 * 2][1] =               max(dp[i + 1][j + 1][b % 2 * 2][1],                   dp[i][j][b][1] + ins(i, j + 1, b % 2 * 2));           dp[i + 1][j + 1][b % 2 * 2 + 1][1] =               max(dp[i + 1][j + 1][b % 2 * 2 + 1][1],                   dp[i][j][b][0] + ins(i, j + 1, b % 2 * 2 + 1));           dp[i + 1][j + 1][b % 2 * 2 + 1][1] =               max(dp[i + 1][j + 1][b % 2 * 2 + 1][1],                   dp[i][j][b][1] + ins(i, j + 1, b % 2 * 2 + 1));           dp[i + 1][j][b][1] =               max(dp[i + 1][j][b][1], dp[i][j][b][1] + ins(i, j, b));           dp[i + 1][j][b][0] = max(dp[i + 1][j][b][0], dp[i][j][b][1]);         }       for (int(j) = 0; (j) < (K + 1); (j)++)         for (int(k) = 0; (k) < (4); (k)++)           for (int(l) = 0; (l) < (2); (l)++)             if (dp[i + 1][j][k][l] < -(1 << 29)) dp[i + 1][j][k][l] = -(1 << 30);     }     int res = -(1 << 30);     for (int(b) = 0; (b) < (4); (b)++)       for (int(l) = 0; (l) < (2); (l)++) res = max(res, dp[N][K][b][l]);     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long powmod(long long n, long long q) {     long long ans = 1;     n %= 1000000007;     while (q > 0) {       if (q & 1) ans = (ans * n) % 1000000007;       n = (n * n) % 1000000007;       q >>= 1;     }     return ans % 1000000007;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc = 1;     while (tc--) {       int n, ans = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           int k = i ^ j;           if (k < i + j) {             if (i < k + j) {               if (j < i + k) {                 if (k >= 1 && k <= n) ans++;               }             }           }         }       }       cout << ans / 3 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int reverseChar(char input) {     const int N = 8;     int output(0);     for (int p = 0; p < N; p++) {       output = 2 * output + (input % 2);       input /= 2;     }     return output;   }   int main() {     const int N = 256;     std::string line;     getline(std::cin, line);     int previous = 0;     for (int p = 0; p < line.size(); p++) {       int current = reverseChar(line[p]);       printf( %d n , (N + previous - current) % N);       previous = current;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   const int MOD = 1000000007;   int n, x[N], y[N], w[N][N], vis[N];   inline void dfs(int v, int val) {     for (int u = 0; u < n; u++) {       if (w[v][u] > val) {         if (vis[u] == vis[v]) throw 0;         if (vis[u] != -1) continue;         vis[u] = !vis[v];         dfs(u, val);       }     }   }   inline int check(int val) {     memset(vis, -1, sizeof vis);     int ans = 1;     for (int i = 0; i < n; i++)       if (vis[i] == -1) {         try {           vis[i] = 0;           dfs(i, val);         } catch (...) {           return 0;         }         ans += ans;         if (ans >= MOD) ans -= MOD;       }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , x + i, y + i);     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         w[i][j] = w[j][i] = abs(x[i] - x[j]) + abs(y[i] - y[j]);     int lo = 0, hi = 10050, mid;     while (lo < hi) {       mid = lo + hi >> 1;       if (check(mid))         hi = mid;       else         lo = mid + 1;     }     cout << hi <<   n  << check(hi) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int rowblk[200005];   long long int colblk[200005];   long long int col[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int l, n, i, j, k, m;     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> k >> l;       rowblk[k] = 1;       colblk[l] = 1;     }     long long int cnt = 0;     for (i = 2; i < n; i++) {       if (colblk[i] == 0) {         cnt++;         col[i] = 1;       }     }     for (i = 2; i < n; i++) {       if (rowblk[i] == 0) {         if (n % 2 != 0 && i == n / 2 + 1) {           if (col[i] == 0) cnt++;         } else {           cnt++;         }       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200001];   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr, arr + n, greater<int>());     long long gcf = 0, total = 0;     for (int i = 0; i < n; ++i) {       gcf = gcd(arr[0] - arr[i], gcf);       total += (arr[0] - arr[i]);     }     cout << total / gcf <<     << gcf << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout <<  ?  <<    ;     fflush(stdout);     for (int i = 0; i < 100; i++) {       cout << i <<    ;       fflush(stdout);     }     cout << endl;     int n;     cin >> n;     cout <<  ?  <<    ;     fflush(stdout);     long long a = 0;     for (int i = 0; i < 100; i++) {       a += (1 << 7);       cout << a <<    ;       fflush(stdout);     }     cout << endl;     int b;     cin >> b;     bitset<14> x(n), y(b), z;     for (int i = 0; i < 14; i++) {       if (i < 7)         z[i] = y[i];       else         z[i] = x[i];     }     cout <<  !   << z.to_ulong();   }
#include <bits/stdc++.h>   using namespace std;   struct Pair {     int a, b, c;   };   int a1[200009], a2[200009];   vector<Pair> arr;   bool rules(Pair x, Pair y) { return ((x.a - x.b) < (y.a - y.b)); }   int main() {     int n, k, sum = 0;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a1[i]);     for (int i = 0; i < n; i++) {       scanf( %d , &a2[i]);       Pair p;       p.a = a1[i], p.b = a2[i];       arr.push_back(p);     }     sort(arr.begin(), arr.end(), rules);     for (int i = 0; i < k; i++) sum += arr[i].a;     for (int i = k; i < n; i++) sum += min(arr[i].a, arr[i].b);     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &x, T y) {     if (y > x) x = y;   }   template <class T>   inline void umin(T &x, T y) {     if (y < x) x = y;   }   const int N = 2e5 + 5, B = 0x7fffffff;   map<int, int> comp;   set<int> s;   vector<int> ans;   int a[N];   int st[4 * N];   int n;   int nn;   void upd(int l, int r, int id, int u, int v) {     if (l == r) {       umax(st[id], v);       return;     }     int mid = (l + r) >> 1;     if (u <= mid)       upd(l, mid, id << 1, u, v);     else       upd(mid + 1, r, id << 1 | 1, u, v);     st[id] = max(st[id << 1], st[id << 1 | 1]);   }   int get(int l, int r, int id, int ql, int qr) {     if (r < ql || l > qr) return 0;     if (l >= ql && r <= qr) return st[id];     int mid = (l + r) >> 1;     return max(get(l, mid, id << 1, ql, qr),                get(mid + 1, r, id << 1 | 1, ql, qr));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), s.insert(a[i]), s.insert(a[i] - 1);     for (int x : s) comp[x] = ++nn;     for (int i = n; i >= 1; i--) {       int ppq = (get(1, nn, 1, 1, comp[a[i] - 1]));       ans.push_back(ppq == 0 ? -1 : ppq - i - 1);       upd(1, nn, 1, comp[a[i]], i);     }     for (int i = (int)ans.size() - 1; i >= 0; i--) printf( %d  , ans[i]);     return !1;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long int MOD = 1000000007;   int main() {     int t, a, b;     scanf( %lld , &t);     while (t--) {       scanf( %d %d , &a, &b);       if (b >= a)         printf( 1 );       else {         vector<int> v;         bool k = false;         int c;         for (int i = 1; i * i <= a; i++) {           if (a % i == 0) {             v.push_back(i);             v.push_back(a / i);             k = true;           }         }         if (!k)           printf( %d , a);         else {           sort(v.begin(), v.end(), greater<int>());           for (int i = 0; i < (int)v.size(); i++) {             if (v[i] <= b) {               printf( %d , a / v[i]);               break;             }           }         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void __p(T a) {     cout << a;   }   template <typename T, typename U>   void __p(pair<T, U> a) {     cout <<  { ;     __p(a.first);     cout <<  , ;     __p(a.second);     cout <<  } ;   }   template <typename T>   void __p(std::vector<T> a) {     cout <<  { ;     for (auto it = a.begin(); it < a.end(); it++)       __p(*it), cout <<  ,} [it + 1 == a.end()];   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 2) {       cout << 2 - k * (a[0] | a[1]) << endl;       return;     }     long long ans = 2 - k * (a[0] | a[1]);     for (long long i = n - 2; i > n - 300 && i >= 0; i--) {       for (long long j = n - 1; j > i; j--) {         ans = max(ans, (i + 1) * (j + 1) - k * (a[i] | a[j]));       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     cin >> tc;     for (int t = 1; t <= tc; t++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x;   bool X[26];   int mat[6][6];   int niz[26];   int sum;   bool check() {     sum = 0;     for (int i = 0; i < n; i++) sum += mat[i][0];     for (int j = 1; j < n; j++) {       int st = 0;       for (int i = 0; i < n; i++) st += mat[i][j];       if (st != sum) return false;     }     for (int i = 0; i < n; i++) {       int st = 0;       for (int j = 0; j < n; j++) st += mat[i][j];       if (st != sum) return false;     }     int sz = 0;     for (int i = 0; i < n; i++) {       sz += mat[i][i];     }     if (sz != sum) return false;     sz = 0;     for (int i = 0; i < n; i++) {       sz += mat[i][n - i - 1];     }     if (sz != sum) return false;     return true;   }   vector<pair<int, int> > pos;   vector<int> vals;   int empty_cnt = 0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n * n; i++) {       scanf( %d , &niz[i]);       vals.push_back(i);       pos.push_back(make_pair(i / n, i % n));     }     do {       for (int i = 0; i < pos.size(); i++) {         mat[pos[i].first][pos[i].second] = niz[vals[i]];       }       if (check()) {         break;       }     } while (next_permutation(vals.begin(), vals.end()));     printf( %d n , sum);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         printf( %d  , mat[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200001], b[200001], m;   int main() {     cin >> n >> m;     n = n + m;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     vector<int> vec;     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       if (b[i] == 1) {         vec.push_back(a[i]);       }     }     vec.push_back(2e9 + 1);     int l = 0, cnt = 0, r = 1, c = 0;     while (l < vec.size() - 1 && r <= n) {       if (b[r] == 0) {         while (abs(a[r] - vec[l]) > abs(a[r] - vec[l + 1])) {           cout << cnt <<    ;           c++;           l++;           cnt = 0;         }         cnt++;       }       r++;     }     cout << cnt <<    ;     for (int i = 0; i < vec.size() - 2 - c; i++) {       cout <<  0  ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<1000> mask[1010];   long long sqr(int x) { return 1LL * x * x; }   int n, m, k;   int px[10010], py[10010], x[10010], y[10010], r[10010];   int main() {     int i, j;     scanf( %d%d%d , &n, &m, &k);     for (i = 0; i < n; ++i) {       scanf( %d%d , &px[i], &py[i]);     }     for (i = 0; i < m; ++i) {       scanf( %d%d%d , &r[i], &x[i], &y[i]);     }     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j)         if (sqr(px[i] - x[j]) + sqr(py[i] - y[j]) <= sqr(r[j])) mask[i][j] = 1;     }     while (k--) {       int a, b;       scanf( %d%d , &a, &b);       printf( %d n , (mask[a - 1] ^ mask[b - 1]).count());     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n;   int head[N], Next[N << 1], ver[N << 1], size[N], edge[N << 1], w[N];   int tot;   long long ans;   void add(int x, int y, int z) {     ver[++tot] = y;     edge[tot] = z;     Next[tot] = head[x];     head[x] = tot;   }   void dfs(int x, int fa) {     size[x] = 1;     for (int i = head[x]; i; i = Next[i]) {       int y = ver[i];       if (y == fa) continue;       dfs(y, x);       size[x] += size[y];     }   }   void solve(int x, int fa, long long s) {     for (int i = head[x]; i; i = Next[i]) {       int y = ver[i], z = edge[i];       if (y == fa) continue;       if (s + (long long)z > (long long)w[y])         ans += (long long)size[y];       else         solve(y, x, max(0ll, s + (long long)z));     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (int i = 2; i <= n; i++) {       int p, c;       scanf( %d%d , &p, &c);       add(p, i, c);       add(i, p, c);     }     dfs(1, 0);     solve(1, 0, 0ll);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   long long n, k;   long long a[maxn];   int vis[maxn];   long long ans = 0;   bool Overflow(long long x, long long y) {     if (x > LLONG_MAX / y)       return false;     else       return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(vis, 0, sizeof(vis));     memset(a, 0, sizeof(a));     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     vis[n + 1] = -1;     for (int i = n; i >= 1; i--) {       if (a[i] > 1)         vis[i] = i;       else         vis[i] = vis[i + 1];     }     long long p = 1;     long long s = 0;     for (int i = 1; i <= n; i++) {       int j = i;       p = a[i];       s = a[i];       if (p == s * k) ans++;       while (1) {         int z = vis[j + 1];         if (z == -1) z = n + 1;         int ones = z - j - 1;         if (p % k == 0 && p / k - s >= 1 && p / k - s <= ones) {           ans++;         }         if (z == n + 1) break;         if (Overflow(p, a[z])) {           p = p * a[z];           j = z;           s = s + a[z] + ones;           if (p == s * k) ans++;         } else           break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 5;   long long N, K;   long long v[MAXN];   int main() {     cin >> N >> K;     for (int i = 0; i < N; i++) cin >> v[i];     sort(v, v + N);     long long resp = N;     for (int i = 0; i < N; i++) {       long long value = v[i] * K;       int l = i + 1, r = N - 1;       while (l <= r) {         int mid = (l + r) / 2;         if (v[mid] == value) {           resp--;           v[mid] = -1;           break;         }         if (v[mid] < value)           l = mid + 1;         else           r = mid - 1;       }     }     cout << resp << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, n, c = 0, p = 0, al, bl, l = 0;     string s;     cin >> s;     for (i = 0; i < s.length(); i++) {       l++;       c += (s[i] -  0 );       if (c % 3 == 0 || (s[i] -  0 ) % 3 == 0 || l >= 3) {         p++;         c = 0;         l = 0;       }     }     if (s[0] ==  0 ) p--;     cout << p;   }
#include <bits/stdc++.h>   using namespace std;   const int NMX = 5007;   const int MMX = 20007;   long long a[NMX][NMX];   long long mi[NMX];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int k, l;       scanf( %d %d , &k, &l);       a[k % n][l % n] += 1;     }     for (int i = 0; i < n; i++) {       bool first = false;       for (int j = i; j < (n + i); j++) {         if (first == false && a[i][j % n] >= 1) {           mi[i] += abs(j - i);           first = true;           a[i][j % n] -= 1;         }         mi[i] += a[i][j % n] * n;       }     }     for (int i = 1; i <= n; i++) {       long long ans = 0;       for (int j = 1; j <= n; j++) {         if (mi[j % n] >= 1)           ans = max(ans, mi[j % n] + ((i > j) ? n - i + j : j - i));       }       cout << ans <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int h[n];     for (int i = 0; i < n; i++) {       cin >> h[i];     }     int wys[n][2];     int rosnpr = 0;     int rosnlw = 0;     for (int i = 0; i < n; i++) {       if (h[i] > rosnpr) {         rosnpr++;         wys[i][0] = rosnpr;       } else {         rosnpr = h[i];         wys[i][0] = rosnpr;       }     }     for (int i = n - 1; i >= 0; i--) {       if (h[i] > rosnlw) {         rosnlw++;         wys[i][1] = rosnlw;       } else {         rosnlw = h[i];         wys[i][1] = rosnlw;       }     }     int maxi = 0;     for (int i = 0; i < n; i++) {       if (min(wys[i][0], wys[i][1]) > maxi) {         maxi = min(wys[i][0], wys[i][1]);       }     }     cout << maxi;   }