malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     queue<int> r, d;     char c;     for (int i = 0; i < n; i++) {       cin >> c;       if (c ==  D )         d.push(i);       else         r.push(i);     }     while (r.size() != 0 && d.size() != 0) {       if (r.front() < d.front()) {         d.pop();         r.push(r.front() + n);         r.pop();       } else {         r.pop();         d.push(d.front() + n);         d.pop();       }     }     if (r.size() == 0)       cout <<  D n ;     else       cout <<  R n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 310;   int l[maxn], c[maxn];   int n;   int f[1 << 9];   int g[maxn][10], cnt[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i];     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) {       int x = l[i];       for (int j = 2; j * j <= x; j++) {         if (x % j == 0) {           g[i][++cnt[i]] = j;           while (x % j == 0) x /= j;         }       }       if (x > 1) {         g[i][++cnt[i]] = x;       }     }     int ans = 1e9 + 10;     for (int i = 1; i <= n; i++) {       memset(f, 0x3f, sizeof f);       int tot = (1 << cnt[i]) - 1;       f[tot] = c[i];       for (int j = 1; j <= n; j++) {         if (i == j) continue;         int s = 0;         for (int k = 1; k <= cnt[i]; k++) {           int flag = 0;           for (int x = 1; x <= cnt[j]; x++) {             if (g[i][k] == g[j][x]) {               flag = 1;               break;             }           }           if (flag) s |= (1 << (k - 1));         }         for (int k = 0; k <= tot; k++) f[k & s] = min(f[k & s], f[k] + c[j]);       }       ans = min(ans, f[0]);     }     if (ans == 1e9 + 10)       cout << -1;     else       cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 * 3 + 10;   int n, k, m;   vector<int> graph[2][MAXN];   int p[2][MAXN];   int sum;   void read_input() {     scanf( %d , &n);     scanf( %d , &k);     int v;     for (int i = 0; i < k - 1; i++) {       sum++;       scanf( %d , &v);       graph[0][n + i + 2].push_back(v + n);       graph[0][v + n].push_back(n + i + 2);       p[0][n + i + 2] = v + n;     }     for (int i = 0; i < n; i++) {       scanf( %d , &v);       graph[0][i + 1].push_back(v + n);       graph[0][v + n].push_back(i + 1);       p[0][i + 1] = n + v;     }     scanf( %d , &m);     for (int i = 0; i < m - 1; i++) {       sum++;       scanf( %d , &v);       graph[1][n + i + 2].push_back(v + n);       graph[1][v + n].push_back(n + i + 2);       p[1][n + i + 2] = v + n;     }     for (int i = 0; i < n; i++) {       scanf( %d , &v);       graph[1][i + 1].push_back(v + n);       graph[1][v + n].push_back(i + 1);       p[1][i + 1] = n + v;     }   }   int timer;   int in[2][MAXN], out[2][MAXN];   int depth[2][MAXN];   void dfs(int v, int p, int r, int dt = 0) {     in[r][v] = timer++;     depth[r][v] = dt;     for (auto x : graph[r][v]) {       if (in[r][x] == 0 && x != p) {         dfs(x, v, r, dt + 1);       }     }     out[r][v] = timer++;   }   int lca[2][MAXN][MAXN];   const int INF = 1e9;   int _abs(int f) {     if (f < 0) return -f;     return f;   }   int T[MAXN][MAXN];   int rec(int l, int r) {     int temp = max(l, r) + 1;     if (temp > n) return 0;     if (T[l][r]) return T[l][r];     int ans = INF;     int add = 0;     if (l != 0) {       int LCA = lca[0][l][temp];       add = _abs(depth[0][LCA] - depth[0][temp]) - 1;       ans = min(ans, rec(temp, r) + add);     } else {       ans = rec(temp, r) + depth[0][temp] - 1;     }     if (r != 0) {       int LCA = lca[1][r][temp];       add = _abs(depth[1][LCA] - depth[1][temp]) - 1;       ans = min(ans, rec(l, temp) + add);     } else {       ans = min(ans, rec(l, temp) + depth[1][temp] - 1);     }     return T[l][r] = ans;   }   void solve() {     timer = 1;     dfs(n + 1, n + 1, 0);     for (int i = 0; i < n; i++) {       int temp = i + 1;       int LCA = temp;       for (int j = i + 1; j < n; j++) {         int tr = j + 1;         while (in[0][tr] > out[0][LCA] || out[0][tr] < in[0][LCA])           LCA = p[0][LCA];         lca[0][temp][tr] = lca[0][tr][temp] = LCA;       }     }     timer = 1;     dfs(n + 1, n + 1, 1);     for (int i = 0; i < n; i++) {       int temp = i + 1;       int LCA = temp;       for (int j = i + 1; j < n; j++) {         int tr = j + 1;         while (in[1][tr] > out[1][LCA] || out[1][tr] < in[1][LCA])           LCA = p[1][LCA];         lca[1][temp][tr] = lca[1][tr][temp] = LCA;       }     }     printf( %d n , sum - rec(0, 0));   }   int main() {     read_input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     if (n > 1) sort(a, a + n);     int cont = 0;     if (k == n) {       cout << a[k - 1] <<   n ;     } else if (k == 0) {       if (a[0] - 1 >= 1)         cout << a[0] - 1 << endl;       else         puts( -1 );     } else {       k--;       if (a[k] == a[k + 1])         cout << -1 << endl;       else         cout << a[k] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long v[N];   signed main() {     long long n;     cin >> n;     long long p = 2 * n;     long long x = p * (p + 1);     if (x % 4 == 0)       cout <<  NO n ;     else {       cout <<  YES n ;       for (long long i = 1; i <= 2 * n; i++) v[i] = i;       for (long long i = 1; i <= n; i++) {         if (i & 1) {           cout << 2 * i - 1 <<    ;           v[2 * i - 1] = 0;         } else {           cout << 2 * i <<    ;           v[2 * i] = 0;         }       }       for (long long i = 1; i <= 2 * n; i++)         if (v[i] != 0) cout << v[i] <<    ;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   const int Maxn = 505;   const int Maxk = 11;   const int Maxd = 10;   const int Inf = 1000000000;   int n, k;   string s;   int w;   struct trie {     trie *ch[Maxd];     int cnt;     trie() {       for (int i = 0; i < Maxd; i++) ch[i] = nullptr;       cnt = 0;     }   };   trie *tr;   void Add(trie *tr, int lvl, const string &s, int add) {     if (lvl >= s.length()) {       tr->cnt += add;       return;     }     int dig = s[lvl] -  0 ;     if (!tr->ch[dig]) tr->ch[dig] = new trie();     Add(tr->ch[dig], lvl + 1, s, add);   }   void Solve(trie *tr, int lvl, int dp[][Maxk]) {     for (int i = 0; i <= lvl; i++) {       for (int j = 0; j <= k; j++) dp[i][j] = Inf;       dp[i][0] = (lvl - i) * tr->cnt;     }     int my[Maxk];     for (int j = 0; j <= k; j++) my[j] = Inf;     my[1] = 0;     int oth[Maxn][Maxk];     for (int i = 0; i < Maxd; i++)       if (tr->ch[i]) {         Solve(tr->ch[i], lvl + 1, oth);         for (int l = 0; l <= lvl; l++)           for (int j = k; j >= 0; j--) {             int ways = dp[l][j];             dp[l][j] = Inf;             for (int z = 0; j + z <= k; z++)               dp[l][j + z] = min(dp[l][j + z], ways + oth[l][z]);           }         for (int j = k; j > 0; j--) {           int ways = my[j];           my[j] = Inf;           for (int z = 0; j + z <= k; z++)             my[j + z] = min(my[j + z], ways + oth[lvl][z]);         }       }     for (int i = 0; i <= lvl; i++)       for (int j = 0; j <= k; j++) dp[i][j] = min(dp[i][j], my[j]);   }   int main() {     tr = new trie();     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> s >> w;       Add(tr, 0, s, w);     }     int dp[Maxn][Maxk];     Solve(tr, 0, dp);     int res = Inf;     for (int j = 0; j <= k; j++) res = min(res, dp[0][j]);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, w, r, k, i, j, s, q, x, y, l, a[22000];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i], s += a[i];       if (a[i] < 0) k = 1;     }     if (k == 0) {       cout << s;       return 0;     }     for (l = 2; l <= n; l++)       if (n % l == 0 && n / l >= 3)         for (j = 1; j <= l; j++) {           m = 0;           for (i = j; i <= n; i += l) m += a[i];           s = max(s, m);         }     cout << s;   }
#include<bits/stdc++.h>   using namespace std;   int main()   {    long long t,n,x;    cin>>t;    while(t--)    {     cin>>n>>x;     long long a[n+1],m=30,j,s=0,k,c;     for (long long i = 0; i < n; ++i)     {      cin>>a[i];      k=a[i];      c=0;      while(k%x==0)      {       k/=x;       c++;      }      if (m>c)       m=c,j=i;     }     //cout<<m<<   <<j<<endl;     for (long long i = 0; i < n; ++i)     {      s+=(m+1)*a[i];     }     for (long long i = 0; i < j; ++i)     {      s+=a[i];     }     cout<<s<<endl;    }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2005;   int n, m, k, l[MAXN][MAXN], r[MAXN][MAXN];   char S[MAXN];   int a[MAXN][MAXN], dp[MAXN][MAXN], x[MAXN], y[MAXN], ans[MAXN];   void clr(int i) {     for (int j = 1; j <= m; ++j) l[i][j] = a[i][j] ? 0 : l[i][j - 1] + 1;     for (int j = m; j >= 1; --j) r[i][j] = a[i][j] ? 0 : r[i][j + 1] + 1;   }   int solve() {     int re = 0;     for (int i = 1; i <= n; ++i) clr(i);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (!a[i][j]) {           dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;           re = max(re, dp[i][j]);         }     return re;   }   int v[2][MAXN], q[2][MAXN], s[2], t[2];   inline void del(int p) {     while (s[0] < t[0] && q[0][s[0]] <= p) ++s[0];     while (s[1] < t[1] && q[1][s[1]] <= p) ++s[1];   }   inline void ins(int i) {     while (s[0] < t[0] && v[0][q[0][t[0] - 1]] >= v[0][i]) --t[0];     q[0][t[0]++] = i;     while (s[1] < t[1] && v[1][q[1][t[1] - 1]] >= v[1][i]) --t[1];     q[1][t[1]++] = i;   }   bool calc(int j, int len) {     for (int i = 1; i <= n; ++i) v[0][i] = l[i][j], v[1][i] = r[i][j];     s[0] = s[1] = t[0] = t[1] = 0;     q[0][0] = q[1][0] = 0;     for (int i = 1, p = 0; i <= n; ++i) {       while (i - p >= len) del(p++);       ins(i);       if (i >= len && v[0][q[0][s[0]]] + v[1][q[1][s[1]]] - 1 >= len) return 1;     }     return 0;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       scanf( %s , S + 1);       for (int j = 1; j <= m; ++j) a[i][j] = S[j] ==  X ;     }     for (int i = 1; i <= k; ++i) scanf( %d%d , &x[i], &y[i]), a[x[i]][y[i]] = 1;     ans[k] = solve();     for (int i = k; i > 1; --i) {       a[x[i]][y[i]] = 0;       clr(x[i]);       for (ans[i - 1] = ans[i]; calc(y[i], ans[i - 1] + 1); ++ans[i - 1])         ;     }     for (int i = 1; i <= k; ++i) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   void setIO(string name =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (!name.empty()) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   long long calc(long long a, long long b) { return (a + a * b) * b / 2; }   int main() {     setIO();     long long a, b;     cin >> a >> b;     if (b == 1) {       cout << a;       return 0;     }     long long cur;     if (b % 2)       cur = (b + 1) / 2 * b;     else       cur = b / 2 * (b + 1);     if (a <= b || a < cur || b >= 400000) {       cout << -1;       return 0;     }     vector<long long> divs;     for (long long i = 1; i * i <= a; i++) {       if (a % i == 0) {         if (i == a / i)           divs.push_back(i);         else {           divs.push_back(i);           divs.push_back(a / i);         }       }     }     sort(divs.begin(), divs.end());     for (int i = (int)divs.size() - 1; i >= 0; i--) {       if (calc(divs[i], b) <= a && (calc(divs[i], b) % divs[i] == 0)) {         long long cur = divs[i];         for (int j = 1; j <= b; j++) {           if (j != b) {             cout << cur * j <<    ;             a -= cur * j;           } else {             cout << a;             return 0;           }         }       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 2;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     srand(time(NULL));     int N;     long long sa = 0, sb = 0;     cin >> N;     vector<int> A(N), B(N), ind(N);     iota(ind.begin(), ind.end(), 0);     for (int i = 0; i < N; ++i) {       cin >> A[i];       sa += A[i];     }     for (int i = 0; i < N; ++i) {       cin >> B[i];       sb += B[i];     }     int ok = (N >> 1) + 1;     while (1) {       mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());       long long x = 0, y = 0;       random_shuffle(ind.begin(), ind.end());       for (int i = 0; i < ok; ++i) {         x += A[ind[i]];         y += B[ind[i]];       }       if (x << 1LL > sa && y << 1LL > sb) {         cout << ok <<   n ;         for (int i = 0; i < ok; ++i) {           cout << ind[i] + 1 <<    ;         }         exit(0);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool lucky(int n) {     n = abs(n);     if (n == 8) return true;     while (n) {       int x = n % 10;       if (x == 8) return true;       n /= 10;     }     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= 100; i++) {       int x = n + i;       if (lucky(x)) {         printf( %d n , i);         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   const int N = 2e5 + 10;   int a[N];   map<int, long long> mp;   signed main() {     int _;     read(_);     while (_--) {       mp.clear();       int n;       read(n);       long long s = 0, ans = 0;       for (int i = (1); i <= (n); i++) read(a[i]), s += a[i], mp[a[i]]++;       if (s * 2 % n != 0) {         puts( 0 );         continue;       }       long long mid = s * 2 / n;       for (int i = (1); i <= (n); i++)         if (a[i] < mid - a[i]) ans += mp[mid - a[i]];       if (mid % 2 == 0) ans += mp[mid / 2] * (mp[mid / 2] - 1) / 2;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[2005], c[2005];   int n, root = -1;   vector<int> v[2005];   int d[2005], vis[2005];   int ans[2005];   struct cmp {     bool operator()(int x, int y) { return d[x] > d[y]; }   };   priority_queue<int, vector<int>, cmp> q;   void dfs(int x) {     if (c[x] == 0) q.push(x);     for (auto y : v[x]) {       if (vis[y]) continue;       vis[y] = 1;       d[y] = d[x] + 1;       dfs(y);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i] >> c[i];       if (!p[i]) {         root = i;         continue;       }       v[i].push_back(p[i]);       v[p[i]].push_back(i);     }     vis[root] = 1;     dfs(root);     bool flag = true;     int count = 1;     while (!q.empty()) {       int _top = q.top();       q.pop();       ans[_top] = count++;       int head = p[_top];       while (head) {         c[head]--;         if (c[head] == 0) q.push(head);         head = p[head];       }     }     for (int i = 1; i <= n; i++) {       if (c[i] > 0) {         flag = false;         break;       }     }     if (flag) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << ans[i] <<    ;       cout << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     vector<pair<int, int> > g;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       g.push_back(make_pair(a, b));     }     sort(g.begin(), g.end());     int mx = 0, ans = 0;     for (int i = 0; i < n; i++) {       if (g[i].second < mx) ans++;       mx = max(mx, g[i].second);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int spf[15000005], ans[15000002];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 15000002; i++) spf[i] = i;     for (int i = 4; i < 15000002; i += 2) spf[i] = 2;     for (int i = 3; i * i < 15000002; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 15000002; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   int main() {     int i, n, ans1 = 1, k = 0;     scanf( %d , &n);     int a[300005];     sieve();     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     ans1 = a[1];     for (i = 1; i <= n; i++) ans1 = gcd(ans1, a[i]);     for (i = 1; i <= n; i++) a[i] = (a[i] / ans1);     for (i = 1; i <= n; i++) {       int x = a[i];       set<int> q;       while (x != 1) {         q.insert(spf[x]);         x = x / spf[x];       }       set<int>::iterator it1;       for (it1 = q.begin(); it1 != q.end(); ++it1) ans[*it1]++;     }     int p = 0;     for (i = 1; i <= 15000000; i++) p = max(p, ans[i]);     if (p == 0)       printf( -1 n );     else       printf( %d n , n - p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fx[] = {1, 0, 0, -1};   int fy[] = {0, -1, 1, 0};   int n, m;   int data[1002][1002], dist[1002][1002];   void bfs(int sx, int sy) {     for (int i = 0; i < 1002; i++) {       for (int j = 0; j < 1002; j++) dist[i][j] = INT_MAX;     }     queue<int> q;     q.push(sx);     q.push(sy);     dist[sx][sy] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       int v = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int x = u + fx[i];         int y = v + fy[i];         if (x >= 0 && x < n && y >= 0 && y < m && data[x][y] == 0 &&             dist[x][y] > dist[u][v] + 1) {           dist[x][y] = dist[u][v] + 1;           q.push(x);           q.push(y);         }       }     }   }   int main() {     int k;     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &k);     int sx, sy;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char ch;         cin >> ch;         if (ch ==  * )           data[i][j] = 1;         else if (ch ==  X ) {           sx = i;           sy = j;         }       }     }     if (k % 2 != 0) {       cout <<  IMPOSSIBLE n ;       return 0;     }     bfs(sx, sy);     vector<char> res;     while (k > 0) {       if (sx < n - 1 && dist[sx + 1][sy] < k) {         sx++;         res.push_back( D );       } else if (sy > 0 && dist[sx][sy - 1] < k) {         sy--;         res.push_back( L );       } else if (sy < m - 1 && dist[sx][sy + 1] < k) {         sy++;         res.push_back( R );       } else if (sx > 0 && dist[sx - 1][sy] < k) {         sx--;         res.push_back( U );       } else {         cout <<  IMPOSSIBLE n ;         return 0;       }       k--;     }     for (int i = 0; i < res.size(); i++) {       cout << res[i];     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 210;   int n, a[mxN], pos[mxN][3];   int next(int i) {     if (pos[a[i]][0] == i) return pos[a[i]][1];     return pos[a[i]][0];   }   void upd(int u, int v) {     if (pos[a[u]][0] == u)       pos[a[u]][0] = v;     else       pos[a[u]][1] = v;   }   bool gd() {     for (int i = 1; i < 2 * n; i += 2) {       if (a[i] != a[i - 1]) return false;     }     return true;   }   void prnt() {     cout <<  Array  << endl;     for (int i = 0; i < 2 * n; i++) {       cout << a[i] <<    ;     }     cout << endl << endl;   }   int main() {     memset(pos, -1, sizeof pos);     cin >> n;     for (int i = 0; i < 2 * n; i++) {       cin >> a[i];       if (pos[a[i]][0] == -1)         pos[a[i]][0] = i;       else         pos[a[i]][1] = i;     }     int cnt = 0;     while (!gd()) {       for (int i = 0; i < 2 * n; i++) {         if (i + 1 < 2 * n && a[i] == a[i + 1]) continue;         if (i && a[i] == a[i - 1]) continue;         if (i + 1 < 2 * n && next(i) > i && next(i + 1) < next(i)) {           upd(i, i + 1);           upd(i + 1, i);           swap(a[i], a[i + 1]);           cnt++;         } else if (i && next(i) < i && next(i - 1) > next(i)) {           upd(i, i - 1);           upd(i - 1, i);           swap(a[i], a[i - 1]);           cnt++;         }       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int f[256], b[8];   vector<pair<int, int>> a;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       int l, r;       scanf( %d%d , &l, &r);       a.push_back({l, i});       a.push_back({r + 1, -i});     }     sort(a.begin(), a.end());     for (int i = 0; i < 2 * n; i++) {       if (i > 0) {         int ms = 0;         for (int p = 0; p < 8; p++) {           if (b[p]) ms += 1 << p;         }         for (int s = 0; s < (1 << k); s++) {           int cnt = __builtin_popcount(s & ms);           if (cnt & 1) f[s] += a[i].first - a[i - 1].first;         }       }       int j = i;       while (j < 2 * n && a[j].first == a[i].first) {         int y = a[j].second;         if (y < 0) {           y = -y;           for (int p = 0; p < 8; p++) {             if (b[p] == y) {               for (int s = 0; s < (1 << k); s++)                 f[s] = max(f[s], f[s ^ (1 << p)]);               b[p] = 0;               break;             }           }         } else {           for (int p = 0; p < 8; p++) {             if (b[p] == 0) {               b[p] = y;               break;             }           }         }         j++;       }       i = j - 1;     }     int ans = 0;     for (int i = 0; i < (1 << k); i++) ans = max(ans, f[i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 3e5 + 100;   int a[N], n;   long long ans;   void update(int i, int c) {     if (i <= 0 || i > n) return;     if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans += a[i] * c;     if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans -= a[i] * c;   }   int main() {     int w;     cin >> w;     while (w--) {       int q;       scanf( %d%d , &n, &q);       a[0] = a[n + 1] = 0;       for (int i = 1; i <= n; i++) scanf( %d , a + i);       ans = 0;       for (int i = 1; i <= n; i++) update(i, 1);       printf( %lld n , ans);       while (q--) {         int l, r;         scanf( %d%d , &l, &r);         set<int> st;         for (int i = -1; i <= 1; i++) {           st.insert(l + i);           st.insert(r + i);         }         for (int i : st) update(i, -1);         swap(a[l], a[r]);         for (int i : st) update(i, 1);         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, sum = 0;     char str[51];     scanf( %s , &str);     n = strlen(str);     for (i = 0; i < n; i = i + 1) {       if (str[i] ==  a ) {         sum++;       }     }     if (sum > n / 2) {       printf( %d n , n);     } else {       printf( %d n , 2 * sum - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     vector<long long int> v;     cin >> n >> k;     long long int r;     for (long long int i = 0; i < n; i++) {       long long int a;       cin >> a;       v.push_back(a);     }     r = v[0] % k;     long long int mn = 10000000000000;     for (long long int i = 0; i < n; i++) {       if (v[i] % k != r) {         cout <<  -1 n ;         return 0;       }       mn = min(mn, v[i]);     }     long long int count = 0;     for (int i = 0; i < n; i++) {       count += (v[i] - mn) / k;     }     cout << count <<   n ;     return 0;   }