malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else {       return (gcd(b, (a % b)));     }   }   int main() {     int t;     long long n;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       cin >> n;       long long a = (long long)4LL * n;       long long b = (long long)(n + 1LL);       long long res = gcd(a, b);       res = (long long)(a) / res;       cout << (res + 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int maxn = 100010;   int n, m, k, t, t1, t2, t3, t4;   struct node {     int x, y;     int xd, xx, yd, yx;   } a[maxn];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d%d%d%d%d%d , &a[i].x, &a[i].y, &t1, &t2, &t3, &t4);         if (t1 == 1) {           a[i].xx = -100000;         } else if (t1 == 0) {           a[i].xx = a[i].x;         }         if (t2 == 1) {           a[i].yd = 100000;         } else if (t2 == 0) {           a[i].yd = a[i].y;         }         if (t3 == 1) {           a[i].xd = 100000;         } else if (t3 == 0) {           a[i].xd = a[i].x;         }         if (t4 == 1) {           a[i].yx = -100000;         } else if (t4 == 0) {           a[i].yx = a[i].y;         }       }       bool flag = true;       int xmaxn = a[0].xd, xmin = a[0].xx, ymaxn = a[0].yd, ymin = a[0].yx;       for (int i = 1; i < n; i++) {         if (xmaxn < a[i].xx || xmin > a[i].xd || ymaxn < a[i].yx ||             ymin > a[i].yd) {           printf( 0 n );           flag = false;           break;         }         if (xmaxn > a[i].xd) {           xmaxn = a[i].xd;         }         if (xmin < a[i].xx) {           xmin = a[i].xx;         }         if (ymaxn > a[i].yd) {           ymaxn = a[i].yd;         }         if (ymin < a[i].yx) {           ymin = a[i].yx;         }       }       if (flag) {         printf( 1 %d %d n , xmin, ymin);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     pair<int, int> A[50007];     int n;     cin >> n;     for (int i = 0; i < (n); i++) cin >> A[i].first >> A[i].second;     sort(A, A + n);     int r1 = A[0].first, r2 = A[0].second;     int r3, r4;     for (int i = 1; i < n; i++) {       if (A[i].first >= r1 || A[i].first >= r2) {         r3 = A[i].first;       } else         r3 = 1000000009;       if (A[i].second >= r1 || A[i].second >= r2) {         r4 = A[i].second;       } else         r4 = 1000000009;       r1 = r3, r2 = r4;     }     printf( %d n , min(r1, r2));   }   int main() {     int T = 1;     for (int i = 1; i <= T; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     if (x % 4 == 0) {       cout <<  1 A ;     } else if (x % 4 == 1) {       cout <<  0 A ;     } else if (x % 4 == 2) {       cout <<  1 B ;     } else if (x % 4 == 3) {       cout <<  2 A ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 2e5 + 5;   long long a[N];   long long n, m, k;   bool check(int x) {     long long now = 0, cnt = 1;     for (int i = n - x + 1; i <= n; i++) {       if (now + a[i] > k) {         cnt++, now = a[i];       } else         now += a[i];     }     return cnt <= m;   }   int upp(int l, int r) {     while (l < r) {       int mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     return l;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) a[i] = read();     printf( %d n , upp(1, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void setIo(string nom) {     ios_base::sync_with_stdio(0);     cin.tie(0);     freopen((nom +  .in ).c_str(),  r , stdin);     freopen((nom +  .out ).c_str(),  w , stdout);   }   struct Reine {     int x, y, id;     vector<int> tris;     int indTri;     void init(int i) {       cin >> x >> y;       id = i;       tris = {x, y - x, y, -x - y};     }     bool operator<(const Reine& autre) const {       if (indTri != 0)         return x < autre.x;       else         return y < autre.y;     }   };   const int N = 2e5;   int ans[N], comptes[N];   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int cote, nReines;     cin >> cote >> nReines;     vector<Reine> reines(nReines);     map<int, vector<Reine>> idems;     int ind = 0;     for (Reine& reine : reines) reine.init(ind++);     for (int indTri = 0; indTri < 4; ++indTri) {       for (Reine& reine : reines) {         reine.indTri = indTri;         idems[reine.tris[indTri]].push_back(reine);       }       for (auto& etage : idems) {         sort(etage.second.begin(), etage.second.end());         for (int i = 0; i < (int)etage.second.size(); ++i) {           ans[etage.second[i].id] +=               (i != 0) + (i != ((int)etage.second.size() - 1));         }       }       idems.clear();     }     for (ind = 0; ind < nReines; ++ind) {       comptes[ans[ind]]++;     }     cout << endl;     for (int i = 0; i < 9; ++i) cout << comptes[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double a[21][21];   double f[1100000];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %lf , &a[i][j]);     f[1] = 1;     for (int i = 2; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (!((1 << j) & i)) continue;         for (int k = 0; k < n; k++) {           if (!((1 << k) & i)) continue;           if (j == k) continue;           f[i] = max(f[i], a[k + 1][j + 1] * f[i ^ (1 << j)] +                                a[j + 1][k + 1] * f[i ^ (1 << k)]);         }       }     }     printf( %.15lf , f[(1 << n) - 1]);   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int mx = 2e5 + 9;   int game[2][mx];   int f_occ[2][mx];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       x--;       game[x][i]++;     }     memset(f_occ, -1, sizeof f_occ);     for (auto x : {0, 1}) {       for (int i = 1; i <= n; i++) {         game[x][i] += game[x][i - 1];         if (f_occ[x][game[x][i]] != -1) continue;         f_occ[x][game[x][i]] = i;       }     }     vector<pii> ans;     for (int t = 1; t <= n; t++) {       int s = 0;       int last[] = {0, 0};       int win[] = {0, 0};       int idx = 0;       int latest = -1;       while (true) {         int next[] = {0, 0};         for (auto x : {0, 1}) next[x] = last[x] + t;         int f[] = {0, 0};         for (auto x : {0, 1}) f[x] = f_occ[x][next[x]];         if (f[0] == -1 and f[1] == -1) break;         if (f[0] == -1) {           last[0] = game[0][f[1]];           last[1] = game[1][f[1]];           idx = f[1];           win[1]++;           latest = 1;           continue;         }         if (f[1] == -1) {           last[0] = game[0][f[0]];           last[1] = game[1][f[0]];           idx = f[0];           win[0]++;           latest = 0;           continue;         }         if (f[0] < f[1]) {           last[0] = game[0][f[0]];           last[1] = game[1][f[0]];           idx = f[0];           win[0]++;           latest = 0;         } else {           last[0] = game[0][f[1]];           last[1] = game[1][f[1]];           idx = f[1];           win[1]++;           latest = 1;         }       }       if (idx != n) continue;       if (win[0] == win[1]) continue;       if (win[latest] < win[1 - latest]) continue;       s = win[latest];       ans.emplace_back(s, t);     }     sort(ans.begin(), ans.end());     printf( %d n , (int)ans.size());     for (auto [s, t] : ans) {       printf( %d %d n , s, t);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n, k, t;     cin >> n;     string s;     cin >> s;     int a1 = 0, a2 = 0;     int flag1 = 0;     int flag2 = 0;     while (1) {       flag1 = 0;       flag2 = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  D ) {           flag1 = 1;           if (a2 != 0) {             a2--;             s[i] =  A ;             continue;           }           a1++;         } else if (s[i] ==  R ) {           flag2 = 1;           if (a1 != 0) {             a1--;             s[i] =  A ;             continue;           }           a2++;         } else {           continue;         }       }       if (flag1 == 0 || flag2 == 0) {         break;       }     }     if (flag1 == 1)       cout <<  D  << endl;     else if (flag2 == 1)       cout <<  R  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int M = 1e7 + 5;   int x[N];   int cnt[M];   bool vis[M + 5];   int f[M + 5];   int sum[M + 5];   void erato() {     for (int i = 2; i <= M; i++) vis[i] = true;     for (int i = 2; i <= M; i++) {       if (vis[i]) {         f[i] += cnt[i];         for (int j = 2; j <= M / i; j++) {           vis[j * i] = false;           f[i] += cnt[j * i];         }       }     }   }   int main() {     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x[i]);       cnt[x[i]]++;     }     erato();     sum[0] = 0;     for (int i = 1; i <= M - 5; i++) sum[i] += (sum[i - 1] + f[i]);     scanf( %d , &m);     while (m--) {       int l, r;       scanf( %d%d , &l, &r);       if (l >= M - 5) {         printf( 0 n );         continue;       }       if (r >= M - 5) r = M - 5;       printf( %d n , sum[r] - sum[l - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 5005;   vector<long long> arr(MAX);   long long solve(long long l, long long r, long long cur) {     if (l > r) return 0;     long long mn = arr[l], idx = l;     for (int i = l; i <= r; i++) {       if (arr[i] < mn) {         mn = arr[i];         idx = i;       }     }     return min(r - l + 1,                solve(l, idx - 1, mn) + solve(idx + 1, r, mn) + mn - cur);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     cout << solve(0, n - 1, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t_;     cin >> t_;     while (t_--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int turns = 0;       int alice = 0;       int bob = n - 1;       int alice_candies = 0;       int bob_candies = 0;       int alice_candies_previous = 0;       int bob_candies_previous = 0;       while (alice <= bob) {         turns++;         alice_candies_previous = 0;         while (alice <= bob && alice_candies_previous <= bob_candies_previous) {           alice_candies += a[alice];           alice_candies_previous += a[alice];           alice++;         }         if (alice <= bob) {           turns++;           bob_candies_previous = 0;           while (alice <= bob && bob_candies_previous <= alice_candies_previous) {             bob_candies += a[bob];             bob_candies_previous += a[bob];             bob--;           }         }       }       cout << turns <<     << alice_candies <<     << bob_candies << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ee {     int x, y, w;   };   vector<int> ke[300010], kq;   int n, m, s, c[300010] = {0}, p[300010], b[300010];   ee e[300010];   priority_queue<pair<long long, int> > Q;   long long d[300010];   void enter() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].w);       ke[e[i].x].push_back(i);       ke[e[i].y].push_back(-i);     }     scanf( %d , &s);   }   void dijkstra() {     for (int i = 1; i <= n; ++i) d[i] = 1e18;     d[s] = 0;     Q.push(pair<long long, int>(0, s));     int u, v;     long long w;     while (!Q.empty()) {       u = Q.top().second;       w = -Q.top().first;       Q.pop();       if (d[u] != w) continue;       for (vector<int>::iterator i = ke[u].begin(); i != ke[u].end(); ++i) {         v = (*i > 0 ? e[*i].y : e[-*i].x);         if (w + e[abs(*i)].w < d[v]) {           d[v] = w + e[abs(*i)].w;           Q.push(pair<long long, int>(-d[v], v));           p[v] = abs(*i);         } else if (w + e[abs(*i)].w == d[v] && e[abs(*i)].w < e[p[v]].w)           p[v] = abs(*i);       }     }   }   bool compare(int i, int j) { return e[i].w < e[j].w; }   int Find(int u) {     if (p[u] < 0) return u;     return p[u] = Find(p[u]);   }   void process() {     long long ans = 0;     int t;     for (int i = 1; i <= m; ++i)       if (abs(d[e[i].x] - d[e[i].y]) != e[i].w)         continue;       else {         t = (d[e[i].x] > d[e[i].y] ? e[i].x : e[i].y);         if (i != p[t]) continue;         ans += e[i].w;         kq.push_back(i);       }     cout << ans <<   n ;     for (vector<int>::iterator i = kq.begin(); i != kq.end(); ++i)       printf( %d  , *i);   }   int main() {     enter();     dijkstra();     process();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 10, INF = 1e9 + 10;   long long dp[N][2], a[N], n, k;   inline bool check(long long x) {     for (long long i = 1; i <= n; i++) dp[i][0] = i - 1;     for (long long i = 1; i <= n; i++)       for (long long j = i - 1; j; --j) {         if (a[i] + (i - j) * x < a[j] || a[i] - (i - j) * x > a[j]) continue;         dp[i][0] = min(dp[i][0], dp[j][0] + i - j - 1);       }     for (long long i = n; i; i--) dp[i][1] = n - i;     for (long long i = n; i; i--)       for (long long j = i + 1; j <= n; ++j) {         if (a[i] + (j - i) * x < a[j] || a[i] - (j - i) * x > a[j]) continue;         dp[i][1] = min(dp[i][1], dp[j][1] + j - i - 1);       }     for (long long i = 1; i <= n; i++)       if (dp[i][0] + dp[i][1] <= k) return 1;     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     if (k == n) return cout <<  0 , 0;     for (long long i = 1; i <= n; i++) cin >> a[i];     long long lo = 0, hi = 2e9 + 5;     while (hi - lo > 0) {       long long mid = (hi + lo) / 2;       if (check(mid))         hi = mid;       else         lo = mid + 1;     }     cout << lo;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     x *= f;   }   int mx[40][110][110];   int a[40][110], b[40][110];   int ans[110][110], n, m;   int main() {     read(n);     read(m);     for (int i = 1; i <= n; ++i) {       int x, k = 0;       read(x);       while (x) {         a[k][i] = x & 1;         x >>= 1;         k++;       }     }     for (int i = 1; i <= m; ++i) {       int x, k = 0;       read(x);       while (x) {         b[k][i] = x & 1;         x >>= 1;         k++;       }     }     for (int k = 0; k <= 30; ++k) {       int nn = 0, mm = 0;       for (int i = 1; i <= n; ++i) nn += a[k][i];       for (int i = 1; i <= m; ++i) mm += b[k][i];       if ((nn - mm) % 2 != 0) {         cout <<  NO  << endl;         exit(0);       } else {         for (int i = 1; i <= n; ++i)           for (int j = 1; j <= m; ++j) {             if (j == m && a[k][i])               mx[k][i][j] = 1, a[k][i] = (!a[k][i]), b[k][j] = (!b[k][j]);             if (i == n && b[k][j])               mx[k][i][j] = 1, a[k][i] = (!a[k][i]), b[k][j] = (!b[k][j]);             if (j != m && i != n && (a[k][i] || b[k][j]))               mx[k][i][j] = 1, a[k][i] = (!a[k][i]), b[k][j] = (!b[k][j]);           }       }       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j) ans[i][j] += mx[k][i][j] * (1 << k);     }     cout <<  YES  << endl;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) printf( %d  , ans[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, A[100001], BIT[100001], res[100001];   vector<int> v;   map<int, int> m;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) scanf( %d , &A[i]), v.push_back(A[i]);     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     int n = v.size();     for (int i = 0; i < n; ++i) m[v[i]] = i + 1;     for (int i = N; i >= 1; --i) {       int mx = 0;       for (int x = m[A[i]] - 1; x > 0; x -= x & -x)         if (mx < BIT[x]) mx = BIT[x];       res[i] = ((mx - i - 1 >= 0) ? (mx - i - 1) : -1);       for (int x = m[A[i]]; x <= n; x += x & -x)         if (!BIT[x]) BIT[x] = i;     }     for (int i = 1; i <= N; ++i) printf( %d  , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k, m;     cin >> n >> k >> m;     map<string, int> mp;     vector<int> cost(n);     for (int i = 0; i < n; ++i) {       string str;       cin >> str;       mp[str] = i;     }     for (int i = 0; i < n; ++i) {       cin >> cost[i];     }     for (int i = 0; i < k; ++i) {       int t, mn = INT_MAX;       cin >> t;       stack<int> st;       while (t--) {         int x;         cin >> x;         --x;         st.push(x);         mn = min(mn, cost[x]);       }       while (!st.empty()) {         cost[st.top()] = mn;         st.pop();       }     }     long long sum = 0;     for (int i = 0; i < m; ++i) {       string str;       cin >> str;       sum += cost[mp[str]];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, k, mini = INT_MAX, maxi = 0;     cin >> t;     while (t--) {       mini = INT_MAX;       maxi = 0;       cin >> n >> k;       int a[n];       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);         mini = min(mini, a[i]);         maxi = max(maxi, a[i]);       }       if ((maxi - mini) > 2 * k) {         cout << -1 << endl;         continue;       } else {         cout << (mini + k) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct re {     long long x[300300];     long long up[300300];     bool f[300300];   };   int o;   re rmq;   void f_read() {     int i, n, a[100100];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     o = 1;     memset(rmq.x, 0, sizeof(rmq.x));     memset(rmq.up, 0, sizeof(rmq.up));     memset(rmq.f, 0, sizeof(rmq.f));     while (o < n) o *= 2;     for (i = 0; i < n; ++i) rmq.x[i + o] = a[i];     for (i = o - 1; i > 0; --i)       rmq.x[i] = ((rmq.x[i * 2]) < (rmq.x[i * 2 + 1]) ? (rmq.x[i * 2 + 1])                                                       : (rmq.x[i * 2]));   }   void RPUSH(int v) {     if (!rmq.f[v]) return;     rmq.f[v * 2] = 1;     rmq.up[v * 2] = rmq.up[v];     rmq.f[v * 2 + 1] = 1;     rmq.up[v * 2 + 1] = rmq.up[v];     rmq.x[v] = rmq.up[v];     rmq.f[v] = 0;   }   long long RMAX(int l, int r, int v = 1, int cl = 1, int cr = o) {     if (l > r) return 0;     if (l == cl && r == cr) {       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RMAX(l, ((r) > (t) ? (t) : (r)), v * 2, cl, t),               b = RMAX(((t + 1) < (l) ? (l) : (t + 1)), r, v * 2 + 1, t + 1, cr);     return ((a) < (b) ? (b) : (a));   }   long long RADD(int l, int r, long long d, int v = 1, int cl = 1, int cr = o) {     if (l > r)       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     if (l == cl && r == cr) {       rmq.f[v] = 1;       rmq.up[v] = d;       return d;     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RADD(l, ((t) > (r) ? (r) : (t)), d, v * 2, cl, t),               b = RADD(((t + 1) < (l) ? (l) : (t + 1)), r, d, v * 2 + 1, t + 1,                        cr);     rmq.x[v] = ((a) < (b) ? (b) : (a));     return rmq.x[v];   }   int main() {     f_read();     int i, m, w, h;     cin >> m;     for (i = 0; i < m; ++i) {       cin >> w >> h;       long long t = RMAX(1, w);       cout << t << endl;       RADD(1, w, h + t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const long long MOD = 1e9 + 7;   long long n, x[N], ans, pw[N], dp[N], num[N];   inline long long add(long long a, long long b) {     a += b;     while (a >= MOD) a -= MOD;     return a;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i];     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     sort(x, x + n);     pw[0] = 1;     for (int i = 1; i <= n; ++i) {       pw[i] = add(pw[i - 1], pw[i - 1]);     }     dp[1] = x[1] - x[0];     num[1] = 1;     for (int i = 2; i < n; ++i) {       long long now = x[i] - x[i - 1];       dp[i] = add(dp[i - 1], num[i - 1] * now);       dp[i] = add(dp[i], dp[i]);       dp[i] = add(dp[i], now);       num[i] = add(num[i - 1], num[i - 1]);       num[i] = add(num[i], 1);     }     for (int i = 0; i < n; ++i) ans = add(ans, dp[i]);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char ss[8][5] = { 1869 ,  6198 ,  1896 ,  1689 ,  1986 ,  1968 ,  1698 };   string s;   int x, cnt, vis[1000010];   int main() {     cin >> s;     int len = s.length();     for (register int i = 0; i < len; i++) {       if (s[i] ==  0 )         cnt++;       else if (!vis[s[i]] and                (s[i] ==  1  or s[i] ==  6  or s[i] ==  8  or s[i] ==  9 ))         vis[s[i]] = 1;       else {         x = (x << 3) + (x << 1) + (s[i] ^ 48);         x %= 7;         cout << s[i];       }     }     if (x == 0)       cout << 1869;     else if (x == 1)       cout << 6198;     else if (x == 2)       cout << 1896;     else if (x == 3)       cout << 1689;     else if (x == 4)       cout << 1986;     else if (x == 5)       cout << 1968;     else if (x == 6)       cout << 1698;     for (int i = 1; i <= cnt; i++) cout << 0;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read1() {     T t = 0;     char k = getchar();     bool flag = 0;     while ( 0  > k || k >  9 ) {       if (k ==  - ) flag = 1;       k = getchar();     }     while ( 0  <= k && k <=  9 )       t = (t << 3) + (t << 1) + (k ^ 48), k = getchar();     return flag ? -t : t;   }   int s, x[5], dp[2][16][16][16];   char str[5][1005];   int main() {     s = read1<long long>();     for (int i = 1; i < 5; ++i) x[i] = read1<long long>();     for (int i = 1; i <= 4; ++i) scanf( %s , str[i] + 1);     memset(dp[0], 0x7f, sizeof(dp[0]));     dp[0][15][15][15] = 0;     for (int i = 1; i <= s; ++i) {       memset(dp[i & 1], 0x7f, sizeof(dp[i & 1]));       int t = 0;       for (int j = 1; j < 5; ++j) t = t << 1 | (str[j][i] ==  . );       for (int j = 0; j < 16; ++j)         for (int k = 0; k < 16; ++k)           for (int l = 0; l < 16; ++l)             dp[i & 1][15][15][15] =                 min(dp[i & 1][15][15][15], dp[~i & 1][j][k][l] + x[4]);       for (int k = 0; k < 16; ++k)         for (int l = 0; l < 16; ++l)           dp[i & 1][k][l][t] = min(dp[i & 1][k][l][t], dp[~i & 1][15][k][l]);       for (int j = 0; j < 16; ++j)         for (int k = 0; k < 16; ++k)           for (int r = 0; r < 16; ++r)             for (int l = 1; l < 4; ++l)               for (int w = 0; w < 5 - l; ++w) {                 int op[3] = {j, k, r};                 for (int f = 2; f > 2 - l; --f) op[f] |= (1 << l) - 1 << w;                 dp[i & 1][op[0]][op[1]][op[2]] = min(                     dp[i & 1][op[0]][op[1]][op[2]], dp[i & 1][j][k][r] + x[l]);               }     }     cout << dp[s & 1][15][15][15];     return 0;   }