malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m, x, y;       cin >> n >> m >> x >> y;       int arr[n][m];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           char c;           cin >> c;           if (c ==  * )             arr[i][j] = 0;           else             arr[i][j] = 1;         }       long int ans = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (arr[i][j] == 1) {             if (j + 1 < m && arr[i][j + 1] == 1) {               ans += min(2 * x, y);               j++;             } else               ans += x;           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a, k;   int fun(int x) {     int c = 0;     for (auto y : a)       if (y <= x) c++;     for (auto y : k) {       if (y > 0 && y <= x) c++;       if (y < 0 && -y <= c) c--;     }     return c;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     srand(time(NULL));     ;     int T = 1;     cin >> T;     while (T--) {       int n;       cin >> n;       cout << setprecision(10) << 1 / (2 * sin(3.141592653589793238 / (4 * n)));       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-9;   const double Exp = 2.718281828459045;   const double pi = 3.14159;   const double E = 2.7182818284590452354;   int isRight(int x1, int x2) {     if (x1 < x2)       return 1;     else       return -1;   }   int main() {     int arr[3][2];     for (int i = 0; i < 3; ++i) {       cin >> arr[i][0] >> arr[i][1];     }     int resultArr[3][2];     double xn = (arr[0][0] + arr[1][0]) / 2.0;     double yn = (arr[0][1] + arr[1][1]) / 2.0;     resultArr[0][0] = 2 * xn - arr[2][0];     resultArr[0][1] = 2 * yn - arr[2][1];     xn = (arr[1][0] + arr[2][0]) / 2.0;     yn = (arr[1][1] + arr[2][1]) / 2.0;     resultArr[1][0] = 2 * xn - arr[0][0];     resultArr[1][1] = 2 * yn - arr[0][1];     xn = (arr[0][0] + arr[2][0]) / 2.0;     yn = (arr[0][1] + arr[2][1]) / 2.0;     resultArr[2][0] = 2 * xn - arr[1][0];     resultArr[2][1] = 2 * yn - arr[1][1];     int number = 3;     if (resultArr[0][0] == resultArr[1][0] &&         resultArr[0][1] == resultArr[1][1]) {       number--;     }     if (resultArr[1][0] == resultArr[2][0] &&         resultArr[1][1] == resultArr[2][1]) {       number--;     }     if (resultArr[2][0] == resultArr[0][0] &&         resultArr[2][1] == resultArr[0][1]) {       number--;     }     cout << number << endl;     for (int i = 0; i < 3; ++i) {       cout << resultArr[i][0] <<     << resultArr[i][1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, ar[100010];     long long int xr[50010], yr[50010], mr[50010];     while (cin >> t) {       for (int i = 0; i < t; i++) {         cin >> n;         xr[i] = 0;         yr[i] = 0;         mr[i] = 0;         for (int j = 0; j < n; j++) {           cin >> ar[j];           if (ar[j] % 3 == 1) xr[i]++;           if (ar[j] % 3 == 2) yr[i]++;           if (ar[j] % 3 == 0 && ar[j] != 0) mr[i]++;         }       }       for (int i = 0; i < t; i++) {         if (xr[i] >= yr[i])           cout << yr[i] + mr[i] + (xr[i] - yr[i] - (xr[i] - yr[i]) % 3) / 3                << endl;         else           cout << mr[i] + xr[i] + (yr[i] - xr[i] - (yr[i] - xr[i]) % 3) / 3                << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int first, second;     scanf( %d%d , &first, &second);     if (first > second) swap(first, second);     int sum = 0;     if (first <= 2) {       if (first == 1)         sum = second;       else {         if (second < 5)           sum = 4;         else {           if (second % 2 == 0) {             if ((second - 6) % 4 == 0)               sum = second + 2;             else               sum = second;           } else             sum = second + 1;         }       }     } else {       if (first % 2 == 0 || second % 2 == 0)         sum = (first * second) / 2;       else         sum = (first * second) / 2 + 1;     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, soln;     cin >> s;     soln = s;     for (int i = 0, idx = (n - 1) / 2; i < n; i++) {       soln[idx] = s[i];       if ((n + i) % 2 == 0)         idx += (i + 1);       else if ((n + i) % 2 == 1)         idx -= (i + 1);     }     cout << soln << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     string wall[2];     int water = 0;     cin >> n >> k;     cin >> wall[0] >> wall[1];     queue<pair<int, int> > q;     q.push(make_pair(0, 0));     while (!q.empty()) {       queue<pair<int, int> > next;       do {         pair<int, int> pos = q.front();         q.pop();         if (pos.second + k >= n) {           cout <<  YES  << endl;           return 0;         }         if (pos.second - 1 > water && wall[pos.first][pos.second - 1] !=  X ) {           wall[pos.first][pos.second - 1] =  X ;           next.push(make_pair(pos.first, pos.second - 1));         }         if (wall[pos.first][pos.second + 1] !=  X ) {           wall[pos.first][pos.second + 1] =  X ;           next.push(make_pair(pos.first, pos.second + 1));         }         if (wall[1 - pos.first][pos.second + k] !=  X ) {           wall[1 - pos.first][pos.second + k] =  X ;           next.push(make_pair(1 - pos.first, pos.second + k));         }       } while (!q.empty());       ++water;       q = next;     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, d;     double t;     cin >> k >> d >> t;     long long time1 = k;     long long time2 = 0;     if (k % d > 0) {       time2 = (k / d + 1) * d - k;     }     double each_sum = k + (double)time2 / 2;     double res = 0;     res += (long long)(t / each_sum) * (time1 + time2);     t = t - (long long)(t / each_sum) * each_sum;     if (t == 0) {       printf( %.1f n , res);     } else {       res += min(t, (double)k);       t -= min(t, (double)k);       res += t * 2;       printf( %.1f n , res);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > data;   int ii, jj, kk, l;   pair<int, int> bc(int x) {     int q[4];     for (int i = 0; i < 4; i++) {       q[i] = x % 10;       x /= 10;     }     int vis[10];     memset(vis, 0, sizeof vis);     vis[ii] = vis[jj] = vis[kk] = vis[l] = 1;     int b = 0;     int c = 0;     if (q[0] == ii)       b++;     else if (vis[q[0]] == 1)       c++;     if (q[1] == jj)       b++;     else if (vis[q[1]] == 1)       c++;     if (q[2] == kk)       b++;     else if (vis[q[2]] == 1)       c++;     if (q[3] == l)       b++;     else if (vis[q[3]] == 1)       c++;     return make_pair(b, c);   }   int con() {     int ret = l;     ret = ret * 10 + kk;     ret = ret * 10 + jj;     ret = ret * 10 + ii;     return ret;   }   int main() {     int n;     scanf( %d , &n);     int x, y, z;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       scanf( %d , &y);       scanf( %d , &z);       data.push_back(make_pair(x, make_pair(y, z)));     }     int flag = 0;     int val;     int vis[10];     for (ii = 0; ii < 10; ii++) {       for (jj = 0; jj < 10; jj++) {         for (kk = 0; kk < 10; kk++) {           for (l = 0; l < 10; l++) {             memset(vis, 0, sizeof vis);             vis[ii]++;             vis[jj]++;             vis[kk]++;             vis[l]++;             int shit = 0;             for (int i = 0; i < 10; i++) {               if (vis[i] > 1) {                 shit = 1;                 break;               }             }             if (shit) continue;             int i;             for (i = 0; i < n; i++) {               pair<int, int> ret = bc(data[i].first);               if (ret != data[i].second) break;             }             if (i == n) {               flag++;               val = con();             }           }         }       }     }     if (flag == 1) {       vector<int> stud;       for (int i = 0; i < 4; i++) {         stud.push_back(val % 10);         val /= 10;       }       for (int i = 3; i >= 0; i--) cout << stud[i];     } else if (flag == 0) {       cout <<  Incorrect data n ;     } else       cout <<  Need more data n ;   }
#include <bits/stdc++.h>   using namespace std;   int x[100] = {4,   22,  27,  58,  85,  94,   121,  166, 202, 265, 274,                 319, 346, 355, 378, 382, 391,  438,  454, 483, 517, 526,                 535, 562, 576, 588, 627, 634,  636,  645, 648, 654, 663,                 666, 690, 706, 728, 729, 762,  778,  825, 852, 861, 895,                 913, 915, 922, 958, 985, 1086, 1111, 1165};   int main() {     int a;     cin >> a;     cout << x[a - 1];   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 5;   pair<int, int> seg[maxn];   int f[maxn][maxn][2];   int ans;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> seg[i].first >> seg[i].second;     sort(seg + 1, seg + n + 1);     seg[0].first = -(1 << 30);     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= i; ++j) {         for (int k = 0; k < 2; ++k) {           ans = max(ans, f[i][j][k]);           int nr = seg[j].first + seg[j].second * k, mx = -(1 << 30), x = 0,               y = 0;           for (int l = i + 1; l <= n; ++l) {             for (int m = 0; m < 2; ++m) {               int tr = seg[l].first + seg[l].second * m;               if (tr > mx) mx = tr, x = l, y = m;               f[l][x][y] = max(                   f[l][x][y], f[i][j][k] + mx - tr + min(seg[l].second, tr - nr));             }           }         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, zero, one, tot;   long long mod;   long long dp[505][505];   string str[505];   long long dfs(int z, int o) {     long long& ret = dp[z][o];     if (ret != -1) return ret;     ret = 0;     if (z == 0 && o == 0) return ret = 1;     if (z > 0 && o > 0) {       long long nxt = dfs(z - 1, o);       nxt = nxt * (long long)z % mod;       nxt = nxt * (long long)o % mod;       ret = (ret + nxt) % mod;     }     if (z > 1) {       long long nxt = dfs(z - 2, o + 2);       nxt = nxt * (long long)z * (z - 1) / 2 % mod;       ret = (ret + nxt) % mod;     }     if (o > 1) {       long long nxt = dfs(z, o - 2);       nxt = nxt * (long long)o * (o - 1) / 2 % mod;       ret = (ret + nxt) % mod;     }     return ret;   }   int main() {     scanf( %d %d %I64d , &n, &m, &mod);     int flag = 0;     for (int i = 0; i < m; i++) {       cin >> str[i];       int cnt = 0;       for (int j = 0; j < n; j++) {         if (str[i][j] ==  1 ) ++cnt;       }       if (cnt != 2) {         flag = 1;       }     }     if (flag) {       puts( 0 );       return 0;     }     for (int j = 0; j < n; j++) {       int cc = 0;       for (int i = 0; i < m; i++) {         if (str[i][j] ==  1 ) ++cc;       }       if (cc >= 3) {         puts( 0 );         return 0;       }       if (cc == 0)         zero++;       else if (cc == 1)         one++;     }     if (zero + zero + one != 2 * (n - m)) {       puts( 0 );       return 0;     }     memset(dp, -1, sizeof(dp));     long long ans = dfs(zero, one);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1e6) + 7;   const int inf = (1e9) + 7;   const long long LLinf = (1e18) + 7;   const long double eps = 1e-9;   const long long mod = 1e9 + 7;   const int maxlog = 31;   stack<pair<int, int> > stos;   int tab[maxn];   int lewo[maxn];   int prawo[maxn];   int le[maxn][maxlog];   int pr[maxn][maxlog];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> tab[i];       while (((int)(stos).size()) && stos.top().first < tab[i]) stos.pop();       if (((int)(stos).size())) lewo[i] = stos.top().second;       stos.push({tab[i], i});     }     while (((int)(stos).size())) stos.pop();     for (int i = n; i > 0; i--) {       while (((int)(stos).size()) && stos.top().first <= tab[i]) stos.pop();       if (((int)(stos).size()))         prawo[i] = stos.top().second;       else         prawo[i] = n + 1;       stos.push({tab[i], i});     }     for (int bit = 0; bit < maxlog; bit++) {       int curr = 0;       for (int i = 1; i < n + 1; i++) {         if (tab[i] & (1 << bit)) curr = i;         le[i][bit] = curr;       }       curr = n + 1;       for (int i = n; i > 0; i--) {         if (tab[i] & (1 << bit)) curr = i;         pr[i][bit] = curr;       }     }     long long res = 0LL;     for (int i = 1; i < n + 1; i++) {       int l = 0;       int p = n + 1;       for (int bit = 0; bit < maxlog; bit++) {         if (tab[i] & (1 << bit)) continue;         l = max(l, le[i][bit]);         p = min(p, pr[i][bit]);       }       if (l - lewo[i] > 0) res += (l - lewo[i]) * (long long)(prawo[i] - i);       if (prawo[i] - p > 0) res += (prawo[i] - p) * (long long)(i - lewo[i]);       if (prawo[i] - p > 0 && l - lewo[i] > 0)         res -= (prawo[i] - p) * (long long)(l - lewo[i]);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a, b;     cin >> t;     for (int i = 0; i < t; ++i) {       bool res = true;       cin >> n;       cin >> a;       for (int i = 1; i < n; ++i) {         cin >> b;         if (a < b && b - a > 1) res = false;         a = b;       }       cout << (res ?  Yes n  :  No n );     }     return 0;   }
#include <bits/stdc++.h>   long long quickpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       b >>= 1, a = a * a % 1000000007;     }     return ans;   }   using namespace std;   const long long N = 1e3 + 7;   const long long maxn = 2e3 + 9;   long long n, m;   char s[maxn];   long long cnt[27];   bool check(long long x, long long y) {     for (long long i = 0; i <= 25; i++) {       y -= cnt[i] / x;     }     return y <= 0;   }   void solve() {     long long n, k;     cin >> n >> k;     scanf( %s , s + 1);     memset(cnt, 0, sizeof(cnt));     for (long long i = 1; i <= n; i++) {       cnt[s[i] -  a ]++;     }     long long ans = 1;     for (long long i = 1; i <= k; i++) {       if (k % i == 0) {         long long l = 1, r = n;         while (r >= l) {           long long mid = (l + r) >> 1;           if (check(mid, i)) {             l = mid + 1;           } else {             r = mid - 1;           }         }         ans = max(ans, r * i);       }     }     cout << ans << endl;   }   signed main() {     long long _;     cin >> _;     while (_--) solve();   }
#include <bits/stdc++.h>   const double eps = 1e-10;   using namespace std;   int n, m, q, a, b, k;   int so;   int allin, games;   const int N = (1111111);   int in[N];   int answ;   void cut(int m, int k) {     for (int i = 0; i < n; i++) {       if (k <= 0) break;       if (in[i] != -1 && in[i] % 3 == m) {         in[i] = -1;         k--;       }     }   }   int main() {     scanf( %d , &n);     bool can = 0;     long long answr = 1;     long long ss = 0;     int one = 0, two = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &in[i]);       if (in[i] == 0) {         can = 1;       }       if (in[i] % 3 == 1) one++;       if (in[i] % 3 == 2) two++;       ss += in[i];     }     if (!can) {       printf( -1 n );       return 0;     }     sort(in, in + n);     if (ss % 3 == 1) {       if (one > 0) {         cut(1, 1);       } else if (two >= 2) {         cut(2, 2);       }     } else if (ss % 3 == 2) {       if (two > 0) {         cut(2, 1);       } else if (one > 1) {         cut(1, 2);       }     }     bool fl = 0;     for (int i = n - 1; i >= 0; i--) {       if (in[i] != -1) {         printf( %d , in[i]);         if (fl == 0 && in[i] == 0) {           fl = 1;           break;         }         fl = 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   void umax(int &a, int b) { a = max(a, b); }   void umin(int &a, int b) { a = min(a, b); }   void file() { freopen( a.in ,  r , stdin); }   namespace Solver {   const int maxn = 220000;   int n, k;   long long v[maxn];   long long dp[maxn], suf[maxn], id[maxn];   void solve() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     long long sum = 0;     for (int i = n; i > n - k; i--) sum += v[i];     dp[n - k + 1] = sum;     for (int i = n - k; i >= 1; i--) {       sum += v[i];       sum -= v[i + k];       dp[i] = sum;     }     for (int i = n; i >= 1; i--) {       if (dp[i] >= suf[i + 1])         suf[i] = dp[i], id[i] = i;       else         suf[i] = suf[i + 1], id[i] = id[i + 1];     }     long long ans = 0;     int ans1, ans2;     for (int i = 1; i <= n - 2 * k + 1; i++) {       if (ans < dp[i] + suf[i + k]) {         ans = dp[i] + suf[i + k];         ans1 = i;         ans2 = id[i + k];       }     }     cout << ans1 <<     << ans2 << endl;   }   };  // namespace Solver   int main() {     Solver::solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, sum = 0, a, maxx = 0;     scanf( %I64d , &n);     for (long long i = 0; i < n; ++i) {       scanf( %I64d , &a);       sum += a;       maxx = max(maxx, a);     }     if (sum - maxx >= maxx) {       if (sum % 2)         printf( NO n );       else         printf( YES n );     } else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   string vow =  aeiou ;   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double pie = 3.14159265358979;   const long long mod = 1e9 + 7;   long long ans = LLONG_MAX;   long long in;   void f(long long n, int four, int sev) {     if (n > 1e11) return;     if (n >= in) {       if (four == sev) ans = min(ans, n);     }     f(n * 10 + 4, four + 1, sev);     f(n * 10 + 7, four, sev + 1);   }   void solve(int test_case) {     cin >> in;     f(0, 0, 0);     cout << ans;   }   int main() {     int t = 1;     for (int i = 0; i < t; i++) solve(i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> sol;   int n, m, T, h, mi, cnt, fndm, v[1000100], sec;   char ch;   int main() {     cin >> n >> m >> T;     for (int i = 1; i <= n; ++i) {       cin >> h;       cin >> ch;       h *= 3600;       cin >> mi;       cin >> ch;       mi *= 60;       cin >> sec;       v[i] = h + mi + sec;     }     int la = 0;     int lt = 0;     int user = 0;     multiset<int> hm;     for (int i = 1; i <= n; ++i) {       while (!hm.empty() && *hm.begin() < v[i]) hm.erase(hm.begin());       if (hm.size() == m) {         sol.push_back(user);         if (hm.count(v[i - 1] + T - 1)) hm.erase(hm.find(v[i - 1] + T - 1));       } else         sol.push_back(++user);       hm.insert(v[i] + T - 1);       if (hm.size() == m) fndm = 1;     }     if (!fndm) {       cout <<  No solution ;       return 0;     }     cout << user <<   n ;     for (vector<int>::iterator it = sol.begin(); it != sol.end(); it++)       cout << *it <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 5, mod = 998244353, inf = 1e18 + 7;   long long dp[N][N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     for (long long i = 0; i <= n; i++) {       dp[i][0] = m;     }     for (long long i = 2; i <= n; i++) {       for (long long j = 1; j <= k; j++) {         dp[i][j] = (dp[i - 1][j - 1] * (m - 1)) % mod;         dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;       }     }     cout << dp[n][k];   }
#include <bits/stdc++.h>   using namespace std;   long n, m;   long a[4], b[4], c[4];   int main() {     cin >> n;     for (int i = 1; i <= 3; i++) {       cin >> a[i] >> b[i];       c[i] = a[i];     }     m = a[1] + a[2] + a[3];     for (int i = 1; i <= 3; i++) {       while (c[i] < b[i] && m < n) {         c[i] += 1;         m += 1;       }     }     cout << c[1] <<     << c[2] <<     << c[3];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int MAXM = 1000005;   const int MOD = 1000000007;   const int MAMOD = 998244353;   const int INF = 0x3f3f3f3f;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1.0);   const double EPS = 1e-8;   long long n, k, b, c;   long long t[MAXN];   int main() {     ios::sync_with_stdio(0);     cin >> n >> k >> b >> c;     for (int i = 1; i <= n; ++i) {       cin >> t[i];       t[i] += 1000000000;     }     sort(t + 1, t + 1 + n);     long long ret = LLINF;     b = min(b, 5 * c);     for (int i = 0; i < 5; ++i) {       priority_queue<long long, vector<long long>, greater<long long>> pq;       long long x, y, z, sum = 0;       for (int j = 1; j <= n; ++j) {         x = (i - t[j] % 5 + 5) % 5;         y = (t[j] + x) / 5;         z = y * b - x * c;         sum += z;         pq.push(z);         if (j >= k) {           ret = min(ret, y * k * b - sum);           sum -= pq.top();           pq.pop();         }       }     }     cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   int in() {     int x = 0;     char c = getchar();     bool f = false;     while (c <  0  || c >  9 ) f |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return f ? -x : x;   }   long long lin() {     long long x = 0;     char c = getchar();     bool f = false;     while (c <  0  || c >  9 ) f |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return f ? -x : x;   }   const int N = 1e5 + 5;   struct node {     long long a, b;     inline bool operator<(const node &x) const {       return (this->a - this->b) > (x.a - x.b);     }   } s[N];   long long res;   int main() {     int n = in();     for (int i = 1; i <= n; ++i) s[i] = (node){lin(), lin()};     std::sort(s + 1, s + 1 + n);     for (int i = 1; i <= n; ++i)       res += (long long)s[i].b * n + (s[i].a - s[i].b) * i - s[i].a;     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   const long long MOD = 1e9 + 7, INF = 1e18 + 1;   using namespace std;   long long a[1000000], cnt, n, m;   long long p[1000000], sz[1000000];   int d[10000001];   long long gcd(long long a, long long b) {     if (!b)       return (a > 1);     else       return gcd(b, a % b);   }   long long find(long long x) {     if (p[x] == x)       return x;     else       return p[x] = find(p[x]);   }   void unite(long long a, long long b) {     a = find(a);     b = find(b);     if (a == b) return;     if (sz[a] < sz[b]) swap(a, b);     p[b] = a;     sz[a] += sz[b];     cnt--;   }   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       p[i] = i;       sz[i] = 1;     }     memset(d, -1, sizeof(d));     cnt = n;     for (long long i = 0; i < n; i++) {       scanf( %lld , &a[i]);       d[a[i]] = i;       m = max(m, a[i]);     }     for (long long y = 0; y <= m; y++)       for (long long x = y + 1; x * x - y * y <= m && 2 * x * y <= m; x++) {         long long x1 = x * x + y * y;         long long x2 = 2 * x * y;         long long x3 = x * x - y * y;         if (gcd(x1, x2) || gcd(x2, x3) || gcd(x1, x3)) continue;         if (x1 <= m && d[x1] >= 0 && d[x2] >= 0) unite(d[x1], d[x2]);         if (x1 <= m && d[x1] >= 0 && d[x3] >= 0) unite(d[x1], d[x3]);         if (d[x2] >= 0 && d[x3] >= 0) unite(d[x2], d[x3]);       }     cout << cnt;   }