malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long double PI = 3.141592653589793;   const long long maxn = 100005;   long long x, y, z, n, k;   void _print(long long t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   void solve() {     string s, t;     cin >> s >> t;     long long f[26];     memset(f, 0, sizeof(f));     long long n = (long long)s.size(), m = (long long)t.size();     vector<vector<long long>> v(26);     for (long long i = 0; i <= n - 1; i++) {       f[s[i] -  a ]++;       v[s[i] -  a ].push_back(i);     }     for (long long i = 0; i <= m - 1; i++) {       if (f[t[i] -  a ] == 0) {         cout << -1 <<   n ;         return;       }     }     long long ans = 1, last = -1;     for (long long i = 0; i <= m - 1; i++) {       long long prev = last;       long long val = t[i] -  a ;       long long pos =           lower_bound(v[val].begin(), v[val].end(), last + 1) - v[val].begin();       if (pos == v[val].size()) {         ans++;         last = v[val][0];       } else {         last = v[val][pos];       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(15) << fixed;     long long t;     t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-8;   const long long INF = 0x3f3f3f3f;   const int mod = 20000311;   const int maxn = 1e5 + 5;   const int N = 1005;   using namespace std;   int a[maxn] = {0};   int dp[maxn][305] = {0};   int n;   int dfs(int p, int k) {     if (p > n) return 0;     if (dp[p][k] != -1) return dp[p][k];     int num = p + a[p] + k;     return dp[p][k] = dfs(num, k) + 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int j = 1; j <= 300; j++) {       for (int i = n; i >= 1; i--) {         int num = i + a[i] + j;         if (num > n)           dp[i][j] = 1;         else           dp[i][j] = dp[num][j] + 1;       }     }     int q;     scanf( %d , &q);     while (q--) {       int p, k;       scanf( %d %d , &p, &k);       if (k >= 300) {         int res = 0;         while (p <= n) {           p = a[p] + k + p;           res++;         }         cout << res <<   n ;       } else         cout << dp[p][k] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string Max(int n, int s) {     string str =   ;     while (s >= 9 && n > 0) {       str +=  9 ;       s -= 9;       n--;     }     if (n == 0 && s > 0) return  -1 ;     if (n > 0) {       str += char(s + 48);       for (int i = 1; i < n; i++) str +=  0 ;     }     return str;   }   int main() {     int n, s;     string str =   ;     cin >> n >> s;     if (n * 9 < s)       cout <<  -1 -1 ;     else if (n > 1 and s == 0)       cout <<  -1 -1 ;     else if (s == 1) {       cout << 1;       for (int i = 1; i < n; i++) cout << 0;       cout <<   1 ;       for (int i = 1; i < n; i++) cout << 0;     } else {       for (int i = Max(n, s).size() - 1; i >= 0; i--) str += Max(n, s)[i];       if (str[0] ==  0  and str.size() > 1) {         str[0] =  1 ;         for (int i = 1; i < str.size(); i++)           if (str[i] >  0 ) {             str[i] = char(int(str[i]) - 1);             break;           }       }       cout << str <<     << Max(n, s);     }   }
#include <bits/stdc++.h>   using namespace std;   inline int max3(int a, int b, int c) { return max(a, max(b, c)); }   inline int min3(int a, int b, int c) { return min(a, min(b, c)); }   const int INF = 1e9;   const long long LINF = 1e18;   const double EPS = 1e-6;   const double PI = acos(-1.0);   const int maxn = 150;   int n, m, k;   int a[maxn][maxn][maxn];   int ans;   int main() {     scanf( %d %d %d n , &n, &m, &k);     char b[maxn];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         gets(b);         for (int p = 0; p < k; ++p) a[i][j][p] = b[p] ==  1 ;       }       if (i < n - 1) gets(b);     }     ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         for (int p = 0; p < k; ++p) {           if (!a[i][j][p]) continue;           if ((p > 0 && p < k - 1 && a[i][j][p - 1] && a[i][j][p + 1]) ||               (p > 0 && j < m - 1 && a[i][j][p - 1] && a[i][j + 1][p] &&                !a[i][j + 1][p - 1]) ||               (p > 0 && i < n - 1 && a[i][j][p - 1] && a[i + 1][j][p] &&                !a[i + 1][j][p - 1]) ||               (j > 0 && j < m - 1 && a[i][j - 1][p] && a[i][j + 1][p]) ||               (j > 0 && p < k - 1 && a[i][j - 1][p] && a[i][j][p + 1] &&                !a[i][j - 1][p + 1]) ||               (j > 0 && i < n - 1 && a[i][j - 1][p] && a[i + 1][j][p] &&                !a[i + 1][j - 1][p]) ||               (i > 0 && i < n - 1 && a[i - 1][j][p] && a[i + 1][j][p]) ||               (i > 0 && j < m - 1 && a[i - 1][j][p] && a[i][j + 1][p] &&                !a[i - 1][j + 1][p]) ||               (i > 0 && p < k - 1 && a[i - 1][j][p] && a[i][j][p + 1] &&                !a[i - 1][j][p + 1]))             ++ans;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int MAX_N = 1002;   int dp_end[MAX_N][MAX_N];   int dp_not[MAX_N][MAX_N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       dp_end[0][i] = (i + 1) / 2;       dp_not[0][i] = i / 2;     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         dp_end[i][j] = 1 + dp_not[i - 1][j] + dp_end[i][j - 1];         if (i - 1 >= j) {           dp_end[i][j] =               max(dp_end[i][j], 1 + dp_not[i][j - 1] + dp_end[i - 1][j]);         }         dp_end[i][j] %= M;         dp_not[i][j] = dp_end[i][j - 1] + dp_end[i - 1][j];         dp_not[i][j] %= M;       }     }     cout << dp_end[n][n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long n;     string s[222222];     map<string, bool> check;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> ws;       getline(cin, s[i]);     }     for (long long i = n; i >= 1; i--) {       if (!check[s[i]]) {         check[s[i]] = 1;         cout << s[i] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fact(int n) {     const int N = 1e5;     vector<int> arr(N, 0);     int q = 2;     arr[0] = 1;     int len = 1;     int x = 0;     int carry = 0;     while (q <= n) {       x = 0;       carry = 0;       while (x < len) {         arr[x] = arr[x] * q + carry;         carry = arr[x] / 10;         arr[x] = arr[x] % 10;         x++;       }       while (carry) {         arr[len] = carry % 10;         carry = carry / 10;         len++;       }       q++;     }     len--;     for (int i = len; i >= 0; i--) {       cout << arr[i];     }     return;   }   long long int binary_exp(long long int x, long long int n) {     if (n == 0) {       return 1;     } else if (n == 1) {       return x % 1000000007;     } else {       long long int temp = binary_exp(x, n / 2);       temp = (temp * temp) % 1000000007;       if (n % 2 == 0) {         return temp;       } else {         return ((x % 1000000007) * temp) % 1000000007;       }     }   }   int main() {     int k, r;     cin >> k >> r;     int i = 1;     while (i * k % 10 != r and i * k % 10 != 0) {       i++;     }     cout << i;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[100006];   int main() {     int n, k;     while (cin >> n >> k) {       memset(vis, false, sizeof(vis));       int st = 1, ed = 1 + k;       int cnt = 0;       while (cnt < k && st <= ed) {         if (st != ed)           vis[st] = vis[ed] = true, cout << st <<     << ed <<    ;         else           vis[st] = true, cout << st <<    ;         st++, ed--;         cnt++;       }       for (int i = 1; i <= n; i++) {         if (!vis[i]) cout << i <<    ;       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500023;   bool vis[N];   vector<int> adj[N];   void solve() {     long long int n, m;     cin >> n >> m;     map<long long int, long long int> cntA;     map<long long int, long long int> cntB;     map<long long int, long long int> cntC;     map<long long int, long long int> cntD;     map<long long int, long long int> cntE;     for (long long int i = 0; i < n; i++) {       string s;       cin >> s;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  A )           cntA[i]++;         else if (s[i] ==  B )           cntB[i]++;         else if (s[i] ==  C )           cntC[i]++;         else if (s[i] ==  D )           cntD[i]++;         else if (s[i] ==  E )           cntE[i]++;       }     }     long long int ans = 0;     for (int i = 0; i < m; i++) {       long long int c;       cin >> c;       long long int maxi = 0;       maxi = max(max(cntA[i], cntB[i]), cntC[i]);       maxi = max(max(maxi, cntD[i]), cntE[i]);       long long int temp = maxi * c;       ans += temp;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     int t = 0;     while (t++ < T) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x;   int cnt[100], b[105][105], sol[105][105], c[105][105], a[105][105];   inline void Mult_Mat(int a[][105], int b[][105]) {     int i, j, k, s;     for (i = 0; i < x; ++i)       for (j = 0; j < x; ++j) {         s = 0;         for (k = 0; k < x; ++k)           s = (1LL * s + 1LL * a[i][k] * b[k][j]) % 1000000007;         c[i][j] = s;       }     for (i = 0; i < x; ++i)       for (j = 0; j < x; ++j) a[i][j] = c[i][j];   }   inline void Pow_Log(int a[][105], int p) {     int i, j;     for (i = 0; i < x; ++i) sol[i][i] = 1;     while (p) {       if (p & 1) {         --p;         Mult_Mat(sol, a);       }       p >>= 1;       Mult_Mat(a, a);     }     for (i = 0; i < x; ++i)       for (j = 0; j < x; ++j) a[i][j] = sol[i][j];   }   int main() {     int i, j, B, k, xx;     cin.sync_with_stdio(0);     cin >> n >> B >> k >> x;     for (i = 1; i <= n; ++i) {       cin >> xx;       ++cnt[xx];     }     for (i = 0; i < x; ++i)       for (j = 0; j < 10; ++j)         b[i][(i * 10 + j) % x] = (b[i][(i * 10 + j) % x] + cnt[j]) % 1000000007;     Pow_Log(b, B);     a[1][0] = 1;     Mult_Mat(a, b);     cout << a[1][k] <<   n ;     return 0;   }
#include<bits/stdc++.h>   #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);   #define int long long   #define ull unsigned long long   #define FOR(i,a,b) for(int i=a;i<b;i++)   #define all(x) (x).begin(), (x).end()   #define pb push_back   #define mp make_pair   #define in insert   #define ff first   #define ss second   #define endl   n    #define pi pair<int,int>   #define  deb1(a)         cout<<a<<  n ;   #define  deb2(a,b)       cout<<a<<   <<b<<  n ;   #define  deb3(a,b,c)     cout<<a<<   <<b<<   <<c<<  n ;   #define  debp(a)         cout<<a.ff<<   <<a.ss<<  n ;   #define  debvec(a)      for(auto it: a)cout<<it<<   ;cout<<   ; cout<<endl;   #define  debvp(a)      for(auto it: a)cout<<it.ff<<   <<it.ss<<endl;   #define  debmap(a)      for(auto it: a)cout<< { <<it.ff<< , <<it.ss<< },  ;newl;   #define  debarr(a,n)    FOR(i,0,n)cout<<a[i]<<   ;cout<<endl;   #define inf ((int)1<<60)   #define mod 1000000007   using namespace std;   //int,char,float,double,bool,string,break,continue,endl,if,else,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf   //strlen,strcmp,compar e,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO      signed main() {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif    fast_io    int test, i, j;   //  cin >> test;    test = 1;    while (test--) {     int n, m;     cin >> n >> m;     string s, t;     cin >> s >> t;     int a[m], b[m];     j = 0;     for (int i = 0; i < n; ++i) {      if (s[i] == t[j]) {       a[j] = i;       j++;      }     }     j = m - 1;     for (int i = n - 1; i >= 0 ; i--) {      if (s[i] == t[j]) {       b[j] = i;       j--;      }     }     int ans = 0;     for (int i = 0; i < m - 1; ++i) {      ans = max(ans, b[i + 1] - a[i]);     }     cout << ans << endl;    }      }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   const int mo = 1e9 + 7;   int n, k, a[N], num[3], nn, f = 0;   long long ans, now[N][N], dp[N][N], aa[N];   long long po(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long c = po(a, b / 2);     if (b & 1)       return c * c % mo * a % mo;     else       return c * c % mo;   }   long long tmp[N][N];   void multi(long long a[][N], long long b[][N], int n) {     memset(tmp, 0, sizeof tmp);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++)           tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j] % mo) % mo;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) a[i][j] = tmp[i][j];   }   long long res[N][N];   void Pow(long long a[][N], long long n) {     memset(res, 0, sizeof res);     for (int i = 0; i < num[0] + 1; i++) res[i][i] = 1;     while (n) {       if (n & 1) multi(res, a, num[0] + 1);       multi(a, a, num[0] + 1);       n >>= 1;     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), num[a[i]]++;     if (num[0] < num[1]) {       for (int i = 1; i <= num[0]; i++)         if (!a[i]) nn++;     } else {       swap(num[0], num[1]);       for (int i = n; i >= n - num[0] + 1; i--)         if (a[i]) nn++;     }     for (int j = 0; j <= num[0]; j++) {       now[j][j] += j * (num[0] - j);       now[j][j] += (num[0] - j) * (num[1] - num[0] + j);       now[j][j] += num[0] * (num[0] - 1) / 2ll;       now[j][j] += num[1] * (num[1] - 1) / 2ll;       if (j + 1 <= num[0]) now[j][j + 1] = (j + 1) * (num[1] - (num[0] - j - 1));       if (j) now[j][j - 1] = (num[0] - j + 1) * (num[0] - j + 1);     }     Pow(now, k);     for (int i = 0; i <= num[0]; i++) ans = (ans + res[i][nn]) % mo;     printf( %lld n , res[num[0]][nn] * po(ans, mo - 2) % mo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1000000000;   int n, m, x, i, j, a[5050], f[5050];   int main() {     scanf( %d%d , &n, &m);     for (i = 3; i <= n; i++) f[i] = f[i - 1] + (i - 1) / 2;     if (f[n] < m) {       puts( -1 );       return 0;     }     for (i = 3; i <= n; i++)       if (f[i] > m) break;     m -= f[--i];     for (j = 1; j <= i; j++) a[j] = j;     if (m > 0) {       for (j = 1; j < i; j++) {         x = (i + j - 1) / 2 - j + 1;         if (x == m) {           a[i + 1] = i + j;           break;         }       }       if (j >= i) {         puts( -1~ );         return 0;       }       ++i;     }     x = a[i] + 1;     for (j = 2; j <= i; j++)       if (a[j] != a[j - 1] + 1) {         x = a[j - 1] + 1;         break;       }     for (++i; i <= n; ++i) {       a[i] = a[i - 1] + x;       if (a[i] > MX) break;     }     if (i <= n) {       puts( -1# );       return 0;     }     for (i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int INF = (int)1e9 + 7;   const long long linf = (long long)1e16 + 7;   struct pnt {     double x, y;     pnt(double x, double y) : y(y), x(x) {}     pnt() = default;   };   int cmp(double a, double b) {     if (abs(a - b) < eps) return 0;     if (a > b) return 1;     return -1;   }   int main() {     int n;     cin >> n;     int ans = 0;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> cnt0(n + 1);     vector<int> cnt1(n + 1);     for (int i = 0; i < n; ++i) {       if (a[i] == 0) cnt0[i]++;       if (i) cnt0[i] += cnt0[i - 1];     }     for (int i = n - 1; i >= 0; --i) {       if (a[i] == 1) cnt1[i]++;       if (i != n - 1) cnt1[i] += cnt1[i + 1];     }     for (int i = 0; i < n; ++i) {       ans = max(ans, cnt0[i] + cnt1[i + 1]);       ans = max(ans, cnt1[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     string s;     map<char, int> m;     for (i = 0; i < n; i++) {       cin >> s;       m[s[0]]++;     }     int ans = 0, f1, f2;     for (auto it = m.begin(); it != m.end(); it++) {       f1 = it->second / 2;       f2 = it->second - f1;       ans += f1 * (f1 - 1) / 2 + f2 * (f2 - 1) / 2;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d, a, b;     cin >> n >> d >> a >> b;     vector<pair<long long, int> > v(n);     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       v[i].first = x * a + y * b;       v[i].second = i + 1;     }     sort(v.begin(), v.end());     int ans = 0, sum = 0, pos = 0;     for (int i = 0; i < n; i++) {       if (sum + v[i].first <= d) {         sum += v[i].first;         ans++;         pos = i;       }     }     cout << ans << endl;     if (ans)       for (int i = 0; i <= pos; i++) cout << v[i].second <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long x, y, p, q;     cin >> t;     while (t--) {       cin >> x >> y >> p >> q;       long long l = 0, h = 1e9, ans = -1, mid, a, b;       while (l <= h) {         mid = (l + h) / 2;         a = p * mid;         b = q * mid;         if (b >= y && a >= x && b - a >= y - x) {           ans = b - y;           h = mid - 1;         } else           l = mid + 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int N = 2 * (1e5);   const long long int maxo = 1e14;   const long long int inf = 1e17;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int x0, y0, ax, ay, bx, by;     cin >> x0 >> y0 >> ax >> ay >> bx >> by;     long long int xs, ys, t;     cin >> xs >> ys >> t;     vector<pair<long long int, long long int> > v;     v.push_back({x0, y0});     for (long long int i = 0; i < 100; i++) {       if (v.back().first > (inf - bx) / (ax)) break;       if (v.back().second > (inf - by) / ay) break;       long long int x1 = v.back().first * ax + bx;       long long int y1 = v.back().second * ay + by;       v.push_back({x1, y1});     }     long long int n = v.size();     long long int ans = 0;     for (long long int l = 0; l < n; l++) {       for (long long int r = l; r < n; r++) {         long long int d1 = abs(xs - v[l].first) + abs(ys - v[l].second);         long long int d2 = abs(xs - v[r].first) + abs(v[r].second - ys);         long long int len =             abs(v[l].first - v[r].first) + abs(v[l].second - v[r].second);         if (d1 + len <= t) {           ans = max(ans, r - l + 1);         }         if (d2 + len <= t) {           ans = max(ans, r - l + 1);         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void setIO(string name =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (int((name).size())) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long mcm(long long a, long long b) { return (a * b) / gcd(a, b); }   bool prime(long long n, long long i) {     if (i > sqrt(n)) return true;     if (n % i == 0)       return false;     else       return prime(n, i + 1);   }   struct compii {     bool operator()(const pair<int, int> &a, const pair<int, int> &b) {       if (a.first == a.second) return a.second < b.second;       return a.first > b.first;     }   };   bool comp(int a, int b) { return a > b; }   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   const int mod = 1e9 + 7;   const long long inf = 1e18;   bool check(string a, string b) {     if (a ==  rock  and b ==  scissors ) return true;     if (a ==  paper  and b ==  rock ) return true;     if (a ==  scissors  and b ==  paper ) return true;     return false;   }   void solve() {     string first, m, second;     cin >> first >> m >> second;     if (check(first, m) and check(first, second))       cout <<  F ;     else if (check(m, second) and check(m, first))       cout <<  M ;     else if (check(second, first) and check(second, m))       cout <<  S ;     else       cout <<  ? ;   }   int main() {     setIO(  );     int t = 1;     while (t-- > 0) solve();     return 0;   }