malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long a, long long p) { return power(a, p - 2, p); }   long long gcd(long long x, long long y) {     if (x == 0 || y == 0) {       return max(y, x);     }     return gcd(y % x, x);   }   long long gcdExtended(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   };   long long bit[1504];   void update(long long x) {     while (x <= 1500) {       bit[x]++;       x += (x & (-x));     }   }   long long get(long long x) {     long long ret = 0;     while (x) {       ret += bit[x];       x -= (x & (-x));     }     return ret;   }   long long dp[1504][1504];   int main() {     long long n;     scanf( %lld , &n);     vector<long long> a;     for (long long i = 0; i < n; i++) {       long long x;       scanf( %lld , &x);       a.push_back(x);     }     for (long long i = 0; i < n; i++) {       for (long long j = 1; j <= n; j++) bit[j] = 0;       long long here = 0;       for (long long j = i; j < n; j++) {         update(a[j]);         here += get(a[j] - 1);         dp[i][j] = here;       }     }     long long q;     scanf( %lld , &q);     long long tot = dp[0][n - 1];     tot = (n) * (n - 1);     tot /= 2;     tot -= dp[0][n - 1];     tot %= 2;     while (q--) {       long long x, y;       scanf( %lld %lld , &(x), &(y));       long long len = y - x + 1;       long long here = (len) * (len - 1);       here /= 2;       here %= 2;       tot = tot + here;       tot %= 2;       if (tot)         cout <<  odd  << endl;       else         cout <<  even  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 111111;   int Tit[M];   int ra[M];   int k[M];   int r, j, rslt = 0;   vector<int> vec[M];   void dfs(int u, int v) {     ra[u] = ra[v] + 1;     k[ra[u]] ^= 1;     int j = vec[u].size();     int z;     while (j--) {       z = vec[u][j];       if (z != v) dfs(z, u);     }   }   int main() {     scanf( %d , &r);     for (j = 2; j <= r; j = j + 1) scanf( %d , Tit + j), vec[Tit[j]].push_back(j);     dfs(1, 0);     for (j = 1; j <= r; j = j + 1) rslt += k[j];     cout << rslt;     return 0;   }
#include <bits/stdc++.h>   typedef long long ll;   #define endl   n    #define pq priority_queue <pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>   #define graph1 vector<vector<pair<ll,ll>>>   #define graph vector<vector<ll>>   #define pq1 priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll,ll>>>, greater<pair<ll, pair<ll, ll>>>>   #define loop(i,a,b) for (ll i = a; i < b; i++)   using namespace std;   vector <ll>  arr;   bool check3(ll i)   {       if(max(arr[i],arr[i+2]) >=  arr[i+1] && min(arr[i],arr[i+2]) <=  arr[i+1]  )       {           return true;       }       return false;   }   bool check4(ll i)   {       if(check3(i) ||check3(i + 1))       {           return true;       }       if(max(arr[i],arr[i+3]) >=  arr[i + 1] && min(arr[i],arr[i+3]) <=  arr[i+1]  )       {           return true;       }       if(max(arr[i],arr[i+3]) >=  arr[i + 2] && min(arr[i],arr[i+3]) <=  arr[i+2]  )       {           return true;       }       return false;   }   int main()   {       ios::sync_with_stdio(0); cin.tie(0);       ll t;       cin >> t;       while(t--)       {           ll n;           cin >> n;           arr.resize(n);           loop(i,0,n)               cin >> arr[i];              ll ans = n * 2 - 1;              loop(i,0,n-2)           {               if(!check3(i))               ans++;           }           loop(i,0,n-3)           {               if(!check4(i))               ans++;           }           cout << ans << endl;       }   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using ll = long long;   using vll = vector<ll>;   using vvll = vector<vll>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   ll power[40];   void dfs(int id, vi& v, vi& s) {     if (id < v.size()) {       s.push_back(v[id]);       dfs(id * 2, v, s);       dfs(id * 2 + 1, v, s);     }   }   void solve() {     int h, g, num;     cin >> h >> g;     vi v(power[h]);     vvi mins(power[g], vi());     set<int> fin;     for (int i = 1; i < power[h]; i++) {       cin >> v[i];     }     for (int i = 0; i < power[g - 1]; i++) {       dfs(i + power[g - 1], v, mins[i + power[g - 1]]);       sort(mins[i + power[g - 1]].begin(), mins[i + power[g - 1]].end(),            greater<int>());     }     for (int i = g; i > 0; i--) {       for (int j = power[i - 1]; j < power[i]; j++) {         fin.insert(*mins[j].rbegin());       }       if (i == 1) {         break;       }       for (int j = power[i - 1]; j < power[i]; j += 2) {         num = max(*mins[j].rbegin(), *mins[j + 1].rbegin());         mins[j].pop_back();         mins[j + 1].pop_back();         mins[j / 2].push_back(v[j / 2]);         merge(mins[j].begin(), mins[j].end(), mins[j + 1].begin(),               mins[j + 1].end(), std::back_inserter(mins[j / 2]), greater<int>());         while (*mins[j / 2].rbegin() < num) {           mins[j / 2].pop_back();         }       }     }     ll sum = 0;     vi print;     print.reserve(power[h] - 1);     for (int i = 1; i < power[h]; i++) {       if (fin.find(v[i]) == fin.end()) {         print.push_back(i);       } else {         sum += v[i];       }     }     reverse(print.begin(), print.end());     cout << sum <<   n ;     for (int i : print) {       cout << i <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     power[0] = 1;     for (int i = 1; i < 40; i++) {       power[i] = 2ll * power[i - 1];     }     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   struct Point {     double x, y;     Point(double x = 0, double y = 0) : x(x), y(y) {}   };   double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }   double Length(Point A) { return sqrt(Dot(A, A)); }   double Angle(Point A, Point B) {     return acos(Dot(A, B) / Length(A) / Length(B));   }   Point Normal(Point A) {     double L = Length(A);     return Point(-A.y / L, A.x / L);   }   double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }   Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }   Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }   Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); }   Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }   int dcmp(double x) {     if (fabs(x) < eps) return 0;     return x < 0 ? -1 : 1;   }   bool operator<(const Point &a, const Point &b) {     return a.x < b.x || (a.x == b.x && a.y < b.y);   }   bool operator==(const Point &a, const Point &b) {     return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;   }   double GetAngleByLength(double a, double b, double c) {     double cosA = (b * b + c * c - a * a) / (b * c * 2);     return acos(cosA);   }   Point Rotate(Point A, double rad) {     return Point(A.x * cos(rad) - A.y * sin(rad),                  A.x * sin(rad) + A.y * cos(rad));   }   Point GetLineIntersection(Point P, Point v, Point Q, Point w) {     Point u = P - Q;     double t = Cross(w, u) / Cross(v, w);     return P + v * t;   }   Point R;   Point v;   double solve(Point P, Point vP, Point Q, Point vQ) {     auto X = GetLineIntersection(P, vP, R, v);     auto Y = GetLineIntersection(Q, vQ, R, v);     return Length(P - X) + Length(X - Y) + Length(Q - Y);   }   int main() {     double a, b, c, x1, y1, x2, y2;     cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2;     if (a == 0 || b == 0) {       double ans = fabs(x1 - x2) + fabs(y1 - y2);       printf( %.10f n , ans);       return 0;     }     R.x = 0;     R.y = -c / b;     v = Point(b, -a);     double ans = fabs(x1 - x2) + fabs(y1 - y2);     ans = min(ans, solve(Point(x1, y1), Point(1, 0), Point(x2, y2), Point(1, 0)));     ans = min(ans, solve(Point(x1, y1), Point(1, 0), Point(x2, y2), Point(0, 1)));     ans = min(ans, solve(Point(x1, y1), Point(0, 1), Point(x2, y2), Point(1, 0)));     ans = min(ans, solve(Point(x1, y1), Point(0, 1), Point(x2, y2), Point(0, 1)));     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long int   #define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);   #define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index];   #define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<   ;cout<<endl;   #define mod 1000000007   #define pb push_back   #define mp make_pair   #define ss second   #define ff first   #define vli vector<long long int>   #define vlli vector<pair<long long int,long long int>>   #define vsi vector<string>   #define all(n) n.begin(),n.end()   #define forn(i,a,b) for(i=a;i<b;i++)   ll mul(ll x,ll y){  return (x*y)%mod;}   ll power(ll x, ll y) {ll res = 1; x %= mod;    while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}   ll mod_inv(ll x) {return power(x, mod - 2);}   ll fact(ll n) {ll res = 1; for (ll i = 2; i <= n; i++) res = mul(res , i); return res; }    ll nCr(ll n, ll r) { return mul(fact(n),mod_inv(mul(fact(r),fact(n - r))));}           int main() {     fast;     #ifndef ONLINE_JUDGE     freopen( input.txt , r ,stdin);     freopen( output.txt , w ,stdout);     #endif     ll t=1;     cin>>t;     while(t--){       ll n,k;       cin>>n>>k;       ll a[n],b[n],i;       for(i=0;i<n;i++){         cin>>a[i]>>b[i];       }       ll f=-1,j;       ll x,y;       for(i=0;i<n;i++){        x=0;        for(j=0;j<n;j++){           y=abs(a[i]-a[j])+abs(b[i]-b[j]);         if(y<=k) x++;        }        if(x==n) f=1;       }       cout<<f<<endl;                           }   return 0;        }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     long long sum = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> odd, even;     for (int i = 0; i < n; i++) {       if (arr[i] & 1)         odd.push_back(arr[i]);       else         even.push_back(arr[i]);     }     sort(odd.begin(), odd.end());     sort(even.begin(), even.end());     if (odd.size() > even.size()) {       for (int i = 0; i < odd.size() - even.size() - 1; i++) sum += odd[i];     } else if (odd.size() == even.size())       sum = 0;     else {       for (int i = 0; i < even.size() - odd.size() - 1; i++) sum += even[i];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<long long int>;   using vvi = vector<vi>;   using vb = vector<bool>;   using vc = vector<char>;   using vs = vector<string>;   using vld = vector<long double>;   using pii = pair<long long int, long long int>;   using psi = pair<string, long long int>;   using pci = pair<char, long long int>;   using vpii = vector<pii>;   long long int mod = 1e9 + 7;   long long int const maxn = 2e5 + 5;   long long int const inf = 1e18;   long long int add(long long int a, long long int b) {     return ((a % mod) + (b % mod)) % mod;   }   long long int mul(long long int a, long long int b) {     return ((a % mod) * (b % mod)) % mod;   }   long long int powm(long long int x, long long int n, long long int M) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result * x) % M;       x = (x * x) % M;       n = n / 2;     }     return result;   }   long long int modinverse(long long int a, long long int m) {     return powm(a, m - 2, m);   }   bool prime(long long int x) {     if (x <= 1) return false;     for (int i = 2; i <= sqrt(x); i++)       if (x % i == 0) return false;     return true;   }   long long int divisor(long long int x) {     long long int cnt = 0;     for (int i = 1; i <= sqrt(x); i++) {       if (x % i == 0) {         if (i != x / i)           cnt += 2;         else           cnt += 1;       }     }     return cnt;   }   vector<long long int> sieve(long long int n) {     bool prim[n + 1];     memset(prim, true, sizeof(prim));     for (long long int p = 2; p * p <= n; p++) {       if (prim[p] == true) {         for (int i = p * p; i <= n; i += p) prim[i] = false;       }     }     vector<long long int> v;     for (int i = 2; i <= n; i++)       if (prim[i]) v.push_back(i);     return v;   }   vvi adj(maxn);   vb vis(maxn, false);   long long int x, y;   void dfs(long long int u) {     if (vis[u] == true) return;     vis[u] = true;     if (x == -1 and y == -1) {       x = u;       y = u;     }     x = min(x, u);     y = max(y, u);     for (auto v : adj[u]) {       if (!vis[v]) {         dfs(v);       }     }   }   int main() {     int t;     t = 1;     while (t--) {       long long int n, m;       cin >> n >> m;       vpii ans;       for (long long int i = 0; i < m; i++) {         long long int a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       for (long long int i = 1; i <= n; i++) {         if (!vis[i]) {           x = -1;           y = -1;           dfs(i);           ans.push_back({x, y});         }       }       sort(ans.begin(), ans.end());       long long int cnt = 0;       for (long long int i = 1; i <= (long long int)ans.size() - 1; i++) {         if (ans[i - 1].second >= ans[i].first) {           cnt++;           ans[i].second = max(ans[i - 1].second, ans[i].second);         }       }       cout << cnt <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx[8] = {-1, 1, -1, 1, -2, 2, -2, 2};   const int my[8] = {-2, -2, 2, 2, -1, -1, 1, 1};   const int MAXN = 1100;   const int MAXM = 1100;   int N, M;   const int MAXV = MAXN * MAXM;   int V;   int source[2];   int target[2];   int dist[2][MAXV];   int nxt[2][MAXV];   int st_dist[2][2];   bool parity(int v) { return ((v / M) + (v % M)) & 1; }   bool one_move(int a, int b) {     int dx = abs(a / M - b / M);     int dy = abs(a % M - b % M);     return (dx == 1 && dy == 2) || (dx == 2 && dy == 1);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> N >> M;     V = N * M;     {       int X0, Y0, X1, Y1;       cin >> X0 >> Y0 >> X1 >> Y1;       X0--, Y0--, X1--, Y1--;       source[0] = X0 * M + Y0;       source[1] = X1 * M + Y1;     }     target[0] = (N / 2 - 1) * M + (M / 2 - 1);     target[1] = (N / 2 + 1 - 1) * M + (M / 2 - 1);     for (int z = 0; z < 2; z++) {       for (int i = 0; i < V; i++) dist[z][i] = -1;       queue<int> q;       dist[z][target[z]] = 0;       q.push(target[z]);       while (!q.empty()) {         int cur = q.front();         q.pop();         int x = cur / M, y = cur % M;         for (int d = 0; d < 8; d++) {           int nx = x + mx[d], ny = y + my[d];           if (0 <= nx && nx < N && 0 <= ny && ny < M) {             int n = nx * M + ny;             if (dist[z][n] == -1) {               dist[z][n] = dist[z][cur] + 1;               nxt[z][n] = cur;               q.push(n);             }           }         }       }       for (int x = 0; x < 2; x++) {         st_dist[x][z] = dist[z][source[x]];       }     }     int adv;     if (parity(source[0]) != parity(source[1])) {       adv = 0;     } else {       adv = 1;     }     int dis_dist = st_dist[!adv][!adv];     int adv_turns = (adv == 0) ? dis_dist : dis_dist - 1;     int me, goal;     if (st_dist[adv][adv] <= adv_turns) {       me = adv;       goal = adv;     } else if (st_dist[adv][!adv] - 1 <= adv_turns) {       me = adv;       goal = !adv;     } else {       me = !adv;       goal = !adv;     }     nxt[0][target[0]] = target[0] + 2 * M + 1;     nxt[1][target[1]] = target[1] - 2 * M + 1;     cout << (me == 0 ?  WHITE  :  BLACK ) <<   n  << flush;     int cur[2] = {source[0], source[1]};     for (int t = 0; true; t++) {       if (t % 2 == me) {         auto print_pos = [&]() {           cout << (cur[me] / M + 1) <<     << (cur[me] % M + 1) <<   n  << flush;         };         if (one_move(cur[me], cur[!me])) {           cur[me] = cur[!me];           print_pos();           exit(0);         }         if (cur[me] == target[goal]) goal = me;         cur[me] = nxt[goal][cur[me]];         print_pos();         if (cur[me] == target[me]) {           exit(0);         }       } else {         int x, y;         cin >> x >> y;         if (x == -1 && y == -1) {           exit(0);         }         x--, y--;         cur[!me] = x * M + y;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 7;   int n, a[maxn], ans[maxn], b[maxn], id;   map<int, int> mp;   int t0 = 0, t1 = 0, t2 = 0;   int cnt[maxn];   void work(int id) {     for (int i = 2;; ++i) {       int t = i * i;       if (a[id] >= 0 && t > a[id]) return;       if (a[id] < 0 && t > -1 * a[id]) return;       if (a[id] % t == 0) {         while (a[id] % t == 0) {           a[id] /= t;         }       }     }   }   void init() {     scanf( %d , &n);     id = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       work(i);       int t;       if (t = mp[a[i]])         b[i] = t;       else         b[i] = mp[a[i]] = id++;     }     memset(ans, 0, sizeof ans);   }   int main() {     init();     for (int i = 1; i <= n; ++i) {       for (int k = 1; k < id; ++k) cnt[k] = 0;       int sum = 0;       for (int j = i; j <= n; ++j) {         if (a[j] && !cnt[b[j]]) {           sum++;         }         cnt[b[j]]++;         ans[max(1, sum)]++;       }     }     for (int i = 1; i <= n; ++i) {       printf( %d%c , ans[i], (i == n ?   n  :    ));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, k = 2000000000;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x % n <= i)         x = x / n;       else         x = x / n + 1;       if (x < k) {         a = i;         k = x;       }     }     cout << (a + 1);   }
#include <bits/stdc++.h>   using namespace std;   long long fact[100001], inv[100001], ifact[100001];   template <typename T, typename T1>   T mod(T x, T1 p) {     x %= p;     if (x < 0) x += p;     return x;   }   template <typename T>   T inverse(T x, T p) {     x = mod(x, p);     if (x == 1) return x;     return mod((1LL * (-p / x) * (inv[p % x] % p)), p);   }   int NcR(int n, int r) {     int ret = (1LL * ifact[n - r] * ifact[r]) % 1000000007;     ret = (1LL * ret * fact[n]) % 1000000007;     return ret;   }   int main(int argc, char **argv) {     ios::sync_with_stdio(false);     fact[0] = 1;     for (int i = 1; i < 100001; i++) {       fact[i] = 1LL * fact[i - 1] * i % 1000000007;     }     ifact[0] = 1;     for (int i = 1; i < 100001; i++) {       inv[i] = inverse(i, 1000000007);       ifact[i] = 1LL * ifact[i - 1] * inv[i] % 1000000007;     }     int N;     cin >> N;     long long ans = 0;     for (int i = 1; i < N; i++) {       ans = (ans + 1LL * NcR(N - 1, i) * NcR(N, i + 1)) % 1000000007;     }     ans = (ans * 2 + N) % 1000000007;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   long long n, m, k, x, s;   const int maxn = 2e5 + 10;   long long a[maxn], b[maxn], c[maxn], d[maxn];   int main(void) {     cin.sync_with_stdio(false);     cin >> n >> m >> k >> x >> s;     for (int i = (0); i < (m); i++) {       cin >> a[i];     }     for (int i = (0); i < (m); i++) {       cin >> b[i];     }     for (int i = (0); i < (k); i++) {       cin >> c[i];     }     for (int i = (0); i < (k); i++) {       cin >> d[i];     }     long long ans = n * x;     for (int i = (0); i < (m); i++) {       long long cur = 0;       long long curd = s - b[i];       if (curd < 0) continue;       int idx = upper_bound(d, d + k, curd) - d - 1;       if (idx < 0) {         cur = n * a[i];         ans = min(ans, cur);       } else {         cur = (n - c[idx]) * a[i];         ans = min(ans, cur);       }     }     int idx = upper_bound(d, d + k, s) - d - 1;     if (idx >= 0) {       long long cur = (n - c[idx]) * x;       ans = min(ans, cur);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 500;   const int INF = 1e7 + 500;   const int MOD = 1e9 + 7;   const int LOG = 18;   const double EPS = 1e-9;   const double PI = 3.1415926535;   vector<pair<int, int> > P;   long double L = INF, R = -INF, M1, M2;   long double dist(long double x0, long double y0, long double x1,                    long double y1) {     return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));   }   long double f(long double sx) {     long double s, h, r = 0;     for (auto p : P) {       s = dist(sx, 0, p.first, p.second);       h = dist(sx, 0, sx, p.second);       r = max(r, (s * s) / (2 * h));     }     return r;   }   int main() {     int N, xi, yi;     bool pl = false, mi = false;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> xi >> yi;       P.push_back({xi, yi});       if (yi > 0) pl = true;       if (yi < 0) mi = true;       if (L > xi) L = xi;       if (R < xi) R = xi;     }     if (pl & mi) {       cout <<  -1  << endl;       return 0;     }     long double rad1, rad2, ans = 1e18;     for (int i = 0; i < 500; i++) {       M1 = (2 * L + R) / 3;       M2 = (L + 2 * R) / 3;       rad1 = f(M1);       rad2 = f(M2);       if (rad1 < rad2) {         R = M2;         ans = min(ans, rad1);       } else {         L = M1;         ans = min(ans, rad2);       }     }     cout << setprecision(20) << ans << endl;     return 0;   }