malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<string> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];       }       int a[26] = {0};       for (auto s : v) {         for (auto i : s) {           a[i -  a ]++;         }       }       int f = 0;       for (int i = 0; i < 26; i++) {         if (a[i] % n) {           f = 1;           break;         }       }       if (f) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> V[100005];   long long n;   map<long long, long long> DP[100005];   long long concatHash(long long x, long long y) {     return (x * 100005 + y) % 1000000007;   }   void answer(long long x) {     cout << x;     exit(0);   }   void fail() {     cout << -1;     exit(0);   }   void prec(long long x, long long f) {     if (V[x].size() == 1 && f) {       DP[x][f] = 1;       return;     }     unordered_set<long long> S;     for (auto i : V[x]) {       if (i != f) {         prec(i, x);         if (DP[i][x] == -1) DP[x][f] = -1;         S.insert(DP[i][x]);       }     }     if (DP[x][f] == -1) return;     if (S.size() == 1) {       long long chash = *(S.begin());       DP[x][f] = concatHash(chash, V[x].size());     } else       DP[x][f] = -1;   }   void DFS(long long x, long long f, long long phash) {     if (V[x].size() == 1 && f) {       if (phash != -1) {         answer(x);       }       return;     }     unordered_map<long long, long long> S;     for (auto i : V[x])       if (i != f) S[DP[i][x]]++;     if (f) S[phash]++;     if (S.size() == 0) {       assert(false);       return;     }     if (S.size() == 1 && S.begin()->first != -1) {       answer(x);     }     if (S.size() == 1 && S.begin()->first == -1) {       if (S.begin()->second != 1) return;       for (auto i : V[x]) {         if (DP[i][x] == -1) {           if (f)             DFS(i, x, concatHash(phash, V[x].size()));           else             DFS(i, x, V[x].size());           return;         }       }     }     if (S.size() >= 3) {       return;     }     auto it = S.begin();     auto a = make_pair(it->first, it->second);     it++;     auto b = make_pair(it->first, it->second);     for (auto i : V[x]) {       if (i != f && (DP[i][x] == a.first && a.second == 1 && b.first != -1)) {         DFS(i, x, concatHash(b.first, V[x].size()));       }       if (i != f && (DP[i][x] == b.first && b.second == 1 && a.first != -1)) {         DFS(i, x, concatHash(a.first, V[x].size()));       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 1) {       answer(1);     }     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       V[x].push_back(y);       V[y].push_back(x);     }     prec(1, 0);     DFS(1, 0, -1);     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const double pi = acos(-1.0);   const long long mod = 1e9 + 7;   int n, k;   int a[MAXN], b[MAXN], z[MAXN], f[MAXN];   void solve() {     scanf( %d %d , &n, &k);     int t = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] < k)         b[i] = 0;       else if (a[i] == k) {         b[i] = 1;         t = 1;       } else         b[i] = 2;     }     int flag = 0, last = -10;     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = 0; j < 3; j++)         if (b[i + j] >= 1) cnt++;       if (cnt > 1) flag = 1;     }     if ((flag && t) || (n == 1 && a[1] == k))       puts( yes );     else       puts( no );     for (int i = 1; i <= n; i++) b[i] = 0;   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000 + 7;   const double esp = 1e-13;   struct node {     int x, y;     bool operator<(const node &op) const {       return op.x > x || (op.x == x && op.y > y);     }   } a[2000 + 10];   int h, w, n;   long long res[2000 + 10], gt[200000 + 10], rev[200000 + 10];   long long power(long long a, long long n) {     long long ans = 1;     while (n) {       if (n % 2) ans = ans * a % INF;       a = a * a % INF;       n /= 2;     }     return ans;   }   long long C(int n, int k) { return gt[n] * rev[k] % INF * rev[n - k] % INF; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> h >> w >> n;     for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     a[++n] = {h, w};     sort(a + 1, a + n + 1);     gt[0] = 1;     rev[0] = power(1, INF - 2);     for (long long i = 1; i <= 200000; i++) {       gt[i] = gt[i - 1] * i % INF;       rev[i] = power(gt[i], INF - 2);     }     for (long long i = 1; i <= n; i++) {       res[i] = C(a[i].x + a[i].y - 2, a[i].x - 1);       for (long long j = 1; j <= i - 1; j++)         if (a[i].x >= a[j].x && a[i].y >= a[j].y) {           res[i] -= res[j] *                     C(a[i].x - a[j].x + a[i].y - a[j].y, a[i].x - a[j].x) % INF;           if (res[i] < 0) res[i] += INF;         }     }     cout << res[n];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> p[100000];     int n, ans = 0, a, k, c = 0, i;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a), p[i] = make_pair(a, i);     sort(p, p + n);     for (i = 0; i < n; i++) {       if ((p[i].first + ans) <= k) c++, ans += p[i].first;     }     printf( %d n , c);     for (i = 0; i < c; i++) printf( %d  , p[i].second + 1);   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 20) + 1000;   const int INF = 1000000000;   const int Mod = 1000000007;   void update(int tree[], int k, int v) {     while (k < N) {       tree[k] += v;       k += k & (-k);     }   }   int get(int tree[], int k) {     int ret = 0;     while (k) {       ret += tree[k];       k -= k & (-k);     }     return ret;   }   int a[N], n, tot, r[N], mp[N], tree[N];   long long dp[30], sum[30], f[30];   bool cmpr(int i, int j) { return a[i] < a[j]; }   int Hash() {     for (int i = 0; i < tot; i++) r[i] = i;     sort(r, r + tot, cmpr);     int K = 1;     mp[1] = a[r[0]];     for (int i = 0; i < tot; i++) {       if (mp[K] != a[r[i]]) mp[++K] = a[r[i]];       a[r[i]] = K;     }     return K;   }   int main() {     scanf( %d , &n);     tot = 1 << n;     for (int i = 0; i < tot; i++) scanf( %d , &a[i]);     int fuck = Hash();     for (int i = 1; i <= n; i++) {       dp[i] += dp[i - 1];       sum[i] += sum[i - 1];       int len = 1 << (i - 1);       for (int j = tot / len - 2; j >= 0; j -= 2) {         for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], 1);         for (int k = 0; k < len; k++) {           int tmp = get(tree, a[j * len + k] - 1);           sum[i] += tmp;           dp[i] += tmp;         }         for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], -1);         for (int k = 0; k < len; k++) update(tree, a[j * len + k], 1);         for (int k = 0; k < len; k++) {           sum[i] += get(tree, a[(j + 1) * len + k] - 1);         }         for (int k = 0; k < len; k++) update(tree, a[j * len + k], -1);       }     }     int m;     scanf( %d , &m);     while (m--) {       int x;       scanf( %d , &x);       long long t1 = dp[x], t2 = sum[x] - dp[x];       f[0] = 0;       for (int i = 1; i < x; i++) {         f[i] = dp[i];         dp[i] = sum[i] - dp[i];       }       for (int i = x; i <= n; i++) {         dp[i] = dp[i] - t1 + t2;       }       printf( %I64d n , dp[n]);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   vector<long long int> edges[500010];   long long int c[500010], cc[500010], color[500010], bip[500010];   long long int dfs(long long int u, long long int co, long long int j) {     color[u] = co;     cc[u] = j;     for (auto v : edges[u]) {       if (c[v] != c[u]) continue;       if (color[v] == color[u]) return false;       if (color[v] != 0) continue;       if (!dfs(v, 3 - co, j)) return false;     }     return true;   }   map<pair<long long int, long long int>,       vector<pair<long long int, long long int>>>       es;   map<long long int, vector<pair<long long int, long long int>>> gr;   map<long long int, long long int> flip;   long long int dfs2(long long int u, long long int f) {     flip[u] = f;     for (auto e : gr[u]) {       long long int v = e.first;       if (e.second == 0) {         if (flip.count(v) && flip[v] != flip[u]) return false;         if (flip.count(v) == 0) {           if (!dfs2(v, f)) return false;         }       }       if (e.second == 1) {         if (flip.count(v) && flip[v] == flip[u]) return false;         if (flip.count(v) == 0) {           if (!dfs2(v, !f)) return false;         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, k;     cin >> n >> m >> k;     for (long long int i = 1; i <= n; ++i) cin >> c[i];     for (long long int i = 0; i < m; ++i) {       long long int a, b;       cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);       if (c[a] != c[b]) {         long long int mi = min(c[a], c[b]);         long long int ma = max(c[a], c[b]);         es[{mi, ma}].push_back({a, b});       }     }     for (long long int i = 1; i <= k; ++i) bip[i] = 1;     for (long long int i = 1; i <= n; ++i) {       if (!color[i]) {         if (!dfs(i, 1, i)) bip[c[i]] = 0;       }     }     long long int nb = accumulate(bip, bip + k + 1, 0ll);     set<pair<long long int, long long int>> bad;     for (auto pp : es) {       long long int c1 = pp.first.first;       long long int c2 = pp.first.second;       if ((!bip[c1]) || (!bip[c2])) continue;       gr.clear();       flip.clear();       set<long long int> rc;       for (auto e : pp.second) {         if (color[e.first] == color[e.second])           gr[cc[e.first]].push_back({cc[e.second], 1});         if (color[e.first] != color[e.second])           gr[cc[e.first]].push_back({cc[e.second], 0});         if (color[e.first] == color[e.second])           gr[cc[e.second]].push_back({cc[e.first], 1});         if (color[e.first] != color[e.second])           gr[cc[e.second]].push_back({cc[e.first], 0});         rc.insert(cc[e.first]);         rc.insert(cc[e.second]);       }       for (auto i : rc) {         if (!flip.count(i)) {           if (!dfs2(i, 0)) bad.insert(pp.first);         }       }     }     cout << nb * (nb - 1) / 2 - bad.size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   string winner;   int score;   int calc(int Suc, int Fal, int A, int B, int C, int D, int E) {     int ret = A + B + C + D + E;     ret += Suc * 100;     ret -= Fal * 50;     return ret;   }   int main() {     int n;     while (cin >> n) {       score = -100000000;       for (int i = 1; i <= n; i++) {         string name;         int Suc, Fal, A, B, C, D, E;         cin >> name >> Suc >> Fal >> A >> B >> C >> D >> E;         int s = calc(Suc, Fal, A, B, C, D, E);         if (s > score) winner = name, score = s;       }       cout << winner << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }   int main() {     int n;     scanf( %d , &n);     if (n % 2)       printf( %d %d n , n / 2, n / 2 + 1);     else {       for (int a = n / 2 - 1; a; a--) {         if (gcd(a, n - a) == 1) {           printf( %d %d n , a, n - a);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int r, c;     scanf( %d %d , &r, &c);     bool banR[1000] = {false};     bool banC[1000] = {false};     char map[100][100];     for (int i = 0; i < r; i++) {       scanf( %s , map[i]);     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (map[i][j] ==  S ) {           banR[i] = true;           banC[j] = true;         }       }     }     int minus = 0;     int ans = 0;     for (int i = 0; i < r; i++) {       if (banR[i] == false) {         ans += c;         minus++;       }     }     for (int i = 0; i < c; i++) {       if (banC[i] == false && minus <= r) {         ans += (r - minus);       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[10];   int n, ans, m, tmp;   vector<int> v2;   void recur(int now) {     if (now == n) {       int vis[7][7];       memset(vis, 0, sizeof(vis));       int ans2 = 0;       for (int e = 1; e <= n; e++) {         for (int p = 0; p < v[e].size(); p++) {           int next = v[e][p];           int f = v2[e - 1], s = v2[next - 1];           if (f > s) swap(f, s);           if (vis[f][s] == 0) {             vis[f][s] = 1;             ans2++;           }         }       }       ans = max(ans, ans2);     } else {       for (int p = 1; p <= min(n, 6); p++) {         v2.push_back(p);         recur(now + 1);         v2.pop_back();       }     }   }   int main(void) {     scanf( %d%d , &n, &m);     for (int e = 0; e < m; e++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     recur(0);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int ans = 0;     int start = 0;     int end = n - 1;     while (s1[start] == s2[start]) start++;     while (s1[end] == s2[end]) end--;     if (s1.substr(start, end - start) == s2.substr(start + 1, end - start)) ans++;     if (s2.substr(start, end - start) == s1.substr(start + 1, end - start)) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t1, t2, x1, x2, t0, y1, y2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2)       cout << x1 <<     << x2 << endl;     else if (t1 == t0)       cout << x1 <<     << 0 << endl;     else if (t2 == t0)       cout << 0 <<     << x2 << endl;     else {       y1 = 0;       y2 = x2;       long double min_diff = t2 - t0;       for (long long i = 1; i <= x1; i++) {         long long j = ((t0 - t1) * i + (t2 - t0 - 1)) / (t2 - t0);         if (j > x2) continue;         long double temp = (t1 * i + t2 * j + 0.0) / (i + j + 0.0);         long double diff = temp - t0;         if (min_diff > diff) {           min_diff = diff;           y1 = i;           y2 = j;         } else if (min_diff == diff && i + j > y1 + y2) {           y1 = i;           y2 = j;         }       }       cout << y1 <<     << y2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sortLU(long long a[], long long n, long long b[]) {     long long i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (a[i] < a[j]) {           swap(a[i], a[j]);           swap(b[i], b[j]);         }       }     }   }   int main() {     long long p;     cin >> p;     long long a, s = 0, i;     for (i = 0; i < p; i++) {       cin >> a;       s += a;     }     long long n;     cin >> n;     long long x[n], y[n];     for (i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (i = 0; i < n; i++) {       if (s <= max(x[i], y[i])) {         if (s <= min(x[i], y[i])) {           cout << min(x[i], y[i]) << endl;           return 0;         } else {           cout << s << endl;           return 0;         }       }     }     cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e7 + 10;   const long long MOD = (long long)(1e9) + (long long)(7);   const long double INF = 1e17;   long long dp[505][505][12];   long long edge[505][505][4];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> v(n);     map<long long, long long> cnt;     for (auto &it : v) {       cin >> it;       cnt[it]++;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     if (n < 4)       cout << 0;     else {       for (int i = 0; i < n; i++) {         if (cnt[v[i]] % 2 == 1) {           cnt[v[i]]--;           cnt[v[i] - 1]++;         }       }       long long ans = 0;       bool form = true;       long long store = 0;       for (long long i = 0; i < n; i++) {         long long l = v[i];         while (cnt[l] >= 2) {           if (form == true) {             form = false;             store = l;             cnt[l] -= 2;           } else {             form = true;             ans += store * l;             store = 0;             cnt[l] -= 2;           }         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   const int N = 3e5 + 3;   const int mod = 1e9 + 7;   int n;   ll a[N];   template <class T>   struct FT {     vector<T> tree;     int sz;     FT(int n) { sz = n, tree.resize(n + 1); }     T get(int i) {       if (i <= 0 || i > sz) return T(0);       T sum = T(0);       for (; i; i -= (i & -i)) sum += tree[i];       return sum;     }     void upd(int i, T val) {       for (; i <= sz; i += (i & -i)) tree[i] += val;     }     void init(T *arr, int n) {       sz = n;       for (int i = 1; i <= n; i++) upd(i, arr[i - 1]);     }   };   ll ans[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     FT<ll> tree1(N);     FT<ll> tree2(N);     ll sum = 0;     for (int i = 0; i < n; i++) {       ans[i] = 1ll * i * a[i] + sum;       ans[i] -= tree1.get(a[i]);       sum += a[i];       int mul = a[i];       while (mul < N) {         tree1.upd(mul, 1ll * a[i]);         mul += a[i];       }       mul = (300000 / a[i]) * a[i];       ll cnt = 0;       while (mul != 0) {         ll cur = i - tree2.get(mul - 1);         ll how_many = cur - cnt;         ans[i] -= 1ll * mul * how_many;         cnt = cur;         mul -= a[i];       }       tree2.upd(a[i], 1ll);     }     for (int i = 0; i < n; i++) {       printf( %lld  , ans[i]);       ans[i + 1] += ans[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double a, v;     cin >> a >> v;     double l, d, w;     cin >> l >> d >> w;     w = min(w, v);     double s = w / a;     double t = a * s * s / 2;     double thead = 0;     double vhead = 0;     if (t < d) {       double t1 = v / a;       double t2 = (v - w) / a;       double dd = t1 * v / 2 + t2 * (v + w) / 2;       if (dd < d) {         double t3 = (d - dd) / v;         thead = t1 + t2 + t3;         vhead = w;       } else {         double vv = sqrt((2 * a * d + w * w) / 2);         thead = vv / a + (vv - w) / a;         vhead = w;       }     } else {       thead = sqrt(2 * d / a);       vhead = a * thead;     }     double ttail = 0;     double tt = (-vhead + sqrt(vhead * vhead + 2 * a * (l - d))) / a;     if (vhead + tt * a < v) {       ttail = tt;     } else {       double t1 = (v - vhead) / a;       double rest = (l - d) - (vhead + v) * t1 / 2;       double t2 = rest / v;       ttail = t1 + t2;     }     cout << setiosflags(ios::fixed) << setprecision(12);     cout << thead + ttail << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = 1;   long long MOD = 1e9 + 7;   const int N = 2e5 + 10;   map<int, vector<int>> mpe, mps;   int nonred[N];   int n;   set<int> st;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int l, r;       scanf( %d%d , &l, &r);       mpe[l].push_back(i + 1);       mps[r + 1].push_back(i + 1);       st.insert(l);       st.insert(r + 1);     }     set<int> at;     for (auto &tempo : st) {       for (auto &it : mpe[tempo]) {         at.insert(it);       }       for (auto &it : mps[tempo]) {         if (!nonred[it]) {           cout << it << endl;           return 0;         }         at.erase(it);       }       if (at.size() == 1) {         nonred[*at.begin()] = 1;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, a = 0, b = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (t == 25)         a++;       else if (t == 50) {         b++;         a--;         if (a < 0 || b < 0) {           cout <<  NO  << endl;           return 0;         }       } else if (t == 100) {         if (b - 1 < 0) {           a -= 3;         } else {           b--;           a--;         }         if (a < 0) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const unsigned long long key = 31;   const int MB = 1e5 + 5;   int n, m;   string s;   unsigned long long p[100008];   unsigned long long h[100008];   vector<int> v[100005];   vector<int> vv[100005];   int a[100005];   map<unsigned long long, int> pos;   string b[100005];   inline void build(int len) {     unsigned long long cur = 0;     for (int i = 0; i < v[len].size(); ++i) {       cur = 0;       for (int j = 0; j < len; ++j)         cur = (cur + (b[v[len][i]][j] -  a  + 1) * p[j + 1]);       cur = (cur * p[MB - 1]);       pos[cur] = v[len][i];     }     for (int i = 1; i <= n - len + 1; ++i) {       cur = h[i + len - 1] - h[i - 1];       cur *= p[MB - i];       if (pos.count(cur)) vv[pos[cur]].push_back(i);     }     pos.clear();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     n = s.size();     p[0] = 1;     for (int i = 1; i <= MB; ++i) p[i] = p[i - 1] * key;     for (int i = 1; i <= n; ++i) h[i] = h[i - 1] + (s[i - 1] -  a  + 1) * p[i];     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> a[i];       cin >> b[i];       v[b[i].size()].push_back(i);     }     for (int i = 1; i <= n; ++i)       if (v[i].size() > 0) {         build(i);       }     for (int i = 1; i <= m; ++i) {       if (vv[i].size() < a[i]) {         cout << -1 <<   n ;         continue;       }       int cur = n;       int z;       for (int j = a[i]; j <= vv[i].size(); ++j) {         z = vv[i][j - 1] - vv[i][j - a[i]] + b[i].size();         if (z < cur) cur = z;       }       cout << cur <<   n ;     }   }