malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; }   int n;   int inp[100001], p[100001], pc, g[100001], h[100001];   void init() {     inp[0] = inp[1] = 1;     g[1] = 1;     for (int i = 2; i <= (100000); ++i) {       if (!inp[i]) p[++pc] = i, g[i] = 2, h[i] = 1;       for (int j = 1; j <= pc && p[j] * i <= 100000; ++j) {         inp[i * p[j]] = 1;         if (i % p[j])           g[i * p[j]] = g[i] * 2, h[i * p[j]] = 1;         else {           g[i * p[j]] = g[i] / (h[i] + 1) * (h[i] + 2);           h[i * p[j]] = h[i] + 1;           break;         }       }     }   }   int main() {     init();     int T;     scanf( %d , &T);     while (T--) {       int A, B, C;       scanf( %d%d%d , &A, &B, &C);       int f[8];       f[1] = A;       f[2] = B;       f[4] = C;       f[3] = Gcd(A, B);       f[5] = Gcd(A, C);       f[6] = Gcd(B, C);       f[7] = Gcd(A, Gcd(B, C));       long long Ans1 = 0, Ans2 = 0;       for (int S = 1; S <= ((1 << 6) - 1); ++S) {         int X = 0, Y = 0, Z = 0, Cnt = -1;         if (S >> 0 & 1) X |= 1, Y |= 2, Z |= 4, Cnt = -Cnt;         if (S >> 1 & 1) X |= 1, Y |= 4, Z |= 2, Cnt = -Cnt;         if (S >> 2 & 1) X |= 2, Y |= 1, Z |= 4, Cnt = -Cnt;         if (S >> 3 & 1) X |= 2, Y |= 4, Z |= 1, Cnt = -Cnt;         if (S >> 4 & 1) X |= 4, Y |= 1, Z |= 2, Cnt = -Cnt;         if (S >> 5 & 1) X |= 4, Y |= 2, Z |= 1, Cnt = -Cnt;         Ans1 = Ans1 + (long long)Cnt * g[f[X]] * g[f[Y]] * g[f[Z]];         Ans2 = Ans2 +                (long long)Cnt * (g[f[X | Y]] * g[f[Z]] + g[f[X | Z]] * g[f[Y]] +                                  g[f[Y | Z]] * g[f[X]]);       }       long long Ans3 = 2 * g[f[7]];       printf( %lld n , (Ans1 + Ans2 + Ans3) / 6);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct T {     int lz, sz;     int v[2], t[2], f1[2], f2[2];     T(int x = 1) {       lz = 0, sz = x;       for (int i = 0; i < 2; i++) {         v[i] = f1[i] = x;         t[i] = f2[i] = 0;       }     }     void upd() {       for (int i = 0; i < 2; i++) t[i] ^= 1;       swap(v[0], v[1]);       lz ^= 1;     }     friend T operator+(T l, T r) {       T ret(0);       T c[2] = {l, r};       int first = 0, g = 0;       for (int i = 0; i < 2; i++) ret.v[i] = 0;       for (int i = 0; i < 2; i++) {         first += c[i].f1[!i];         g ^= c[i].t[!i];         ret.sz += c[i].sz;         ret.t[i] = c[i].t[i];         if (c[i].f1[i] == c[i].sz) {           if (c[i].t[i] == c[!i].t[i]) {             ret.f1[i] = c[i].f1[i] + c[!i].f1[i];             ret.f2[i] = c[!i].f2[i];           } else {             ret.f1[i] = c[i].f1[i];             ret.f2[i] = c[!i].f1[i];           }         } else {           ret.f1[i] = c[i].f1[i];           ret.f2[i] = c[i].f2[i];           ret.f2[i] +=               (ret.f1[i] + ret.f2[i] == c[i].sz && c[i].t[i] != c[!i].t[i]) *               c[!i].f1[i];         }         for (int j = 0; j < 2; j++)           ret.v[j] = max({ret.v[j], ret.f1[i], ret.f2[i], c[i].v[j]});       }       if (g) {         ret.v[c[0].t[1]] = max(ret.v[c[0].t[1]], first);       } else {         for (int i = 0; i < 2; i++) {           int j = !i ^ c[i].t[!i];           ret.v[j] = max(ret.v[j], first + c[i].f2[!i]);         }       }       return ret;     }   };   struct segTree {     int l, r;     segTree *c[2];     T val;     segTree(int a, int b) {       l = a, r = b;       val.sz = r - l + 1;       if (l != r) {         int mid = (l + r) / 2;         c[0] = new segTree(l, mid);         c[1] = new segTree(mid + 1, r);         val = c[0]->val + c[1]->val;       }     }     T add(int a, int b) {       if (b < l || r < a) return T(0);       if (a <= l && r <= b) {         val.upd();         return val;       }       T ret[2];       for (int i = 0; i < 2; i++) {         if (val.lz) c[i]->val.upd();         ret[i] = c[i]->add(a, b);       }       val = c[0]->val + c[1]->val;       return ret[0] + ret[1];     }   };   const int mxn = 500000;   int n, q;   segTree tre(1, mxn);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       if (c ==  < ) tre.add(i, i);     }     while (q--) {       int l, r;       cin >> l >> r;       cout << tre.add(l, r).v[0] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, Q, Sum, op[100005], X[100005], Y[100005], Ans[100005], Mp[1005][1005],       Lh[1005], Ln[1005];   int lnk[100005], nxt[100005], son[100005], tot;   bool vis[100005], Num[1005];   inline int read() {     int N = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) N = N * 10 + ch -  0 , ch = getchar();     return N;   }   inline void add(int x, int y) {     son[++tot] = y;     nxt[tot] = lnk[x];     lnk[x] = tot;   }   inline void fz(int x) {     Sum += Ln[X[x]] - Lh[X[x]];     Num[X[x]] ^= 1;     swap(Ln[X[x]], Lh[X[x]]);   }   inline void work(int x) {     if (op[x] == 1 && !(Mp[X[x]][Y[x]] ^ Num[X[x]]))       Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++, vis[x] = 1;     if (op[x] == 2 && Mp[X[x]][Y[x]] ^ Num[X[x]])       Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--, vis[x] = 1;     if (op[x] == 3) fz(x);   }   inline void rework(int x) {     if (op[x] == 1 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--;     if (op[x] == 2 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++;     if (op[x] == 3) fz(x);   }   void DFS(int x) {     work(x);     Ans[x] = Sum;     for (int i = lnk[x]; i; i = nxt[i]) DFS(son[i]);     rework(x);   }   int main() {     N = read();     M = read();     Q = read();     for (int i = 1; i <= Q; i++) {       op[i] = read();       X[i] = read();       if (op[i] <= 2) Y[i] = read();       if (op[i] == 4)         add(X[i], i);       else         add(i - 1, i);     }     for (int i = 1; i <= N; i++) Ln[i] = M;     DFS(0);     for (int i = 1; i <= Q; i++) printf( %d n , Ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int K;   long long p[21], a[21], aLeft[21];   long long N, Nq3;   long long minArea = 3000000000000000000LL;   long long ansA, ansB, ansC;   long long curA;   long long leftMul[21];   long long BCq, BC, nowBest;   void dfs2(int cur, long long carry) {     if (carry * leftMul[cur] < BCq) return;     if (carry > nowBest) return;     if (carry >= BCq) {       nowBest = carry;       return;     }     if (cur == K + 1) return;     dfs2(cur + 1, carry);     for (int i = 1; i <= aLeft[cur]; i++) {       carry *= p[cur];       dfs2(cur + 1, carry);     }   }   void calc(long long _curA) {     nowBest = 3000000000000000000LL;     curA = _curA;     BC = N / curA;     double each = sqrt(double(BC));     if (curA * 2 * each + BC > minArea + 10) return;     leftMul[K + 1] = 1;     for (int i = K; i >= 1; i--) {       leftMul[i] = leftMul[i + 1];       for (int j = 1; j <= aLeft[i]; j++) leftMul[i] *= p[i];     }     BCq = sqrt(double(BC - 1));     while (BCq * BCq < BC) BCq++;     dfs2(1, 1);     long long curB = nowBest, curC = BC / curB;     if (curA * (curB + curC) + BC < minArea) {       minArea = curA * (curB + curC) + BC;       ansA = curA;       ansB = curB;       ansC = curC;     }   }   void dfs(int cur, long long carry) {     if (cur == K + 1)       calc(carry);     else {       aLeft[cur] = a[cur];       dfs(cur + 1, carry);       for (int i = 1; i <= a[cur]; i++) {         carry *= p[cur];         if (carry > Nq3) return;         aLeft[cur] = a[cur] - i;         dfs(cur + 1, carry);       }     }   }   void solve() {     minArea = 3000000000000000000LL;     for (int iteration = 1; iteration <= K; iteration++)       for (int i = 1; i < K; i++)         if (p[i] < p[i + 1]) {           swap(p[i], p[i + 1]);           swap(a[i], a[i + 1]);         }     N = 1;     for (int i = 1; i <= K; i++)       for (int j = 1; j <= a[i]; j++) N *= p[i];     Nq3 = pow(double(N - 1), 1 / 3.0);     while (Nq3 * Nq3 * Nq3 < N) Nq3++;     dfs(1, 1);     cout << 2 * minArea <<     << ansA <<     << ansB <<     << ansC << endl;   }   int main() {     ios ::sync_with_stdio(false);     int TestCase;     cin >> TestCase;     for (int CaseID = 1; CaseID <= TestCase; CaseID++) {       cin >> K;       for (int i = 1; i <= K; i++) cin >> p[i] >> a[i];       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string bus[7];     bus[0] =  +------------------------+ ;     bus[1] =  |#.#.#.#.#.#.#.#.#.#.#.|D|) ;     bus[2] =  |#.#.#.#.#.#.#.#.#.#.#.|.| ;     bus[3] =  |#.......................| ;     bus[4] =  |#.#.#.#.#.#.#.#.#.#.#.|.|) ;     bus[5] =  +------------------------+ ;     if (n == 0) {       for (int i = 0; i < 6; i++) cout << bus[i] << endl;       return 0;     }     int curRow = 1;     if (n == 1) {       bus[1][1] =  O ;     } else if (n == 2) {       bus[1][1] =  O ;       bus[2][1] =  O ;     } else if (n == 3) {       bus[1][1] =  O ;       bus[2][1] =  O ;       bus[3][1] =  O ;     } else if (n == 4) {       bus[1][1] =  O ;       bus[2][1] =  O ;       bus[3][1] =  O ;       bus[4][1] =  O ;     } else {       bus[1][1] =  O ;       bus[2][1] =  O ;       bus[3][1] =  O ;       bus[4][1] =  O ;       n -= 4;       while (n != 0) {         curRow += 2;         if (n >= 3) {           bus[1][curRow] =  O ;           bus[2][curRow] =  O ;           bus[4][curRow] =  O ;           n -= 3;         } else if (n == 2) {           bus[1][curRow] =  O ;           bus[2][curRow] =  O ;           n -= 2;         } else if (n == 1) {           bus[1][curRow] =  O ;           n -= 1;         } else {         }       }     }     for (int i = 0; i < 6; i++) cout << bus[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, string> > vc[100010];   vector<string> vc1[100010];   bool comp(pair<int, string> a, pair<int, string> b) {     return a.first > b.first;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       int a, b;       cin >> s >> a >> b;       vc[a].push_back(make_pair(b, s));     }     for (int i = 1; i <= m; i++) {       sort(vc[i].begin(), vc[i].end(), comp);     }     for (int i = 1; i <= m; i++) {       if (vc[i].size() == 2) {         for (int j = 0; j < vc[i].size(); j++) {           vc1[i].push_back(vc[i][j].second);         }       } else if (vc[i].size() == 1) {         for (int j = 0; j < vc[i].size(); j++) {           vc1[i].push_back(vc[i][j].second);         }       } else if (vc[i].size() > 2) {         if (vc[i][1].first == vc[i][2].first) {           vc1[i].push_back( ? );         } else {           for (int j = 0; j < 2; j++) {             vc1[i].push_back(vc[i][j].second);           }         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 0; j < vc1[i].size(); j++) {         cout << vc1[i][j];         if (j < vc1[i].size() - 1) cout <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 1e6 + 1;   const long long int modn = 1e9 + 7;   long long int T, len, num, gav, ver, x, maxi, sum, fir, sec, out, th;   vector<long long int> vec[maxn];   bool is_use[maxn];   long long int all[maxn];   void dfs(long long int x) {     is_use[x] = true;     sum++;     for (int i = 0; i < vec[x].size(); i++) {       ver = vec[x][i];       if (is_use[ver] == false) dfs(ver);     }     return;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> len >> num >> gav;     for (int i = 1; i <= gav; i++) cin >> all[i];     for (int i = 1; i <= num; i++) {       cin >> fir >> sec;       vec[fir].push_back(sec);       vec[sec].push_back(fir);     }     for (int i = 1; i <= gav; i++) {       sum = 0;       dfs(all[i]);       out += (sum * (sum - 1)) / 2;       maxi = max(maxi, sum);     }     sum = 0;     for (int i = 1; i <= len; i++) {       if (is_use[i] == false) sum++;     }     out += (sum * (sum - 1)) / 2 + sum * maxi;     cout << out - num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[10][10], b[10][10];   int n, ok[8];   struct matrix {     char m[10][10];   } v[7];   int main() {     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> b[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         v[0].m[j][n - i - 1] = v[1].m[n - i - 1][n - j - 1] =             v[2].m[n - j - 1][i] = v[3].m[i][n - j - 1] =                 v[4].m[n - j - 1][n - i - 1] = v[5].m[n - i - 1][j] =                     v[6].m[j][i] = b[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (a[i][j] != b[i][j]) ok[0] = 1;         if (a[i][j] != v[0].m[i][j]) ok[1] = 1;         if (a[i][j] != v[1].m[i][j]) ok[2] = 1;         if (a[i][j] != v[2].m[i][j]) ok[3] = 1;         if (a[i][j] != v[3].m[i][j]) ok[4] = 1;         if (a[i][j] != v[4].m[i][j]) ok[5] = 1;         if (a[i][j] != v[5].m[i][j]) ok[6] = 1;         if (a[i][j] != v[6].m[i][j]) ok[7] = 1;       }     if (ok[0] && ok[1] && ok[2] && ok[3] && ok[4] && ok[5] && ok[6] && ok[7])       cout <<  No ;     else       cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x = 0, y = 0;     cin >> n >> m;     x = max(m, n);     for (int a = 0; a <= x; a++) {       for (int b = 0; b <= x; b++) {         if ((a * a) + b == n && (b * b) + a == m) {           y++;         }       }     }     cout << y << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long POW(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b & 1) return (a * POW(a, b - 1)) % 1000000007;     long long t = POW(a, b / 2);     return (t * t) % 1000000007;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1};   int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};   map<int, int> M;   map<int, int>::iterator it, it2;   int main() {     int n, q;     scanf( %d%d , &n, &q);     M[0] = 0;     M[1000000007] = 1000000007;     M[1] = n;     int ans = n;     while (q--) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       if (k == 1) {         it = M.upper_bound(r);         it--;         while (it != M.begin()) {           it2 = it;           it--;           int L = it2->first, R = it2->second;           if (l <= R) {             M.erase(it2);             ans -= R - L + 1;           }           if (L <= r && R > r) {             M[r + 1] = R;             ans += R - r;           }           if (L < l && R >= l) {             M[L] = l - 1;             ans += l - L;           }           if (L <= l) break;         }       } else {         it = M.upper_bound(r);         it--;         int L = 1000000007, R = -1;         while (it != M.begin()) {           it2 = it;           it--;           if (it2->second < l) break;           L = min(L, it2->first), R = max(R, it2->second);           ans -= it2->second - it2->first + 1;           M.erase(it2);         }         M[min(l, L)] = max(r, R);         ans += max(r, R) - min(l, L) + 1;       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   #pragma GCC optimize  O3,no-stack-protector    using namespace std;   const int MAXN = 1e5 + 7;   vector<int> G[MAXN];   bool blo[MAXN];   short odw[MAXN];   bool tried[MAXN];   int n, m;   bool dfs(int v) {     if (blo[v] == true) return false;     odw[v] = 1;     for (auto w : G[v]) {       if (odw[w] == 0) {         if (dfs(w)) return true;       } else if (odw[w] == 1) {         for (int i = 1; i <= n; i++) {           if (odw[i] != 1) tried[i] = true;         }         return true;       }     }     odw[v] = 2;     return false;   }   bool check() {     for (int i = 1; i <= n; i++) {       odw[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (!odw[i]) {         if (dfs(i)) return false;       }     }     return true;   }   inline double elapsed() { return clock() / (double)CLOCKS_PER_SEC; }   int main(int argc, char **argv) {     srand(15061994);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       G[a].emplace_back(b);     }     vector<int> KAN;     for (int i = 1; i <= n; i++) {       KAN.push_back(i);     }     random_shuffle(KAN.begin(), KAN.end());     for (int i = 0; elapsed() <= 0.95 and i < int(KAN.size()); i++) {       blo[KAN[i]] = true;       if (!tried[KAN[i]] and check()) {         cout << KAN[i] <<   n ;         exit(0);       }       blo[KAN[i]] = false;     }     cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int mod = 1e9 + 7;   long long power(int a, long long b) {     if (b == 0LL) return 1LL;     long long tmp = power(a, b / 2);     if (b & 1LL) return (tmp * tmp % mod) * a % mod;     return tmp * tmp % mod;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     cout << 6 * power(4, (1LL << n) - 2) % mod;   }
#include <bits/stdc++.h>   struct M {     int p, b;   };   struct F {     const int p, i;     int r, c;     F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {}     int t() { return r - p; }   };   void solve(std::vector<F> &fs, std::vector<M> &ms) {     std::multimap<int, int> ms_landed;     std::map<int, F *> fs_active;     {       std::vector<F *> fs_sort;       fs_sort.reserve(fs.size());       for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]);       std::sort(fs_sort.begin(), fs_sort.end(),                 [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; });       fs_active.insert({fs_sort[0]->p, fs_sort[0]});       int curr = fs_sort[0]->r;       for (int i = 1; i < fs_sort.size(); i++) {         F &f = *fs_sort[i];         if (f.r > curr) {           int l = std::max(curr + 1, f.p);           curr = f.r;           fs_active.insert({l, &f});         }       }     }     auto update = [&](F &f, std::map<int, F *>::iterator &f_succ, const int &b) {       f.c++;       f.r += b;       while (f_succ != fs_active.end()) {         int l_succ = f_succ->first;         int r_succ = f_succ->second->r;         if (f.r < r_succ) {           if (f.r >= l_succ) {             f_succ = fs_active.insert(fs_active.erase(f_succ),                                       {f.r + 1, f_succ->second});           }           break;         }         f_succ = fs_active.erase(f_succ);       }     };     for (const M &m : ms) {       auto f_it = --fs_active.upper_bound(m.p);       const int l = f_it->first;       F &f = *f_it->second;       if (l <= m.p && m.p <= f.r) {         update(f, ++f_it, m.b);         auto m_it = ms_landed.lower_bound(l);         while (m_it != ms_landed.end()) {           M m{m_it->first, m_it->second};           if (l <= m.p && m.p <= f.r) {             update(f, f_it, m.b);             m_it = ms_landed.erase(m_it);           } else {             break;           }         }       } else {         ms_landed.insert({m.p, m.b});       }     }     for (F &f : fs) {       printf( %d %d n , f.c, f.t());     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     std::vector<F> fs;     fs.reserve(n);     std::vector<M> ms;     ms.reserve(m);     for (int i = 0; i < n; i++) {       int p, t;       scanf( %d%d , &p, &t);       fs.push_back({p, t, i});     }     for (int i = 0; i < m; i++) {       int p, b;       scanf( %d%d , &p, &b);       ms.push_back({p, b});     }     solve(fs, ms);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 1000006, INF = 1000000009;   int n;   int a[N];   int dp[N][2];   int p[N][2];   void minh(int& x, int& px, int y, int u) {     if (y < x) {       x = y;       px = u;     }   }   bool solv() {     dp[1][0] = dp[1][1] = -INF;     for (int i = 2; i <= n; ++i) dp[i][0] = dp[i][1] = INF;     for (int i = 1; i < n; ++i) {       if (a[i] < a[i + 1]) {         minh(dp[i + 1][0], p[i + 1][0], dp[i][0], 0);       }       if (dp[i][0] < a[i + 1]) {         minh(dp[i + 1][0], p[i + 1][0], a[i], 0);       }       if (dp[i][0] < -a[i + 1]) {         minh(dp[i + 1][1], p[i + 1][1], a[i], 0);       }       if (-a[i] < a[i + 1]) {         minh(dp[i + 1][0], p[i + 1][0], dp[i][1], 1);       }       if (-a[i] < -a[i + 1]) {         minh(dp[i + 1][1], p[i + 1][1], dp[i][1], 1);       }       if (dp[i][1] < a[i + 1]) {         minh(dp[i + 1][0], p[i + 1][0], -a[i], 1);       }       if (dp[i][1] < -a[i + 1]) {         minh(dp[i + 1][1], p[i + 1][1], -a[i], 1);       }     }     if (dp[n][0] != INF || dp[n][1] != INF) {       int u;       if (dp[n][0] != INF)         u = 0;       else         u = 1;       for (int i = n; i >= 1; --i) {         if (u == 1) a[i] *= -1;         u = p[i][u];       }       cout <<  YES n ;       for (int i = 1; i <= n; ++i) cout << a[i] <<    ;       cout <<   n ;       return true;     }     cout <<  NO n ;     return false;   }   bool solv0() {     for (int x = 0; x < (1 << n); ++x) {       for (int i = 1; i <= n; ++i) {         if ((x & (1 << (i - 1)))) a[i] *= -1;       }       bool z = true;       for (int i = 1; i <= n; ++i) {         for (int j = i + 1; j <= n; ++j) {           for (int k = j + 1; k <= n; ++k) {             if (a[i] > a[j] && a[j] > a[k]) {               z = false;               break;             }           }           if (!z) break;         }         if (!z) break;       }       if (z) {         return true;         for (int i = 1; i <= n; ++i) {           if ((x & (1 << (i - 1)))) a[i] *= -1;         }         return true;       }       for (int i = 1; i <= n; ++i) {         if ((x & (1 << (i - 1)))) a[i] *= -1;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int tt = 100;     cin >> tt;     while (tt--) {       cin >> n;       for (int i = 1; i <= n; ++i) cin >> a[i];       solv();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string text;   map<int, int> cache;   string to_bin(int v) {     string res =   ;     for (int i = 128; i >= 1; i /= 2) {       if (v - i >= 0) {         res +=  1 ;         v -= i;       } else {         res +=  0 ;       }     }     return move(res);   }   int reverse_bin(int v) {     if (cache.count(v)) {       return cache[v];     }     int res = 0;     string bin = to_bin(v);     for (int i = 0, k = 1; i < 8; ++i, k *= 2) {       if (bin[i] ==  1 ) {         res += k;       }     }     cache[res] = v;     cache[v] = res;     return res;   }   int intercal(int prev, int ch) {     int rprev = reverse_bin(prev);     int rch = reverse_bin(ch);     return (256 - rch + rprev) % 256;   }   int main() {     getline(cin, text);     cout << intercal(0, (int)text[0]) << endl;     for (int i = 1; i < text.size(); ++i) {       cout << intercal((int)text[i - 1], (int)text[i]) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, i, j, k, p, c, x, m, a, b, d, y, t;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       x = (a - b) * n;       y = (a + b) * n;       if ((y < (c - d)) || (x > (c + d)))         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }