malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0), eps = 1e-8;   const int inf = ~0U >> 2;   int mod = 1e9 + 7;   int Pow(int x, long long t) {     int r = 1;     for (; t; t >>= 1, x = (long long)x * x % mod)       if (t & 1) r = (long long)r * x % mod;     return r;   }   const int N = 101010;   int n, K;   struct P {     long long x, y;     void in() { cin >> x >> y; }     P(long long _x = 0, long long _y = 0) { x = _x, y = _y; }     double dis() { return sqrt(x * x + y * y); }     long long operator^(const P& b) { return x * b.y - y * b.x; }     P operator-(const P& b) { return P(x - b.x, y - b.y); }   } p[N << 1], q;   long long mul(P& o, P& a, P& b) { return (a - o) ^ (b - o); }   bool in(P q) {     double a = 0;     for (int i = 0; i < n; ++i) {       long long aera = mul(q, p[i], p[i + 1]);       double disa = (p[i] - q).dis(), disb = (p[i + 1] - q).dis(),              disc = (p[i] - p[i + 1]).dis();       double angle = acos(((disa) * (disa) + (disb) * (disb) - (disc) * (disc)) /                           2.0 / disa / disb);       if (aera > 0)         a += angle;       else         a -= angle;     }     return fabs(a) >= 1;   }   long long wk() {     q.in();     if (!in(q)) return 0;     long long ans = (long long)n * (n - 1) * (n - 2) / 6;     for (int i = 0, j = 1; i < n; ++i) {       while (mul(p[i], p[j], q) <= 0) ++j;       int del = (j + n - i) % n;       int rm = n - del;       ans -= (long long)rm * (rm - 1) / 2;     }     return ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) p[i].in(), p[i + n] = p[i];     cin >> K;     for (int i = 0; i < K; ++i) cout << wk() << endl;     return 0;   }
#include <bits/stdc++.h>       using namespace std;       bool palindrome(const string &s) {       int n = s.length();       for(int i = 0; i < n; i++) {           if(s[i] != s[n - i - 1]) return false;       }       return true;   }       int main() {       ios::sync_with_stdio(false);       cin.tie(0);       int te;       cin >> te;       while(te--) {           string s;           cin >> s;           if(!palindrome(s +  a )) {               cout <<  YES n  << s <<  a  <<   n ;           }else if(!palindrome( a  + s)) {               cout <<  YES n  <<  a  << s <<   n ;           }else {               cout <<  NO n ;           }       }   }
#include <bits/stdc++.h>   const long double PI(acosl(-1.0));   long double eps = 1e-9;   using namespace std;   using namespace std;   const int N = 1000000;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<int, int> > p(n);     int s = 0;     for (int i(0); i < n; i++) {       int x;       cin >> x;       s += x;       p[i] = {x, i + 1};     }     sort(++p.begin(), p.end());     reverse(++p.begin(), p.end());     vector<pair<int, int> > ans;     int j = 1;     int i = 0;     while (j < n) {       while (j < n && p[i].first > 0) {         ans.push_back({p[i].second, p[j].second});         p[i].first--;         j++;       }       i++;       if (i == j) break;     }     if (j < n) {       cout << -1;       return 0;     }     cout << ans.size() << endl;     for (int i(0); i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void CIN(T &a) {     cin >> a;   }   template <class T>   void CIN(T &a, T &b) {     cin >> a >> b;   }   template <class T>   void CIN(T &a, T &b, T &c) {     cin >> a >> b >> c;   }   template <class T>   void CIN(T &a, T &b, T &c, T &d) {     cin >> a >> b >> c >> d;   }   template <class T>   void PI(T a) {     cout << a << endl;   }   template <class T>   void PI(T a, T b) {     cout << a <<     << b << endl;   }   template <class T>   void PIS(T a) {     cout << a <<    ;   }   template <class T>   T abs(T a) {     return a < 0 ? -a : a;   }   const int N = 10000010;   long long n, x, y, dx, dy, t;   int b[6][6] = {{2, 1, 1, 0, 1, 0}, {1, 2, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0},                  {1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}};   struct matrix {     long long a[6][6];     matrix() { memset(a, 0, sizeof(a)); }     void init() {       int i, j;       for (i = 0; i < (int)(6); ++i)         for (j = 0; j < (int)(6); ++j) a[i][j] = b[i][j];     }     void unit() {       memset(a, 0, sizeof(a));       int i;       for (i = 0; i < (int)(6); ++i) a[i][i] = 1;     }     matrix operator*(const matrix &b) const {       matrix ret;       int i, j, k;       for (i = 0; i < (int)(6); ++i)         for (j = 0; j < (int)(6); ++j)           for (k = 0; k < (int)(6); ++k) {             ret.a[i][j] += a[i][k] * b.a[k][j];             ret.a[i][j] %= n;           }       return ret;     }     matrix Pow(long long k) {       matrix ret, p = *this;       ret.unit();       while (k) {         if (k & 1) ret = ret * p;         k >>= 1;         p = p * p;       }       return ret;     }   } mx;   int main() {     CIN(n);     CIN(x, y, dx, dy);     CIN(t);     mx.init();     mx = mx.Pow(t);     long long ex = mx.a[0][0] * x + mx.a[0][1] * y + mx.a[0][2] * dx +                    mx.a[0][3] * dy + mx.a[0][5];     long long ey = mx.a[1][0] * x + mx.a[1][1] * y + mx.a[1][2] * dx +                    mx.a[1][3] * dy + mx.a[1][5];     ex %= n;     if (ex <= 0) ex += n;     ey %= n;     if (ey <= 0) ey += n;     PI(ex, ey);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int max = 0;     int n[100];     n[0] = a * b + c, n[1] = a * b * c, n[2] = a + b * c, n[3] = a + b + c,     n[4] = a * (b + c), n[5] = (a + b) * c;     for (int i = 0; i < 6; i++) {       if (n[i] > max) max = n[i];     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      typedef long long Int;   typedef pair<int,int> PII;   typedef vector<int> VInt;       #define FOR(i, a, b) for(i = (a); i < (b); ++i)   #define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)   #define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)   #define CLEAR(a, b) memset(a, b, sizeof(a))   #define SIZE(a) int((a).size())   #define ALL(a) (a).begin(),(a).end()   #define MP make_pair      int f(VInt p, VInt s)   {    int n = SIZE(p);    int left = 0, right = n - 1;    int res = 0;    VInt used(n, 0);    while(left < right)    {     int cnt = 0;     int flips = 0;     int l = left;     int r = right + 1;     while(l >= left || r <= right)     {      if(l >= left)      {       int a = left;       ++left;       if(used[a] == 0)       {        int b = p[a];        used[a] = used[b] = 1;        ++cnt;        flips += s[a];        if(b > r) return -1;        r = b;        if(l >= r) return -1;       }      }      if(r <= right)      {       int a = right;       --right;       if(used[a] == 0)       {        int b = p[a];        used[a] = used[b] = 1;        ++cnt;        flips += s[a];        if(b < l) return -1;        l = b;        if(l >= r) return -1;       }      }     }     res += min(flips, cnt - flips);    }    return res;   }      void SolveTest(int test)   {    int n;    cin >> n;    int i, j;    VInt p(n + n);    VInt s(n + n);    FOR(i, 0, n)    {     int a, b;     cin >> a >> b;     --a;     --b;     p[a] = b;     p[b] = a;     s[a] = 0;     s[b] = 1;    }       cout << f(p, s) << endl;   }      int main()   {    int T, t;    T = 1;    //cin >> T;    FOR(t, 0, T) SolveTest(t);    return 0;   };
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const int MOD = 1e9 + 7;   struct Node {     int op, x, y, d;     Node() {}     Node(int _op, int _x, int _y, int _d) { op = _op, x = _x, y = _y, d = _d; }     bool operator<(const Node &cur) const { return d > cur.d; }   };   priority_queue<Node> que;   int dist[2][N][N], n, m, nx, ny;   long long ans[2][N][N], C[N][N];   void init() {     int i, j;     memset(C, 0, sizeof(C));     for (i = 0; i < N; i++) {       C[i][0] = 1;       for (j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;     }   }   int main() {     int i, j, tmp;     init();     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 1, nx = ny = 0; i <= n; i++) {         scanf( %d , &tmp);         if (tmp == 50)           nx++;         else           ny++;       }       memset(dist, 0x3f, sizeof(dist));       memset(ans, 0, sizeof(ans));       while (!que.empty()) que.pop();       dist[1][0][0] = 0;       ans[1][0][0] = 1;       que.push(Node(1, 0, 0, 0));       while (!que.empty()) {         Node cur = que.top();         que.pop();         if (cur.d > dist[cur.op][cur.x][cur.y]) continue;         for (i = 0; i <= nx; i++)           for (j = 0; j <= ny; j++) {             if (i + j == 0 || 50 * i + 100 * j > m) continue;             if (cur.op == 0 && cur.x >= i && cur.y >= j) {               if (dist[1][cur.x - i][cur.y - j] >= cur.d + 1) {                 if (dist[1][cur.x - i][cur.y - j] > cur.d + 1) {                   ans[1][cur.x - i][cur.y - j] = 0;                   dist[1][cur.x - i][cur.y - j] = cur.d + 1;                   que.push(Node(1, cur.x - i, cur.y - j, cur.d + 1));                 }                 ans[1][cur.x - i][cur.y - j] +=                     ans[0][cur.x][cur.y] * C[cur.x][i] % MOD * C[cur.y][j] % MOD;                 ans[1][cur.x - i][cur.y - j] %= MOD;               }             }             if (cur.op == 1 && cur.x + i <= nx && cur.y + j <= ny) {               if (dist[0][cur.x + i][cur.y + j] >= cur.d + 1) {                 if (dist[0][cur.x + i][cur.y + j] > cur.d + 1) {                   ans[0][cur.x + i][cur.y + j] = 0;                   dist[0][cur.x + i][cur.y + j] = cur.d + 1;                   que.push(Node(0, cur.x + i, cur.y + j, cur.d + 1));                 }                 ans[0][cur.x + i][cur.y + j] += ans[1][cur.x][cur.y] *                                                 C[nx - cur.x][i] % MOD *                                                 C[ny - cur.y][j] % MOD;                 ans[0][cur.x + i][cur.y + j] %= MOD;               }             }           }       }       if (dist[0][nx][ny] == 0x3f3f3f3f) {         printf( -1 n0 n );       } else {         printf( %d n%I64d n , dist[0][nx][ny], ans[0][nx][ny]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[305], Lcm;   long long sol(long long x) {     long long cnt = 0;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         cnt += 2;         if (i * i == x) cnt--;       }     }     return cnt;   }   int main() {     int T;     cin >> T;     while (T--) {       int ok = 1;       scanf( %d , &n);       for (int i = 0; i < n; i++) scanf( %lld , &a[i]);       sort(a, a + n);       if (n == 1)         Lcm = a[0] * a[0];       else         Lcm = a[0] * a[n - 1];       for (int i = 1; i < (n + 1) / 2; i++) {         if (a[i] * a[n - 1 - i] != Lcm) {           ok = 0;           break;         }       }       if (ok && sol(Lcm) == n)         printf( %lld n , Lcm);       else         puts( -1 );     }   }
#include <bits/stdc++.h>   using namespace std;   char ch[100001];   int per[100001];   bool is[100001];   bool vis[100001];   bool mem[100001];   bool have[100001];   vector<int> V;   int main() {     int i, j;     int a, b;     int n, m;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> ch[i] >> per[i];       have[per[i]] = true;     }     V.clear();     memset(is, true, sizeof is);     for (i = 0; i < m; i++) {       if (ch[i] ==  + ) {         if (!vis[per[i]] && i) is[per[i]] = false;         if (V.size()) {           is[per[i]] = false;         } else {           for (j = i - 1; j >= 0; j--) {             if (per[i] != per[j]) is[per[j]] = false;             if (mem[j]) break;           }           mem[i - 1] = true;         }         V.push_back(per[i]);       } else {         if (!vis[per[i]]) {           for (j = i - 1; j >= 0; j--) {             is[per[j]] = false;             if (mem[j]) break;           }           mem[i - 1] = true;           if (V.size()) is[per[i]] = false;         } else if (V.size() == 1) {           if (V[0] == per[i])             V.clear();           else {             int num = per[i];             V.erase(std::remove(V.begin(), V.end(), num), V.end());             is[num] = false;           }         } else if (V.size()) {           int num = per[i];           V.erase(std::remove(V.begin(), V.end(), num), V.end());           is[num] = false;         }       }       if (!vis[per[i]]) vis[per[i]] = true;     }     vector<int> res;     res.clear();     for (i = 1; i <= n; i++) {       if (!have[i]) {         res.push_back(i);       } else {         if (is[i]) res.push_back(i);       }     }     int sz = res.size();     cout << sz << endl;     for (i = 0; i < sz; i++) cout << res[i] <<    ;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define ld long double   #define For(i,x,y) for(ll i = (x);i <= (y);++i)   #define FOr(i,x,y) for(ll i = (x);i >= (y);--i)   #define fi first   #define se second   #define pa pair<ll,ll>   #define mk make_pair   #define pb push_back   #define clr(a,b) memset(a,b,sizeof(a))   #define cpy(a,b) memcpy(a,b,sizeof(b))   #define y1 y11111111111111111111   #define debug puts( @@@@@@@@@@@@@@@@@@@@ )   #define NO puts( NO )   #define YES puts( YES )   #define Yes puts( Yes )   #define No puts( No )   inline ll read()   {    ll x = 0,f = 1;char ch = getchar();    while(ch <  0  || ch >  9 ){if(ch ==  - )f = -1;ch = getchar();}    while(ch >=  0  && ch <=  9 ){x = x*10+ch- 0 ;ch = getchar();}    return x*f;   }   char s[999];   int main()   {    while (scanf( %s ,s)!=EOF)    {     if (s[1]== s ) puts( NO ),fflush(stdout);    }   }
#include <bits/stdc++.h>   using namespace std;   int n;   double s;   vector<int> E[100005];   int dist[100005], pa[100005];   int dfs(int u, int p, int d) {     dist[u] = d;     int ans = u;     for (int v : E[u]) {       if (v == p) continue;       int tmp = dfs(v, u, d + 1);       pa[v] = u;       if (dist[ans] < dist[tmp]) ans = tmp;     }     return ans;   }   int main() {     scanf( %d%lf , &n, &s);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       E[u].push_back(v);       E[v].push_back(u);     }     if (n == 2) {       printf( %.10lf n , s);       return 0;     }     int l = 0;     for (int i = 1; i <= n; i++) {       if (E[i].size() == 1) l++;     }     printf( %.10lf n , 2.0 * s / l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long mk[100000];   int main() {     long a, b, m, r0, r;     cin >> a >> b >> m >> r0;     for (long i = 0; i < m; i++) mk[i] = -1;     r = (a * r0 + b) % m;     mk[r] = 1;     long k = 1;     while (true) {       k++;       r = (a * r + b) % m;       if (mk[r] == -1)         mk[r] = k;       else {         cout << k - mk[r];         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, maxi = 2, ans = 2;   int a[100005];   vector<int> num;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     if (n < 3) {       cout << n;       return 0;     }     for (int i = 2; i < n; i++) {       if (a[i] == a[i - 1] + a[i - 2]) {         ans++;         maxi = max(maxi, ans);       } else         ans = 2;     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {+1, -1, +0, +0};   int dy[] = {+0, +0, +1, -1};   int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};   int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};   int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};   int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};   const int MAXN = 1e5 + 9;   int main() {     int i, j, k, l, m, n, tc, t, mx, ans, total = 0;     cin >> n >> m;     mx = -9999;     ans = -1;     for (int i = 0; i < (int)n; i++) {       cin >> k;       t = k / m;       if (k % m) t++;       if (t >= mx) {         mx = t;         ans = i + 1;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int mod = 1e9 + 7;   long long dp[maxn] = {0, 1, 2, 3, 5, 8};   int main() {     for (int i = 6; i < maxn; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % mod;     int n, m;     cin >> n >> m;     cout << (2 * (dp[n] + dp[m] - 1)) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }   int n, m, l, r;   string s;   char c1, c2;   int main() {     cin >> n >> m;     cin >> s;     for (int i = 1; i <= m; i++) {       cin >> l >> r >> c1 >> c2;       l--, r--;       for (int j = l; j <= r; j++) {         if (s[j] == c1) s[j] = c2;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     set<string> g;     g.insert(s);     int n = s.size();     for (int k = 0; k < s.size(); k++) {       string s1 =   ;       s1 += s[n - 1];       for (int i = 0; i < s.size() - 1; i++) {         s1 += s[i];       }       s = s1;       g.insert(s);     }     cout << g.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   vector<long long> parent(200005), Size(200005, 1);   long long answer = 0;   long long find_set(long long n) {     if (parent[n] == n)       return n;     else       return find_set(parent[n]);   }   void add_edge(long long a, long long b) {     long long A = find_set(a);     long long B = find_set(b);     if (Size[A] >= Size[B]) {       answer -= ((Size[A] * (Size[A] - 1)) / 2);       answer -= ((Size[B] * (Size[B] - 1)) / 2);       Size[A] += Size[B];       Size[B] = 0;       parent[B] = A;       answer += ((Size[A] * (Size[A] - 1)) / 2);     } else {       answer -= ((Size[B] * (Size[B] - 1)) / 2);       answer -= ((Size[A] * (Size[A] - 1)) / 2);       Size[B] += Size[A];       Size[A] = 0;       parent[A] = B;       answer += ((Size[B] * (Size[B] - 1)) / 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long N, Q, p, q, r;     cin >> N >> Q;     if (N == 1) {       for (long long i = 1; i <= Q; i++) cout <<  0  ;       return 0;     }     for (long long i = 1; i <= N; i++) parent[i] = i;     vector<pair<long long, pair<long long, long long>>> G;     for (long long i = 1; i < N; i++) {       cin >> p >> q >> r;       G.push_back({r, {p, q}});     }     sort(G.begin(), G.end());     vector<long long> final_ans(N + 1);     long long ptr = 0;     for (long long i = 1; i <= N;) {       if (G[ptr].first == i) {         add_edge(G[ptr].second.first, G[ptr].second.second);         ptr++;       } else {         final_ans[i] = answer;         i++;       }     }     while (Q--) {       long long k;       cin >> k;       cout << final_ans[k] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<long long, long long> isolados;     long long n, k, i, j, prox, qtd, x, resp;     bool first = true;     while (cin >> n >> k) {       resp = 0;       isolados.clear();       prox = -1;       first = true;       for (i = 0; i < k; i++) {         cin >> qtd;         for (j = 0; j < qtd; j++) {           cin >> x;           if (x == 1) prox = 1;           if (x == prox && first == true) {             prox++;           } else if (j == 0) {             isolados[x] = 0;           } else {             isolados[x] = 1;           }         }         if (prox != -1) first = false;       }       for (prox; prox <= n; prox++) {         resp += isolados[prox] + 1;       }       cout << resp << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sti[101], i, x, ans;     cin >> n;     memset(sti, 0, sizeof(sti));     for (i = 1; i <= n; i++) {       cin >> x;       sti[x]++;     }     ans = 0;     for (i = 1; i <= 100; i++) {       ans += 2 * (sti[i] / 4);       sti[i] %= 4;       ans += sti[i] / 2;     }     cout << ans / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double a[4010];   int main() {     cin >> n;     n *= 2;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) a[i] = a[i] - int(a[i]);     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (abs(a[i] - 0) <= 0.0000001) cnt++;     double sum = 0;     for (int i = 1; i <= n; ++i) sum += a[i];     double res = 1000000001;     for (int i = 0; i <= cnt; ++i) res = min(res, abs(n / 2 - sum - i));     printf( %.3f , res);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[100005];     int n, i;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a, a + n);     if (a[n - 1] == 1) {       for (i = 0; i < n - 1; i++) {         printf( %d  , a[i]);       }       puts( 2 );     } else {       printf( 1 );       for (i = 0; i < n - 1; i++) {         printf(  %d , a[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct group {     int sz;     vector<int> worst, best;     group(vector<int>& a)         : sz(1), worst(a.begin(), a.end()), best(a.begin(), a.end()) {}     bool operator<(const group& a) const {       for (int i = 0; i < best.size(); i++)         if (best[i] >= a.worst[i]) return false;       return true;     }     struct group& operator+=(const group& a) {       sz += a.sz;       for (int i = 0; i < best.size(); i++) {         best[i] = max(best[i], a.best[i]);         worst[i] = min(worst[i], a.worst[i]);       }       return *this;     }   };   set<group> positions;   int main() {     int n, k;     scanf( %d %d , &n, &k);     while (n--) {       vector<int> skills(k, 0);       for (int i = 0; i < k; i++) scanf( %d , &skills[i]);       group player = group(skills);       auto f = positions.lower_bound(player), l = positions.upper_bound(player);       while (f != l) {         player += *f;         f = positions.erase(f);       }       positions.insert(f, player);       printf( %d n , positions.rbegin()->sz);     }     return 0;   }