malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct FlowEdge {     int to, cap, rev;     FlowEdge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {}   };   class FordFulkerson {    public:     FordFulkerson() {}     FordFulkerson(int n) : G(n), used(n) {}     void add(int from, int to, int cap) {       G[from].emplace_back(to, cap, (int)G[to].size());       G[to].emplace_back(from, 0, (int)G[from].size() - 1);     }     int get(int s, int t) {       int f = 1, res = 0;       while (f) {         fill(begin(used), end(used), false);         f = dfs(s, t, INT_MAX);         res += f;       }       return res;     }       private:     vector<vector<FlowEdge>> G;     vector<bool> used;     int dfs(int v, int t, int f) {       if (v == t) return f;       used[v] = 1;       for (auto &e : G[v]) {         if (!used[e.to] && e.cap > 0) {           int d = dfs(e.to, t, min(e.cap, f));           if (d > 0) {             e.cap -= d;             G[e.to][e.rev].cap += d;             return d;           }         }       }       return 0;     }   };   const string T =  fair n , F =  unfair n ;   const int MAXV = 20099, SRC = 0, QUERY = 10001, SINK = 20010, MOD5 = 20001;   int N, B, Q, upTo[10099], quantity[10099];   pair<int, int> query[10099];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N >> B >> Q;     for (int i = 0; i < (int)Q; ++i) cin >> upTo[i] >> quantity[i];     for (int i = 0; i < (int)Q; ++i) query[i] = make_pair(upTo[i], quantity[i]);     query[Q] = make_pair(0, 0);     query[Q] = make_pair(B, N);     Q += 2;     sort(query, query + Q);     FordFulkerson flowG(MAXV);     for (int i = 0; i < (int)5; ++i) flowG.add(SRC, MOD5 + i, N / 5);     for (int num = 1; num < (int)B + 1; ++num) {       int mod5 = num % 5;       flowG.add(MOD5 + mod5, num, 1);     }     for (int i = 0; i < (int)Q - 1; ++i) {       int lef = query[i].first, rig = query[i + 1].first;       int cnt = query[i + 1].second - query[i].second;       if (cnt < 0) {         cout << F;         return 0;       }       for (int num = lef + 1; num <= rig; ++num) {         flowG.add(num, QUERY + i, 1);       }       flowG.add(QUERY + i, SINK, cnt);     }     int maxFlow = flowG.get(SRC, SINK);     cout << (maxFlow == N ? T : F);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, x = 0, k = 0;     cin >> t;     while (t--) {       int m, n, x, y = 0;       cin >> m;       cin >> n;       x = m * n;       int a[x];       for (int i = 0; i < x; i++) {         cin >> a[i];         if (a[i] < 0) {           a[i] = 0 - a[i];           k++;         }         y = y + a[i];       }       sort(a, a + x);       if (k % 2 == 0)         cout << y << endl;       else         cout << y - 2 * a[0] << endl;       k = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   void runCase(int caseNum) {     string s;     cin >> s;     int res = true;     if (s.size()) {       stack<char> st;       st.push(s[0]);       for (int i = 1; i < s.size(); ++i) {         if (!st.empty() && st.top() == s[i])           st.pop();         else           st.push(s[i]);       }       res = st.empty();     }     cout << (res ?  Yes  :  No ) << endl;   }   int main(int argc, char* argv[]) {     runCase(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read(int f = 1, int x = 0, char ch =    ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 1e2 + 5;   int n, c[2], p[N], q[N], f[2][N][N][N];   int main() {     n = read();     for (int i = 1; i <= n; ++i)       p[i] = q[i] = read(), p[i] &= 1, c[p[i]] += q[i] != 0;     c[0] = n / 2 - c[0], c[1] = n - n / 2 - c[1];     memset(f, 0x3f, sizeof(f)), f[0][0][0][0] = f[1][0][0][0] = 0;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= c[0]; ++j)         for (int k = 0; k <= c[1]; ++k)           if (q[i])             f[p[i]][i][j][k] = min(f[0][i - 1][j][k] + (0 ^ p[i]),                                    f[1][i - 1][j][k] + (1 ^ p[i]));           else {             if (j)               f[0][i][j][k] = min(f[0][i][j][k], f[0][i - 1][j - 1][k]),               f[0][i][j][k] = min(f[0][i][j][k], f[1][i - 1][j - 1][k] + 1);             if (k)               f[1][i][j][k] = min(f[1][i][j][k], f[1][i - 1][j][k - 1]),               f[1][i][j][k] = min(f[1][i][j][k], f[0][i - 1][j][k - 1] + 1);           }     printf( %d n , min(f[0][n][c[0]][c[1]], f[1][n][c[0]][c[1]]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAGIC = 400;   const long long N = 1e5 + 2;   const long long inf = 1e14 + 2;   long long lzval[MAGIC], lzmul[MAGIC], ar[N], add[N];   bool used[N];   vector<long long> idx[MAGIC];   struct hull {     long long ptr;     struct line {       long long a, b, idx;       long long y(long long x) { return a * x + b; }     };     vector<line> hull;     bool bad(line x, line y, line z) {       assert(y.a != x.a);       if (z.a == y.a) {         return z.b > y.b;       }       return (1.0 * (x.b - z.b)) / (z.a - x.a) <              (1.0 * (y.b - z.b)) / (z.a - y.a);     }     void insert(line a) {       while (hull.size() > 1) {         if (bad(hull[hull.size() - 2], hull[hull.size() - 1], a)) {           hull.pop_back();         } else {           break;         }       }       if (hull.size() && hull.back().a == a.a) {         if (hull.back().b > a.b) {           return;         } else {           hull.pop_back();         }       }       hull.push_back(a);     }     void build(vector<long long> &wow) {       hull.clear();       ptr = 0;       for (long long i = 0; i < wow.size(); i++) {         long long idx = wow[i];         if (used[idx]) {           continue;         }         line tmp;         tmp.a = ar[idx];         tmp.b = add[idx];         tmp.idx = idx;         insert(tmp);       }     }     pair<long long, long long> get(long long idx) {       while (ptr + 1 < hull.size() &&              hull[ptr].y(lzmul[idx]) < hull[ptr + 1].y(lzmul[idx])) {         ptr++;       }       return pair<long long, long long>(hull[ptr].y(lzmul[idx]) + lzval[idx],                                         -hull[ptr].idx);     }   } lis[MAGIC];   long long grp(long long x) { return (x + MAGIC - 1) / MAGIC; }   bool cmp(long long x, long long y) {     if (ar[x] != ar[y]) {       return ar[x] > ar[y];     }     return add[x] > add[y];   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, i, j, k, l, mx, ans = 0, mxans = 0, z, q;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ar[i];       add[i] = ar[i];       idx[grp(i)].push_back(i);     }     mx = grp(n);     for (i = 1; i <= mx; i++) {       sort(idx[i].begin(), idx[i].end(), cmp);       lis[i].build(idx[i]);     }     for (i = 1; i <= n; i++) {       pair<long long, long long> res = {-inf, -1};       for (j = 1; j <= mx; j++) {         if (lis[j].hull.size()) {           res = max(res, lis[j].get(j));           pair<long long, long long> kek = lis[j].get(j);         }       }       ans += res.first;       mxans = max(mxans, ans);       q = j = -res.second;       used[j] = true;       j = grp(j);       for (k = j + 1; k <= mx; k++) {         lzmul[k]++;       }       for (k = 1; k < j; k++) {         lzval[k] += ar[q];       }       k = (j - 1) * MAGIC + 1, l = min(j * MAGIC, n);       for (z = k; z <= l; z++) {         add[z] += lzval[j] + lzmul[j] * ar[z];         if (z >= q) {           add[z] += ar[z];         } else {           add[z] += ar[q];         }       }       lzval[j] = lzmul[j] = 0;       lis[j].build(idx[j]);     }     cout << mxans;   }
#include <bits/stdc++.h>   using namespace std;   long long m[1000001], cd, kq[100000];   map<long long, long long> ruler;   int main() {     cin >> cd;     for (long long i = 1; i <= cd; i++) {       cin >> m[i];       ruler[m[i]] = 1;     }     for (long long i = 1; i <= cd; i++) {       long long e = 1;       kq[e] = m[i];       long long t = m[i];       while (e <= cd) {         if (ruler[t * 2] == 1) {           kq[e + 1] = t * 2;           t = t * 2;         } else if (t % 3 == 0 && ruler[t / 3] == 1) {           kq[e + 1] = t / 3;           t = t / 3;         } else           break;         e++;         if (e == cd) {           for (long long k = 1; k <= cd; k++) cout << kq[k] <<    ;           exit(0);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> A;   string s;   int main() {     A[ void ] = 100;     A[ errtype ] = 0;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s;       if (s[4] ==  d ) {         string a, b;         cin >> a >> b;         int l = a.length();         int p = 0, q = 0;         for (int j = 0; j < l; ++j)           if (a[j] ==  & )             ++p;           else if (a[j] ==  * )             ++q;         a = a.substr(p, l - p - q);         q -= p;         if (A[a] + q < 100)           A[b] = 0;         else           A[b] = A[a] + q;       } else {         string a;         cin >> a;         int p = 0, q = 0;         int l = a.length();         for (int j = 0; j < l; ++j)           if (a[j] ==  & )             ++p;           else if (a[j] ==  * )             ++q;         a = a.substr(p, l - p - q);         q -= p;         if (A[a] + q < 100)           puts( errtype );         else {           printf( void );           int t = A[a] + q;           for (int j = 100; j < t; ++j) printf( * );           puts(  );         }       }     }     return 0;   }
#include <bits/stdc++.h>   using std::map;   const int MAXN = 1000 + 3;   int table[MAXN][MAXN];   int n, m, k;   map<int, int> r, c;   int main(int argc, char *argv[]) {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       r[i] = i;       for (int j = 1; j <= m; ++j) {         if (i == 1) c[j] = j;         scanf( %d , &table[i][j]);       }     }     char cmd;     int tmp, x, y;     while (k--) {       scanf( %s%d%d , &cmd, &x, &y);       if (cmd ==  r ) {         tmp = r[x];         r[x] = r[y];         r[y] = tmp;       } else if (cmd ==  c ) {         tmp = c[x];         c[x] = c[y];         c[y] = tmp;       } else         printf( %d n , table[r[x]][c[y]]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, d = 0, e = 0, f = 0, sum = 0, c = 0, n;     cin >> n;     char a[4][4];     map<int, int> m;     for (i = 0; i < 4; i++) {       for (j = 0; j < 4; j++) {         cin >> a[i][j];       }     }     for (i = 0; i < 4; i++) {       for (j = 0; j < 4; j++) {         if (a[i][j] >= 49 && a[i][j] <= 57) {           m[a[i][j]]++;         }       }     }     for (auto x : m) {       if (x.second > (2 * n)) {         c++;       }     }     if (c == 0) {       cout <<  YES ;     } else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = (int)998244353;   const int MAXN = (int)1e6 + 5;   template <typename T>   class BIT {    public:     BIT(T* _a, int _n) {       a = _a;       n = _n;       bit = new T[n + 1];       for (int i = 1; i <= n; ++i) bit[i] = 0;       for (int i = 1; i <= n; ++i) upd_(i, a[i]);     }     void upd(int i, T val) {       T diff = val - a[i];       a[i] = val;       while (i <= n) {         bit[i] = bit[i] + diff;         i += i & (-i);       }     }     T get(int i) {       T ret = 0;       while (i > 0) {         ret = ret + bit[i];         i -= i & (-i);       }       return ret;     }       private:     void upd_(int i, T val) {       while (i <= n) {         bit[i] = bit[i] + val;         i += i & (-i);       }     }     T *bit, *a;     int n;   };   ll n, k, m, a1[MAXN], a2[MAXN], a3[MAXN];   struct Segment {     Segment(int _l, int _r, int _c, int _p) : l(_l), r(_r), c(_c), p(_p) {       end = 0;     };     int l, r, c, p;     bool end;     int pos;     int get_coord() {       if (end) return r;       return l;     }   };   bool cmp1(Segment& lhs, Segment& rhs) { return lhs.p < rhs.p; }   bool cmp2(Segment& lhs, Segment& rhs) {     int lhsx = (lhs.end == 1) ? lhs.r : lhs.l;     int rhsx = (rhs.end == 1) ? rhs.r : rhs.l;     if (lhsx == rhsx) return lhs.end < rhs.end;     return lhsx < rhsx;   }   vector<Segment> segs;   bool can(BIT<ll>& bit1, BIT<ll>& bit2, int pos) { return (bit1.get(pos) >= k); }   int main() {     cin >> n >> k >> m;     for (int i = 0; i < m; ++i) {       int l, r, c, p;       scanf( %d%d%d%d , &l, &r, &c, &p);       Segment seg(l, r, c, p);       segs.push_back(seg);     }     sort(segs.begin(), segs.end(), cmp1);     int sz = segs.size();     for (int i = 1; i <= sz; ++i) {       segs[i - 1].pos = i;       a3[i] = segs[i - 1].p;       Segment seg = segs[i - 1];       seg.end = 1;       segs.push_back(seg);     }     sort(segs.begin(), segs.end(), cmp2);     ll sol = 0;     BIT<ll> bit1(a1, m), bit2(a2, m);     int segpos = 0;     for (int i = 1; i <= n; ++i) {       while (segpos < 2 * m &&              (segs[segpos].get_coord() < i ||               (segs[segpos].get_coord() == i && segs[segpos].end == 0))) {         int pos = segs[segpos].pos;         if (segs[segpos].end == 0) {           bit1.upd(pos, segs[segpos].c);           bit2.upd(pos, 1LL * segs[segpos].c * segs[segpos].p);         } else {           bit1.upd(pos, 0);           bit2.upd(pos, 0);         }         segpos++;       }       ll solc = m;       int l = 1, r = m;       while (l <= r) {         int mid = (l + r) / 2;         if (can(bit1, bit2, mid)) {           solc = min(solc, (ll)mid);           r = mid - 1;         } else           l = mid + 1;       }       if (bit1.get(m) < k)         sol += bit2.get(m);       else {         ll diff = bit1.get(solc) - k;         sol += bit2.get(solc) - diff * a3[solc];       }     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   const int INF = 1e9 + 7;   struct Node {     int min, max;     int low, high;     int lcnt, rcnt, cnt;   } st[2000000];   int as[500005];   int query(int w, int L, int R, int& low, int& high) {     if (R - L == 1) {       return as[L] >= low && as[L] <= high;     }     int M = (L + R) / 2;     if (low > st[w].max) return 0;     if (high < st[w].min) return 0;     if (low <= st[w].min && high >= st[w].max) return st[w].cnt;     if (low > st[w].high) {       return query(w * 2 + 1, L, M, low, high);     } else if (high < st[w].low) {       return query(w * 2 + 2, M, R, low, high);     } else {       high = std::max(high, st[w].high);       low = std::min(low, st[w].low);       int res = 0;       int ign1, ign2;       if (high > st[w].high)         res += query(w * 2 + 1, L, M, ign1 = st[w].high + 1, high);       if (low < st[w].low)         res += query(w * 2 + 2, M, R, low, ign2 = st[w].low - 1);       if (low <= st[w].low && high >= st[w].high && st[w].low <= st[w].high)         res++;       return res;     }   }   void pull(int w, int L, int R) {     int ign1, ign2;     assert(R - L > 1);     int M = (L + R) / 2;     st[w].min = std::min(st[w * 2 + 1].min, st[w * 2 + 2].min);     st[w].max = std::max(st[w * 2 + 1].max, st[w * 2 + 2].max);     st[w].high = st[w * 2 + 2].max;     st[w].low = st[w * 2 + 1].min;     query(w * 2 + 1, L, M, st[w].low, st[w].high);     query(w * 2 + 2, M, R, st[w].low, st[w].high);     if (st[w].low <= st[w].high) {       st[w].lcnt = query(w * 2 + 1, L, M, ign1 = st[w].high + 1, ign2 = INF);       st[w].rcnt = query(w * 2 + 2, M, R, ign1 = -INF, ign2 = st[w].low - 1);       st[w].cnt = st[w].lcnt + st[w].rcnt + 1;     } else {       st[w].lcnt = st[w * 2 + 1].cnt;       st[w].rcnt = st[w * 2 + 2].cnt;       st[w].cnt = st[w].lcnt + st[w].rcnt;     }   }   void build(int w, int L, int R, int a, int b) {     if (a >= R || b <= L) return;     if (R - L == 1) {       st[w].min = st[w].max = as[L];       st[w].cnt = 1;     } else {       int M = (L + R) / 2;       build(w * 2 + 1, L, M, a, b);       build(w * 2 + 2, M, R, a, b);       pull(w, L, R);     }   }   void dump(int w, int L, int R) {     int M = (L + R) / 2;     if (R - L > 1) {       printf( [%d,%d): min=%d max=%d low=%d high=%d lcnt=%d rcnt=%d cnt=%d n , L,              R, st[w].min, st[w].max, st[w].low, st[w].high, st[w].lcnt,              st[w].rcnt, st[w].cnt);       dump(w * 2 + 1, L, M);       dump(w * 2 + 2, M, R);     }   }   int main() {     int N, Q;     scanf( %d %d , &N, &Q);     for (int i = 0; i < N; i++) {       scanf( %d , &as[i]);     }     build(0, 0, N, 0, N);     for (int i = 0; i < Q; i++) {       int I, X;       scanf( %d %d , &I, &X);       I--;       as[I] = X;       build(0, 0, N, I, I + 1);       printf( %d n , st[0].cnt);     }   }
#include <bits/stdc++.h>   using namespace std;   const string nameFiles =   ;   void error(vector<string>::iterator) {}   template <typename T, typename... Args>   void error(vector<string>::iterator cur_var, T a, Args... args) {     cerr << cur_var->substr((*cur_var)[0] ==    ) <<   =   << a << endl;     error(++cur_var, args...);   }   vector<string> split(string const& str, char c) {     vector<string> res;     stringstream ss(str);     string x;     while (getline(ss, x, c)) res.emplace_back(x);     return move(res);   }   int main() {     if (!nameFiles.empty()) {       freopen((nameFiles +  .in ).c_str(),  r , stdin);       freopen((nameFiles +  .out ).c_str(),  w , stdout);     }     int n, m;     cin >> n >> m;     vector<int> a(n);     unordered_set<int> mod;     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i] %= m;       if (a[i] == 0) {         cout <<  YES  << endl;         return 0;       }     }     for (int i = 0; i < n; ++i) {       vector<int> ttt;       for (int x : mod) {         int temp = (x + a[i]) % m;         if (temp == 0) {           cout <<  YES  << endl;           return 0;         }         ttt.push_back(temp);       }       mod.insert(ttt.begin(), ttt.end());       mod.insert(a[i]);     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7f7f7f7f;   const int MOD = 1e9 + 7;   const double eps = 1e-6;   int main() {     int n, r, v;     scanf( %d%d%d , &n, &r, &v);     double s = acos(-1.0) * r * 2;     while (n--) {       int a, b;       scanf( %d%d , &a, &b);       double d = b - a;       int c = (d / s);       double len = d - c * s;       double L = 0, R = len;       double mid = (L + R) / 2;       while (R - L >= eps) {         if (mid + 2 * r * sin(mid / 2 / r) >= len)           R = mid;         else           L = mid;         mid = (L + R) / 2;       }       printf( %.12lf n , (c * s + mid) / v);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void write(ostream& out, T t) {     out << t <<   n ;   }   template <typename T, typename... Args>   void write(ostream& out, T t, Args... args) {     out << t <<    ;     write(out, args...);   }   template <typename... Args>   void debug(Args... args) {}   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   const long long modn2 = 10000019;   inline long long mod(long long x) { return x % modn; }   const int MAXK = 1003, MAXQ = 2 * 30004 + 10010;   const int MAXN = MAXQ;   const long long INF = 9000000000LL;   int n, m, k;   vector<pair<long long, int> > s;   long long dp[15009][MAXK];   void prep_cin() {     ios::sync_with_stdio(false);     cin.tie(0);   }   struct qry {     int t, id;   };   vector<qry> q;   int L[MAXN], R[MAXN];   int acu[MAXN];   long long pot[MAXK];   int h;   inline long long f(int h) {     long long res = 0;     long long mx = 0;     for (int a = 1; a <= k; a++) {       mx = mod(max(mx, dp[h][a]));       res = mod(res + mod(mx * pot[a - 1]));     }     return res;   }   inline bool sup(int i, int j, int l, int r) { return (i < l && j > r); }   inline void add(int id) {     h++;     int pes = s[id].second;     long long val = s[id].first;     for (int a = 0; a <= k; a++) {       dp[h][a] = dp[h - 1][a];       if (a >= pes && dp[h - 1][a - pes] != -INF)         dp[h][a] = max(dp[h][a], dp[h - 1][a - pes] + val);     }   }   void go(int i, int j) {     if (i == j) {       if (q[i].t == 3) printf( %lld n , f(h));       return;     }     int m = (i + j) / 2;     if (acu[m] - (i == 0 ? 0 : acu[i - 1]) != 0) {       int old = h;       for (int a = m + 1; a <= j; a++) {         if (q[a].t == 1 || q[a].t == 3) continue;         int id = q[a].id;         if (sup(L[id], R[id], i, m)) add(id);       }       go(i, m);       h = old;     }     if (acu[j] - acu[m] != 0) {       int old = h;       for (int a = i; a <= m; a++) {         if (q[a].t == 2 || q[a].t == 3) continue;         int id = q[a].id;         if (sup(L[id], R[id], m + 1, j)) add(id);       }       go(m + 1, j);       h = old;     }   }   int main() {     scanf( %d%d , &n, &k);     pot[0] = 1;     for (int a = 1; a < k; a++) pot[a] = mod(pot[a - 1] * modn2);     const int inf = 1e7;     for (int a = 0; a < n; a++) {       pair<long long, int> x;       scanf( %lld %d , &x.first, &x.second);       s.push_back(x);       q.push_back({1, a});       L[a] = a;       R[a] = inf;     }     scanf( %d , &m);     for (int a = 0; a < m; a++) {       qry p;       scanf( %d , &p.t);       if (q.size() > 0) acu[q.size()] = acu[q.size() - 1];       if (p.t == 1) {         pair<long long, int> x;         scanf( %lld %d , &x.first, &x.second);         s.push_back(x);         p.id = (int)s.size() - 1;         L[p.id] = q.size();         R[p.id] = inf;       } else if (p.t == 2) {         scanf( %d , &p.id);         p.id--;         R[p.id] = q.size();       } else         acu[q.size()]++;       q.push_back(p);     }     n = s.size();     m = q.size();     for (int a = 0; a <= k; a++) dp[0][a] = -INF;     dp[0][0] = 0;     go(0, m - 1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     for (int tt = 0; tt < t; tt++) {       vector<vector<int> > A(9, vector<int>(9));       for (int i = 0; i < 9; i++) {         int q;         scanf( %d , &q);         for (int j = 0; j < 9; j++) {           A[i][8 - j] = q % 10;           q /= 10;         }       }       A[0][0] = A[0][1];       A[1][3] = A[0][3];       A[2][6] = A[0][6];       A[3][1] = A[3][0];       A[4][4] = A[3][4];       A[5][7] = A[4][7];       A[6][2] = A[6][1];       A[7][5] = A[8][5];       A[8][8] = A[7][7];       for (int i = 0; i < 9; i++) {         for (int j = 0; j < 9; j++) printf( %d , A[i][j]);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, n, k, p;     long long a[50];     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       long long limit = 10e16;       p = 1;       while (p < limit) {         p *= k;       }       if (p > limit) {         p /= k;       }       while (p != 0) {         for (int i = 0; i < n; i++) {           if (a[i] >= p) {             a[i] -= p;             break;           }         }         p /= k;       }       bool checker = true;       for (int i = 0; i < n; i++) {         if (a[i] != 0) {           checker = false;           break;         }       }       if (checker) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, ans = 0;     cin >> n >> a >> b;     vector<int> vec(n);     for (int i = 0; i < n; i++) cin >> vec[i];     for (int i = 0; i < n / 2 + (n % 2); i++) {       if (vec[i] != vec[n - i - 1] && vec[i] != 2 && vec[n - i - 1] != 2) {         cout << -1;         return 0;       }       if (vec[i] == vec[n - i - 1] && vec[i] == 2 && i != n - i - 1) {         ans += 2 * (min(a, b));       } else if (vec[i] == vec[n - i - 1] && vec[i] == 2 && i == n - i - 1) {         ans += min(a, b);       }       if (vec[i] == 1 && vec[n - i - 1] == 2 ||           vec[n - i - 1] == 1 && vec[i] == 2) {         ans += b;       }       if (vec[i] == 0 && vec[n - i - 1] == 2 ||           vec[n - i - 1] == 0 && vec[i] == 2) {         ans += a;       }     }     cout << ans;   }