malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[200], t[200];   int cnt[200], cnt2[200];   int check(int p, char t[]) {     int i;     for (i = 0; i < 26; i++) {       cnt2[i] = 0;     }     for (i = p; i < p + n; i++) {       cnt2[t[i] -  a ]++;     }     for (i = 0; i < 26; i++) {       if (cnt[i] != cnt2[i]) return 0;     }     return 1;   }   int main() {     int T, flag, i;     scanf( %d , &T);     while (T--) {       flag = 0;       scanf( %s%s , s, t);       n = strlen(s);       m = strlen(t);       for (i = 0; i < 26; i++) {         cnt[i] = 0;       }       for (i = 0; i < n; i++) {         cnt[s[i] -  a ]++;       }       for (i = 0; i <= m - n; i++) {         if (check(i, t)) {           flag = 1;           break;         }       }       if (flag) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct node {     long long k[51][51];   } a, ans;   long long t, n, m, q, op, x, y, z, s = 1, mp[26][26];   inline long long read() {     long long sum = 0, x = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       sum = sum * 10 + ch -  0 ;       ch = getchar();     }     return sum * x;   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   inline node mul(node a, node b) {     node c;     memset(c.k, 0, sizeof(c.k));     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j)         for (register long long p = 1; p <= t; p++)           c.k[i][j] = (c.k[i][j] + a.k[i][p] * b.k[p][j]) % mod;     return c;   }   inline void power(long long b) {     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ans = mul(a, ans);   }   inline void build() {     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j) {         long long aa = ((i - 1) / m) + 1, bb = (i - 1) % m + 1,                   A = ((j - 1) / m) + 1, B = (j - 1) % m + 1;         if (mp[aa][bb] == 0 && mp[A][B] == 0 && abs(A - aa) + abs(B - bb) <= 1)           a.k[i][j] = 1;         else           a.k[i][j] = 0;       }   }   signed main() {     n = read();     m = read();     q = read();     t = n * m;     ans.k[1][1] = 1;     while (q--) {       build();       op = read();       x = read();       y = read();       z = read();       power(z - s);       s = z;       if (op == 2 || op == 3) ans.k[(x - 1) * m + y][1] = 0;       if (op == 2) mp[x][y] = 1;       if (op == 3) mp[x][y] = 0;       if (op == 1) {         write(ans.k[(x - 1) * m + y][1]);         putchar(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long exp) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base);       base = (base * base);       exp /= 2;     }     return res;   }   long long mod(long long a, long long b) { return (a % b + b) % b; }   long long powerm(long long base, long long exp, long long mod) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return ans;   }   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     t = 1;     while (t--) {       string s;       cin >> s;       cout << s;       for (long long i = s.size() - 1; i >= 0; i--) cout << s[i];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 1024 * 1024;   int n;   int k;   int v[MXN];   int c[MXN];   int p[MXN];   pair<int, int> vstk[MXN];   pair<int, int> cstk[MXN];   int vn, cn;   static pair<int, int> getxy(int iv) {     int p1 = vstk[iv].first;     auto cx =         lower_bound(cstk, cstk + cn, p1,                     [](const pair<int, int>& a, int b) { return a.first > b; });     return {vstk[iv].second, cx->second};   }   static void calcP() {     vn = 0;     cn = 0;     for (int i = n - 1; i >= 0; i--) {       while (vn > 0 && vstk[vn - 1].second <= v[i]) vn--;       vstk[vn++] = pair<int, int>(i, v[i]);       while (cn > 0 && cstk[cn - 1].second >= c[i]) cn--;       cstk[cn++] = pair<int, int>(i, c[i]);       int l = 0, r = vn - 1;       while (l < r) {         int m = (l + r) / 2;         pair<int, int> xy = getxy(m);         if (xy.first < xy.second)           r = m;         else           l = m + 1;       }       pair<int, int> a1 = getxy(l);       int tans = min(a1.first, a1.second);       if (l > 0) {         a1 = getxy(l - 1);         tans = max(tans, min(a1.first, a1.second));       }       p[i] = tans;     }   }   static double solve() {     for (int i = 0; i < n; i++) v[i] *= 100;     calcP();     sort(p, p + n);     double prb = double(k) / n;     double ans = p[0] * prb;     for (int i = 1; i < n && n - k - i + 1 >= 0; i++) {       prb *= n - k - i + 1;       prb /= (n - i);       ans += p[i] * prb;     }     return ans;   }   int main() {     while (scanf( %d %d , &n, &k) == 2) {       for (int i = 0; i < n; i++) scanf( %d , v + i);       for (int i = 0; i < n; i++) scanf( %d , c + i);       double ans = solve();       printf( %.7f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int *input = new int[n];     for (int i = 0; i < n; i++) cin >> input[i];     sort(input, input + n);     int over = input[n - 1] + 1;     int ans = 1;     for (int i = n - 2; i >= 0; i--) {       if (input[i] + 1 < over) {         over = input[i] + 1;         ans++;       } else if (input[i] < over) {         over = input[i];         ans++;       } else if (input[i] - 1 > 0 && input[i] - 1 < over) {         over = input[i] - 1;         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<string, string>, int> m, m1;   vector<pair<string, string> > ans;   int main() {     string s1, s2;     int n, t, i, d, j;     scanf( %d%d , &n, &d);     for (i = 1; i <= n; i++) {       cin >> s1 >> s2 >> t;       for (j = 0; j < ans.size(); j++)         if ((ans[j].first == s1 && ans[j].second == s2) ||             (ans[j].first == s2 && ans[j].second == s1))           break;       if (j != int(ans.size())) continue;       t++;       if ((m[make_pair(s2, s1)] != 0 && t - m[make_pair(s2, s1)] <= d &&            t - m[make_pair(s2, s1)] > 0) ||           (m1[make_pair(s2, s1)] != 0 && t - m1[make_pair(s2, s1)] <= d &&            t - m1[make_pair(s2, s1)] > 0))         ans.push_back(make_pair(s1, s2));       if (m[make_pair(s1, s2)] != t) m1[make_pair(s1, s2)] = m[make_pair(s1, s2)];       m[make_pair(s1, s2)] = t;     }     printf( %d , int(ans.size()));     for (i = 0; i < ans.size(); i++)       cout << endl << ans[i].first <<     << ans[i].second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   void bugp(const pair<T, V> &x) {     cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl;   }   template <typename T, typename U, typename V>   void bugpp(const pair<T, pair<U, V> > &x) {     cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second          <<  }}  << endl;   }   template <typename T>   bool maximize(T &x, const T &y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   template <typename T>   bool minimize(T &x, const T &y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   const int N = 2002;   int n, C[N], A[N], subsz[N];   bool chk[N], answer = 1;   vector<int> child[N];   int getNext(int idx) {     int ans = -1;     for (int i = 1, _n = (n); i <= _n; ++i) {       if (!chk[i]) --idx;       if (!idx) {         ans = i;         break;       }     }     return ans;   }   void DFS(int u) {     subsz[u] = 1;     A[u] = getNext(C[u] + 1);     if (A[u] == -1)       answer = 0;     else       chk[A[u]] = 1;     for (int &v : child[u]) {       DFS(v);       subsz[u] += subsz[v];     }     if (C[u] >= subsz[u]) answer = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int root;     for (int i = 1, _n = (n); i <= _n; ++i) {       int p;       cin >> p >> C[i];       if (p)         child[p].push_back(i);       else         root = i;     }     DFS(root);     if (!answer)       cout <<  NO ;     else {       cout <<  YES n ;       for (int i = 1, _n = (n); i <= _n; ++i) cout << A[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace io {   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <class I>   inline void fr(I &num) {     num = 0;     register char c = nc();     register int p = 1;     while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = nc() : c = nc();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = nc();     num *= p;   }   template <class I>   inline I Max(I p, I q) {     return p > q ? p : q;   }   template <class I>   inline I Min(I p, I q) {     return p < q ? p : q;   }   template <class I>   inline I A(I x) {     return x < 0 ? -x : x;   }   template <class I>   inline void sp(I &p, I &q) {     I x = p;     p = q, q = x;   }   template <class I>   inline void ckMax(I &p, I q) {     p = (p > q ? p : q);   }   template <class I>   inline void ckMin(I &p, I q) {     p = (p < q ? p : q);   }   };  // namespace io   using io ::A;   using io ::ckMax;   using io ::ckMin;   using io ::fr;   using io ::Max;   using io ::Min;   using io ::nc;   using io ::sp;   const int N = 1000005;   map<pair<int, int>, int> mp;   int n, k, cn, d;   inline void gcd(const int a, const int b) {     return !b ? d = a, void() : gcd(b, a % b);   }   inline double dis(const int x, const int y) {     return sqrt(1.0 * x * x + 1.0 * y * y);   }   struct ky {     int x, y;     double ds;     bool operator<(const ky &p) const { return ds < p.ds; }   };   vector<ky> vec[N];   vector<double> o;   int main() {     scanf( %d%d , &n, &k);     const int kk = k >> 1;     register double ans = 0;     for (register int i = 1, x, y; i <= n; ++i) {       scanf( %d%d , &x, &y);       if ((!x) && (!y)) {         vec[++cn].push_back((ky){x, y, 0});         continue;       }       gcd(A(x), A(y));       pair<int, int> p = make_pair(x / d, y / d);       if (!mp[p]) mp[p] = ++cn;       vec[mp[p]].push_back((ky){x, y, dis(x, y)});     }     for (register int j = 1, i; j <= cn; ++j) {       const int sz = vec[j].size();       register int mn = Min(kk, sz);       std::sort(vec[j].begin(), vec[j].end());       for (i = 1; i <= mn; ++i)         o.push_back(vec[j][sz - i].ds * ((k - i) - (i - 1)));       double s = 0;       mn = Min(k, sz);       for (i = kk + 1; i <= mn; ++i)         o.push_back(vec[j][i - kk - 1].ds * ((k - kk - 1) - kk) - 2.0 * s),             s += vec[j][i - kk - 1].ds;     }     std::sort(o.begin(), o.end());     for (register int i = o.size() - 1; (~i) && k; --i) ans += o[i], --k;     printf( %.9lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<int> val[100010];   int x[100010];   int td[100010 * 4], ti[100010 * 4];   int queryd(int node, int lo, int hi, int l, int r) {     if (l > hi or r < lo) return 0;     if (lo >= l and hi <= r) return td[node];     int md = (lo + hi) >> 1;     int p1 = queryd(node << 1, lo, md, l, r);     int p2 = queryd(node << 1 | 1, md + 1, hi, l, r);     return max(p1, p2);   }   void updated(int node, int lo, int hi, int idx, int val) {     if (lo == hi) {       td[node] = max(td[node], val);       return;     }     int md = (lo + hi) >> 1;     if (idx <= md)       updated(node << 1, lo, md, idx, val);     else       updated(node << 1 | 1, md + 1, hi, idx, val);     td[node] = max(td[node << 1], td[node << 1 | 1]);   }   int queryi(int node, int lo, int hi, int l, int r) {     if (l > hi or r < lo) return 0;     if (lo >= l and hi <= r) return ti[node];     int md = (lo + hi) >> 1;     int p1 = queryi(node << 1, lo, md, l, r);     int p2 = queryi(node << 1 | 1, md + 1, hi, l, r);     return max(p1, p2);   }   void updatei(int node, int lo, int hi, int idx, int val) {     if (lo == hi) {       ti[node] = max(ti[node], val);       return;     }     int md = (lo + hi) >> 1;     if (idx <= md)       updatei(node << 1, lo, md, idx, val);     else       updatei(node << 1 | 1, md + 1, hi, idx, val);     ti[node] = max(ti[node << 1], ti[node << 1 | 1]);   }   int ai[100010], ad[100010], md[100010];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0, l, r; i < n; ++i) {       cin >> l >> r;       x[l]++;       x[r + 1]--;     }     for (int i = 1; i <= m; ++i) {       x[i] += x[i - 1];     }     for (int i = 1; i <= m; ++i) {       auto xz = queryi(1, 0, n, 0, x[i]);       ai[i] = xz + 1;       updatei(1, 0, n, x[i], xz + 1);     }     for (int i = m; i > 0; --i) {       auto xz = queryd(1, 0, n, 0, x[i]);       ad[i] = xz + 1;       updated(1, 0, n, x[i], xz + 1);     }     md[m] = ad[m];     int ans = 0;     for (int i = m - 1; i > 0; --i) {       md[i] = max(ad[i], md[i + 1]);     }     for (int i = 1; i < m; ++i) {       ans = max(ans, ai[i] + md[i + 1]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long Inf = 1e18;   const int N = 1010;   const int mod = 0;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   template <typename T>   bool chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   };   template <typename T>   bool chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   };   int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }   void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }   void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ;   }   template <typename T>   string to_string(T v) {     int fst = 1;     string ret =  { ;     for (auto x : v) {       if (!fst) ret +=  , ;       fst = 0, ret += to_string(x);     }     ret +=  } ;     return ret;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << to_string(H);     dbg_out(T...);   }   int n, m, c, a[N], h, t;   void print(int x) {     cout << x <<   n ;     fflush(stdout);   }   int place(int x) {     if (x <= c / 2) {       if (x >= a[h])         return ++h;       else {         int p = 1;         while (a[p] <= x) ++p;         return p;       }     } else {       if (x <= a[t])         return --t;       else {         int p = n;         while (a[p] >= x) --p;         return p;       }     }   }   int main() {     n = gi(), m = gi(), c = gi();     h = 0, t = n + 1;     a[t] = c + 1;     for (int i = 1; i <= m; i++) {       int x = gi(), pos = place(x);       print(pos);       a[pos] = x;       if (h + 1 == t) return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[60];   int n;   long long f[60][10];   int main() {     gets(s + 1);     n = strlen(s + 1);     for (int j = 0; j < 10; ++j) f[1][j] = 1;     for (int i = 1; i < n; ++i)       for (int j = 0; j < 10; ++j) {         int sum = j + s[i + 1] - 48;         if (sum & 1) {           f[i + 1][sum - 1 >> 1] += f[i][j];           f[i + 1][sum + 1 >> 1] += f[i][j];         } else           f[i + 1][sum >> 1] += f[i][j];       }     long long ans = 0;     for (int j = 0; j < 10; ++j) ans += f[n][j];     bool flag = true;     for (int i = 2; i <= n; ++i) {       int sum = s[i - 1] + s[i] - 48 * 2;       if (sum & 1) {         if ((sum - 1 >> 1) != s[i] - 48 && (sum + 1 >> 1) != s[i] - 48)           flag = false;       } else if ((sum >> 1) != s[i] - 48)         flag = false;     }     if (flag) --ans;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a[n];     long long m = 1e9;     long long sum = 0;     for (long long i = 0; i < n; ++i) cin >> a[i], m = min(m, a[i]), sum += a[i];     for (long long i = 0; i < n; ++i) {       if ((a[i] - m) % k != 0) {         cout << -1;         return 0;       }     }     long long l = sum - m * n;     cout << l / k;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   int ansa, ansb, ansc;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int main() {     a = read();     b = read();     c = read();     d = read();     if (c * 2 < d || d * 2 < c || a <= d || b <= d) {       printf( -1 );       return 0;     }     printf( %d n%d n%d , a * 2, b * 2, min(c * 2, d * 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = long double;   using pl = pair<ll, ll>;   using pi = pair<int, int>;   vector<pi> viz[100010];   pi p[100010];   double num[100010];   bool no;   set<int> val;   vector<int> in;   void dfs(int u) {     in.push_back(u);     for (auto x : viz[u]) {       int v = x.first, c = x.second;       if (p[v].first != 0) {         if (p[v].first != p[u].first) {           if ((p[v].second == c - p[u].second))             continue;           else             no = true;         }         if (p[v].first == p[u].first) {           val.insert((c - p[v].second - p[u].second) * p[v].first);         }       } else {         p[v].first = -p[u].first;         p[v].second = c - p[u].second;         dfs(v);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b, c;       cin >> a >> b >> c;       viz[a].push_back({b, c});       viz[b].push_back({a, c});     }     no = false;     for (int i = 1; i <= n; i++) {       if (p[i].first == 0) {         val.clear();         in.clear();         p[i] = {1, 0};         dfs(i);         if (val.size() > 1) no = true;         if (val.size() == 0) {           vector<int> fd;           for (auto x : in) fd.push_back(p[x].first * p[x].second);           sort(begin(fd), end(fd));           int c = -fd[fd.size() / 2];           for (auto x : in) num[x] = (double)p[x].first * c + p[x].second;         } else {           double c = (double)*val.begin() / 2;           for (auto x : in) num[x] = (double)p[x].first * c + p[x].second;         }       }     }     if (no)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << num[i] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, r;     cin >> n >> r;     if (r <= (n + 1) / 2) {       cout << (2 * r - 1) << endl;     } else {       r -= (n + 1) / 2;       cout << 2 * r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007, n, m, siz[100010], s[210][210], dp[100010][210],             f[210], sum[210];   vector<long long> g[100010];   void jia(long long &x, long long y) {     x += y;     if (x >= mod) x -= mod;   }   void dfs(long long x, long long fa) {     dp[x][0] = 2;     siz[x] = 1;     for (long long i = 0, v; i < g[x].size(); i++) {       v = g[x][i];       if (v == fa) continue;       dfs(v, x);       for (long long j = 0; j <= m; j++) f[j] = 0;       for (long long j = 0; j <= min(m, siz[x]); j++)         for (long long k = 0; k <= min(m - j, siz[v]); k++)           jia(f[j + k], dp[x][j] * dp[v][k] % mod);       for (long long j = 0; j <= m; j++) dp[x][j] = f[j];       for (long long j = 0; j <= m; j++) jia(sum[j], mod - dp[v][j]);       siz[x] += siz[v];     }     for (long long j = 0; j <= m; j++) jia(sum[j], dp[x][j]);     for (long long j = m; j >= 1; j--) jia(dp[x][j], dp[x][j - 1]);     jia(dp[x][1], mod - 1);   }   int main() {     scanf( %lld%lld , &n, &m);     for (long long u, v, i = 1; i < n; i++) {       scanf( %lld%lld , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     s[1][1] = 1;     for (long long i = 2; i <= m; i++)       for (long long j = 1; j <= i; j++)         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod;     dfs(1, 0);     long long ans = 0;     for (long long fac = 1, i = 1; i <= m; i++) {       fac = fac * i % mod;       jia(ans, fac * s[m][i] % mod * sum[i] % mod);     }     printf( %lld , ans);     return 0;   }