malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, K;   vector<int> arr;   struct Query {     int l, r, p, q;   };   vector<Query> query, tmp;   vector<vector<long long> > dp;   vector<int> cnt;   int lpos, rpos;   long long cost;   void solve(int k) {     query.push_back({0, N - 1, 0, N - 1});     while (query.size()) {       cnt = vector<int>(N, 0);       lpos = rpos = cost = 0;       tmp.clear();       for (int i = 0; i < query.size(); i++) {         int l = query[i].l;         int r = query[i].r;         int p = query[i].p;         int q = query[i].q;         if (l > r) continue;         int m = (l + r) >> 1;         int a = q;         dp[k][m] = 1e18;         while (rpos < max(m + 1, p)) {           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]++;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           rpos++;         }         while (rpos > max(m + 1, p)) {           rpos--;           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]--;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;         }         while (lpos < m) {           cost -= 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2;           cnt[arr[lpos]]--;           cost += 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2;           lpos++;         }         for (int i = max(m + 1, p); i <= q; i++) {           if (dp[k][m] > dp[k - 1][i] + cost) {             dp[k][m] = dp[k - 1][i] + cost;             a = i;           }           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]++;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           rpos++;         }         tmp.push_back({l, m - 1, p, a});         tmp.push_back({m + 1, r, a, q});       }       query = tmp;     }   }   int main() {     scanf( %d %d , &N, &K);     arr.resize(N);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       arr[i]--;     }     dp = vector<vector<long long> >(K + 1, vector<long long>(N));     cnt = vector<int>(N, 0);     cost = 0;     for (int i = N - 1; i >= 0; i--) {       cost -= 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2;       cnt[arr[i]]++;       cost += 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2;       dp[1][i] = cost;     }     for (int i = 2; i <= K; i++) {       solve(i);     }     printf( %lld , dp[K][0]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double d, h, v, e;     while (~scanf( %lf%lf%lf%lf , &d, &h, &v, &e)) {       double v1, v2;       v1 = (d / 2) * (d / 2) * 3.1415927 * e;       v2 = (d / 2) * (d / 2) * 3.1415927 * h;       if (v1 >= v)         printf( NO n );       else {         double time = v2 / (v - v1);         printf( YES n );         printf( %lf n , time);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int tot = 1;   int b[200005], e[200005], h[200005], p[200005], u[200005];   vector<int> ans[200005];   void add(int x, int y) {     b[++tot] = y;     e[tot] = h[x];     h[x] = tot;   }   void dfs(int k, int fa_edge) {     p[k] = 1;     for (int go = h[k]; go; go = e[go])       if (b[go] != b[fa_edge]) {         if (p[b[go]] == 0) dfs(b[go], go ^ 1);         if (u[go] == 0) ans[k].push_back(b[go]), u[go] = u[go ^ 1] = 1;       }     int sum = ans[k].size();     if (sum & 1)       sum++, ans[k].push_back(b[fa_edge]), u[fa_edge] = u[fa_edge ^ 1] = 1;     for (int i = 0; i < sum; i += 2)       printf( %d %d %d n , ans[k][i] + 1, k + 1, ans[k][i + 1] + 1);   }   int main() {     scanf( %d%d , &n, &m);     if (m % 2) {       printf( No solution );       return 0;     }     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       add(--x, --y);       add(y, x);     }     dfs(0, -1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n;   int neg = 0;   string s[N + 5];   inline long long pars(int x) {     long long ret = 0LL;     for (int i = 0; i < s[x].size(); i++) {       if (s[x][i] ==  - ) continue;       if (s[x][i] ==  . ) break;       ret *= 10;       ret += s[x][i] -  0 ;     }     if (s[x][0] ==  - ) ret *= -1;     return ret;   }   bool bisa(int x) {     for (int i = s[x].size() - 1; i >= 0; i--) {       if (s[x][i] ==  . ) break;       if (s[x][i] !=  0 ) return 1;     }     return 0;   }   int main() {     cin >> n;     long long ct = 0LL;     for (int i = 1; i <= n; i++) {       cin >> s[i];       if (s[i][0] ==  - ) neg++;       ct += pars(i);     }     for (int i = 1; i <= n; i++) {       long long tmp = pars(i);       if (bisa(i)) {         if (ct > 0) {           if (s[i][0] ==  - ) {             tmp--;             ct--;           }         } else if (ct < 0) {           if (s[i][0] !=  - ) {             tmp++;             ct++;           }         }       }       cout << tmp << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int sum;   int l, r;   int ans = 360;   int a[360];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     while (r < n) {       sum += a[r];       while (sum >= 180) {         ans = min(ans, 2 * abs(180 - sum));         sum -= a[l];         l++;       }       ans = min(ans, 2 * abs(180 - sum));       r++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long int LLINF = 1000000000000000001LL;   struct ITree {     vector<long long int> T;     int p = 1;     ITree(int n) {       while (p < n) p *= 2;       T.resize(2 * p - 1, 0);     }     int par(int x) { return (x - 1) / 2; }     void Set(int l, long long int v) {       l += p - 1;       T[l] = v;       while (l > 0) {         l = par(l);         T[l] = T[2 * l + 1] + T[2 * l + 2];       }     }     long long int Query(int l, int r) {       l += p - 1;       r += p - 1;       long long int ans = T[l];       if (l < r) ans += T[r];       while (par(l) != par(r)) {         if (l % 2 == 1) ans += T[l + 1];         if (r % 2 == 0) ans += T[r - 1];         l = par(l);         r = par(r);       }       return ans;     }   };   int main() {     ios_base::sync_with_stdio(0);     int n, k, a, b, q;     cin >> n >> k >> a >> b >> q;     ITree treeA(n), treeB(n);     vector<long long int> A(n, 0);     while (q--) {       int type;       cin >> type;       if (type == 1) {         int day, add;         cin >> day >> add;         day--;         A[day] += add;         treeB.Set(day, min((long long int)b, A[day]));         treeA.Set(day, min((long long int)a, A[day]));       } else {         int l;         cin >> l;         l--;         int r = l + k - 1;         long long int ans = 0;         if (l > 0) ans += treeB.Query(0, l - 1);         if (r < n - 1) ans += treeA.Query(r + 1, n - 1);         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   void solve() {     int a, b;     cin >> a >> b;     if (a * 2 <= b)       cout << a <<     << a * 2 <<   n ;     else       cout <<  -1 -1 n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int S = 40;   const unsigned long long mod = 998244353;   struct poly {     int a[S + 10];     inline int& operator[](const int& x) { return a[x]; }     poly() {       for (int i = 0; i < S; i++) a[i] = 0;     }     friend poly operator*(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++)         for (int j = 0; j < S && i + j < S; j++) c[i + j] += a[i] * b[j];       return c;     }     friend poly operator+(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++) c[i] = a[i] + b[i];       return c;     }     friend poly operator-(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++) c[i] = a[i] - b[i];       return c;     }     poly operator<<(const int& x) {       poly c;       for (int i = S - 1; i >= x; i--) c[i] = a[i - x];       return c;     }   } a, b, c, q, fz, fm, fz1, fm1;   int n;   unsigned long long f0[N];   unsigned long long c0[N];   unsigned long long f1[N];   unsigned long long c1[N];   unsigned long long f2[N];   unsigned long long c2[N];   unsigned long long g[N];   unsigned long long sqr[N];   inline void calc(poly& fz, poly& fm, unsigned long long* f,                    unsigned long long* c) {     for (int i = 0; i < S; i++) f[i] = (mod + fz[i]) % mod;     for (int i = 0; i < S; i++) c[i] = (mod - fm[i]) % mod;     (c[0] += 1) %= mod;     for (int i = 0; i <= n; i++)       for (int j = 1; j < S && j <= i; j++) (f[i] += f[i - j] * c[j]) %= mod;   }   int main() {     a[8] = 16;     a[6] = 12;     a[4] = 20;     a[2] = 4;     b[8] = 9;     b[6] = 2;     b[4] = 23;     b[2] = 6;     b[0] = 1;     c[8] = 4;     c[6] = -4;     c[4] = 24;     c[2] = 4;     c[0] = 4;     q[12] = -1;     q[10] = -3;     q[6] = +5;     q[2] = -3;     q[0] = +1;     scanf( %d , &n);     fz = ((b * b) << 3) - a * ((c << 3) - q);     fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4);     calc(fz, fm, f0, c0);     fz = b * q;     fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4);     calc(fz, fm, f1, c1);     fz1 = c * fm + ((b * fz) << 1);     fm1 = fm * (q - (c << 3));     calc(fz1, fm1, f2, c2);     g[0] = 1;     g[2] = 1;     for (int i = 4; i <= n; i++) g[i] = (g[i - 2] + g[i - 4]) % mod;     for (int i = 1; i <= n; i++) sqr[i] = (unsigned long long)i * i % mod;     unsigned long long ans = (g[n - 1] + g[n - 3]) * sqr[n - 1] % mod * n % mod;     for (int i = 2; i <= n - 2; i++) {       unsigned long long ret = 0;       (ret += g[i - 1] * f0[n - i - 1]) %= mod;       (ret += g[i - 2] * f1[n - i - 2] * 2) %= mod;       if (3 <= i && i <= n - 3) (ret += g[i - 3] * f2[n - i - 3]) %= mod;       (ans += ret * sqr[i - 1] % mod * i) %= mod;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k, m, x, ans = 0;     cin >> n >> k >> m;     vector<pair<long long, long long> > v;     for (int i = 0; i < n; i++) {       cin >> x;       if (v.empty() || (v.back().first != x)) {         v.push_back({x, 1});       } else if (v.back().first == x) {         v.back().second = (v.back().second + 1) % k;         if (v.back().second == 0) v.pop_back();       }     }     if (v.size() == 0) return cout << 0, 0;     if (v.size() == 1) {       return cout << ((v[0].second * m) % k), 0;     }     for (auto &i : v) {       ans += m * i.second;     }     if (m == 1) return cout << ans, 0;     long long rem = 0;     int back = v.size() - 1, front = 0;     while (back > front) {       if ((v[front].first != v[back].first)) {         break;       } else {         rem += ((v[front].second + v[back].second) -                 ((v[front].second + v[back].second) % k)) *                (m - 1);         if ((v[front].second + v[back].second) % k) break;       }       back--;       front++;     }     if (back == front) {       rem += ((v[back].second) * m) - ((v[back].second) * m) % k;       if (((v[back].second) * m) % k == 0) {         back--;         front++;       }     }     if (back < front)       while (back >= 0) {         if ((v[front].first != v[back].first)) {           break;         } else {           rem += ((v[front].second + v[back].second) -                   ((v[front].second + v[back].second) % k));           if ((v[front].second + v[back].second) % k) break;         }         back--;         front++;       }     cout << (ans - rem);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long A = 100000000000000LL, N = 300005;   long long p, d, limit;   long long cal(long long p) {     int x = 0;     if (p % 10 != 9) return 0;     while (p % 10 == 9) {       x++;       p /= 10;     }     return x;   }   int main() {     cin >> p >> d;     limit = p - d;     long long j = p;     long long length = log10(p) + 1;     long long initial = cal(p);     int i = 0;     long long powerr = 10;     while (true) {       j = p - p % powerr - 1;       if (j == -1) break;       if (j < limit) break;       powerr *= 10;     }     powerr /= 10;     j = p - p % powerr - 1;     if (j < limit) j = p;     if (j >= limit and powerr == 1) j = p;     if (initial >= (log10(powerr))) j = p;     cout << j;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int data[100];     int n, x, y;     cin >> n >> x >> y;     int c = 0;     for (int i = 0; i < n; i++) {       cin >> data[i];       if (data[i] <= x) c++;     }     if (x > y) {       cout << n;     } else {       if (c % 2 == 0) {         cout << c / 2;       } else         cout << (c / 2) + 1;     }     char a;     cin >> a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int n, c[100005], dp[100005][2], i, j;     cin >> n;     string s[100005], rs[100005];     for (i = 1; i <= n; i++) cin >> c[i];     for (i = 1; i <= n; i++) {       cin >> s[i];       rs[i] = s[i];       dp[i][0] = dp[i][1] = 1e15;       reverse(rs[i].begin(), rs[i].end());     }     dp[1][0] = 0;     dp[1][1] = c[1];     for (i = 2; i <= n; i++) {       if (s[i] < s[i - 1] && s[i] < rs[i - 1] && rs[i] < rs[i - 1] &&           rs[i] < s[i - 1]) {         cout <<  -1 ;         return 0;       }       if ((string)s[i] >= s[i - 1] && dp[i - 1][0] != 1e15)         dp[i][0] = min(dp[i][0], dp[i - 1][0]);       if ((string)s[i] >= rs[i - 1] && dp[i - 1][1] != 1e15)         dp[i][0] = min(dp[i][0], dp[i - 1][1]);       if ((string)rs[i] >= s[i - 1] && dp[i - 1][0] != 1e15)         dp[i][1] = min(dp[i][1], c[i] + dp[i - 1][0]);       if ((string)rs[i] >= rs[i - 1] && dp[i - 1][1] != 1e15)         dp[i][1] = min(dp[i][1], c[i] + dp[i - 1][1]);     }     long long int ans = min(dp[n][0], dp[n][1]);     if (ans == 1e15)       cout <<  -1 ;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long unsigned, long long unsigned>,       pair<long long unsigned, long long unsigned> >       dp;   long long unsigned n;   void read() {     cin >> n;     return;   }   pair<long long unsigned, long long unsigned> find(long long unsigned s,                                                     long long unsigned mx) {     if (s <= 9) return make_pair(0, s);     if (dp.find(make_pair(s, mx)) != dp.end()) return dp[make_pair(s, mx)];     long long unsigned t, r, m;     pair<long long unsigned, long long unsigned> &ans = dp[make_pair(s, mx)];     t = 1;     while (t * 10 <= s) t *= 10;     r = s % t;     s = s / t;     while (1) {       m = max(mx, s);       pair<long long unsigned, long long unsigned> f = find(r, m);       ans.first += f.first;       if (s == 0) {         ans.second = f.second;         break;       }       if (f.second >= m) {         ans.first += 2;         r = t - m;       } else {         ans.first++;         r = t - (m - f.second);       }       s--;     }     return ans;   }   void solve() {     read();     pair<long long unsigned, long long unsigned> cvp = find(n, 0);     cout << cvp.first + !!cvp.second << endl;     return;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10001001;   int min_div[MAXN];   vector<long long> primes;   void criba() {     for (int i = (int)0; i < (int)MAXN; i++) min_div[i] = i;     for (int i = (int)2; i < (int)MAXN; i++) {       if (min_div[i] != i) continue;       primes.push_back(i);       for (int j = i + i; j < MAXN; j += i) {         min_div[j] = i;       }     }   }   void solve(long long* acum) {     long long now = acum[MAXN - 1];     for (int i = MAXN - 2; i > 1; i--) {       now += acum[i];       acum[i] = now;     }     for (int i = MAXN - 1; i > 1; i--)       if (acum[i]) {         if (min_div[i] == i) continue;         int a = min_div[i];         int b = i / min_div[i];         acum[a] += acum[i];         acum[b] += acum[i];         acum[i] = 0;       }   }   long long acum_a[MAXN];   bool test(long long n) {     for (int i = (int)0; i < (int)primes.size(); i++) {       long long e = 0;       long long n_t = n;       while (n_t) {         e += (n_t /= (long long)primes[i]);       }       if (e < acum_a[primes[i]]) return false;     }     return true;   }   int main() {     criba();     int k;     scanf( %d , &k);     long long lo = 1, hi = 0;     for (int i = (int)0; i < (int)k; i++) {       int n = 1000101;       scanf( %d , &n);       acum_a[n]++;       hi += n;     }     solve(acum_a);     while (lo < hi) {       long long mid = (lo + hi) / 2LL;       if (test(mid)) {         hi = mid;       } else {         lo = mid + 1;       }     }     cout << lo << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 5;   int n;   char c[N];   int main() {     int T = 1;     scanf( %d , &T);     while (T--) {       scanf( %s , c + 1);       n = strlen(c + 1);       printf( %d n , 4);       printf( L 2 n );       printf( L 2 n );       printf( R 2 n );       n += 2;       n += n - 2;       printf( R %d n , n - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char grid[1005][1005];   int lewo[1005][1005], prawo[1005][1005], gora[1005][1005], dol[1005][1005];   bool odwiedzony[1005][1005];   vector<pair<int, int> > przedzialy_x[1005], przedzialy_y[1005];   vector<pair<pair<int, int>, int> > wynik;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int y, x, xd = 0, wszystkie = 0;     cin >> y >> x;     for (int i = 1; i <= y; i++) {       for (int j = 1; j <= x; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  * ) wszystkie++;         if (grid[i][j] ==  . )           lewo[i][j] = j;         else           lewo[i][j] = lewo[i][j - 1];       }       prawo[i][x + 1] = x + 1;       for (int j = x; j > 0; j--) {         if (grid[i][j] ==  . )           prawo[i][j] = j;         else           prawo[i][j] = prawo[i][j + 1];       }     }     for (int i = 1; i <= x; i++) {       for (int j = 1; j <= y; j++) {         if (grid[j][i] ==  . )           gora[j][i] = j;         else           gora[j][i] = gora[j - 1][i];       }       dol[y + 1][i] = y + 1;       for (int j = y; j > 0; j--) {         if (grid[j][i] ==  . )           dol[j][i] = j;         else           dol[j][i] = dol[j + 1][i];       }     }     for (int i = 2; i < y; i++)       for (int j = 2; j < x; j++) {         int pom = min(min(j - lewo[i][j] - 1, prawo[i][j] - j - 1),                       min(i - gora[i][j] - 1, dol[i][j] - i - 1));         if (pom && grid[i][j] ==  * ) {           przedzialy_x[i].push_back({j - pom, j + pom});           przedzialy_y[j].push_back({i - pom, i + pom});           wynik.emplace_back(make_pair(make_pair(i, j), pom));         }       }     for (int i = 1; i <= y; i++) {       przedzialy_x[i].push_back({1e9, 1e9});       sort(przedzialy_x[i].begin(), przedzialy_x[i].end());       int indeks = 0;       for (int j = 1; j <= x; j++) {         while (przedzialy_x[i][indeks].second < j) indeks++;         if (grid[i][j] ==  *  && przedzialy_x[i][indeks].first <= j) {           xd++;           odwiedzony[i][j] = true;         }       }     }     for (int i = 1; i <= x; i++) {       przedzialy_y[i].push_back({1e9, 1e9});       sort(przedzialy_y[i].begin(), przedzialy_y[i].end());       int indeks = 0;       for (int j = 1; j <= y; j++) {         while (przedzialy_y[i][indeks].second < j) indeks++;         if (grid[j][i] ==  *  && przedzialy_y[i][indeks].first <= j &&             !odwiedzony[j][i])           xd++;       }     }     if (xd == wszystkie) {       int aha = wynik.size();       cout << aha <<   n ;       for (int i = 0; i < aha; i++)         cout << wynik[i].first.first <<     << wynik[i].first.second <<                  << wynik[i].second <<   n ;     } else       cout <<  -1 n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   void qr(int &x) { scanf( %d , &x); }   int n, sz[N], f[N], root, c[N];   long long k, mn, mx;   struct edge {     int y, next;   } a[N * 2];   int len, last[N];   void ins(int x, int y) {     a[++len] = (edge){y, last[x]};     last[x] = len;   }   void dfs1(int x, int fa) {     sz[x] = f[x] = 1;     for (int k = last[x], y; k; k = a[k].next) {       y = a[k].y;       if (y ^ fa) {         dfs1(y, x);         sz[x] += sz[y];         mn += sz[y] & 1;         mx += min(sz[y], n - sz[y]);         f[x] = max(f[x], sz[y]);       }     }     f[x] = max(f[x], n - sz[x]);   }   void dfs2(int x, int fa) {     sz[x] = 1;     for (int k = last[x], y; k; k = a[k].next) {       y = a[k].y;       if (y ^ fa) {         dfs2(y, x);         sz[x] += sz[y];       }     }     c[sz[x]]++;   }   vector<int> d[N];   int son[N], tot, A[N], B[N];   void dfs3(int x, int fa) {     sz[x] = 1;     for (int k = last[x], y; k; k = a[k].next)       if ((y = a[k].y) ^ fa) dfs3(y, x), sz[x] += c[y];     int C = (sz[x] - c[x]) >> 1, st = 1, ed;     son[tot = 1] = x;     d[x].push_back(x);     for (int k = last[x], y; k; k = a[k].next)       if ((y = a[k].y) ^ fa) son[++tot] = y;     ed = tot;     for (int i = 1; i <= C; i++) {       while (d[son[st]].empty()) st++;       A[i] = d[son[st]].back();       d[son[st]].pop_back();       while (d[son[ed]].empty()) ed--;       B[i] = d[son[ed]].back();       d[son[ed]].pop_back();     }     for (int i = 1; i <= C; i++) printf( %d %d n , A[i], B[C - i + 1]);     for (int i = 2; i <= tot; i++) {       if (d[son[i]].size() > d[x].size()) swap(d[x], d[son[i]]);       for (int j : d[son[i]]) d[x].push_back(j);     }   }   int main() {     qr(n);     scanf( %lld , &k);     for (int i = 1, x, y; i < n; i++) qr(x), qr(y), ins(x, y), ins(y, x);     dfs1(1, 0);     if (!(mn <= k && k <= mx) || (k - mn) % 2 == 1) puts( NO ), exit(0);     root = 1;     for (int i = 2; i <= n; i++)       if (f[i] < f[root]) root = i;     dfs2(root, 0);     int p = n - 1;     for (; p > 1; p--)       if (mx - c[p] * 2 >= k) {         mx -= c[p] * 2;         c[p - 2] += c[p];       } else         break;     for (int i = 1; i <= n; i++) c[i] = min(sz[i], p - (p + sz[i]) % 2);     c[root] = 0;     for (int i = 1; i <= n; i++)       if (c[i] == p && mx > k) {         mx -= 2;         c[i] -= 2;       }     puts( YES );     dfs3(root, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 111111;   const int INF = 0x3f3f3f3f;   int vis[maxn];   bool selected[maxn];   int n, m;   vector<int> adj[maxn];   bool test[maxn];   double elapsed() { return clock() / (double)CLOCKS_PER_SEC; }   bool dfs(int v) {     if (selected[v] == true) return false;     vis[v] = -1;     for (auto w : adj[v]) {       if (vis[w] == 0) {         if (dfs(w)) return true;       } else if (vis[w] == -1) {         for (int i = 1; i <= n; i++) {           if (vis[i] != -1) test[i] = true;         }         return true;       }     }     vis[v] = 1;     return false;   }   bool check() {     memset(vis, 0, sizeof vis);     for (int i = 1; i <= n; i++) {       if (!vis[i] && dfs(i)) return false;     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);     }     vector<int> emp;     for (int i = 0; i < n; ++i) emp.push_back(i + 1);     random_shuffle(emp.begin(), emp.end());     for (int i = 0; elapsed() <= 0.95 and i < emp.size(); i++) {       selected[emp[i]] = true;       if (!test[emp[i]] && check()) {         printf( %d n , emp[i]);         return 0;       }       selected[emp[i]] = false;     }     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   long long a[212345], sumi, wow, i;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       sumi += a[i];     }     wow = 0;     for (i = 0; i < n; i++) {       wow += a[i];       if (2 * wow >= sumi) break;     }     cout << i + 1 << endl;     return 0;   }