malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     int hx, hy;     int tx, ty;     int dep;     long dir;     int zt[15];   };   queue<node> q;   int n, m, len;   int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};   bool v[15][15][262144];   char c[30][30];   bool init(int a, int b) {     if (a < 0 || a >= n || b < 0 || b >= m) return 0;     return 1;   }   int update(int d, int nd) {     d = d | (nd << ((len - 1) * 2));     d >>= 2;     return d;   }   void out(int d) {     for (int i = 1; i < len; i++) {       int t = d % 4;       if (t == 0) cout <<  w ;       if (t == 1) cout <<  d ;       if (t == 2) cout <<  s ;       if (t == 3) cout <<  a ;       d /= 4;     }   }   void zut(int x) {     for (int i = 1; i <= m; i++) {       cout << x % 2;       x /= 2;     }   }   int ax, ay;   node fst;   int main() {     cin >> n >> m;     int fhx, fhy, ftx, fty;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> c[i][j];         if (c[i][j] >=  1  && c[i][j] <=  9 ) len = max(len, c[i][j] -  0 );         if (c[i][j] ==  1 ) {           fhx = i;           fhy = j;         }         if (c[i][j] == len +  0 ) {           ftx = i;           fty = j;         }         if (c[i][j] ==  @ ) {           ax = i;           ay = j;         }       }     int fdir = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (c[i][j] >=  1  && c[i][j] <=  9 ) {           for (int k = 0; k < 4; k++) {             int nx = i + dx[k], ny = j + dy[k];             if (init(nx, ny) && c[nx][ny] == c[i][j] - 1) {               int nk = k;               fdir = fdir | (nk << ((len - (c[i][j] -  0 )) * 2));               break;             }           }           fst.zt[i] |= (1 << j);         }     fst.dir = fdir, fst.hx = fhx, fst.hy = fhy, fst.tx = ftx, fst.ty = fty,     fst.dep = 0;     q.push(fst);     while (!q.empty()) {       node f = q.front();       q.pop();       if (f.hx == ax && f.hy == ay) {         cout << f.dep;         return 0;       } else {         for (int i = 0; i < 4; i++) {           int nx = f.hx + dx[i], ny = f.hy + dy[i];           if (!init(nx, ny)) continue;           if (c[nx][ny] ==  # ) continue;           if (f.zt[nx] & (1 << ny) && !(nx == f.tx && ny == f.ty)) continue;           node nf = f;           nf.hx = nx;           nf.hy = ny;           nf.tx = dx[f.dir & (3)] + f.tx;           nf.ty = dy[f.dir & (3)] + f.ty;           nf.zt[f.tx] ^= (1 << f.ty);           nf.zt[nx] |= (1 << ny);           nf.dir = update(f.dir, i);           nf.dep++;           if (v[nx][ny][nf.dir]) continue;           v[nx][ny][nf.dir] = 1;           q.push(nf);         }       }     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vb = vector<bool>;   using vvb = vector<vb>;   using vi = vector<int>;   using vvi = vector<vi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vc = vector<char>;   using vvc = vector<vc>;   using vs = vector<string>;   const ll mod = 1e9 + 7, inf = 1e18;   void setIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;   }   int main() {     setIO();     int t;     cin >> t;     while (t--) {       ll n;       cin >> n;       ll m = 1;       for (int i = 3; i <= 2 * n; i++) m = m * i % 1000000007;       cout << m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ara[n];     int temp = n;     int k = 0;     while (n--) {       cin >> ara[k++];     }     sort(ara, ara + temp);     queue<int> Q;     for (int i = 0; i < temp; i++) {       Q.push(ara[i]);     }     int i;     for (i = 1; i < 1000000; i++) {       while (!Q.empty() && Q.front() < i) {         Q.pop();       }       if (Q.empty()) break;       Q.pop();     }     cout << i << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   long long eq(long long start, long long k) {     long long num = k - (start - 1);     return ((num * (start + k)) / 2) - (num - 1);   }   void solve() {     long long n, k;     cin >> n >> k;     long long q = eq(2, k);     if (n == 1)       cout << 0 <<   n ;     else if (n <= k)       cout << 1 <<   n ;     else if (q < n)       cout << -1 <<   n ;     else {       long long en = k;       long long st = 2;       long long res = -1;       while (st < en && st > 1) {         long long mid = st + en >> 1;         if (eq(mid, k) < n) {           en = mid;         } else {           st = mid + 1;           res = mid;         }       }       res--;       cout << k - res <<   n ;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1 << 30);   const double Exp = 1e-8;   const int maxm = 1e5 + 7;   const int maxn = 1e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const double pi = 3.1415926535898;   string s;   int q, n, sum1, sum2, sum3;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> q;     while (q--) {       cin >> n;       sum1 = sum2 = sum3 = 0;       for (int i = 1; i <= n; ++i) {         cin >> s;         if (s.size() % 2) sum3++;         for (int j = 0; j < s.size(); ++j) {           if (s[j] ==  1 )             sum1++;           else             sum2++;         }       }       if (sum1 % 2 && sum2 % 2 && !sum3)         cout << n - 1 << endl;       else         cout << n << endl;     }     return 0;   }
#include<bits/stdc++.h>   using  namespace std;      #define  ll                  long long   #define  inf                  1e18      #define  memset(a , b)       memset((a) , (b) , sizeof(a))   #define  mod                 1000000007   #define  rep(i , n)          for((i) = 0 ; (i) < n ; (i)++)   #define  N                   200005               ll t , d , ct  , q, ans , l ,m , r , n , mx , mn , i, j , k , x , y , z , s  ;        char ch ;           string ss =    ,  str =    ;        ll a[N] ,  b[N] ;               void dbg(ll x, ll y = 0, ll z = 0, ll a = 0)     { cout <<  Dbg:   << x <<     << y <<     << z <<     << a <<   n ;   }           /*---------------------------------------Main Code----------------------------------------------------- */                  int main(){                                 ios_base::sync_with_stdio (false),            cin.tie(nullptr);                          cin >> x >> y >> k;             if (y == 1)         {             if (k)             {                 cout <<  No n ;                 return 0;             }             cout <<  Yes n ;                 cout <<  1 ;             rep(i, x)                     cout                 <<  0 ;             cout <<   n ;                 cout <<  1 ;             rep(i, x)                     cout                 <<  0 ;             return 0;         }                 if (!x)         {             if (k)             {                 cout <<  No n ;                 return 0;             }                 cout <<  Yes n ;             rep(i, y)                     cout                 <<  1 ;             cout <<   n ;             rep(i, y)                     cout                 <<  1 ;             return 0;         }            if (k > x + y - 2)         {             cout <<  No ;             return 0;         }            cout <<  Yes n ;            rep(i, y)                 cout             <<  1 ;         rep(i, x)                 cout             <<  0 ;            cout <<   n ;            if (k <= x)         {             rep(i, y - 1)                     cout                 <<  1 ;             rep(i, k)                     cout                 <<  0 ,                 x--;                cout <<  1 ;                rep(i, x)                     cout                 <<  0 ;                return 0;         }            k -= x;            rep(i, y  - k -1)                 cout             <<  1 ;            cout <<  0 ;            y -= (y -k-  1);            rep(i, y - 1)                 cout             <<  1 ;            rep(i, x - 1)                 cout             <<  0 ;            cout <<  1 ;            return 0;   }
#include <bits/stdc++.h>   using namespace std;   int D, m, x, y;   vector<vector<long double>> e;   const long double oo = 1e13;   vector<long double> mns(vector<long double> a, vector<long double> b) {     vector<long double> ret;     ret.resize(D);     for (int i = 0; i < D; i++) ret[i] = a[i] - b[i];     return ret;   }   vector<long double> tms(vector<long double> a, long double c) {     for (int i = 0; i < D; i++) a[i] *= c;     return a;   }   vector<long double> perp(vector<long double> a, vector<long double> b) {     long double norma = 0, normb = 0, dot = 0;     for (int i = 0; i < D; i++) {       norma += a[i] * a[i];       normb += b[i] * b[i];       dot += a[i] * b[i];     }     if (normb < 1e-9) return a;     long double tmp = dot / normb;     vector<long double> bb = tms(b, tmp);     return mns(a, bb);   }   struct subspace {     vector<vector<long double>> vectors;     vector<vector<long long>> canon;     subspace(vector<vector<long double>> _vectors) {       int d = _vectors.size();       vectors = _vectors;       for (int i = 0; i < d; i++)         for (int j = 0; j < i; j++) vectors[i] = perp(vectors[i], vectors[j]);       for (int i = 0; i < D; i++) {         vector<long double> x = e[i];         for (int j = 0; j < d; j++) x = perp(x, vectors[j]);         vector<long long> y(D);         for (int i = 0; i < D; i++) {           y[i] = llround(x[i] * oo);         }         canon.push_back(y);       }     }   };   map<vector<vector<long long>>, int> mp;   int cnt = 1;   int main() {     std::ios::sync_with_stdio(false);     cin >> m >> D;     e.resize(D);     for (int i = 0; i < D; i++) {       e[i].resize(D);       e[i][i] = 1;     }     for (int i = 1; i <= m; i++) {       vector<vector<long double>> tmp;       cin >> x;       for (int j = 0; j < x; j++) {         vector<long double> v;         for (int k = 0; k < D; k++) {           cin >> y;           v.push_back(y);         }         tmp.push_back(v);       }       auto c = subspace(tmp).canon;       if (mp.count(c))         cout << mp[c] <<    ;       else         cout << (mp[c] = cnt++) <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 233333;   int par[N][25], dep[N];   int u, v, ans;   int n;   inline int lca(int u, int v) {     if (dep[u] < dep[v]) {       u ^= v;       v ^= u;       u ^= v;     }     for (int i = 0; i < 25; i++)       if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i];     if (u == v) return u;     for (int i = 24; i >= 0; i--)       if (par[u][i] != par[v][i]) {         u = par[u][i];         v = par[v][i];       }     return par[u][0];   }   int main() {     scanf( %d , &n);     par[1][0] = 0;     dep[1] = 0;     u = v = 1;     for (int i = 2; i <= n; i++) {       int w;       scanf( %d , &w);       par[i][0] = w;       dep[i] = dep[w] + 1;       for (int j = 1; j < 24; j++) par[i][j] = par[par[i][j - 1]][j - 1];       w = i;       int l = lca(u, w);       int dst = dep[u] - dep[l] + dep[w] - dep[l];       int nu = u, nv = v;       if (dst > ans) {         ans = dst;         nu = u;         nv = w;       }       l = lca(v, w);       dst = dep[v] - dep[l] + dep[w] - dep[l];       if (dst > ans) {         ans = dst;         nu = w;         nv = v;       }       printf( %d%c , ans, i == n ?   n  :    );       u = nu;       v = nv;     }     return 0;   }
#include <bits/stdc++.h>   unsigned long long mulmod(unsigned long long a, unsigned long long b,                             unsigned long long c) {     unsigned long long x = 0, y = a % c;     while (b > 0) {       if (b % 2 == 1) {         x = (x + y) % c;       }       y = (y * 2) % c;       b /= 2;     }     return x % c;   }   unsigned long long pow(unsigned long long a, unsigned long long b,                          unsigned long long c) {     unsigned long long x = 1, y = a;     while (b > 0) {       if (b & 1) x = mulmod(x, y, c);       y = mulmod(y, y, c);       b >>= 1;     }     return x;   }   bool Miller(unsigned long long p, int iteration) {     if (p < 2) {       return false;     }     if (p != 2 && p % 2 == 0) {       return false;     }     unsigned long long second = p - 1;     while (second % 2 == 0) {       second /= 2;     }     for (int i = 0; i < iteration; i++) {       unsigned long long a = rand() % (p - 1) + 1, temp = second;       unsigned long long mod = pow(a, temp, p);       while (temp != p - 1 && mod != 1 && mod != p - 1) {         mod = mulmod(mod, mod, p);         temp *= 2;       }       if (mod != p - 1 && temp % 2 == 0) {         return false;       }     }     return true;   }   using namespace std;   int main() {     int n;     scanf( %d , &n);     int pos = 0;     string ans =   ;     string text[2][10] = {{ zero ,  one ,  two ,  three ,  four ,  five ,  six ,                             seven ,  eight ,  nine },                           {  ,  ten- ,  twenty- ,  thirty- ,  forty- ,  fifty- ,                             sixty- ,  seventy- ,  eighty- ,  ninety- }};     string tens[9] = { ten ,    twenty ,   thirty ,  forty ,  fifty ,                        sixty ,  seventy ,  eighty ,  ninety };     if (n % 10 == 0 && n != 0) {       cout << tens[(n / 10) - 1] <<   n ;       return 0;     } else if (n < 20) {       if (n < 10) {         cout << text[0][n] <<   n ;       } else {         switch (n) {           case 11:             cout <<  eleven n ;             break;           case 12:             cout <<  twelve n ;             break;           case 13:             cout <<  thirteen n ;             break;           case 14:             cout <<  fourteen n ;             break;           case 15:             cout <<  fifteen n ;             break;           case 16:             cout <<  sixteen n ;             break;           case 17:             cout <<  seventeen n ;             break;           case 18:             cout <<  eighteen n ;             break;           case 19:             cout <<  nineteen n ;         }       }       return 0;     }     while (n) {       int d = n % 10;       ans.insert(0, text[pos][d]);       pos++;       n /= 10;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long s[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> s[i][j];       }     }     long long ans = sqrt((long long)((s[0][1] * s[0][2]) / s[1][2]));     cout << ans;     for (int i = 1; i < n; i++) {       cout <<     << s[0][i] / ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str(string s) {     if (s.size() % 2) return s;     string a = str(s.substr(0, s.size() / 2));     string b = str(s.substr(s.size() / 2, s.size() / 2));     if (a < b)       return a + b;     else       return b + a;   }   int main() {     ios_base::sync_with_stdio(0);     string s1, s2;     cin >> s1 >> s2;     if (str(s1) == str(s2))       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   int n;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int a[100005];   int main() {     int i, j, fl, test, pos = 0, mx = 0;     scanf( %d , &n);     long long ans = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > mx) {         mx = a[i];         pos = i;       }     }     for (i = pos; i < n; i++) {       ans = ans + (mx - a[i]);     }     int sofar[100005];     sofar[0] = 0;     for (i = 1; i < pos; i++) {       sofar[i] = max(sofar[i - 1], a[i]);     }     for (i = pos - 1; i >= 0; i--) {       mx--;       mx = max(mx, a[i]);       ans = ans + max((mx - a[i]), (sofar[i] - a[i]));     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   const int N = 307;   int n, m, p[] = {1, 0, 0, 1, -1, 0, 0, -1};   char s[N][N];   long long P, q;   long long val[N][N];   queue<pair<pair<int, int>, long long> > Q;   bool vis[N][N];   vector<pair<int, int> > kto;   void bfs(int x, int y, long long v) {     Q.push({{x, y}, v});     for (auto xx : kto) vis[xx.first][xx.second] = 0;     kto.clear();     vis[x][y] = 1;     while (!Q.empty()) {       int xx = Q.front().first.first, yy = Q.front().first.second;       long long vv = Q.front().second;       val[xx][yy] += vv;       Q.pop();       kto.push_back({xx, yy});       vv /= 2;       if (vv == 0) continue;       for (int i = 0; i < 8; i += 2) {         int ux = xx + p[i], uy = yy + p[i + 1];         if (s[ux][uy] ==  * ) continue;         if (1 > ux || ux > n || 1 > uy || uy > m) continue;         if (!vis[ux][uy]) {           vis[ux][uy] = 1;           Q.push({{ux, uy}, vv});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q >> P;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if ( A  <= s[i][j] && s[i][j] <=  Z ) {           long long vv = (long long)(s[i][j] -  A  + 1) * q;           bfs(i, j, vv);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (val[i][j] > P) ans++;       }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int parent[200005], par[200005], root;   int find(int i) {     if (parent[i] != i) parent[i] = find(parent[i]);     return parent[i];   }   void merge(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (xroot == yroot) {       if (!root) root = xroot;       par[x] = root;     } else       parent[xroot] = yroot;   }   int main() {     int n, temp[200005], dsu[200005], k = 0, cnt = 0;     cin >> n;     for (int i = 1; i <= n; i++) parent[i] = i;     for (int i = 1; i <= n; i++) {       cin >> par[i];       temp[i] = par[i];       if (par[i] == i) root = i;     }     for (int i = 1; i <= n; i++) {       if (par[i] == i) {         if (i == root) {         } else           par[i] = root;       } else         merge(i, par[i]);     }     for (int i = 1; i <= n; i++)       if (temp[i] != par[i]) cnt++;     cout << cnt <<   n ;     for (int i = 1; i <= n; i++) cout << par[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pr(vector<T> &v) {     for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ;     cout <<   n ;     ;   }   template <typename T>   void pr(vector<vector<T>> &v) {     for (int i = 0; i < (int)(v).size(); i++) {       pr(v[i]);     }   }   template <typename T>   void re(T &x) {     cin >> x;   }   template <typename T>   void re(vector<T> &a) {     for (int i = 0; i < (int)(a).size(); i++) re(a[i]);   }   template <class Arg, class... Args>   void re(Arg &first, Args &...rest) {     re(first);     re(rest...);   }   template <typename T>   void pr(T x) {     cout << x <<   n ;     ;   }   template <class Arg, class... Args>   void pr(const Arg &first, const Args &...rest) {     cout << first <<    ;     pr(rest...);     cout <<   n ;     ;   }   void ps() {     cout <<   n ;     ;   }   template <class T, class... Ts>   void ps(const T &t, const Ts &...ts) {     cout << t;     if (sizeof...(ts)) cout <<    ;     ps(ts...);   }   const long long MOD = 998244353;   long double PI = 4 * atan(1);   long double eps = 1e-12;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, A, cf, cm, m;     cin >> n >> A >> cf >> cm >> m;     vector<pair<long long, int>> a(n + 1);     for (int i = 1; i < n + 1; i++) {       cin >> a[i].first;       a[i].second = i;     }     vector<long long> pre(n + 1);     vector<long long> pre2(n + 1);     sort(a.begin(), a.end());     vector<long long> ac(n);     long long minv = MOD;     for (int i = 0; i < n; i++) {       ac[i] = a[i + 1].first;       minv = min(minv, ac[i]);     }     pre[0] = 0;     pre2[0] = 0;     for (int i = 1; i < n + 1; i++) {       pre[i] = a[n - i + 1].first + pre[i - 1];       pre2[i] = a[i].first + pre2[i - 1];     }     long long ans = cm * minv;     long long ind = 0;     long long besti = 0;     long long bestm = 0;     for (int i = 0; i < n + 1; i++) {       long long cost = (i)*A - pre[i];       if (cost > m) {         break;       }       long long lo = 0;       long long hi = A;       while (lo != hi) {         long long mid = (lo + hi + 1) / 2;         vector<long long>::iterator high =             upper_bound(ac.begin(), ac.begin() + n - i, mid);         long long ntm = high - ac.begin();         long long cost2 = cost + (mid * ntm - pre2[ntm]);         if (cost2 <= m) {           if (i * cf + cm * mid > ans) {             ans = i * cf + cm * mid;             besti = i;             bestm = mid;           }           lo = mid;         } else {           hi = mid - 1;         }       }     }     for (int i = 0; i < besti; i++) {       a[n - i].first = A;     }     for (int i = 1; i < n + 1; i++) {       if (a[i].first < bestm) a[i].first = bestm;     }     vector<long long> out(n + 1);     for (int i = 1; i < n + 1; i++) {       out[a[i].second] = a[i].first;     }     cout << ans <<   n ;     ;     for (int i = 1; i < n + 1; i++) {       cout << out[i] <<    ;     }     cout <<   n ;     ;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 105;   const int N = 200;   int f[maxn][maxn][maxn];   int g[maxn][maxn][maxn];   bool usedf[maxn][maxn];   bool usedg[maxn][maxn];   int n, m, K, ans, c[N + 5][N + 5];   int main() {     scanf( %d %d %d , &n, &m, &K);     if (K == 0) {       puts( 0 );       return 0;     }     for (int i = 0; i <= N; i++) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++)           if (usedg[j][k]) memset(g[j][k], 0, sizeof(g[j][k]));       memset(usedg, 0, sizeof usedg);       for (int t = 1; t <= n; t++) usedg[t][1] = true, g[t][1][t] = 1;       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++)           if (usedf[j][k]) {             for (int l = 1; l <= n; l++)               if (int val = f[j][k][l]) {                 int tmp;                 for (int t = l; t <= n - j; t++)                   if (c[t - 1][l - 1] <= K && (tmp = k * c[t - 1][l - 1]) <= K)                     (g[j + t][tmp][t - l] += val) %= mod,                         usedg[j + t][tmp] = true;               }           }       swap(f, g);       swap(usedf, usedg);       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++) (ans += f[j][k][0]) %= mod;     }     printf( %d , ans);     return 0;   }