malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   bool isPrime(int n) {     if (n == 1) return false;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) return false;     }     return true;   }   void solve() {     int n, sum = 0;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     if (!isPrime(sum)) {       cout << n <<   n ;       for (int i = 1; i <= n; ++i) {         cout << i <<    ;       }       cout <<   n ;     } else {       cout << n - 1 <<   n ;       int oddpos = -1;       for (int i = 0; i < n; ++i) {         if (a[i] % 2 != 0) {           oddpos = i;           break;         }       }       for (int i = 0; i < n; ++i) {         if (i != oddpos) cout << i + 1 <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     int a[100000 + 3], b[100000 + 3];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     int cnt = 1;     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         cnt++;       }     }     if (cnt == 3 || cnt == 1) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, p;   long long ans = -1e18;   struct nd {     int val, c;     friend bool operator<(nd a, nd b) { return a.val < b.val; }   } a[N], b[N];   struct mon {     int x, y, z;     friend bool operator<(mon a, mon b) { return a.x < b.x; }   } c[N];   struct BIT {     int tot;     int ls[N << 1], rs[N << 1];     long long mx[N << 1], tag[N << 1];     void up(int x) { mx[x] = max(mx[ls[x]], mx[rs[x]]); }     void down(int x) {       if (!tag[x]) return;       if (ls[x]) {         mx[ls[x]] += tag[x];         tag[ls[x]] += tag[x];       }       if (rs[x]) {         mx[rs[x]] += tag[x];         tag[rs[x]] += tag[x];       }       tag[x] = 0;     }     int build(int l, int r) {       int x = ++tot;       if (l == r) {         mx[x] = -b[l].c;         return x;       }       int mid = l + r >> 1;       ls[x] = build(l, mid);       rs[x] = build(mid + 1, r);       up(x);       return x;     }     void add(int x, int l, int r, int L, int R, long long d) {       if (L <= l && r <= R) {         mx[x] += d;         tag[x] += d;         return;       }       down(x);       int mid = l + r >> 1;       if (L <= mid) add(ls[x], l, mid, L, R, d);       if (R > mid) add(rs[x], mid + 1, r, L, R, d);       up(x);     }     void init() {       mx[0] = -1e18;       int root = build(1, m);     }   } T;   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].val, &a[i].c);     for (int i = 1; i <= m; ++i) scanf( %d%d , &b[i].val, &b[i].c);     for (int i = 1; i <= p; ++i) scanf( %d%d%d , &c[i].x, &c[i].y, &c[i].z);     sort(a + 1, a + n + 1);     sort(b + 1, b + m + 1);     sort(c + 1, c + p + 1);     T.init();     for (int i = 1, R = 0; i <= n; ++i) {       while (R < p && c[R + 1].x < a[i].val) {         ++R;         int l = 1, r = m;         while (l != r) {           int mid = l + r >> 1;           if (b[mid].val > c[R].y)             r = mid;           else             l = mid + 1;         }         if (b[l].val > c[R].y) {           T.add(1, 1, m, l, m, c[R].z);         }       }       ans = max(ans, -a[i].c + T.mx[1]);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, s;     while (cin >> n >> k >> s) {       long long temp = (s / k);       long long rem = s % k;       temp++;       if (((n - 1) * k < s || (k > s))) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       long long ans = 1;       int flag = 0;       for (int i = 1; i <= k; i++) {         if (flag == 0 && rem == 0) {           flag = 1;           temp--;         } else           rem--;         if (ans + temp <= n) {           ans += temp;           cout << ans <<    ;         } else {           ans -= temp;           cout << ans <<    ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long a, b, c, d;   long long solve(long long x) {     long long times = x / d + 1;     long long sum = (x / d + 1) * a;     long long finished;     if (x < c) {       finished = 0;     } else {       finished = (x - c) / d + 1;     }     long long left = times - finished;     long long a1 = x - (x / d) * d;     sum -= left * a1 * b + left * (left - 1) / 2 * d * b;     sum -= finished * b * c;     return sum;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       if (d >= c) {         if (a > b * c) {           cout << -1 << endl;         } else {           cout << a << endl;         }       } else {         if (a > b * c) {           cout << -1 << endl;         } else {           long long l = 0, r = 1e6 / d;           while (l < r - 5) {             long long ml = (l + r) / 2;             long long mr = (ml + r) / 2;             if (solve(ml * d) <= solve(mr * d)) {               l = ml;             } else {               r = mr;             }           }           long long mx = 0;           for (long long i = l; i <= r; i++) {             mx = max(mx, solve(i * d));           }           cout << mx << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const double pi = 2.0 * asin(1.0), eps = 1e-12;   const int maxn = 2100, maxm = 1100000, inf = 0x3f3f3f3f;   char ch[maxn][maxn];   int ans[maxn];   int main() {     int n, m, i, j, l, x;     while (scanf( %d%d%d , &n, &m, &l) == 3) {       memset(ans, 0, sizeof(ans));       for (i = 0; i < n; i++) {         scanf( %s , ch[i]);         for (j = 0; j < m; j++) {           if (ch[i][j] ==  U ) {             if (i % 2 == 0) ans[j]++;           } else if (ch[i][j] ==  L ) {             x = j - i;             if (x >= 0) ans[x]++;           } else if (ch[i][j] ==  R ) {             x = j + i;             if (x < m) ans[x]++;           }         }       }       for (i = 0; i < m; i++) {         if (i != 0) printf(   );         printf( %d , ans[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   vector<int> cur;   void split(int x, int p) {     if (p == 1) {       cout << x <<    ;       return;     }     cout << x - 1 <<    ;     split(x - 1, p - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     long long n, k;     cin >> n >> k;     string s =   ;     while (n > 0) {       s += (char)((n % 2) +  0 );       n /= 2;     }     for (int i = ((int)s.size() - 62); i < (int)s.size(); i++) {       long long cnt = 0;       for (int j = 0; j <= i; j++) {         cnt += (s[j] ==  1 );       }       bool ok = true;       for (long long j = max(i + 1, 0); j < s.size(); j++) {         cnt += (1ll << (j - i)) * (s[j] ==  1 );         if (cnt > k) {           ok = false;           break;         }       }       if (cnt > k) {         ok = false;         continue;       }       if (!ok) continue;       cout <<  Yes  << endl;       cur.clear();       for (int j = 0; j <= i; j++) {         if (s[j] ==  1 ) cur.push_back(j);       }       for (int j = max(i + 1, 0); j < s.size(); j++) {         if (s[j] ==  0 ) continue;         for (long long t = 0; t < (1ll << (j - i)); t++) {           cur.push_back(i);         }       }       for (int j = cur.size() - 1; j > 0; j--) {         cout << cur[j] <<    ;       }       split(cur[0], k - cnt + 1);       cout << endl;       return 0;     }     cout <<  No  << endl;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::sort;   using std::string;   using std::swap;   int main() {     int times = INT_MAX;     int a[6];     while (times-- && ~scanf( %d , &a[0])) {       for (int i = 1; i < 6; ++i) scanf( %d , a + i);       printf( %d n , (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -                          a[2] * a[2] - a[4] * a[4]);     };     return 0;   };
#include <bits/stdc++.h>   const double inf = 1e20;   using namespace std;   int n, m, i, j, f;   char a[55][55];   int vis[55][55];   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   void dfs(int x, int y, int oldx, int oldy) {     if (x == i && y == j && vis[i][j]) {       f = 1;       return;     }     for (int d = 0; d < 4 && !f; d++) {       int xx = x + dx[d], yy = y + dy[d];       if (a[xx][yy] == a[i][j] && xx >= 0 && yy >= 0 && xx < n && yy < m &&           !vis[xx][yy] && (oldx != xx || oldy != yy))         vis[xx][yy] = 1, dfs(xx, yy, x, y);     }   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++)       for (j = 0; j < m && !f; j++) {         memset(vis, 0, sizeof(vis));         dfs(i, j, -1, -1);       }     if (f)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], x = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         x++;       }     }     if (x == n) {       cout << n - 1 <<   n ;     } else {       int p = 0, m = 0;       for (int i = 0; i < n; i++) {         m = 0;         for (int j = i; j < n; j++) {           if (a[j] == 0) {             m++;           } else {             m--;           }           p = max(m, p);         }       }       cout << x + p <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   string sherlock, moriarty;   int algos(bool upper) {     int res = 0;     multiset<int> S;     for (int i = 0; i < n; ++i) S.insert((int)moriarty[i]);     for (int i = 0; i < n; ++i) {       multiset<int>::iterator it;       if (upper)         it = S.upper_bound((int)sherlock[i]);       else         it = S.lower_bound((int)sherlock[i]);       if (it == S.end()) continue;       res++;       S.erase(it);     }     return res;   }   int main() {     cin >> n;     cin >> sherlock >> moriarty;     cout << n - algos(0) << endl << algos(1);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   int n;   int firzero = -1;   int a[MAX];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       if (!a[i] && firzero == -1) firzero = i;     }     if (a[n - 1])       printf( NO n );     else {       if (n == 1) {         printf( YES n0 n );       } else if (a[n - 2]) {         printf( YES n );         for (int i = 0; i < n; ++i) {           if (i)             printf( ->%d , a[i]);           else             printf( %d , a[i]);         }         printf(  n );       } else if (firzero != n - 2 && firzero != -1) {         printf( YES n );         for (int i = 0; i < firzero; ++i) {           printf( %d-> , a[i]);         }         printf( (0->( );         for (int i = firzero + 1; i < n - 1; ++i) {           if (i == firzero + 1)             printf( %d , a[i]);           else             printf( ->%d , a[i]);         }         printf( ))->0 n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[100005], goal[100005], parent[100005];   bool used[100005];   int n;   vector<int> A[100005], leaves, sol;   void dfs(int node, int current_xor, int other_xor) {     if (used[node]) return;     used[node] = 1;     if ((v[node] ^ current_xor) != goal[node]) {       sol.push_back(node);       current_xor ^= 1;     }     for (int i = 0; i < A[node].size(); i++) {       dfs(A[node][i], other_xor, current_xor);     }   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++) {       scanf( %d %d , &x, &y);       A[x].push_back(y);       A[y].push_back(x);     }     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= n; i++) scanf( %d , &goal[i]);     dfs(1, 0, 0);     printf( %d n , sol.size());     for (int i = 0; i < sol.size(); i++) {       printf( %d n , sol[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NN = 150000 + 10;   int N, M, H;   int b[NN], a[NN];   int _max[NN << 2];   int add[NN << 2];   void up(int idx) { _max[idx] = max(_max[idx << 1], _max[idx << 1 | 1]); }   void build(int l, int r, int idx) {     _max[idx] = -100000000;     add[idx] = 0;     if (l == r) {       _max[idx] = -M - 1 + l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, idx << 1);     build(mid + 1, r, idx << 1 | 1);     up(idx);   }   void down(int idx) {     int ls = idx << 1, rs = idx << 1 | 1;     if (add[idx]) {       add[ls] += add[idx];       add[rs] += add[idx];       _max[ls] += add[idx];       _max[rs] += add[idx];       add[idx] = 0;     }   }   void update(int idx, int l, int r, int a, int b, int val) {     if (l == a && r == b) {       _max[idx] += val;       add[idx] += val;       return;     }     down(idx);     int mid = (l + r) >> 1;     if (b <= mid)       update(idx << 1, l, mid, a, b, val);     else if (a > mid)       update(idx << 1 | 1, mid + 1, r, a, b, val);     else {       update(idx << 1, l, mid, a, mid, val);       update(idx << 1 | 1, mid + 1, r, mid + 1, b, val);     }     up(idx);   }   int main() {     while (cin >> N >> M >> H) {       for (int i = 1; i < (int)(M + 1); ++i) cin >> b[i];       sort(b + 1, b + 1 + M);       for (int i = 1; i < (int)(N + 1); ++i) {         cin >> a[i];         a[i] = H - a[i];         a[i] = lower_bound(b + 1, b + 1 + M, a[i]) - b;       }       build(1, M + 1, 1);       int ans = 0;       for (int i = 1; i < (int)(N + 1); ++i) {         update(1, 1, M + 1, 1, a[i], 1);         if (i > M) {           update(1, 1, M + 1, 1, a[i - M], -1);         }         if (i >= M) {           ans += (_max[1] <= 0);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1000];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , &s);     }     for (int i = 0; i < 10; i++) cout <<  ??  << i <<  >>  << i <<  ?? n ;     cout <<  ??>>? n ;     for (int i = 0; i < 9; i++) {       cout << i <<  ?<>  << i + 1 <<   n ;     }     cout <<  9?>>?0 n ;     cout <<  ?<>1 n ;     cout <<  >>?? n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long N, K;     string X;     cin >> N >> K;     cin >> X;     string foo = X;     for (long long i = 0; i + K < foo.size(); i++) {       foo[i + K] = foo[i];     }     if (foo >= X) {       cout << foo.size() << endl;       cout << foo << endl;       return;     }     string bar = foo.substr(0, K);     bool all_nine = true;     for (auto it : bar)       if (it !=  9 ) {         all_nine = false;         break;       }     if (all_nine) {       cout << N + 1 << endl;       for (long long i = 0; i < (N + 1); i++) {         if (i % K == 0)           cout << 1;         else           cout << 0;       }       cout << endl;       return;     }     for (long long i = 0; i < (bar.size()); i++) {       if (bar[bar.size() - i - 1] ==  9 ) {         bar[bar.size() - i - 1] =  0 ;       } else {         bar[bar.size() - i - 1] += 1;         break;       }     }     cout << N << endl;     ;     for (long long i = 0; i < (N); i++) cout << bar[i % K];     cout << endl;   }   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cout.precision(12);     cout << fixed;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> A[7], B[100005];   int n, a[5005], f[5005][5005], ans;   int main() {     int i, j, u, v, w, p, q, r;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = n; i >= 1; i--) {       A[a[i] % 7].push_back(i);       B[a[i]].push_back(i);     }     ans = 2;     for (i = 1; i <= n; i++) {       A[a[i] % 7].pop_back();       B[a[i]].pop_back();       u = A[a[i] % 7].size() ? A[a[i] % 7][A[a[i] % 7].size() - 1] : 0;       v = B[a[i] - 1].size() ? B[a[i] - 1][B[a[i] - 1].size() - 1] : 0;       w = B[a[i] + 1].size() ? B[a[i] + 1][B[a[i] + 1].size() - 1] : 0;       for (j = 0; j < i; j++) {         f[i][j] = max(f[i][j], f[j][0] + 1);         ans = max(ans, f[i][j]);         if (u) f[u][j] = max(f[u][j], f[i][j] + 1);         if (v) f[v][j] = max(f[v][j], f[i][j] + 1);         if (w) f[w][j] = max(f[w][j], f[i][j] + 1);         if (!j) continue;         p = A[a[j] % 7].size() ? A[a[j] % 7][A[a[j] % 7].size() - 1] : 0;         q = B[a[j] - 1].size() ? B[a[j] - 1][B[a[j] - 1].size() - 1] : 0;         r = B[a[j] + 1].size() ? B[a[j] + 1][B[a[j] + 1].size() - 1] : 0;         if (p) f[p][i] = max(f[p][i], f[i][j] + 1);         if (q) f[q][i] = max(f[q][i], f[i][j] + 1);         if (r) f[r][i] = max(f[r][i], f[i][j] + 1);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;   long long int getint() {     long long int ret = 0;     bool f = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f ^= 1;     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return f ? -ret : ret;   }   using namespace std;   const int MAXN = 200000;   int a[MAXN + 10], f[MAXN + 10][20], w[MAXN + 10], lg2[MAXN + 10];   int nxt[MAXN + 10][20], far[MAXN + 10][20];   int query(int l, int r) {     int t = lg2[r - l + 1];     int ret = f[r - (1 << t) + 1][t];     if (w[f[l][t]] > w[ret]) ret = f[l][t];     return ret;   }   int main() {     int n = getint(), N = 2 * n;     for (int i = n; i >= 1; --i) a[i + n] = a[i] = getint();     lg2[0] = -1;     for (int i = 1; i <= N; ++i) {       w[i] = i + a[i];       f[i][0] = i;       lg2[i] = lg2[i >> 1] + 1;     }     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i + (1 << j) - 1 <= N; ++i) {         f[i][j] = f[i + (1 << (j - 1))][j - 1];         if (w[f[i][j - 1]] > w[f[i][j]]) f[i][j] = f[i][j - 1];       }     for (int i = 1; i < N; ++i) {       nxt[i][0] = query(i + 1, min(N, i + a[i]));       far[i][0] = w[i];     }     far[N][0] = nxt[N][0] = N;     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i <= N; ++i) {         nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];         far[i][j] = far[nxt[i][j - 1]][j - 1];       }     long long int output = 0;     for (int i = 1; i <= n; ++i) {       int ans = 0, u = i;       for (int j = lg2[N]; j >= 0; --j)         if (far[u][j] < i + n - 1) ans += 1 << j, u = nxt[u][j];       output += ans + 1;     }     printf( %I64d n , output);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     string st;     vector<string> v;     map<string, int> mp;     cin >> n;     for (i = 0; i < n; i++) {       cin >> st;       if (mp[st] == 0) {         v.push_back(st);       }       mp[st]++;     }     if (v.size() == 1)       cout << v[0] <<   n ;     else {       if (mp[v[0]] > mp[v[1]])         cout << v[0];       else         cout << v[1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int res[1111];   bool sol(int d) {     int g = 1, e;     for (e = 2; e <= sqrt(d); e++) {       if (d % e == 0) {         while (d % e == 0) d /= e;         if (d != 1) {           g = 0;         }         break;       }     }     return g;   }   int main() {     int a, b, c, d, e, f, g, h;     scanf( %d , &a);     if (a < 2) {       printf( 0 n );       return 0;     }     for (d = 2, g = 0; d <= a; d++) {       if (sol(d)) {         res[g++] = d;       }     }     printf( %d n , g);     for (d = 0; d < g; d++) printf( %d%c , res[d], d != g - 1 ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int f, int s) {     if (s == 0)       return f;     else       return gcd(s, f % s);   }   int const N = 1000006;   long long const M = 1000 * 1000 * 1000 + 7;   long double const ep = .000000000000000001;   int arr[N];   int main() {     int n, m;     cin >> n >> m;     int mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       sum += arr[i];       mx = max(arr[i], mx);     }     sort(arr, arr + n);     int curr = 1;     long long ans = n;     for (int i = 0; i < n; i++) {       if (curr > mx) curr = mx;       if (arr[i] >= curr) curr++;     }     if (curr > mx) {       printf( %lld n , sum - ans);     } else {       printf( %lld n , sum - (mx - (curr - 1)) - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int used[550][550];   int main() {     int x, y;     int x0, y0;     cin >> x >> y;     cin >> x0 >> y0;     string s;     cin >> s;     int cnt = 0;     cout << 1 <<    ;     int last = x * y - 1;     for (int i = 0; i < s.size(); i++) {       used[x0][y0] = 1;       bool flag = false;       if (s[i] ==  D ) {         if (x0 < x) {           if (!used[x0 + 1][y0]) flag = true;           x0++;         }       }       if (s[i] ==  U ) {         if (x0 > 1) {           if (!used[x0 - 1][y0]) flag = true;           x0--;         }       }       if (s[i] ==  L ) {         if (y0 > 1) {           if (!used[x0][y0 - 1]) flag = true;           y0--;         }       }       if (s[i] ==  R ) {         if (y0 < y) {           if (!used[x0][y0 + 1]) flag = true;           y0++;         }       }       if (i < s.size() - 1) {         if (flag) {           cnt++;           last--;         }         cout << int(flag) <<    ;       }     }     cout << last << endl;   }
#include <bits/stdc++.h>   const long long MAX_N = 2e5 + 100;   const long long MOD = 1e9 + 7;   using namespace std;   long long rm[MAX_N][20];   long long a[MAX_N];   map<int, int> last;   long long ans;   const long long c = (1ll << 50) - 1;   long long ask(long long l, long long r) {     long long len = r - l + 1;     int lg = (int)log2(len);     long long s = r - (1 << lg) + 1;     return (rm[l][lg] | rm[s][lg]);   }   bool check(long long i, long long j) {     j ^= c;     if (j & i) return true;     return false;   }   int main() {     long long n;     cin >> n;     ans = n * (n + 1) / 2;     for (int i = 1; i <= n; ++i) cin >> a[i], last[a[i]] = 0;     for (int i = 1; i <= n; ++i) rm[i][0] = a[i];     for (int i = 1; i < 20; ++i) {       for (int j = 1; j <= n - (1 << i) + 1; ++j) {         rm[j][i] = rm[j][i - 1] | rm[j + (1 << (i - 1))][i - 1];       }     }     for (int i = 1; i <= n; ++i) {       long long l1 = i;       long long r1 = last[a[i]] + 1;       long long l2 = i;       long long r2 = n;       if (!check(ask(r1, i), a[i]))         l1 = r1;       else {         while (l1 - r1 > 1) {           long long mid = (l1 + r1) / 2;           if (!check(ask(mid, i), a[i]))             l1 = mid;           else             r1 = mid;         }       }       if (!check(ask(i, n), a[i]))         l2 = n;       else {         while (r2 - l2 > 1) {           long long mid = (l2 + r2) / 2;           if (!check(ask(i, mid), a[i]))             l2 = mid;           else             r2 = mid;         }       }       ans -= (i - l1 + 1) * (l2 - i + 1);       last[a[i]] = i;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char A[3][3], B[3][3];   int main() {     scanf( %s , A[0]);     scanf( %s , A[1]);     scanf( %s , B[0]);     scanf( %s , B[1]);     string a = A[0], b = B[0];     a += A[1][1];     a += A[1][0];     b += B[1][1];     b += B[1][0];     for (int i = 0; i < a.length(); i++)       if (a[i] ==  X ) a.erase(a.begin() + i);     for (int i = 0; i < b.length(); i++)       if (b[i] ==  X ) b.erase(b.begin() + i);     for (int i = 0; i < 3; i++) {       a += a[0];       a.erase(a.begin());       if (a == b) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }