malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 50;   const long long Mod = 1e9 + 7;   struct node {     long long to, next, w;   } edge[maxn * 2];   struct Edge {     long long u, v;   } t[maxn];   long long k = 0, head[maxn];   void add(long long u, long long v) {     edge[++k].to = v;     edge[k].next = head[u];     head[u] = k;   }   long long T, p[maxn], m, n;   long long ans = 0, sz[maxn], cnt[maxn];   void dfs(long long x, long long f, long long opt) {     sz[x] = 1;     for (long long i = head[x]; i; i = edge[i].next) {       if (edge[i].to == f) continue;       dfs(edge[i].to, x, i);       sz[x] += sz[edge[i].to];     }     if (opt == 0) return;     cnt[opt] = sz[x] * (n - sz[x]);     if (cnt[opt] == 0 && opt != 0) cnt[opt] = n - 1;   }   int main() {     cin >> T;     while (T--) {       k = 0;       memset(head, 0, sizeof(head));       memset(cnt, 0, sizeof(cnt));       cin >> n;       for (long long i = 1; i <= n - 1; i++) {         long long u, v;         cin >> u >> v;         add(u, v);         add(v, u);       }       cin >> m;       for (long long i = 1; i <= m; i++) cin >> p[i];       sort(p + 1, p + 1 + m);       long long cnt1 = n - 1 - m;       if (cnt1 <= 0) cnt1 = 0;       dfs(1, 1, 0);       sort(cnt + 1, cnt + 1 + k);       while (m > n - 1) {         p[m - 1] = (p[m - 1] * p[m]) % Mod;         m--;       }       long long ans = 0, opt = 0;       for (long long i = k / 2 + 1; i <= k; i++) {         if (cnt1) {           ans = (ans + cnt[i] * 1) % Mod;           cnt1--;         } else {           ans = (ans + cnt[i] * p[++opt] % Mod) % Mod;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> L[1000005];   long long fac[1000005];   const long long MOD = 1000000007;   int main() {     int N, M;     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) {       int g;       scanf( %d , &g);       map<int, int> cnt;       for (int j = 0; j < g; ++j) {         int a;         scanf( %d , &a);         ++cnt[a];       }       for (auto x : cnt) {         L[x.first].push_back({i, x.second});       }     }     map<vector<pair<int, int>>, int> mp;     for (int i = 1; i <= M; ++i) ++mp[L[i]];     fac[0] = 1;     for (int i = 1; i <= M; ++i) fac[i] = (fac[i - 1] * i) % MOD;     long long ans = 1;     for (auto &x : mp) ans = (ans * fac[x.second]) % MOD;     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long get_sum(vector<long long> &prefix, int left, int right) {     if (left != 0)       return prefix[right] - prefix[left - 1];     else       return prefix[right];   }   void To_Add_or_Not_To_Add(vector<long long> &a, long long k) {     int n = a.size();     sort(a.begin(), a.end());     vector<long long> prefix = a;     for (int i = 1; i < n; i++) prefix[i] += prefix[i - 1];     long ans = 0;     int maxFreq = INT_MIN;     for (auto key : a) {       int freq = upper_bound(a.begin(), a.end(), key) -                  lower_bound(a.begin(), a.end(), key);       int low = 0;       int high = lower_bound(a.begin(), a.end(), key) - a.begin();       high--;       long long stock = k;       while (low <= high) {         int mid = (low + high) / 2;         int len = high - mid + 1;         auto req = len * key - get_sum(prefix, mid, high);         if (stock >= req) {           stock -= req;           high = mid - 1;           freq += len;         } else {           low = mid + 1;         }       }       if (freq > maxFreq) {         maxFreq = freq;         ans = key;       }     }     cout << maxFreq <<     << ans << endl;   }   int main() {     int n;     cin >> n;     long long k;     cin >> k;     vector<long long> a(n);     for (auto &ele : a) cin >> ele;     To_Add_or_Not_To_Add(a, k);     return 0;   }
/*     */   #include <bits/stdc++.h>   using namespace std;      #define rng(x) x.begin(), x.end()   #define pb push_back   #define ff first   #define ss second      typedef double db;   typedef long long ll;   typedef pair<int, int> pi;   typedef pair<ll, ll> pl;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef vector<bool> vb;   typedef unsigned long long int lld;      /*-----------------------------Code begins----------------------------------*/   ll mod = 1e9 + 7;   const ll INF = 1e9;      ll inv(ll v)   {    if (v<=1)     return v;    return inv(mod%v)*(mod-mod/v)%mod;   }      void solve(){       int n; cin>>n;       vvl dist(n,vl(n,INF));       for(int i=1; i<n; i++){           int u,v; cin>>u>>v;           u--; v--;           dist[u][v]=1;           dist[v][u]=1;       }       for(int i=0; i<n; i++){           dist[i][i]=0;       }       for(int k=0; k<n; k++){           for(int i=0; i<n; i++){               for(int j=0; j<n; j++){                   dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);               }           }       }       vvl prob(207,vl(207));       for(int i=0; i<=n; i++){           for(int j=0; j<=n; j++){               if(i==0){                   prob[i][j]=0;               }               else if(j==0){                   prob[i][j]=1;               }               else{                   prob[i][j] = ((prob[i-1][j] + prob[i][j-1])%mod * inv(2) )%mod;               }           }       }          ll ans=0;       for(int a=0; a<n; a++){           for(int b=a+1; b<n; b++){               for(int root=0; root<n; root++){                   int root_a = dist[a][root];                   int root_b = dist[b][root];                   int root_lca = ( root_a + root_b - dist[a][b] )/2 ;                   int lca_a = root_a - root_lca ;                   int lca_b = root_b - root_lca ;                   ans = (ans + prob[lca_a][lca_b])%mod;               }           }       }       ans = (ans * inv(n) )%mod;       cout<<ans<<  n ;   }   int main(){     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     //cin >> T;     while (T--){       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = (long double)1e-7;   const long double PI = acos(0) * 2;   bool isZero(const long double& x) { return abs(x) <= EPS; }   int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b)) {     }     return abs(a);   }   pair<long long, long long> operator+(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first + b.first, a.second + b.second);   }   pair<long long, long long> operator-(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first - b.first, a.second - b.second);   }   pair<long long, long long> operator*(const pair<long long, long long>& a,                                        const long long& b) {     return pair<long long, long long>(a.first * b, a.second * b);   }   long long operator*(const pair<long long, long long>& a,                       const pair<long long, long long>& b) {     return a.first * b.second - b.first * a.second;   }   long long ccw(const pair<long long, long long>& a,                 const pair<long long, long long>& b,                 const pair<long long, long long>& c) {     return a * b + b * c + c * a;   }   void fg(vector<int> G[], int a, int b) {     G[a].emplace_back(b);     G[b].emplace_back(a);   }   void fg(vector<pair<int, int> > G[], int a, int b, int c) {     G[a].emplace_back(b, c);     G[b].emplace_back(a, c);   }   const int MAXN = 1000055;   int A[MAXN], B[MAXN];   bitset<MAXN> C;   int T, N;   void run() {     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> A[i];       B[i] = i - A[i];     }     vector<int> V;     for (int i = 1;;) {       V.emplace_back(i);       if (C[i]) break;       C[i] = true;       i = B[i];     }     for (int v : V) C[v] = false;     V.erase(V.begin(), find(((V).begin()), ((V).end()), V.back()) + 1);     cout << ((int)(V).size()) <<   n ;     for (int v : V) cout << v <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (cin >> T; T--;) run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf(1010101010);   int le_res, aa;   char naam[1000];   int le_naam;   char naam_and_res[1000];   char occ[1000];   int zvals[1000];   void z_functie(char* s, int n, int* z) {     int a(0), b(0);     for (int i(0); i < (n); i++) z[i] = n;     for (int i = 1; i < n; i++) {       int k = max(0, min(b - i, z[i - a]));       while (i + k < n && s[i + k] == s[k]) k++;       z[i] = k;       if (i + k > b) a = i, b = i + k;     }   }   bool chk(char* s) {     for (int i(0); i < (le_res); i++) naam_and_res[le_naam + 1 + i] = s[i];     naam_and_res[le_naam + 1 + le_res] = 0;     z_functie(naam_and_res, le_naam + 1 + le_res, zvals);     for (int i(0); i < (le_res - le_naam + 1); i++) {       int zz(zvals[le_naam + 1 + i]);       if (zz == le_naam && occ[i] ==  0 ) return false;       if (zz != le_naam && occ[i] ==  1 ) return false;     }     return true;   }   char tpl[1000];   char ans[1000];   int main() {     cin >> le_res >> aa;     scanf( %s , naam), le_naam = strlen(naam);     for (int i(0); i < (le_naam); i++) naam_and_res[i] = naam[i];     naam_and_res[le_naam] =  $ ;     scanf( %s , occ);     for (int i(0); i < (le_res); i++) tpl[i] =  . ;     for (int i(0); i < (le_res - le_naam + 1); i++) {       if (occ[i] ==  1 ) {         for (int j(i); j < (i + le_naam); j++) {           tpl[j] = naam[j - i];         }       }     }     for (int i(0); i < (le_naam); i++) {       char c( a  + (((naam[i] -  a ) + 1) % aa));       for (int i(0); i < (le_res); i++) {         if (tpl[i] ==  . )           ans[i] = c;         else           ans[i] = tpl[i];       }       if (chk(ans)) {         ans[le_res] = 0;         printf( %s n , ans);         goto done;       }     }     puts( No solution );   done:;   }
#include <bits/stdc++.h>   #pragma GCC optimize  03    using namespace std;   const long long int N = 2e5 + 5;   const long long int mod = 1e9 + 7;   const long long int inf = 1e9 + 9;   long long int a[N];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     stack<long long int> s;     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];       while (!s.empty() && a[s.top()] < a[i]) s.pop();       if (!s.empty()) ans = max(ans, a[s.top()] ^ a[i]);       s.push(i);     }     for (long long int i = n; i >= 1; i--) {       while (!s.empty() && a[s.top()] < a[i]) s.pop();       if (!s.empty()) ans = max(ans, a[s.top()] ^ a[i]);       s.push(i);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c[2001][2001];   int sum1[2001][2001], sum2[2001][2001];   int f[2001][2001][2];   int mod = 1000000007;   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf(  %c , &c[i][j]);       }     }     if (n == 1 && m == 1 && c[1][1] ==  . ) {       cout << 1 << endl;       return 0;     }     for (int i = n; i >= 1; i--) {       for (int j = m; j >= 1; j--) {         if (c[i][j] ==  R ) {           sum1[i][j] = sum1[i][j + 1] + 1;           sum2[i][j] = sum2[i + 1][j] + 1;         } else {           sum1[i][j] = sum1[i][j + 1];           sum2[i][j] = sum2[i + 1][j];         }       }     }     for (int i = 1; i < n; i++) {       if (sum2[i][m] == 0) f[i][m][0] = 1;     }     for (int i = 1; i < m; i++) {       if (sum1[n][i] == 0) f[n][i][1] = 1;     }     for (int i = n - 1; i >= 1; i--) {       for (int j = m - 1; j >= 1; j--) {         f[i][j][0] += f[i + 1][j][1];         f[i][j][1] += f[i][j + 1][0];         f[i][j][0] %= mod;         f[i][j][1] %= mod;         if (c[i + 1][j] ==  R ) {           f[i][j][0] +=               (f[i + 1][j][0] - f[n - sum2[i + 1][j] + 1][j][1] + mod) % mod;         } else {           f[i][j][0] += f[i + 1][j][0];         }         if (c[i][j + 1] ==  R ) {           f[i][j][1] +=               (f[i][j + 1][1] - f[i][m - sum1[i][j + 1] + 1][0] + mod) % mod;         } else {           f[i][j][1] += f[i][j + 1][1];         }         f[i][j][0] %= mod;         f[i][j][1] %= mod;       }     }     cout << (f[1][1][0] + f[1][1][1]) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const int LIM = 1e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   vector<int> par, rk;   int getpar(int i) { return (par[i] == i) ? i : (par[i] = getpar(par[i])); }   bool join(int i, int j) {     i = getpar(i), j = getpar(j);     if (i == j) return 0;     if (rk[i] > rk[j])       par[j] = i;     else {       par[i] = j;       if (rk[i] == rk[j]) rk[j]++;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     par.resize(2 * n + 2 * m - 2);     for (int i = 0; i < par.size(); i++) par[i] = i;     x = t + m + n + m - 2;     rk.assign(2 * n + 2 * m - 2, 0);     for (int i = 0; i < n; i++) {       join(i + x, i);       join(i + x + 1 - m, i + m - 1);     }     for (int i = 0; i < m; i++) {       join(x - i, i);       join(x - i + n - 1, i + n - 1);     }     set<int> st;     for (int i = 0; i < par.size(); i++) {       st.insert(getpar(i));     }     cout << st.size() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   ll x[1 << 18];   int main() {     ios::sync_with_stdio(false), cin.tie(0);     ll n, r;     cin >> n >> r;     ll m = 1 << n;     ll sum = 0;     for (int i = 0; i < m; i++) cin >> x[i], sum += x[i];     cout << fixed << setprecision(7);     cout << (ld)sum / (ld)m << endl;     for (int i = 0; i < r; i++) {       ll a, b;       cin >> a >> b;       sum -= x[a];       x[a] = b;       sum += x[a];       cout << (ld)sum / (ld)m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     if (k >= n / 2)       cout << n * (n - 1) / 2;     else       cout << n * (n - 1) / 2 - (n - 2 * k) * (n - 2 * k - 1) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T;     cin >> T;     while (T--) {       int N;       string S;       cin >> N >> S;       int Who = -1;       string Ans1 =   , Ans2 =   ;       for (int i = 0; i < N; i++) {         if (S[i] ==  2  && !(~Who)) {           Ans1.push_back( 1 );           Ans2.push_back( 1 );         } else if (S[i] ==  2  && ~Who) {           Ans1.push_back( 0 );           Ans2.push_back( 2 );         } else if (S[i] ==  0 ) {           Ans1.push_back( 0 );           Ans2.push_back( 0 );         } else {           if (~Who) {             Ans1.push_back( 0 );             Ans2.push_back( 1 );           } else {             Ans1.push_back( 1 );             Ans2.push_back( 0 );             Who = 1;           }         }       }       cout << Ans1 <<   n  << Ans2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 1000000;   int n, m;   vector<vector<pair<int, int> > > adj;   bool valid;   int ans[N];   int cnt;   int st[N * 3];   void readin() {     int u, v;     char b[10];     scanf( %d%d , &n, &m);     valid = true;     adj.clear();     adj.resize(n + 1);     for (int i = 0; i < m; ++i) {       scanf( %d%d%s , &u, &v, b);       if (v <= u) {         valid = false;       }       adj[u].push_back(make_pair(v, b[0] ==  L  ? 0 : 1));     }   }   inline int lc(int root) { return root << 1; }   inline int rc(int root) { return (root << 1) | 1; }   void init_st(int root, int l, int r) {     if (l == r) {       st[root] = l;       return;     }     int mid = (l + r) >> 1;     init_st(lc(root), l, mid);     init_st(rc(root), mid + 1, r);     st[root] = max(st[lc(root)], st[rc(root)]);   }   void update_st(int root, int l, int r, int x, int v) {     if (l == r) {       st[root] = v;       return;     }     int mid = (l + r) >> 1;     if (x <= mid) {       update_st(lc(root), l, mid, x, v);     } else {       update_st(rc(root), mid + 1, r, x, v);     }   }   int query_st(int root, int l, int r, int x, int y) {     if (l == r) {       return st[root];     }     int mid = (l + r) >> 1;     if (y <= mid) {       return query_st(lc(root), l, mid, x, y);     } else if (x > mid) {       return query_st(rc(root), mid + 1, r, x, y);     } else {       return max(query_st(lc(root), l, mid, x, mid),                  query_st(rc(root), mid + 1, r, mid + 1, y));     }   }   bool build(int root, int limit) {     if (root > limit) {       return true;     }     int l_max = 0, r_min = INT_MAX;     for (vector<pair<int, int> >::const_iterator it = adj[root].begin();          it != adj[root].end(); ++it) {       if (it->second == 0) {         l_max = max(l_max, query_st(1, 1, n, root + 1, it->first));       } else {         r_min = min(r_min, it->first);       }     }     if (l_max == 0) {       ans[cnt++] = root;       return build(root + 1, limit);     } else if (r_min == INT_MAX) {       bool ret = build(root + 1, limit);       ans[cnt++] = root;       return ret;     } else {       if (l_max >= r_min) {         return false;       }       bool ret = true;       ret = ret && build(root + 1, l_max);       ans[cnt++] = root;       ret = ret && build(l_max + 1, limit);       return ret;     }   }   void solve() {     if (!valid) {       printf( IMPOSSIBLE n );       return;     }     init_st(1, 1, n);     for (int i = n; i >= 1; --i) {       int u = i;       for (vector<pair<int, int> >::const_iterator it = adj[i].begin();            it != adj[i].end(); ++it) {         u = max(u, it->first);       }       update_st(1, 1, n, i, query_st(1, 1, n, i, u));     }     cnt = 0;     if (build(1, n)) {       for (int i = 0; i < n; ++i) {         printf( %d%c , ans[i], i < n - 1 ?     :   n );       }     } else {       printf( IMPOSSIBLE n );     }   }   int main() {     readin();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     string s, st =   ;     cin >> s;     vector<int> m(28);     vector<int> l(28);     for (int i = 0; i < n; i++) {       m[((int)s[i]) - 97]++;     }     if (n == k) {       cout <<   n ;       return 0;     }     while (k > 0) {       for (int i = 0; i < 27; i++) {         if (k >= m[i]) {           k -= m[i];           l[i] = m[i];         } else {           m[i] = k;           l[i] = k;           k = 0;         }         if (k == 0) {           break;         }       }     }     for (int i = 0; i < n; i++) {       if (l[((int)s[i]) - 97] > 0) {         l[((int)s[i]) - 97]--;         continue;       } else         cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 80, Inf = 0x3f3f3f3f;   int n, f[N][N][N][2];   int pos[3][N], num[3][N];   char s[N];   inline int getid(char ch) {     if (ch ==  V ) return 0;     if (ch ==  K ) return 1;     return 2;   }   inline int move(int i, int j, int k, int id) {     return max(0, num[0][id] - i) + max(0, num[1][id] - j) +            max(0, num[2][id] - k) - 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> s + 1;     for (int i = 1; i <= n; ++i) {       int now = getid(s[i]);       for (int j = 0; j < 3; ++j) num[j][i] = num[j][i - 1];       pos[now][++num[now][i]] = i;     }     memset(f, 0x3f, sizeof f);     f[0][0][0][0] = 0;     for (int i = 0; i <= num[0][n]; ++i)       for (int j = 0; j <= num[1][n]; ++j)         for (int k = 0; k <= num[2][n]; ++k)           for (int fl = 0; fl < 2; ++fl) {             if (i < num[0][n])               f[i + 1][j][k][1] =                   min(f[i + 1][j][k][1],                       f[i][j][k][fl] + move(i, j, k, pos[0][i + 1]));             if (j < num[1][n] && !fl)               f[i][j + 1][k][0] =                   min(f[i][j + 1][k][0],                       f[i][j][k][fl] + move(i, j, k, pos[1][j + 1]));             if (k < num[2][n])               f[i][j][k + 1][0] =                   min(f[i][j][k + 1][0],                       f[i][j][k][fl] + move(i, j, k, pos[2][k + 1]));           }     cout << min(f[num[0][n]][num[1][n]][num[2][n]][0],                 f[num[0][n]][num[1][n]][num[2][n]][1])          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   long long fn(string a, string b) {     long long n = a.size(), m = b.size(), j = 0;     for (long long i = 0; i < m; i++) {       if (b[i] == a[j]) {         j++;         if (j >= n) {           return m - n;         }       }     }     if (j >= n) {       return m - n;     }     return m - j + n - j;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long ttt;     cin >> ttt;     vector<string> v;     long long x = 1;     while (x <= inf) {       string s =   ;       long long z = x;       while (z) {         s += (char)( 0  + z % 10);         z /= 10;       }       reverse(s.begin(), s.end());       v.push_back(s);       x *= 2;     }     while (ttt--) {       string s;       cin >> s;       long long n = s.size();       long long ans = inf;       for (auto x : v) {         ans = min(ans, fn(x, s));       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>      using namespace std;      #define lln long long int      #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);      void solve(){    int n, k;    cin>>n>>k;       vector<int> a(n+1);       for(int i = 1;i<=k;i++)     a[i] = i;       int x = k - 1;       for(int i = k+1;i<=n;i++){     a[i] = x;     x--;    }       vector<int> p(n+1);    vector<int> ans;       for(int i = n;i>=1;i--){     if(p[a[i]]==1)      continue;     else {      ans.push_back(a[i]);      p[a[i]] = 1;     }    }    reverse(ans.begin(),ans.end());       for(auto i:ans){     cout<<i<<   ;    }    cout<<endl;   }      int main(){       fast          int q;       cin>>q;          while(q--){     solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, sz1, sz2, val;   int d1[200005], d2[200005], d[200005];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &val);       if (val != 0) d1[sz1++] = val;     }     for (int i = 0; i < n; i++) {       scanf( %d , &val);       if (val != 0) d2[sz2++] = val;     }     for (int i = 0; i < sz1; i++) {       int val = d1[i];       int id = (i + 1) % sz1;       d[val] = d1[id];     }     for (int i = 0; i < sz2; i++) {       int val = d2[i];       int id = (i + 1) % sz2;       if (d[val] == d2[id]) continue;       printf( NO n );       return 0;     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char arr[4][4], a;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         cin >> a;         arr[i][j] = a;       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (arr[i][j] ==  #  && arr[i][1 + j] ==  #  &&                 (arr[1 + i][j] ==  #  || arr[i + 1][1 + j] ==  # ) ||             (arr[i][j] ==  #  || arr[i][1 + j] ==  # ) && arr[1 + i][j] ==  #  &&                 arr[i + 1][1 + j] ==  # ) {           cout <<  YES ;           return 0;         } else if (arr[i][j] ==  .  && arr[i][1 + j] ==  .  &&                        (arr[1 + i][j] ==  .  || arr[i + 1][1 + j] ==  . ) ||                    (arr[i][j] ==  .  || arr[i][1 + j] ==  . ) &&                        arr[1 + i][j] ==  .  && arr[i + 1][1 + j] ==  . ) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;   }