malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1e6 + 5;   const int N = 2e5 + 5;   const long long int mod = 1e9 + 7;   const long long int mx = 1e16;   bool comp(const int a, const int b) { return a > b; }   const double PI = 2 * acos(0.0);   long long int fac[N];   void pre() {     fac[0] = 1LL;     for (long long int i = 1; i < N; i++) {       fac[i] = 1LL * i * fac[i - 1];       if (fac[i] >= mod) fac[i] %= mod;     }   }   long long int power(long long int a, long long int b) {     long long int x = 1;     while (b) {       if (b & 1) {         x *= a;         if (x >= mod) x %= mod;       }       a *= a;       if (a >= mod) a %= mod;       b >>= 1;     }     return x;   }   long long int inv(long long int k) { return power(k, mod - 2); }   int main() {     vector<int> v1, v2;     int x, t, a, b, da, db;     cin >> x >> t >> a >> b >> da >> db;     int t1 = t;     int t2 = t;     int x1 = x;     int x2 = x;     if (x == 0) {       printf( YES n );       return 0;     }     for (long long int i = 0; i < t; i++) {       if (a - i * da == x || b - i * db == x) {         printf( YES n );         return 0;       }     }     for (long long int i = 0; i < t; i++) {       for (long long int j = 0; j < t; j++) {         int res = a - i * da + b - j * db;         if (res == x) {           printf( YES n );           return 0;         }       }     }     printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * (1e5) + 10, inf = 2147483647;   long long ans;   int n, lastR, lastB, lastP, mxR, mxB;   int main() {     int x;     char c;     scanf( %d , &n);     lastR = lastB = lastP = -inf;     mxR = mxB = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d %c n , &x, &c);       if (c ==  R  || c ==  P ) {         if (lastR != -inf) ans += x - lastR, mxR = max(mxR, x - lastR);         lastR = x;       }       if (c ==  B  || c ==  P ) {         if (lastB != -inf) ans += x - lastB, mxB = max(mxB, x - lastB);         lastB = x;       }       if (c ==  P ) {         if (lastP != -inf) ans += min(0, x - lastP - mxR - mxB);         lastP = x;         mxR = mxB = 0;       }     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[41][1001][1001];   int bir(int n) {     int s = 0;     while (n > 0) {       s += n % 2;       n /= 2;     }     return s;   }   bool fun(int x, int i) {     if (i < 0) return 0;     return ((x >> i) & 1);   }   bool funk(int a, int b, int c, int m) {     for (int i = 0; i < m; i++) {       if (!(fun(a, i) || fun(b, i) || fun(c, i) || fun(b, i - 1) ||             fun(b, i + 1)))         return 1;     }     return 0;   }   int main() {     int n, m, i, j, msk, pmsk, tmsk, ans = 1e9;     cin >> n >> m;     if (n < m) swap(n, m);     for (i = 0; i <= n; i++) {       for (pmsk = 0; pmsk < (1 << m); pmsk++) {         for (msk = 0; msk < (1 << m); msk++) {           a[i][pmsk][msk] = 1e9;         }       }     }     for (i = 0; i < (1 << m); i++) a[0][0][i] = bir(i);     for (i = 1; i <= n; i++) {       for (pmsk = 0; pmsk < (1 << m); pmsk++) {         for (msk = 0; msk < (1 << m); msk++) {           for (tmsk = 0; tmsk < (1 << m); tmsk++) {             if (funk(tmsk, pmsk, msk, m)) continue;             a[i][pmsk][msk] =                 min(a[i][pmsk][msk], a[i - 1][tmsk][pmsk] + bir(msk));           }         }       }     }     for (i = 0; i < (1 << m); i++) {       ans = min(ans, a[n][i][0]);     }     cout << n * m - ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long k, left;     cin >> k;     long long base = k + 1;     vector<long long> v;     v.push_back(-1);     left = base;     for (long long i = 1; i < 2001; i++) {       left++;       if (left > 1000000) {         v.push_back(1000000);         left -= 1000000;       } else {         v.push_back(left);         break;       }     }     cout << v.size() << endl;     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   char buf[1 << 7];   string s;   int smask;   int D1[5][5] = {{0, 3, 7, -1, -1},                   {1, 4, 8, 12, -1},                   {2, 5, 9, 13, 16},                   {6, 10, 14, 17, -1},                   {11, 15, 18, -1, -1}};   int D2[5][5] = {{2, 6, 11, -1, -1},                   {1, 5, 10, 15, -1},                   {0, 4, 9, 14, 18},                   {3, 8, 13, 17, -1},                   {7, 12, 16, -1, -1}};   int D3[5][5] = {{0, 1, 2, -1, -1},                   {3, 4, 5, 6, -1},                   {7, 8, 9, 10, 11},                   {12, 13, 14, 15, -1},                   {16, 17, 18, -1, -1}};   inline void init() {     int m = 0;     smask = 0;     for (int i = 0; i < 5; ++i) {       gets(buf);       s = string(buf);       int l = (int)s.length();       string stringstream =   ;       for (int j = 0; j < l; ++j)         if (s[j] ==  .  || s[j] ==  O ) stringstream += s[j];       s = stringstream;       l = (int)s.length();       for (int j = 0; j < l; ++j) {         if (s[j] ==  O ) smask |= (1 << m);         ++m;       }     }   }   int f[1 << 20];   int rec(int mask) {     if (f[mask] != -1) return f[mask];     for (int x = 0; x < 5; ++x) {       int n = 3;       if (x == 1 || x == 3) n = 4;       if (x == 2) n = 5;       for (int i = 0; i < n; ++i) {         int nmask = mask;         for (int j = i; j < n; ++j) {           int p = D1[x][j];           if (!(mask & (1 << p))) break;           nmask ^= (1 << p);           if (!rec(nmask)) return f[mask] = 1;         }       }     }     for (int x = 0; x < 5; ++x) {       int n = 3;       if (x == 1 || x == 3) n = 4;       if (x == 2) n = 5;       for (int i = 0; i < n; ++i) {         int nmask = mask;         for (int j = i; j < n; ++j) {           int p = D2[x][j];           if (!(mask & (1 << p))) break;           nmask ^= (1 << p);           if (!rec(nmask)) return f[mask] = 1;         }       }     }     for (int x = 0; x < 5; ++x) {       int n = 3;       if (x == 1 || x == 3) n = 4;       if (x == 2) n = 5;       for (int i = 0; i < n; ++i) {         int nmask = mask;         for (int j = i; j < n; ++j) {           int p = D3[x][j];           if (!(mask & (1 << p))) break;           nmask ^= (1 << p);           if (!rec(nmask)) return f[mask] = 1;         }       }     }     return f[mask] = 0;   }   int main() {     init();     memset(f, -1, sizeof f);     if (rec(smask))       puts( Karlsson );     else       puts( Lillebror );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[500000];   const int mod = 1000003;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     int result = 1;     for (int i = 0; i < n; i++) {       bool ok1 = false, ok2 = false;       for (int j = 0; j < m; j++) {         if (j % 2 == 0 && (s[i][j] ==  1  || s[i][j] ==  2 )) ok1 = true;         if (j % 2 == 1 && (s[i][j] ==  3  || s[i][j] ==  4 )) ok1 = true;         if (j % 2 == 1 && (s[i][j] ==  1  || s[i][j] ==  2 )) ok2 = true;         if (j % 2 == 0 && (s[i][j] ==  3  || s[i][j] ==  4 )) ok2 = true;       }       if (ok1 && ok2) result *= 0;       if (!ok1 && !ok2) result = (result * 2) % mod;     }     for (int j = 0; j < m; j++) {       bool ok1 = false, ok2 = false;       for (int i = 0; i < n; i++) {         if (i % 2 == 0 && (s[i][j] ==  4  || s[i][j] ==  1 )) ok1 = true;         if (i % 2 == 1 && (s[i][j] ==  2  || s[i][j] ==  3 )) ok1 = true;         if (i % 2 == 1 && (s[i][j] ==  4  || s[i][j] ==  1 )) ok2 = true;         if (i % 2 == 0 && (s[i][j] ==  2  || s[i][j] ==  3 )) ok2 = true;       }       if (ok1 && ok2) result *= 0;       if (!ok1 && !ok2) result = (result * 2) % mod;     }     cout << result;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, t, p = 0, hPxl, hPxl1, wPxl, Pxl, sum = 0;     scanf( %d , &n);     int h[n + 5], w[n + 5];     for (i = 0; i < n; ++i) {       scanf( %d %d , &w[i], &h[i]);       sum += w[i];     }     hPxl = *max_element(h, h + n);     for (i = 0; i < n; ++i) {       wPxl = sum - w[i];       if (hPxl == h[i] && p == 0) {         t = h[i];         h[i] = 0;         hPxl1 = *max_element(h, h + n);         Pxl = wPxl * hPxl1;         ++p;       } else {         Pxl = wPxl * hPxl;       }       printf( %d  , Pxl);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const long long int LINF = 1LL * INF * INF;   const int MAXN = 2e5 + 10;   const int MAXM = 5e3 + 10;   priority_queue<int> pq;   vector<vector<int> > graph;   queue<int> que;   long long int mygcd(long long int a, long long int b) {     return a ? mygcd(b % a, a) : b;   }   int main() {     long long int n, m, k, a, b, x, y, q;     int sum = 0;     int cnt = 0;     int mx = 0;     int mn = INF;     int cur = 0, idx = -1;     int tc;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long int res = n;     for (long long int i = 1; i * i <= n; i++) {       if (n % i) continue;       a = mygcd(i, n / i);       if (a == 1) {         res = min(n / i, res);       }     }     cout << n / res <<     << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long i, j, t, n, m;     cin >> n;     long long a[n], b[n], c[n];     if (n & 1) {       for (long long i = 0; i < n; ++i) {         a[i] = i;         b[i] = i;         c[i] = i + i;         c[i] %= n;       }       for (long long i = 0; i < n; ++i) {         cout << a[i] <<    ;       }       cout << endl;       for (long long i = 0; i < n; ++i) {         cout << b[i] <<    ;       }       cout << endl;       for (long long i = 0; i < n; ++i) {         cout << c[i] <<    ;       }       cout << endl;     } else {       cout <<  -1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 100005;   int gap, tmp[SIZE * 2];   class SuffixArray {    public:     int sa[SIZE], rk[SIZE], ht[SIZE];     static bool cmp(int x, int y) {       if (tmp[x] != tmp[y]) return tmp[x] < tmp[y];       return tmp[x + gap] < tmp[y + gap];     }     void gao(const char* s, int n) {       copy(s, s + n + 1, rk);       for (gap = 1; gap <= n; gap <<= 1) {         for (int i = 0; i <= n; i++) sa[i] = i;         copy(rk, rk + n + 1, tmp);         sort(sa, sa + n + 1, cmp);         for (int i = rk[*sa] = 0; i < n; i++)           rk[sa[i + 1]] = rk[sa[i]] + cmp(sa[i], sa[i + 1]);       }       for (int i = gap = ht[*sa] = 0; i < n; i++) {         if (gap) --gap;         while (s[i + gap] == s[sa[rk[i] - 1] + gap]) gap++;         ht[rk[i]] = gap;       }     }   };   char str[SIZE];   SuffixArray SA;   int main() {     int n = strlen(gets(str));     long long ans = n * (n + 1ll) / 2, cnt = 0;     SA.gao(str, n);     vector<int> u = {0};     for (int i = 1; i <= n; i++) {       while (SA.ht[i] < SA.ht[u.back()]) {         cnt -= SA.ht[u.back()] * (u.back() - u[u.size() - 2]);         u.pop_back();       }       u.push_back(i);       cnt += SA.ht[u.back()] * (u.back() - u[u.size() - 2]);       ans += cnt;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> t;     while (t--) {       cin >> n;       vector<int> a(n);       int mx = 0;       for (auto &it : a) {         cin >> it;         mx = max(mx, it);       }       int r = n - 1;       int ind = -1;       for (int l = 0; l < n; l++) {         if (a[l] != mx)           continue;         else if (l > 0 && a[l - 1] != mx)           ind = l + 1;         else if (r > l && a[l + 1] != mx)           ind = l + 1;       }       cout << ind << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 100010;   int a[N];   bool cont[110][N];   long long f[N][110], sumf[N];   int main() {     ios::sync_with_stdio(false);     int n, k, len;     cin >> n >> k >> len;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int j = 1; j <= k; j++) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (a[i] == -1 || a[i] == j)           cnt++;         else           cnt = 0;         if (cnt >= len) cont[j][i] = true;       }     }     f[0][0] = 1;     sumf[0] = 1;     for (int i = 1; i <= n; i++) {       if (a[i] == -1)         for (int j = 1; j <= k; j++) {           f[i][j] = sumf[i - 1];           if (cont[j][i]) f[i][j] -= sumf[i - len] - f[i - len][j];           sumf[i] = (sumf[i] + f[i][j]) % MOD;         }       else {         f[i][a[i]] = sumf[i - 1];         if (cont[a[i]][i]) f[i][a[i]] -= sumf[i - len] - f[i - len][a[i]];         sumf[i] = (sumf[i] + f[i][a[i]]) % MOD;       }     }     cout << (sumf[n] + MOD) % MOD <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 1;   long long gcd(long long a, long long b) {     long long r;     while (b > 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   int main() {     long long n, k, a, b, maxkq = 0, minkq = 1e18, l, kq, g, tmp;     cin >> n >> k >> a >> b;     tmp = n * k;     for (int i = 0; i < n; i++) {       l = (k * i + a - b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i + a + b) % tmp;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i - a + b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i - a - b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;     }     cout << minkq <<     << maxkq;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long INF_LL = 1000000000000000000LL;   const double pi = 2 * acos(0.0);   template <class T>   void smin(T& a, T b) {     if (a > b) a = b;   }   template <class T>   void smax(T& a, T b) {     if (a < b) a = b;   }   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   T sqr(T a) {     return a * a;   }   template <typename Iterator>   void print(const char* fmt, Iterator begin, Iterator end,              const char* separator =    ) {     for (Iterator it = begin; it != end; ++it) {       if (it != begin) printf(separator);       printf(fmt, *it);     }     printf(  n );   }   long long t, a, b;   int main() {     scanf( %I64d%I64d%I64d , &t, &a, &b);     int ans = 0;     if (a == b) ++ans;     if (t > a || a > b) {       printf( %d n , ans);       return 0;     }     if (a > 1) {       vector<int> c;       while (b) c.push_back(b % a), b /= a;       for (int i(int((c).size()) - 1), _b(0); i >= _b; --i) {         b *= t;         b += c[i];       }       if (b == a) ++ans;       if (t == 1 && b == 1 && int((c).size()) > 2) ++ans;     } else {       if (b == 1) ans = -1;     }     if (ans == -1)       printf( inf n );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ppp {     int x, y, id;   } a[120000], b[120000];   int i, j, k, l, n, m, p, t;   bool cmp(const ppp& a, const ppp& b) {     return a.y < b.y || a.y == b.y && a.x > b.x;   }   bool cmp2(const ppp& a, const ppp& b) {     return a.x > b.x || a.x == b.x && a.y > b.y;   }   int main() {     scanf( %d%d%d , &n, &p, &m);     for (i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].y), a[i].id = i;     sort(a + 1, a + n + 1, cmp);     p -= m;     for (i = p + 1; i <= n; ++i) b[i].x = a[i].x, b[i].y = i;     sort(b + p + 1, b + n + 1, cmp2);     t = n;     for (i = p + 1; i <= p + m; ++i) {       t = min(t, b[i].y);       printf( %d  , a[b[i].y].id);     }     for (i = 1; i <= p; ++i) printf( %d  , a[t - i].id);   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000 + 10;   const int INF = 0x7f7f7f7f;   const double eps = 1e-8;   const double pi = 3.1415926535897932384626433832795;   double p[Maxn], f[Maxn][Maxn];   long long L[Maxn], R[Maxn];   inline long long power(int a, int b) {     long long ans = 1;     for (int i = 1; i <= b; i++) ans *= a;     return ans;   }   double calc(long long a, long long b) {     char ch[50];     int len1, len2;     long long ansa = 0, ansb = 0;     a--;     sprintf(ch,  %I64d , a);     len1 = (int)strlen(ch);     for (int i = 1; i < len1; i++) ansa += power(10, i - 1);     if (ch[0] !=  1  && ch[0] !=  0 )       ansa += power(10, len1 - 1);     else if (ch[0] ==  1 )       ansa += a - power(10, len1 - 1) + 1;     sprintf(ch,  %I64d , b);     len2 = (int)strlen(ch);     for (int i = 1; i < len2; i++) ansb += power(10, i - 1);     if (ch[0] !=  1  && ch[0] !=  0 )       ansb += power(10, len2 - 1);     else if (ch[0] ==  1 )       ansb += b - power(10, len2 - 1) + 1;     return (ansb - ansa) * 1.0 / (b - a);   }   int main() {     int n, K;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> L[i] >> R[i];       p[i] = calc(L[i], R[i]);     }     cin >> K;     f[0][0] = 1;     for (int i = 1; i <= n; i++) {       f[i][0] = 1;       for (int j = 1; j <= i; j++) f[i][0] *= (1 - p[j]);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         f[i][j] = f[i - 1][j] * (1 - p[i]) + f[i - 1][j - 1] * p[i];     double ans = 0;     for (int i = 0; i <= n; i++)       if (100 * i >= K * n) ans += f[n][i];     printf( %.11f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> m >> k;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);     }     long long sum = 0;     int i;     for (i = n - 1; i >= 0; i--) {       sum += v[i];       if (sum > k) {         sum = 0;         i++;         m--;         if (m == 0) {           break;         }       }     }     if (i < 0) i = 0;     cout << n - i;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long x = a, y = b;     if (y > x) {       swap(x, y);     }     while (y != 0) {       x = x % y;       swap(x, y);     }     return (a * b) / x;   }   long long x, a, y, b, k, c;   bool checker(long long n, long long k, const vector<long long>& p) {     long long m = (long long)p.size() - 1;     if (m == 2) {     }     long long _c = n / c;     long long _a = n / a - _c;     long long _b = n / b - _c;     long long sum = 0;     for (long long i = 0; i < _c; ++i) {       sum += p[m - i] * (x + y) / 100;     }     for (long long i = _c; i < _c + _a; ++i) {       sum += p[m - i] * x / 100;     }     for (long long i = _c + _a; i < _c + _a + _b; ++i) {       sum += p[m - i] * y / 100;     }     return sum >= k;   }   signed main() {     long long q;     cin >> q;     vector<long long> p;     for (long long qwerty = 0; qwerty < q; ++qwerty) {       long long n;       cin >> n;       vector<long long>(n).swap(p);       for (long long i = 0; i < n; ++i) {         cin >> p[i];       }       sort(p.begin(), p.end());       cin >> x >> a >> y >> b >> k;       if (x < y) {         swap(x, y);         swap(a, b);       }       c = gcd(a, b);       long long L = 0;       long long R = n;       while (L + 1 < R) {         long long m = (L + R) / 2;         if (checker(m, k, p)) {           R = m;         } else {           L = m;         }       }       if (checker(R, k, p)) {         cout << R << endl;       } else {         cout << -1 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int> > adj;   bool acyclic = 1;   int topo[500005];   int ptr = 0;   bool visited[500005];   bool in_stack[500005];   void solve(int i) {     if (in_stack[i]) {       acyclic = 0;       return;     }     if (visited[i]) {       return;     }     visited[i] = 1;     in_stack[i] = 1;     for (auto m : adj[i]) {       solve(m);     }     in_stack[i] = 0;     topo[ptr++] = i;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> m;       adj.resize(n + 2);       for (int(i) = 1; (i) < (n + 2); (i)++) {         adj[i].clear();       }       vector<pair<int, int> > ans;       for (int(i) = 0; (i) < (m); (i)++) {         bool dir;         int u, v;         cin >> dir >> u >> v;         if (dir) {           adj[u].push_back(v);         }         if (!dir) {           ans.push_back(make_pair((u), (v)));         }       }       acyclic = 1;       ptr = 0;       memset((visited), 0, sizeof((visited)));       bool valid = 0;       for (int i = 1; i <= n; ++i) {         valid = 1;         solve(i);       }       if (!valid || !acyclic) {         cout <<  NO n ;         continue;       }       unordered_map<int, int> topo_map;       for (int i = 0; i < n; ++i) {         topo_map[topo[i]] = i;       }       cout <<  YES n ;       for (auto p : ans) {         if (topo_map[p.first] > topo_map[p.second]) {           cout << p.first <<     << p.second << endl;         } else {           cout << p.second <<     << p.first << endl;         }       }       for (int i = 1; i <= n; ++i) {         for (auto m : adj[i]) {           cout << i <<     << m << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string s;     cin >> s;     long long n = s.length();     s =  1  + s;     long long x[n + 1], y[n + 1], z[n + 1];     x[0] = 0;     y[0] = 0;     z[0] = 0;     for (long long i = 1; i <= n; i++) {       x[i] = x[i - 1];       y[i] = y[i - 1];       z[i] = z[i - 1];       if (s[i] ==  x ) x[i]++;       if (s[i] ==  y ) y[i]++;       if (s[i] ==  z ) z[i]++;     }     long long m;     cin >> m;     for (long long i = 0; i < m; i++) {       long long l, r;       cin >> l >> r;       long long len = r - l + 1;       long long cx = x[r] - x[l - 1];       long long cy = y[r] - y[l - 1];       long long cz = z[r] - z[l - 1];       if (len < 3) {         cout <<  YES  <<   n ;         continue;       }       if (abs(cx - cy) > 1 || abs(cx - cz) > 1 || abs(cz - cy) > 1)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int nxt() {     int wow;     scanf( %d , &wow);     return wow;   }   inline long long int lxt() {     long long int wow;     scanf( %lld , &wow);     return wow;   }   inline double dxt() {     double wow;     scanf( %lf , &wow);     return wow;   }   long long int dp[2][5002];   int main() {     int n = nxt(), p = 0, c = 1;     long long int a[5002], b[5002];     for (int i = 1; i <= n; i++) b[i] = a[i] = lxt() - i;     sort(b + 1, b + n + 1);     dp[1][0] = (long long int)1e17;     for (int j = 1; j <= n; j++) dp[c][j] = min(dp[c][j - 1], abs(b[j] - a[1]));     for (int i = 2; i <= n; i++) {       swap(c, p);       dp[c][0] = (long long int)1e17;       for (int j = 1; j <= n; j++)         dp[c][j] = min(dp[c][j - 1], abs(b[j] - a[i]) + dp[p][j]);     }     cout << dp[c][n] << endl;     return 0;   }