malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   const long long int MOD = 1000000007;   const long long int MAXN = 1000005;   const long long int INF = 100000000000005;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n), pos, neg;     for (long long int i = 0; i < n; ++i) cin >> a[i];     long long int ans = 1;     if (n == 5) {       for (long long int i = 0; i < n; ++i) {         ans = ans * a[i];       }       cout << ans << endl;       return;     }     for (auto itr : a) {       if (itr < 0) {         neg.push_back(itr);       } else {         pos.push_back(itr);       }     }     if (pos.size() == 0 and neg.size() == 0) {       ans = 0;     } else if (pos.size() == 0) {       sort(neg.begin(), neg.end());       reverse(neg.begin(), neg.end());       if (neg.size() < 5) {         ans = 0;       } else {         for (long long int i = 0; i < 5; ++i) {           ans = ans * neg[i];         }       }     } else if (neg.size() == 0) {       sort(pos.begin(), pos.end());       reverse(pos.begin(), pos.end());       if (pos.size() < 5) {         ans = 0;       } else {         for (long long int i = 0; i < 5; ++i) {           ans = ans * pos[i];         }       }     } else {       sort(pos.begin(), pos.end());       sort(neg.begin(), neg.end());       long long int si_pos = pos.size(), si_neg = neg.size(), res = -INF;       if (si_neg + si_pos < 5) {         ans = 0;       } else {         if (si_pos >= 5) {           res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] *                              pos[si_pos - 4] * pos[si_pos - 5]);         }         if (si_pos >= 3 and si_neg >= 2) {           res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] *                              neg[0] * neg[1]);         }         if (si_pos >= 1 and si_neg >= 4) {           res = max(res, pos[si_pos - 1] * neg[2] * neg[3] * neg[0] * neg[1]);         }         ans = res;       }     }     cout << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[200005];   int lis[200005];   int main() {     int n1, n2, n3;     cin >> n1 >> n2 >> n3;     for (int i = 1; i <= n1 + n2 + n3; i++) {       cin >> num[i];     }     sort(num + 1, num + 1 + n1);     sort(num + 1 + n1, num + 1 + n1 + n2);     sort(num + 1 + n1 + n2, num + 1 + n1 + n2 + n3);     int st = 1, et = 1;     lis[1] = num[1];     for (int i = 2; i <= n1 + n2 + n3; i++) {       int l = st, r = et;       if (num[i] >= lis[et]) {         et++;         lis[et] = num[i];         continue;       }       while (l < r) {         int mid = (l + r) >> 1;         if (lis[mid] < num[i]) {           l = mid + 1;         } else {           r = mid;         }       }       lis[l] = num[i];     }     cout << n1 + n2 + n3 - et << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       long long ans = 0;       for (int i = 0; i <= 8 && i <= n; i++) {         for (int j = 0; j <= (i == 0 ? 8 : 4) && i + j <= n; j++) {           ans += n + 1 - i - j;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, ar, b, fi;   int i, j, ans, o1[3000], o2[3000];   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b;     ar = a;     reverse(ar.begin(), ar.end());     for (; i < b.size(); ++i) {       if (a.find(b[i]) == string::npos) {         cout <<  -1 n ;         return 0;       }     }     for (i = 0; i < b.size();) {       for (j = 1; i + j <= b.length(); ++j) {         fi = b.substr(i, j);         if (a.find(fi) == string::npos && ar.find(fi) == string::npos) {           if (a.find(b.substr(i, j - 1)) == string::npos) {             o1[ans] = a.length() - ar.find(b.substr(i, j - 1));             o2[ans] = a.length() - ar.find(b.substr(i, j - 1)) - j + 2;           } else {             o1[ans] = a.find(b.substr(i, j - 1)) + 1;             o2[ans] = a.find(b.substr(i, j - 1)) + j - 1;           }           i += j - 1;           ++ans;           break;         } else if (i + j == b.length()) {           if (a.find(b.substr(i, j)) == string::npos) {             o1[ans] = a.length() - ar.find(b.substr(i, j));             o2[ans] = a.length() - ar.find(b.substr(i, j)) - j + 1;           } else {             o1[ans] = a.find(b.substr(i, j)) + 1;             o2[ans] = a.find(b.substr(i, j)) + j;           }           i += j;           ++ans;         }       }     }     cout << ans <<   n ;     for (i = 0; i < ans; ++i) cout << o1[i] <<     << o2[i] <<   n ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   inline void amin(T &x, const T &y) {     if (y < x) x = y;   }   template <class T>   inline void amax(T &x, const T &y) {     if (x < y) x = y;   }   template <class Iter>   void rprintf(const char *fmt, Iter begin, Iter end) {     for (bool sp = 0; begin != end; ++begin) {       if (sp)         putchar(   );       else         sp = true;       printf(fmt, *begin);     }     putchar(  n );   }   int N;   int T[100011];   int X[100011];   int Y[100011];   int val[100011];   void MAIN() {     int R;     scanf( %d%d , &R, &N);     for (int i = 0, i_len = (N); i < i_len; ++i)       scanf( %d%d%d , T + i, X + i, Y + i);     const int INF = 1 << 29;     for (int i = 0, i_len = (N); i < i_len; ++i) {       val[i] = -INF;       if (X[i] + Y[i] - 2 <= T[i]) val[i] = 1;       for (int j = i - 1; j >= 0; j--) {         if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= T[i] - T[j]) {           amax(val[i], val[j] + 1);         }         if (T[i] - T[j] > 2000) break;       }     }     int ans = 0;     for (int i = 0, i_len = (N); i < i_len; ++i) amax(ans, val[i]);     printf( %d n , ans);   }   int main() {     int TC = 1;     for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   pair<long long, long long> dp[20][1 << 10];   int a[20];   long long pw[20];   int change(long long n) {     int cnt = 0;     while (n) {       if (n & 1) cnt++;       n /= 2;     }     return cnt;   }   int k;   long long pow(int e, int n) {     long long ans = 1;     while (n--) {       ans *= e;     }     return ans;   }   pair<long long, long long> dfs(int len, long long Set, bool zero, bool limit) {     if (len == 0) {       if (change(Set) <= k) return make_pair(1, 0);       return make_pair(0, 0);     }     if (!limit && dp[len][Set].first != 0 && !zero) return dp[len][Set];     int u = limit ? a[len - 1] : 9;     pair<long long, long long> ans = make_pair(0, 0);     for (int i = 0; i <= u; i++) {       pair<long long, long long> tem = make_pair(0, 0);       if (change(Set | (1 << i)) > k) continue;       if (zero && i == 0)         tem = dfs(len - 1, Set, zero, i == u && limit);       else {         tem = dfs(len - 1, Set | (1 << i), zero && i == 0, i == u && limit);       }       ans.first += tem.first;       ans.first %= mod;       ans.second =           (ans.second + i * tem.first % mod * pw[len - 1] % mod + tem.second) %           mod;     }     if (!limit && !zero) dp[len][Set] = ans;     return ans;   }   void init() {     pw[0] = 1;     for (int i = 1; i < 20; i++) pw[i] = (pw[i - 1] * 10) % mod;     for (int i = 0; i < 20; i++)       for (int j = 0; j < 1 << 9; j++) dp[i][j].first = dp[i][j].second = 0;   }   long long solve(long long n) {     int len = 0;     init();     while (n) {       a[len++] = n % 10;       n /= 10;     }     return dfs(len, 0, 1, 1).second;   }   int main() {     long long l, r;     while (cin >> l >> r >> k) {       cout << (solve(r) - solve(l - 1) + mod) % mod << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> ans(n);     int a1, a2, a3;     cout <<  ? 1 2  << endl;     fflush(stdout);     cin >> a1;     cout <<  ? 1 3  << endl;     fflush(stdout);     cin >> a2;     cout <<  ? 2 3  << endl;     fflush(stdout);     cin >> a3;     int t = (a1 + a2 - a3) / 2;     ans[0] = t;     ans[2] = a2 - t;     ans[1] = a3 - ans[2];     for (int i = 3; i < n; i++) {       int now = 0;       cout <<  ? 1   << i + 1 << endl;       fflush(stdout);       cin >> now;       ans[i] = now - t;     }     cout <<  !  ;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a, ok, ans, occ[10];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       int total = k + 1;       memset(occ, 0, sizeof(occ));       while (a) {         if (!occ[a % 10] && (a % 10 <= k)) {           total--;         }         occ[a % 10] = 1;         a /= 10;       }       if (!total) {         ans++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int R = 1000;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, s, d;     cin >> n >> s >> d;     vector<bitset<R>> a(s);     for (int i = 0, k, x; i < s; ++i) {       cin >> k;       while (k--) cin >> x, a[i][x - 1] = 1;     }     vector<pair<int, bitset<R>>> f1;     int m = min(s, 10);     for (int i = 0; i < 1 << m; ++i) {       f1.push_back({0, {}});       for (int j = 0; j < m; ++j)         if (i >> j & 1) ++f1.back().first, f1.back().second ^= a[j];     }     unordered_map<bitset<R>, int> mp;     int m2 = s - m;     for (int i = 0; i < 1 << m2; ++i) {       bitset<R> b;       int c = 0;       for (int j = 0; j < m2; ++j)         if (i >> j & 1) ++c, b ^= a[m + j];       if (!mp.count(b))         mp[b] = c;       else         mp[b] = min(mp[b], c);     }     for (int k, x; d--;) {       cin >> k;       bitset<R> b;       while (k--) cin >> x, b[x - 1] = 1;       int ans = 1 << 30;       for (auto &i : f1) {         b ^= i.second;         if (mp.count(b)) ans = min(ans, i.first + mp[b]);         b ^= i.second;       }       if (ans == 1 << 30) ans = -1;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 10000 + 10;   int n, m;   int second[200], a[200];   bool vis[200];   int main() {     scanf(  %d %d , &n, &m);     for (int i = 0; i < m; i++) scanf(  %d , &second[i]);     for (int i = 0; i < m; i++) second[i]--;     bool win = true;     for (int i = 0; i < m - 1; i++) {       int next = second[i + 1];       if (next <= second[i]) next += n;       if (a[second[i]] == 0 ||           a[second[i]] != 0 && a[second[i]] == next - second[i])         a[second[i]] = next - second[i];       else         win = false;     }     for (int i = 0; i < n; i++) {       if (vis[a[i]] && a[i] != 0) win = false;       vis[a[i]] = true;     }     if (win) {       int ind = 1;       for (int i = 0; i < n; i++) {         if (a[i] == 0) {           while (vis[ind]) ind++;           a[i] = ind;           vis[ind] = true;         }       }       for (int i = 0; i < n; i++) {         if (i > 0) printf(   );         printf( %d , a[i]);       }       printf(  n );     } else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 10;   int n, a[MAXN], k, dp[MAXN];   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     long long l = -1, r = 2e9 + 1;     while (l + 1 < r) {       long long mid = (r + l) / 2;       bool flag = false;       for (int i = 0; i < n; i++) {         dp[i] = i;         for (int j = 0; j < i; j++) {           if (abs(a[i] - a[j]) > (i - j) * mid) continue;           dp[i] = min(dp[i], dp[j] + i - j - 1);         }         if (dp[i] + n - i - 1 <= k) {           flag = true;           break;         }       }       if (flag)         r = mid;       else         l = mid;     }     cout << r;   }
#include <bits/stdc++.h>   using namespace std;   long long* parent;   long long* size;   void make_set(long long v) {     parent[v] = v;     size[v] = 1;   }   long long find_set(long long v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_set(long long u, long long v) {     long long p1, p2;     p1 = find_set(u);     p2 = find_set(v);     if (p1 != p2) {       if (size[p1] < size[p2]) swap(p1, p2);       parent[p2] = p1;       size[p1] += size[p2];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     vector<long long> vc(n + 1);     parent = new long long[n + 1];     size = new long long[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> vc[i];       make_set(i);     }     long long a, b;     for (long long i = 0; i < m; i++) {       cin >> a >> b;       union_set(a, b);     }     unordered_map<long long, long long> mp;     vector<vector<long long> > ele(n + 1);     vector<vector<long long> > ind(n + 1);     long long k;     long long p = 0, pp;     for (long long i = 1; i <= n; i++) {       k = find_set(i);       if (mp[k] == 0) {         p++;         pp = p;         mp[k] = p;       } else {         pp = mp[k];       }       ele[pp].push_back(vc[i]);       ind[pp].push_back(i);     }     for (long long i = 1; i <= p; i++) {       sort(ele[i].begin(), ele[i].end(), greater<long long>());       sort(ind[i].begin(), ind[i].end());       for (long long j = 0; j < ele[i].size(); j++) {         vc[ind[i][j]] = ele[i][j];       }     }     for (long long i = 1; i <= n; i++) cout << vc[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   const int MAX_N = 3e5 + 2;   struct Ant {     int id;     long long pos, speed;     Ant(){};     Ant(int id, long long pos, long long speed) {       this->id = id;       this->pos = pos;       this->speed = speed;     }   };   bool comparePosition(Ant a, Ant b) { return (a.pos < b.pos); }   long long mod(long long x, long long m) { return ((x % m) + m) % m; }   int ans[MAX_N];   std::vector<Ant> startPosition, endPosition;   int main() {     int n;     long long cycleLength, time;     std::cin >> n >> cycleLength >> time;     for (int i = 1; i <= n; i++) {       int pos;       char dir;       std::cin >> pos >> dir;       startPosition.push_back(Ant(i, pos, (dir ==  R ) ? 1 : -1));     }     std::sort(startPosition.begin(), startPosition.end(), comparePosition);     for (int i = 0; i < (int)startPosition.size(); i++)       endPosition.push_back(startPosition[i]);     long long cyclicShift = 0;     for (int i = 0; i < n; i++) cyclicShift += startPosition[i].speed;     cyclicShift = mod(cyclicShift * (time / cycleLength), n);     time %= cycleLength;     for (int i = 0; i < n; i++) {       endPosition[i].pos =           mod((startPosition[i].pos - 1) + time * startPosition[i].speed,               cycleLength) +           1;       if (startPosition[i].speed == 1) {         if (endPosition[i].pos < startPosition[i].pos) cyclicShift++;       } else {         if (endPosition[i].pos > startPosition[i].pos) cyclicShift--;       }     }     cyclicShift = mod(cyclicShift, n);     std::sort(endPosition.begin(), endPosition.end(), comparePosition);     for (int i = 0; i < n; i++) {       endPosition[i].id = startPosition[mod(i - cyclicShift, n)].id;       ans[endPosition[i].id] = endPosition[i].pos;     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> v(n);     vector<int> c(m + 5, 0);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int l = 0, r = 0;     int res = 1;     c[v[0] - 1]++;     int maxC = 1;     int maxI = v[0] - 1;     while (r < n) {       if (c[v[r] - 1] > maxC) {         maxC = c[v[r] - 1];         maxI = v[r] - 1;       }       if (c[v[l] - 1] > maxC) {         maxC = c[v[l] - 1];         maxI = v[l] - 1;       }       if (r - l + 1 - maxC > k) {         if (v[l] - 1 == maxI) {           maxC--;         }         c[v[l] - 1]--;         l++;       } else if (r == n - 1) {         break;       } else {         r++;         c[v[r] - 1]++;         if (c[v[r] - 1] > maxC) {           maxC = c[v[r] - 1];           maxI = v[r] - 1;         }         if (r - l + 1 - maxC <= k) {           res = max(res, maxC);         }       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 0, BAR = 1e6, LIM = 5e6;   int x, y, n;   int main() {     scanf( %d , &n);     int xa = inf, xb = -inf, ya = inf, yb = -inf;     while (n--) {       scanf( %d%d , &x, &y);       x += BAR, y += BAR;       xa = min(xa, x - y - 1), xb = max(xb, x + y + 1);       ya = min(ya, x - (LIM - y + 1)), yb = max(yb, x + (LIM - y + 1));     }     int ans = 0;     int rya = (LIM - (yb - ya) / 2);     ans += (yb - ya) % 2;     int ryb = (xb - xa) / 2;     ans += (xb - xa) % 2;     ans += 2 * (ryb - rya);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( lol.in );   ofstream fout( lol.out );   char c;   int m[10][10], ok;   int main() {     ios::sync_with_stdio(false);     for (int i = 1; i <= 6; ++i) {       m[1][i] = m[6][i] = 100;       m[i][1] = m[i][6] = 100;     }     for (int i = 2; i <= 5; ++i) {       for (int j = 2; j <= 5; ++j) {         cin >> c;         if (c ==  x ) m[i][j] = 1;         if (c ==  o ) m[i][j] = 100;       }     }     for (int i = 2; i <= 5; ++i) {       for (int j = 2; j <= 5; ++j) {         if (m[i][j] + m[i + 1][j] + m[i + 2][j] == 2) ok = 1;         if (m[i][j] + m[i + 1][j + 1] + m[i + 2][j + 2] == 2) ok = 1;         if (m[i][j] + m[i + 1][j - 1] + m[i + 2][j - 2] == 2) ok = 1;         if (m[i][j] + m[i][j + 1] + m[i][j + 2] == 2) ok = 1;         if (ok == 1) {           cout <<  YES ;           return 0;         }       }     }     if (ok == 1) {       cout <<  YES ;       return 0;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7f7f7f7f;   int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   vector<int> arr;   int main() {     int n;     string st;     int x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       arr.push_back(x);     }     cin >> st;     int beg = 0;     int flag = 0;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  1  && flag == 0) {         beg = i;         flag = 1;       } else if (st[i] ==  0 ) {         if (flag) {           sort(arr.begin() + beg, arr.begin() + i + 1);           flag = 0;           beg = -1;         }       }     }     if (flag == 1) sort(arr.begin() + beg, arr.end());     bool f = 0;     for (int i = 0; i < n; i++) {       if (arr[i] != i + 1) {         f = 1;         break;       }     }     if (f == 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, f[101][50001], a[101], b[101];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 0; i <= 100; i++)       for (int j = 0; j <= 50000; j++) f[i][j] = -99999999;     f[0][20000] = 0;     for (int i = 1; i <= n; i++)       for (int j = -10000; j <= 10000; j++)         f[i][j + 20000] = max(f[i][j + 20000],                               max(f[i - 1][j + 20000],                                   f[i - 1][j - a[i] + k * b[i] + 20000] + a[i]));     int ans = -1;     if (f[n][20000]) ans = f[n][20000];     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x, t;     char card, ha;     map<int, pair<int, int> > mh;     map<int, pair<int, int> > ma;     map<int, pair<int, int> >::iterator it;     string h, a;     cin >> h >> a;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t >> ha;       getchar();       cin >> x >> card;       getchar();       if (ha ==  a ) {         for (it = ma.begin(); it != ma.end(); it++) {           if ((it->second).first == x) break;         }         if (it == ma.end() && card ==  y )           ma[t] = make_pair(x, 1);         else if (it == ma.end() && card ==  r )           ma[t] = make_pair(x, 2);         else if (it != ma.end() && (it->second).second == 1) {           ma[t] = make_pair(x, 2);           ma.erase(it);         }       }       if (ha ==  h ) {         for (it = mh.begin(); it != mh.end(); it++) {           if ((it->second).first == x) break;         }         if (it == mh.end() && card ==  y )           mh[t] = make_pair(x, 1);         else if (it == mh.end() && card ==  r )           mh[t] = make_pair(x, 2);         else if (it != ma.end() && (it->second).second == 1) {           mh[t] = make_pair(x, 2);           mh.erase(it);         }       }     }     for (i = 0; i <= 90; i++) {       if (ma[i].second == 2) cout << a <<     << ma[i].first <<     << i << endl;       if (mh[i].second == 2) cout << h <<     << mh[i].first <<     << i << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 101000;   struct p {     long long x, y;   } a[N];   long long n, m;   long long pro(p o, p b, p c) {     return (b.x - o.x) * (c.y - o.y) - (c.x - o.x) * (b.y - o.y);   }   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i].x, &a[i].y);     scanf( %I64d , &m);     for (long long i = 1; i <= m; i++) {       p b;       scanf( %I64d%I64d , &b.x, &b.y);       if (pro(a[1], a[2], b) >= 0 || pro(a[1], a[n], b) <= 0) {         puts( NO );         return 0;       }       long long l = 2, r = n;       while (l < r) {         long long mid = (l + r) / 2;         if (pro(a[1], a[mid], b) >= 0)           r = mid;         else           l = mid + 1;       }       if (pro(a[l], a[l - 1], b) <= 0) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }