malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int d4x[4] = {1, 0, -1, 0};   int d4y[4] = {0, 1, 0, -1};   int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long oo = 1e18;   const long long maxN = 1e6;   void maximize(int &a, int b) { a = max(a, b); }   void minimize(int &a, int b) { a = min(a, b); }   int cnt[15];   void solve() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;       int g = 0, b, d = 0;       b = n + 1;       for (int j = 1; j <= 10; j++) {         if (cnt[j] > 0) {           cnt[j]--;           int p = 0;           bool ok = true;           for (int k = 1; k <= 10; k++) {             if (cnt[k]) {               if (!p)                 p = cnt[k];               else if (p != cnt[k])                 ok = false;             }           }           cnt[j]++;           if (ok) ans = i;         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, ddd = 0;     while (tc--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   char s[20];   int m;   long long dp[1 << 18][110];   int cnt[20];   int main() {     ios::sync_with_stdio(false);     cin >> s >> m;     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     dp[0][0] = 1;     int l = strlen(s);     long long x = 1 << l, d = 1;     for (int i = 0; i < l; i++) d *= ++cnt[s[i] -  0 ];     for (int i = 0; i < x; i++) {       for (int j = 0; j < l; j++) {         if (!(i & (1 << j)) && (i || s[j] -  0 )) {           for (int k = 0; k < m; k++) {             if (dp[i][k])               dp[i | (1 << j)][(k * 10 + (s[j] -  0 )) % m] += dp[i][k];           }         }       }     }     cout << dp[x - 1][0] / d << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, s, x;     map<long long, long long> mp;     map<long long, long long>::iterator it;     cin >> n;     s = 0;     for (i = 0; i < n; i++) {       cin >> x;       s += x;       mp[s]++;     }     i = -1;     for (it = mp.begin(); it != mp.end(); it++) {       i = max(i, it->second);     }     cout << n - i <<   n ;   }
#include<bits/stdc++.h>   using namespace std;      #define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define ll long long int    #define all(v) (v).begin(), (v).end()   #define mp make_pair   #define pb push_back   #define pf push_front   #define ff first   #define ss second   #define lcm(a, b) ((a) * (b)) / __gcd(a, b)   #define umpit unordered_map<ll,ll>::iterator   #define mpit map<ll,ll>::iterator   #define setit set<ll>::iterator   #define mx(a) *max_element(all(a))   #define mn(a) *min_element(all(a))   #define yes cout<< YES n    #define no cout<< NO n    const ll INF = LLONG_MAX / 2;   #define PI 3.1415926535897932384626433832795   #define mod 1000000007      ll bin_exp_mod(ll a,ll n)   {       ll res=1;       a%=mod;       if(a==0)           return 0;       while(n)       {           if(n&1)               res=((res%mod)*(a%mod))%mod;           n=n>>1;           a=((a%mod)*(a%mod))%mod;       }       res%=mod;       return res;   }         int main()   {      FASTio;       #ifndef ONLINE_JUDGE                    //file start       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);          #endif                                  //file end       ll t,i,j;       cin>>t;       while(t--)       {           ll n,k;           cin>>n>>k;           while(k>3)           {               cout<< 1  ;               k--;               n--;           }           vector<ll>arr(k);           if(n%3 == 0)           {                              arr[0] = n/3;               arr[1] = n/3;               arr[2] = n/3;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%4 == 0)           {              arr[0] = n/2;               arr[1] = n/4;               arr[2] = n/4;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%2 == 0)           {                arr[0] = n/2 -1;               arr[1] = n/2 - 1;               arr[2] = 2;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%2 == 1)           {                arr[0] = n/2;               arr[1] = n/2;               arr[2] = 1;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   void start(vector<int> &arr, pair<char, int> &prefAns, pair<char, int> &sufAns,              string &s) {     int i;     for (i = 0; i < s.size(); ++i) {       int cnt = 0;       while (i + 1 != s.size() && s[i] == s[i + 1]) {         ++cnt;         ++i;       }       arr[s[i]] = max(arr[s[i]], cnt + 1);     }     i = 0;     while (i + 1 != s.size() && s[i] == s[i + 1]) {       ++i;     }     prefAns = {s[0], i + 1};     i = s.size() - 1;     while (i - 1 != -1 && s[i] == s[i - 1]) {       --i;     }     sufAns = {s[s.size() - 1], s.size() - i};   }   char same(string &s) {     int res = s[0];     for (auto c : s) {       if (res != c) {         return -1;       }     }     return res;   }   void relax(vector<int> &ans, pair<char, int> &prefAns, pair<char, int> &sufAns,              string &s) {     for (auto c : s) {       ans[c] = max(ans[c], (sufAns.first == c) * sufAns.second + 1 +                                (prefAns.first == c) * prefAns.second);     }   }   int max(vector<int> &arr) {     int res = 0;     for (auto elem : arr) {       res = max(res, elem);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<string> arr(n);     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     vector<int> ans( z  + 1);     pair<char, int> prefAns;     pair<char, int> sufAns;     start(ans, prefAns, sufAns, arr[n - 1]);     bool flag = (same(arr[n - 1]) != -1);     for (int i = n - 2; i >= 0; --i) {       char c = same(arr[i]);       if (flag && (c != arr[n - 1][0])) {         c = arr[n - 1][0];         vector<int> tmpAns( z  + 1);         pair<char, int> tmpPrefAns;         pair<char, int> tmpSufAns;         start(tmpAns, tmpPrefAns, tmpSufAns, arr[i]);         ans[c] = ans[c] * (tmpAns[c] + 1) + tmpAns[c];         if (tmpPrefAns.first == c) {           prefAns = {               c, prefAns.second * (tmpPrefAns.second + 1) + tmpPrefAns.second};         }         if (tmpSufAns.first == c) {           sufAns = {c, sufAns.second * (tmpSufAns.second + 1) + tmpSufAns.second};         }         flag = false;         continue;       }       if (flag) {         ans[c] = ans[c] * (arr[i].size() + 1) + arr[i].size();         prefAns = {c, ans[c]};         sufAns = {c, ans[c]};       } else {         relax(ans, prefAns, sufAns, arr[i]);       }     }     cout << max(ans) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const long long llinf = 1e18;   const long long nax = 0;   long long n;   vector<long long> arr(5005);   vector<bool> ada(5005), masuk(5005);   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr.begin(), arr.begin() + n);     for (int i = 0; i < n; ++i) {       if (masuk[i]) {         continue;       }       for (int j = i + 1; j < n; ++j) {         if (arr[j] <= arr[i]) continue;         if (!ada[j]) {           masuk[i] = 1, ada[j] = 1;           break;         }       }     }     int ans = n;     for (int i = 0; i < n; ++i) {       if (masuk[i]) ans--;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int l, r;   long long pw[500007], inv[500007], ans = 0;   pair<int, int> p[500007];   const long long mod = 1e9 + 7;   long long pwr(long long x, long long y) {     if (y == 0) return 1LL;     if (y == 1) return x;     long long ret = pwr(x, y / 2);     if (y % 2 == 0)       return (ret * ret) % mod;     else       return (((ret * ret) % mod) * x) % mod;   }   long long C(long long k, long long n) {     if (k > n)       return 0;     else       return (((pw[n] * inv[k]) % mod) * inv[n - k]) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     inv[0] = 1;     pw[0] = 1;     for (long long i = 1; i <= 500000; i++) pw[i] = (pw[i - 1] * i) % mod;     inv[500000] = pwr(pw[500000], mod - 2);     for (long long i = 499999; i >= 1; i--) inv[i] = (inv[i + 1] * (i + 1)) % mod;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> l >> r;       p[i * 2 - 1] = make_pair(l, 1);       p[i * 2] = make_pair(r + 1, -1);     }     sort(p + 1, p + 1 + 2 * n);     long long cur = 1;     for (int i = 2; i <= 2 * n; i++) {       long long val = p[i].first - p[i - 1].first;       ans += (val * C(k, cur)) % mod;       if (ans >= mod) ans -= mod;       cur += p[i].second;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, d;     cin >> k >> d;     if (d == 0) {       if (k == 1)         cout << 0 << endl;       else         cout <<  No solution  << endl;     } else {       cout << d;       for (int i = 0; i < k - 1; i++) cout <<  0 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 100 * 1000 + 13;   queue<int> bfsq;   set<int> bfsS;   set<pair<int, int> > forbid;   vector<int> compV[MAXN], toDel;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       forbid.insert(make_pair(min(a, b), max(a, b)));     }     for (int i = 1; i <= n; i++) bfsS.insert(i);     int comp = 0;     while (!bfsS.empty()) {       comp++;       bfsq.push(*(bfsS.begin()));       bfsS.erase(bfsS.begin());       while (!bfsq.empty()) {         int u = bfsq.front();         compV[comp].push_back(u);         bfsq.pop();         for (auto v : bfsS)           if (forbid.find(make_pair(min(u, v), max(u, v))) == forbid.end()) {             toDel.push_back(v);             bfsq.push(v);           }         for (auto u : toDel) bfsS.erase(u);         toDel.clear();       }     }     cout << comp << endl;     for (int i = 1; i <= comp; i++) {       cout << compV[i].size() <<    ;       for (auto u : compV[i]) cout << u <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int N;   set<int> P;   void setP(long long int n, int x, int y) {     if (n > N) return;     if (n != 0) P.insert(n);     if (n != 0 || x != 0) setP(n * 10 + x, x, y);     if (n != 0 || y != 0) setP(n * 10 + y, x, y);   }   int main() {     cin >> N;     for (int i = 0; i < 10; i++) {       for (int j = i + 1; j < 10; j++) {         setP(0, i, j);       }     }     cout << P.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int hit[12];     string notes[12] = { C ,   C# ,  D ,   D# ,  E ,  F ,                          F# ,  G ,   G# ,  A ,   B ,  H };     string x, y, z;     cin >> x >> y >> z;     for (int i = 0; i < 12; i++) {       if (x == notes[i] || y == notes[i] || z == notes[i]) {         hit[i] = 1;       }     }     for (int i = 0; i < 12; i++) {       if (hit[i] == 1) {         if (hit[(i + 4) % 12] == 1 && hit[(i + 7) % 12] == 1) {           cout <<  major  << endl;           return 0;         } else if (hit[(i + 3) % 12] == 1 && hit[(i + 7) % 12] == 1) {           cout <<  minor  << endl;           return 0;         }       }     }     cout <<  strange  << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, l, j;     char t;     char kb[100] =  qwertyuiopasdfghjkl;zxcvbnm,./ ;     char s[1000];     scanf( %c , &t);     scanf( %s , s);     l = strlen(s);     for (i = 0; i < l; i++) {       for (j = 0; j < 30; j++) {         if (kb[j] == s[i]) {           if (t ==  R ) {             printf( %c , kb[j - 1]);           } else if (t ==  L ) {             printf( %c , kb[j + 1]);           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long n, k, ans = 0;     cin >> n >> k;     if (k >= n / 2)       ans = (n * (n - 1)) / 2;     else {       ans = (n * (n - 1)) / 2 - (((n - k) * (n - k - 1)) / 2) + k * (n - 2 * k) +             (k * (k - 1)) / 2;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void runTest() {     long long int n, a, b, k;     cin >> n >> a >> b >> k;     long long int ans = 0;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int val;       cin >> val;       long long int temp =           ((val % (a + b) == 0) ? (val / (a + b)) - 1 : val / (a + b));       temp *= (a + b);       temp = val - temp;       temp = ((temp - 1) / a) + 1;       temp--;       if (temp <= 0)         ans++;       else         v.push_back(temp);     }     sort(v.begin(), v.end());     for (auto i : v) {       if (k >= i) {         ans++;         k -= i;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) runTest();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, sum;   int main() {     cin >> n;     int ans = 0;     for (int i = 1; i <= 1000000; i++) {       sum += i;       ans += (n + i) % 3 == 0 && (n + i) / 3 >= sum;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int ROOT = 0, MAXN = 100000;   const char WHITE = 0, GRAY = 1, BLACK = 2;   vector<int> graph[MAXN];   int n, m, a, b, i;   char k[MAXN] = {WHITE};   inline int dfs(const int& v = ROOT) {     k[v] = GRAY;     int i, t, p = -1;     for (i = 0; i < (int)(graph[v].size()); i++)       if (k[graph[v][i]] == WHITE) {         t = dfs(graph[v][i]);         if (t == -1) {           if (p == -1)             p = graph[v][i];           else {             printf( %d %d %d n , p + 1, v + 1, graph[v][i] + 1);             p = -1;           }         } else           printf( %d %d %d n , v + 1, graph[v][i] + 1, t + 1);       } else if (k[graph[v][i]] == BLACK) {         if (p == -1)           p = graph[v][i];         else {           printf( %d %d %d n , p + 1, v + 1, graph[v][i] + 1);           p = -1;         }       }     k[v] = BLACK;     return p;   }   int main() {     scanf( %d%d , &n, &m);     if (m & 1) {       printf( No solution n );       return 0;     }     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       a--;       b--;       graph[a].push_back(b);       graph[b].push_back(a);     }     assert(dfs() == -1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long cnt = 0;     int H;     scanf( %d  , &H);     ;     long long N;     cin >> N;     N--;     long long n = 0;     int d = 0;     for (int h = (0); h < (H); h++) {       long long msk = ((1LL) << (long long)(H - h - 1));       if (N & msk) {         if (d & 1)           cnt++;         else {           cnt += msk * 2LL;           d++;         }       } else {         if (d & 1) {           cnt += msk * 2LL;           d++;         } else           cnt++;       }       d++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   template <class T>   void dbs(string str, T t) {     cout << str <<   :   << t << endl;   }   template <class T, class... second>   void dbs(string str, T t, second... s) {     int idx = str.find( , );     cout << str.substr(0, idx) <<   :   << t <<  , ;     dbs(str.substr(idx + 1), s...);   }   template <class second, class T>   ostream& operator<<(ostream& os, const pair<second, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class second, class T>   ostream& operator<<(ostream& os, const map<second, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cout <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cout <<  ,  ;       cout << *i;     }     cout <<  ] ;     cout << endl;   }   struct pt {     int x, y;     pt(int x = 0, int y = 0) : x(x), y(y) {}     pt operator-(const pt& b) { return pt(x - b.x, y - b.y); }   };   int cross(pt x, pt y) { return y.y * x.x - y.x * x.y; }   bool inside(pt a, vector<pt> b) {     int ar = abs(cross(b[1] - b[0], b[2] - b[0])) +              abs(cross(b[2] - b[0], b[3] - b[0]));     for (auto i = (0); i <= (3); ++i)       ar -= abs(cross(b[i] - a, b[(i + 1) % 4] - a));     return ar == 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     vector<pt> a(4);     for (auto i = (0); i <= (3); ++i)       cin >> a[i].x >> a[i].y, a[i].x *= 4, a[i].y *= 4;     vector<pt> b(4);     for (auto i = (0); i <= (3); ++i)       cin >> b[i].x >> b[i].y, b[i].x *= 4, b[i].y *= 4;     pt A, B;     for (auto i = (0); i <= (3); ++i)       A.x += a[i].x, A.y += a[i].y, B.x += b[i].x, B.y += b[i].y;     A.x /= 4, A.y /= 4, B.x /= 4, B.y /= 4;     bool ans = inside(A, b) | inside(B, a);     for (auto i = (0); i <= (3); ++i) ans |= inside(a[i], b) | inside(b[i], a);     cout << (ans ?  YES n  :  NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, b[100020], cnt, p, q;   char s[100020], s1[100020], s2[100020];   char chose(char x, char y) {     if (x !=  a  && y !=  a )       return  a ;     else if (x !=  b  && y !=  b )       return  b ;     else       return  c ;   }   int main() {     scanf( %d%d , &n, &t);     scanf( %s , s1);     scanf( %s , s2);     cnt = 0;     p = 0;     q = 0;     for (int i = 0; i < n; i++)       if (s1[i] != s2[i]) cnt++;     if (t < (cnt + 1) / 2) {       printf( -1 n );       return 0;     }     if (t <= cnt) {       for (int i = 0; i < n; i++) {         if (s1[i] == s2[i])           s[i] = s1[i];         else {           p++;           if (p <= 2 * t - cnt)             s[i] = chose(s1[i], s2[i]);           else if (p % 2 == 1)             s[i] = s1[i];           else             s[i] = s2[i];         }       }     } else {       for (int i = 0; i < n; i++) {         if (s1[i] == s2[i]) {           q++;           if (q <= t - cnt)             s[i] = chose(s1[i], s1[i]);           else             s[i] = s1[i];         } else {           p++;           s[i] = chose(s1[i], s2[i]);         }       }     }     printf( %s , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int n, m;       cin >> n >> m;       vector<int> a(n), b(m);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < m; i++) {         cin >> b[i];       }       vector<int> idx(100001);       for (int i = 0; i < n; i++) {         idx[a[i]] = i;       }       long long ans = 0;       int mxDepth = 0;       for (int i = 0; i < m; i++) {         if (idx[b[i]] < mxDepth) {           ans++;         } else {           mxDepth = idx[b[i]];           ans += 2 * (idx[b[i]] - i) + 1;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   const int mod = 998244353;   int n;   map<int, int> a;   char s[N];   long long ans = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       int x = 0, l = strlen(s + 1);       for (int j = 1; j <= l; j++) x = x ^ (1 << (s[j] -  a ));       for (int j = 0; j < 26; j++) ans += a[x ^ (1 << j)];       ans += a[x];       a[x]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> working;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     working[-1] = -1;     working[2E9] = 2E9;     working[1] = n;     int answer = n;     while (q--) {       int l, r, k;       cin >> l >> r >> k;       int haveNow = 0;       map<int, int>::iterator it = working.lower_bound(l);       it--;       if (it->second >= l) {         working[l] = it->second;         it->second = l - 1;       }       it++;       while (it->first <= r) {         if (it->second > r) {           haveNow += r + 1 - it->first;           working[r + 1] = it->second;         } else           haveNow += it->second - it->first + 1;         map<int, int>::iterator it2 = it;         it++;         working.erase(it2);       }       if (k == 1) {         answer -= haveNow;       } else {         answer -= haveNow;         working[l] = r;         answer += r - l + 1;       }       cout << answer <<   n ;     }     return 0;   }