malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long orz = 1e9 + 7;   char s[500100];   vector<long long> xc;   vector<long long> yc;   vector<long long> tempx;   vector<long long> tempy;   int n, h, w, len, x, y, ly, uy, lx, rx, i, nx, ny, xs, ys, flag;   long long ans, temp;   int main() {     scanf( %d%d%d , &n, &h, &w);     scanf( %s , s);     len = strlen(s);     x = y = ly = uy = lx = rx = 0;     for (i = 0; i < len; i++) {       if (s[i] ==  L ) {         x -= 1;         if (x < lx) lx = x, xc.push_back(i);       } else if (s[i] ==  U ) {         y -= 1;         if (y < uy) uy = y, yc.push_back(i);       } else if (s[i] ==  D ) {         y += 1;         if (y > ly) ly = y, yc.push_back(i);       } else if (s[i] ==  R ) {         x += 1;         if (x > rx) rx = x, xc.push_back(i);       }     }     for (i = 0; i < len; i++) {       if (s[i] ==  L ) {         x -= 1;         if (x < lx) lx = x, tempx.push_back(i);       } else if (s[i] ==  U ) {         y -= 1;         if (y < uy) uy = y, tempy.push_back(i);       } else if (s[i] ==  D ) {         y += 1;         if (y > ly) ly = y, tempy.push_back(i);       } else if (s[i] ==  R ) {         x += 1;         if (x > rx) rx = x, tempx.push_back(i);       }     }     if (tempx.size() != 0)       while (xc.size() < w)         for (i = 0; i < tempx.size(); i++) {           tempx[i] += n;           xc.push_back(tempx[i]);         }     for (i = 0; i < xc.size(); i++) xc[i] += 1;     if (tempy.size() != 0)       while (yc.size() < h)         for (i = 0; i < tempy.size(); i++) {           tempy[i] += n;           yc.push_back(tempy[i]);         }     for (i = 0; i < yc.size(); i++) yc[i] += 1;     xs = xc.size(), ys = yc.size(), nx = ny = 0;     while (nx < xs || ny < ys) {       if (h == 0 || w == 0) break;       flag = (ys == ny || xs > nx && xc[nx] < yc[ny]);       if (flag) {         temp = (h % orz) * (xc[nx] % orz);         ans += temp;         ans %= orz;         nx += 1, w -= 1;       } else {         temp = (w % orz) * (yc[ny] % orz);         ans += temp;         ans %= orz;         ny += 1, h -= 1;       }     }     if (h > 0 && w > 0)       puts( -1 );     else       printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long Hash(char* s, int sz) {     const int p = 31;     long long hash = 0, p_pow = 1;     for (size_t i = 0; i < sz; ++i) {       hash += (s[i] -  a  + 1) * p_pow;       p_pow *= p;     }     return hash;   }   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   vector<int> fac;   void Factor(int N) {     int n = N;     for (int i = 2; i * i <= N; i++) {       if (n % i == 0) {         fac.push_back(i);         n /= i;         i--;       }     }     if (n > 1) fac.push_back(n);     sort(fac.begin(), fac.end());     fac.push_back(1);   }   int main() {     int n;     scanf( %d , &n);     fac.clear();     Factor(n);     int qur = 1;     long long ans = 0;     int k = 0;     while (fac.size() != k) {       ans += n / qur;       qur *= fac[k];       k++;     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[5432][5432], p[5432], b[5432], p_true[5432], b_true[5432];   int main() {     int n;     scanf( %d , &n);     int x;     for (int i = 0; i < n; i++) {       printf( ? %d %d n , i, 0);       fflush(stdout);       scanf( %d , &x);       ans[i][0] = x;     }     for (int i = 1; i < n; i++) {       printf( ? %d %d n , 0, i);       fflush(stdout);       scanf( %d , &x);       ;       ans[0][i] = x;     }     int res = 0;     for (int i = 0; i < n; i++) {       memset(p, -1, sizeof(p));       memset(b, -1, sizeof(b));       p[0] = i;       for (int j = 0; j < n; j++) {         b[j] = (ans[0][j] ^ p[0]);       }       for (int j = 1; j < n; j++) {         p[j] = (ans[j][0] ^ b[0]);       }       int flag = 0;       for (int j = 0; j < n; j++) {         if (p[b[j]] != j || p[j] >= n || b[j] >= n) {           flag = 1;           break;         }       }       if (!flag) {         res++;         for (int j = 0; j < n; j++) {           p_true[j] = p[j];           b_true[j] = b[j];         }       }     }     printf( ! n );     printf( %d n , res);     for (int i = 0; i < n; i++) {       printf( %d  , p_true[i]);     }     printf(  n );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t, n;     cin >> t;     while (t--) {       cin >> n;       long long int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       if (a[0] == a[n - 1])         cout << n << endl;       else         cout << 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> ed[N], leaves;   int n, root = -1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       ed[u].push_back(v);       ed[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (ed[i].size() > 2) {         if (root != -1) {           cout <<  No n ;           return 0;         }         root = i;       }       if (ed[i].size() == 1) leaves.push_back(i);     }     if (root == -1)       cout <<  Yes n             <<  1 n             << leaves[0] <<     << leaves.back() <<   n ;     else {       cout <<  Yes n ;       cout << leaves.size() <<   n ;       for (auto i : leaves) cout << root <<     << i <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<long long, long long> > f(n);     for (int i = 0; i < n; ++i) cin >> f[i].first >> f[i].second;     sort(f.begin(), f.end());     vector<long long> v(n);     v[n - 1] = f[n - 1].second;     for (int i = n - 2; i >= 0; --i) {       v[i] = v[i + 1];       long long mn = 0;       for (int j = i + 2; j < n; ++j) {         mn += f[j - 1].first - f[i].first;         if (mn + v[j] < v[i]) v[i] = mn + v[j];       }       if (mn + f[n - 1].first - f[i].first < v[i])         v[i] = mn + f[n - 1].first - f[i].first;       v[i] += f[i].second;     }     cout << v[0];   }
#include <bits/stdc++.h>   using namespace std;   bool isOk(string s) {     for (long long i = 0; i + 1 < s.size(); i++) {       if (s[i] ==  1  && s[i + 1] ==  1 ) {         return false;       }     }     return true;   }   int main() {     long long n;     cin >> n;     string s;     cin >> s;     if (!isOk(s)) {       puts( No );       return 0;     }     for (long long i = 0; i < n; i++) {       string tmp = s;       if (tmp[i] ==  0 ) {         tmp[i] =  1 ;         if (isOk(tmp)) {           puts( No );           return 0;         }       }     }     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N, M, a, b, c, t[100007], C, D, S, nn, ans;   char s[100007];   int main() {     scanf( %I64d%I64d%I64d , &N, &C, &D);     for (long long i = 1; i <= N; i++) {       scanf( %d , &t[i]);       scanf( %c%c , &s[i], &s[i]);     }     scanf( %d , &t[N + 1]);     ans = N * D;     S = ans;     for (long long i = N; i >= 1; i--) {       long long l = i, r = i + 1;       while (l > 1 && s[l - 1] == s[l]) l--;       a = min(i - 1, nn);       while (i > l && (t[r] - t[i]) * C < D) {         S = S - D + (t[r] - t[i]) * C;         ans = min(ans, S);         i--;       }       S = S - D + (t[r] - t[l]) * C;       ans = min(ans, S);       i = l;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char str[105];     int n, d;     while (~scanf( %d%d , &n, &d)) {       int sum = 0, flag = 0;       int maxn = 0;       for (int i = 0; i < d; i++) {         scanf( %s , str);         for (int i = 0; i < strlen(str); i++) {           if (str[i] ==  0 ) {             flag = 1;             break;           }         }         if (flag)           sum++;         else           sum = 0;         maxn = max(sum, maxn);         flag = 0;       }       printf( %d n , maxn);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[1001] = {0}, t, x;     bool flag = false;     if (n % 2 == 0)       x = n / 2;     else       x = n / 2 + 1;     for (int i = 0; i < n; i++) {       scanf( %d , &t);       a[t]++;       if (a[t] > x) flag = true;     }     if (flag)       printf( NO );     else       printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     if (b == 0) return a;     return (a % b == 0 ? b : GCD(b, a % b));   }   long long POW(long long base, long long exp) {     long long val;     val = 1;     while (exp > 0) {       if (exp % 2 == 1) {         val = (val * base) % 1000000007;       }       base = (base * base) % 1000000007;       exp = exp / 2;     }     return val;   }   int main() {     int n, m, ans;     scanf( %d%d , &n, &m);     if (n == 1) {       ans = 1;     } else {       if ((m - 1) >= (n - m)) {         ans = m - 1;       } else {         ans = m + 1;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, fa, h[N];   vector<int> G[N], p, q;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n - 1); ++i) scanf( %d , &fa), G[fa].push_back(i);     function<void(int)> dfs = [&](int u) {       for (int v : G[u]) dfs(v), h[u] = max(h[u], h[v] + 1);     };     dfs(0);     function<int(int, int)> solve = [&](int u, int nd) {       sort(G[u].begin(), G[u].end(), [&](int x, int y) { return h[x] < h[y]; });       p.push_back(u);       for (int i = (1); i <= (nd); ++i) q.push_back(u);       nd = 0;       for (int v : G[u]) nd = solve(v, nd);       return nd + 1;     };     solve(0, 0);     for (int x : p) printf( %d  , x);     printf(  n%d n , q.size());     for (int x : q) printf( %d  , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long d[3];       cin >> d[0] >> d[1] >> d[2];       sort(d, d + 3);       if (d[2] >= d[0] + d[1])         cout << d[0] + d[1] << endl;       else {         cout << d[2] + (d[1] + d[0] - d[2]) / 2 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> orderA[500005];   pair<long long, long long> orderB[500005];   void copyArray(int mBegin, int mEnd) {     for (int i = mBegin; i < mEnd; i++) {       orderA[i] = orderB[i];     }   }   void doMerge(int mBegin, int mMid, int mEnd) {     int i = mBegin, j = mMid;     for (int k = mBegin; k < mEnd; k++) {       if (i < mMid && (j >= mEnd || orderA[i].second <= orderA[j].second)) {         orderB[k] = orderA[i];         i++;       } else {         orderB[k] = orderA[j];         j++;       }     }   }   void splitMerge(int mBegin, int mEnd) {     if (mEnd - mBegin < 2) return;     int mMid = (mEnd + mBegin) / 2;     splitMerge(mBegin, mMid);     splitMerge(mMid, mEnd);     doMerge(mBegin, mMid, mEnd);     copyArray(mBegin, mEnd);   }   void mergeSort(int n) { splitMerge(0, n); }   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; i++) {       long long x, y;       scanf( %I64d %I64d , &x, &y);       orderA[i] = make_pair(x, y);     }     mergeSort(N);     long long current = 0;     int ans = 0;     for (int i = 0; i < N; i++) {       if (current < orderA[i].first) {         current = orderA[i].second;         ans++;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, h[260], f = 1, c, g, i;   string s;   int main() {     cin >> s >> n;     if (n > s.length()) return cout <<  impossible , 0;     for (i = 0; i < s.length(); i++) h[s[i]]++;     for (i = 97; i <= 122; i++)       if (h[i] > 0) g++;     if (g < n)       c = n - g;     else       f = 1;   l:     if (f == 1)       cout << c;     else       cout <<  impossible ;   }
#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-11;   double a[4];   double p[4][2] = {{-1, -1}, {1, -1}, {-1, 1}, {1, 1}};   bool poss(double thr) {     double min03 = numeric_limits<double>::infinity();     double max03 = -numeric_limits<double>::infinity();     double min12 = numeric_limits<double>::infinity();     double max12 = -numeric_limits<double>::infinity();     for (int i = 0; i < 4; i++) {       min03 = min(min03, (a[0] + thr * p[i][0]) * (a[3] + thr * p[i][1]));       min12 = min(min12, (a[1] + thr * p[i][0]) * (a[2] + thr * p[i][1]));       max03 = max(max03, (a[0] + thr * p[i][0]) * (a[3] + thr * p[i][1]));       max12 = max(max12, (a[1] + thr * p[i][0]) * (a[2] + thr * p[i][1]));     }     return !(max03 < min12 || max12 < min03);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 0; i < 4; i++) cin >> a[i];     double lo = 0, hi = 1e9;     for (int i = 0; i < 10000; i++) {       const double mid = (lo + hi) / 2;       if (poss(mid))         hi = mid;       else         lo = mid;     }     cout << setprecision(20) << lo << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   int vecinos[MAXN];   int prof[MAXN];   int n;   set<int> arbol[MAXN];   void dfs(int i, int p, int profund) {     prof[i] = profund;     for (int h : arbol[i]) {       if (h == p) continue;       dfs(h, i, profund + 1);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     int raiz;     for (int i = (0); i < (n); i++) {       int p;       cin >> p;       p--;       if (p != -1) {         arbol[p].insert(i);         vecinos[p]++;         arbol[i].insert(p);         vecinos[i]++;       } else {         raiz = i;       }     }     dfs(raiz, -1, 0);     set<pair<int, int> > q;     for (int i = (0); i < (n); i++) {       if (vecinos[i] % 2 == 0) {         q.insert({-prof[i], i});       }     }     vector<int> eliminados;     while (!q.empty()) {       auto actual = *q.begin();       q.erase(q.begin());       int act = actual.second;       if (vecinos[act] % 2) continue;       for (int h : arbol[act]) {         vecinos[h]--;         arbol[h].erase(arbol[h].find(act));         if (vecinos[h] % 2 == 0) {           q.insert({-prof[h], h});         }       }       arbol[act].clear();       eliminados.push_back(act);     }     if ((int)(eliminados).size() != n) {       cout <<  NO n ;     } else {       cout <<  YES n ;       for (int e : eliminados) {         cout << e + 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, LG = 19;   struct edge {     int u, v, w, c, i, in;     bool operator<(const edge &b) const { return w < b.w; }   } arr[N];   vector<pair<int, int> > adj[N];   int ST[N][LG], mx[N][LG], in[N], out[N];   bool isAncestor(int u, int v) { return in[v] >= in[u] && out[v] <= out[u]; }   void go(int &ret, int i) {     if (ret == -1 || arr[ret].w < arr[i].w) ret = i;   }   int solve(int u, int v) {     int ret = -1;     for (int j = LG - 1; j >= 0; j--) {       if (ST[u][j] && !isAncestor(ST[u][j], v)) {         go(ret, mx[u][j]);         u = ST[u][j];       }     }     for (int j = LG - 1; j >= 0; j--) {       if (ST[v][j] && !isAncestor(ST[v][j], u)) {         go(ret, mx[v][j]);         v = ST[v][j];       }     }     if (!isAncestor(u, v)) go(ret, mx[u][0]);     if (!isAncestor(v, u)) go(ret, mx[v][0]);     return ret;   }   int t;   void dfs(int cur, int from = 0) {     in[cur] = t++;     ST[cur][0] = from;     for (int j = 1; j < LG; ++j) {       ST[cur][j] = ST[ST[cur][j - 1]][j - 1];       mx[cur][j] = mx[cur][j - 1];       int to = ST[cur][j - 1];       if (to) go(mx[cur][j], mx[to][j - 1]);     }     for (int i = 0; i < adj[cur].size(); ++i)       if (adj[cur][i].first != from) {         mx[adj[cur][i].first][0] = adj[cur][i].second;         dfs(adj[cur][i].first, cur);       }     out[cur] = t++;   }   int p[N];   int findSet(int i) { return (i == p[i] ? i : p[i] = findSet(p[i])); }   int n, m, s;   int main() {     scanf( %d , &n), scanf( %d , &m);     for (int i = 0; i < m; ++i) scanf( %d , &arr[i].w);     for (int i = 0; i < m; ++i) scanf( %d , &arr[i].c);     for (int i = 0; i < m; ++i) {       scanf( %d , &arr[i].u);       scanf( %d , &arr[i].v);       arr[i].i = i + 1;       arr[i].in = 0;     }     scanf( %d , &s);     for (int i = 1; i <= n; i++) p[i] = i;     sort(arr, arr + m);     long long sum = 0;     for (int i = 0; i < m; ++i) {       int ru = findSet(arr[i].u);       int rv = findSet(arr[i].v);       if (ru == rv) continue;       arr[i].in = 1;       p[ru] = rv;       sum += arr[i].w;       adj[arr[i].u].push_back(pair<int, int>(arr[i].v, i));       adj[arr[i].v].push_back(pair<int, int>(arr[i].u, i));     }     dfs(1);     int be = -1, re = -1;     long long delta = 1e18;     for (int i = 0; i < m; ++i) {       int j = solve(arr[i].u, arr[i].v);       if (arr[i].w - arr[j].w - s / arr[i].c < delta) {         be = i, re = j;         delta = arr[i].w - arr[j].w - s / arr[i].c;       }     }     cout << sum + delta << endl;     for (int i = 0; i < m; ++i) {       if ((arr[i].in && re != i) || i == be) {         printf( %d  , arr[i].i);         if (i == be)           printf( %d n , arr[i].w - s / arr[i].c);         else           printf( %d n , arr[i].w);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0, i, flag = 1;     cin >> n;     char s[n + 1], c;     cin >> s;     int l = 0, r = 0;     l++;     for (i = 1; i < n; i++) {       c = s[i];       if (c == s[0])         l++;       else         r++;       if (r > l && flag == 1) {         flag = 0;         count++;       }       if (r < l && flag == 0) {         flag = 1;         count++;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   const long double EPS = 1e-12;   long long w[200005];   long long h[200005];   long long c[200005];   long long rgcd[200005];   map<long long, vector<pair<long long, long long> > > ma;   long long gcd(long long a, long long b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   int main() {     int n;     cin >> n;     long long tp = 0;     for (int i = 0; i < (int)n; i++) {       cin >> w[i] >> h[i] >> c[i];       ma[w[i]].push_back(make_pair(h[i], c[i]));       if (i == 0)         tp = c[i];       else         tp = gcd(tp, c[i]);     }     map<long long, vector<pair<long long, long long> > >::iterator it, it_;     for (it = ma.begin(); it != ma.end(); it++) {       sort((it->second).begin(), (it->second).end());     }     it_ = ma.begin();     it_++;     for (it = ma.begin(); it_ != ma.end(); it++) {       int si = (int)(it->second).size();       int si_ = (int)(it_->second).size();       if (si != si_) {         cout <<  0  << endl;         return 0;       }       for (int i = 0; i < (int)si; i++) {         if ((it->second)[i].first != (it_->second)[i].first) {           cout <<  0  << endl;           return 0;         }       }       it_++;     }     long long net;     int fl = 0;     for (it = ma.begin(); it != ma.end(); it++) {       int si = (int)(it->second).size();       int si_ = (int)(it_->second).size();       long long tmp = (it->second)[0].second;       for (int i = (int)1; i < (int)si; i++) {         if (tmp == 1) break;         tmp = gcd(tmp, (it->second)[i].second);       }       for (int i = 0; i < (int)si; i++) {         ((it->second)[i].second) /= tp;       }     }     net = tp;     if (net == 1) {       it_ = ma.begin();       it_++;       for (it = ma.begin(); it_ != ma.end(); it++) {         int si = (int)(it->second).size();         int si_ = (int)(it_->second).size();         long long d1 = 0;         long long d2 = 0;         for (int i = 0; i < (int)si; i++) {           d1 += ((it->second)[i].first) * ((it->second)[i].second);         }         for (int i = 0; i < (int)si; i++) {           d2 += ((it_->second)[i].first) * ((it_->second)[i].second);         }         if (d1 != d2) {           cout <<  0  << endl;           return 0;         }         it_++;       }     }     long long ans = 0;     for (int i = (int)1; i < (int)1e6 + 5; i++) {       long long i_ = (long long)(i);       if (i_ * i_ > net) break;       if (net % i_ == 0) {         ans += 2;       }       if (i_ * i_ == net) {         ans--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m, e, h, x, y;   long long cal() {     for (int i = 0; i <= m * 2; i++) {       h = (h * x + y) % m;       if (h == e) return i + 1;     }     return -1;   }   void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b)       d = a, x = 1, y = 0;     else {       exgcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   int main() {     cin >> m;     cin >> h >> e >> x >> y;     long long t1 = cal();     long long t2 = cal();     cin >> h >> e >> x >> y;     long long t3 = cal();     long long t4 = cal();     if (t1 == t3) {       cout << t1 << endl;       return 0;     }     if (~t1 && ~t2 && ~t3 && t3 > t1 && (t3 - t1) % t2 == 0) {       cout << t3 << endl;       return 0;     }     if (~t3 && ~t4 && ~t1 && t1 > t3 && (t1 - t3) % t4 == 0) {       cout << t1 << endl;       return 0;     }     if (t1 == -1 || t2 == -1 || t3 == -1 || t4 == -1) {       cout << -1 << endl;       return 0;     }     long long x, y, d, a = t2, b = t4, c = t3 - t1;     exgcd(a, b, d, x, y);     if (c % d) {       cout << -1 << endl;       return 0;     }     x = (x * (c / d)) % b;     x = (x % (b / d) + b / d) % (b / d);     y = (a * x - c) / b;     while (x < 0 || y < 0) x += d, y += d;     cout << t1 + x * t2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, p = 0, k = 0;     cin >> n;     for (int i = 0; i <= n; i++) {       if (i < n)         cin >> t;       else         t = 90;       if (t - p > 15 && k == 0) {         k = p + 15;       } else         p = t;     }     if (k == 0) k = p;     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N_ = 25;   int N;   char D[N_][N_];   int Table[40][1 << 20];   bool Chk[40][1 << 20];   int wh[26][N_ + N_];   int cst[2][2] = {{1, -1}, {-1, 1}};   int solve(int x, int state) {     if (x == N + N - 1) return 0;     if (Chk[x][state]) return Table[x][state];     int &ret = Table[x][state];     ret = (int)-1e9;     int state_s = state | (state << 1);     if (!state) state_s = 1;     for (int c = 0; c < 26; c++) {       int nxt = state_s & wh[c][x];       if (nxt != 0) {         int nxtret = ((c > 1) ? 0 : cst[x & 1][c]) - solve(x + 1, nxt);         ret = max(ret, nxtret);       }     }     Chk[x][state] = 1;     return ret;   }   int main() {     int i, j, k;     scanf( %d , &N);     for (i = 0; i < N; i++) scanf( %s , D[i]);     for (int c = 0; c < 26; c++)       for (i = 0; i < 2 * N - 1; i++) {         for (j = max(i - N + 1, 0); j < N && j <= i; j++)           if (D[i - j][j] == c +  a ) wh[c][i] |= 1 << j;       }     int ret = solve(0, 0);     puts((ret == 0) ?  DRAW  : ((ret > 0) ?  FIRST  :  SECOND ));     return 0;   }
#include <bits/stdc++.h>   int cmpfunc(const void *a, const void *b) { return (*(int *)a) - (*(int *)b); }   int main() {     int n, arr[200000], i, r, count = 0;     long long int result = 0;     double root;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     for (i = 0; i < n; i++) {       root = sqrt((double)arr[i]);       r = round(root);       r = r * r;       r -= arr[i];       if (arr[i] == 0) count++;       arr[i] = abs(r);     }     qsort(arr, n, sizeof(int), cmpfunc);     n = n / 2;     for (i = 0; i < n; i++) {       if (arr[i] != 0) result += (long long int)arr[i];     }     if (result == 0) {       n = 2 * n;       for (i = n / 2; i < n; i++) {         if (arr[i] == 0) result++;       }       if (count > n / 2) {         count -= (n / 2);         result += (long long int)count;       }     }     printf( %lld , result);     return 0;   }