malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int min_dist[3005][3005];   vector<int> furthest_out[3005];   vector<pair<int, int> > X;   vector<pair<int, int> > furthest_in[3005];   vector<int> E[3005];   int n;   void bfs(int source) {     for (int j = 1; j <= n; j++) min_dist[source][j] = 1 << 30;     min_dist[source][source] = 0;     queue<int> Q;     Q.push(source);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       int d = min_dist[source][v];       for (int i = 0; i < E[v].size(); i++) {         int to = E[v][i];         if (min_dist[source][to] >= (1 << 30)) {           min_dist[source][to] = d + 1;           Q.push(to);         }       }     }     X.clear();     for (int i = 1; i <= n; i++) {       if (i == source) continue;       if (min_dist[source][i] >= (1 << 30)) continue;       X.push_back(make_pair(min_dist[source][i], i));       furthest_in[i].push_back(make_pair(min_dist[source][i], source));     }     sort(X.begin(), X.end());     reverse(X.begin(), X.end());     for (int i = 0; i < X.size() && i < 5; i++) {       furthest_out[source].push_back(X[i].second);     }   }   long long v[222222];   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       E[u].push_back(v);     }     for (int i = 1; i <= n; i++) bfs(i);     for (int i = 1; i <= n; i++) {       sort(furthest_in[i].begin(), furthest_in[i].end());       reverse(furthest_in[i].begin(), furthest_in[i].end());     }     long long ans = 0;     int x = -1, y = -1, z = -1, dd = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         if (min_dist[i][j] == (1 << 30)) {           continue;         }         for (int k = 0; k < furthest_in[i].size() && k < 6; k++) {           int a = furthest_in[i][k].second;           if (i == a || j == a) continue;           for (int p = 0; p < furthest_out[j].size() && p < 6; p++) {             int b = furthest_out[j][p];             if (a == b) continue;             if (i == b || j == b) continue;             long long cur = min_dist[a][i] + min_dist[i][j] + min_dist[j][b];             if (cur > ans) {               ans = cur;               x = i;               y = j;               z = a;               dd = b;             }           }         }       }     }     cout << z <<     << x <<     << y <<     << dd << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace myrand {   mt19937 mt(chrono::system_clock::now().time_since_epoch() /              chrono::microseconds(1));   long long Int(long long l, long long r) {     return uniform_int_distribution<long long>(l, r)(mt);   }   }  // namespace myrand   using namespace myrand;   auto ss = chrono::system_clock::now();   double remain_time() {     auto en = chrono::system_clock::now();     return (chrono::duration_cast<chrono::nanoseconds>(en - ss).count() * 1e-9);   }   long long cnt;   long long dp[3001][3001];   const long long mod = 998244353;   void solve(string s, string t) {     int n = s.size();     int m = t.size();     for (int i = 0; i <= n; i++) dp[i][i] = 1;     for (int len = 1; len <= n; len++)       for (int i = 0; i + len <= n; i++) {         int j = i + len;         if (i >= m || s[len - 1] == t[i]) dp[i][j] += dp[i + 1][j];         if (j > m || s[len - 1] == t[j - 1]) dp[i][j] += dp[i][j - 1];         dp[i][j] %= mod;       }     for (int j = m; j <= n; j++) cnt = (cnt + dp[0][j]) % mod;     cout << cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s;     cin >> t;     solve(s, t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k[110], v[110][110], t[110][110], res, s, i, j;   int ktra(long long &s1, long long &s2, long long f1, long long f2, int &p) {     int res = ((s1 - s2) * (f1 - f2) < 0) || ((s1 == s2) && (p * (f1 - f2) < 0));     if (f1 > f2) p = 1;     if (f1 < f2) p = -1;     s1 = f1;     s2 = f2;     return res;   }   int tinh(int i, int j) {     long long s1 = 0, s2 = 0;     int i1 = 0, i2 = 0, t1 = t[i][0], t2 = t[j][0], d = 0, tt, p = 0;     while (s1 < s && s2 < s) {       tt = min(t1, t2);       d += ktra(s1, s2, s1 + tt * v[i][i1], s2 + tt * v[j][i2], p);       t1 -= tt;       t2 -= tt;       if (t1 == 0 && i1 < k[i] - 1) t1 = t[i][++i1];       if (t2 == 0 && i2 < k[j] - 1) t2 = t[j][++i2];     }     return d;   }   int main() {     cin >> n >> s;     for (i = 0; i < n; i++) {       cin >> k[i];       for (j = 0; j < k[i]; j++) cin >> v[i][j] >> t[i][j];     }     res = 0;     for (i = 0; i < n - 1; i++)       for (j = i + 1; j < n; j++) res += tinh(i, j);     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int dp[300000];   int main() {     int r, g;     cin >> r >> g;     int h;     int low = 0, high = 1000;     while (low <= high) {       int mid = (low + high) / 2;       if (mid * (mid + 1) / 2 <= r + g)         h = mid, low = mid + 1;       else         high = mid - 1;     }     int all = h * (h + 1) / 2;     dp[0] = 1;     for (int i = 1; i <= h; i++) {       for (int j = r; j >= 0; j--) {         dp[j + i] += dp[j];         dp[j + i] %= mod;       }     }     int ans = 0;     for (int i = min(all, r); i >= max(0, all - g); --i) {       ans = (ans + dp[i]) % mod;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A[100];     cin >> n;     int aux = 0, ans = 15;     while (n--) {       int t;       cin >> t;       if (t <= ans)         ans = t + 15;       else         break;     }     if (ans > 90) ans = 90;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   const long long INF = 1e9 + 7;   long long n, ans = INF;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     long long n = s.size();     for (long long mask = 1; mask < 1 << n; mask++) {       long long t = 0;       bool check = true;       for (long long i = 0; i < n; i++)         if (mask >> i & 1) {           t = t * 10 + s[i] -  0 ;           if (t == 0 && s[i] ==  0 ) check = false;         }       long long tt = sqrt(t);       if (tt * tt == t && tt != 0 && check)         ans = min(ans, n - __builtin_popcount(mask));     }     cout << (ans == INF ? -1 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000000000001, mod = 1000000007;   long long toi(string s) {     long long a;     istringstream in(s);     in >> a;     return a;   }   int main() {     string s;     cin >> s;     for (int i = 1; i < s.length(); i++)       if (s[i] == s[i - 1]) {         cout <<  Impossible ;         return 0;       }     int a, b;     for (int i = 0; i < s.length(); i++)       for (int j = i + 1; j < s.length(); j++)         if (s[i] == s[j]) {           a = i;           b = j;           break;         }     char arr[2][13];     int A = b - a - 1, B = 26 - A - 1;     arr[0][A / 2] = s[a];     int x = 0, y = A / 2;     int cnt = A;     int p = a + 1;     while (cnt) {       if (x == 0 && y > 0)         y--;       else if (x == 0 && y == 0)         x++;       else         y++;       arr[x][y] = s[p];       p++;       cnt--;     }     cnt = B;     x = 0;     y = A / 2;     p = (b + 1) % 27;     while (cnt) {       if (x == 0 && y < 12)         y++;       else if (x == 0 && y == 12)         x++;       else         y--;       arr[x][y] = s[p];       p++;       p %= 27;       cnt--;     }     for (int i = 0; i < 13; i++) cout << arr[0][i];     cout <<   n ;     for (int i = 0; i < 13; i++) cout << arr[1][i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       long long int n, i, arr[200005];       string s;       cin >> n;       cin >> s;       long long int ans = 0;       for (i = 0; i < n; i++) {         int p = s[i] - 48;         if (p % 2 == 0) {           ans += i + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long k;   vector<vector<long long>> operator*(vector<vector<long long>> a,                                       vector<vector<long long>> b) {     vector<vector<long long>> ans(n, vector<long long>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         ans[i][j] = 0;         for (int k = 0; k < n; k++)           ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % 1000000007;       }     }     return ans;   }   vector<vector<long long>> fastxp(vector<vector<long long>> a, long long e) {     if (e == 1) return a;     vector<vector<long long>> ans = fastxp(a, e / 2);     ans = (ans * ans);     if (e % 2 == 1) ans = ans * a;     return ans;   }   int sumbits(long long a) {     int sum = 0;     while (a > 0) {       sum += a % 2;       a /= 2;     }     return sum;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     vector<vector<long long>> aux(n, vector<long long>(n));     vector<vector<long long>> v(n, vector<long long>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         aux[i][j] = 0;         v[i][j] = 0;       }     }     for (int i = 0; i < n; i++) v[i][0] = 1;     long long a[110];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (sumbits((a[i] ^ a[j])) % 3 == 0) aux[i][j] = 1;       }     }     if (k == 1) {       cout << n << endl;       return 0;     } else {       vector<vector<long long>> ans = fastxp(aux, k - 1);       v = ans * v;       long long sum = 0;       for (int i = 0; i < n; i++) {         sum = (sum + v[i][0]) % 1000000007;       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a, b, n, i, x, y, v;   double min1, ans, k;   int main() {     cin >> a >> b;     cin >> n;     min1 = 999999;     for (i = 1; i <= n; i++) {       cin >> x >> y >> v;       k = (x - a) * (x - a) + (y - b) * (y - b);       ans = sqrt(k) / v;       min1 = min(min1, ans);     }     printf( %.12f n , min1);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     ios_base::sync_with_stdio(false);     int _;     int m, d, w;     for (cin >> _; _ && _--;) {       cin >> m >> d >> w;       int d_dcg = gcd(d - 1, w);       int d1 = (d - 1) / d_dcg;       int w1 = w / d_dcg;       int m_w1 = (min(m, d) - 1) / w1;       cout << 1LL * m_w1 * min(m, d) - 1LL * w1 * (1 + m_w1) * m_w1 / 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, k, j;     cin >> n >> k;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++)         if (i == j)           cout << k <<    ;         else           cout << 0 <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int c, d;       cin >> c >> d;       int temp = abs(c - d);       if (temp % 2) {         cout <<  -1  << endl;         continue;       }       if (c == 0 and d == 0) {         cout <<  0  << endl;         continue;       }       if (temp == 0) {         cout <<  1  << endl;         continue;       }       cout <<  2  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 305;   long long n, k;   long long a[N][N], rows[N], cols[N];   long long sqr(long long x) { return x * x; }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       cin >> n >> k;       for (long long i = 0; i < n; i++) {         rows[i] = cols[i] = 0;         for (long long j = 0; j < n; j++) a[i][j] = 0;       }       long long sti = 0, i = 0, j = 0;       while (k > 0) {         if (a[i][j]) {           sti++;           i = sti, j = 0;         } else {           a[i][j] = 1;           rows[i]++;           cols[j]++;           i++, j++;           i %= n;           j %= n;           k--;         }       }       long long ans = 0;       sort(rows, rows + n);       sort(cols, cols + n);       ans += sqr(rows[n - 1] - rows[0]) + sqr(cols[n - 1] - cols[0]);       cout << ans <<   n ;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) cout << a[i][j];         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 10;   struct Node {     int l, r, q;   };   struct Tree {     int l, r;     int ans;     int lazy;   };   Tree tree[M * 3];   Node d[M];   int mex[M];   int n, m;   void get_same(int s) {     if (tree[s].l == tree[s].r) return;     if (tree[s].lazy) {       tree[s << 1].ans = tree[s << 1].ans | tree[s].ans;       tree[s << 1 | 1].ans = tree[s << 1 | 1].ans | tree[s].ans;       tree[s << 1].lazy = tree[s << 1 | 1].lazy = 1;       tree[s].lazy = tree[s].ans = 0;     }   }   void bulit(int s, int l, int r) {     tree[s].l = l;     tree[s].r = r;     tree[s].ans = 0;     tree[s].lazy = 0;     if (l != r) {       int mid = (l + r) >> 1;       bulit(s << 1, l, mid);       bulit(s << 1 | 1, mid + 1, r);     }   }   void updata(int s, int l, int r, int z) {     if (tree[s].l == l && tree[s].r == r) {       tree[s].ans = tree[s].ans | z;       tree[s].lazy = 1;       return;     }     get_same(s);     int mid = (tree[s].l + tree[s].r) >> 1;     if (r <= mid)       updata(s << 1, l, r, z);     else if (l > mid)       updata(s << 1 | 1, l, r, z);     else {       updata(s << 1, l, mid, z);       updata(s << 1 | 1, mid + 1, r, z);     }   }   void inse(int s) {     get_same(s);     if (tree[s].l == tree[s].r) {       mex[tree[s].l] = tree[s].ans;       return;     }     inse(s << 1);     inse(s << 1 | 1);     tree[s].ans = tree[s << 1].ans & tree[s << 1 | 1].ans;   }   int query(int s, int l, int r) {     if (tree[s].l == l && tree[s].r == r) {       return tree[s].ans;     }     int mid = (tree[s].l + tree[s].r) >> 1;     if (r <= mid)       return query(s << 1, l, r);     else if (l > mid)       return query(s << 1 | 1, l, r);     else       return query(s << 1, l, mid) & query(s << 1 | 1, mid + 1, r);   }   bool solve() {     for (int i = 0; i < m; i++) {       if (query(1, d[i].l, d[i].r) != d[i].q) return false;     }     return true;   }   int main() {     while (scanf( %d%d , &n, &m) == 2) {       bulit(1, 1, n);       for (int i = 0; i < m; i++) {         scanf( %d%d%d , &d[i].l, &d[i].r, &d[i].q);         updata(1, d[i].l, d[i].r, d[i].q);       }       inse(1);       if (solve()) {         puts( YES );         for (int i = 1; i <= n; i++) {           if (i != 1) printf(   );           printf( %d , mex[i]);         }         printf(  n );       } else {         puts( NO );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     char arr[105];     cin >> t;     gets(arr);     for (int i = 0; i < t; i++) {       int flg1 = 0;       int flg2 = 0;       gets(arr);       int len = strlen(arr);       if (arr[0] ==  m  && arr[1] ==  i  && arr[2] ==  a  && arr[3] ==  o  &&           arr[4] ==  . ) {         flg1 = 1;       }       if (arr[len - 1] ==  .  && arr[len - 2] ==  a  && arr[len - 3] ==  l  &&           arr[len - 4] ==  a  && arr[len - 5] ==  l ) {         flg2 = 1;       }       if ((flg1 == 1 && flg2 == 1) || (flg1 == 0 && flg2 == 0)) {         printf( OMG>.< I don t know! n );       } else if (flg1 == 1) {         printf( Rainbow s n );       } else {         printf( Freda s n );       }     }     return 0;   }
#include<cstdio>   #include<cstring>   #include<iostream>   #include<algorithm>   #include<cmath>   #include<vector>   #include<queue>   #include<stack>   #include<ctime>   #include<map>   #define ll long long   #define MAXN 20105   #define uns unsigned   #define INF 0x3f3f3f3f   #define MOD 1000000007ll   #define lowbit(x) ((x)&(-(x)))   using namespace std;   inline ll read(){    ll x=0;bool f=1;char s=getchar();    while((s< 0 ||s> 9 )&&s>0){if(s== - )f^=1;s=getchar();}    while(s>= 0 &&s<= 9 )x=(x<<1)+(x<<3)+s- 0 ,s=getchar();    return f?x:-x;   }   int n,q,a[MAXN],st[MAXN][20],dp[MAXN][20][35],lg[MAXN];   int A[35],B[35],tmp[35];   inline int maxx(int x,int y){return x+a[x]>y+a[y]?x:y;}   inline int rmq(int l,int r){    if(l>r)return 0;r=min(r,n);int k=lg[r-l+1];    return maxx(st[l][k],st[r-(1<<k)+1][k]);   }   signed main()   {    n=read(),q=read();    for(int i=1;i<=n;i++)a[i]=read(),st[i][0]=i;    lg[1]=0;    for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;    for(int i=n;i>0;i--)     for(int j=1;i+(1<<j)-1<=n;j++)      st[i][j]=maxx(st[i][j-1],st[i+(1<<(j-1))][j-1]);    for(int i=1;i<=n;i++)     for(int k=0;k<=30;k++)dp[i][0][k]=i+a[i]+k;    for(int j=0;j<lg[n];j++)     for(int i=1;i<=n;i++)      for(int k=0;k<=30;k++){       for(int l=k;l<=30;l++)        dp[i][j+1][l]=max(dp[i][j+1][l],dp[ rmq(i,dp[i][j][k]) ][j][l-k]);       for(int l=k;l<=30;l++)        dp[i][j+1][l]=max(dp[i][j+1][l],dp[i][j+1][k]+l-k);      }    while(q--){     int l=read(),r=read(),k=read();     if(l==r){printf( 0 n );continue;}     if(r<=l+a[l]+k){printf( 1 n );continue;}     int ans=2;     for(int i=0;i<=k;i++)A[i]=l+a[l]+i;     for(int e=lg[r-l+1];e>=0;e--){      for(int i=0;i<=k;i++)tmp[i]=A[i],B[i]=rmq(l,A[i]);      bool off=0;      for(int i=0;i<=k&&!off;i++)       for(int j=i;j<=k&&!off;j++)        if(dp[B[i]][e][j-i]>tmp[j]){         tmp[j]=dp[B[i]][e][j-i];         if(tmp[j]>=r)off=1;        }      if(off)continue;ans+=(1<<e);      for(int i=0;i<=k;i++)A[i]=tmp[i];     }     printf( %d n ,ans);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, arr[25], ans = 0, c[3];     bool r1 = 1;     cin >> n >> a >> b;     c[0] = a, c[1] = b;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int mid = n / 2;     if (2 * mid < n) mid++;     for (int i = 0; i < mid; i++) {       if (arr[i] == arr[n - i - 1] && arr[i] != 2) {         continue;       } else if (arr[i] == arr[n - i - 1] && arr[i] == 2) {         if (i == n - i - 1)           ans += min(a, b);         else           ans += 2 * min(a, b);       } else if (arr[i] == 2 || arr[n - i - 1] == 2) {         if (arr[i] == 2)           ans += c[arr[n - i - 1]];         else           ans += c[arr[i]];       } else         r1 = 0;     }     if (r1)       cout << ans << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 10;   const long long M = 1e9 + 7;   int n, x, y, z;   int last[N], to[2 * N], w[2 * N], num, nxt[2 * N];   long long a[N];   long long ans;   void Add(int u, int v, int c) {     nxt[++num] = last[u];     to[num] = v;     w[num] = c;     last[u] = num;   }   long long dp[N];   long long dfs(int u, int f) {     long long max1, max2;     max1 = max2 = 0;     for (int i = last[u]; i; i = nxt[i]) {       int v = to[i];       if (v == f) continue;       dfs(v, u);       long long now = dp[v] - w[i];       if (now >= max1) {         max2 = max1;         max1 = now;       } else if (now > max2)         max2 = now;     }     long long tot = max1 + max2 + a[u];     ans = max(ans, tot);     return dp[u] = max(max1, max2) + a[u];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , a + i);     for (int i = 1; i <= n - 1; ++i) {       scanf( %d%d%d , &x, &y, &z);       Add(x, y, z);       Add(y, x, z);     }     dfs(1, 0);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, t, d, e, f;   long long int max(long long int x, long long int y) {     if (x > y)       return x;     else       return y;   }   int main() {     scanf( %I64d%I64d%I64d , &a, &b, &c);     t = max(a, max(b, c));     d = max(t - 1, b);     e = max(t - 1, c);     f = max(t - 1, a);     printf( %I64d n , d - b + e - c + f - a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const double inf = 2 * INF;   const long long N = 0;   vector<long long> tmp, v;   long long pw(long long a, long long p) {     long long result = 1;     while (p > 0) {       if (p & 1) result = a * result;       a = a * a;       p >>= 1;     }     return result;   }   long long sq(long long x) {     long long ans = sqrt(x);     while (ans * ans < x) {       ans++;     }     while (ans * ans > x) {       ans--;     }     return ans;   }   void precompute() {     for (long long i = 3; i < 61; i++) {       for (long long j = 2; j < INF; j++) {         if (pow(j, i) >= inf) {           break;         }         tmp.push_back(pw(j, i));       }     }     sort((tmp).begin(), (tmp).end());     (tmp).erase(unique((tmp).begin(), (tmp).end()), (tmp).end());     for (long long x : tmp) {       long long t = sq(x);       if (t * t == x) {         continue;       }       v.push_back(x);     }   }   void solve() {     long long n;     cin >> n;     long long ans = upper_bound((v).begin(), (v).end(), n) - v.begin();     long long x = sq(n) - 1;     ans += x;     ans = n - 1 - ans;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     precompute();     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long srw[1000], scol[1000];   long long rows[1000001], cols[1000001];   int main() {     int x, n, m, k, p, y, i, j;     scanf( %d%d%d%d , &n, &m, &k, &p);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         scanf( %d , &x);         srw[i] += x;         scol[j] += x;       }     multiset<long long, greater<long long> > rsm, csm;     multiset<long long, greater<long long> >::iterator it;     for (i = 0; i < n; i++) rsm.insert(srw[i]);     for (j = 0; j < m; j++) csm.insert(scol[j]);     for (i = 1; i <= k; i++) {       it = rsm.begin();       long long val = *it;       rsm.erase(it);       rsm.insert(val - p * m);       rows[i] = rows[i - 1] + val;       it = csm.begin();       val = *it;       csm.erase(it);       csm.insert(val - p * n);       cols[i] = cols[i - 1] + val;     }     long long ans = -99999999999999999;     for (i = 0; i <= k; i++)       ans = max(ans, cols[i] + rows[k - i] - 1LL * (k - i) * i * p);     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, T, ti;   long long MX = 4294967295;   long long temp;   long long loop(int n) {     long long ret = 0;     string str;     int rn;     cin >> str;     m--;     while (str !=  end ) {       if (str ==  add ) {         ret++;       } else if (str ==  for ) {         cin >> rn;         temp = loop(rn);         if (temp == -1) break;         ret += temp;       } else {         cerr <<  WOW   << str << endl;       }       if (m == 0) break;       cin >> str;       m--;     }     if (temp == -1) return -1;     if (ret * n > MX) {       return -1;     }     return ret * n;   }   int main() {     ios::sync_with_stdio(false);     cin >> m;     temp = 0;     temp = loop(1);     if (temp == -1) {       cout <<  OVERFLOW!!!  << endl;     } else {       cout << temp << endl;     }     return 0;   }