malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int graph[101][101];   int dp[101][101][26];   int dfs(int x, int y, int curr, int n) {     if (dp[x][y][curr] != -1) {       return dp[x][y][curr];     }     for (int i = 0; i < n; i++) {       if (graph[x][i] >= curr) {         if (!dfs(y, i, graph[x][i], n)) {           dp[x][y][curr] = 1;           return 1;         }       }     }     dp[x][y][curr] = 0;     return 0;   }   int main(void) {     memset(dp, -1, sizeof(dp));     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         graph[i][j] = -1;       }     }     for (int i = 0; i < m; i++) {       int a, b;       char c;       cin >> a >> b >> c;       a--;       b--;       graph[a][b] = c -  a ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (dfs(i, j, 0, n)) {           cout <<  A ;         } else {           cout <<  B ;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, f[1001], l[1001];     bool rated = false;     cin >> n;     for (i = 0; i < n; i++) {       cin >> f[i] >> l[i];       if (f[i] != l[i]) {         rated = true;         cout <<  rated  << endl;         return 0;       }     }     if (!rated) {       for (i = 1; i < n; i++) {         if (l[i] > l[i - 1]) {           cout <<  unrated  << endl;           return 0;         }       }     }     cout <<  maybe  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 800005;   int n, m, q, sa[N], sb[N], s[N];   set<int> a[N], b[N];   void modify(int x, int l, int r, int k, int val, int id) {     if (l == r) {       if (id)         sa[x] = val;       else         sb[x] = val;       s[x] = (sa[x] <= -sb[x]);       return;     }     int mid = (l + r) >> 1;     if (k <= mid)       modify(x << 1, l, mid, k, val, id);     else       modify(x << 1 | 1, mid + 1, r, k, val, id);     sa[x] = min(sa[x << 1], sa[x << 1 | 1]);     sb[x] = min(sb[x << 1], sb[x << 1 | 1]);     s[x] = s[x << 1] || s[x << 1 | 1] || sa[x << 1] <= -sb[x << 1 | 1];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) a[i].insert(0x3f3f3f3f), b[i].insert(0);     memset(sa, 0x3f, sizeof(sa));     while (q--) {       int x, y, id;       scanf( %d%d , &x, &y);       id = x & 1, x = (x + 1) / 2, y = (y + 1) / 2;       if (id) {         if (a[x].find(y) != a[x].end())           a[x].erase(y);         else           a[x].insert(y);         modify(1, 1, n, x, *a[x].begin(), 1);         if (s[1])           printf( NO n );         else           printf( YES n );       } else {         if (b[x].find(-y) != b[x].end())           b[x].erase(-y);         else           b[x].insert(-y);         modify(1, 1, n, x, *b[x].begin(), 0);         if (s[1])           printf( NO n );         else           printf( YES n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int soch(int a) {     if (a == 3) return 1;     return soch(a - 1) * a / (a - 3);   }   int main() {     int n, num, i, j, k, raz, dob, num1, dob1, sum = 0, flag = 0, flag1 = 0;     bool graf[105][105];     bool graf1[6][6];     vector<pair<int, int>> ver;     vector<int> v;     vector<int> v1;     vector<int> v2;     cin >> k;     for (i = 1; i <= 100; i++)       for (j = 1; j <= 100; j++) graf[i][j] = 0;     for (i = 3; i <= 100; i++) {       v2.push_back(soch(i));       if (soch(i) > k) break;     }     num = i - 1;     raz = k - soch(num);     v.push_back(0);     v.push_back(1);     for (i = 3; i <= num; i++) v.push_back(soch(i + 1) - soch(i));     for (i = 0; i < v.size(); i++)       if (v[i] > raz) {         dob = i - 1;         break;       };     raz -= v[dob];     dob++;     k = raz;     if (k) {       flag1 = 1;       for (i = 3; i <= 100; i++)         if (soch(i) > k) break;       num1 = i - 1;       raz = k - soch(num1);       for (i = 0; i < v.size(); i++)         if (v[i] > raz) {           dob1 = i - 1;           break;         };       raz -= v[dob1];       dob1++;       k = raz;     }     if (k == 3) {       flag = 1;       v1.push_back(5);       for (i = 1; i <= 5; i++)         for (j = 1; j <= 5; j++)           if (i != j)             graf1[i][j] = 1;           else             graf1[i][j] = 0;       graf1[1][3] = graf1[3][1] = graf1[1][4] = graf1[4][1] = graf1[4][3] =           graf1[3][4] = 0;     }     if (!flag)       for (i = v2.size() - 1; k > 0; i--)         while (v2[i] <= k) {           k -= v2[i];           v1.push_back(i + 3);         }     for (i = 0; i < v1.size(); i++) sum += v1[i];     if (!flag1) num1 = dob1 = 0;     n = num + num1 + sum + 1 + flag1;     cout << n << endl;     for (i = 1; i <= num; i++)       for (j = 1; j <= num; j++)         if (i != j) graf[i][j] = 1;     for (j = 1; j <= dob; j++) graf[num + 1][j] = graf[j][num + 1] = 1;     if (flag1) {       for (i = num + 2; i <= num + num1 + 1; i++)         for (j = num + 2; j <= num + num1 + 1; j++)           if (i != j) graf[i][j] = 1;       for (j = num + 2; j <= dob1 + num + 1; j++)         graf[num + num1 + 2][j] = graf[j][num + num1 + 2] = 1;       num = num + num1 + 1;     }     if (!flag) {       raz = 2;       for (k = 0; k < v1.size(); k++) {         for (i = num + raz; i <= num + raz + v1[k] - 1; i++)           for (j = num + raz; j <= num + raz + v1[k] - 1; j++)             if (i != j) graf[i][j] = 1;         raz += v1[k];       }     } else {       for (i = 0; i < 5; i++)         for (j = 0; j < 5; j++)           graf[num + 2 + i][num + 2 + j] = graf1[i + 1][j + 1];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) cout << graf[i][j];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 2147483647;   const int MOD = 1000000007;   const long long INF64 = 9223372036854775807;   const long double EPS = 1e-7;   using namespace std;   vector<int> a;   int getDist(int fr, int to) {     int l = fr, r = to, mid = (a[to] + a[fr]) / 2;     while (l < r - 1) {       int m = (l + r) / 2;       if (a[m] < mid)         l = m;       else         r = m;     }     int l1 = fr, r1 = to, mid1 = (a[to] + a[fr]) / 2 + (a[to] + a[fr]) % 2;     while (l1 < r1 - 1) {       int m = (l1 + r1) / 2;       if (a[m] < mid1)         l1 = m;       else         r1 = m;     }     return min(         min(max(a[l] - a[fr], a[to] - a[l]), max(a[r] - a[fr], a[to] - a[r])),         min(max(a[l1] - a[fr], a[to] - a[l1]),             max(a[r1] - a[fr], a[to] - a[r1])));   }   int main() {     int n, k;     char t;     scanf( %d%d n , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %c , &t);       if (t ==  0 ) a.push_back(i);     }     int ans = INF;     for (int i = 0; i < (int)a.size() - k; i++) ans = min(ans, getDist(i, i + k));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 17LL;   const long long MOD = 998244353LL;   const int MAXN = 1e5 + 10;   struct Node {     long long v;     long long tagv;     long long len;   } st[MAXN << 2];   long long a[MAXN];   inline long long fp(long long x, long long y) {     long long ret = 1LL;     while (y) {       if (y & 1) ret = ret * x % MOD;       x = x * x % MOD;       y >>= 1;     }     return ret;   }   long long inv = fp(base - 1, MOD - 2);   long long basep[MAXN];   Node operator+(const Node& a, const Node& b) {     Node ret;     ret.len = a.len + b.len;     ret.tagv = -1;     ret.v = (a.v * basep[b.len] % MOD + b.v) % MOD;     return ret;   }   void init() {     basep[0] = 1LL;     for (int i = 1; i < MAXN; i++) basep[i] = basep[i - 1] * base % MOD;   }   void setv(int o, long long v) {     st[o].v = (basep[st[o].len] - 1 + MOD) % MOD * v % MOD * inv % MOD;     st[o].tagv = v;   }   void pushup(int o) { st[o] = st[o << 1] + st[o << 1 | 1]; }   void pushdown(int o) {     if (st[o].tagv != -1) {       setv(o << 1, st[o].tagv);       setv(o << 1 | 1, st[o].tagv);       st[o].tagv = -1;     }   }   void build(int o, int l, int r) {     st[o].tagv = -1;     st[o].len = r - l + 1;     if (l == r) {       setv(o, a[l]);       return;     }     int m = l + r >> 1;     build(o << 1, l, m);     build(o << 1 | 1, m + 1, r);     pushup(o);   }   void update(int o, int l, int r, int L, int R, long long v) {     if (L <= l && r <= R) {       setv(o, v);       return;     }     pushdown(o);     int m = l + r >> 1;     if (L <= m) update(o << 1, l, m, L, R, v);     if (m < R) update(o << 1 | 1, m + 1, r, L, R, v);     pushup(o);   }   Node query(int o, int l, int r, int L, int R) {     if (L <= l && r <= R) return st[o];     pushdown(o);     int m = l + r >> 1;     if (R <= m) return query(o << 1, l, m, L, R);     if (m < L) return query(o << 1 | 1, m + 1, r, L, R);     return query(o << 1, l, m, L, R) + query(o << 1 | 1, m + 1, r, L, R);   }   char s[MAXN];   int main() {     init();     int n, m, k;     int x, l, r, y;     scanf( %d%d%d , &n, &m, &k);     scanf( %s , s);     for (int i = 1; i <= n; i++) a[i] = s[i - 1] -  0 ;     build(1, 1, n);     for (int i = 1; i <= m + k; i++) {       scanf( %d%d%d%d , &x, &l, &r, &y);       if (x == 1) {         update(1, 1, n, l, r, 1LL * (y));       } else {         if (y == (r - l + 1)) {           puts( YES );           continue;         }         if (query(1, 1, n, l + y, r).v == query(1, 1, n, l, r - y).v)           puts( YES );         else           puts( NO );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool deb = false;   int i;   const int N = 100011;   int g[N];   int ans1[N], ans2[N];   int main() {     int i, j, n, k;     scanf( %d , &n), scanf( %d , &k);     int a, b, c, d;     scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d);     if (k < n + 1 || n == 4) {       printf( %d n , -1);       return 0;     }     g[1] = a;     g[2] = c;     g[n] = b, g[n - 1] = d;     j = 3;     for (i = 1; i < n + 1; ++i) {       if (i == a || i == b || i == c || i == d) continue;       if (g[j] == 0) g[j] = i, j++;     }     for (i = 1; i < n + 1; ++i) printf( %d  , g[i]);     printf(  n );     printf( %d  , g[2]), printf( %d  , g[1]);     for (i = 3; i < n - 1; ++i) {       printf( %d  , g[i]);     }     printf( %d  , g[n]), printf( %d n , g[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   long cmpduong(string s1, string s2) {     long len1 = s1.size();     long len2 = s2.size();     if (len1 < len2) return 2;     if (len1 == len2) {       if (s1 > s2)         return 1;       else         return 2;     }     if (len1 > len2) return 1;   }   long cmp_am(string s1, string s2) {     long len1 = s1.size();     long len2 = s2.size();     if (len1 < len2) return 1;     if (len1 == len2) {       if (s1 >= s2)         return 2;       else         return 1;     }     if (len1 > len2) return 2;   }   long check(string s) {     string tam =  -  + s;     if (s[0] ==  - ) {       if (cmp_am(s,  -128 ) == 1) return 1;       if (cmp_am(s,  -32768 ) == 1) return 2;       if (cmp_am(s,  -2147483648 ) == 1) return 3;       if (cmp_am(s,  -9223372036854775808 ) == 1) return 4;       return 5;     } else {       if (cmpduong(s,  127 ) == 2) return 1;       if (cmpduong(s,  32767 ) == 2) return 2;       if (cmpduong(s,  2147483647 ) == 2) return 3;       if (cmpduong(s,  9223372036854775807 ) == 2) return 4;       return 5;     }   }   int main() {     cin >> s;     if (check(s) == 1) cout <<  byte  << endl;     if (check(s) == 2) cout <<  short  << endl;     if (check(s) == 3) cout <<  int  << endl;     if (check(s) == 4) cout <<  long  << endl;     if (check(s) == 5) cout <<  BigInteger  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sum[400006] = {0};   long long Min[400006] = {0};   long long Max[400006] = {0};   void solve() {     long long n;     cin >> n;     long long k;     cin >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     for (long long i = 0; i <= 2 * k + 3; i++) Min[i] = Max[i] = sum[i] = 0;     for (long long i = 0; i < n / 2; i++) {       Max[max(v[i], v[n - i - 1])]++;       Min[min(v[i], v[n - i - 1])]++;       sum[v[i] + v[n - i - 1]]++;     }     for (long long i = 1; i <= k; i++) {       Min[i] += Min[i - 1];       Max[i] += Max[i - 1];     }     long long ans = 2000000000000000005;     long long c;     for (long long i = 2; i <= k + 1; i++) {       c = Min[i - 1];       if (c <= n / 2) ans = min(ans, c + 2 * ((n / 2) - c) - sum[i]);     }     for (long long i = k + 1; i <= 2 * k; i++) {       if (i - k - 1 >= 0) c = Max[i - k - 1];       if (c <= n / 2) ans = min(ans, c * 2 + (n / 2 - c) - sum[i]);     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int ans[100010];   int a[100010], b[100010];   int c[100010], d[100010], cnt[100010];   set<pair<int, int> > s;   int x[100010 * 4], nx;   vector<int> A[100010 * 4], B[100010 * 4];   bool solve() {     for (int i = 0; i < N; i++) {       x[nx++] = a[i];       x[nx++] = b[i];     }     for (int i = 0; i < M; i++) {       x[nx++] = c[i];       x[nx++] = d[i];     }     sort(x, x + nx);     nx = unique(x, x + nx) - x;     for (int i = 0; i < M; i++) {       c[i] = lower_bound(x, x + nx, c[i]) - x;       d[i] = lower_bound(x, x + nx, d[i]) - x;       A[c[i]].push_back(-(i + 1));       B[d[i]].push_back(-(i + 1));     }     for (int i = 0; i < N; i++) {       a[i] = lower_bound(x, x + nx, a[i]) - x;       b[i] = lower_bound(x, x + nx, b[i]) - x;       A[a[i]].push_back(i + 1);     }     memset(ans, -1, sizeof(ans));     for (int i = 0; i < nx; i++) {       int n;       n = A[i].size();       for (int j = 0; j < n; j++) {         if (A[i][j] > 0) {           int k = A[i][j] - 1;           set<pair<int, int> >::iterator it =               s.lower_bound(pair<int, int>(b[k], -1));           if (it == s.end()) return false;           int u = it->second;           ans[k] = u + 1;           cnt[u]--;           if (!cnt[u]) s.erase(it);         } else {           int k = -A[i][j] - 1;           s.insert(pair<int, int>(d[k], k));         }       }       n = B[i].size();       for (int j = 0; j < n; j++) {         int k = -B[i][j] - 1;         s.erase(pair<int, int>(d[k], k));       }     }     return true;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d%d , &a[i], &b[i]);     scanf( %d , &M);     for (int i = 0; i < M; i++) scanf( %d%d%d , &c[i], &d[i], &cnt[i]);     if (solve()) {       puts( YES );       for (int i = 0; i < N; i++) printf( %d  , ans[i]);       puts(  );     } else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, n1 = 0, n2 = 0, ar = 0, curr = 0, current;     cin >> n;     vector<int> a(n);     for (i = 0; i < n; i++) cin >> a[i];     current = a[0];     for (i = 0; i < n; i++) {       if (curr == 0 && a[i] == current)         n1++;       else if (a[i] != current)         curr++, n2++;       if ((curr > 0 && a[i] == current) || i == n - 1) {         current = a[i - 1];         if (n1 == n2)           ar = max(n1 + n2, ar);         else           ar = max((2 * min(n1, n2)), ar);         n1 = n2, n2 = 1;       }     }     cout << ar << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     vector<int> d(n);     for (int(i) = 0; (i) < (n); (i)++) {       cin >> d[i];     }     sort((d).begin(), (d).end());     if (d[b] != d[b - 1]) {       cout << d[b] - d[b - 1] << endl;     } else {       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205000;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   vector<string> w, a, b;   string s1, s2;   bool check(string& s) {     if (s.size() == 0) return 0;     if (s[0] ==  0 ) return s.size() == 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] >  9  || s[i] <  0 ) return 0;     }     return 1;   }   signed main() {     cin >> s1;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  ,  || s1[i] ==  ; ) {         w.push_back(s2);         s2 =   ;       } else {         s2 += s1[i];       }       if (i == s1.size() - 1) w.push_back(s2);     }     for (int i = 0; i < w.size(); i++) {       if (check(w[i])) {         a.push_back(w[i]);       } else         b.push_back(w[i]);     }     if (a.size() == 0) {       cout <<  -  << endl;     } else {       cout <<    ;       for (int i = 0; i < a.size(); i++) {         cout << a[i];         if (i != a.size() - 1) cout <<  , ;       }       cout <<    n ;     }     if (b.size() == 0) {       cout <<  -  << endl;     } else {       cout <<    ;       for (int i = 0; i < b.size(); i++) {         cout << b[i];         if (i != b.size() - 1) cout <<  , ;       }       cout <<    n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e5 + 5;   int n, I;   int a[MAXN], num[MAXN];   int read() {     int s = 1, x = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) s = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * s;   }   int main() {     n = read(), I = read();     int maxk = 8 * I / n, maxK = pow(2, maxk);     if (maxk >= 20) {       cout <<  0 n ;       return 0;     }     for (int i = 1; i <= n; ++i) a[i] = read();     sort(a + 1, a + n + 1);     int cnt = 1;     num[cnt] = 1;     for (int i = 2; i <= n; ++i) {       if (a[i] == a[i - 1])         num[cnt]++;       else         num[++cnt] = num[cnt - 1] + 1;     }     if (cnt <= maxK) {       cout <<  0 n ;       return 0;     }     int max_con = -1;     for (int i = maxK; i <= cnt; ++i) {       int tmp = num[i] - num[i - maxK];       max_con = max(max_con, tmp);     }     cout << n - max_con << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int a[MAXN], deg[MAXN];   set<pair<int, int> > s;   int main() {     int n, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> deg[i] >> a[i];       if (deg[i]) s.insert(make_pair(deg[i], i));       sum += deg[i];     }     cout << sum / 2 << endl;     while (s.size()) {       pair<int, int> x = *s.begin();       s.erase(x);       int t = a[x.second];       cout << x.second <<     << t << endl;       s.erase(make_pair(deg[t], t));       deg[t]--;       a[t] ^= x.second;       if (deg[t]) s.insert(make_pair(deg[t], t));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[6], ans[100001];   pair<int, int> arr[100001];   bool given[100001];   string tshirt[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   int match(string s) {     for (int i = 0; i < 6; i++) {       if (tshirt[i] == s) return i;     }   }   void convert(int ind, string s) {     string tmp;     bool flag = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  , ) {         flag = 1;         arr[ind].first = match(tmp);         tmp.clear();       } else         tmp.push_back(s[i]);     }     if (flag) {       arr[ind].second = match(tmp);       if (arr[ind].first > arr[ind].second) swap(arr[ind].first, arr[ind].second);     } else {       arr[ind].first = match(tmp);       arr[ind].second = -1;     }     return;   }   bool cal_ans(int n) {     for (int i = 0; i < n; i++) {       if (arr[i].second == -1) {         if (cnt[arr[i].first] == 0) return false;         ans[i] = arr[i].first;         cnt[arr[i].first]--;         given[i] = 1;       }     }     for (int j = 0; j < 5; j++) {       for (int i = 0; i < n; i++) {         if (given[i] == 0 and arr[i].first == j) {           if (cnt[arr[i].first]) {             cnt[arr[i].first]--;             ans[i] = j;           } else {             if (cnt[arr[i].second]) {               cnt[arr[i].second]--;               ans[i] = arr[i].second;             } else               return false;           }           given[i] = 1;         }       }     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     for (int i = 0; i < 6; i++) cin >> cnt[i];     int n;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       convert(i, s);     }     if (cal_ans(n)) {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         cout << tshirt[ans[i]] << endl;       }     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   set<pair<int, int> > s;   set<pair<pair<int, int>, int> > vis;   char dir[10];   int sx, sy, h, w, d, tar;   inline void update(int& a, int b) {     if (b < a) a = b;   }   int main() {     scanf( %d%d%d%d%s , &h, &w, &sx, &sy, dir);     tar = ((h + w) * 2 - 4) >> 1;     if (dir[0] ==  U  && dir[1] ==  L )       d = 3;     else if (dir[0] ==  U  && dir[1] ==  R )       d = 2;     else if (dir[0] ==  D  && dir[1] ==  L )       d = 1;     else       d = 0;     --tar;     s.insert(make_pair(sx, sy));     vis.insert(make_pair(make_pair(sx, sy), d));     long long ans = 1;     pair<int, int> p1;     pair<pair<int, int>, int> p2;     while (tar > 0) {       if ((D[d][0] == 1 && sx == h) || (D[d][0] == -1 && sx == 1)) d ^= 2;       if ((D[d][1] == 1 && sy == w) || (D[d][1] == -1 && sy == 1)) d ^= 1;       int g = 0x3f3f3f3f;       if (D[d][0] == 1)         update(g, h - sx);       else         update(g, sx - 1);       if (D[d][1] == 1)         update(g, w - sy);       else         update(g, sy - 1);       ans += g;       sx += D[d][0] * g;       sy += D[d][1] * g;       p1 = make_pair(sx, sy);       if (s.find(p1) == s.end()) {         --tar;         s.insert(p1);       }       p2 = make_pair(p1, d);       if (vis.find(p2) != vis.end()) {         printf( -1 n );         return 0;       } else         vis.insert(p2);     }     printf(          %I64d            n ,         ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[100009];   int main() {     int n;     while (cin >> n) {       for (int i = 0; i < n; ++i) cin >> num[i];       long long sum = n;       long long count = 1;       for (int i = 1; i < n; ++i) {         if (num[i] == num[i - 1])           count++;         else {           sum += ((count - 1) * (count)) / 2;           count = 1;         }       }       if (count != 0) sum += ((count - 1) * (count)) / 2;       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 11;   int n, l;   int main() {     scanf( %d , &n);     while (n) {       int a = n % 10;       int b = n % 100;       int c = n % 1000;       if (a == 1)         n /= 10;       else if (b == 14)         n /= 10;       else if (c == 144)         n /= 100;       l++;       if (l > 1000) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> MP1, MP2;   map<int, int>::iterator it;   const int N = 300100;   const long long INF = 3000 * 1000 * 1000LL;   vector<int> v;   int a[N];   long long ps[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, l, r;     long long ans = -INF;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (!MP1.count(a[i])) MP1[a[i]] = i;       MP2[a[i]] = i;       ps[i] += ps[i - 1];       if (a[i] > 0) ps[i] += a[i];     }     for (it = MP1.begin(); it != MP1.end(); it++) {       if (MP2[it->first] != it->second) {         long long t = ps[MP2[it->first]] - ps[it->second] + it->first;         if (it->first < 0) t += it->first;         if (t > ans) {           ans = t;           l = it->second;           r = MP2[it->first];         }       }     }     for (int i = 1; i <= n; i++)       if ((i != l && i != r && a[i] < 0) || (i < l || i > r)) v.push_back(i);     cout << ans <<     << v.size() << endl;     for (int u : v) cout << u <<    ;     cout << endl;     return 0;   }