malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, val, i, j, k, n, m, val2;     vector<pair<long long, long long> > ans;     cin >> x;     for (n = 1; n <= (3000000); n++) {       val = x;       val -= (n - 1) * n * (2 * n - 1) / 6;       val += n * n * (n - 1) / 2;       val2 = n * n - ((n - 1) * n) / 2;       if (val % val2 == 0) {         val2 = val / val2;         if (val2 >= n) {           ans.push_back(make_pair(n, val2));           if (n != val2) ans.push_back(make_pair(val2, n));         }       }     }     printf( %d n , ans.size());     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++)       printf( %lld %lld n , ans[i].first, ans[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n, m, f[N], vis[N], cnt;   int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }   struct node {     int x, y, w;   } a[N];   bool cmp(node a, node b) { return a.w < b.w; }   int main() {     while (cin >> n >> m) {       int ans = 0;       for (int i = 1; i <= n; i++) f[i] = i;       for (int i = 1; i <= m; i++) {         int x, y, k;         cin >> x >> y >> k;         a[i].x = x;         a[i].y = y;         a[i].w = k;       }       sort(a + 1, a + 1 + m, cmp);       int mx = 0;       for (int i = 1; i <= m;) {         int j = i;         while (a[i].w == a[j].w) j++;         cnt = 0;         for (int k = i; k < j; k++)           if (find(a[k].x) != find(a[k].y)) cnt++;         for (int k = i; k < j; k++) {           if (find(a[k].x) != find(a[k].y)) {             f[find(a[k].x)] = find(a[k].y);             cnt--;           }         }         ans += cnt;         i = j;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long x[105];   double f[105][105525];   double sum[105525];   inline void read() {     cin >> n >> m;     for (long long i = 0; i <= n - 1; i++) {       cin >> x[i];     }   }   inline void solve() {     long long ms = n * m;     if (m == 1) {       puts( 1 );       return;     }     f[0][0] = 1;     for (long long i = 0; i <= n - 1; i++) {       for (long long s = 0; s <= ms; s++) {         if (s) {           sum[s] = sum[s - 1] + f[i][s];         } else {           sum[s] = f[i][s];         }         if (s > m) {           f[i + 1][s] = sum[s - 1] - sum[s - m - 1];         } else {           f[i + 1][s] = sum[s - 1];         }         if (s >= x[i]) {           f[i + 1][s] -= f[i][s - x[i]];         }         f[i + 1][s] /= (m - 1);       }     }     long long score = 0;     for (long long i = 0; i <= n - 1; i++) {       score += x[i];     }     double prob = 0;     for (long long s = 0; s <= score - 1; s++) {       prob += f[n][s];     }     prob *= (m - 1);     prob += 1.0;     cout.precision(20);     cout << fixed << prob;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::fixed;   using std::make_pair;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::sort;   const long long base = (long long)(5 * 1e8 + 5);   const long long coefficient = (long long)(4 * 1e9);   long long convertCoordinate(long long x, long long y) {     return (x + base) * coefficient + (y + base);   }   pair<long long, long long> convertCoordinateBack(long long pos) {     long long x = pos / coefficient - base - base;     long long y = pos % coefficient - base - base;     return make_pair(x, y);   }   const int MaxN = 200000 + 9;   int n, k, l, r, used;   long long points[MaxN];   long long x, y, now;   set<long long> waitList;   set<pair<long long, long long> > ans;   set<long long>::iterator it;   set<pair<long long, long long> >::iterator pit;   int main() {     waitList.clear();     ans.clear();     scanf( %d%d , &n, &k);     if (k >= n) return cout <<  -1 n , 0;     for (int i = 1; i <= n; i++) {       scanf( %I64d%I64d , &x, &y);       points[i] = convertCoordinate(x, y);     }     sort(points + 1, points + n + 1);     for (int i = 1; i <= min(k + 2, n); i++) {       for (int j = max(n - k - 2, 1); j <= n; j++) {         waitList.insert(points[i] + points[j]);       }     }     for (it = waitList.begin(); it != waitList.end(); it++) {       l = 1;       r = n;       used = 0;       while (l <= r) {         now = points[l] + points[r];         if (now < (*it))           l++, used++;         else if (now > (*it))           r--, used++;         else           l++, r--;       }       if (used <= k) ans.insert(convertCoordinateBack(*it));     }     if (ans.size() == 0)       printf( 0 n );     else {       printf( %d n , ans.size());       for (pit = ans.begin(); pit != ans.end(); pit++) {         printf( %.2lf %.2lf n , (double)(*pit).first * 0.5,                (double)(*pit).second * 0.5);       }     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     string s;     cin >> s;     long long int n = s.length();     long long int dp[s.length() + 5][27];     for (int i = 0; i <= s.length(); i++) {       for (int j = 0; j < 27; j++) dp[i][j] = 0;     }     for (int i = 0; i < s.length(); i++) {       if (i != 0) {         for (int j = 0; j < 27; j++) {           dp[i + 1][j] = dp[i][j];         }       }       dp[i + 1][s[i] -  a ]++;     }     long long int ans = 1000000000000000000;     for (char c =  a ; c <=  z ; c++) {       long long int low = 1, high = n;       long long int mid;       while (low <= high) {         mid = (low + high) / 2;         bool f = 1;         for (int i = mid; i <= n; i++) {           if (dp[i][c -  a ] - dp[i - mid][c -  a ] <= 0) {             f = 0;           }         }         if (f) {           high = mid - 1;         } else {           low = mid + 1;         }       }       ans = min(low, ans);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   template <class T>   void clr(T& a, int n) {     a.clear();     a.resize(n + 1);   }   void solve();   const int N = 2e5 + 10;   const int INF = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }   int n;   void solve() {     cin >> n;     vector<long long> a(n + 1);     for (int i = int(1); i <= int(n); i++) {       cin >> a[i];     }     const int B = 20;     vector<long long> count(B + 1);     for (int i = int(1); i <= int(n); i++) {       for (int j = int(0); j <= int(B); j++) {         long long mask = (1ll << j);         count[j] += (mask & a[i] ? 1 : 0);       }     }     debug() <<   [              <<  count                  :               << (count) <<  ]  ;     long long ans = 0;     for (int i = int(1); i <= int(n); i++) {       long long curr = 0;       for (int j = int(0); j <= int(B); j++) {         if (count[j] == 0) continue;         curr += (1ll << j);         count[j]--;       }       ans += curr * curr;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   class state {    public:     int d[4];     int e;     state() : d{0, 0, 0, 0}, e(1) {}     bool operator<(const state &x) const {       for (int i = 0; i < 4; ++i) {         if (d[i] == x.d[i]) continue;         return d[i] > x.d[i];       }       return e > x.e;     }     bool operator!=(const state &x) const {       for (int i = 0; i < 4; ++i)         if (d[i] != x.d[i]) return true;       return e != x.e;     }   };   std::map<state, int> mp;   int main() {     int n;     scanf( %d , &n);     mp[state()] = 0;     while (n--) {       int a, b;       scanf( %d%d , &a, &b);       std::map<state, int> nmp;       for (auto it = mp.begin(); it != mp.end(); ++it) {         if (it->first.d[0] != 0) continue;         state s = it->first;         int t = it->second;         t += abs(a - s.e) + 1;         s.e = a;         s.d[0] = b;         std::sort(s.d, s.d + 4);         auto it2 = nmp.lower_bound(s);         if (it2 == nmp.end() || it2->first != s)           it2 = nmp.insert(it2, std::pair<state, int>(s, t));         it2->second = std::min(it2->second, t);       }       mp.swap(nmp);       0;       for (auto it = mp.begin(); it != mp.end(); ++it) {         0;         for (int i = 0; i < 4; ++i) {           if (!it->first.d[i]) continue;           state s = it->first;           int t = it->second;           t += abs(s.d[i] - s.e) + 1;           s.e = s.d[i];           s.d[i] = 0;           std::sort(s.d, s.d + 4);           auto it2 = mp.lower_bound(s);           if (it2 == mp.end() || it2->first != s)             it2 = mp.insert(it2, std::pair<state, int>(s, t));           it2->second = std::min(it2->second, t);         }       }     }     int ans = ((int)1e9);     for (auto it = mp.begin(); it != mp.end(); ++it) {       if (it->first.d[0] || it->first.d[1] || it->first.d[2] || it->first.d[3])         continue;       ans = std::min(ans, it->second);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[15], cnt[7] = {0}, ans = 0;   int j, hr = 0, mi = 0;   int se[100] = {0};   vector<int> na, ma;   void rec(int pos, int a) {     int i;     if (pos == -1) {       ans++;       return;     }     if (pos == mi - 1) {       for (i = 0; i <= na[pos]; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           if (i == na[pos]) se[pos] = 1;           rec(pos - 1, i);           cnt[i] = 0;         }         se[pos] = 0;       }     } else if (se[pos + 1] == 0) {       for (i = 0; i < 7; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           rec(pos - 1, i);           cnt[i] = 0;         }       }     } else {       for (i = 0; i <= na[pos]; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           if (i == na[pos]) {             se[pos] = 1;           }           rec(pos - 1, i);           cnt[i] = 0;         }         se[pos] = 0;       }     }   }   bool chk(int *a, int n) {     int i, flg = 0;     for (i = 0; i < n - 1; i++) {       if (a[i] <= a[i + 1])         flg = 1;       else {         flg = 0;         break;       }     }     return flg;   }   int main() {     arr[0] = 1;     for (int i = 1; i <= 10; i++) {       arr[i] = arr[i - 1] * 7;     }     int n, m, i;     cin >> n >> m;     n = n - 1;     m = m - 1;     int x = n, y = m;     if (y == 0) {       na.push_back(0);       mi++;     }     while (y != 0) {       na.push_back(y % 7);       mi++;       y = y / 7;     }     if (x == 0) {       na.push_back(0);       hr++;     }     while (x != 0) {       na.push_back(x % 7);       hr++;       x = x / 7;     }     if (hr + mi > 7)       ans = 0;     else {       int pos = na.size() - 1;       for (i = 0; i <= na[pos]; i++) {         cnt[i] = 1;         if (i == na[pos]) se[pos] = 1;         rec(pos - 1, i);         cnt[i] = 0;         se[pos] = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[55][55];   int main() {     int n;     scanf( %d , &n);     memset(a, 0, sizeof(a));     int p = 1, q = 2, nn = n / 2 + 1;     for (int i = 1; i <= n; ++i) {       a[nn][i] = p;       p += 2;     }     for (int i = 1; i <= n; ++i) {       if (i != nn) {         a[i][nn] = p;         p += 2;       }     }     int maxn = n * n;     for (int i = 1; i < nn; ++i) {       for (int j = 1; j < nn; ++j) {         if (p <= maxn) {           a[i][j] = p;           a[n + 1 - i][j] = p + 2;           a[n + 1 - i][n + 1 - j] = p + 4;           a[i][n + 1 - j] = p + 6;           p += 8;         } else {           a[i][j] = q;           a[n + 1 - i][j] = q + 2;           a[n + 1 - i][n + 1 - j] = q + 4;           a[i][n + 1 - j] = q + 6;           q += 8;         }       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) printf( %d  , a[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) { return (a > b) ? a : b; }   struct player {     int i;     int j;     int pos;   };   int main() {     bool firstwon1 = false;     bool secondwon1 = false;     bool firstwon2 = false, firstwon3 = false, firstwon4 = false;     bool secondwon2 = false, secondwon3 = false, secondwon4 = false;     int won = 0;     player a[2], b[2];     cin >> a[0].i >> a[0].j;     cin >> a[1].i >> a[1].j;     cin >> b[0].i >> b[0].j;     cin >> b[1].i >> b[1].j;     if (a[0].i > b[1].j && a[1].j > b[0].i) firstwon1 = true;     if (a[0].i < b[1].j && a[1].j < b[0].i) secondwon1 = true;     if (a[0].i > b[0].j && a[1].j > b[1].i) firstwon2 = true;     if (a[0].i < b[0].j && a[1].j < b[1].i) secondwon2 = true;     if (a[1].i > b[1].j && a[0].j > b[0].i) firstwon3 = true;     if (a[1].i < b[1].j && a[0].j < b[0].i) secondwon3 = true;     if (a[1].i > b[0].j && a[0].j > b[1].i) firstwon4 = true;     if (a[1].i < b[0].j && a[0].j < b[1].i) secondwon4 = true;     if ((firstwon1 == true && firstwon2 == true) ||         (firstwon3 == true && firstwon4 == true))       won = 1;     if ((secondwon1 == true || secondwon2 == true) &&         (secondwon3 == true || secondwon4 == true))       won = 2;     switch (won) {       case 1: {         cout <<  Team 1 n ;         break;       }       case 2: {         cout <<  Team 2 n ;         break;       }       case 0: {         cout <<  Draw n ;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const double pi = acos(-1.0);   void cp();   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long fact(long long n) {     if (n <= 1) return n;     return n * fact(n - 1);   }   bool prime[100001];   void sieve() {     int n = 10000;     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   void solve() {     int n, i;     cin >> n;     string s;     cin >> s;     for (i = 0; i <= (2 * n) - 1; i++) {       if (i % 2 == 0) cout << s[i];     }     cout <<   n ;   }   int main() {     cp();     int t;     cin >> t;     while (t--) solve();     return 0;   }   void cp() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }
#include <bits/stdc++.h>   using namespace std;   typedef pair<int, int> P;   const int OO = 1e18;   const int md = 1e9 + 7;   int X[] = {0, 0, 1, -1}, Y[] = {1, -1, 0, 0};   void fast() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int dp[int(1e4 + 4)], t = 0, x, y, z, n, q, g[int(1e4 + 4)], res;   pair<P, int> p[int(1e4 + 4)];   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < q; i++)       scanf( %d%d%d , &p[i].first.first, &p[i].first.second, &p[i].second);     sort(p, p + q);     memset(dp, -1, sizeof dp);     memset(g, -1, sizeof g);     dp[0] = g[0] = n;     for (int i = 0; i < q; i++) {       for (int j = 0; j <= n; j++) {         g[j] = max(g[j], dp[j]);         if (dp[j] >= p[i].first.first && j + p[i].second <= n)           g[j + p[i].second] =               max(dp[j + p[i].second], min(dp[j], p[i].first.second));       }       g[p[i].second] = max(g[p[i].second], p[i].first.second);       swap(dp, g);     }     for (int i = 1; i <= n; i++)       if (dp[i] != -1) res++;     printf( %d n , res);     for (int i = 1; i <= n; i++)       if (dp[i] != -1) printf( %d  , i);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int Maxn = 10010;   int a[Maxn];   int tot = 0;   int main() {     int n;     cin >> n;     long long sum = 0;     for (int i = 2; i <= n; i++) {       for (int j = 2 * i; j <= n; j += i) {         sum += 4ll * (j / i);       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct PR {     int to;     int ne;   } Prise[200010];   bool compare(PR a, PR b) { return (a.to - a.ne) < (b.to - b.ne); }   int main(int argc, char const *argv[]) {     int n, k;     cin >> n >> k;     int i;     for (i = 0; i < n; i++) {       cin >> Prise[i].to;     }     for (i = 0; i < n; i++) {       cin >> Prise[i].ne;     }     sort(Prise, Prise + n, compare);     int count = 0;     for (i = 0; i < k; i++) {       count += Prise[i].to;     }     for (i = k; i < n; i++) {       if (Prise[i].to < Prise[i].ne) {         count += Prise[i].to;       } else {         count += Prise[i].ne;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long far(long long x, long long y) { return x * x + y * y; }   vector<long long> val;   vector<long long> dsu;   vector<long long> rang;   long long pred(long long a) {     if (a == dsu[a]) {       return a;     } else {       long long to = pred(dsu[a]);       if (to != dsu[a]) {         val[a] *= val[dsu[a]];       }       dsu[a] = to;       return to;     }   }   void unite(long long a, long long b) {     a = pred(a);     b = pred(b);     if (a != b) {       if (rang[a] < rang[b]) {         swap(a, b);       }       if (val[a] == -1) {         val[b] *= -1;       }       dsu[b] = a;       if (rang[a] == rang[b]) {         rang[a]++;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     val.resize(n);     dsu.resize(n);     rang.resize(n);     vector<pair<long long, long long> > x(n);     vector<long long> type(n, 1);     long long stx = 0, sty = 0;     for (long long i = 0; i < n; i++) {       cin >> x[i].first >> x[i].second;     }     long long p = 1e6;     p = p * p;     vector<long long> ind(n);     for (long long i = 0; i < n; i++) {       ind[i] = i;       dsu[i] = i;       rang[i] = 1;       val[i] = 1;     }     for (long long i = 0; i < n - 2; i++) {       for (long long j = i + 0; j < min(n, 3 + i); j++) {         for (long long d = j + 1; d < min(n, 3 + i); d++) {           if (far(x[j].first + x[d].first, x[j].second + x[d].second) <= p) {             unite(ind[j], ind[d]);             x[d].first += x[j].first;             x[d].second += x[j].second;             if (j != i) {               x[i + 1] = x[i];               ind[i + 1] = ind[i];             }             j = 3 + i;             break;           } else if (far(x[j].first - x[d].first, x[j].second - x[d].second) <=                      p) {             val[pred(ind[d])] *= -1;             unite(ind[j], ind[d]);             x[d].first = x[j].first - x[d].first;             x[d].second = x[j].second - x[d].second;             if (j != i) {               x[i + 1] = x[i];               ind[i + 1] = ind[i];             }             j = 3 + i;             break;           }         }       }     }     long long p1 = 1.5e6;     p1 = p1 * p1;     if (n > 1) {       if (far(x[n - 2].first + x[n - 1].first,               x[n - 2].second + x[n - 1].second) <= p1) {         unite(ind[n - 2], ind[n - 1]);       } else {         val[pred(ind[n - 1])] *= -1;         unite(ind[n - 2], ind[n - 1]);       }     }     for (long long i = 0; i < n; i++) {       long long t = pred(i);       if (t != i) {         cout << val[t] * val[i] <<    ;       } else {         cout << val[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   const double EPS = 1e-15;   const int INF = 1e9 + 7;   const long long LINF = 8e18 + 7;   const int N = 2e5 + 7;   vector<long long> t[4 * N];   int a[N];   long long s[N];   void build(int v, int L, int R) {     if (L + 1 == R) {       t[v].push_back(s[L]);       return;     }     int M = L + R >> 1;     build(v << 1, L, M);     build(v << 1 | 1, M, R);     t[v].resize(t[v << 1].size() + t[v << 1 | 1].size());     merge(t[v << 1].begin(), t[v << 1].end(), t[v << 1 | 1].begin(),           t[v << 1 | 1].end(), t[v].begin());   }   int get(int v, int L, int R, int l, int r, long long val) {     if (L == l && R == r) {       return t[v].end() - upper_bound(t[v].begin(), t[v].end(), val);     }     int M = L + R >> 1;     int ans = 0;     if (l < M) {       ans += get(v << 1, L, M, l, min(M, r), val);     }     if (r > M) {       ans += get(v << 1 | 1, M, R, max(l, M), r, val);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long long t;     cin >> n >> t;     for (int i = 0; i < int(n); ++i) {       cin >> a[i];       s[i + 1] = a[i] + s[i];     }     build(1, 0, n + 1);     long long ans = 0;     for (int i = 0; i < int(n); ++i) {       ans += get(1, 0, n + 1, 0, i + 1, s[i + 1] - t);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 3;   int t;   long long m, n;   pair<long long, long long> v[MX];   long long p[MX];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %lld %lld , &n, &m);       long long ans = 0;       for (int i = 0; i < m; i++) {         scanf( %lld %lld , &v[i].first, &v[i].second);       }       sort(v, v + m, greater<pair<long long, long long>>());       for (int i = 0; i < m; i++) {         p[i] = v[i].first + (i ? p[i - 1] : 0);         if (i < n) ans += v[i].first;       }       for (int i = 0; i < m; i++) {         int l = 0;         int r = m - 1;         int md;         while (l != r) {           md = (l + r) / 2;           if (v[md].first < v[i].second)             r = md;           else             l = md + 1;         }         int cnt = l;         if (v[m - 1].first >= v[i].second) cnt++, l++;         long long sum = 0;         if (l) sum = p[l - 1];         if (l > i && cnt) {           cnt--;           sum -= v[i].first;         }         if (cnt > n - 2) {           continue;         }         long long ret = v[i].first + v[i].second * (n - cnt - 1) + sum;         ans = max(ans, ret);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string equalString(string a) {     int len = a.size();     if (len % 2 == 1) return a;     string a1 = a.substr(0, len / 2);     string a2 = a.substr(len / 2, len / 2);     a1 = equalString(a1);     a2 = equalString(a2);     return a1.compare(a2) < 0 ? a1 + a2 : a2 + a1;   }   int main() {     string a, b;     cin >> a >> b;     string nor_a = equalString(a);     string nor_b = equalString(b);     if (nor_a.compare(nor_b) == 0)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }