malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 3010;   int n;   int x[N], y[N], top;   pair<int, pair<int, int> > st[N * N];   bitset<N> adj[N];   int sqr(int u) { return u * u; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x[i], &y[i]);     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int dis = sqr(abs(x[i] - x[j])) + sqr(abs(y[i] - y[j]));         st[top++] = make_pair(dis, make_pair(i, j));       }     }     sort(st, st + top);     for (int i = top - 1; i >= 0; i--) {       int dis = st[i].first;       int a = st[i].second.first;       int b = st[i].second.second;       if ((adj[a] & adj[b]).any()) {         printf( %0.17f , sqrt(dis) / 2);         return 0;       }       adj[a][b] = 1;       adj[b][a] = 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void maximize(int &a, int b) { a = max(a, b); }   int absolut(int x) {     if (x < 0) return -x;     return x;   }   const int tope = 1 << 19;   const int first = 1 << 18;   struct elem {     int ls, lH, lh, lb;     int rs, rH, rh, rb;     int sol;   };   elem v[tope];   void recompute(int pos) {     elem &e = v[pos];     elem &e0 = v[2 * pos];     elem &e1 = v[2 * pos + 1];     e.ls = e0.ls + e1.ls;     e.lH = max(e0.lH, e0.ls + e1.lH);     e.lh = min(e0.lh, e0.ls + e1.lh);     e.lb = max(e0.lb, -e0.ls + e1.lb);     if (e0.lh < e0.ls + e1.lH) maximize(e.lb, -2 * e0.lh + e0.ls + e1.lH);     e.rs = e0.rs + e1.rs;     e.rH = max(e1.rH, e0.rH + e1.rs);     e.rh = min(e1.rh, e0.rh + e1.rs);     e.rb = max(e1.rb, e0.rb - e1.rs);     if (e1.rh < e0.rH + e1.rs) maximize(e.rb, -2 * e1.rh + e1.rs + e0.rH);     e.sol = max(max(e0.sol, e1.sol), max(e0.rb + e1.lH, e0.rH + e1.lb));   }   void insert(int pos, int val) {     pos += first;     elem &e = v[pos];     e.ls = val;     e.lH = max(0, val);     e.lh = min(0, val);     e.lb = absolut(val);     val *= -1;     e.rs = val;     e.rH = max(0, val);     e.rh = min(0, val);     e.rb = absolut(val);     e.sol = absolut(val);     while (pos > 1) {       pos /= 2;       recompute(pos);     }   }   int n, cases;   string s;   void insert(int pos) { insert(pos, s[pos] ==  (  ? 1 : -1); }   int main() {     cin >> n >> cases >> s;     s =     + s;     for (int i = 1; i < int(s.size()); i++) insert(i);     cout << v[1].sol << endl;     for (int cas = 0; cas < cases; cas++) {       int pos0, pos1;       cin >> pos0 >> pos1;       swap(s[pos0], s[pos1]);       insert(pos0);       insert(pos1);       cout << v[1].sol << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, plen;   char p[200], ar[200];   char res[200];   int preone[200];   bool pos, found;   bool is_start(int ind) {     if (plen + ind > n) return false;     for (int l = 0; l < plen; l++)       if (p[l] != res[l + ind]) return false;     return true;   }   bool back(int ind) {     if (ind < 0) {       return true;     }     if (res[ind] != -1) {       if (ar[ind] ==  0  && is_start(ind)) return false;       return back(ind - 1);     }     for (int i = 0; i < k; i++) {       res[ind] =  a  + i;       if (!is_start(ind))         if (back(ind - 1)) return true;     }     return false;   }   int main() {     cin >> n >> k;     cin >> p;     cin >> ar;     plen = strlen(p);     for (int i = n - plen + 1; i < n; i++) {       ar[i] =  0 ;     }     memset(res, -1, sizeof(res));     pos = true;     for (int i = 0; i < n && pos; i++) {       if (ar[i] ==  1 ) {         for (int j = 0; j < plen && pos; j++) {           if (res[i + j] != -1 && res[i + j] != p[j])             pos = false;           else             res[i + j] = p[j];         }       }     }     if (pos && back(n)) {       for (int i = 0; i < n; i++) cout << res[i];     } else       cout <<  No solution ;     cout << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1000000007LL * 1000000007LL;   const long double EPS = 1e-9;   const int SIZE = 100100;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   int n;   int a[SIZE];   int d[210][SIZE][2];   const long long md = 998244353;   const int val = 200;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 1) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int lst = 1; lst <= val; ++lst) {       if (a[n] == -1) {         d[lst][n][0] = lst;         d[lst][n][1] = 1;       } else {         d[lst][n][0] = (a[n] <= lst);         d[lst][n][1] = (a[n] == lst);       }     }     for (int i = n - 1; i >= 1; --i) {       if (a[i] != -1) {         for (int lst = 1; lst <= val; ++lst) {           d[lst][i][0] = d[a[i]][i + 1][lst < a[i]];         }         for (int lst = 1; lst <= a[i]; ++lst) {           d[lst][i][1] = d[a[i]][i + 1][lst < a[i]];         }         continue;       }       long long pref = 0, suff = 0;       for (int b = 1; b <= val; ++b) {         suff += d[b][i + 1][1];         suff %= md;       }       for (int lst = 1; lst <= val; ++lst) {         pref += d[lst][i + 1][0];         pref %= md;         suff += md - d[lst][i + 1][1];         suff %= md;         d[lst][i][0] = (pref + suff) % md;       }       suff = 0;       for (int lst = val; lst >= 1; --lst) {         d[lst][i][1] = (suff + d[lst][i + 1][0]) % md;         suff += d[lst][i + 1][1];         suff %= md;       }     }     cout << d[1][1][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   const long long int LINF = 0x3f3f3f3f3f3f3f3f;   int n, m, k, s;   const int MAXN = 2005;   int a[MAXN][MAXN];   int maxma[15], maxme[15], minma[15], minme[15];   int seq[MAXN * MAXN];   int get(int v1, int v2) {     int ret = 0;     ret = max(ret, maxma[v1] - minma[v2]);     ret = max(ret, maxme[v1] - minme[v2]);     return ret;   }   int main() {     memset(minma, INF, sizeof(minma));     memset(minme, INF, sizeof(minme));     scanf( %d%d%d , &n, &m, &k);     scanf( %d , &s);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);         int v = a[i][j];         int ma = i + j;         int me = i - j;         maxma[v] = max(maxma[v], ma);         maxme[v] = max(maxme[v], me);         minma[v] = min(minma[v], ma);         minme[v] = min(minme[v], me);       }     }     int resp = 0;     scanf( %d , &seq[0]);     for (int i = 1; i < s; i++) {       scanf( %d , &seq[i]);       resp = max(resp, max(get(seq[i], seq[i - 1]), get(seq[i - 1], seq[i])));     }     printf( %d n , resp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void make_uni(vector<int> &v) {     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());   }   int get(vector<int> &v, int d) {     return lower_bound(v.begin(), v.end(), d) - v.begin();   }   int getu(vector<int> &v, int d) {     return upper_bound(v.begin(), v.end(), d) - v.begin();   }   int n, k;   vector<tuple<int, int, int> > que;   int main() {     scanf( %d %d , &n, &k);     vector<int> c1;     for (int i = 0, a, b, c; i < n; ++i) {       scanf( %d %d %d , &a, &b, &c);       c1.emplace_back(c);       que.emplace_back(a, b, c);     }     make_uni(c1);     vector<vector<int> > c2(c1.size());     for (int i = 0, a, b, c; i < n; ++i) {       tie(a, b, c) = que[i];       c2[get(c1, c)].emplace_back(a + b);     }     for (int i = 0; i < c2.size(); ++i) make_uni(c2[i]);     vector<vector<vector<int> > > c3(c2.size());     for (int i = 0; i < c3.size(); ++i) c3[i].resize(c2[i].size());     for (int i = 0, a, b, c; i < n; ++i) {       tie(a, b, c) = que[i];       int k1 = get(c1, c);       int k2 = get(c2[k1], a + b);       for (int i = k2 + 1; i; i -= i & -i) c3[k1][i - 1].emplace_back(a);     }     for (int i = 0; i < c3.size(); ++i)       for (int j = 0; j < c3[i].size(); ++j) make_uni(c3[i][j]);     vector<vector<vector<int> > > t(c3.size());     for (int i = 0; i < c3.size(); ++i) {       t[i].resize(c3[i].size());       for (int j = 0; j < t[i].size(); ++j) t[i][j].resize(c3[i][j].size());     }     sort(que.begin(), que.end(),          [&](const tuple<int, int, int> &a, const tuple<int, int, int> &b) {            return get<0>(a) < get<0>(b);          });     long long sum = 0;     for (auto &x : que) {       int a, b, c;       tie(a, b, c) = x;       for (int l = get(c1, c - k), r = getu(c1, c + k); l != r; ++l)         for (int i = get(c2[l], a) + 1; i <= c2[l].size(); i += i & -i)           for (int j = get(c3[l][i - 1], a - b) + 1; j <= c3[l][i - 1].size();                j += j & -j)             sum += t[l][i - 1][j - 1];       int p = get(c1, c);       for (int i = get(c2[p], a + b) + 1; i; i -= i & -i)         for (int j = get(c3[p][i - 1], a) + 1; j; j -= j & -j)           t[p][i - 1][j - 1]++;     }     printf( %lld n , sum);   }
#include <bits/stdc++.h>   using namespace std;   int prime(int n) {     int val = sqrt(n), counter = 0;     ;     if (n == 1) return false;     for (int i = 2; i <= val; i++) {       if (!(n % i)) counter++;     }     if (counter) return -1;     return n;   }   int root(int n) {     int val = sqrt(n);     int x = n, flag = 0;     ;     for (int i = 2; i <= val; i++) {       if (!(n % i)) {         while (n > 1) {           if (n % i != 0) {             flag = 1;             break;           }           n = n / i;         }         if (flag) return -1;         return x;       }     }     return -1;   }   int main() {     int n, counter = 0, val, val1;     vector<int> vec;     ;     cin >> n;     for (int i = 2; i <= n; i++) {       val = prime(i);       val1 = root(i);       if (val != -1) {         counter++;         vec.push_back(val);       } else if (val1 != -1) {         counter++;         vec.push_back(val1);       }     }     cout << counter << endl;     for (int i = 0; i < counter; i++) cout << vec[i] <<    ;     cout << endl;     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 a1, a2, a3, b1, b2, b3, n, total = 0;     cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n;     if ((a1 + a2 + a3) % 5 == 0) {       total = total + (a1 + a2 + a3) / 5;     } else {       total = total + 1 + (a1 + a2 + a3) / 5;     }     if ((b1 + b2 + b3) % 10 == 0) {       total = total + (b1 + b2 + b3) / 10;     } else {       total = total + 1 + (b1 + b2 + b3) / 10;     }     if (total <= n) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int R = 300005;   const int inf = 2000000001;   const int mod = 998244353;   map<char, int> m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string second;     cin >> second;     if (k == 1) {       for (int i = 0; i < n; i++) {         m[second[i]]++;       }       int ma = 0;       for (int i = 0; i < n; i++) {         if (m[second[i]] > ma) ma = m[second[i]];       }       cout << ma;       return 0;     }     char last = second[0];     int l = 1;     for (int i = 1; i < n; i++) {       if (second[i] == second[i - 1] && l > 0) {         l++;         if (l == k) {           l = 0;           m[second[i]]++;         }       } else {         l = 1;         last = second[i];       }     }     int ma = 0;     for (int i = 0; i < n; i++) {       if (m[second[i]] > ma) ma = m[second[i]];     }     cout << ma;   }
#include <bits/stdc++.h>   long long int maxx(long long int a, long long int b) { return a > b ? a : b; }   long long int minn(long long int a, long long int b) { return a > b ? b : a; }   using namespace std;   int dx[] = {1, 1, 1, 0, 0, -1, -1, -1, 0};   int dy[] = {-1, 0, 1, 1, -1, 0, 1, -1, 0};   void boostIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int poww(long long int base, long long int exp) {     base %= 1000000007;     long long int result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % 1000000007;       base = (base * base) % 1000000007;       exp >>= 1;     }     return result;   }   const int Max_N = 100100;   int dist[101][Max_N];   vector<int> a[Max_N], type[101];   void bfs(int t) {     for (int i = 0; i <= 100000; i++) dist[t][i] = 1e9;     queue<int> q;     for (int i = 0; i < type[t].size(); i++)       q.push(type[t][i]), dist[t][type[t][i]] = 0;     while (!q.empty()) {       int node = q.front();       q.pop();       for (int i = 0; i < a[node].size(); i++) {         if (dist[t][a[node][i]] > dist[t][node] + 1) {           dist[t][a[node][i]] = dist[t][node] + 1;           q.push(a[node][i]);         }       }     }     return;   }   int main() {     boostIO();     int n, m, k, seco3nd;     cin >> n >> m >> k >> seco3nd;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       type[x].push_back(i);     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       a[u].push_back(v), a[v].push_back(u);     }     for (int i = 1; i <= k; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       priority_queue<int> q;       int ans = 0;       for (int j = 1; j <= k; j++) {         q.push(-dist[j][i]);       }       for (int j = 0; j < seco3nd; j++) {         ans = ans + -q.top();         q.pop();       }       cout << ans <<    ;     }   }
#include <stdio.h>   #include <stdlib.h>   #include <sys/time.h>      #define N 300000      int min(int a, int b) { return a < b ? a : b; }      unsigned int X;      void srand_() {    struct timeval tv;       gettimeofday(&tv, NULL);    X = tv.tv_sec ^ tv.tv_usec;    if (X % 2 == 0)     X++;   }      int rand_() {    return (X *= 3) >> 1;   }      int *ej[N], eo[N];      void append(int i, int j) {    int o = eo[i]++;       if (o >= 2 && (o & o - 1) == 0)     ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);    ej[i][o] = j;   }      int aa[N], pp[N], dd[N], mn[N];      void dfs1(int i, int d) {    int o;       dd[i] = d;    for (o = eo[i]; o--; ) {     int j = ej[i][o];        dfs1(j, d + 1);    }   }      int bb[N], a_, a, b;      void sort(int *ii, int l, int r) {    while (l < r) {     int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;        while (j < k)      if (mn[ii[j]] == mn[i_])       j++;      else if (mn[ii[j]] < mn[i_]) {       tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;       i++, j++;      } else {       k--;       tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;      }     sort(ii, l, i);     l = k;    }   }      void dfs2(int i) {    int o;       mn[i] = aa[i];    for (o = eo[i]; o--; ) {     int j = ej[i][o];        dfs2(j);     mn[i] = min(mn[i], mn[j]);    }    sort(ej[i], 0, eo[i]);   }      int dfs3(int i) {    int o;       bb[i] = ++b;    for (o = 0; o < eo[i]; o++) {     int j = ej[i][o];        if (!dfs3(j))      return 0;    }    if (aa[i] < a_ && aa[i] != a++)     return 0;    return 1;   }      int dfs4(int i) {    int o;       if (aa[i] < a_)     return 1;    if (aa[i] != a++)     return 0;    for (o = 0; o < eo[i]; o++) {     int j = ej[i][o];        if (!dfs4(j))      return 0;    }    return 1;   }      int main() {    static int ii[N];    int n, h, i, j, tmp;    long long ans;       srand_();    scanf( %d , &n);    for (i = 0; i < n; i++) {     scanf( %d , &aa[i]), aa[i]--;     ii[aa[i]] = i;    }    for (i = 0; i < n; i++)     ej[i] = (int *) malloc(2 * sizeof *ej[i]);    for (h = 0; h < n - 1; h++) {     scanf( %d%d , &i, &j), i--, j--;     append(i, j);     pp[j] = i;    }    dfs1(0, 0);    a_ = 0, ans = 0;    while (ii[a_] != 0)     ans += dd[ii[a_++]];    if (a_ > 0) {     i = ii[--a_];     while (i != 0) {      if (aa[pp[i]] != a_ + dd[i]) {       printf( NO n );       return 0;      }      tmp = aa[i], aa[i] = aa[pp[i]], aa[pp[i]] = tmp;      i = pp[i];     }    }    dfs2(0);    if (!dfs3(0) || !dfs4(0)) {     printf( NO n );     return 0;    }    printf( YES n );    printf( %lld n , ans);    for (i = 0; i < n; i++)     printf( %d  , bb[i]);    printf(  n );    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long dp[1001][2001][4];   long long solve(long long n, long long k, long long i) {     if (dp[n][k][i] != -1) {       return dp[n][k][i];     }     if (k < 1 || k > 2 * n) return 0;     if (i == 0) {       dp[n][k][i] = solve(n - 1, k, 0) + solve(n - 1, k - 1, 1) +                     solve(n - 1, k - 1, 2) + solve(n - 1, k - 2, 3);     } else if (i == 1) {       dp[n][k][i] = solve(n - 1, k, 0) + solve(n - 1, k, 1) +                     solve(n - 1, k - 1, 2) + solve(n - 1, k, 3);     } else if (i == 2) {       dp[n][k][i] = solve(n - 1, k, 0) + solve(n - 1, k - 1, 1) +                     solve(n - 1, k, 2) + solve(n - 1, k, 3);     } else {       dp[n][k][i] = solve(n - 1, k - 2, 0) + solve(n - 1, k - 1, 1) +                     solve(n - 1, k - 1, 2) + solve(n - 1, k, 3);     }     dp[n][k][i] %= mod;     return dp[n][k][i];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     long long n, k;     cin >> n >> k;     dp[1][1][0] = dp[1][1][3] = 0;     dp[1][1][1] = dp[1][1][2] = 1;     dp[1][2][0] = dp[1][2][3] = 1;     dp[1][2][1] = dp[1][2][2] = 0;     cout << (solve(n, k, 0) + solve(n, k, 1) + solve(n, k, 2) + solve(n, k, 3)) %                 mod          << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 2005;   long long int cnt[26];   long long int n, k;   bool ok(long long int l, long long int k) {     long long int k2 = k % l;     if (k2 == 0) return 1;     if (l % k2 != 0) return cnt[25] >= l;     long long int need = l / k2;     for (long long int i = 25; i >= 0; i--) {       l -= (cnt[i] / need) * need;       if (l <= 0) return 1;     }     return 0;   }   int32_t main() {     long long int t;     cin >> t;     while (t--) {       for (long long int i = 0; i < 26; i++) cnt[i] = 0;       string s;       cin >> n >> k >> s;       for (long long int i = 0; i < n; i++) cnt[s[i] -  a ]++;       sort(cnt, cnt + 26);       long long int ans;       long long int flag = 1;       for (ans = n; ans >= 1; ans--) {         for (long long int i = 1; i * i <= k and flag; i++) {           if (k % i) continue;           if (ok(ans, i)) flag = 0;           if (flag and k / i != i and ok(ans, k / i)) flag = 0;         }         if (flag == 0) break;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   const int MOD = 1000000007;   const int N = 100010;   vector<int> g[N];   multiset<int> seg[4 * N], stk;   int n, u, v, sz[N], st[N], ed[N], bk[N], cnt = 1, res[N];   void dfs(int u, int p) {     sz[u] = 1, bk[cnt] = u, st[u] = cnt++;     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       dfs(v, u);       sz[u] += sz[v];     }     ed[u] = cnt - 1;   }   void update(int n, int s, int e, int at, int val, int type) {     if (s > at || e < at) return;     if (type == 0) {       seg[n].insert(val);     } else {       seg[n].erase(seg[n].find(val));     }     if (s == e) return;     update(2 * n, s, (s + e) / 2, at, val, type);     update(2 * n + 1, (s + e) / 2 + 1, e, at, val, type);   }   inline int check(multiset<int> &mst, int mn, int mx, int OFFSET) {     int ans = 1e9;     int S = (mx - mn) / 2 + OFFSET;     multiset<int>::iterator it = mst.lower_bound(S);     for (int f = 0; f < 2; ++f) {       if (it != mst.end() && (*it != n))         ans = min(ans, max(mx - (*it - OFFSET), mn + (*it - OFFSET)));       if (it == mst.begin()) break;       it--;     }     return ans;   }   int l, r, mn, mx;   int get(int n, int s, int e) {     if (s > r || e < l) return oo;     if (s >= l && e <= r) return check(seg[n], mn, mx, 0);     return min(get(2 * n, s, (s + e) / 2), get(2 * n + 1, (s + e) / 2 + 1, e));   }   int get(int _l, int _r, int _mn, int _mx) {     l = _l;     r = _r;     mn = _mn;     mx = _mx;     if (l > r) return oo;     return get(1, 1, n);   }   void solve(int u, int p) {     pair<int, int> mx(-1, -1), mn(1e9, -1);     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       mx = max(mx, make_pair(sz[v], v));       mn = min(mn, make_pair(sz[v], v));     }     if (p != -1) {       mx = max(mx, make_pair(n - sz[u], p));       mn = min(mn, make_pair(n - sz[u], p));     }     update(1, 1, n, st[u], sz[u], 1);     int ans = max(0, mx.first);     if (mx.first != mn.first) {       if (mx.second == p) {         ans = min(ans, get(1, st[u] - 1, mn.first, mx.first));         ans = min(ans, get(ed[u] + 1, n, mn.first, mx.first));         ans = min(ans, check(stk, mn.first, mx.first, sz[u]));       } else {         ans = min(ans, get(st[mx.second], ed[mx.second], mn.first, mx.first));       }       for (int i = 0; i < g[u].size(); ++i) {         int v = g[u][i];         if (v == mx.second || v == mn.second) continue;         ans = max(ans, sz[v]);       }       if (p != -1 && mx.second != p && mn.second != p) {         ans = max(ans, n - sz[u]);       }     }     res[u] = ans;     stk.insert(sz[u]);     for (int i = 0; i < g[u].size(); ++i) {       solve(g[u][i], u);     }     stk.erase(stk.find(sz[u]));     update(1, 1, n, st[u], sz[u], 0);   }   int root = -1;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &u, &v);       if (!u) {         root = v;         continue;       }       g[u].push_back(v);     }     dfs(root, -1);     for (int i = 1; i <= n; ++i) update(1, 1, n, st[i], sz[i], 0);     solve(root, -1);     for (int i = 1; i <= n; ++i) {       printf( %d n , res[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> myvec;   long long int dp[100003];   int main() {     int t1, t2, x, index1, index2, time, n;     vector<int>::iterator it, it2;     cin >> n;     myvec.push_back(0);     dp[0] = 0;     for (int i = 0; i < n; i++) cin >> x, myvec.push_back(x);     for (int i = 1; i <= n; i++) {       time = myvec[i];       t1 = max(0, myvec[i] - 90);       t2 = max(0, myvec[i] - 1440);       it = upper_bound(myvec.begin(), myvec.end(), t1);       it2 = upper_bound(myvec.begin(), myvec.end(), t2);       index1 = it - myvec.begin();       index2 = it2 - myvec.begin();       if (myvec[i] - 90 < 0) {         dp[i] = min(dp[0] + 50, dp[0] + 120);         dp[i] = min(dp[i], dp[i - 1] + 20);       } else {         if (myvec[i] - 1440 < 0)           dp[i] = min(dp[index1 - 1] + 50, dp[0] + 120);         else           dp[i] = min(dp[index1 - 1] + 50, dp[index2 - 1] + 120);         dp[i] = min(dp[i], dp[i - 1] + 20);       }     }     for (int i = 1; i <= n; i++) cout << dp[i] - dp[i - 1] << endl;     return 0;   }