malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   template <class T>   inline void checkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void checkmin(T &x, T y) {     if (x > y) x = y;   }   template <class T>   inline T Min(T x, T y) {     return (x > y ? y : x);   }   template <class T>   inline T Max(T x, T y) {     return (x < y ? y : x);   }   using namespace std;   vector<int> a[111111], ans;   int n, m, b[111111], c[111111];   int main() {     while (scanf( %d%d , &n, &m) == 2) {       for (int i = 1; i <= n; ++i) a[i].clear();       ans.clear();       memset(c, 0, sizeof(c));       for (int i = 1; i <= m; ++i) {         int u, v;         scanf( %d%d , &u, &v);         a[u].push_back(v);         a[v].push_back(u);       }       for (int i = 1; i <= n; ++i) scanf( %d , b + i);       queue<int> q;       for (int i = 1; i <= n; ++i)         if (!b[i]) q.push(i);       while (!q.empty()) {         int v = q.front();         q.pop();         if (b[v] == c[v])           ans.push_back(v);         else           continue;         c[v]++;         for (int i = 0; i < a[v].size(); ++i) {           c[a[v][i]]++;           if (b[a[v][i]] == c[a[v][i]]) q.push(a[v][i]);         }       }       printf( %d n , ans.size());       for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);       if (ans.size()) puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   using vv = vector<vector<T>>;   template <class T>   inline bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   const ll MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(0);     int n;     cin >> n;     string opes(n,  . );     vector<pii> clds(n);     for (int(i) = 0; (i) < (n); ++(i)) {       string s;       cin >> s >> clds[i].first;       if (s ==  IN ) {         opes[i] =  > ;         continue;       }       --clds[i].first;       if (s ==  NOT ) {         opes[i] =  ~ ;         continue;       }       cin >> clds[i].second;       --clds[i].second;       if (s ==  AND ) {         opes[i] =  & ;       } else if (s ==  OR ) {         opes[i] =  | ;       } else if (s ==  XOR ) {         opes[i] =  ^ ;       } else         return 1;     };     vector<int> vals(n);     {       function<int(int)> dfs = [&](int v) {         if (opes[v] ==  & ) {           vals[v] = dfs(clds[v].first) & dfs(clds[v].second);         } else if (opes[v] ==  | ) {           vals[v] = dfs(clds[v].first) | dfs(clds[v].second);         } else if (opes[v] ==  ^ ) {           vals[v] = dfs(clds[v].first) ^ dfs(clds[v].second);         } else if (opes[v] ==  ~ ) {           vals[v] = 1 - dfs(clds[v].first);         } else           vals[v] = clds[v].first;         return vals[v];       };       dfs(0);     };     string re(n, vals[0] +  0 );     ;     {       function<void(int)> dfs = [&](int v) {         if (opes[v] ==  & ) {           if (vals[clds[v].first]) dfs(clds[v].second);           if (vals[clds[v].second]) dfs(clds[v].first);         } else if (opes[v] ==  | ) {           if (!vals[clds[v].first]) dfs(clds[v].second);           if (!vals[clds[v].second]) dfs(clds[v].first);         } else if (opes[v] ==  ^ ) {           dfs(clds[v].first);           dfs(clds[v].second);         } else if (opes[v] ==  ~ ) {           dfs(clds[v].first);         } else           re[v] ^= 1;       };       dfs(0);     }     for (int(i) = 0; (i) < (n); ++(i))       if (opes[i] ==  > ) cout << re[i];     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1000000009;   const double eps = 1e-9;   const int mod = 1000000007;   int nos[100001], n, pos = 0;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) scanf( %d , &nos[i]);     sort(nos, nos + n);     for (int i = 0; i < n; ++i)       if (pos + 1 <= nos[i]) ++pos;     printf( %d n , pos + 1);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, qu;   int a[100011];   int st[100011], en[100011];   int pos[100011];   int rt[100011], nxt[100011];   int step[100011];   bool vis[100011];   vector<int> v[100011], vv;   queue<int> q;   void bunhae_interval() {     int r = n % m, mm = n / m;     st[0] = 1;     for (int i = 0; i < m; i++) {       if (i) st[i] = en[i - 1] + 1;       en[i] = st[i] + mm - 1;       if (i < r) en[i]++;       for (int j = st[i]; j <= en[i]; j++) pos[j] = i;     }   }   void update(int x) {     int p = pos[x];     for (int i = st[p]; i <= x; i++) vis[i] = 0;     vis[x] = 1;     q.push(x);     while (!q.empty()) {       int y = q.front();       q.pop();       for (int i = 0; i < v[y].size(); i++) {         int z = v[y][i];         if (vis[z]) continue;         vis[z] = 1;         step[z] = step[y] + 1;         rt[z] = rt[x];         q.push(z);       }     }   }   int main() {     scanf( %d %d , &n, &qu);     m = sqrt(n);     bunhae_interval();     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = n; i >= 1; i--) {       int j = i + a[i];       if (j > n || pos[j] != pos[i])         nxt[i] = j, rt[i] = i, step[i] = 0;       else         rt[i] = rt[j], step[i] = step[j] + 1, v[j].push_back(i);     }     while (qu--) {       int tp, x, y;       scanf( %d %d , &tp, &x);       if (tp == 1) {         int cnt = 1, en = x;         while (1) {           if (rt[en] == en) {             if (nxt[en] > n)               break;             else               cnt++, en = nxt[en];           } else {             cnt += step[en], en = rt[en];           }         }         printf( %d %d n , en, cnt);       } else {         int xx = x + a[x];         if (xx > n) goto la;         vv.clear();         for (int i = 0; i < v[xx].size(); i++)           if (v[xx][i] != x) vv.push_back(v[xx][i]);         v[xx].clear();         for (int i = 0; i < vv.size(); i++) v[xx].push_back(vv[i]);       la:;         scanf( %d , &y);         int z = x + y;         if (z > n || pos[z] != pos[x])           nxt[x] = z, rt[x] = x, step[x] = 0;         else           rt[x] = rt[z], step[x] = step[z] + 1, v[z].push_back(x);         a[x] = y;         update(x);       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int powers[1000100];   vector<pair<int, int> > edges;   unsigned long long hashes[1000100] = {0};   unsigned long long ts[1000100] = {0};   int main(void) {     powers[0] = 1;     for (int i = 1; i <= 1000000; i++)       powers[i] = (powers[i - 1] * (unsigned long long)41) % 291598227841757;     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       hashes[u] = (hashes[u] + powers[v]) % 291598227841757;       hashes[v] = (hashes[v] + powers[u]) % 291598227841757;       ts[u - 1] = hashes[u];       ts[v - 1] = hashes[v];       edges.push_back(make_pair(u, v));     }     sort(ts, ts + n);     int cur = 0;     long long int ans = 0;     for (int i = 1; i < n; i++) {       if (ts[i] != ts[cur]) {         long long int n = i - cur;         ans += n * (n - 1) / 2;         cur = i;       }     }     long long int a = n - cur;     ans += a * (a - 1) / 2;     for (int i = 0; i < m; i++) {       int u = edges[i].first, v = edges[i].second;       unsigned long long hu = (hashes[u] + powers[u]) % 291598227841757;       unsigned long long hv = (hashes[v] + powers[v]) % 291598227841757;       if (hu == hv) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e5 + 1;   int n, m;   vector<int> adj[N];   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int rand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }   int d[N];   bool inq[N];   bool vis3[N];   bool ok = true;   void dfs3(int id) {     inq[id] = true;     vis3[id] = true;     for (auto x : adj[id]) {       if (!vis3[x]) {         dfs3(x);       } else if (!inq[x])         ok = false;     }     inq[id] = false;   }   bool arin(int x) {     for (int i = 1; i <= n; i++) vis3[i] = inq[i] = false;     ok = true;     dfs3(x);     return ok;   }   bool vis[N];   vector<int> ch[N];   int par[N];   int dx[N], dy[N];   int cs[N];   int up[N];   void dfs(int id) {     vis[id] = true;     up[id] = id;     for (auto x : adj[id]) {       if (!vis[x]) {         d[x] = d[id] + 1;         par[x] = id;         ch[id].push_back(x);         cs[id] = x;         dfs(x);       } else {         dx[x]--;         dx[id]++;         if (d[up[id]] > d[x]) up[id] = x;       }     }     for (auto x : ch[id]) {       if (d[up[x]] < d[up[id]]) up[id] = up[x];     }   }   int dfs4(int id) {     int duh = dx[id];     for (auto x : ch[id]) duh += dfs4(x);     dy[id] = duh;     return duh;   }   bool good[N];   int rt;   void dfs2(int id) {     if (dy[id] <= 1) good[id] = good[up[id]];     if (id == rt) good[id] = true;     for (auto x : ch[id]) {       dfs2(x);     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       adj[i].clear();       ch[i].clear();       dx[i] = dy[i] = 0;       good[i] = false;     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);     }     int x = 0;     for (int i = 1; i <= 100; i++) {       x = rand(n) + 1;       if (arin(x)) break;       x = 0;     }     if (x == 0) {       cout <<  -1 n ;       return;     }     for (int i = 1; i <= n; i++) vis[i] = false;     d[x] = 0;     dfs(x);     rt = x;     dfs4(x);     dfs2(x);     int cnt = 0;     for (int i = 1; i <= n; i++)       if (good[i]) cnt++;     if (cnt * 5 < n) {       cout <<  -1 n ;       return;     }     for (int i = 1; i <= n; i++)       if (good[i]) cout << i <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   const int maxN = 3e5 + 5;   int main() {     if (fopen( iput.txt ,  r )) {       freopen( iput.txt ,  r , stdin);       freopen( oput.txt ,  w , stdout);     }     int n;     scanf( %d , &n);     printf( %d n , n / 2 * 2 + n - n / 2);     printf( 2  );     for (int i = 4; i <= n; i += 2) printf( %d  , i);     for (int i = 1; i <= n; i += 2) printf( %d  , i);     for (int i = 2; i <= n; i += 2) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> st[200000 + 7];   set<int>::iterator it;   vector<int> graph[200000 + 7], edge[200000 + 7];   pair<int, int> edges[200000 + 7], path[200000 + 7];   int sid[200000 + 7], prio[200000 + 7], pr_id, can[200000 + 7], neg[200000 + 7],       rev[200000 + 7];   long long weg[200000 + 7], uwg[200000 + 7];   void dfs(int u, int edg) {     int v, ed;     long long wg = 0;     neg[u] = edg;     for (int i = 0; i < graph[u].size(); i++) {       v = graph[u][i];       ed = edge[u][i];       dfs(v, ed);       wg += weg[v];     }     if (u == 1) return;     prio[u] = ++pr_id;     rev[pr_id] = edg;     sid[u] = u;     st[u].insert(pr_id);     can[edg] = min(1LL * edges[edg].first - 1, edges[edg].second - wg);     if (can[edg] < 0) {       puts( -1 );       exit(0);     }     weg[u] = wg + edges[edg].first - can[edg];   }   void solve(int u) {     int v, id1, id2;     for (int i = 0; i < graph[u].size(); i++) {       v = graph[u][i];       solve(v);       uwg[u] += uwg[v];       id1 = sid[u];       id2 = sid[v];       if (st[id2].size() > st[id1].size()) swap(id1, id2);       for (it = st[id2].begin(); it != st[id2].end(); it++)         st[id1].insert(int(*it));       sid[u] = id1;     }     if (u == 1) return;     int temp;     while (uwg[u] > edges[neg[u]].second) {       temp = *st[sid[u]].begin();       temp = rev[temp];       if (uwg[u] - can[temp] >= edges[neg[u]].second) {         edges[temp].first -= can[temp];         edges[temp].second -= can[temp];         uwg[u] -= can[temp];         can[temp] = 0;         st[sid[u]].erase(st[sid[u]].begin());       } else {         int tpv = uwg[u] - edges[neg[u]].second;         edges[temp].first -= tpv;         edges[temp].second -= tpv;         uwg[u] -= tpv;         can[temp] -= tpv;       }     }     uwg[u] += edges[neg[u]].first;   }   int main() {     int n, u, v, w, p;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       scanf( %d %d , &edges[i].first, &edges[i].second);       edge[u].push_back(i);       graph[u].push_back(v);       path[i] = make_pair(u, v);     }     dfs(1, 0);     solve(1);     printf( %d n , n);     for (int i = 1; i < n; i++)       printf( %d %d %d %d n , path[i].first, path[i].second, edges[i].first,              edges[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }   const long long mod = 1e9 + 7;   inline signed rd() {     signed ans = 0;     char last =    , ch = getchar();     while (!(ch >=  0  && ch <=  9 )) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar();     if (last ==  - ) ans = -ans;     return ans;   }   inline long long QPow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline long long QPow(long long a, long long b, const long long &mod) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     long long d = a;     if (b == 0)       x = 1, y = 0;     else {       d = exgcd(b, a % b, y, x), y -= a / b * x;     }     return d;   }   const long double PI = 3.141592653589793115997963468544185161590576171875;   const long long maxn = 100005;   struct Req {     long long s, a, b;     bool friend operator<(const Req &a, const Req &b) {       return (a.b - a.a) > (b.b - b.a);     }   } reqs[maxn];   long long arr[maxn];   long long rarr[maxn];   long long cnt[maxn];   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t, m, n, R, s;     long long k;     cin >> n >> s;     for (long long i = 1; i <= n; i++) cin >> reqs[i].s >> reqs[i].a >> reqs[i].b;     long long ans = 0;     long long sum = 0;     for (long long i = 1; i <= n; i++)       ans += reqs[i].a * reqs[i].s, sum += reqs[i].s;     sort(reqs + 1, reqs + 1 + n);     for (long long i = 1; i <= n; i++)       arr[i] = reqs[i].b - reqs[i].a, cnt[i] = reqs[i].s;     for (long long i = 1; i <= n; i++) rarr[i] = arr[n - i + 1];     signed id = 1;     while (arr[id] > 0) id++;     id--;     long long tot = 0;     long long tmp = ans;     for (long long i = 1; i <= id; i++) {       tot += cnt[i];       tmp += arr[i] * cnt[i];     }     long long num = (tot + s - 1) / s;     num *= s;     long long tmp3 = tmp;     long long re = sum % s;     num -= tot;     num -= (s - re) % s;     for (long long i = id + 1; i <= n; i++) {       if (num <= 0) break;       long long tmp1 = min(num, cnt[i]);       num -= tmp1;       tmp3 += tmp1 * arr[i];       if (num <= 0) break;     }     num = (tot + s - 1) / s;     num *= s;     num -= s;     long long tmp4 = ans;     for (long long i = 1; i <= n; i++) {       if (num <= 0) break;       long long tmp2 = min(cnt[i], num);       num -= tmp2;       tmp4 += tmp2 * arr[i];       if (num == 0) break;     }     ans = max(ans, max(tmp4, tmp3));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, a, b, ii;   int ans;   char ch[1500][1500];   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   int dp[1500][1500];   int p[100007];   void dfs(int x, int y) {     if (x > n || x < 1 || y > m || y < 1) return;     if (ch[x][y] ==  * ) {       ans++;       return;     }     if (dp[x][y] != 0) return;     dp[x][y] = ii;     for (int i = 0; i < 4; i++) {       int temp_x = x + dx[i];       int temp_y = y + dy[i];       dfs(temp_x, temp_y);     }     return;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch[i][j];       }     }     for (ii = 1; ii <= k; ii++) {       cin >> a >> b;       ans = 0;       if (!dp[a][b])         dfs(a, b);       else         ans = p[dp[a][b]];       p[ii] = ans;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     cin >> n >> m;     double mn = 101.00, x = 0.00;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       x = a / (b * 1.00);       if (mn > x) mn = x;     }     cout << fixed << setprecision(8);     cout << mn * m << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int B) { return (unsigned long long)rng() % B; }   inline double time() {     return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(                                    chrono::steady_clock::now().time_since_epoch())                                    .count()) *            1e-9;   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<string> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     vector<int> sum(m + 1);     for (int i = 0; i + 1 < m; i++) {       int u = 0;       for (int j = 1; j < n; j++) {         if (s[j][i] ==  X  and s[j - 1][i + 1] ==  X ) u = 1;       }       sum[i + 1] = sum[i] + u;     }     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       if (x == y) {         printf( YES n );         continue;       }       if (sum[y - 1] - sum[x - 1] > 0) {         printf( NO n );         continue;       } else {         printf( YES n );         continue;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, S, s, up, down, mid, mx, mn, a, b, k, l, r, ans, raod;   pair<long long, long long> p[300005];   int main() {     cin >> t;     while (t--) {       cin >> n >> S;       mn = 1e10;       mx = 0;       for (k = 1; k <= n; k++) {         cin >> a >> b;         p[k].first = a;         mn = min(mn, a);         p[k].second = b;         mx = max(mx, b);       }       ans = 0;       sort(p + 1, p + n + 1);       l = mn;       r = mx;       while (l <= r) {         long long mid = (l + r + 1) / 2;         up = 0;         down = 0;         s = 0;         for (k = 1; k <= n; k++)           if (p[k].first > mid)             up++;           else if (p[k].second < mid)             down++;         if (up >= n / 2 + 1) {           l = mid + 1;         } else if (down >= n / 2 + 1)           r = mid - 1;         else {           raod = 0;           for (k = n; k >= 1; k--) {             if (raod <= n / 2 & p[k].second >= mid) {               raod++;               s += max(mid, p[k].first);             } else               s += p[k].first;           }           if (s <= S) {             ans = mid;             l = mid + 1;           } else             r = mid - 1;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int const maxn = 100 * 1000 + 5;   int a[maxn];   int b[maxn];   int main() {     int t;     cin >> t;     int n, f1, fm1;     for (int i = 0; i < t; i++) {       f1 = maxn;       fm1 = maxn;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> a[j];         if (a[j] == 1 && f1 == maxn) f1 = j;         if (a[j] == -1 && fm1 == maxn) fm1 = j;       }       bool check = true;       for (int j = 0; j < n; j++) {         cin >> b[j];       }       for (int j = n - 1; j >= 0; j--) {         if (j > 0) {           if (a[j] < b[j] && f1 >= j) check = false;           if (a[j] > b[j] && fm1 >= j) check = false;         } else {           if (a[j] != b[j]) check = false;         }         if (!check) break;       }       if (check)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long k, i, j, b = 1;     string s =  codeforces ;     vector<int> a(10, 1);     cin >> k;     for (; b < k;)       for (i = 0; i < 10; i++) {         b /= a[i];         ++a[i];         b = b * a[i];         if (b > k - 1) break;       }     for (i = 0; i < 10; i++)       for (j = 0; j < a[i]; j++) cout << s[i];     cout <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int dp[502][502][2], n, m;   char str[502][502];   int dis;   int check(int x, int y) {     if (x < 0 or x >= n and y < 0 or y >= m)       return 0;     else       return 1;   }   int call(int x, int y, int a, int idx) {     int ham = x + y;     int paisi = n - 1 - a;     int baki = ham - paisi;     int b = m - 1 - baki;     if (check(x, y) == 0 or check(a, b) == 0) return dp[x][y][a & 1] = 0;     if (str[x][y] != str[a][b]) return dp[x][y][a & 1] = 0;     if (idx == 0) return dp[x][y][a & 1];     int dx = ((x - a) < 0 ? -(x - a) : (x - a));     int dy = ((y - b) < 0 ? -(y - b) : (y - b));     if (dis % 2 == 0) {       if (ham + 1 > dis / 2) return dp[x][y][a & 1] = 0;       if (ham + 1 == dis / 2) return dp[x][y][a & 1] = (dx + dy <= 1);     } else {       if (ham > dis / 2) return dp[x][y][a & 1] = 0;       if (ham == dis / 2) return dp[x][y][a & 1] = (x == a and y == b);     }     long long ret = 0;     ret += call(x + 1, y, a, 1 - idx);     ret += call(x + 1, y, a - 1, 1 - idx);     ret += call(x, y + 1, a, 1 - idx);     ret += call(x, y + 1, a - 1, 1 - idx);     return dp[x][y][a & 1] = ret % MOD;   }   int main() {     scanf( %d %d , &n, &m);     dis = n + m - 1;     for (int i = 0; i < n; i++) scanf( %s , str[i]);     for (int a = 0; a < n; a++) {       for (int y = m - 1; y >= 0; y--) {         int tempx = n - 1;         int tempy = y;         while (tempx >= 0 and tempy < m) {           call(tempx, tempy, a, 1);           tempy++;           tempx--;         }       }       for (int x = n - 2; x >= 0; x--) {         int tempx = x;         int tempy = 0;         while (tempx >= 0 and tempy < m) {           call(tempx, tempy, a, 1);           tempy++;           tempx--;         }       }     }     printf( %d n , dp[0][0][(n - 1) & 1]);   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 500500;   int n, k;   vector<pair<int, int> > g[N];   long long dp[N], W[N];   void dfs(int v, int pr = -1) {     dp[v] = 0;     vector<long long> u;     for (auto to : g[v]) {       if (to.first == pr) continue;       dfs(to.first, v);       dp[v] += dp[to.first] + W[to.first];       if (-W[to.first] + to.second > 0) u.push_back(-W[to.first] + to.second);     }     sort(u.begin(), u.end());     reverse(u.begin(), u.end());     for (int i = 0; i < min(k - 1, (int)u.size()); ++i) dp[v] += u[i];     if (k <= (int)u.size())       W[v] = u[k - 1];     else       W[v] = 0;   }   void solve() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) g[i].clear();     for (int i = 1; i < n; ++i) {       int x, y, w;       cin >> x >> y >> w;       g[x].push_back(make_pair(y, w));       g[y].push_back(make_pair(x, w));     }     dfs(1);     cout << dp[1] + W[1] << endl;   }   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int T;     cin >> T;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     int count = 0;     for (int a = 1; a <= n; a++) {       for (int b = a; b <= n; b++) {         int k = a * a + b * b;         int c = sqrt(k);         if (c * c == k && c <= n) count++;       }     }     cout << count;     return 0;   }