malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double pie = acos(-1);   int n, m, i, N, f[1100000], t, s, j, k, chz[266], ans, a[4][1100000],       b[4][1100000], gs[4], use[1100000];   char s1[1100000], s2[1100000];   struct fs {     double x, y;   } w[1100000], A[1100000], B[1100000], C[1100000], v, ww;   fs operator+(fs x, fs y) {     fs t;     t.x = x.x + y.x;     t.y = x.y + y.y;     return t;   }   fs operator-(fs x, fs y) {     fs t;     t.x = x.x - y.x;     t.y = x.y - y.y;     return t;   }   fs operator*(fs x, fs y) {     fs t;     t.x = x.x * y.x - x.y * y.y;     t.y = x.y * y.x + y.y * x.x;     return t;   }   void Init() {     for (i = 1; i < N; i++) f[i] = (f[i >> 1] >> 1) + ((i & 1) << t);     w[1].x = cos(2 * pie / N);     w[1].y = sin(2 * pie / N);     for (i = 2; i <= N; i++) w[i] = w[i - 1] * w[1];     w[0] = w[N];   }   void FFT(fs *a, int F) {     int i, j, k;     for (i = 0; i < N; i++)       if (i < f[i]) swap(a[i], a[f[i]]);     for (i = 1; i < N; i <<= 1) {       s = (N / i) >> 1;       for (j = 0; j < N; j += i << 1)         for (k = j; k < j + i; k++) {           if (F > 0)             ww = w[(k - j) * s];           else             ww = w[N - (k - j) * s];           v = a[k];           a[k] = v + ww * a[k + i];           a[k + i] = v - ww * a[k + i];         }     }     if (F < 0)       for (i = 0; i < N; i++) a[i].x /= N;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     chz[ A ] = 0;     chz[ C ] = 1;     chz[ G ] = 2;     chz[ T ] = 3;     for (N = 1; N < n || N < m; N <<= 1, t++)       ;     N <<= 1;     Init();     scanf( %s , s1);     scanf( %s , s2);     for (i = 0; i <= k && i < n; i++) a[chz[s1[i]]][0]++;     for (i = 1; i < n; i++) {       for (j = 0; j < 4; j++) a[j][i] = a[j][i - 1];       if (i > k) a[chz[s1[i - k - 1]]][i]--;       if (i + k < n) a[chz[s1[i + k]]][i]++;     }     for (i = 0; i < n; i++)       for (j = 0; j < 4; j++) a[j][i] = a[j][i] > 0;     for (i = 0; i < m; i++) b[chz[s2[i]]][m - i - 1] = 1, gs[chz[s2[i]]]++;     memset(use, -1, sizeof(use));     for (i = 0; i < 4; i++) {       for (j = 0; j < N; j++) A[j].x = a[i][j], A[j].y = 0;       for (j = 0; j < N; j++) B[j].x = b[i][j], B[j].y = 0;       FFT(A, 1);       FFT(B, 1);       for (j = 0; j < N; j++) C[j] = A[j] * B[j];       FFT(C, -1);       for (j = 0; j < N; j++)         if ((int)(C[j].x + 0.5) != gs[i]) use[j] = 0;     }     for (i = 0; i < N; i++)       if (use[i] < 0) ans++;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long t, a[200010];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       long long n;       set<long long> s;       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i], a[i] = a[i] % n;       for (long long i = 0; i < n * 3; i++) s.insert(i + (a[i % n]));       if (s.size() != 3 * n)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     string s;     cin >> s;     int n = s.size();     long long maxDiff = 0;     long long ans = 0;     int x;     if (n == 1) {       cout << s << endl;       return 0;     }     vector<pair<char, vector<long long> > > a;     char t =  o ;     for (int i = 0; i < n; i += 2) {       x = s[i] -  0 ;       if (((i > 0) && (s[i - 1] ==  * )) || ((i < n - 1) && (s[i + 1] ==  * ))) {         if (t !=  * ) {           t =  * ;           a.push_back(make_pair(t, vector<long long>(1, x)));         } else {           a.back().second.push_back(a.back().second.back() * x);         }         if ((i < n - 1) && (s[i + 1] ==  + )) {           t =  o ;         }       } else {         if (t !=  + ) {           t =  + ;           a.push_back(make_pair(t, vector<long long>(1, x)));         } else {           a.back().second.push_back(a.back().second.back() + x);         }       }     }     n = a.size();     vector<long long> b(n);     for (int i = 0; i < n; i++) {       b[i] = a[i].second.back();       if (i) {         b[i] += b[i - 1];       }     }     ans = b[n - 1];     maxDiff = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         for (int si = 0; si < a[i].second.size(); si++) {           for (int sj = 0; sj < a[j].second.size(); sj++) {             long long old = b[j];             if (i > 0) {               old -= b[i - 1];             }             long long vLeft, vRight, vMiddle = 0;             vLeft = a[i].second.back();             if (si > 0) {               if (a[i].first ==  + ) {                 vLeft -= a[i].second[si - 1];               } else {                 vLeft /= a[i].second[si - 1];               }             }             vRight = a[j].second[sj];             if (j - 1 > i) {               vMiddle = b[j - 1] - b[i];             }             long long v = vLeft + vRight + vMiddle;             if (si > 0) {               if (a[i].first ==  + ) {                 v += a[i].second[si - 1];               } else {                 v *= a[i].second[si - 1];               }             }             if (sj < a[j].second.size() - 1) {               if (a[j].first ==  + ) {                 v += a[j].second.back() - a[j].second[sj];               } else {                 v *= a[j].second.back() / a[j].second[sj];               }             }             maxDiff = max(maxDiff, v - old);           }         }       }     }     cout << ans + maxDiff << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct TPoint {     double x, y;     TPoint(){};     TPoint(double _x, double _y) {       x = _x;       y = _y;     }   };   struct TVector {     double x, y;     TVector() {}     TVector(TPoint p) {       x = p.x;       y = p.y;     }     TVector(TPoint p1, TPoint p2) {       x = p2.x - p1.x;       y = p2.y - p1.y;     }   };   double cosv(TVector v1, TVector v2) {     return (double)(v2.x * v1.y - v1.x * v2.y);   }   int main() {     int n;     cin >> n;     vector<TPoint> in;     for (int i = 0; i < n; ++i) {       double x, y;       cin >> x >> y;       in.push_back(TPoint(x, y));     }     double maxpl = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         double lefter = -1, righter = -1;         for (int k = 0; k < n; ++k) {           if (k != i && k != j) {             double cosven = cosv(TVector(in[i], in[j]), TVector(in[i], in[k]));             if (cosven > 0) {               lefter = max(lefter, cosven / 2);             } else {               righter = max(righter, -cosven / 2);             }           }         }         if (lefter > 0 && righter > 0) maxpl = max(maxpl, lefter + righter);       }     }     cout.precision(10);     cout << maxpl << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 400010;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch -  0 ), ch = getchar();     return s * w;   }   void print(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   long long n, deg[N], root, cnt;   struct Node {     long long a, b, c;   } h[N];   long long head[N], maxE;   struct Edge {     long long nxt, to, rdis;   } e[N << 1];   inline void Add(long long u, long long v, long long w) {     e[++maxE].nxt = head[u];     head[u] = maxE;     e[maxE].to = v;     e[maxE].rdis = w;   }   long long DFS(long long x, long long fa, long long w) {     long long res;     long long p, q;     res = p = q = 0;     for (long long i = head[x]; i; i = e[i].nxt) {       if (e[i].to == fa) continue;       res += e[i].rdis;       long long gt = DFS(e[i].to, x, e[i].rdis);       (p ? q : p) = gt;     }     if (x == root) return p;     if (!p)       p = x, h[++cnt] = (Node){p, root, w};     else {       h[++cnt] = (Node){p, q, (res - w) / 2};       h[++cnt] = (Node){p, root, (w - res) / 2};       h[++cnt] = (Node){q, root, (w - res) / 2};     }     return p;   }   signed main() {     n = read();     for (register long long i = 1; i < n; i++) {       long long u, v, w;       u = read(), v = read(), w = read();       Add(u, v, w), Add(v, u, w);       deg[u]++, deg[v]++;     }     for (register long long i = 1; i <= n; i++) {       if (deg[i] == 2) {         puts( NO );         return 0;       }       if (deg[i] == 1) root = i;     }     puts( YES );     DFS(root, 0, 0);     printf( %lld n , cnt);     for (register long long i = 1; i <= cnt; i++)       printf( %lld %lld %lld n , h[i].a, h[i].b, h[i].c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chkmin(T& a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   bool chkmax(T& a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   void read(T& a) {     char c = getchar_unlocked();     T f = 1;     a = 0;     for (; !isdigit(c); c = getchar_unlocked())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar_unlocked()) a = a * 10 + c -  0 ;     a *= f;   }   const int maxN = 2e5 + 5;   int N;   pair<int, int> a[maxN];   map<int, int> f;   map<pair<int, int>, int> g;   int main() {     read(N);     for (int i = (1), _ = (N); i <= _; ++i) read(a[i].first), read(a[i].second);     for (int i = (1), _ = (N); i <= _; ++i) f[a[i].first]++;     long long ans = 0;     for (map<int, int>::iterator it = f.begin(); it != f.end(); ++it)       ans += (long long)it->second * (it->second - 1) / 2;     f.clear();     for (int i = (1), _ = (N); i <= _; ++i) f[a[i].second]++;     for (map<int, int>::iterator it = f.begin(); it != f.end(); ++it)       ans += (long long)it->second * (it->second - 1) / 2;     for (int i = (1), _ = (N); i <= _; ++i) g[a[i]]++;     for (map<pair<int, int>, int>::iterator it = g.begin(); it != g.end(); ++it)       ans -= (long long)(it->second) * (it->second - 1) / 2;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   const int N = 1005;   int n, k, b;   long long a[N][N], c[N][N];   int x[N], y[N];   int main() {     k = read(), b = 1 << k;     for (int i = (0); i <= (b - 1); i++)       for (int j = (0); j <= (b - 1); j++) a[i][j] = read();     n = read();     for (int i = (1); i <= (n); i++) x[i] = read(), y[i] = read();     for (int d = (0); d <= (k - 1); d++) {       memset(c, 0, sizeof(c));       for (int i = (0); i <= (b - 1); i++)         for (int j = (0); j <= (b - 1); j++)           for (int t = (1); t <= (n); t++)             c[(i + (x[t] << d)) & (b - 1)][(j + (y[t] << d)) & (b - 1)] ^=                 a[i][j];       swap(a, c);     }     int c = 0;     for (int i = (0); i <= (b - 1); i++)       for (int j = (0); j <= (b - 1); j++)         if (a[i][j]) c++;     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, is, it;   vector<int> res;   string s, t;   int getis() {     for (int i = it; i < t.size(); ++i) {       if (s[i] == t[it]) return i;     }     return -1;   }   int main() {     cin >> n >> s >> t;     while (s != t) {       is = getis();       if (is == -1) {         cout << -1;         return 0;       }       while (is >= 0 && is > it) {         res.push_back(is - 1);         swap(s[is - 1], s[is]);         is--;       }       it++;     }     if (res.size() > 10000) {       cout << -1;       return 0;     }     cout << res.size() << endl;     for (int i : res) cout << i + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     bool flag = 1;     int c = 0, a[] = {5, 7, 5}, k = 0;     map<char, bool> m{{ a , 1}, { e , 1}, { o , 1}, { u , 1}, { i , 1}};     while (getline(cin, s)) {       c = 0;       for (int i = 0; i < s.size(); i++) c += m[s[i]];       if (c != a[k]) flag = 0;       k++;     }     if (flag == 1)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T big(T a, T b) {     return a > b ? a : b;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   bool mod(long double a, long double b) { return a / b - floor(a / b); }   long long occurs(vector<long long> v, long long n) {     auto it = lower_bound(((v)).begin(), ((v)).end(), (n));     auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n));     long long x = it1 - it;     return x;   }   long long logb(long long base, long long x) { return (log(x) / log(base)); }   long long pow(long long n, long long m) {     long long ans = 1;     for (long long i{0}; i < m; i++) {       ans *= n;     }     return ans;   }   long long factors(long long ans) {     long long count = 0;     for (long long i = 1; i <= sqrt(ans); i++) {       if (ans % i == 0) {         if (ans / i == i)           count++;         else           count += 2;       }     }     return count;   }   bool isSubSequence(string str1, string str2, long long m, long long n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   long long log2(long long n) {     long long count = 0;     while (n != 0) {       n /= 2;       count++;     }     return count - 1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string s;     cin >> s;     if (n == 1 && m != 0) {       cout << 0;       return 0;     }     if (m == 0) {       for (long long i{0}; i < n; i++) {         cout << s[i];       }       return 0;     }     if (s[0] ==  1 ) {       m++;     }     cout << 1;     for (long long i{1}; i < m; i++) {       if (s[i] ==  0 ) {         m++;       }       cout << 0;       if (i == n - 1) break;     }     if (m <= n) {       for (long long i{m}; i < n; i++) {         cout << s[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   struct Item {     int parent;     int count;   };   int Find(int x, std::vector<Item>* items) {     if (items->at(x).parent == x) {       return x;     }     return items->at(x).parent = Find(items->at(x).parent, items);   }   void Unite(int x, int y, std::vector<Item>* items) {     assert(x == Find(x, items));     assert(y == Find(y, items));     if (items->at(x).count < items->at(y).count) {       std::swap(x, y);     }     items->at(y).parent = x;     items->at(x).count += items->at(y).count;   }   int main() {     std::ios_base::sync_with_stdio(false);     int N, M;     cin >> N >> M;     std::vector<std::pair<int, int>> A(N);     std::vector<Item> items(N);     for (int i = 0; i < N; ++i) {       int a;       cin >> a;       A[i].first = a;       A[i].second = i;       items[i].parent = i;       items[i].count = 1;     }     std::vector<std::vector<int>> gr(N);     for (int i = 0; i < M; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       gr[a].push_back(b);       gr[b].push_back(a);     }     std::sort(A.begin(), A.end());     int64_t answer = 0;     std::vector<int> visited(N, false);     for (int index = N - 1; index >= 0; --index) {       int value = A[index].first;       int vertex = A[index].second;       int64_t sum = 0, sum_sq = 0;       for (int neib : gr[vertex]) {         int x = Find(vertex, &items);         int y = Find(neib, &items);         if (x == y) {           continue;         }         if (!visited[y]) {           continue;         }         sum += items[y].count;         sum_sq += (int64_t)items[y].count * items[y].count;         Unite(x, y, &items);       }       answer += (int64_t)value * (sum * sum - sum_sq + 2 * sum);       visited[Find(vertex, &items)] = true;     }     long double result = (long double)answer / ((int64_t)N * (N - 1));     cout.precision(6);     cout << std::fixed << result <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, i, c, x, y, z, k, h;   int main() {     cin >> x >> y;     for (a = 0; a <= 1000; a++) {       for (b = 0; b <= 1000; b++)         if (a * a + b == x && a + b * b == y) h++;     }     cout << h;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 999999;   const double Eps = 1e-12;   const double PI = acos(-1.0);   int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }   long long pe[2222], key[2222];   char a[100], b[100];   int p[11111];   using namespace std;   int num[200004], ans[200005];   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) scanf( %d , num + i);       memset(ans, -1, sizeof(ans));       ans[1] = 0;       queue<int> q;       q.push(1);       while (!q.empty()) {         int s = q.front();         q.pop();         for (int i = -1; i <= 1; ++i) {           if (i == 0) continue;           int d = s + i;           if (d >= 1 && d <= n && ans[d] == -1) {             ans[d] = ans[s] + 1;             q.push(d);           }         }         int d = num[s];         if (ans[d] == -1) {           ans[d] = ans[s] + 1;           q.push(d);         }       }       cout << ans[1];       for (int i = 2; i <= n; i++) printf(  %d , ans[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string in =  111 ;     cin >> in;     vector<vector<int>> result;     set<int> last1, last0;     for (int i = 0; i < in.size(); i++) {       if (in[i] ==  0 ) {         if (last1.empty()) {           result.push_back({i});           last0.insert(result.size() - 1);         } else {           int cur = *last1.begin();           result[cur].push_back(i);           last1.erase(cur);           last0.insert(cur);         }       } else {         if (last0.empty()) {           cout << -1;           return 0;         } else {           int cur = *last0.begin();           result[cur].push_back(i);           last0.erase(cur);           last1.insert(cur);         }       }     }     if (last1.size()) {       cout << -1;       return 0;     }     cout << result.size() << endl;     for (auto &it : result) {       cout << it.size() <<    ;       for (auto it2 : it) {         cout << (it2 + 1) <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct abcd {     int to, next;   } table[300300 << 1];   int head[300300], tot;   int n, m;   char ans[300300];   void Add(int x, int y) {     table[++tot].to = y;     table[tot].next = head[x];     head[x] = tot;   }   void DFS(int x) {     int i, cnt = 0;     for (i = head[x]; i; i = table[i].next)       if (ans[table[i].to] == ans[x]) ++cnt;     if (cnt >= 2) {       ans[x] ^= 1;       for (i = head[x]; i; i = table[i].next) DFS(table[i].to);     }   }   int main() {     vector<int>::iterator it;     int i, x, y;     cin >> n >> m;     for (i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       Add(x, y);       Add(y, x);     }     for (i = 1; i <= n; i++) ans[i] =  0 ;     for (i = 1; i <= n; i++) DFS(i);     printf( %s n , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 2e9;   vector<string> v;   int n, m;   int diff(string a, string b) {     int i, cc = 0;     for (i = 0; i < m; ++i) cc += (a[i] != b[i]);     return cc;   }   string solve() {     string s = v[0], t;     int i, j, cc;     char c;     bool f;     for (i = 0; i < m; ++i) {       t = s;       for (c =  a ; c <=  z ; ++c) {         t[i] = c;         cc = 0;         f = 1;         for (j = 0; j < n; ++j) {           cc = diff(t, v[j]);           if (cc > 1) f = 0;         }         if (f) return t;       }     }     return  -1 ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc, ti = 1;     cin >> tc;     while (tc--) {       int i, j;       cin >> n >> m;       v.resize(n);       for (i = 0; i < n; ++i) cin >> v[i];       cout << solve() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000010;   int a[MAXN], parent[MAXN], rnk[MAXN];   vector<int> arr[MAXN];   vector<int> ans;   void make_set(int v) {     parent[v] = v;     rnk[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (rnk[a] < rnk[b]) swap(a, b);       parent[b] = a;       if (rnk[a] == rnk[b]) rnk[a]++;     }   }   int main() {     int n, m;     cin >> n >> m;     ans.clear();     ans.resize(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       make_set(i);     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       union_sets(u, v);     }     for (int i = 0; i < n; i++) {       int st = find_set(i);       arr[st].push_back(a[i]);     }     for (int i = 0; i < n; i++) {       sort(arr[i].begin(), arr[i].end());     }     for (int i = 0; i < n; i++) {       int st = find_set(i);       int x = arr[st].back();       arr[st].pop_back();       ans[i] = x;     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   long long c[4005][4005];   void getc() {     memset(c, 0, sizeof(c));     c[0][0] = 1;     for (int i = 1; i < 4001; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;       }     }   }   long long a[4005];   void geta() {     a[0] = 1;     a[1] = 1;     for (long long i = 2; i <= 4000; i++) a[i] = a[i - 1] * i % mod;   }   int main() {     getc();     geta();     int n, w, b;     while (scanf( %d%d%d , &n, &w, &b) == 3) {       int x = max(1, n - w), y = min(b, n - 2);       long long ans = 0;       for (int i = x; i <= y; i++) {         ans = (ans +                c[b - 1][i - 1] * c[w - 1][n - i - 1] % mod * (n - i - 1) % mod) %               mod;       }       ans = ans * a[w] % mod * a[b] % mod;       printf( %lld n , ans);     }     return 0;   }