malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 100007;   long long n, x[N], y[N];   pair<long long, long long> mid(long long a, long long b) {     long long xx = (x[a] + x[b]) / 2;     long long yy = (y[a] + y[b]) / 2;     return {xx, yy};   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> x[i] >> y[i];       x[i] *= 2;       y[i] *= 2;     }     if (n % 2) {       cout <<  NO n ;       return 0;     }     pair<long long, long long> midpoint = mid(0, n / 2);     for (long long i = 1; i < n / 2; ++i) {       pair<long long, long long> cur = mid(i, i + n / 2);       if (cur != midpoint) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %I64d , &n);       for (long long i = n;; i += i)         if (i * (n + 1) % (4 * n) == 0) {           printf( %I64d n , i + 1);           break;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   int cnt[30];   int main() {     int k, i;     scanf( %s , s);     scanf( %d , &k);     for (i = 0; s[i]; i++) cnt[s[i] -  a ]++;     if (k >= i) {       puts( 0 n );       return 0;     }     while (1) {       int minx = 1 << 30, mini;       for (i = 0; i < 30; i++) {         if (cnt[i]) {           minx = min(cnt[i], minx);           if (minx == cnt[i]) mini = i;         }       }       if (k >= cnt[mini]) {         k -= cnt[mini];         cnt[mini] = 0;       } else         break;     }     int ans = 0;     for (i = 0; i < 30; i++)       if (cnt[i]) ans++;     printf( %d n , ans);     for (i = 0; s[i]; i++) {       if (cnt[s[i] -  a ]) putchar(s[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   vector<int> adj[100005];   vector<int> ans;   vector<int> vis;   int dfs(int s) {     if (s >= n) return 0;     vis[s] = 1;     int flag = 0;     for (int i = 0; i < adj[s].size(); i++) {       if (!vis[adj[s][i]]) {         flag = 1;         ans[s] += dfs(adj[s][i]);       }     }     if (!flag) {       ans[s] = 1;     }     return ans[s];   }   int main() {     cin >> n;     ans.resize(n, 0);     vis.resize(n, 0);     for (int i = 0; i < n - 1; i++) {       cin >> p;       adj[i + 1].push_back(p - 1);       adj[p - 1].push_back(i + 1);     }     dfs(0);     sort(ans.begin(), ans.end());     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> ind;     int num = 0, add = 0;     for (int i = 0; i < n; ++i) {       if (a[i] == i)         ++num;       else if (a[a[i]] == i)         add = 2;     }     if (!add) add = 1;     if (num == n) add = 0;     cout << num + add << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename... Args>   void read(Args &...args) {     ((cin >> args), ...);   }   template <typename... Args>   void show(Args... args) {     ((cout << args <<    ), ...);   }   void solve() {     int n;     read(n);     vector<int> v(n);     for (auto &it : v) cin >> it;     int l = 0, r = n - 1, x = 0;     string s;     while (l <= r) {       if (min(v[l], v[r]) > x) {         if (v[l] < v[r]) {           s.push_back( L );           x = v[l++];         } else if (v[r] < v[l]) {           s.push_back( R );           x = v[r--];         } else {           int ll = l + 1, rr = r - 1;           while (ll < r && v[ll] > v[ll - 1]) ll++;           while (rr > l && v[rr] > v[rr + 1]) rr--;           if (ll - l > r - rr) {             x = ll - l;             while (x--) s.push_back( L );           } else {             x = r - rr;             while (x--) s.push_back( R );           }           break;         }       } else if (max(v[l], v[r]) > x) {         if (v[l] > v[r]) {           s.push_back( L );           x = v[l++];         } else {           s.push_back( R );           x = v[r--];         }       } else {         break;       }     }     cout << int(s.size()) <<   n  << s;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int cmp(int x, int y) {     int x1 = 10 - x % 10;     int y1 = 10 - y % 10;     return x1 < y1;   }   int main() {     int i, n, m;     cin >> n >> m;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + 1 + n, cmp);     for (i = 1; i <= n; i++) {       if (a[i] == 100) continue;       int x = 10 - a[i] % 10;       if (m < x) {         a[i] += m;         m = 0;         break;       }       a[i] += x;       m -= x;     }     int s = 0;     for (i = 1; i <= n; i++) {       s += a[i] / 10;     }     if (m > 0) {       for (i = 1; i <= n; i++) {         if (m + a[i] >= 100) {           s += (100 - a[i]) / 10;           m -= (100 - a[i]);         } else {           s += m / 10;           m = 0;           break;         }       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9 + 10;   const int MOD = (int)1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, a, b, c, t;     cin >> n >> a >> b >> c >> t;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     if (c < b) return cout << n * a, 0;     long long ans = 0;     for (int i = 0; i < n; i++) ans += a + (t - v[i]) * (c - b);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int N = 510000, M = N << 1;   int n, hd[N], to[M], nxt[M], noedg = 1, size[N];   long long buc[N], f[N], ans = inf;   vector<int> app[N];   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   inline void addEdg(int x, int y) {     nxt[++noedg] = hd[x], hd[x] = noedg, to[noedg] = y;     nxt[++noedg] = hd[y], hd[y] = noedg, to[noedg] = x;     return;   }   inline long long sq(long long x) { return x * x; }   void dfs(int now, int fa) {     size[now] = 1, f[now] = inf;     for (register int i = hd[now], v; i; i = nxt[i]) {       if ((v = to[i]) == fa) continue;       dfs(v, now), size[now] += size[v];     }     buc[0] = 0, app[now].push_back(0);     for (register int i = hd[now], v; i; i = nxt[i]) {       if ((v = to[i]) == fa) continue;       for (register int j = 0, sz = app[now].size(); j < sz; ++j)         ans = min(ans, buc[app[now][j]] + f[v] + sq(n - app[now][j] - size[v]));       if (buc[size[v]] == inf) app[now].push_back(size[v]);       buc[size[v]] = min(buc[size[v]], f[v]);       f[now] = min(f[now], f[v] + sq(size[now] - size[v]));     }     for (register int i = 0, sz = app[now].size(); i < sz; ++i)       buc[app[now][i]] = inf;     if (f[now] == inf) f[now] = 1;     return;   }   int main() {     int x, y;     read(n);     for (register int i = 1; i < n; ++i)       read(x), read(y), addEdg(x, y), buc[i] = inf;     dfs(1, 0);     cout << ((long long)n * (2 * n - 1) - ans) / 2;     return 0;     int qwq;   }
#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   using namespace std;   const long long N = 5e5 + 3;   const long long mod = 998244353;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   long long test = 1, n, m, x, y, k, b[N], a[N];   vector<long long> v;   long long ch(int l, int r) {     long long mx = max(a[l], a[r]), res = 0;     set<long long> s1, s2;     for (int i = l + 1; i < r; i++) {       if (a[i] > mx) s1.insert(i);       s2.insert(i);     }     if (s2.size() < k and s1.size()) {       cout << -1 <<   n ;       exit(0);     }     if (k * x > y) {       res = (s2.size() / k) * y + (s2.size() % k) * x;     } else {       if (s1.size())         res = y + (s2.size() - k) * x;       else         res = s2.size() * x;     }     return res;   }   void solve() {     cin >> n >> m >> y >> k >> x;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) cin >> b[i];     a[0] = a[n + 1] = b[0] = b[m + 1] = 0;     int j = 1;     v.push_back(0);     for (int i = 1; i <= n; i++)       if (a[i] == b[j]) j++, v.push_back(i);     v.push_back(n + 1);     if (j != m + 1) {       cout << -1 <<   n ;       return;     }     long long ans = 0;     for (int i = 1; i <= m + 1; i++) {       ans += ch(v[i - 1], v[i]);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(15);     ;     for (int i = 1; i <= test; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e9 + 999999;   const long long Mod = (long long)1e9 + 7;   const long long MaXN = (long long)1e18;   const int N = (int)1e6 + 7;   const int MaXI = (int)1e9;   const int Mass = (int)2e5;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int b = 0, g = 0, r = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  B ) {         b++;       }       if (s[i] ==  G ) {         g++;       }       if (s[i] ==  R ) {         r++;       }     }     if (b == n) {       cout <<  B ;       return 0;     } else if (g == n) {       cout <<  G ;       return 0;     } else if (r == n) {       cout <<  R ;       return 0;     }     if (r > 1 || g > 1) {       cout <<  B ;     } else if (r == 1 && g == 1) {       cout <<  B ;     }     if (b > 1 || r > 1) {       cout <<  G ;     } else if (b == 1 && r == 1) {       cout <<  G ;     }     if (b > 1 || g > 1) {       cout <<  R ;     } else if (b == 1 && g == 1) {       cout <<  R ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, vector<long long> &a) {     for (auto i : a) out << i <<    ;     return out;   }   istream &operator>>(istream &in, vector<long long> &a) {     for (auto &i : a) in >> i;     return in;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     long long q;     cin >> q;     while (q--) {       string a, b, c;       cin >> a >> b >> c;       bool boo = 0;       for (long long i = 0; i < a.size(); ++i) {         if (c[i] != b[i] && c[i] != a[i]) {           cout <<  NO                 <<   n ;           boo = 1;           break;         }       }       if (!boo)         cout <<  YES               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q;     char c;     vector<int> a(10);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c;       if (c ==  L ) {         q = 0;         while (a[q] == 1) {           q++;         }         a[q] = 1;       } else if (c ==  R ) {         q = 9;         while (a[q] == 1) {           q--;         }         a[q] = 1;       } else {         q = (int)c - 48;         a[q] = 0;       }     }     for (int i = 0; i < 10; i++) {       cout << a[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int bits[32];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       bits[x]++;     }     sort(v.begin(), v.end());     long long ans = 0;     for (int j = 0; j < 31; j++) {       for (auto &x : v) {         if ((x & 1) && bits[j]) {           x--;           ans++;           bits[j]--;         }       }       for (auto &x : v) {         while (x && bits[j]) {           x--;           ans++;           bits[j]--;         }       }       for (auto &x : v) {         x >>= 1;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1009;   pair<int, pair<int, int> > sr[Maxn * Maxn];   int n, m;   int check(int k) {     bitset<Maxn> row[Maxn];     for (int i = 0; i <= k; i++) {       int x = sr[i].second.first, y = sr[i].second.second;       row[x].set(y);     }     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         if ((row[i] & row[j]).count() >= 2) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int p;         scanf( %d , &p);         sr[i * m + j] = make_pair(-p, make_pair(i, j));       }     sort(sr, sr + n * m);     int l = 0, r = n * m - 1;     while (l < r - 1) {       int mid = l + r >> 1;       if (check(mid))         r = mid;       else         l = mid;     }     cout << -sr[r].first << endl;   }
#include <bits/stdc++.h>   using namespace std;   double dp[128][128];   int x[128], y[128];   int N, K, x_0, y_0;   double eps;   double dist(double x1, double y1) {     return sqrt((x_0 - x1) * (x_0 - x1) + (y_0 - y1) * (y_0 - y1));   }   double hit(double R, double D) {     return (D <= R) ? 1. : exp(1 - D * D / R / R);   }   double P(double R) {     fill(*dp, *dp + 128 * 128, 0.);     dp[0][1] = hit(R, dist(x[0], y[0]));     dp[0][0] = 1 - dp[0][1];     for (int i = 1; i < N; i++)       for (int j = 0; j <= N; j++) {         double ph = hit(R, dist(x[i], y[i]));         dp[i][j] += (1 - ph) * dp[i - 1][j];         if (j >= 1) dp[i][j] += ph * dp[i - 1][j - 1];       }     double ret = 0.;     for (int j = 0; j < K; j++) ret += dp[N - 1][j];     return ret;   }   int main() {     cin >> N >> K >> eps >> x_0 >> y_0;     eps /= 1000.;     for (int i = 0; i < N; i++) cin >> x[i] >> y[i];     double lo = 0., hi = 1000000.;     for (int x = 0; x < 50; x++) {       double ave = (lo + hi) / 2.;       if (P(ave) <= eps)         hi = ave;       else         lo = ave;     }     cout << setprecision(10) << fixed << hi << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n / 2; i++) {       for (j = 1; j <= m; j++) {         printf( %d %d n , i, j);         printf( %d %d n , n - i + 1, m + 1 - j);       }     }     if (n % 2 == 1) {       for (j = 1; j <= m / 2; j++) {         printf( %d %d n , (n + 1) / 2, j);         printf( %d %d n , (n + 1) / 2, m + 1 - j);       }       if (m % 2 == 1) printf( %d %d n , (n + 1) / 2, (m + 1) / 2);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a, b;       cin >> a >> b;       if (a % b == 0) {         cout << 0 <<   n ;       } else {         long long int g = a / b;         long long int ans = (b * (g + 1) - a);         cout << ans <<   n ;       }     }     return 0;   }
#include <iostream>   #include <cstdio>   #include <cassert>   #include <cstring>   #include <cmath>   #include <functional>   #include <algorithm>   #include <utility>   #include <vector>   #include <string>   #include <map>   #include <set>   using namespace std;   using ll = long long;   using PII = pair<int,int>;   const ll inf = 1ll << 60;   const int maxn = 200000 + 5;      int n, s;      struct DS {     ll base = 0;     map<int, ll> f;     set<pair<ll,int> > bag;        int size() {       return f.size();     }        bool count(int x) {       return f.count(x);     }        ll get(int x) {       if (f.count(x)) {         return f[x] + base;       } else {         return inf;       }     }        void set(int x, ll v) {       if (f.count(x)) {         v = std::min(v, erase(x));       }       v -= base;       f[x] = v;       bag.emplace(v, x);     }        ll erase(int x) {       if (f.count(x)) {         ll val = f[x];         f.erase(x);         bag.erase({ val, x });         return val + base;       } else {         return inf;       }     }        ll min() {       return bag.begin()->first + base;     }   };      int main() {     scanf( %d%d , &n, &s);     vector<DS> stk { {} };     vector<int> cond;     stk.back().set(0, 0);     for (int i = 1; i <= n; i++) {       char op[8];       scanf( %s , op);       if (op[0] ==  s ) {         int x, v;         scanf( %d%d , &x, &v);         ll mn = stk.back().min();         stk.back().base += v;         if (x != s) {           stk.back().set(x, mn);         }       } else if (op[0] ==  i ) {         int x;         scanf( %d , &x);         DS u;         u.set(x, stk.back().get(x));         stk.back().erase(x);         stk.push_back(u);         cond.push_back(x);       } else if (op[0] ==  e ) {         int c = cond.back();         cond.pop_back();            int sz = stk.size();         auto& x = stk[sz - 1];         auto& y = stk[sz - 2];            if (x.size() > y.size()) swap(x, y);         for (auto u: x.f) {           y.set(u.first, x.get(u.first));         }         stk.pop_back();       }     }     printf( %lld n , stk.back().min());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans;   vector<long long> a;   int main() {     cin >> n;     a.resize(n);     long long min_A = 1 << 31 - 1;     long long max_A = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > max_A) {         max_A = a[i];       }       if (a[i] < min_A) {         min_A = a[i];       }     }     for (int i = 0; i < n; i++) {       if (a[i] < max_A && a[i] > min_A) {         ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sol[200000];   long long solve(int in, vector<int> v[], int visited[], int a[]) {     if (sol[in] != -2e16) {       return sol[in];     }     long long ans = a[in];     visited[in] = 1;     for (int i = 0; i < v[in].size(); i++) {       if (visited[v[in][i]] == 0) {         ans += solve(v[in][i], v, visited, a);       }     }     visited[in] = 0;     sol[in] = ans;     return ans;   }   long long max1[200000];   long long maxx(int in, vector<int> v[], int visited[], long long sol[]) {     if (max1[in] != -2e16) {       return max1[in];     }     long long ans = sol[in];     visited[in] = 1;     for (int i = 0; i < v[in].size(); i++) {       if (visited[v[in][i]] == 0) {         long long xx = maxx(v[in][i], v, visited, sol);         if (xx > ans) {           ans = xx;         }       }     }     visited[in] = 0;     max1[in] = ans;     return ans;   }   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> v[n];     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       v[x - 1].push_back(y - 1);       v[y - 1].push_back(x - 1);     }     int vis[n];     for (int i = 0; i < n; i++) {       vis[i] = 0;     }     for (int i = 0; i < 200000; i++) {       sol[i] = -2e16;       max1[i] = -2e16;     }     long long xx = solve(0, v, vis, a);     long long xy = maxx(0, v, vis, sol);     queue<int> q;     q.push(0);     long long ans = -2e16;     while (!q.empty()) {       int p = q.front();       q.pop();       vis[p] = 1;       priority_queue<long long> pq;       for (int i = 0; i < v[p].size(); i++) {         if (vis[v[p][i]] == 0) {           pq.push(max1[v[p][i]]);           q.push(v[p][i]);         }       }       if (pq.size() < 2) {         continue;       } else {         long long val = pq.top();         pq.pop();         val += pq.top();         if (val > ans) {           ans = val;         }       }     }     if (ans == -2e16) {       cout <<  Impossible  << endl;       return 0;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long G[500][500], d[500][500];   long long x[500], n, m;   void floyd(long long k) {     for (long long i = 0; i < n; i++)       if (i != k) {         for (long long j = 0; j < n; j++)           if (i != j && j != k)             if (G[i][j] > G[i][k] + G[k][j]) {               G[i][j] = G[i][k] + G[k][j];             }       }   }   void build_graph() {     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         scanf( %I64d , &G[i][j]);       }     }     for (long long i = 0; i < n; i++) {       scanf( %I64d , &x[n - i - 1]);       x[n - i - 1]--;     }   }   void solve() {     m = 0;     long long ans[500] = {0};     memcpy(d, G, sizeof(G));     for (long long i = 0; i < n; i++) {       m++;       floyd(x[i]);       for (long long j = 0; j < m; j++) {         for (long long k = 0; k < m; k++) {           ans[n - i - 1] += G[x[j]][x[k]];         }       }     }     printf( %I64d , ans[0]);     for (long long i = 1; i < n; i++) printf(  %I64d , ans[i]);     putchar(10);   }   int main() {     while (~scanf( %I64d , &n)) {       build_graph();       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char inp[200005];   int main() {     bool ok;     queue<int> zeroes, ones;     vector<int> vec[200005];     int n_vec = 0, n_z = 0, n_o = 0, tam;     scanf( %s , inp);     tam = strlen(inp);     if (inp[0] ==  1 )       cout << -1 << endl;     else {       vec[n_vec++].push_back(0);       zeroes.push(0);       n_z++;       ok = true;       for (int i = 1; i < tam; i++) {         if (inp[i] ==  0 ) {           if (n_o == 0) {             vec[n_vec++].push_back(i);             zeroes.push(n_vec - 1);             n_z++;           } else {             int q = ones.front();             vec[q].push_back(i);             zeroes.push(q);             n_z++;             ones.pop();             n_o--;           }         } else {           if (n_z == 0) {             ok = false;             break;           } else {             int q = zeroes.front();             vec[q].push_back(i);             ones.push(q);             n_o++;             zeroes.pop();             n_z--;           }         }       }       if (n_o != 0) ok = false;       if (!ok)         printf( -1 n );       else {         printf( %d n , n_vec);         vector<int>::iterator vit;         for (int i = 0; i < n_vec; i++) {           printf( %d , vec[i].size());           vit = vec[i].begin();           while (vit != vec[i].end()) {             printf(  %d , (*vit) + 1);             vit++;           }           printf(  n );         }       }     }     return 0;   }