malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct str {     int q, cost;     str(int _q = 0, int _cost = 0) {       q = _q;       cost = _cost;     }     bool operator<(const str &two) const { return cost > two.cost; }   };   struct edge {     int u, v, cost;     edge(int _u = 0, int _v = 0, int _cost = 0) { u = _u, v = _v, cost = _cost; }   };   vector<str> adj[(100000 + 10)];   int n, m, s;   int len;   int u, v, cost;   int dis[(100000 + 10)];   vector<edge> all;   int main() {     cin >> n >> m >> s;     for (int i = 0; i < m; i++) {       cin >> u >> v >> cost;       all.push_back(edge(u, v, cost));       adj[u].push_back(str(v, cost));       adj[v].push_back(str(u, cost));     }     cin >> len;     for (int i = 1; i <= n; i++) dis[i] = 1000000000;     dis[s] = 0;     priority_queue<str> pq;     pq.push(str(s, 0));     while (!pq.empty()) {       str v = pq.top();       pq.pop();       int node = v.q;       for (int i = 0; i < adj[node].size(); i++) {         int u = adj[node][i].q;         int cost = adj[node][i].cost;         if (dis[node] + cost < dis[u]) {           dis[u] = dis[node] + cost;           pq.push(str(u, dis[u]));         }       }     }     int out = 0;     for (int i = 1; i <= n; i++)       if (dis[i] == len) out++;     int one, two;     for (int i = 0; i < all.size(); i++) {       u = all[i].u;       v = all[i].v;       cost = all[i].cost;       if (dis[u] < len && len < dis[u] + cost &&           cost - (len - dis[u]) + dis[v] > len)         out++;       if (dis[v] < len && len < dis[v] + cost &&           cost - (len - dis[v]) + dis[u] > len)         out++;       if (dis[v] < len && dis[u] < len && dis[u] + dis[v] + cost == 2 * len)         out++;     }     cout << out << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int d4x[4] = {1, 0, -1, 0};   int d4y[4] = {0, 1, 0, -1};   int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long oo = 1e18;   const long long maxN = 1e6;   const int N = 105;   long long a[N];   void solve() {     int n;     long long h;     cin >> n >> h;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     auto ok = [&](long long x) -> bool {       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (i < n)           ans += min(a[i + 1] - a[i], x);         else           ans += x;         if (ans >= h) return true;       }       return false;     };     long long L = 1, R = h, ans = 0;     while (L <= R) {       long long mid = (L + R) >> 1;       if (ok(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, ddd = 0;     cin >> tc;     while (tc--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[500005], sum[500005];   bool vis[100005];   map<long long int, long long int> hola;   map<pair<long long int, long long int>, long long int> con;   vector<pair<long long int, long long int>> conn;   int main() {     long long int n, maxi = INT_MIN;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> arr[i];       hola[arr[i]]++;     }     for (long long int i = 0; i < n; i++) {       if (hola[arr[i]] > maxi) maxi = hola[arr[i]];     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MAX = 5000;   const int MOD = 1000000007;   int C[MAX][MAX];   int CL[MAX];   int main() {     int n;     cin >> n;     C[0][0] = 1;     for (int i = (1); i < (n + 1); ++i) {       C[i][0] = 1;       for (int j = (1); j < (n + 1); ++j) {         C[i][j] = C[i - 1][j] + C[i - 1][j - 1];         if (C[i][j] >= MOD) C[i][j] -= MOD;       }     }     CL[0] = 1;     for (int i = (1); i < (n + 1); ++i) {       CL[i] = 0;       for (int j = (1); j < (i + 1); ++j) {         long long c = C[i - 1][j - 1];         c *= CL[i - j];         c %= MOD;         CL[i] += c;         if (CL[i] >= MOD) CL[i] -= MOD;       }     }     long long res = 0;     for (int i = (1); i < (n + 1); ++i) {       long long c = C[n][i];       int m = n - i;       c *= CL[m];       c %= MOD;       res += c;       if (res >= MOD) res -= MOD;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-8;   const int dx4[4] = {1, 0, 0, -1};   const int dy4[4] = {0, -1, 1, 0};   const int inf = 0x3f3f3f3f;   const int N = 2E5 + 7;   int tree[2][N];   int a[N], p[N];   int n;   long long k;   int lowbit(int x) { return x & (-x); }   void update(int o, int x, int delta) {     if (!o) x = n - x + 1;     for (int i = x; i <= n; i += lowbit(i)) tree[o][i] += delta;   }   int Hash(int x) { return lower_bound(p + 1, p + n + 1, x) - p; }   int Sum(int o, int x) {     if (!o) x = n - x + 1;     int res = 0;     for (int i = x; i >= 1; i -= lowbit(i)) res += tree[o][i];     return res;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i], p[i] = a[i];     sort(p + 1, p + n + 1);     long long total = 0;     for (int i = n; i >= 1; i--) {       int x = Hash(a[i]);       a[i] = x;       total += Sum(1, a[i] - 1);       update(1, a[i], 1);     }     int r = 1;     long long ans = 0;     for (int l = 1; l <= n; l++) {       total += Sum(0, a[l] + 1) + Sum(1, a[l] - 1);       update(0, a[l], 1);       while ((r <= l || total > k) && r <= n) {         total -= Sum(0, a[r] + 1) + Sum(1, a[r] - 1);         update(1, a[r], -1);         r++;       }       ans += n - r + 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 25, M = 300005;   int n, a[N][N];   long long f[M], g[N][M], d[N][M], dp[N][M];   map<long long, long long> mp;   string st;   inline int bp(int x) { return __builtin_popcount(x); }   void dfs(int p, int s, int x, long long m) {     if (s == n) {       long long w = 0;       for (int i = 0; i < (1 << n); i++) {         if ((n + bp(i)) & 1)           w -= d[x][i];         else           w += d[x][i];       }       mp[m] = w;       return;     }     if (s + p > n) return;     for (int i = 0; i < (1 << n); i++) d[x + 1][i] = d[x][i] * g[p][i];     dfs(p, s + p, x + 1, m * 10 + p);     dfs(p + 1, s, x, m);   }   long long ch(int x) {     vector<int> v;     int s = 0;     for (int i = 0; i < n; i++) {       if (x >> i & 1)         s++;       else {         v.push_back(s + 1);         s = 0;       }     }     sort(v.begin(), v.end());     long long y = 0;     for (auto i : v) y = y * 10 + i;     return y;   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> st;       for (int j = 0; j < n; j++) a[i][j] = (st[j] ==  1 );     }     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     for (int i = 1; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (dp[j][i]) {           g[bp(i)][i] += dp[j][i];           for (int k = 0; k < n; k++)             if (!(i >> k & 1) && a[j][k]) dp[k][i | (1 << k)] += dp[j][i];         }       }     }     for (int i = 1; i <= n; i++)       for (int j = 0; j < n; j++)         for (int s = 0; s < (1 << n); s++)           if (s >> j & 1) g[i][s] += g[i][s ^ (1 << j)];     for (int i = 0; i < (1 << n); i++) d[0][i] = 1;     dfs(1, 0, 0, 0);     for (int i = 0; i < (1 << (n - 1)); i++) f[i] = mp[ch(i)];     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < (1 << (n - 1)); j++)         if (!(j >> i & 1)) f[j] -= f[j ^ (1 << i)];     for (int i = 0; i < (1 << (n - 1)); i++) printf( %lld  , f[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[n], i, s = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       s = s + a[i];     }     if (s == 0)       printf( EASY n );     else       printf( HARD n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1000 + 10;   const int mod = 1e9 + 7;   int a[3][6];   int vis[100];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < 6; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       for (int k = 0; k < 6; k++) {         vis[a[i][k]] = 1;         for (int j = 0; j < n; j++) {           if (i == j) continue;           for (int l = 0; l < 6; l++) {             vis[a[i][k] * 10 + a[j][l]] = 1;           }         }       }     }     for (int i = 1; i < 100; i++) {       if (!vis[i]) {         cout << i - 1 << endl;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     cin >> tt;     while (tt--) {       string t, s, ans;       bool f = 0;       cin >> t;       long long n = t.size();       vector<long long> a(26), b(26), c(26);       for (long long i = n - 1; i >= 0; --i) {         if (a[t[i] -  a ] == 0) s = t[i] + s;         a[t[i] -  a ]++;       }       long long sz = 0;       for (long long i = 0; i < s.size(); ++i) {         if (a[s[i] -  a ] % (i + 1)) {           f = 1;           break;         }         b[s[i] -  a ] = a[s[i] -  a ] / (i + 1);         sz += b[s[i] -  a ];       }       if (!f) {         vector<string> st(sz);         long long id = 0;         for (long long i = 0; i < s.size(); ++i) {           st[i] = string(t, id, sz);           id += sz, sz -= b[s[i] -  a ];         }         ans = st[0];         for (long long i = 0; i < st.size() - 1; ++i) {           string cnt;           for (long long j = 0; j < st[i].size(); ++j) {             if (st[i][j] != s[i]) cnt = cnt + st[i][j];           }           if (cnt != st[i + 1]) {             f = 1;             break;           }         }       }       if (f)         cout << -1 <<   n ;       else         cout << ans <<     << s <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, q, a[int(2e5)], sz;   set<pair<int, int> > st;   int main() {     cin >> n >> k >> q;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       if (x == 1) {         st.insert(make_pair(a[y - 1], y));         sz++;         if (sz > k) {           st.erase(st.begin());           sz--;         }       } else {         if (st.find(make_pair(a[y - 1], y)) != st.end()) {           cout <<  YES n ;         } else {           cout <<  NO n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   double max(double a, double b) { return a > b ? a : b; }   double min(double a, double b) { return a < b ? a : b; }   long long modd(long long a) {     if (a < 0LL) return a * -1LL;     return a;   }   double modd(double a) {     if (a < 0.0) return a * -1.0;     return a;   }   long long modulo(long long a) { return a % 1000000007LL; }   long long power(long long k, long long p) {     if (p == 0) return 1LL;     long long P = power(k, p / 2LL);     P = (P * P) % 1000000007LL;     if (p % 2 == 1) P = (P * k) % 1000000007LL;     return P;   }   struct p_str {     long long val, idx;     char ch;   };   bool comp(p_str& a, p_str& b) { return a.val < b.val; }   void solve() {     string s;     cin >> s;     long long m;     cin >> m;     long long b[m];     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     long long cnt[26];     memset(cnt, 0, sizeof(cnt));     for (long long i = 0; i < s.length(); i++) {       cnt[s[i] -  a ]++;     }     char t[m];     long long i_cnt = 26;     while (1) {       bool f = 1;       long long mn_i = -1;       for (long long i = 0; i < m; i++) {         if (b[i] == 0) {           mn_i = i;           f = 0;           break;         }       }       if (f) {         break;       }       vector<long long> zero_pos;       for (long long i = 0; i < m; i++) {         if (b[i] == 0) {           zero_pos.push_back(i);         }       }       long long c = zero_pos.size();       i_cnt--;       while (i_cnt >= 0 && cnt[i_cnt] < c) {         i_cnt--;       }       for (long long i = 0; i < zero_pos.size(); i++) {         t[zero_pos[i]] = (char)(i_cnt +  a );       }       for (long long j = 0; j < zero_pos.size(); j++) {         long long pos = zero_pos[j];         for (long long i = 0; i < m; i++) {           if (b[i] > 0) {             b[i] -= modd(i - pos);           }         }         b[pos] = -1;       }     }     for (long long i = 0; i < m; i++) {       cout << t[i];     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};   int run(int x) {     if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))       return 1;     else       return 0;   }   int main() {     int y1, y2, m1, m2, d1, d2;     int i, j;     scanf( %d:%d:%d , &y1, &m1, &d1);     scanf( %d:%d:%d , &y2, &m2, &d2);     int t;     if (y1 > y2) {       t = y1;       y1 = y2;       y2 = t;       t = m1;       m1 = m2;       m2 = t;       t = d1;       d1 = d2;       d2 = t;     } else if (y1 == y2) {       if (m1 > m2) {         t = m1;         m1 = m2;         m2 = t;         t = d1;         d1 = d2;         d2 = t;       } else if (m1 == m2) {         if (d1 > d2) {           t = d1;           d1 = d2;           d2 = t;         }       }     }     int sum = 0;     for (i = y1 + 1; i < y2; i++) {       if (run(i))         sum += 366;       else         sum += 365;     }     int num = a[m1 - 1] + d1;     int num2 = a[m2 - 1] + d2;     if (y1 != y2) {       if (run(y1)) {         if (m1 > 2)           num = 365 - num;         else           num = 366 - num;       } else         num = 365 - num;       if (run(y2)) {         if (m2 > 2) num2++;       }       sum += num;       sum += num2;     } else {       if (run(y1))         if (m1 > 2) num++;       if (run(y2))         if (m2 > 2) num2++;       sum += num2 - num;     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     char a[8][8];     int i, j, c = 0, k, d = 0, e = 1, f = 0;     vector<int> v;     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         cin >> a[i][j];       }     }     for (i = 0; i < 8; i++) {       d = 0;       for (j = 0; j < 8; j++) {         if (a[i][j] ==  W ) {           d++;         }       }       if (d == 0) {         c++;       } else if (d < 8 && d >= 1 && e == 1) {         for (j = 0; j < 8; j++) {           if (a[i][j] ==  B ) {             v.push_back(j);             c++;           }         }         e++;       } else if (e > 1) {         for (j = 0; j < 8; j++) {           if (a[i][j] ==  B ) {             for (k = 0; k < v.size(); k++) {               if (v[k] == j) {                 f = 1;                 break;               }             }             if (f == 0) {               v.push_back(j);               c++;             } else               f = 0;           }         }       }     }     cout << c << endl;     return;   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   int cho[30];   char str[1005];   int main() {     int a, b, ans = 0;     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> str[i];       cho[str[i] - 96]++;     }     int tot = b;     for (int i = 1; i <= 26; i++) {       if (tot == 0) {         break;       } else if (tot != 0 && cho[i] >= 1) {         if (cho[i - 1] != -1) {           ans += i;           tot--;           cho[i] = -1;         }       }     }     if (tot == 0)       cout << ans << endl;     else if (tot > 0)       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans, tot;   int b[200010], rt[200010];   struct nu {     int val, id;   } a[200010];   char s[200010];   struct node {     int ls, rs, sum;   } tree[200010 * 20];   inline bool cmp(const nu &x, const nu &y) {     if (x.val == y.val)       return x.id < y.id;     else       return x.val > y.val;   }   inline void insert(int num, int &x, int l, int r) {     tree[++tot] = tree[x];     x = tot;     ++tree[x].sum;     if (l == r) return;     int mid = (l + r) >> 1;     if (num <= mid)       insert(num, tree[x].ls, l, mid);     else       insert(num, tree[x].rs, mid + 1, r);   }   inline void prework() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &a[i].val), a[i].id = i, b[i] = a[i].val;     sort(a + 1, a + 1 + n, cmp);     tot = 0;     for (int i = 1; i <= n; i++) {       rt[i] = rt[i - 1];       insert(a[i].id, rt[i], 1, n);     }   }   inline int query(int i, int j, int k, int l, int r) {     if (l == r) return l;     int tp = tree[tree[j].ls].sum - tree[tree[i].ls].sum;     int mid = (l + r) >> 1;     if (k <= tp)       return query(tree[i].ls, tree[j].ls, k, l, mid);     else       return query(tree[i].rs, tree[j].rs, k - tp, mid + 1, r);   }   inline void mainwork() {     scanf( %d , &m);     int k, pos;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &k, &pos);       ans = query(rt[0], rt[k], pos, 1, n);       printf( %d n , b[ans]);     }   }   inline void print() {}   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       prework();       mainwork();       print();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100010], b[100010];   int main() {     int t;     cin >> t;     while (t--) {       int n;       int flag = 1;       long long min = 1e9 + 1;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         if (min > a[i]) min = a[i];       }       sort(b, b + n);       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) {           if (a[i] % min != 0) {             flag = 0;             break;           }         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     set<int> set;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int put;       scanf( %d , &put);       set.insert(put);     }     vector<int> arr(set.size());     copy(set.begin(), set.end(), arr.begin());     sort(arr.begin(), arr.end());     int consq = 0;     int iter = arr.size();     for (int i = 1; i < iter; i++) {       if (arr[i - 1] == arr[i] - 1) {         consq++;       } else {         consq = 0;       }       if (consq == 2) {         printf( YES n );         return 0;       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _ {     int a, b, c, d, id;     bool operator<(const _ &ob) const { return b < ob.b; }   } a[200010];   struct __ {     int val, id;     bool operator<(const __ &ob) const { return val < ob.val; }   };   struct event {     int x, y, depth, id;   };   queue<event> q;   set<int> ss;   multiset<__> s[200010];   _ min_[800010];   int val[200010], tx, ty, n, anss[200010], ans;   int fa[200010];   void pushup(int rt) { min_[rt] = min(min_[rt << 1], min_[rt << 1 | 1]); }   void update(_ tar, int l, int r, int rt) {     if (l == r) {       min_[rt] = tar;       return;     }     int m = l + r >> 1;     if (tar.a <= m)       update(tar, l, m, rt << 1);     else       update(tar, m + 1, r, rt << 1 | 1);     pushup(rt);   }   _ query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) return min_[rt];     int m = l + r >> 1;     _ ans;     ans.b = 1234567890;     if (m >= L) ans = min(ans, query(L, R, l, m, rt << 1));     if (m < R) ans = min(ans, query(L, R, m + 1, r, rt << 1 | 1));     return ans;   }   void bfs(int x, int y, int depth, int id) {     if (id == n) {       ans = depth;       anss[depth] = id;       return;     }     _ t = query(1, x, 1, n << 1, 1);     while (t.b <= y) {       s[t.a].erase(s[t.a].begin());       if (s[t.a].empty())         update((_){t.a, 1234567890, 0, 0, 0}, 1, n << 1, 1);       else         update(a[s[t.a].begin()->id - 1], 1, n << 1, 1);       q.push((event){t.c, t.d, depth + 1, t.id});       fa[t.id] = id;       t = query(1, x, 1, n << 1, 1);     }   }   void bbfs(int x, int y, int depth, int id) {     q.push((event){x, y, depth, id});     event t;     while (!q.empty()) {       t = q.front();       q.pop();       bfs(t.x, t.y, t.depth, t.id);       if (ans) return;     }   }   int main() {     memset(min_, 63, sizeof(min_));     memset(val, 63, sizeof(val));     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) {       scanf( %d%d%d%d , &a[i].a, &a[i].b, &a[i].c, &a[i].d);       ss.insert(a[i].a);       ss.insert(a[i].c);     }     set<int>::iterator it;     for (it = ss.begin(), i = 1; it != ss.end(); it++, i++) {       val[i] = *it;     }     for (i = 0; i < n; i++) {       a[i].a = lower_bound(val + 1, val + 1 + (n << 1), a[i].a) - val;       a[i].c = lower_bound(val + 1, val + 1 + (n << 1), a[i].c) - val;       a[i].id = i + 1;     }     tx = a[n - 1].c;     ty = a[n - 1].d;     if (*ss.begin()) {       printf( -1 n );       return 0;     }     int t;     for (i = 0; i < n; i++) {       t = query(a[i].a, a[i].a, 1, n << 1, 1).b;       if (a[i].b < t) update(a[i], 1, n << 1, 1);       s[a[i].a].insert((__){a[i].b, i + 1});     }     bbfs(1, 0, 0, -1);     if (!ans)       printf( -1 n );     else {       for (i = ans; i; i--) {         anss[i - 1] = fa[anss[i]];       }       printf( %d n , ans);       for (i = 1; i <= ans; i++) {         printf( %d  , anss[i]);       }       printf(  n );     }     return 0;   }