malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     if (y == 0) return 1;     if (y & 1) return (x * power(x, y - 1)) % 1000000007;     long long int t = power(x, y / 2);     return (t * t) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     set<int> arr[26];     int n = (int)s.size();     for (int i = 0; i < n; i++) arr[s[i] -  a ].insert(i);     string mk =  Mike n ;     string ann =  Ann n ;     bool found = false;     for (int i = 0; i < n; i++) {       found = false;       for (int j = 0; j < s[i] -  a ; j++) {         auto itr = arr[j].lower_bound(0);         if (itr != arr[j].end() && *itr < i) {           found = true;           break;         }       }       if (true == found)         cout << ann;       else         cout << mk;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1000010;   const int inf = 0x3f3f3f3f;   using namespace std;   int n, m;   int c[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       c[a]++;       c[b]++;     }     if (n < 3) return puts( 0 ), 0;     long long ret = 0;     for (int i = 1; i <= n; i++) ret += 1ll * c[i] * (n - 1 - c[i]);     ret /= 2;     cout << (1ll * n * (n - 1) * (n - 2) / 6 - ret) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using dd = double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   ll INFLL = (ll)2e18, MOD = 1e9 + 7;   const int INF = 0x6f6f6f6f;   vector<vector<ll>> adj;   vector<int> vis;   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},       dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   inline ll mexp(ll x, ll n, ll m) {     ll res = 1;     while (n) {       if (n & 1) res = (res * x) % m;       n >>= 1;       x = ((x % m) * (x % m)) % m;     }     return res;   }   inline bool ispow2(ll x) { return x && (!(x & (x - 1))); }   inline ll gcd(ll x, ll y) {     pll p{x, y};     while (p.second) p = {p.second, p.first % p.second};     return p.first;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     cerr << fixed;     cout << setprecision(10);     cerr << setprecision(3);     mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());     int n;     cin >> n;     vector<int> seq(n + 1);     map<int, int> m;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       m[t] = i + 1;     }     int ct = 1;     for (auto& e : m) seq[e.second] = ct++;     m.clear();     vector<ll> tree(n + 1, 0);     auto sum = [&](int pos) {       ll ret = 0;       while (pos) {         ret += tree[pos];         pos -= pos & -pos;       }       return ret;     };     auto upd = [&](int pos, ll val) {       while (pos <= n) {         tree[pos] += val;         pos += pos & -pos;       }     };     ll ans = 0;     for (int i = 1; i <= n; ++i) {       ll gr = sum(n) - sum(seq[i]);       ll le = seq[i] - 1 - sum(seq[i] - 1);       ans += gr * le;       upd(seq[i], 1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, int> > H[1000007];   long long n, val[1000005], ans, cnt[1000005];   int S[1000005];   int m, up[1000005], p[1000005], len, b[1000005], mp[1000005];   void prepare() {     int i, j;     b[1] = 1;     for (i = 2; i < 1000005; i++) {       if (!b[i]) p[++len] = i;       for (j = 1; j <= len; j++) {         if (1LL * i * p[j] >= 1000005) break;         b[1LL * i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }     for (i = 1; i < 1000005; i++) S[i] = S[i - 1] + (!b[i]);     for (i = 1; i <= len; i++) mp[p[i]] = i;     for (i = 1000005 - 1; i >= 1; i--) mp[i] = mp[i] ? mp[i] : mp[i + 1];   }   int SQRT(long long n) {     int p = (int)(sqrt(n));     while (1LL * p * p <= n) p++;     return p;   }   long long find(long long x, int t) {     int i, u = x % 1000007, p;     for (i = 0; i < H[u].size(); i++)       if (H[u][i].first == x) break;     p = H[u][i].second;     return t > up[p] ? cnt[p] + up[p] - t : cnt[p];   }   long long Pi(int t) { return cnt[t] + up[t] - 1; }   void update(int t) {     long long i, x = val[t], l = n / (x + 1) + 1, r = n / x;     r = min(r, (long long)(sqrt(n)));     for (i = l; i <= r; i++)       if (!b[i]) ans += Pi(t) - S[i];   }   int main() {     long long i, j = 1, q = 1;     long long x = 0;     cin >> n;     prepare(), m = 1;     for (i = 1; 1LL * p[i] * p[i] * p[i] <= n; i++) ans++;     for (i = 1; i <= n; i = n / (val[m++]) + 1) val[m] = n / i;     m--, sort(val + 1, val + m + 1);     for (i = 1; i <= m; i++)       H[val[i] % 1000007].push_back(pair<long long, int>(val[i], i));     for (i = 1; i <= m; i++) up[i] = mp[SQRT(val[i])];     for (i = 1; i <= up[m]; i++) {       for (j = m; j >= q; j--) {         if (i != 1) {           x = find(val[j] / p[i - 1], i - 1);           cnt[j] = cnt[j] - x - 1;         } else           cnt[j] = val[j] - 1;       }       while (q <= m && i == up[q]) update(q++);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n, i, j, k, l, m, arr[100010], arr1[100010], x, y;     double a, b, c, d, p, t;     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     reverse(arr, arr + n);     arr1[0] = arr[0];     for (i = 1; i < n; i++) arr1[i] = arr1[i - 1] + arr[i];     m = 9999999999;     for (i = 0; i < n - 1; i++)       m = min(abs(abs(arr1[n - 1] - arr1[i]) - arr1[i]) + 1, m);     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   int in() {     int n;     scanf( %d , &n);     return n;   }   long long Lin() {     long long n;     scanf( %lld , &n);     return n;   }   double Din() {     double n;     scanf( %lf , &n);     return n;   }   const long long inf = (long long)1e17;   const long long mod = (long long)1e9 + 7;   const int N = 5e5 + 5;   struct trie {     trie* node[2];     int cnt;     trie() {       node[0] = node[1] = NULL;       cnt = 0;     }   };   void add(trie* root, long long x, bool ck) {     for (int i = 1; i <= 18; i++) {       int p = (x % 2 == 1);       x /= 10;       if (root->node[p] == NULL) root->node[p] = new trie;       root = root->node[p];     }     ck ? root->cnt++ : root->cnt--;   }   int query(trie* root, string s) {     reverse(s.begin(), s.end());     while (s.size() < 18) s.push_back( 0 );     for (int i = 0; i < 18; i++) {       int p = s[i] -  0 ;       if (root->node[p] == NULL) return 0;       root = root->node[p];     }     return root->cnt;   }   int solve() {     int q = in();     trie* root = new trie;     while (q--) {       string ck;       long long x;       cin >> ck;       if (ck ==  + ) {         x = Lin();         add(root, x, true);       } else if (ck ==  - ) {         x = Lin();         add(root, x, false);       } else {         string s;         cin >> s;         printf( %d n , query(root, s));       }     }     return 0;   }   int main() {     int test = 1, tc = 0;     while (test--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     cin >> n >> k;     int r[257] = {};     for (int i = 0; i < 257; i++) {       r[i] = -1;     }     int p;     for (int i = 0; i < n; i++) {       cin >> p;       if (r[p] == -1) {         for (int j = (p - k + 1 >= 0) ? p - k + 1 : 0; j <= p; j++) {           if (r[j] == -1) {             for (int x = j; x <= p; x++) {               if (r[x] != -1) break;               r[x] = j;             }             break;           } else if (r[j + 1] == -1 && r[j] + k - 1 >= p) {             for (int x = j + 1; x <= p; x++) {               r[x] = r[j];             }             break;           }         }       }       cout << r[p] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int i = n / 2 - 1, j = n / 2;     sort(arr, arr + n);     int x = 0;     int ans[n];     if (n % 2) ans[0] = arr[n / 2], x++, j++;     for (; i >= 0 && j < n; i--, j++) {       ans[x++] = arr[i];       ans[x++] = arr[j];     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   void test_case() {     int n;     cin >> n;     cout << fixed << setprecision(10) << (1 / tan(PI / (2 * n))) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tc;     cin >> tc;     for (int tt = 1; tt <= tc; ++tt) {       test_case();     }     return 0;   }
#include <bits/stdc++.h>   struct node {     char a;     struct node *left;     struct node *right;   };   int main() {     int t, len;     char ch[205];     struct node *p, *q, *r[26];     scanf( %d , &t);     getchar();     while (t--) {       int flag = 0;       scanf( %s , ch);       len = strlen(ch);       for (int i = 0; i < 26; i++) r[i] = NULL;       for (int i = 0; i < len; i++) {         if (r[ch[i] -  a ] == NULL) {           p = (struct node *)malloc(sizeof(struct node));           p->a = ch[i];           p->left = NULL;           p->right = NULL;           r[ch[i] -  a ] = p;           if (i > 0) {             if (r[ch[i - 1] -  a ]->left == NULL) {               r[ch[i - 1] -  a ]->left = p;               p->right = r[ch[i - 1] -  a ];             } else if (r[ch[i - 1] -  a ]->right == NULL) {               r[ch[i - 1] -  a ]->right = p;               p->left = r[ch[i - 1] -  a ];             } else {               printf( NO n );               flag = 1;               break;             }           }         } else {           if (r[ch[i] -  a ]->left != r[ch[i - 1] -  a ] &&               r[ch[i] -  a ]->right != r[ch[i - 1] -  a ]) {             printf( NO n );             flag = 1;             break;           }         }       }       if (flag == 1) continue;       printf( YES n );       for (int i = 0; i < 26; i++) {         if (r[i] != NULL) {           q = r[i];           while (q->left != NULL) q = q->left;           while (q != NULL) {             printf( %c , q->a);             q = q->right;           }           break;         }       }       for (int i = 0; i < 26; i++)         if (r[i] == NULL) printf( %c , i +  a );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(2e6);   int n;   bool used[N + 7];   int main() {     cin >> n;     for (int i = 2; i * i <= N; ++i) {       if (!used[i]) {         for (int z = i * i; z <= N; z = z + i) used[z] = true;       }     }     int cnt = 0;     for (int i = 2; i <= N; ++i)       if (!used[i]) {         printf( %d  , i);         ++cnt;         if (cnt == n) return 0;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long const M = 2e5 + 10, M2 = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long tmp = 1;     for (long long i = 1;; i++) {       if (tmp - 1 >= n) return cout << i - 1, 0;       tmp *= 2;     }   }
#include<bits/stdc++.h>   using namespace std;   #define pi acos(-1)   #define printfl   printf( %f n ,f)   #define printd   printf( %lf n ,d)   #define printi   printf( %d n ,p)   #define printl   printf( %ld n ,l)   #define printll   printf( %lld n ,ll)   #define case cout<< Case  <<TEST<< :     #define forcase   for(int TEST=1;TEST<=test;TEST++)   #define max3(a,b,c) max((a,b),c)   #define min3(a,b,c) min((a,b),c)   #define newl printf(  n )   #define printd1d2 printf( %lf %lf n ,d1, d2)   #define ll long long int   void solve()   {       ll n,q;cin>>n>>q;       string s;cin>>s;       map <ll,ll> mp;       ll indx=1;       for (ll i = 1; i <=26; i++)           {               mp[i-1]=i;                          }      ll sum[n+1];      sum[0]=0;      ll l=1;      for (ll i = 0; i < s.size(); i++)          {              sum[l]=sum[l-1]+mp[s[i]- a ];              l++;          }               for (ll i = 0; i < q; i++)          {              ll c,d;cin>>c>>d;              cout<<sum[d]-sum[c-1]<<endl;          }        // cout<<sum[13]<<endl;                      }   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     int test;    // cin>>test;     //forcase     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod_factorial[100005];   long long mod_inv_factorial[100005];   long long binpow(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) {         res = (res * a);       }       a = (a * a);       b >>= 1;     }     return res;   }   long long binpowmod(long long a, long long b, long long p) {     long long res = 1LL;     while (b) {       if (b & 1) {         res = (res * 1LL * a) % 1000000007;       }       a = (a * 1LL * a) % 1000000007;       b >>= 1;     }     return res;   }   long long mod_inverse(long long a) {     return binpowmod(a, 1000000007 - 2, 1000000007);   }   void precomputefact() {     mod_factorial[0] = 1;     for (int i = 1; i <= 1e5; i++) {       mod_factorial[i] = (i * 1LL * mod_factorial[i - 1]) % 1000000007;     }     mod_inv_factorial[0] = 1;     for (int i = 1; i <= 1e5; i++) {       mod_inv_factorial[i] =           ((mod_inv_factorial[i - 1]) * 1LL * mod_inverse(i)) % 1000000007;     }   }   long long modbinomial(long long n, long long k, long long p) {     long long ans = mod_factorial[n] * mod_inv_factorial[n - k] % 1000000007 *                     mod_inv_factorial[k] % 1000000007;     return ans;   }   void solve() {     int n;     cin >> n;     vector<pair<int, int>> temp;     function<bool(pair<int, int>, pair<int, int>)> comp = [](pair<int, int> a,                                                              pair<int, int> b) {       if (a.first < b.first) {         return true;       } else if (a.first == b.first) {         if (a.second > b.second) {           return true;         }       }       return false;     };     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       temp.push_back(make_pair(l, r));     }     sort(temp.begin(), temp.end(), comp);     for (int i = 0; i < temp.size(); i++) {       int f = temp[i].first;       int s = temp[i].second;       if (f == s) {         cout << f <<     << s <<     << f <<   n ;       } else {         if (f == temp[i + 1].first) {           cout << f <<     << s <<     << temp[i + 1].second + 1 <<   n ;         } else if (s == temp[i + 1].second) {           cout << f <<     << s <<     << temp[i + 1].first - 1 <<   n ;         }       }     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long testcase;     cin >> testcase;     while (testcase--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool discount_flag = true;     int num_of_session;     cin >> num_of_session;     vector<int> num_of_teams(200001);     for (int i = 0; i < num_of_session; i++) cin >> num_of_teams[i];     for (int i = 0; i < num_of_session; i++)       if (num_of_teams[i] % 2 == 1)         if (i != num_of_session - 1 and num_of_teams[i + 1] > 0) {           num_of_teams[i + 1] -= 1;           num_of_teams[i] = 0;         } else if (num_of_teams[i + 1] == 0)           discount_flag = false;         else if (i == num_of_session)           discount_flag = false;     if (discount_flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fact(vector<int> x, long long t) {     if (t == 1) return 1;     vector<long long> num(x.begin(), x.end());     stringstream s;     string tmp;     s << t;     s >> tmp;     int count = 0;     for (int i = 0; i < num.size(); i++) {       stringstream ss;       string temp;       ss << num[i];       ss >> temp;       bool flag = false;       for (int j = 0; j < temp.size(); j++) {         for (int k = 0; k < tmp.size(); k++)           if (temp[j] == tmp[k]) {             count++;             flag = true;             break;           }         if (flag) break;       }     }     return count;   }   int main() {     long long n;     cin >> n;     long long t = n;     vector<int> factors;     long long i;     factors.push_back(1);     for (i = 2; i < sqrt(n); i++) {       if (n % i == 0) {         factors.push_back(n / i);         factors.push_back(i);       }     }     if (i * i == n) {       factors.push_back(i);     }     factors.push_back(n);     cout << fact(factors, t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void optimise() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int mod = 998244353;   long long int inf = 1e18 + 6;   void normalize(long long int &a) { a = (a + mod) % mod; }   long long int modmul(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a * b) % mod;   }   long long int modadd(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a + b) % mod;   }   long long int modsub(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a - b + mod) % mod;   }   long long int me(long long int x, long long int n) {     x %= mod;     if (n == 0) return 1;     long long int u = me(x, n / 2) % mod;     u = (u * u) % mod;     if (n % 2) u = (u * x) % mod;     return u;   }   long long int me1(long long int x, long long int n) {     if (n == 0) return 1;     long long int u = me1(x, n / 2);     u = u * u;     if (n % 2) u = u * x;     return u;   }   inline long long int modInv(long long int a) { return me(a, mod - 2); }   inline long long int modDiv(long long int a, long long int b) {     return modmul(a, modInv(b));   }   long long int __gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return __gcd(b, a % b);   }   const long long int N = 1e6 + 1;   vector<long long int> G[N];   void solve() {     long long int n;     cin >> n;     long long int a[n + 1];     long long int sum[n + 1];     sum[0] = 0;     for (long long int i = 1; i <= n; ++i) {       cin >> a[i];       sum[i] = sum[i - 1] + a[i];     }     map<long long int, vector<pair<long long int, long long int> > > m;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j + i - 1 <= n; j++) {         long long int sum1 = sum[i + j - 1] - sum[j - 1];         m[sum1].push_back({j + i - 1, j});       }     }     long long int max1 = 0;     long long int ans = -1;     for (auto i = m.begin(); i != m.end(); i++) {       sort(m[i->first].begin(), m[i->first].end());       long long int j1 = 0;       long long int r = 0;       long long int sum1 = i->first;       for (auto j = m[sum1].begin(); j != m[sum1].end(); j++) {         if (j->second > r) {           j1++;           r = j->first;         }       }       if (j1 > max1) {         ans = sum1;         max1 = j1;       }     }     cout << max1 <<   n ;     long long int r = 0;     for (auto k1 = m[ans].begin(); k1 != m[ans].end(); k1++) {       if (k1->second > r) {         cout << k1->second <<     << k1->first <<   n ;         r = k1->first;       }     }   }   signed main() {     optimise();     long long int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     long long int a[n + 2];     vector<long long int> pre(n + 2);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];     }     int left = 1;     int num = -1, occur = -1;     for (int i = 1; i <= n; i++) {       while ((a[i] * (i - left + 1) - (pre[i] - pre[left - 1])) > k) left++;       if (occur < (i - left + 1)) {         occur = i - left + 1;         num = a[i];       }     }     cout << occur <<     << num << endl;   }
#include <bits/stdc++.h>   int main() {     int t, a, b, i, temp;     scanf( %d , &t);     for (i = 1; i <= t; i++) {       scanf( %d %d , &a, &b);       if (b > a) {         temp = a;         a = b;         b = temp;       }       while ((a * a) < 2 * a * b) {         a++;       }       printf( %d n , a * a);     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[222222], b[222222], c[222222], d[222222];   set<long long> st;   set<long long>::iterator it;   map<long long, long long> sp2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, k, x, s, i;     cin >> n >> m >> k;     cin >> x >> s;     for (i = 1; i <= m; i++) {       cin >> a[i];     }     for (i = 1; i <= m; i++) {       cin >> b[i];     }     for (i = 1; i <= k; i++) {       cin >> c[i];     }     for (i = 1; i <= k; i++) {       cin >> d[i];       st.insert(d[i]);       sp2[d[i]] = c[i];     }     long long ans = n * x;     long long rem;     long long temp;     for (i = 1; i <= m; i++) {       if (b[i] <= s) {         temp = 0;         rem = s - b[i];         it = st.upper_bound(rem);         if (it != st.begin()) {           it--;           temp += sp2[*it];         }         if (temp >= n)           ans = 0;         else           ans = min(ans, (n - temp) * a[i]);       }     }     temp = 0;     it = st.upper_bound(s);     if (it != st.begin()) {       it--;       temp += sp2[*it];     }     if (temp >= n)       ans = 0;     else       ans = min(ans, (n - temp) * x);     cout << ans << endl;     return 0;   }