malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long f[110][2][2];   int ans[110];   int n;   long long k;   long long calc(long long x, long long a, long long b) {     if (f[x][a][b] != -1) return f[x][a][b];     f[x][a][b] = 0;     int y = n - x + 1;     if (x > y) return f[x][a][b] = 1;     for (int i = 0; i < 2; i++)       if (ans[x] == -1 || ans[x] == i)         for (int j = 0; j < 2; j++)           if (ans[y] == -1 || ans[y] == j)             if (i == j || x < y)               if (a || i <= j)                 if (b || i + j <= 1)                   f[x][a][b] += calc(x + 1, a || (i < j), b || ((i + j) <= 0));     return f[x][a][b];   }   int main() {     scanf( %d %I64d , &n, &k);     k++;     memset(f, -1, sizeof(f));     memset(ans, -1, sizeof(ans));     if (calc(1, 0, 0) < k) return puts( -1 ), 0;     for (int i = 1; i <= n; i++) {       memset(f, -1, sizeof(f));       ans[i] = 0;       if (calc(1, 0, 0) < k) {         k -= calc(1, 0, 0);         ans[i] = 1;       }     }     for (int i = 1; i <= n; i++) printf( %d , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int init() {     int now = 0, ju = 1;     char c;     bool flag = false;     while (1) {       c = getchar();       if (c ==  - )         ju = -1;       else if (c >=  0  && c <=  9 ) {         now = now * 10 + c -  0 ;         flag = true;       } else if (flag)         return now * ju;     }   }   inline long long llinit() {     long long now = 0, ju = 1;     char c;     bool flag = false;     while (1) {       c = getchar();       if (c ==  - )         ju = -1;       else if (c >=  0  && c <=  9 ) {         now = now * 10 + c -  0 ;         flag = true;       } else if (flag)         return now * ju;     }   }   char str[200005];   long long mod;   long long fastpow(long long base, long long power) {     long long ret = 1;     for (; power; power >>= 1) {       if (power & 1) {         ret = (ret * base) % mod;       }       base = (base * base) % mod;     }     return ret;   }   int main() {     long long ans = 0x7fffffffffffll, nowans = 0;     scanf( %s , str + 1);     mod = llinit();     int n = strlen(str + 1);     for (int i = 1; i <= n; i++) {       nowans *= 10;       nowans %= mod;       nowans += (str[i] -  0 );       nowans %= mod;     }     ans = min(ans, nowans);     for (int i = 1; i <= n - 1; i++) {       nowans -= (1LL * (str[i] -  0 ) * fastpow(10, n - 1));       while (nowans < 0) nowans += mod;       nowans %= mod;       nowans *= 10;       nowans %= mod;       nowans += (str[i] -  0 );       nowans %= mod;       if (str[i + 1] !=  0 ) {         ans = min(ans, nowans);       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = +100500;   const long long INF = 1e9;   bool ans[MAXN];   long long get(long long x) {     long long l = 0, r = INF;     while (l + 1 < r) {       long long m = (l + r) / 2;       if (m * (m + 1) / 2 <= x) {         l = m;       } else {         r = m;       }     }     return l;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b;     cin >> a >> b;     long long cnt = 0;     long long up = get(a + b);     for (long long i = up; i > 0; --i) {       if (a >= i) {         a -= i;         ans[i] = 1;         cnt++;       }     }     cout << cnt <<   n ;     for (long long i = 1; i <= up; ++i) {       if (ans[i]) {         cout << i <<    ;       }     }     cout <<   n  << up - cnt <<   n ;     for (long long i = 1; i <= up; ++i) {       if (!ans[i]) {         cout << i <<    ;       }     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5;   int arr[MAX];   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         int c;         cin >> c;         arr[c - 1] = i;       }       int l = arr[0], r = arr[0];       for (int i = 0; i < n; i++) {         if (arr[i] < l)           l = arr[i];         else if (arr[i] > r)           r = arr[i];         if (i == r - l)           cout << 1;         else           cout << 0;       }       cout <<   n ;     }   }
#include<iostream>   #include<cstdio>   #include<cmath>   #include<algorithm>   #include<string.h>   #include<map>   #include<vector>   #include<string>   using namespace std;   const int maxN =  3e5+ 10;   typedef long long int ll;   #define mod 998244353   ll dp[maxN];   ll f[maxN];   string c[maxN];   int main()   {          int n,m;       scanf( %d%d ,&n,&m);       f[0]=1;       for(int i=1;i<=n*m;i++)       {           f[i]=f[i-1]*2%mod;       }       dp[0]=dp[1]=0;       for(int i=2;i<=max(n,m);i++)           dp[i]=(dp[i-1]+dp[i-2]*2%mod+f[i-2])%mod;          for(int i=1;i<=n;i++)           cin>>c[i];       ll sum=0;       for(int i=1;i<=n;i++)           for(int j=0;j<m;j++)               if(c[i][j]== o ) sum++;          //cout<<dp[4]<<endl;          ll ans=0;       for(int i=1;i<=n;i++)       {           for(int j=0;j<m;j++)           {               int num=0;               if(c[i][j]== o )               {                   while(j<m&&c[i][j]== o ) j++,num++;                   //cout<<num<<endl;                   ans=(ans+dp[num]*f[sum-num])%mod;               }           }       }       for(int i=0;i<m;i++)       {           for(int j=1;j<=n;j++)           {               int num=0;               if(c[j][i]== o )               {                   while(j<=n&&c[j][i]== o ) j++,num++;                   //cout<<num<<endl;                   ans=(ans+dp[num]*f[sum-num])%mod;               }           }       }       cout<<ans<<endl;   }
#include <bits/stdc++.h>   using namespace std;   int mp[28];   bool fl[28];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     memset(mp, 0, sizeof(mp));     for (int i = 0; i < s.size(); i++) {       mp[s[i] -  a  + 1]++;     }     int cnt = 0;     int ans = 0;     for (int i = 1; i <= 26; i++) {       if (mp[i] != 0 && fl[i - 1] == 0) {         ans += i;         cnt++;         fl[i] = 1;       }       if (cnt >= k) break;     }     if (cnt == k)       cout << ans << endl;     else       cout <<  -1  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   vector<long long> v(100004);   vector<long long> t(100004, 0);   int n;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int bsearch(int r, int key) {     int l = -1;     while (r - l > 1) {       int m = (r + l) / 2;       if (t[m] >= key) {         r = m;       } else {         l = m;       }     }     return r;   }   int longest() {     int length = 1;     t[0] = v[0];     for (int i = 1; i < n; ++i) {       if (v[i] < t[0])         t[0] = v[i];       else if (v[i] > t[length - 1]) {         t[length] = v[i];         length++;       } else {         t[bsearch(length - 1, v[i])] = v[i];       }     }     return length;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     cout << longest();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> dd;   map<long long, long long> tong;   int main() {     long long n;     cin >> n;     string s;     cin >> s;     long long sum = 0;     for (long long i = 0; i < s.size(); i++) {       sum += (s[i] -  0 );     }     for (long long i = 2; i <= s.size(); i++) {       if (sum % i == 0) {         long long tmp = sum / i, dem = 0;         long long sum1 = 0;         for (long long j = 0; j < s.size(); j++) {           sum1 += (s[j] -  0 );           if (sum1 == tmp) {             sum1 = 0;             dem++;           }         }         if (dem == i) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;   }
#include<iostream>   #include<cstdio>   #include<unordered_map>   using namespace std;   const int N=105;   const int MOD=1000000007;   int n,q;   int c[N];   int b[N];   int sb[N],sc[N];   int l,r;   int solve(int x)   {       static int f[N][N*N],g[N][N*N];       f[0][0]=g[0][0]=1;       for(int i=1;i<=n;i++)       {           for(int j=0;j<max(i*x+sb[i-1],0);j++)               f[i][j]=0;           for(int j=max(i*x+sb[i-1],0);j<=sc[i];j++)               f[i][j]=((long long)g[i-1][j-max(j-sc[i-1],0)]-(j-min(c[i],j)-1>=0?g[i-1][j-min(c[i],j)-1]:0)+MOD)%MOD;           g[i][0]=f[i][0];           for(int j=1;j<=sc[i];j++)               g[i][j]=(g[i][j-1]+f[i][j])%MOD;       }       int ans=0;       for(int j=0;j<=sc[n];j++)           ans=(ans+f[n][j])%MOD;       return ans;   }   unordered_map<int,int>res;   int main()   {       scanf( %d ,&n);       for(int i=1;i<=n;i++)           scanf( %d ,&c[i]);       for(int i=1;i<n;i++)           scanf( %d ,&b[i]);       for(int i=1;i<n;i++)           sb[i]=sb[i-1]+b[i];       for(int i=1;i<n;i++)           sb[i]+=sb[i-1];       for(int i=1;i<=n;i++)           sc[i]=sc[i-1]+c[i];       r=(sc[n]-sb[n-1])/n;       for(int i=1;i<n;i++)           r=min(r,(sc[i]-sb[i-1])/i);       l=-sb[n-1]/n;       for(int i=1;i<n;i++)           l=min(l,sb[i-1]/i);       for(int i=l;i<=r;i++)           res[i]=solve(i);       int pw=1;       for(int i=1;i<=n;i++)           pw=1LL*pw*(c[i]+1)%MOD;       scanf( %d ,&q);       while(q--)       {           int x;           scanf( %d ,&x);           if(x<l) printf( %d n ,pw);           else if(x>r) printf( %d n ,0);           else printf( %d n ,res[x]);       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m = 1e9 + 7;   int p = 31;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       long long w, h;       cin >> w >> h;       long long k1, k2, k3, k4;       cin >> k1;       vector<long long> points_h1;       for (int i = 0; i < k1; i++) {         long long x;         cin >> x;         points_h1.push_back(x);       }       cin >> k2;       vector<long long> points_h2;       for (int i = 0; i < k2; i++) {         long long x;         cin >> x;         points_h2.push_back(x);       }       cin >> k3;       vector<long long> points_v1;       for (int i = 0; i < k3; i++) {         long long x;         cin >> x;         points_v1.push_back(x);       }       cin >> k4;       vector<long long> points_v2;       for (int i = 0; i < k4; i++) {         long long x;         cin >> x;         points_v2.push_back(x);       }       long long ans = max({w * (points_v1[points_v1.size() - 1] - points_v1[0]),                            w * (points_v2[points_v2.size() - 1] - points_v2[0]),                            h * (points_h1[points_h1.size() - 1] - points_h1[0]),                            h * (points_h2[points_h2.size() - 1] - points_h2[0])});       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T &x) {     int f = 0;     x = 0;     char ch = getchar();     for (; !isdigit(ch); ch = getchar()) f |= (ch ==  - );     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     if (f) x = -x;   }   const int N = 200005;   int a[N], b[N], c[N], ans[N], n, m, cnt, s;   pair<pair<int, int>, int> x[N];   int check(int lim) {     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         Q;     int cost = 0, rem = 0, id = 0;     for (int i = (cnt); i >= (1); i--) {       if (x[i].second == 0) {         if (!rem) {           if (Q.empty()) return 0;           rem = lim, cost += Q.top().first, id = Q.top().second, Q.pop();           if (cost > s) return 0;         }         rem--, ans[-x[i].first.second] = id;       } else {         Q.push(make_pair(x[i].first.second, x[i].second));       }     }     return 1;   }   int main() {     read(n), read(m), read(s);     for (int i = (1); i <= (m); i++) {       read(a[i]);       x[++cnt] = make_pair(make_pair(a[i], -i), 0);     }     for (int i = (1); i <= (n); i++) {       read(b[i]);     }     for (int i = (1); i <= (n); i++) {       read(c[i]);       x[++cnt] = make_pair(make_pair(b[i], c[i]), i);     }     sort(x + 1, x + cnt + 1);     int l = 1, r = m + 1;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     if (l == m + 1)       puts( NO );     else {       puts( YES );       check(l);       for (int i = (1); i <= (m); i++) {         printf( %d%c , ans[i],    n [i == m]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1001][1001];   int main() {     int n, m, f1 = 0;     cin >> n >> m;     int cnt = m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j && arr[i][j] == 0) {           arr[i][j] = 1;           arr[j][i] = -1;           cnt--;         }         if (cnt == 0) break;       }       if (cnt > 0) {         f1 = 1;         break;       }       cnt = m;     }     if (f1 == 1)       cout <<  -1  << endl;     else {       cout << n * m << endl;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++)           if (arr[i][j] == 1) cout << i + 1 <<     << j + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print1d(vector<T> &a) {     for (long long int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout << endl;   }   vector<long long int> divisor(long long int n) {     vector<long long int> a;     for (long long int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           a.push_back(i);         else {           a.push_back(i);           a.push_back(n / i);         }       }     }     return a;   }   bool sortsecond(const pair<long long int, long long int> &a,                   const pair<long long int, long long int> &b) {     return a.second < b.second;   }   bool isPrime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   vector<string> split_string(const string &s, const string &delimiter) {     vector<string> token;     string ans;     size_t end_point, start_point = 0, delim_length = delimiter.length();     while ((end_point = s.find(delimiter, start_point)) != string::npos) {       ans = s.substr(start_point, end_point - start_point);       start_point = end_point + delim_length;       token.push_back(ans);     }     token.push_back(s.substr(start_point));     return token;   }   bool is_vowel(const char &a) {     switch (a) {       case  a :       case  e :       case  i :       case  o :       case  u :       case  y :       case  A :       case  E :       case  I :       case  O :       case  U :         return true;         break;       default:         return false;         break;     }   }   bool sortstring(const string &a, const string &b) {     return a.length() < b.length();   }   void convert(string &s) {     for (long long int i = 0; i < s.length(); i++) {       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;       if (s[i] ==  o )         s[i] =  0 ;       else if (s[i] ==  l  || s[i] ==  i )         s[i] =  1 ;     }   }   const long long int K = 998244353;   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     long long int fir = 0;     long long int las = 0;     char c = s[0];     long long int k = 0;     for (long long int i = 0; i < n; i++) {       k = i;       if (s[i] == c)         fir++;       else {         break;       }     }     c = s[n - 1];     for (long long int i = n - 1; i >= k; i--) {       if (s[i] == c)         las++;       else         break;     }     if (s[0] == s[n - 1])       cout << ((las + 1) * (fir + 1)) % K << endl;     else       cout << (fir + las + 1) % K << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define l1 long long int    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define test l1 t;cin>>t;while(t--)   // Function to check    // if parentheses are balanced    bool isBalanced(string exp)    {             // Initialising Variables        bool flag = true;        l1 count = 0;             // Traversing the Expression        for (l1 i = 0; i < exp.length(); i++) {                 if (exp[i] ==  ( ) {                count++;            }            else {                     // It is a closing parenthesis                count--;            }            if (count < 0) {                     // This means there are                // more Closing parenthesis                // than opening ones                flag = false;                break;            }        }             // If count is not zero,        // It means there are        // more opening parenthesis        if (count != 0) {            flag = false;        }             return flag;    }      int main()   {       fast       test       {           l1 i,l;           string str,str1=  ,str2=  ;           cin>>str;           l=str.size();           l1 a=0,b=0,c=0;           for(i=0;i<l;i++)           {               if(str[i]== A )               {                   a++;               }               if(str[i]== B )               {                   b++;               }               if(str[i]== C )               {                   c++;               }           }           l1 arr[3];           arr[0]=a;arr[1]=b;arr[2]=c;           sort(arr,arr+3);           char temp=NULL;           if(arr[2]==a)           {               temp= A ;           }           else           {               if(arr[2]==b)               {                   temp= B ;               }               else               {                   temp= C ;               }           }           for(i=0;i<l;i++)           {               if(str[i]==temp)               {                   str1+= ( ;                   str2+= ) ;               }               else               {                   str1+= ) ;                   str2+= ( ;               }           }           if(isBalanced(str1) || isBalanced(str2))           {               cout<< YES n ;           }           else           {               cout<< NO n ;           }       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.size();     int a[2];     int b[2];     a[0] = a[1] = 0;     b[0] = b[1] = 0;     long long ans_odd = 0LL;     long long ans_even = 0LL;     for (int i = 0; i < l; i++) {       ans_odd++;       if (s[i] ==  a ) {         ans_even += a[1 - i % 2];         ans_odd += a[i % 2];       } else {         ans_even += b[1 - i % 2];         ans_odd += b[i % 2];       }       a[i % 2] += (s[i] ==  a );       b[i % 2] += (s[i] ==  b );     }     cout << ans_even <<     << ans_odd << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin >> n;     vector<long long> q(1000100, 0);     for (long long i = 0; i < n; i++) {       long long t;       cin >> t;       q[t]++;     }     long long ans = 0;     for (long long i = 0; (i < 1000100 - 1); ++i) {       if (q[i] % 2 == 1) ans++;       q[i + 1] += q[i] / 2;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chmax(T& a, const T& b) {     return a < b ? (a = b, true) : false;   }   template <typename T>   bool chmin(T& a, const T& b) {     return b < a ? (a = b, true) : false;   }   int N, Q;   const int MAX_N = 100000;   const int BUCKET = 100, SIZE = 1000;   char S[MAX_N + 17];   int bucketCnt[BUCKET][10][11][4];   int getId(char c) {     if (c ==  A ) return 0;     if (c ==  C ) return 1;     if (c ==  G ) return 2;     return 3;   }   void init() {     for (int i = (int)(0); i < (int)(N); i++) {       int bucketL = i / SIZE * SIZE;       for (int j = (int)(1); j < (int)(11); j++) {         bucketCnt[i / SIZE][(i - bucketL) % j][j][getId(S[i])]++;       }     }   }   void change(int idx, char c) {     int bucketL = idx / SIZE * SIZE;     for (int j = (int)(1); j < (int)(11); j++) {       bucketCnt[idx / SIZE][(idx - bucketL) % j][j][getId(S[idx])]--;     }     S[idx] = c;     for (int j = (int)(1); j < (int)(11); j++) {       bucketCnt[idx / SIZE][(idx - bucketL) % j][j][getId(S[idx])]++;     }   }   int getImpact(int l, int r, int M, char e[]) {     int res = 0;     for (int i = (int)(0); i < (int)(BUCKET); i++) {       int bucketL = i * SIZE, bucketR = min(N, (i + 1) * SIZE);       if (r <= bucketL || bucketR <= l) continue;       if (l <= bucketL && bucketR <= r) {         for (int j = (int)(0); j < (int)(min(M, bucketR - bucketL)); j++) {           int x = (bucketL + j - l) % M;           res += bucketCnt[i][j][M][getId(e[x])];         }         continue;       }       for (int j = (int)(max(bucketL, l)); j < (int)(min(bucketR, r)); j++) {         int x = (j - l) % M;         res += e[x] == S[j];       }     }     return res;   }   int main() {     scanf( %s , S);     N = strlen(S);     init();     scanf( %d , &Q);     for (int i = (int)(0); i < (int)(Q); i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int x;         char c[17];         scanf( %d%s , &x, c);         x--;         change(x, c[0]);       } else {         int l, r;         char e[17];         scanf( %d%d%s , &l, &r, e);         l--;         int M = strlen(e);         printf( %d n , getImpact(l, r, M, e));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n);       for (auto &it : v) cin >> it;       int ans = 0;       sort(v.begin(), v.end());       for (int i = n - 1; i >= n - k; i--) ans += v[i - k] / v[i];       for (int i = 0; i < n - 2 * k; i++) ans += v[i];       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[1000], arr2[1000], i = 0;     cin >> n;     while (i < n) {       cin >> arr[i];       arr2[arr[i]] = i + 1;       i++;     }     sort(arr, arr + n);     for (i = 0; i < n; i++) {       cout << arr2[arr[i]] <<    ;     }     return 0;   }