malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(char s) { return string(1, s); }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A>   string to_string(A);   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool f = 1;     string r =  { ;     for (const auto& x : v) {       if (!f) r +=  ,  ;       f = 0;       r += to_string(x);     }     return r +  } ;   }   void debug_out() { cout <<   n ; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cout <<     << to_string(H);     debug_out(T...);   }   const long long MOD = 1000000007;   long long binpow(long long b, long long p) {     long long ans = 1;     while (p > 0) {       if (p & 1) ans = (ans * b) % MOD;       b = (b * b) % MOD;       p >>= 1;     }     return ans;   }   long long modinv(long long x) { return binpow(x, MOD - 2); }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, i, l, r;     cin >> n >> m;     vector<int> a(n), inc(n), dec(n);     for (i = 0; i < n; i++) {       cin >> a[i];       inc[i] = dec[i] = i;     }     for (i = n - 2; i >= 0; i--) {       if (a[i] <= a[i + 1]) inc[i] = inc[i + 1];       if (a[i] >= a[i + 1]) dec[i] = dec[i + 1];     }     while (m--) {       cin >> l >> r;       l--;       r--;       if (dec[inc[l]] >= r)         cout <<  Yes n ;       else         cout <<  No n ;     }   }
#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int add(int a, int b, int m = MOD) { return (a + b + m + m) % m; }   int mul(long long a, long long b, int m = MOD) { return (a * b) % m; }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int N = 200000 + 5;   const int L = 2;   const unsigned int B[] = {257, 311};   int n;   string minimal(string s) {     if (s.size() & 1) return s;     string s1 = minimal(s.substr(0, s.size() / 2));     string s2 = minimal(s.substr(s.size() / 2, s.size() / 2));     if (s1 < s2) return s1 + s2;     return s2 + s1;   }   int main() {     string a, b;     cin >> a >> b;     if (minimal(a) == minimal(b))       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, k, a, b, q, cnt[N];   struct fenwick {     int fen[N];     void add(int p, int x) {       for (; p < N; p += p & -p) fen[p] += x;     }     int get(int p) {       int ans = 0;       for (; p; p -= p & -p) ans += fen[p];       return ans;     }   } fen1, fen2;   void readInput() { cin >> n >> k >> a >> b >> q; }   void writeOutput() {     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t & 1) {         int d, x;         cin >> d >> x;         cnt[d] += x;         fen1.add(d, max(min(b, cnt[d]) - cnt[d] + x, 0));         fen2.add(n - d + 1, max(min(a, cnt[d]) - cnt[d] + x, 0));       } else {         int p;         cin >> p;         cout << fen1.get(p - 1) + fen2.get(n - p - k + 1) << endl;       }     }   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     readInput(), writeOutput();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   long long int n, k, a[200005], dp[200005];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (long long int i = 1; i <= n; i++) dp[i] = dp[i - 1] + a[i];     long long int i = 1, ans = -1;     while (i <= n) {       long long int j = i;       while (j + 1 <= n && a[j + 1] == a[j]) {         j++;       }       long long int cnt = j - i + 1;       if (cnt >= k) {         ans = 0;         break;       }       long long int cur = 1e18;       long long int s1 = i - 1;       long long int s2 = n - j;       long long int ans1 = 0, ans2 = 0;       ans1 = s1 * (a[i] - 1) - dp[i - 1] + dp[0];       ans2 = dp[n] - dp[j] - s2 * (a[i] + 1);       if (s2 + cnt >= k) {         cur = min(cur, ans2);       }       if (s1 + cnt >= k) {         cur = min(cur, ans1);       }       cur = min(cur, ans1 + ans2);       cur = cur + k - cnt;       if (ans == -1) {         ans = cur;       } else         ans = min(ans, cur);       i = j + 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_BUF_SIZE = 16384;   char BUFOR[MAX_BUF_SIZE];   int BUF_SIZE, BUF_POS;   char ZZZ;   const int MXN = 1000010;   const int C = 262144;   const int INF = 1000000001;   void test() {     int n;     scanf( %d , &n);     cout << ((long long int)(n - 1) * (n - 3) + 1) << endl;   }   int main() {     int te = 1;     while (te--) test();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, x1, x2, m, c;     cin >> n >> x1 >> x2;     vector<pair<long long, long long>> v;     for (int i = 0; i < n; ++i) {       cin >> m >> c;       v.push_back({m * x1 + c, m * x2 + c});     }     sort(v.begin(), v.end());     long long p = v[0].second;     for (auto i : v) {       if (i.second < p) {         cout <<  YES ;         return 0;       }       p = i.second;     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n;     map<int, vector<vector<int> > > m;     vector<int> v, ans;     map<int, int> s;     for (int i = 0; i < n - 2; i++) {       int f, g, h;       cin >> f >> g >> h;       v.push_back(f);       v.push_back(g);       v.push_back(h);       s[f]++;       s[g]++;       s[h]++;       m[f].push_back(v);       m[g].push_back(v);       m[h].push_back(v);       v.clear();     }     for (auto i = s.begin(); i != s.end(); i++) {       if (i->second == 1) {         ans.push_back(i->first);         for (auto p = m[i->first].begin(); p != m[i->first].end(); p++) {           auto j = *p;           for (int u = 0; u < 3; u++) {             if (s[j[u]] == 2) a = j[u];             if (s[j[u]] == 3) b = j[u];           }         }         ans.push_back(a);         ans.push_back(b);         break;       }     }     while (ans.size() < n) {       int x, y, z, t;       t = ans.size();       x = ans[t - 1];       y = ans[t - 2];       z = ans[t - 3];       for (auto p = m[y].begin(); p != m[y].end(); p++) {         auto j = *p;         if (((j[0] == y && j[1] == x) || (j[0] == x && j[1] == y)) && j[2] != z)           ans.push_back(j[2]);         else if (((j[0] == y && j[2] == x) || (j[0] == x && j[2] == y)) &&                  j[1] != z)           ans.push_back(j[1]);         else if (((j[1] == y && j[2] == x) || (j[1] == x && j[2] == y)) &&                  j[0] != z)           ans.push_back(j[0]);       }     }     for (auto c : ans) {       cout << c <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int& a, int& b) { return b < a; }   int main() {     int n;     cin >> n;     vector<pair<int, int>> source(n), team1, team2;     long long sum_team1 = 0, sum_team2 = 0;     for (int i = 0; i < n; ++i) {       cin >> source[i].first;       source[i].second = i;     }     sort(source.begin(), source.end());     int i = 0, par = 1;     while (!source.empty()) {       if (par) {         team1.push_back(source.back());         source.pop_back();         par = 0;         sum_team1 += team1.back().first;       } else {         team2.push_back(source.back());         source.pop_back();         par = 1;         sum_team2 += team2.back().first;       }     }     cout << team1.size() <<   n ;     for (int i = 0; i < team1.size(); ++i) cout << team1[i].second + 1 <<    ;     cout <<   n ;     cout << team2.size() <<   n ;     for (int i = 0; i < team2.size(); ++i) cout << team2[i].second + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const long long INF = 1e18;   const int maxn = 1e6 + 6;   const int mod = 1e9 + 7;   const double eps = 1e-9;   inline bool read(long long &num) {     char in;     bool IsN = false;     in = getchar();     if (in == EOF) return false;     while (in !=  -  && (in <  0  || in >  9 )) in = getchar();     if (in ==  - ) {       IsN = true;       num = 0;     } else       num = in -  0 ;     while (in = getchar(), in >=  0  && in <=  9 ) {       num *= 10, num += in -  0 ;     }     if (IsN) num = -num;     return true;   }   long long n, m;   struct node {     int x, v;     bool friend operator<(node a, node b) { return a.x < b.x; }   } save[maxn];   vector<int> v;   long long a[maxn], b[maxn];   int nn;   void update(long long *p, int pos, long long x) {     while (pos <= nn) {       p[pos] += x;       pos += pos & -pos;     }   }   long long GetSum(long long *p, long long x) {     long long ans = 0;     while (x > 0) {       ans += p[x];       x -= x & -x;     }     return ans;   }   int getid(long long x) {     return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) scanf( %d , &save[i].x);     for (int i = 1; i <= n; i++) {       scanf( %d , &save[i].v);       v.push_back(save[i].v);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     nn = v.size();     sort(save + 1, save + 1 + n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int id = getid(save[i].v);       long long tempx = GetSum(b, id);       long long tempy = GetSum(a, id);       ans += tempx * save[i].x - tempy;       update(b, id, 1);       update(a, id, save[i].x);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   long long tot[200010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<long long, int> > v;     for (int i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       v.push_back({l, -1});       v.push_back({r + 1, 1});     }     sort(v.begin(), v.end());     long long open = 0;     long long last = v[0].first;     for (int i = 0; i < v.size();) {       long long pos = v[i].first;       tot[open] += pos - last;       while (i < v.size() && v[i].first == pos) {         open -= v[i].second;         i++;       }       last = pos;     }     for (int i = 1; i <= n; i++) cout << tot[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fa[2005], fb[2005];   long long mina[2005], minb[2005];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (int i = 0; i < n; i++) {       cin >> a[i];       fa[i + 1] = fa[i] + a[i];     }     for (int j = 0; j < m; j++) {       cin >> b[j];       fb[j + 1] = fb[j] + b[j];     }     long long x;     cin >> x;     for (int i = 0; i <= n; i++) {       mina[i] = 2000000000;       for (int k = 0; k + i <= n; k++) {         mina[i] = min(mina[i], fa[k + i] - fa[k]);       }     }     for (int j = 0; j <= m; j++) {       minb[j] = 2000000000;       for (int k = 0; k + j <= m; k++) {         minb[j] = min(minb[j], fb[k + j] - fb[k]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mina[i] * minb[j] <= x) ans = max(ans, i * 1ll * j);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, mx = 0;     cin >> n;     map<int, long long int> mp1, mp2;     map<pair<long long int, long long int>, int> mp;     vector<long long int> a(n), b(n);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a[i] = x, b[i] = y;       mp1[x]++, mp2[y]++;       mp[{a[i], b[i]}]++;       mx = max(mx, mp2[y]);     }     long long int operations = INT_MAX;     for (int i = 0; i < n; i++) {       long long int temp = mp1[a[i]] + mp2[a[i]] - mp[{a[i], a[i]}];       if (temp >= (n + 1) / 2) {         operations =             min(operations, max(min(temp, (n + 1) / 2) - mp1[a[i]], 0LL));       }     }     if (operations == INT_MAX && mx < (n + 1) / 2) {       cout <<  -1 n ;       return 0;     }     if (operations == INT_MAX) {       operations = (n + 1) / 2;     }     cout << operations << endl;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int n1 = n, dig, x = 0, y = 0, z = 0, r;     while (n1 > 0) {       dig = n1 % 10;       if (dig != 4 && dig != 7) {         x++;         break;       }       n1 = n1 / 10;     }     if (x == 0) {       printf( YES );       z++;     } else if (x > 0) {       for (int i = 1; i < n; i++) {         y = 0;         n1 = i;         while (n1 > 0) {           dig = n1 % 10;           if (dig != 4 && dig != 7) {             y++;             break;           }           n1 = n1 / 10;         }         if (y == 0 && n % i == 0) {           printf( YES );           z++;           break;         }       }     }     if (z == 0) {       printf( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ans[2000005];   vector<int> lis[2000005];   string Str[2000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int m = 0;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       Str[i] = str;       int k;       cin >> k;       while (k--) {         int a;         cin >> a;         lis[a].push_back(i);         m = max(m, int(a + str.length() - 1));       }     }     int r = -1, p = 0, ind = 0;     for (int i = 1; i <= m; i++) {       for (int j = 0; j < lis[i].size(); j++) {         int a = Str[lis[i][j]].size();         int b = r - p;         if (a > b) {           r = Str[lis[i][j]].length();           p = 0;           ind = lis[i][j];         }       }       if (p < r) {         ans[i] = Str[ind][p];         p++;       } else {         ans[i] =  a ;       }       cout << ans[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 32;   int n, u, r, a[N][N], b[N], p[N], k[N];   long long ans = -1e18;   void dfs(int x, bool z) {     int i;     if (x % 2 == u % 2) {       long long t = 0;       for (i = 1; i <= n; i = i + 1) t += (long long)a[i][x] * k[i];       ans = max(ans, t);     }     if (x >= u) return;     for (i = 1; i <= n; i = i + 1) a[i][x + 1] = a[p[i]][x] + r;     dfs(x + 1, 1);     if (z) {       for (i = 1; i <= n; i = i + 1) a[i][x + 1] = a[i][x] ^ b[i];       dfs(x + 1, 0);     }   }   int main() {     int i, j;     cin >> n >> u >> r;     for (i = 1; i <= n; i = i + 1) cin >> a[i][0];     for (i = 1; i <= n; i = i + 1) cin >> b[i];     for (i = 1; i <= n; i = i + 1) cin >> k[i];     for (i = 1; i <= n; i = i + 1) cin >> p[i];     dfs(0, 1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, long long> mp;   long long arr[2][1234];   int main() {     string s;     long long idx1, idx2;     char repeating;     cin >> s;     long long i;     for (i = 0; i < s.size(); i++) mp[s[i]]++;     for (auto it : mp)       if (it.second == 2) repeating = it.first;     0;     long long c1 = 0, c2 = 0, c3 = 0, nc1, nc3;     for (i = 0; i < s.size(); i++)       if (s[i] == repeating) {         idx1 = idx2;         idx2 = i;       }     if (idx2 == idx1 + 1) {       cout <<  Impossible ;       return 0;     }     0;     c2 = idx2 - idx1 - 1;     c3 = 26 - idx2;     c1 = idx1;     0;     0;     if (c2 % 2 == 0) {       long long sum = c1 + c3;       nc3 = sum / 2;       nc1 = nc3 + 1;       if (nc1 < c1) {         long long give = c1 - nc1;         string tmp = s.substr(0, give);         s = s.substr(give, 27 - tmp.size());         s += tmp;         0;       } else if (nc1 > c1) {         long long give = nc1 - c1;         string tmp = s.substr(27 - give, give);         s = tmp + s.substr(0, 27 - give);         0;       }     } else if (c2 % 2 == 1) {       long long sum = c1 + c3;       nc3 = sum / 2;       nc1 = nc3;       if (nc1 < c1) {         long long give = c1 - nc1;         string tmp = s.substr(0, give);         s = s.substr(give, 27 - tmp.size());         s += tmp;         0;       } else if (nc1 > c1) {         long long give = nc1 - c1;         string tmp = s.substr(27 - give, give);         s = tmp + s.substr(0, 27 - give);         0;       }     }     0;     for (i = 0; i < s.size(); i++)       if (s[i] == repeating) {         idx1 = idx2;         idx2 = i;       }     long long curr = 0;     if (c2 % 2 == 0) {       for (i = 0; i < idx1; i++) arr[1][curr++] = s[i] -  A ;       curr--;       0;       arr[0][curr] = repeating -  A ;       curr++;       for (i = idx1 + 1; i <= (idx1 + c2 / 2); i++) arr[0][curr++] = s[i] -  A ;       0;       curr--;       for (i = idx1 + c2 / 2 + 1; i <= (idx1 + c2); i++)         arr[1][curr--] = s[i] -  A ;       curr--;       for (i = idx2 + 1; i < 27; i++) arr[0][curr--] = s[i] -  A ;       for (i = 0; i < 2; i++) {         for (long long j = 0; j < 13; j++) {           cout << char(arr[i][j] +  A );         }         cout << endl;       }     } else {       for (i = 0; i < idx1; i++) arr[1][curr++] = s[i] -  A ;       0;       arr[1][curr] = repeating -  A ;       for (i = idx1 + 1; i <= ((idx1 + c2 / 2) + 1); i++)         arr[0][curr++] = s[i] -  A ;       0;       curr--;       for (i = idx1 + c2 / 2 + 2; i <= (idx1 + c2); i++)         arr[1][curr--] = s[i] -  A ;       curr--;       for (i = idx2 + 1; i < 27; i++) arr[0][curr--] = s[i] -  A ;       for (i = 0; i < 2; i++) {         for (long long j = 0; j < 13; j++) {           cout << char(arr[i][j] +  A );         }         cout << endl;       }     }   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   int n,m,pre,N;   string s,t;   ll ans;   map<string,vector<string> >S;   map<string,bool>vis;   int main(){    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);    cin>>n;    for(int i=1;i<=n;i++){     cin>>s;t=s;     sort(t.begin(),t.end());     S[t].push_back(s);    }    m=s.size();    for(auto it:S){     vector<string> v=it.second;     N=v.size(),ans+=1337ll*pre*N,pre+=N;     if(N<=200*m){      for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){       int L=0,R=m-1;       while(v[i][L]==v[j][L]&&L<=R)L++;       while(v[i][R]==v[j][R]&&L<=R)R--;       bool f1=1,f2=1;       for(int k=L;k<R;k++)f1&=(v[i][k]<=v[i][k+1]),f2&=(v[j][k]<=v[j][k+1]);       ans+=2;       if(f1||f2)ans--;      }     }else{      ll cur=(ll)N*(N-1);      vis.clear();      for(auto s:v)vis[s]=1;      for(auto s:v)for(int i=0;i<m;i++)for(int j=i+2;j<=m;j++){       t=s,sort(t.begin()+i,t.begin()+j);       if(t[i]!=s[i]&&t[j-1]!=s[j-1]&&vis.count(t))cur--;      }      ans+=cur;     }    }    cout<<ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   long long a[maxn];   int main() {     int _;     cin >> _;     while (_--) {       int n, k;       cin >> n >> k;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + 1 + n, greater<int>());       long long ans = 0;       for (int i = 1; i <= k; i++) ans += a[k + i] / a[i];       for (int i = 2 * k + 1; i <= n; i++) ans += a[i];       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[111111];   int main() {     cin >> n;     arr[0] = 0x3f3f3f3f;     for (int i = 1; i <= n; ++i) cin >> arr[i];     int ans = 0;     for (int i = 0; i < n; ++i) {       int ii = n - i;       if (arr[ii] < arr[ii - 1]) {         ans = i;         break;       }     }     ans = n - ans - 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, counter = 0, max = 1, a, b = -1;     cin >> n;     for (int i = 0; i < n; i++) {       a = b;       cin >> b;       if (b >= a) {         counter++;       } else {         if (counter > max) {           max = counter;         }         counter = 1;       }       if (counter > max) {         max = counter;       }     }     cout << max << endl;     return 0;   }