malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n, m;   vector<long long> a;   void solve() {     long long cnt = 0;     vector<vector<pair<int, int>>> ps;     queue<pair<int, int>> buff;     ps.resize(m);     for (int i = 0; i < m; i++) ps[i].clear();     for (int i = 0; i < n; i++) ps[a[i] % m].push_back({a[i], i});     for (int i = 0; i < m; i++)       if ((int)ps[i].size() > n / m) {         for (int j = 0; j < m + m; j++) {           int cur = (i + j) % m;           while ((int)ps[cur].size() > n / m) {             pair<int, int> v = ps[cur].back();             ps[cur].pop_back();             buff.push(v);           }           while ((int)ps[cur].size() < n / m && (int)buff.size() > 0) {             pair<int, int> v = buff.front();             buff.pop();             int d = (cur + m - (v.first % m)) % m;             v.first += (long long)d;             ps[cur].push_back(v);             cnt += (long long)d;           }         }         break;       }     vector<long long> res;     res.resize(n);     for (int i = 0; i < m; i++) {       assert((int)ps[i].size() == n / m);       for (pair<int, int> j : ps[i]) {         res[j.second] = j.first;       }     }     cout << cnt << endl;     for (int i = 0; i < n; i++) {       if (i < n - 1)         cout << res[i] <<    ;       else         cout << res[i] << endl;     }   }   int main() {     cin >> n >> m;     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool clash[30][30];   int dp[100001][27];   string s;   int solve(int index, int lastchar) {     if (index == s.size()) {       return 0;     }     int mn = (1 << 30);     if (dp[index][lastchar] != -1) {       return dp[index][lastchar];     }     if (!clash[s[index] -  a ][lastchar])       mn = min(mn, solve(index + 1, s[index] -  a ));     mn = min(mn, solve(index + 1, lastchar) + 1);     return dp[index][lastchar] = mn;   }   int main() {     cin >> s;     int n;     cin >> n;     string s2;     int sum = 0;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) {       cin >> s2;       clash[s2[0] -  a ][s2[1] -  a ] = true;       clash[s2[1] -  a ][s2[0] -  a ] = true;     }     cout << solve(0, 26) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool _cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     int n, x, y;     scanf( %d , &n);     vector<pair<int, int> > V(n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x, &y);       V[i].first = min(x, y);       V[i].second = max(x, y);     }     sort(V.begin(), V.end(), _cmp);     bool U[n];     memset(U, false, sizeof U);     vector<int> Res;     for (int i = 0; i < n; i++) {       if (U[i]) continue;       Res.push_back(V[i].second);       for (int j = i + 1; j < n; j++)         if (V[j].first <= V[i].second) U[j] = true;     }     printf( %d n , Res.size());     for (int i = 0; i < Res.size(); i++)       printf( %s%d , (i == 0 ?    :    ), Res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Q {     int a, b, c, d;     Q(int x, int y, int z, int w) : a(x), b(y), c(z), d(w) {}   };   pair<int, int> query(Q z) {     int u, v;     printf( %d%d%d%d n , z.a, z.b, z.c, z.d);     fflush(stdout);     scanf( %d%d , &u, &v);     return make_pair(u, v);   }   pair<int, int> dist(Q e, Q f) {     int bulls = 0, cows = 0;     if (e.a == f.a) bulls++;     if (e.b == f.b) bulls++;     if (e.c == f.c) bulls++;     if (e.d == f.d) bulls++;     if ((e.a == f.a) || (e.a == f.b) || (e.a == f.c) || (e.a == f.d)) cows++;     if ((e.b == f.a) || (e.b == f.b) || (e.b == f.c) || (e.b == f.d)) cows++;     if ((e.c == f.a) || (e.c == f.b) || (e.c == f.c) || (e.c == f.d)) cows++;     if ((e.d == f.a) || (e.d == f.b) || (e.d == f.c) || (e.d == f.d)) cows++;     return make_pair(bulls, cows - bulls);   }   int main() {     vector<Q> X;     for (int i = 0; i < 10; ++i)       for (int j = 0; j < 10; ++j)         if (i - j) {           for (int k = 0; k < 10; ++k)             if ((i - k) && (j - k)) {               for (int l = 0; l < 10; ++l)                 if ((i - l) && (j - l) && (k - l)) {                   Q h(i, j, k, l);                   X.push_back(h);                 }             }         }     int bulls = 0, cows = 0;     while (bulls < 4) {       pair<int, int> Z = query(X[0]);       bulls = Z.first;       cows = Z.second;       vector<Q> Y;       Q V = X[0];       for (int i = 0; i < X.size(); ++i) {         pair<int, int> T = dist(V, X[i]);         if (T.first == bulls && T.second == cows) Y.push_back(X[i]);       }       X = Y;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, A, cf, cm, m;   struct node {     long long x;     int i;   } a[100001];   long long sum[100001];   long long ans = 0;   bool cmp(node a, node b) { return a.x < b.x; }   bool cmp1(node a, node b) { return a.i < b.i; }   long long minc = 0;   long long bsearch(long long x) {     int l = 0;     int r = n;     while (l < r) {       int mid = l + (r - l) / 2;       if (a[mid].x > x)         r = mid;       else         l = mid + 1;     }     return l;   }   void solve() {     for (int i = 0; i < n; ++i) {       long long num = m - (A * (long long)i - (sum[n - 1] - sum[n - 1 - i]));       if (num < 0) break;       long long l = a[0].x - 1;       long long r = A;       while (l < r) {         long long mid = l + (r - l) / 2;         long long k = bsearch(mid) - 1;         if (k + i >= n) k = n - 1 - i;         long long sum1 = (mid * (k + 1) - sum[k]);         if (sum1 > num)           r = mid;         else           l = mid + 1;       }       l--;       if (ans <= (long long)i * cf + (long long)l * cm) {         ans = (long long)i * cf + (long long)l * cm;         minc = l;       }     }   }   int main() {     while (cin >> n >> A >> cf >> cm >> m) {       for (int i = 0; i < n; ++i) {         scanf( %lld , &a[i].x);         a[i].i = i;       }       a[n].x = A + 1;       a[n].i = n;       ans = 0;       sort(a, a + n, cmp);       sum[0] = a[0].x;       for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i].x;       if (A * n <= sum[n - 1] + m) {         ans = n * cf + A * cm;         minc = A;       } else {         solve();       }       for (int i = 0; i < n; ++i) {         if (a[i].x < minc) {           m -= minc - a[i].x;           a[i].x = minc;         } else           break;       }       for (int i = n - 1; i >= 0; --i) {         if (A - a[i].x <= m) {           m -= A - a[i].x;           a[i].x = A;         } else {           a[i].x += m;           m = 0;           break;         }       }       sort(a, a + n, cmp1);       printf( %lld n , ans);       for (int i = 0; i < n; ++i) {         if (i == n - 1)           printf( %lld n , a[i].x);         else           printf( %lld  , a[i].x);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, z[100005], a[100005], ans[100005];   string s;   int main() {     int i, l = 0, r = 0;     cin >> s;     n = s.length();     memset(z, 0, sizeof(z));     memset(ans, 0, sizeof(ans));     ans[1] = 1;     for (i = 1; i < n; i++) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;       if (i + z[i] - 1 > r) r = i + z[i] - 1, l = i;       ans[1]++;       ans[z[i] + 1]--;     }     for (i = 1; i <= n; i++) ans[i] += ans[i - 1];     a[0] = 0;     for (i = 1; i <= n; i++)       if (z[n - i] == i) a[++a[0]] = i;     a[++a[0]] = n;     printf( %d n , a[0]);     for (i = 1; i <= a[0]; i++) printf( %d %d n , a[i], ans[a[i]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_L = 200;   map<int, pair<int, int> > ds;   int ops[MAX_L];   int powmod(int a, int n, int mod) {     int pm = 1;     while (n > 0) {       if (n & 1) pm = (long long)pm * a % mod;       a = (long long)a * a % mod;       n >>= 1;     }     return pm;   }   bool check(int v, int u, int uc, queue<int> &q, int &mst, int &mgl) {     map<int, pair<int, int> >::iterator mit = ds.find(v);     if (mit != ds.end()) {       if (uc * mit->second.first < 0) {         if (uc > 0)           mst = u, mgl = v;         else           mst = v, mgl = u;         return true;       }     } else {       ds[v] = pair<int, int>(uc, u);       q.push(v);     }     return false;   }   int getop(int u, int v, int p) {     if ((u + 1) % p == v) return 1;     if ((u + p - 1) % p == v) return 2;     return 3;   }   int main() {     int st, gl, p;     scanf( %d%d%d , &st, &gl, &p);     if (st == gl) {       puts( 2 n1 2 );       return 0;     }     ds[st] = pair<int, int>(1, -1);     ds[gl] = pair<int, int>(-1, -1);     queue<int> q;     q.push(st), q.push(gl);     int mst = -1, mgl = -1;     while (!q.empty()) {       int u = q.front();       q.pop();       pair<int, int> ud = ds[u];       int uc = ud.first, up = ud.second;       if (check((u + 1) % p, u, uc, q, mst, mgl) ||           check((u + p - 1) % p, u, uc, q, mst, mgl) ||           check(powmod(u, p - 2, p), u, uc, q, mst, mgl))         break;     }     vector<int> vst, vgl;     for (int u = mst; u >= 0; u = ds[u].second) vst.push_back(u);     for (int u = mgl; u >= 0; u = ds[u].second) vgl.push_back(u);     int l = 0;     for (int i = vst.size() - 1; i > 0; i--)       ops[l++] = getop(vst[i], vst[i - 1], p);     ops[l++] = getop(mst, mgl, p);     for (int i = 0; i + 1 < vgl.size(); i++)       ops[l++] = getop(vgl[i], vgl[i + 1], p);     printf( %d n , l);     for (int i = 0; i < l; i++) printf( %d%c , ops[i], (i + 1 < l) ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E5;   int a[MAXN];   long long pref[MAXN];   long long suff[MAXN];   int main() {     int n, d, m;     cin >> n >> d >> m;     int bigger = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > m) bigger++;     }     sort(a, a + n);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i)         pref[i] = pref[i - 1] + a[i];       else         pref[i] = a[i];     }     if (bigger == 0) {       ans = 0;       for (int i = 0; i < n; i++) ans += a[i];       cout << ans <<   n ;       return 0;     }     long long lowSum = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= m) lowSum += a[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         suff[i] = a[i];       else         suff[i] = a[i] + suff[i + 1];     }     int atLeast = (n + d) / (d + 1);     for (int i = 1; i <= min(bigger, atLeast); i++) {       int minShadow = max((i - 1) * d, bigger - i);       int maxShadow = min(i * d, n - i);       if (minShadow > maxShadow) continue;       long long temp = 0;       if (minShadow - (bigger - i) - 1 >= 0)         temp = suff[n - i] + lowSum - pref[minShadow - (bigger - i) - 1];       else         temp = suff[n - i] + lowSum;       ans = max(ans, temp);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     int k;     char a[101];     int i = 0;     scanf( %d %d , &n, &k);     scanf( %s , a);     if (k > n / 2) {       i = k;       while (i < n) {         printf( RIGHT n );         i++;       }     } else {       i = k;       while (i > 1) {         printf( LEFT n );         i--;       }     }     if (i == 1) {       i--;       printf( PRINT %c n , a[i]);       i++;       while (i < n) {         printf( RIGHT n );         printf( PRINT %c n , a[i]);         i++;       }     } else {       printf( PRINT %c n , a[i - 1]);       i--;       while (i > 0) {         printf( LEFT n );         printf( PRINT %c n , a[i - 1]);         i--;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef int arr[500005];   arr Next, a, Sa, Lcp, pos, tmp, S;   int n, len;   char P[500005];   vector<int> Val[2 * 500005];   bool cmp(int p, int q) {     if (pos[p] != pos[q]) return pos[p] < pos[q];     p += len;     q += len;     if (p <= n && q <= n) return pos[p] < pos[q];     return p > q;   }   void BuildSA() {     for (int i = 1; i <= n; i++) {       Sa[i] = i;       pos[i] = ((P[i] ==  ( ) ? 1 : 2);     }     for (len = 1; len <= n; len *= 2) {       sort(Sa + 1, Sa + n + 1, cmp);       for (int i = 1; i <= n; i++) tmp[i] = tmp[i - 1] + cmp(Sa[i - 1], Sa[i]);       for (int i = 1; i <= n; i++) pos[Sa[i]] = tmp[i];     }   }   void BuildLCP() {     int cur = 0;     for (int i = 1; i <= n; i++) {       int j = Sa[pos[i] - 1];       if (j == 0) continue;       while (P[i + cur] == P[j + cur]) cur++;       Lcp[pos[i]] = cur;       if (cur) cur--;     }   }   int Get(int V, int L, int R) {     int l = lower_bound(Val[V].begin(), Val[V].end(), L) - Val[V].begin();     int r = upper_bound(Val[V].begin(), Val[V].end(), R) - Val[V].begin();     return max(r - l, 0);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> P[i];       a[i] = a[i - 1];       if (P[i] ==  ( ) a[i]++;       if (P[i] ==  ) ) a[i]--;       Val[a[i] + 500005].push_back(i);     }     int top = 0;     S[0] = n + 1;     for (int i = n; i >= 0; i--) {       while (a[i] <= a[S[top]] && top) top--;       Next[i] = S[top];       S[++top] = i;     }     BuildSA();     BuildLCP();     long long ans = 0;     for (int i = 1; i <= n; i++) {       int L = Sa[i] + Lcp[i];       int R = Next[Sa[i] - 1] - 1;       ans += Get(a[Sa[i]] - 1 + 500005, L, R);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n;   pair<long long, long long> x[4000];   long long d[4000];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> x[i].first >> x[i].second;     sort(x + 1, x + n + 1);     d[n] = x[n].second;     for (int i = n - 1; i >= 1; i--) {       d[i] = 1000000000000000000LL;       long long s = 0;       for (int j = i + 1; j <= n; j++)         d[i] = min(d[i], s + d[j]), s += x[j].first - x[i].first;       d[i] = min(d[i], s);       d[i] += x[i].second;     }     cout << d[1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long N = 2e5 + 100;   const long long INF = 1e18;   long long x[N], p[N], a[N];   struct node {     long long ans = 0, pref = 0, suff = 0, sum = 0;     node() {}     node(long long x) {       pref = suff = sum = x;       ans = max(x, 0ll);     }   } t[4 * N];   node merge(node l, node r) {     node ret;     ret.ans = max(l.ans, r.ans);     ret.pref = max(l.pref, l.sum + r.pref);     ret.suff = max(r.suff, r.sum + l.suff);     ret.sum = l.sum + r.sum;     ret.ans = max({ret.ans, ret.pref, ret.suff});     ret.ans = max(ret.ans, l.suff + r.pref);     return ret;   }   void build(long long v, long long l, long long r) {     if (l + 1 == r) {       t[v] = node(a[l]);       return;     }     long long mid = (l + r) / 2;     build(v * 2 + 1, l, mid);     build(v * 2 + 2, mid, r);     t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);   }   node qu(long long v, long long l, long long r, long long ql, long long qr) {     if (qr <= l || r <= ql) return node();     if (ql <= l && r <= qr) return t[v];     long long mid = (l + r) / 2;     return merge(qu(v * 2 + 1, l, mid, ql, qr), qu(v * 2 + 2, mid, r, ql, qr));   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, c;     cin >> n >> m >> c;     for (long long i = 0; i < n; i++) {       cin >> x[i];     }     n--;     for (long long i = 0; i < n; i++) {       x[i] = 50 * (x[i + 1] - x[i]);     }     for (long long i = 0; i < n; i++) {       cin >> p[i];     }     for (long long i = 0; i < n; i++) {       a[i] = (x[i] - p[i] * c);     }     build(0, 0, n);     long long ans = 0;     for (long long i = 0; i < m; i++) {       long long l, r;       cin >> l >> r;       l--;       r--;       ans += qu(0, 0, n, l, r).ans;     }     cout << fixed << setprecision(20) << ans / 100.0 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1e5 + 9;   vector<int> v[N];   bool visited[N];   int c = 0;   map<pair<int, int>, int> m;   void dfs(int x, int parent) {     visited[x] = true;     bool b = false;     for (int i = 0; i < v[x].size(); i++) {       if (!visited[v[x][i]]) {         b = true;         dfs(v[x][i], x);       }     }     if (!b) m[{parent, x}] = c++;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int x;     cin >> x;     int l[x - 1], r[x - 1];     for (int i = 0; i < x - 1; i++) {       cin >> l[i] >> r[i];       v[l[i]].push_back(r[i]);       v[r[i]].push_back(l[i]);     }     dfs(l[0], l[0]);     for (int i = 0; i < x - 1; i++) {       if (m.find({l[i], r[i]}) != m.end())         cout << m[{l[i], r[i]}] <<   n ;       else if (m.find({r[i], l[i]}) != m.end())         cout << m[{r[i], l[i]}] <<   n ;       else         cout << c++ <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout <<  0 0  << endl;     string left;     cin >> left;     int l = 0, r = 1e9;     for (int i = 1; i < n; i++) {       int mid = (l + r) / 2;       cout << mid <<   1  << endl;       string s;       cin >> s;       if (s == left) {         l = mid;       } else {         r = mid;       }     }     cout << l <<   2   << r <<   0  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a, b, c, x, y, z;     int spa = 0, spb = 0, spc = 0;     int req = 0;     cin >> a >> b >> c;     cin >> x >> y >> z;     if (a > x)       spa = a - x;     else       req += x - a;     if (b > y)       spb = b - y;     else       req += y - b;     if (c > z)       spc = c - z;     else       req += z - c;     if (spa > 0) req = req - spa / 2;     if (spb > 0) req = req - spb / 2;     if (spc > 0) req = req - spc / 2;     if (req <= 0)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     if (a.first + a.second == b.first + b.second) {       return a.first < b.first;     }     return (a.first + a.second) < (b.first + b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int q;     cin >> q;     while (q--) {       long long int n;       cin >> n;       vector<pair<long long int, long long int> > A(n + 1, {0, 0});       for (long long int i = 0; i < n; i++) {         long long int a, first;         cin >> a >> first;         if (first == 0) {           A[a].second++;         } else {           A[a].first++;         }       }       sort(A.rbegin(), A.rend(), comp);       pair<long long int, long long int> sol = {A[0].first + A[0].second,                                                 A[0].first};       for (long long int i = 1; i < n + 1; i++) {         if (A[i - 1].first + A[i - 1].second <= 1) break;         if (A[i].first + A[i].second < A[i - 1].first + A[i - 1].second) {           sol.first += A[i].first + A[i].second;           sol.second += A[i].first;         } else if (A[i].first + A[i].second >= A[i - 1].first + A[i - 1].second) {           long long int second = A[i - 1].first + A[i - 1].second - 1;           long long int ma = 0, mai = -1;           for (long long int j = i; j < n + 1; j++) {             if (second <= A[j].first + A[j].second) {               if (A[j].first >= ma) {                 mai = j;                 ma = A[j].first;               }             } else {               break;             }           }           if (A[mai].first >= second) {             A[mai].first = second;             A[mai].second = 0;             sol.first += second;             sol.second += second;           } else {             second = second - A[mai].first;             sol.first += A[mai].first;             sol.second += A[mai].first;             A[mai].second = second;             sol.first += second;           }           swap(A[i], A[mai]);         }       }       cout << sol.first <<     << sol.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[101][101][11][2];   long long k1, k2;   long long solve(long long n1, long long n2, long long count, long long flag) {     if (n1 < 0 || n2 < 0) {       return 0;     }     if (n1 == 0 && n2 == 0) {       return 1;     }     if (flag != -1 && dp[n1][n2][count][flag] != -1) {       return dp[n1][n2][count][flag];     }     long long i;     long long ans = 0;     if (flag != 1) {       for (i = 1; i <= k2; i++) {         ans += solve(n1, n2 - i, i, 1);         ans %= (long long)1e8;       }     }     if (flag != 0) {       for (i = 1; i <= k1; i++) {         ans += solve(n1 - i, n2, i, 0);         ans %= (long long)1e8;       }     }     if (flag != -1) dp[n1][n2][count][flag] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n1, n2;     cin >> n1 >> n2 >> k1 >> k2;     memset(dp, -1, sizeof(dp));     cout << solve(n1, n2, 0, -1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char x[55];   int swim(char *c = x, int res = 0, int round = 0) {     int l = strlen(c);     if (round == 2) {       if (l == 0 || l > 7 || (c[0] ==  0  && l > 1)) return -1;       int ba2y;       sscanf(c,  %d , &ba2y);       if (ba2y > 1000000) return -1;       return ba2y + res;     }     int ma3aya = 0;     int nateg = -1;     for (; c[0]; c++) {       ma3aya *= 10;       ma3aya += c[0] -  0 ;       nateg = max(nateg, swim(c + 1, ma3aya + res, round + 1));       if (ma3aya == 0 || (ma3aya * 10) + (c[1]) -  0  > 1000000) break;     }     return nateg;   }   int main() {     scanf( %s , &x);     printf( %d , swim());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     char a[4];     char b[4];     char x;     int f = 0;     int r = 0;     for (int i = 0; i < 4; i++) {       cin >> x;       if (x !=  X ) {         a[r] = x;         r++;       } else {         if (i < 2) f = 1;       }     }     if (f) {       char t = a[1];       a[1] = a[2];       a[2] = t;       f = 0;     }     r = 0;     for (int i = 0; i < 4; i++) {       cin >> x;       if (x !=  X ) {         b[r] = x;         r++;       } else {         if (i < 2) f = 1;       }     }     if (f) {       char t = b[1];       b[1] = b[2];       b[2] = t;     }     int err = 0;     int j = 0;     for (int i = 0; i < 3; i++) {       if (!i) {         while (a[i] != b[j]) {           j++;         }       } else {         if (a[i] != b[j]) {           err = 1;           break;         }       }       j = (j + 1) % 3;     }     if (!err) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }