malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long p = 131;   const int N = 210000;   int n, m;   char sr1[N], sr2[N];   unsigned long long hash1[N][28], hash2[N][28], Q[N];   int Ans[N], ans;   int main() {     int i, j, k, x, y;     cin >> n >> m;     scanf( %s%s , sr1 + 1, sr2 + 1);     Q[0] = 1;     for (i = 1; i <= n; ++i) Q[i] = Q[i - 1] * p;     for (j = 0; j <= 25; ++j)       for (i = 1; i <= n; ++i) {         hash1[i][j] = hash1[i - 1][j] * p;         if (sr1[i] -  a  == j) hash1[i][j] += 1;       }     for (j = 0; j <= 25; ++j)       for (i = 1; i <= m; ++i) {         hash2[i][j] = hash2[i - 1][j] * p;         if (sr2[i] -  a  == j) hash2[i][j] += 1;       }     int cnt;     for (i = 1; i <= n - m + 1; ++i) {       cnt = 0;       for (x = 0; x < 26; ++x) {         if (cnt != x) break;         for (y = 0; y < 26; ++y)           if (hash2[m][x] == hash1[i + m - 1][y] - hash1[i - 1][y] * Q[m])             if (hash2[m][y] == hash1[i + m - 1][x] - hash1[i - 1][x] * Q[m]) {               cnt++;               break;             }       }       if (cnt == 26) Ans[++ans] = i;     }     cout << ans << endl;     for (i = 1; i < ans; ++i) printf( %d  , Ans[i]);     if (ans != 0) printf( %d , Ans[ans]);   }
#include <bits/stdc++.h>   using namespace std;   int n, f;   long long ans;   long long k, l;   long long d[100001];   int main() {     cin >> n >> f;     for (int i = 1; i <= n; i++) {       cin >> k >> l;       d[i] = -min(k, l - k);       ans = ans + min(k, l);     }     sort(d + 1, d + n + 1);     for (int i = 1; i <= f; i++) ans = ans + max(-d[i], (long long)(0));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, int> M;   char t[7] = { B ,  u ,  l ,  b ,  a ,  s ,  r };   int num[7] = {1, 2, 1, 1, 2, 1, 1};   char ch[200020];   int main() {     scanf( %s , ch);     int n = strlen(ch);     for (int i = 0; i < n; i++) M[ch[i]]++;     int ans = 1 << 30;     for (int i = 0; i < 7; i++) ans = min(ans, M[t[i]] / num[i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void amax(X& x, const Y& y) {     if (x < y) x = y;   }   template <class X, class Y>   void amin(X& x, const Y& y) {     if (x > y) x = y;   }   const int INF = 1e9 + 10;   const long long INFL = 1e18 + 10;   const int MAX = 1e6 + 10;   int n;   int a[MAX], prv[MAX], pos[MAX];   long long gt[MAX * 4], lazy[MAX * 4];   void update(int id, int l, int r, int u, int v) {     if (v < l || u > r) return;     if (u <= l && r <= v) {       lazy[id]++;       gt[id] += (r - l + 1);       return;     }     int mid = (l + r) / 2;     update(id * 2, l, mid, u, v);     update(id * 2 + 1, mid + 1, r, u, v);     gt[id] = gt[id * 2] + gt[id * 2 + 1] + lazy[id] * (r - l + 1);   }   long long query(int id, int l, int r, int u, int v) {     if (v < l || u > r) return 0;     if (u <= l && r <= v) return gt[id];     int mid = (l + r) / 2;     return query(id * 2, l, mid, u, v) + query(id * 2 + 1, mid + 1, r, u, v) +            lazy[id] * (min(r, v) - max(u, l) + 1);   }   void process() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       prv[i] = pos[a[i]];       pos[a[i]] = i;     }     long double sum = 0;     long double choose = (long long)n * n;     for (int i = 1; i <= n; i++) {       update(1, 1, n, prv[i] + 1, i);       sum = sum + (query(1, 1, n, 1, i) * 2 - 1) / choose;     }     cout << fixed << setprecision(10) << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     process();   }
#include <iostream>   #include <vector>   using namespace std;   int t,k,n,m;   vector<int> a,b,v;   int main() {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       cin>>t;       while (t--) {           cin>>k>>n>>m;           a.resize(n);           b.resize(m);           for (int &x:a) cin>>x;           for (int &x:b) cin>>x;           auto solve=[&]()->vector<int> {               vector<int> sequences;               int l=0,r=0,cur=k;               while (true) {                   if (l==n && r==m) break;                   if (l!=n && a[l]>=0 && a[l]<=cur) {                       if (a[l]==0) cur++;                       sequences.emplace_back(a[l++]);                   }                   else if (r!=m && b[r]>=0 && b[r]<=cur) {                       if (b[r]==0) cur++;                       sequences.emplace_back(b[r++]);                   }                   else return vector<int> {-1};               }               return sequences;           };           v=solve();           for (int i=0;i<(int)v.size();i++) cout<<v[i]<<   n [i==(int)v.size()-1];       }   }
#include <bits/stdc++.h>   int main() {     int n, i, a[100001];     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++)       while (a[i] % 2 == 0) a[i] /= 2;     for (i = 1; i <= n; i++)       while (a[i] % 3 == 0) a[i] /= 3;     for (i = 1; i <= n - 1; i++)       if (a[i] != a[i + 1]) {         printf( NO );         return 0;       }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int u, v, w;   } p[400500];   int father[200100];   int use[200100];   int coo(struct data a, struct data b) {     if (a.w > b.w) return 1;     return 0;   }   int find(int x) { return x == father[x] ? x : father[x] = find(father[x]); }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) father[i] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &p[i].u, &p[i].v, &p[i].w);     }     sort(p + 1, p + m + 1, coo);     long long ans = 0;     for (int i = 1; i <= m; i++) {       int x = find(p[i].u), y = find(p[i].v);       if (use[x] && use[y]) continue;       if (x == y)         use[x] = 1;       else {         father[x] = y;         use[y] |= use[x];       }       ans += p[i].w;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int A[202020];   string S;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> K;     for (i = 0; i < (N); i++) cin >> A[i];     cin >> S;     signed long long ret = 0;     for (i = 0; i < N;) {       j = i;       vector<int> V;       while (j < N && S[i] == S[j]) {         V.push_back(A[j]);         j++;       }       i = j;       sort((V.begin()), (V.end()));       reverse((V.begin()), (V.end()));       for (j = 0; j < (min(K, (int)V.size())); j++) ret += V[j];     }     cout << ret << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[500005], b[500005], reach[500005][19];   int tree[4 * 500005][19];   void build(int i, int layer, int low, int high) {     if (low == high) {       tree[i][layer] = reach[low][layer];       return;     }     int mid = (low + high) / 2;     build(2 * i, layer, low, mid);     build(2 * i + 1, layer, mid + 1, high);     tree[i][layer] = min(tree[2 * i][layer], tree[2 * i + 1][layer]);   }   int get(int i, int layer, int low, int high, int u, int v) {     if (v < low || high < u) return 500005;     if (u <= low && high <= v) return tree[i][layer];     int mid = (low + high) / 2;     return min(get(2 * i, layer, low, mid, u, v),                get(2 * i + 1, layer, mid + 1, high, u, v));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i + n] = a[i];     }     m = 2 * n - 1;     for (int i = 1; i <= m; i++) {       b[i] = i - a[i];       reach[i][0] = max(1, b[i]);     }     build(1, 0, 1, m);     for (int j = 1; j < 19; j++) {       for (int i = 1; i <= m; i++)         reach[i][j] = get(1, j - 1, 1, m, reach[i][j - 1], i);       build(1, j, 1, m);     }     long long ret = 0;     for (int end = n; end <= m; end++) {       int moves = 0;       int prev = end;       for (int j = 19 - 1; j >= 0; j--) {         int tmp = get(1, j, 1, m, prev, end);         if (tmp > end - n + 1) {           moves += 1 << j;           prev = tmp;         }       }       moves++;       ret += moves;     }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int mul(long long int a) {     int mi = 10, ma = 0;     while (a != 0) {       int d = a % 10;       mi = min(mi, d);       ma = max(ma, d);       a /= 10;     }     return mi * ma;   }   int main() {     int t = 0;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       k--;       while (k--) {         int mult = mul(n);         if (mult == 0) {           break;         }         n += mult;       }       std::cout << n << std::endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:640000000 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int a, b;     cin >> a >> b;     for (int _n((a)-1), i(0); i <= _n; ++i) cout << i + 1 <<    ;     for (int i = (a + b + 1), _b = (a + 1); i >= _b; --i) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> prime_Numbers;   bool primes[1000005];   void prime(int n) {     for (int i = 2; i <= n; i++) primes[i] = true;     for (int i = 2; i <= n; i++) {       if (primes[i] == true) {         prime_Numbers.push_back(i);         for (int j = i + i; j <= n; j += i) primes[j] = false;       }     }   }   int fib(int n) {     if (n == 1 || n == 0) return n;     return fib(n - 1) + fib(n - 2);   }   long long fastpower(int b, int p) {     if (p == 0) return 1;     long long term = fastpower(b, p / 2);     term *= term;     if (p % 2 != 0) return term *= b;     return term;   }   long long arr[3005];   int main() {     int t;     cin >> t;     while (t--) {       int n, k, d;       cin >> n >> k >> d;       int arr[n + 2];       set<int> st;       map<int, int> mp;       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < d; i++) {         st.insert(arr[i]);         mp[arr[i]]++;       }       int mnm = st.size();       for (int i = d; i < n; i++) {         mp[arr[i - d]]--;         if (mp[arr[i - d]] == 0) st.erase(arr[i - d]);         st.insert(arr[i]);         mp[arr[i]]++;         mnm = min(mnm, (int)st.size());       }       cout << min(mnm, (int)st.size()) << endl;     }     return 0;   }
#include <bits/stdc++.h>   long long int add(long long int a, long long int b) {     return a + b - (a + b >= 1000000007) * 1000000007;   }   long long int sub(long long int a, long long int b) {     return a - b + (a - b < 0) * 1000000007;   }   long long int mult(long long int a, long long int b) {     return (1LL * a * b) % 1000000007;   }   inline long long int gcd(long long int a, long long int b) {     long long int t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   long long int powmod(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int k;     cin >> k;     long long int q = (1000000007 - 1) / 2;     long long int d = 2;     for (long long int i = 0; i < k; i++) {       long long int x;       cin >> x;       q = powmod(q, x);       d = powmod(d, x);     }     d = d * powmod(2, 1000000007 - 2) % 1000000007;     q = (q * 2 + 1) % 1000000007 * powmod(3, 1000000007 - 2) % 1000000007;     long long int p = q * d % 1000000007;     cout << p <<  /  << d;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1 << 20];   int arr[][5] = {{1, 2, -1},       {2, -1},      {-1},     {4, 5, 6, -1},                   {5, 6, -1},       {6, -1},      {-1},     {8, 9, 10, 11, -1},                   {9, 10, 11, -1},  {10, 11, -1}, {11, -1}, {-1},                   {13, 14, 15, -1}, {14, 15, -1}, {15, -1}, {-1},                   {17, 18, -1},     {18, -1},     {-1}};   int arc[][5] = {{3, 7, -1},                   {4, 8, 12, -1},                   {5, 9, 13, 16, -1},                   {7, -1},                   {8, 12, -1},                   {9, 13, 16, -1},                   {10, 14, 17, -1},                   {-1},                   {12, -1},                   {13, 16, -1},                   {14, 17, -1},                   {15, 18, -1},                   {-1},                   {16, -1},                   {17, -1},                   {18, -1},                   {-1},                   {-1},                   {-1}};   int ard[][5] = {{4, 9, 14, 18, -1},                   {5, 10, 15, -1},                   {6, 11, -1},                   {8, 13, 17, -1},                   {9, 14, 18, -1},                   {10, 15, -1},                   {11, -1},                   {12, 16, -1},                   {13, 17, -1},                   {14, 18, -1},                   {15, -1},                   {-1},                   {16, -1},                   {17, -1},                   {18, -1},                   {-1},                   {-1},                   {-1},                   {-1}};   int gao(int st) {     int &res = dp[st];     if (res != -1) return res;     if (st == 0) return res = 0;     for (int i = 0; i < 19; i++) {       if ((st & (1 << i)) == 0) continue;       int now = i;       int tmp = now;       int fk = st;       if (gao(st ^ (1 << i)) == 0) {         return res = 1;       }       fk = st ^ (1 << i);       int j = 0;       while (arr[now][j] != -1) {         if ((st & (1 << arr[now][j])) == 0) break;         fk ^= (1 << arr[now][j]);         if (gao(fk) == 0) {           return res = 1;         }         j++;       }       fk = st ^ (1 << i);       j = 0;       while (arc[now][j] != -1) {         if ((st & (1 << arc[now][j])) == 0) break;         fk ^= (1 << arc[now][j]);         if (gao(fk) == 0) {           return res = 1;         }         j++;       }       fk = st ^ (1 << i);       j = 0;       while (ard[now][j] != -1) {         if ((st & (1 << ard[now][j])) == 0) break;         fk ^= (1 << ard[now][j]);         if (gao(fk) == 0) {           return res = 1;         }         j++;       }     }     return res = 0;   }   int main() {     int i, j, k, n, f = 0;     for (i = 0; i < 19; i++) {       char rr[5];       scanf( %s , rr);       if (rr[0] ==  O ) f |= (1 << i);     }     memset(dp, -1, sizeof(dp));     int ch = gao(f);     if (ch == 1)       puts( Karlsson );     else       puts( Lillebror );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 5;   const long long N = 205;   void solve();   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout << fixed << setprecision(10);     long long _ = 1;     while (_--) solve();     return 0;   }   void solve() {     string s;     cin >> s;     long long n = s.size();     long long ans = LLONG_MAX;     for (long long loop = 0; loop < 26; loop++) {       char ch =  a  + loop;       long long cnt = 0, temp = 0;       for (long long i = 0; i < n; i++) {         cnt++;         if (ch == s[i]) {           temp = max(temp, cnt);           cnt = 0;         }       }       if (cnt) cnt++;       temp = max(temp, cnt);       ans = min(temp, ans);     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[100005];   int main() {     {       cin >> n;       for (int i = 0; i < n; i++) scanf( %lld , &a[i]);       sort(a, a + n);       long long ans = LLONG_MAX;       for (int c = 1;; c++) {         long long now = 1;         long long tot = 0;         bool ok = 1;         for (int i = 0; i < n; i++) {           tot += abs(now - a[i]);           now = now * c;           if (now > 1e14) {             ok = 0;             break;           }         }         if (!ok) break;         ans = min(ans, tot);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   vector<int> primes;   void solve() {     int n;     cin >> n;     set<int> divisors;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         divisors.insert(i);         divisors.insert(n / i);       }     }     auto prime = [&](int x) {       if (x == 2 || x == 3) return true;       for (int i = 2; i * i <= x; i++) {         if (x % i == 0) return false;       }       return true;     };     if (divisors.size() == 2) {       if (prime(*divisors.begin()) && prime(*prev(divisors.end()))) {         for (auto d : divisors) cout << d <<    ;         cout << n << endl;         cout << 1 << endl;         return;       }     }     divisors.insert(n);     vector<int> primes;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         primes.push_back(i);         while (n % i == 0) n = n / i;       }     }     if (n > 1) primes.push_back(n);     vector<int> ans;     unordered_set<int> avail(divisors.begin(), divisors.end());     for (int i = 0; i < primes.size(); i++) {       int p = primes[i];       int q = primes[(i + 1) % primes.size()];       for (auto d : divisors) {         if (avail.find(d) != avail.end() && d % p == 0 && d % q != 0) {           ans.push_back(d);           avail.erase(d);         }       }       int r = p * q;       if (avail.find(r) != avail.end()) {         ans.push_back(r);         avail.erase(r);       }     }     for (auto d : divisors) {       if (avail.find(d) != avail.end()) {         ans.push_back(d);         avail.erase(d);       }     }     assert(avail.empty());     for (auto e : ans) cout << e <<    ;     cout << endl;     cout << 0 << endl;   }   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3,Ofast,no-stack-protector,unroll-loops,fast-math )   const int maxn = 2e3 + 7;   int32_t main() {     int n, d, e;     cin >> n >> d >> e;     int ans = 1e9 + 7;     for (int i = 1; i * 5 * e <= n; i++) {       int t = i * 5 * e;       t = n - t;       t %= (d);       ans = min(ans, t);     }     int t = n % d;     ans = min(ans, t);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   using big = long long;   const int N = 200200;   int a[N];   int f[N][2][2][2][2];   int dfs(int n, int x, int y, int v1, int v2) {     if (!n) {       assert(!x && !y);       return v1 > v2;     }     if (x && !dfs(n - 1, x - 1, y, v2, !v1)) {       return true;     }     if (y && !dfs(n - 1, x, y - 1, v2, v1)) {       return true;     }     return false;   }   vector<int> to_vec(int x, int y) { return {x % 4, y % 4}; }   map<vector<int>, int> init() {     map<vector<int>, int> g;     vector<vector<int>> ans;     for (int n = 1; n <= 16; ++n) {       for (int x = 1; x <= n; x += 2) {         int y = n - x;         int res = dfs(n, x, y, 0, 0);         if (g.count(to_vec(x, y)) && g[to_vec(x, y)] != res) {           cerr <<   ERRRR    << endl;         }         assert(!g.count(to_vec(x, y)) || g[to_vec(x, y)] == res);         g[to_vec(x, y)] = res;         ans.push_back({x, y, res});       }     }     return g;   }   int main() {     ios_base::sync_with_stdio(false);     auto g = init();     int cas;     cin >> cas;     memset(f, -1, sizeof(f));     while (cas--) {       int n;       cin >> n;       int s = 0;       for (int i = 0; i < n; ++i) {         cin >> a[i];         s ^= a[i];       }       int highest = 0;       for (int i = 0; (1ll << i) <= s; ++i) {         highest = i;       }       int cnt = 0;       for (int i = 0; i < n; ++i) {         if (a[i] >> highest & 1) {           ++cnt;         }       }       int other = n - cnt;       if (!s) {         cout <<  DRAW               <<   n ;       } else {         assert(cnt & 1);         if (g[to_vec(cnt, other)]) {           cout <<  WIN                 <<   n ;         } else {           cout <<  LOSE                 <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 123456789;   const long long inf = 123456789000000000;   const double EPS = 1e-10;   const double PI = 2 * asin(1.0);   const long long mod = 1e9 + 7;   inline int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   int main() {     string s;     cin >> s;     long long par, impar, ap, ai, bp, bi;     par = impar = ap = ai = bp = bi = 0LL;     for (int i = 0; i < ((int)s.size()); ++i) {       impar++;       if (i % 2 == 0) {         if (s[i] ==  a ) {           par += ai;           impar += ap;           ap++;         } else {           par += bi;           impar += bp;           bp++;         }       } else {         if (s[i] ==  a ) {           par += ap;           impar += ai;           ai++;         } else {           par += bp;           impar += bi;           bi++;         }       }     }     cout << par <<     << impar << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100100], tmp, Ans, Odd, Even;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1)         Odd++;       else         Even++;     }     tmp = min(Odd, Even);     Ans += tmp;     Odd -= tmp;     Ans += Odd / 3;     cout << Ans <<   n ;     return 0;   }