malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using ll = long long;   const int N = 5e5 + 5;   using namespace std;   int n, m, k;   vector<int> build_kmp(string s, string t, bool check = false) {     vector<int> t_match(((int)t.size()) + 1, 0);     for (int i = (2); i <= (((int)t.size())); ++i) {       int c = t_match[i - 1];       while (c > 0 && t[c] != t[i - 1]) c = t_match[c];       if (t[c] == t[i - 1]) ++c;       t_match[i] = c;     }     vector<int> s_match(((int)s.size()) + 1, 0);     for (int i = (1); i <= (((int)s.size())); ++i) {       int c = s_match[i - 1];       while (c > 0 && t[c] != s[i - 1]) c = t_match[c];       if (t[c] == s[i - 1]) ++c;       if (c == m && check) {         int t = max(i, k);         if (n - t >= k && t - k + 1 <= i - m + 1) {           cout <<  Yes  << endl;           cout << t - k + 1 <<     << t + 1 << endl;           exit(0);         }         t = min(n - k, i - m);         if (t >= k && i <= t + k) {           cout <<  Yes  << endl;           cout << t - k + 1 <<     << t + 1 << endl;           exit(0);         }       }       s_match[i] = c;     }     vector<int> best(((int)t.size()) + 1, -1);     for (int i = (k); i <= (((int)s.size())); ++i) {       int c = s_match[i];       for (; best[c] == -1; c = t_match[c]) best[c] = i;     }     return best;   }   int main() {     string s, t;     cin >> n >> m >> k >> s >> t;     auto L = build_kmp(s, t, true);     reverse((s).begin(), (s).end());     reverse((t).begin(), (t).end());     auto R = build_kmp(s, t);     for (int i = (0); i <= (m); ++i)       if (R[i] != -1) R[i] = n - R[i] + 1;     for (int i = (0); i <= (m); ++i)       if (i <= k && m - i <= k && L[i] != -1 && R[m - i] != -1 &&           L[i] < R[m - i]) {         cout <<  Yes  << endl;         cout << L[i] - k + 1 <<     << R[m - i] << endl;         return 0;       }     cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(m);     int cnt = 0, ma = 0;     for (int i = 0; i < m; ++i) {       cin >> a[i];       cnt += a[i];       ma = max(ma, a[i]);     }     if (cnt < n || 2 * (cnt - ma) < n || (n % 2) && m <= 2) {       cout << -1 << endl;       return 0;     }     set<pair<int, int> > q;     vector<int> res;     for (int i = 0; i < n; ++i) {       int ma = 0, best = 0;       if (i && res[0] != res.back() && a[res[0]] && i + 1 < n) {         best = res[0];       } else {         for (int j = 0; j < m; ++j)           if (res.empty() || j != res.back())             if (i + 1 < n || res[0] != j) {               if (ma < a[j]) {                 ma = a[j];                 best = j;               }             }       }       res.push_back(best);       --a[best];     }     for (int i = 0; i < res.size(); ++i) printf( %d  , res[i] + 1);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TC;     cin >> TC;     while (TC--) {       map<char, int> mp;       string s;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (mp[s[i]] <= 1) mp[s[i]]++;       }       int x1 = 0, x2 = 0;       for (auto i : mp) {         if (i.second == 2) x2++;         if (i.second == 1) x1++;       }       long long ans = (x1 / 2) + x2;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     setlocale(LC_ALL,  RUS );     double r;     cin >> r;     for (double x = 1; x <= 9; x++) {       double y = ((r - 1) / (2 * x)) - ((x + 1) / 2);       if (y == (long long)y && y > 0) {         cout << x <<     << fixed << setprecision(0) << y;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const long long MAXN = 600010;   const long long INF = 2147483600;   long long N, K;   struct data {     long long l, r, id;     bool operator<(const data &a) const {       if (a.l != l) return l < a.l;       return r < a.r;     }   } q[MAXN + 1];   vector<pair<long long, long long> > vec[MAXN + 1];   set<data>::iterator Ers[MAXN + 1];   set<data> S;   long long sum[MAXN + 1], kans, pans;   inline data mdata(long long l, long long r, long long id) {     data n;     n.l = l;     n.r = r;     n.id = id;     return n;   }   inline void check(long long x) {     long long nw = 1, sm = 0;     kans = 0;     pans = 0;     long long sumv = 0;     for (long long i = 1; i <= N; i++) sum[i] = 0;     for (long long i = 1; i <= N; i++) {       long long sumt = 0;       for (long long j = 0, sz = vec[i].size(); j < sz; j++) {         pair<long long, long long> k = vec[i][j];         sum[k.first] += k.second;         sumt += k.second;         if (k.first < nw) sm += k.second, sumv += k.second * (nw - k.first);       }       sum[i + 1] -= sumt;       pans += sumv;       while (nw <= i && sum[nw] + sm >= x)         sm += sum[nw], pans += sm, sumv += sm, ++nw;       kans += nw - 1;     }   }   long long top;   int main() {     N = read();     K = read();     for (long long i = 1; i <= N; i++) {       q[i].l = read(), q[i].r = read() - 1;       q[i].id = i;     }     for (long long i = 1; i <= N; i++) {       set<data>::iterator it = S.upper_bound(q[i]);       data l;       top = 0;       if (S.begin() != it) --it;       if (it == S.end())         l.l = INF;       else         l = (*it);       while (it != S.end()) {         if ((*it).r < q[i].l) {           ++it;           continue;         }         if ((*it).l > q[i].r) break;         Ers[++top] = it;         if ((*it).r >= q[i].r) break;         ++it;       }       data r;       r.r = -1;       if (it != S.end()) r = (*it);       long long last = q[i].l - 1;       for (long long j = 1; j <= top; j++) {         data x = (*Ers[j]);         long long lt = max(x.l, q[i].l), rt = min(x.r, q[i].r);         if (lt > rt) continue;         if (last + 1 != lt) vec[i].push_back(make_pair(1, lt - last - 1));         vec[i].push_back(make_pair(x.id + 1, rt - lt + 1));         last = rt;       }       if (last != q[i].r) vec[i].push_back(make_pair(1, q[i].r - last));       for (long long j = 1; j <= top; j++) S.erase(Ers[j]);       if (l.l < q[i].l && l.r >= q[i].l) S.insert(mdata(l.l, q[i].l - 1, l.id));       if (r.r > q[i].r && r.l <= q[i].r) S.insert(mdata(q[i].r + 1, r.r, r.id));       S.insert(q[i]);     }     long long l = 0, r = 1000000000;     long long ans = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       kans = 0;       check(mid);       if (kans < K)         ans = pans + (mid - 1) * (K - kans), r = mid - 1;       else         l = mid + 1;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int indexp = INT_MAX, indexr = INT_MAX;       int arr[n], brr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] == -1 and indexp == INT_MAX) indexp = i;         if (arr[i] == 1 and indexr == INT_MAX) indexr = i;       }       for (int i = 0; i < n; i++) {         cin >> brr[i];       }       int flag = 0;       for (int i = n - 1; i >= 0; i--) {         if (brr[i] == arr[i])           continue;         else {           if (brr[i] > arr[i]) {             if (i > indexr)               continue;             else {               flag = 1;               break;             }           } else {             if (i > indexp)               continue;             else {               flag = 1;               break;             }           }         }       }       if (flag == 1)         cout <<  NO               <<   n ;       else         cout <<  YES               <<   n ;     }     return (0);   }
#include <bits/stdc++.h>   long long num_div(long long x, long long limit) {     long long ans(0);     for (long long i = 1; i <= sqrt(x); ++i) {       if (!(x % i)) {         if (i > limit && i * i == x)           ans++;         else {           if (i > limit) ans++;           if (x / i > limit) ans++;         }       }     }     return ans;   }   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     if (n == m)       printf( infinity );     else       printf( %lld , n < m ? 0 : num_div(n - m, m));   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   int N;   vector<pair<int, int> > ans;   vector<int> E[maxn];   void go(int i, int t) { ans.push_back({i, t}); }   void dfs(int i, int p, int t) {     go(i, t);     int d = (t < E[i].size());     if (!d) t -= E[i].size(), go(i, t);     for (auto &j : E[i])       if (j != p) {         t++;         dfs(j, i, t);         go(i, t);         if (d && t == E[i].size()) t -= E[i].size(), go(i, t);       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> N;     int u, v;     for (int i = 1; i < N; i++) {       cin >> u >> v;       E[u].push_back(v);       E[v].push_back(u);     }     go(1, 0);     int t = 0;     for (auto &i : E[1]) t++, dfs(i, 1, t), go(1, t);     cout << ans.size() <<   n ;     for (auto &i : ans) cout << i.first <<     << i.second <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200000 + 5], b[200000 + 5], vis[200000 + 5];   int main() {     long long i, j, k;     long long n, m;     long long o = 0, minx = 10005, s = 0;     scanf( %I64d , &n);     for (i = 0; i < n; i++) {       scanf( %I64d , &m);       if (m % 2 == 0)         s += m;       else {         minx = min(minx, m);         s += m;         o++;       }     }     if (minx == 10005) {       cout << 0 << endl;       return 0;     }     if (o % 2)       cout << s << endl;     else       cout << s - minx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   char S[1010];   int E[1010], F[1010][2];   int main() {     scanf( %d , &N);     scanf( %s , S);     memset(E, 0, sizeof(E));     for (int i = 0; i < N; i++) {       E[i + 1] = S[i] -  0 ;       F[i + 1][0] = F[i + 1][1] = 0x3f3f3f3f;     }     F[0][0] = F[0][1] = 0;     for (int i = 1; i <= N; i++)       for (int j = 0; j < 2; j++) {         if (E[i] == j) {           F[i][j] = min(F[i][j], F[i - 1][1 - j]);         } else if (E[i] == 1 - j) {           F[i][j] = min(F[i][j], F[i - 1][E[i]] + 1);         }         if (i - 2 >= 0) {           if (E[i] == E[i - 1]) {             F[i][j] = min(F[i][j], F[i - 2][j] + 1);           } else if (E[i] != E[i - 1]) {             if (E[i] == j)               F[i][j] = min(F[i][j], F[i - 2][j]);             else if (E[i] != j)               F[i][j] = min(F[i][j], F[i - 2][j] + 2);           }         }       }     int ans = min(F[N][0], F[N][1]);     if (ans == 0x3f3f3f3f) ans = -1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, k, i;       cin >> n >> k;       long long a[n], s = INT_MAX, l = INT_MIN;       for (i = 0; i < n; i++) {         cin >> a[i];         s = min(s, a[i]);         l = max(l, a[i]);       }       if (s + k >= l - k)         cout << s + k << endl;       else         cout <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     list<unsigned long long int> blind;     list<unsigned long long int>::iterator bite, tempite;     unsigned long long int total, l, maxarea = 0, sum, i;     cin >> total >> l;     for (i = 0; i < total; ++i) {       cin >> sum;       if (sum >= l) blind.push_back(sum);     }     sum = 1;     while (sum != 0) {       sum = 0;       for (bite = blind.begin(); bite != blind.end();) {         if (*bite < l) {           tempite = bite;           ++bite;           blind.erase(tempite);         } else {           sum += *bite / l;           ++bite;         }       }       if (maxarea < l * sum) maxarea = l * sum;       ++l;     }     cout << maxarea;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long b, q, l, m, a[N];   map<long long, int> vis;   int main() {     scanf( %lld%lld%lld%lld , &b, &q, &l, &m);     while (m--) {       long long x;       scanf( %lld , &x);       vis[x] = 1;     }     if (max(-b, b) > l) {       printf( 0 n );     } else if (b == 0) {       if (vis.count(b) == 0)         printf( inf n );       else         printf( 0 n );     } else {       if (q == 0) {         if (vis.count(0) == 0) {           printf( inf n );         } else {           printf( %d n , !vis.count(b));         }       } else if (q == 1) {         if (vis.count(b) == 0)           printf( inf n );         else           printf( 0 n );       } else if (q == -1) {         if (vis.count(b) == 0 || vis.count(-b) == 0)           printf( inf n );         else           printf( 0 n );       } else {         int ans = 0;         while (max(-b, b) <= l) {           if (vis.count(b) == 0) ans++;           b *= q;         }         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100001];   int res[100001];   vector<vector<pair<int, int> > > g(1e5 + 2);   int check(int v) {     if (dp[v]) {       return dp[v];     }     dp[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       int nxt = g[v][i].first;       if (check(nxt) + 1 > dp[v]) {         dp[v] = dp[nxt] + 1;         res[v] = max(res[nxt], g[v][i].second);       }     }     return dp[v];   }   int main() {     int n, m, v, v1;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> v >> v1;       g[--v].push_back({--v1, i + 1});     }     for (int i = 0; i < n; i++) {       if (check(i) == n) {         cout << res[i];         return 0;       }     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   int a[N];   int vis[N];   int sum[4 * N];   void up(int id, int l, int r, int pos, int val) {     if (l == r) {       sum[id] = val;       return;     }     int mid = l + r >> 1;     if (pos <= mid)       up(id << 1, l, mid, pos, val);     else       up(id << 1 | 1, mid + 1, r, pos, val);     sum[id] = max(sum[id << 1], sum[id << 1 | 1]);   }   int qu(int id, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return sum[id];     int mx = 0;     int mid = l + r >> 1;     if (ql <= mid) mx = max(mx, qu(id << 1, l, mid, ql, qr));     if (qr > mid) mx = max(mx, qu(id << 1 | 1, mid + 1, r, ql, qr));     return mx;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= (n); ++i) cin >> a[i];     int q;     cin >> q;     int h;     int le = 0;     int pre = 0;     for (int i = 1; i <= q; ++i) {       int ty;       cin >> ty;       if (ty == 1) {         int pos, val;         cin >> pos >> val;         vis[pos] = i;         a[pos] = val;       } else {         cin >> h;         up(1, 1, q, i, h);       }     }     for (int i = 1; i <= (n); ++i) {       int le = qu(1, 1, q, vis[i], q);       if (le > a[i])         printf( %d  , le);       else         printf( %d  , a[i]);     }   }
#include <bits/stdc++.h>   int main() {     long long count, number;     long long Totalnumber = 200001;     std::vector<long long> Calresult(Totalnumber);     Calresult[2] = 1;     for (long long i = 3; i <= Totalnumber; i++) {       Calresult[i] = Calresult[i - 1] % 1000000007 * i % 1000000007;     }     std::cin >> count;     while (count--) {       std::cin >> number;       std::cout << Calresult[number * 2] << std::endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2500 + 5;   int n, a[maxn][maxn];   int tot;   struct Data {     int x, y, z;     bool operator<(const Data &a) const { return z < a.z; }   } b[maxn * maxn];   bitset<2505> bt[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         scanf( %d , &a[i][j]), b[++tot] = (Data){i, j, a[i][j]};     for (int i = 1; i <= n; ++i)       if (a[i][i]) puts( NOT MAGIC ), exit(0);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j)         if (a[i][j] != a[j][i]) puts( NOT MAGIC ), exit(0);     sort(b + 1, b + 1 + tot);     for (int i = 1, p = 1; i <= tot; i = p) {       while (b[p].z == b[i].z && p <= tot) {         int x = b[p].x, y = b[p].y;         if ((bt[x] & bt[y]).count()) puts( NOT MAGIC ), exit(0);         p++;       }       for (int j = i; j < p; ++j) bt[b[j].x][b[j].y] = 1;     }     puts( MAGIC );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isValid(string& x, string& y) {     int found = y.find(x);     if (found == string::npos) return false;     for (int i = 0; i < found; ++i) {       if (y[i] ==  0 ) return false;     }     for (int i = found + x.length(); i < y.length(); ++i) {       if (y[i] ==  0 ) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     unsigned long long x, y;     cin >> x >> y;     bitset<64> b1(x);     bitset<64> b2(y);     string xString = b1.to_string();     string yString = b2.to_string();     int index = 0;     while (xString[index] ==  0 ) {       index++;     }     xString = xString.substr(index);     index = 0;     while (yString[index] ==  0 ) {       index++;     }     yString = yString.substr(index);     if (isValid(xString, yString)) {       int temp = yString.find(xString);       if (temp != 0 && xString.back() ==  0  &&           temp + xString.length() == yString.length()) {       } else {         cout <<  YES n ;         return 0;       }     }     index = -1;     for (int i = 0; i < xString.length(); ++i)       if (xString[i] ==  1 ) index = i;     string xNoTrailing = xString.substr(0, index + 1);     if (isValid(xNoTrailing, yString)) {       cout <<  YES n ;       return 0;     }     reverse(xNoTrailing.begin(), xNoTrailing.end());     if (isValid(xNoTrailing, yString)) {       cout <<  YES n ;       return 0;     }     xString.push_back( 1 );     reverse(xString.begin(), xString.end());     if (isValid(xString, yString)) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int y[3], m[3], p[3];   int result;   bool solve(int);   bool if_win(int, int, int);   int main() {     double lb = 0, ub = 0xffffff;     result = 0xfffffff;     scanf( %d%d%d , &y[0], &y[1], &y[2]);     scanf( %d%d%d , &m[0], &m[1], &m[2]);     scanf( %d%d%d , &p[0], &p[1], &p[2]);     if (if_win(0, 0, 0)) {       printf( %d n , 0);       return 0;     }     for (int i = 0; i < 100; i++) {       int mid = (int)((lb + ub) / 2 + 0.5);       if (solve(mid))         ub = mid;       else         lb = mid;       if (lb == ub || ub - lb == 1) break;     }     printf( %d n , result);     return 0;   }   bool solve(int x) {     int i;     int j;     int z;     for (i = x / p[0]; i >= 0; i--) {       for (j = (x - i * p[0]) / p[1]; j >= 0; j--) {         if (y[1] + j < m[2]) break;         for (z = (x - i * p[0] - j * p[1]) / p[2]; z >= 0; z--) {           int prise = p[0] * i + p[1] * j + p[2] * z;           if (if_win(i, j, z)) {             result = min(result, prise);             return true;           }         }       }     }     return false;   }   bool if_win(int i, int j, int z) {     if (y[1] + j <= m[2]) return false;     int time = m[0] / (y[1] + j - m[2]);     if (m[0] % (y[1] + j - m[2]) != 0) time++;     if (y[0] + i - time * (m[1] - y[2] - z) > 0)       return true;     else       return false;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, s, l;   const int mo = 1e9 + 7;   const int inv3 = 333333336;   int a[202020];   int b[202020];   int c[202020];   int sum[202020];   int sum2[202020];   long long gcd_ex(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return 1ll * a;     }     long long d = gcd_ex(b, a % b, y, x);     y = y - a / b * x;     return d;   }   long long solve(long long a, long long b, long long m) {     long long x, y;     long long d = gcd_ex(a, m, x, y);     if (b % d == 0) {       x %= m;       while (x < 0) x += m;       x %= m;       return x * (b / d) % (m / d);     } else {       return m;     }   }   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     cin >> n >> m;     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       sum[i] = (sum[i - 1] + a[i]) % mo;       sum2[i] = (sum2[i - 1] + (1ll * (a[i]) * (a[i]) % mo)) % mo;       b[i] = a[i];       c[i] = i;     }     sort(b + 1, b + n + 1);     sort(c + 1, c + n + 1, cmp);     int r, d, x;     long long aa, ab, ba, bb, mm, ssr, sp, sr;     for (register int i = 1; i <= m; ++i) {       scanf( %d %d %d , &l, &r, &d);       s = r - l + 1;       aa = 1ll * s;       ab = (0ll + mo + sum[r] - sum[l - 1]) % mo;       ba = (1ll * ((1ll * s * (s - 1) / 2) % mo) * d) % mo;       bb = (ab + mo - ba) % mo;       mm = 1ll * mo;       x = solve(aa, bb, mm);       if (b[lower_bound(b + 1, b + n + 1, x) - b] != x) {         printf( No n );         continue;       }       x = c[lower_bound(b + 1, b + n + 1, x) - b];       if (x < l && r < x) {         printf( No n );         continue;       }       x = a[x];       ssr = (0ll + mo + sum2[r] - sum2[l - 1]) % mo;       sr = ((2ll * ba) % mo * x) % mo;       sp = (1ll * ((1ll * (1ll * ba * (2ll * s - 1) % mo) * inv3) % mo) * d) % mo;       sp = (0ll + 1ll * s * (1ll * (x) * (x) % mo) % mo + sp + sr) % mo;       if (ssr != sp) {         printf( No n );         continue;       }       printf( Yes n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int maxn = 10000;   bool is_prime(int x) {     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) return 0;     }     if (x < 2) return 0;     return 1;   }   int main() {     int cc, n;     cin >> cc >> n;     vector<int> a(n);     for (int i = 0; i < cc; i++) {       int x;       cin >> x;       x--;       a[x]++;     }     vector<std::vector<int> > dp(3, std::vector<int>(3, 0));     for (int i = 0; i < n; i++) {       int c = a[i];       vector<std::vector<int> > new_dp(3, std::vector<int>(3, 0));       for (int x = 0; x < 3; x++) {         for (int y = 0; y < 3; y++) {           for (int z = 0; z < 3; z++) {             if (x + y + z <= c) {               new_dp[y][z] =                   max(new_dp[y][z], dp[x][y] + z + (c - x - y - z) / 3);             }           }         }       }       swap(dp, new_dp);     }     cout << dp[0][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (auto &i : a) cin >> i;     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     int ans = INT_MAX, base;     for (int i = 1; i <= 1000; i++) {       int first = i, curr = 0;       for (int j = 0; j < n; j++)         if (a[j] != first + j * k) curr++;       if (curr < ans) base = i, ans = curr;     }     cout << ans <<   n ;     for (int j = 0; j < n; j++) {       int now = base + j * k;       if (a[j] < now)         cout <<  +   << j + 1 <<     << now - a[j] <<   n ;       else if (a[j] > now)         cout <<  -   << j + 1 <<     << a[j] - now <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> a(4 * n);       for (int i = 0; i < 4 * n; i++) cin >> a[i];       sort(a.begin(), a.end());       int area = a[0] * a[4 * n - 1];       int temp = 0;       for (int i = 1; i <= n; i++) {         if ((a[2 * i - 2] != a[2 * i - 1]) ||             (a[4 * n - 2 * i] != a[4 * n - 2 * i + 1]) ||             (a[2 * i - 1 - 1] * a[4 * n - 2 * i + 1] != area)) {           temp = 1;           break;         }       }       if (temp == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }