malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 10;   const int mod = 1e9 + 7;   const int AL = 9;   const int N = 5000;   const int INF = 1e9;   struct Trie {     int net[10000][12], fail[10000];     bool end[10000];     int root, L;     int newnode() {       for (int i = 0; i < AL; ++i) net[L][i] = -1;       end[L++] = false;       return L - 1;     }     void init() {       L = 0;       root = newnode();     }     void insert(char buf[]) {       int len = strlen(buf);       int now = root;       for (int i = 0; i < len; ++i) {         if (net[now][buf[i] -  1 ] == -1) net[now][buf[i] -  1 ] = newnode();         now = net[now][buf[i] -  1 ];       }       end[now] = true;     }     void build() {       queue<int> Q;       fail[root] = root;       for (int i = 0; i < AL; ++i)         if (net[root][i] == -1)           net[root][i] = root;         else {           fail[net[root][i]] = root;           Q.push(net[root][i]);         }       while (!Q.empty()) {         int now = Q.front();         Q.pop();         if (end[fail[now]]) end[now] = true;         for (int i = 0; i < AL; ++i) {           if (net[now][i] == -1)             net[now][i] = net[fail[now]][i];           else {             fail[net[now][i]] = net[fail[now]][i];             Q.push(net[now][i]);           }         }       }     }   } ac;   char ch[1010];   char cp[30];   int x;   int f[30];   void dfs(int num, int le) {     if (x < num) return;     if (x == num) {       f[0] = 0;       for (int i = (1); i < (le + 1); ++i) f[i] = f[i - 1] + cp[i - 1] -  0 ;       for (int i = (1); i < (le + 1); ++i)         for (int j = (i); j < (le + 1 - (i == 1)); ++j) {           if (f[le] % (f[j] - f[i - 1]) == 0) {             return;           }         }       ac.insert(cp);       return;     }     for (int i = (1); i < (10); ++i) {       cp[le] =  0  + i;       dfs(num + i, le + 1);       cp[le] =   0 ;     }   }   int main() {     scanf( %s , ch);     scanf( %d , &x);     ac.init();     dfs(0, 0);     ac.build();     int len = strlen(ch);     vector<vector<int> > dp(len + 1, vector<int>(ac.L, INF));     dp[0][0] = 0;     for (int i = (0); i < (len); ++i)       for (int j = (0); j < (ac.L); ++j)         if (dp[i][j] != INF) {           dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);           int nxt = ac.net[j][ch[i] -  1 ];           if (!ac.end[nxt]) dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j]);         }     printf( %d n , *min_element((dp[len]).begin(), (dp[len]).end()));     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   inline int qpow(int a, int n) {     int ans = 1;     while (n) {       if (n & 1) {         ans *= a;       }       a *= a;       n >>= 1;     }     return ans;   }   inline long long _qpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   inline long long ksm(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   const int maxnum = 1e6 + 5;   const int MAXN = (1 << 13) - 1;   set<int> st[maxnum];   int n;   int x;   int f[MAXN + 5];   void slove() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       st[x].insert(i);     }     for (int i = 0; i <= MAXN; i++) f[i] = 0x3f3f3f3f;     f[0] = 0;     for (int i = 0; i <= MAXN; i++) {       for (int j = MAXN; j >= 0; j--) {         auto it = st[i].upper_bound(f[j]);         if (it != st[i].end()) {           f[i ^ j] = min(f[i ^ j], *it);         }       }     }     vector<int> ans;     for (int i = 0; i <= MAXN; i++) {       if (f[i] != 0x3f3f3f3f) ans.push_back(i);     }     cout << ans.size() <<   n ;     for (int x : ans) cout << x <<    ;     cout <<   n ;   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     slove();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T a) {     return a < 0 ? -a : a;   }   template <typename T>   T sqr(T a) {     return a * a;   }   const int INF = (int)1e9;   const long double EPS = 1e-9;   const long double PI = 3.1415926535897932384626433832795;   long double a, b, h;   inline pair<long double, long double> rotate(       const pair<long double, long double>& a, const long double& ang) {     return pair<long double, long double>(         a.first * cos(ang) + a.second * sin(ang),         -a.first * sin(ang) + a.second * cos(ang));   }   inline long double dist(const long double& w, const long double& h,                           const long double& ang) {     pair<long double, long double> pa(w * cos(ang), 0);     pair<long double, long double> push_back(0, w * sin(ang));     pair<long double, long double> v =         rotate(pair<long double, long double>(h, 0), ang - PI / 2);     pa.first += v.first;     pa.second += v.second;     push_back.first += v.first;     push_back.second += v.second;     long double A, B, C;     A = push_back.second - pa.second;     B = pa.first - push_back.first;     C = -A * pa.first - B * pa.second;     return (A * b + B * a + C) / sqrtl(A * A + B * B);   }   inline long double findMaxAng(const long double& w, const long double& h) {     long double lf = 0;     long double rg = PI / 2;     for (int i = 0; i < int(100); ++i) {       long double mid = lf + (rg - lf) / 2;       if (w * cos(mid) + h * sin(mid) > b)         lf = mid;       else         rg = mid;     }     return lf;   }   inline bool check(const long double& w, const long double& h) {     if (a + EPS < h) return false;     if (w <= b + EPS) return true;     long double lf = 0;     long double rg = findMaxAng(w, h);     for (int i = 0; i < int(200); ++i) {       long double d = (rg - lf) / 3;       long double ml = lf + d;       long double mr = rg - d;       if (dist(w, h, ml) > dist(w, h, mr))         lf = ml;       else         rg = mr;     }     return dist(w, h, lf) > -EPS;   }   int main() {     cin >> a >> b >> h;     long double lf = 0;     long double rg = h;     for (int i = 0; i < int(100); ++i) {       long double mid = lf + ((rg - lf) / 2);       if (check(h, mid) || check(mid, h))         lf = mid;       else         rg = mid;     }     if (lf < EPS) {       puts( My poor head =( );     } else {       cout.precision(10);       cout << fixed << lf << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_set<string> was;   int n, i, j, pos, k = 13, t;   string codes[1001];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (; i < n; ++i) cin >> codes[i];     for (i = 0; i < n; ++i)       for (j = i + 1; j < n; ++j) {         t = 0;         for (pos = 0; pos < 6; ++pos) t += codes[i][pos] != codes[j][pos];         k = min(k, t);       }     cout << (k - 1) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int maxi = -1000000050;     int f, t;     int loli = -1000000050;     for (int i = 0; i < n; i++) {       cin >> f >> t;       if (t > k) {         loli = f - (t - k);       } else         loli = f;       if (loli > maxi) maxi = loli;     }     cout << maxi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, s, cntlog2[2050] = {0};   int main() {     scanf( %d , &q);     while (q--) {       memset(cntlog2, 0, sizeof(cntlog2));       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d , &s);         if (s <= 2048) cntlog2[s]++;       }       for (int i = 1; i < 2048; i++) {         while (cntlog2[i] >= 2) {           cntlog2[i] -= 2;           cntlog2[2 * i]++;         }       }       if (cntlog2[2048]) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct FenwickTree {     vector<long long int> bit;     int n;     FenwickTree(int n) {       this->n = n;       bit.assign(n, 0);     }     FenwickTree(vector<long long int> a) : FenwickTree(a.size()) {       for (size_t i = 0; i < a.size(); i++) add(i, a[i]);     }     long long int sum(int r) {       long long int ret = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];       return ret;     }     long long int sum(int l, int r) { return sum(r) - sum(l - 1); }     void add(int idx, long long int delta) {       for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta;     }   };   const int MAX_VAL = 3e5;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<long long int> a(n);     vector<long long int> ra(MAX_VAL + 5, -1);     for (int i = 0; i < n; ++i) {       cin >> a[i];       ra[a[i]] = i;     }     vector<long long int> tr(n);     vector<long long int> ctr(MAX_VAL + 5);     int cidx = 0;     for (int i = 1; i <= MAX_VAL; ++i) {       if (ra[i] != -1) {         tr[ra[i]] = cidx;         cidx++;       }       ctr[i] = cidx - 1;     }     long long int csum = 0;     long long int tsum = 0;     FenwickTree fw(n);     FenwickTree fw2(n);     for (int i = 0; i < n; ++i) {       csum += tsum + a[i] * fw2.sum(tr[i]);       for (long long int k = 1; k * k <= a[i]; ++k) {         csum -= fw.sum(ctr[a[i] / k]);         if (a[i] / k > k) {           csum -= (a[i] / k - a[i] / (k + 1)) * fw.sum(ctr[k]);         }       }       for (long long int k = 2; k * a[i] <= MAX_VAL; ++k) {         csum -= a[i] * (i - fw2.sum(ctr[k * a[i] - 1]));       }       cout << csum <<    ;       tsum += a[i];       fw.add(tr[i], a[i]);       fw2.add(tr[i], 1);     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n;     cin >> n;     long long int ar[n + 1];     for (long long int i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n, greater<long long int>());     vector<long long int> v, ans;     for (long long int i = 0; i < n; i++) {       v.push_back(ar[i]);     }     ans.push_back(v[0]);     for (long long int i = 1; i < v.size(); i++) {       long long int p = v[i];       while (p >= 0) {         if (find(ans.begin(), ans.end(), p) != ans.end()) {           p--;         } else {           ans.push_back(p);           break;         }       }     }     long long int cnt = 0;     for (long long int i = 0; i < ans.size(); i++) cnt += ans[i];     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans[100], len, a, cur;   int main() {     cur = 1;     cin >> n;     for (int i = 0; i < (n); ++i) {       cin >> a;       if (a == cur) {         ans[len++] = 2001 + i;         cur++;       }     }     cout << len << endl;     for (int i = 0; i < (len); ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 0.000000000000000000001;   using namespace std;   vector<pair<int, int> > W;   int T[200005];   int s, l, last = -1;   bool czy = 0;   vector<int> R;   void make_move(int r) {     R.push_back(s);     if (r == 0) {       last = s;       auto x = upper_bound(W.begin(), W.end(), make_pair(W[s].first + l, inf)) -                W.begin() - 1;       l -= W[x].first - W[s].first;       s = x;     } else {       auto x = lower_bound(W.begin(), W.end(), make_pair(W[s].first - l, -inf)) -                W.begin();       long long d = W[s].first - W[x].first;       l -= d;       if (s == x) {         czy = 1;         return;       }       s = x;       if (s == last) l = l % (d * 2);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       W.push_back(make_pair(a, i));     }     sort(W.begin(), W.end());     for (int i = 0; i < W.size(); i++) T[W[i].second] = i;     for (int i = 1; i <= q; i++) {       cin >> s >> l;       s = T[s];       while (!czy) {         make_move(0);         make_move(1);       }       czy = 0;       last = -1;       cout << W[s].second <<   n ;       R.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<string, int>, vector<pair<string, int> > > edg;   queue<string> que;   map<string, int> num, por;   set<string> sett;   int main() {     int n, i, k, l, r, a, b, j;     cin >> n;     string s, t, S;     for (i = 0; i < n; i++) {       cin >> s >> a;       if (!i) {         que.push(s);         num[s] = a;         S = s;         por[s] = 1;       }       cin >> k;       for (j = 0; j < k; j++) {         cin >> t >> b;         edg[{s, a}].push_back({t, b});       }     }     pair<string, int> st;     while (!que.empty()) {       sett.insert(que.front());       st.first = que.front();       st.second = num[st.first];       que.pop();       for (i = 0; i < edg[st].size(); i++) {         if (!num.count(edg[st][i].first)) {           num[edg[st][i].first] = edg[st][i].second;           por[edg[st][i].first] = por[st.first] + 1;           que.push(edg[st][i].first);         } else {           if (por[st.first] + 1 == por[edg[st][i].first] &&               edg[st][i].second > num[edg[st][i].first]) {             num[edg[st][i].first] = edg[st][i].second;           }         }       }     }     sett.erase(S);     cout << sett.size() <<   n ;     for (auto j : sett) {       cout << j <<     << num[j] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int q = 1; q <= t; q++) {       int n;       int k;       cin >> n >> k;       long long a[n * k + 10];       long long ans = 0;       for (int i = 1; i <= n * k; i++) cin >> a[i];       int ind = n * k - n / 2;       int cnt = n / 2 + 1;       int col = 0;       while (ind > col) {         ans += a[ind];         ind -= cnt;         if (ind > 0) col += n - cnt;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], vis[100005], b[100005], h[100005], g[100005];   int main() {     int n, m = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == i) {         g[a[i]] = ++m;         h[m] = i;       }     }     for (int i = 1; i <= n; i++) {       if (!g[a[i]]) {         cout << -1;         return 0;       }     }     cout << m << endl;     for (int i = 1; i <= n; i++) {       cout << g[a[i]] <<    ;     }     cout << endl;     for (int i = 1; i <= m; i++) cout << h[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ya, yb, a[100003], b[100003], l[100003], dp[2][100003], ans;   int main() {     cin >> n >> m >> ya >> yb;     ans = n;     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) scanf( %d , b + i);     b[0] = -998244353;     m++;     b[m] = 998244353;     m++;     for (int i = 0; i < m; i++) l[i] = 998244353;     for (int i = 0; i < n; i++) {       int j = lower_bound(b, b + m, a[i]) - b;       int d = min(a[i] - b[j - 1], b[j] - a[i]);       if (b[j] - a[i] > d ||           (a[i] - b[j - 1] == d && (l[j - 1] == 998244353 || l[j - 1] == d)))         j--;       if (l[j] == 998244353 || l[j] == d) ans--;       l[j] = min(l[j], d);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100010], b[100010];   int main() {     long long n, i, res1 = 0, res2 = 0, l1, l2, r1, r2, turn;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       cin >> b[i];     }     sort(a + 1, a + n + 1);     sort(b + 1, b + n + 1);     l1 = 1;     r1 = n;     l2 = 1;     r2 = n;     turn = 0;     while (l1 <= r1 || l2 <= r2) {       if (turn == 0) {         if (l1 <= r1 && l2 <= r2) {           if (a[r1] >= b[r2]) {             res1 += a[r1];             r1--;           } else {             r2--;           }         } else if (l1 <= r1) {           res1 += a[r1];           r1--;         } else {           r2--;         }       } else {         if (l1 <= r1 && l2 <= r2) {           if (a[r1] >= b[r2]) {             r1--;           } else {             res2 += b[r2];             r2--;           }         } else if (l1 <= r1) {           r1--;         } else {           res2 += b[r2];           r2--;         }       }       turn ^= 1;     }     cout << res1 - res2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     if (n > m) swap(n, m);     if (n == 1)       printf( %d n , m / 6 * 6 + 2 * max(m % 6 - 3, 0));     else if (n == 2) {       if (m == 2)         printf( 0 n );       else if (m == 3)         printf( 4 n );       else if (m == 7)         printf( 12 n );       else         printf( %lld n , 1LL * n * m);     } else       printf( %lld n , 1LL * n * m / 2 * 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   long long sumb, sumc;   int n, a[N], b[N], c[N], cnt[30];   bool check() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         if (a[i] & 1 << j) cnt[j]++;       }     }     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j < 30; j++) {         if (a[i] & 1 << j) sum += cnt[j] * (1 << j);       }       if (sum != b[i]) return 0;     }     return 1;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , b + i), sumb += b[i];     for (int i = 0; i < n; i++) scanf( %d , c + i), sumc += c[i];     for (int i = 0; i < n; i++) {       long long buf = b[i] + c[i] - (sumb + sumc) / 2 / n;       if ((sumb + sumc) % (2 * n) || buf % n) {         puts( -1 );         return 0;       }       a[i] = buf / n;     }     if (!check())       puts( -1 );     else {       for (int i = 0; i < n; i++) {         printf( %d%c , a[i],    n [i == n - 1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fx[] = {1, -1, 0, 0};   int fy[] = {0, 0, 1, -1};   const unsigned long long hs = 3797;   unsigned long long F[100005], H[100005], H2[15];   int H2_size[15];   unsigned long long seg(int x, int y) { return H[y] - F[y - x + 1] * H[x - 1]; }   int main() {     F[0] = 1;     for (int i = 1; i <= 100005; i++) F[i] = F[i - 1] * hs;     string str, p;     str =  . ;     cin >> p;     str = str + p;     H[0] = 0;     for (int i = 1; i <= str.size() - 1; i++) {       H[i] = H[i - 1] * hs + str[i];     }     int N;     cin >> N;     for (int k = 1; k <= N; k++) {       string st, pp;       st =  . ;       cin >> pp;       st = st + pp;       H2_size[k] = st.size() - 1;       H2[k] = 0;       for (int i = 1; i <= st.size() - 1; i++) {         H2[k] = H2[k] * hs + st[i];       }     }     int start = 0, cnt = 0, ans = 0, ans_pos = 0;     for (int i = 1; i <= str.size() - 1; i++) {       bool flag = false;       int new_pos = 0;       for (int k = 1; k <= N; k++) {         if (i - H2_size[k] >= start) {           if (seg(i - H2_size[k] + 1, i) == H2[k]) {             flag = true;             new_pos = max(new_pos, i - H2_size[k] + 1);           }         }       }       if (flag) {         if (cnt > ans) {           ans = cnt;           ans_pos = start;         }         cnt = cnt - (new_pos - start) + 1;         start = new_pos;         continue;       }       cnt++;     }     if (cnt > ans) {       ans = cnt;       ans_pos = start;     }     cout << ans <<     << ans_pos;   }
#include <bits/stdc++.h>   const int MAXN = 200 + 5;   char str[MAXN][MAXN];   int n, m;   namespace Flow {   const int MAXM = 2e5 + 5;   struct Edge {     int to, w, nxt;   } e[MAXM << 3];   int head[MAXM], cur[MAXM], cnt = 1;   int dep[MAXM];   int S, T, N;   inline void add(int u, int v, int w) {     e[++cnt] = (Edge){v, w, head[u]};     head[u] = cnt;     e[++cnt] = (Edge){u, 0, head[v]};     head[v] = cnt;   }   inline bool bfs() {     for (int i = 0; i <= N; ++i) cur[i] = head[i], dep[i] = 0;     std::queue<int> q;     q.push(S);     dep[S] = 1;     while (!q.empty()) {       int v = q.front();       q.pop();       for (int i = head[v]; i; i = e[i].nxt) {         if (e[i].w > 0 && !dep[e[i].to]) {           dep[e[i].to] = dep[v] + 1;           if (e[i].to == T) return true;           q.push(e[i].to);         }       }     }     return dep[T];   }   inline int dfs(int v, int flow = 1e9) {     if (v == T) return flow;     if (!flow) return 0;     int ans = 0;     for (int &i = cur[v]; i; i = e[i].nxt) {       if (e[i].w > 0 && dep[e[i].to] == dep[v] + 1) {         int t = dfs(e[i].to, std::min(flow, e[i].w));         if (t > 0) {           ans += t;           flow -= t;           e[i].w -= t;           e[i ^ 1].w += t;           if (!flow) break;         }       }     }     return ans;   }   inline int Dinic() {     int ans = 0, t = 0;     while (bfs())       while ((t = dfs(S))) ans += t;     return ans;   }   };  // namespace Flow   const int dx[] = {0, 0, 1, -1};   const int dy[] = {1, -1, 0, 0};   inline int id(int i, int j) { return (i - 1) * m + j; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , str[i] + 1);     Flow::T = Flow::N = n * m + 2;     Flow::S = n * m + 1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (str[i][j] ==  . ) continue;         int c1 = 0, c2 = 0;         for (int k = 0; k <= 3; ++k) {           int ii = i + dx[k], jj = j + dy[k];           if (ii >= 1 && ii <= n && jj >= 1 && jj <= m && str[ii][jj] ==  # ) {             Flow::add(id(i, j), id(ii, jj), 1);           } else {             if (k <= 1)               c1++;             else               c2++;           }         }         Flow::add(Flow::S, id(i, j), c1);         Flow::add(id(i, j), Flow::T, c2);       }     }     printf( %d n , Flow::Dinic() / 2);     return 0;   }