malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long l[200001], r[200001];   struct data {     long long l, r, ans, num;     bool operator<(const data &p) const { return r > p.r; }   } a[300001];   priority_queue<data> q;   bool cmp(data p, data q) {     if (p.l == q.l) return p.num < q.num;     return p.l < q.l;   }   bool cmp2(data p, data q) { return p.num < q.num; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]);     for (int i = 1; i < n; i++) {       a[i].l = l[i + 1] - r[i];       a[i].r = r[i + 1] - l[i];       a[i].num = i;     }     for (int i = n; i <= m + n - 1; i++) {       long long x;       scanf( %lld , &x);       a[i].num = i;       a[i].l = x;     }     sort(a + 1, a + m + n, cmp);     for (int i = 1; i <= m + n - 1; i++) {       if (a[i].num < n) {         data now = a[i];         now.num = i;         q.push(now);         continue;       }       if (q.empty()) continue;       data now = q.top();       q.pop();       if (now.r < a[i].l) {         printf( No n );         return 0;       }       a[now.num].ans = a[i].num - n + 1;     }     if (!q.empty()) {       printf( No n );       return 0;     }     printf( Yes n );     sort(a + 1, a + n + m, cmp2);     for (int i = 1; i < n; i++) printf( %d  , a[i].ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     long k = min(d, min(c, b));     long m = min(a, d);     long cost = 0;     if (e > f) {       d = d - m;       cost = m * e + min(d, min(c, b)) * f;     } else {       d = d - k;       cost = k * f + min(a, d) * e;     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, L, K;   string s;   int cnt[26];   string res[1000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> L >> K;     cin >> s;     for (int i = 0; i < N * L; i++) cnt[s[i] -  a ]++;     int l = 0;     int t = 0;     while (l < K - 1 and t < 26) {       int st = cnt[t];       for (int j = 0, _t = cnt[t]; j < _t; j++) {         if (res[l + j % (K - l)].size() == L) {           l = K + 1;           break;         }         res[l + j % (K - l)] += (char)(t +  a );         cnt[t]--;       }       l += st % (K - l);       t++;     }     int lst = 25;     for (int i = 0; i < K - 1; i++) {       while (res[i].size() < L) {         while (cnt[lst] == 0) lst--;         res[i] += (char)(lst +  a );         cnt[lst]--;       }     }     int fst = 0;     for (int i = K - 1; i < N; i++) {       while (res[i].size() < L) {         while (cnt[fst] == 0) fst++;         res[i] += (char)(fst +  a );         cnt[fst]--;       }     }     sort(res, res + N);     for (int i = 0; i < N; i++) {       cout << res[i] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int justgreater(long long int n) {     long long int i;     for (i = 1;; i++)       if (i * (i + 1) / 2 > n) break;     return i - 1;   }   int main() {     long long int m, n, a[100009] = {0}, sum = 0, cnt = 0;     cin >> m >> n;     long long int up = justgreater(m + n);     long long int tup = up;     for (; tup >= 1; tup--) {       if (sum + tup > m) continue;       sum += tup;       a[tup]++;     }     long long int cnt0 = 0, cnt1 = 0;     for (long long int i = 1; i <= up; i++)       if (a[i] == 1)         cnt0++;       else         cnt1++;     cout << cnt0 << endl;     for (long long int i = 1; i <= up; i++)       if (a[i] == 1) cout << i <<    ;     cout << endl;     cout << cnt1 << endl;     for (long long int i = 1; i <= up; i++)       if (a[i] == 0) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   long long n, maxl = 2e5;   long long montonic(vector<long long> &b) {     bool inc = true, dec = true;     long long n = (long long)b.size();     for (long long i = 1; i < n; ++i) {       if (b[i] <= b[i - 1]) {         inc = false;       }       if (b[i] >= b[i - 1]) {         dec = false;       }     }     if (inc == 1) {       return 1;     }     if (dec == 1) {       return 0;     } else       return -1;   }   void f(vector<long long> &a, vector<long long> &b) {     string ans =   ;     while (true) {       if (b == a) {         break;       } else {         vector<long long> c = b;         reverse(c.begin(), c.end());         if (c == a) {           ans +=  R ;           break;         }       }       long long m = montonic(b);       if (m == -1) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else {         if (m == 0) {           reverse(b.begin(), b.end());           ans +=  R ;         } else {           for (long long i = n - 1; i >= 1; --i) b[i] -= b[i - 1];           ans +=  P ;         }       }     }     if ((long long)ans.size() > maxl) {       cout <<  BIG  <<   n ;       long long cnt = 0;       for (long long i = 0; i < (long long)ans.size(); ++i)         if (ans[i] ==  P ) ++cnt;       cout << cnt <<   n ;     } else {       cout <<  SMALL  <<   n ;       cout << (long long)ans.size() <<   n ;       reverse(ans.begin(), ans.end());       cout << ans <<   n ;     }   }   void solve() {     cin >> n;     if (n == 1) {       long long a;       cin >> a;       long long b;       cin >> b;       if (b % a) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else {         long long op = b / a - 1;         if (op > maxl) {           cout <<  BIG  <<   n ;           cout << op <<   n ;         } else {           cout <<  SMALL  <<   n ;           cout << op <<   n ;         }       }     } else if (n == 2) {       vector<long long> a(n), b(n);       for (long long i = 0; i < n; ++i) cin >> a[i];       for (long long i = 0; i < n; ++i) cin >> b[i];       vector<long long> c = a;       vector<long long> d = b;       long long popr = 0;       sort(c.begin(), c.end());       sort(d.begin(), d.end());       long long op = 0;       while (d[0] != c[0]) {         if (d[0] == 0) {           cout <<  IMPOSSIBLE  <<   n ;           return;         }         op += d[1] / d[0];         d[1] %= d[0];         swap(d[0], d[1]);       }       if ((d[1] - c[1]) % c[0]) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else         op += (d[1] - c[1]) / c[0];       if (op > maxl) {         cout <<  BIG  <<   n ;         cout << op <<   n ;       } else         f(a, b);     } else {       vector<long long> a(n), b(n);       for (long long i = 0; i < n; ++i) cin >> a[i];       for (long long i = 0; i < n; ++i) cin >> b[i];       f(a, b);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long maxn = 1e6 + 10;   int a[4], b[10] = {0, 1, 2, 0, 2, 1, 0}, c[4];   int check(int w) {     int sum = 0;     for (int i = 0; i < 3; i++) c[i] = a[i];     for (int i = w; i < 7; i++) {       if (c[b[i]] == 0) break;       --c[b[i]], ++sum;     }     int weeks = min(c[0] / 3, min(c[1] / 2, c[2] / 2));     c[0] -= weeks * 3, c[1] -= weeks * 2, c[2] -= weeks * 2, sum += weeks * 7;     for (int i = 0; i < 7; i++) {       if (c[b[i]] == 0) break;       --c[b[i]], ++sum;     }     return sum;   }   int main() {     for (int i = 0; i < 3; i++) cin >> a[i];     if (a[0] == 1 && a[1] == 1 && a[2] == 2) {       cout <<  4  << endl;       return 0;     }     int ans = 0;     for (int i = 0; i < 7; i++) {       ans = max(ans, check(i));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int n;   bool M[1005][1005];   int q;   bool ans = 0;   void setMatrix() {     for (int i = 0; i < n; i++)       if (M[i][i]) ans = !ans;   }   void CallEdit() {     int i;     scanf( %d , &i);     ans = !ans;   }   void CallPuts() { printf( %d , ans); }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &M[i][j]);     setMatrix();     scanf( %d , &q);     while (q--) {       int flag;       scanf( %d , &flag);       switch (flag) {         case 1: {           CallEdit();           break;         }         case 2: {           CallEdit();           break;         }         case 3: {           CallPuts();           break;         }         default:           break;       }     }     printf(  n );     return;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000010;   int p[maxn];   int main() {     int i, j, st, a, n, maxi;     long long ans = 0;     scanf( %d%d , &a, &n);     maxi = (int)(sqrt(a + n - 1) + 1e-7);     for (i = 1; i <= maxi; i++) {       st = (int)(a / (i * i) + 1e-7) * i * i;       for (j = st; j <= a + n - 1; j += i * i) p[j] = i * i;     }     for (i = a; i <= a + n - 1; i++) ans += i / p[i];     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, m, c;     cin >> n >> m >> c;     for (int i = 1; i <= m; i++) {       int x, ans;       cin >> x;       if (x <= c / 2) {         for (int j = 1; j <= n; j++) {           if (x < a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       } else {         for (int j = n; j >= 1; j--) {           if (x > a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   struct T {     int id, v, c, l, r, sum, prev;     void read(int ii) {       id = ii;       scanf( %d%d%d%d , &v, &c, &l, &r);     }     int total() { return c + l + r; }   };   int n;   map<int, vector<T> > gr;   vector<int> ans;   int res;   map<int, pair<int, int> > d;   int main() {     scanf( %d , &n);     for (int i = 0, _n = (n); i < _n; i++) {       T x;       x.read(i);       gr[x.total()].push_back(x);     }     res = 0;     for (map<int, vector<T> >::iterator git = gr.begin(); git != gr.end();          ++git) {       vector<T>& a = git->second;       d.clear();       d[0] = pair<int, int>(0, -1);       int n = (int)(a).size();       for (int i = 0, _n = (n); i < _n; i++) {         map<int, pair<int, int> >::iterator it = d.find(a[i].l);         if (it == d.end()) continue;         a[i].prev = it->second.second;         int newcost = it->second.first + a[i].v;         map<int, pair<int, int> >::iterator it2 = d.find(a[i].l + a[i].c);         if (it2 == d.end() || it2->second.first < newcost) {           d[a[i].l + a[i].c] = pair<int, int>(newcost, i);         }       }       int total = git->first;       if (d.count(total) == 0) continue;       if (d[total].first <= res) continue;       res = d[total].first;       int last = d[total].second;       ans.clear();       for (; last != -1; last = a[last].prev) ans.push_back(a[last].id);       reverse((ans).begin(), (ans).end());     }     printf( %d n , (int)(ans).size());     for (int i = 0, _n = ((int)(ans).size()); i < _n; i++)       printf(  %d  + (i == 0), ans[i] + 1);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string toString(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long toLong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T S(T a) {     return a * a;   }   template <typename T>   inline T gcd(T a, T b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   template <typename T>   inline unsigned long long bigmod(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return S(bigmod(a, b / 2, m)) % m;     else       return (a % m * bigmod(a, b - 1, m)) % m;   }   template <typename T>   inline vector<string> parse(T str) {     vector<string> res;     string s;     istringstream os(str);     while (os >> s) res.push_back(s);     return res;   }   template <typename T>   inline unsigned long long dist(T A, T B) {     unsigned long long res =         (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   template <typename T>   inline double cosAngle(T a, T b, T c) {     double res = a * a + b * b - c * c;     res = res / (2 * a * b);     res = acos(res);     return res;   }   template <typename T>   inline T power(T base, int po) {     T res = 1;     if (base == 0) return 0;     for (int i = (0); i < (po); i++) res *= base;     return res;   }   template <typename T>   inline bool isOn(T mask, T pos) {     return mask & (1 << pos);   }   template <typename T>   inline int Off(T mask, T pos) {     return mask ^ (1 << pos);   }   template <typename T>   inline int On(T mask, T pos) {     return mask | (1 << pos);   }   long long arr[10005];   vector<int> v[5000];   long long dp[2005][2005];   int Size[2005];   int N;   int main() {     int i, j, k;     int n, q;     long long x, y;     int ks, cas;     int kk;     cin >> n >> kk;     for (i = 1; i <= n; i++) {       for (j = 1; j <= i; j++) {         if (i % j == 0) {           v[i].push_back(j);         }       }     }     for (i = 0; i <= n; i++) {       Size[i] = v[i].size();     }     memset(dp, 0, sizeof dp);     for (i = 1; i <= n; i++) {       dp[1][i] = 1;     }     for (i = 2; i <= kk; i++) {       for (j = 1; j <= n; j++) {         for (k = 0; k < Size[j]; k++) {           dp[i][j] = (dp[i][j] + dp[i - 1][v[j][k]]) % 1000000007;         }       }     }     long long res = 0;     for (i = 1; i <= n; i++) {       res = (res + dp[kk][i]) % 1000000007;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long x, int p) {     long long res = 1;     while (p) {       if (p & 1) res = (res * x) % 998244353;       x = (x * x) % 998244353;       p >>= 1;     }     return res;   }   int main() {     int n, m;     cin >> n >> m;     vector<long long> d(n), pref(n);     for (int i = 0; i < n; i++) cin >> d[i];     sort(d.begin(), d.end());     pref[0] = d[0];     for (int i = 1; i < n; i++) pref[i] = (pref[i - 1] + d[i]) % 998244353;     while (m--) {       int a, b;       cin >> a >> b;       int x = lower_bound(d.begin(), d.end(), b) - d.begin();       int big = n - x;       if (big < a) {         cout << 0 <<   n ;         continue;       }       long long big_total = (pref[n - 1] - (x > 0 ? pref[x - 1] : 0)) % 998244353;       (big_total += 998244353) %= 998244353;       long long ans = (big_total * (big - a)) % 998244353;       ans = (ans * bigmod(big, 998244353 - 2)) % 998244353;       long long tmp = ((x > 0 ? pref[x - 1] : 0) * (big + 1 - a)) % 998244353;       tmp = (tmp * bigmod(big + 1, 998244353 - 2)) % 998244353;       ans = (ans + tmp) % 998244353;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846264338327950288419716939937510,                     EPS = 1e-9;   const int MAX = 1 << 17;   struct prav {     long double a, b, c;   };   pair<int, int> sred;   long double Sq(long double x) { return x * x; }   long double Dist(pair<int, int> a, pair<int, int> b) {     return sqrt(Sq(a.first - b.first) + Sq(a.second - b.second));   }   long double DistPrav(prav p, pair<int, int> toc) {     return abs(p.a * toc.first + p.b * toc.second + p.c) /            sqrt((Sq(p.a) + Sq(p.b)));   }   prav Pravac(pair<int, int> a, pair<int, int> b) {     return prav{         (long double)b.second - a.second, (long double)a.first - b.first,         (long double)b.first * a.second - (long double)a.first * b.second};   }   pair<int, int> tocke[MAX];   int main() {     int n;     scanf( %d%d%d , &n, &sred.first, &sred.second);     for (int i = 0; i < n; i++) scanf( %d%d , &tocke[i].first, &tocke[i].second);     long double minn = 1e15, maxx = -1e15;     for (int i = 0; i < n; i++) {       long double dd = Dist(sred, tocke[i]);       minn = min(minn, dd);       maxx = max(maxx, dd);       int slj = (i + 1) % n;       if (Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[i], sred)) + EPS >               Sq(Dist(tocke[slj], sred)) &&           Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[slj], sred)) + EPS >               Sq(Dist(tocke[i], sred))) {         minn = min(minn, DistPrav(Pravac(tocke[i], tocke[slj]), sred));       }     }     printf( %.15lf n , (double)((Sq(maxx) - Sq(minn)) * PI));     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...);   }   int n;   vector<int> nailed;   struct evn {     int pos, type, num;   };   vector<evn> events;   bool comp(const evn& a, const evn& b) {     if (a.pos == b.pos && a.type == b.type) return a.num < b.num;     if (a.pos == b.pos) return a.type == 0;     return a.pos < b.pos;   }   int main() {     srand(chrono::steady_clock::now().time_since_epoch().count());     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     nailed.resize(n, 0);     int l, r;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       cin >> l >> r;       if (r < l) swap(l, r);       evn a, b;       a.pos = l;       a.num = i;       a.type = 0;       events.push_back(a);       b.pos = r;       b.num = i;       b.type = 1;       events.push_back(b);     }     sort(events.begin(), events.end(), comp);     queue<int> pinned;     vector<int> ans;     for (auto it : events) {       if (it.type) {         if (nailed[it.num] == 0) {           while (!pinned.empty()) {             int ind = pinned.front();             nailed[ind] = 1;             pinned.pop();           }           nailed[it.num] = 1;           ans.push_back(it.pos);         }       } else {         pinned.push(it.num);       }     }     cout << (int)(ans.size()) <<   n ;     if ((int)(ans.size()) > 0) {       for (auto it : ans) cout << it <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 5;   int n, k, v;   int a[maxn];   bool f[maxn][maxn];   pair<int, int> fr[maxn][maxn];   bool u[maxn][maxn];   bool vis[maxn];   struct ex {     int cnt, x, y;   };   vector<ex> ans;   vector<int> vec;   int read() {     int x;     scanf( %d , &x);     return x;   }   int main() {     int i, j;     int x, y;     n = read();     k = read();     v = read();     f[0][0] = true;     for (i = 1; i <= n; i++) {       a[i] = read();       for (j = 0; j < k; j++) {         f[i][j] = f[i - 1][j];         fr[i][j] = make_pair(i - 1, j);         u[i][j] = false;       }       for (j = 0; j < k; j++) {         if (f[i - 1][j]) {           if (!f[i][(j + a[i]) % k]) {             f[i][(j + a[i]) % k] = true;             fr[i][(j + a[i]) % k] = make_pair(i - 1, j);             u[i][(j + a[i]) % k] = true;           }         }       }     }     if (!f[n][v % k]) {       printf( NO n );       return 0;     }     pair<int, int> tmp = make_pair(n, v % k);     while (tmp.first) {       if (u[tmp.first][tmp.second]) {         vec.push_back(tmp.first);         vis[tmp.first] = true;       }       tmp = fr[tmp.first][tmp.second];     }     for (i = 1; i < vec.size(); i++) {       x = vec[i];       ans.push_back((ex){a[x] / k + 1, x, vec[0]});       a[vec[0]] += a[x];       a[x] = 0;     }     if (v % k) {       x = vec[0];       y = 1;       if (x == 1) {         y = 2;       }     } else {       x = 1;       y = 2;       ans.push_back((ex){a[x] / k + 1, x, y});       a[y] += a[x];       a[x] = 0;       vis[x] = true;     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         y = i;         break;       }     }     for (i = y + 1; i <= n; i++) {       if (!vis[i]) {         ans.push_back((ex){a[i] / k + 1, i, y});         a[y] += a[i];         a[i] = 0;       }     }     if (a[x] >= v) {       ans.push_back((ex){(a[x] - v) / k, x, y});     } else {       if (a[x] + a[y] / k * k < v) {         printf( NO n );         return 0;       } else {         ans.push_back((ex){(v - a[x]) / k, y, x});       }     }     printf( YES n );     for (ex t : ans) {       if (t.cnt >= 1) printf( %d %d %d n , t.cnt, t.x, t.y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buffer[10];   bool query(int x, int y) {     cout << x <<     << y << endl;     cout.flush();     cin >> buffer;     return (buffer[0] ==  w );   }   const int Y = 100;   bool get(int x) { return query(x, Y); }   void answer(int l, int r) {     cout << l <<     << (Y - 1) <<    ;     cout << r <<     << (Y + 1) <<   n ;   }   int main() {     int n;     cin >> n;     const bool init = get(0);     int l = 0, r = 1000 * 1000 * 1000;     for (int i = 1; i < n; i++) {       int m = (r - l) / 2 + l;       if (get(m) == init) {         l = m;       } else {         r = m;       }     }     answer(l, r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int T, n, m, ans;   char s[N], p[N];   int ne[N], len[N];   int main() {     scanf( %s , s + 1);     m = strlen(s + 1);     cin >> T;     while (T--) {       scanf( %s , p + 1);       n = strlen(p + 1);       if (n == 1) continue;       for (int i = 2, j = 0; i <= n; i++) {         while (j && p[i] != p[j + 1]) j = ne[j];         if (p[i] == p[j + 1]) j++;         ne[i] = j;       }       memset(len, 0, sizeof len);       for (int i = 1, j = 0; i <= m; i++) {         while (j && s[i] != p[j + 1]) j = ne[j];         if (s[i] == p[j + 1]) j++;         len[i] = max(len[i - 1], j);         if (j == n) j = ne[j];       }       memset(ne, 0, sizeof ne);       for (int i = 2, j = 0; i <= n; i++) {         while (j && p[n - i + 1] != p[n - j]) j = ne[j];         if (p[n - i + 1] == p[n - j]) j++;         ne[i] = j;       }       bool flag = false;       for (int i = 1, j = 0; i <= m; i++) {         while (j && s[m - i + 1] != p[n - j]) j = ne[j];         if (s[m - i + 1] == p[n - j]) j++;         if (j && len[m - i] && (j + len[m - i] >= n)) {           flag = true;           break;         }         if (j == n) j = ne[j];       }       if (flag) ans++;     }     printf( %d n , ans);     return 0;   }