malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 65, MAXM = 65;   int N, M;   int A[MAXN], B[MAXM];   int Id[40011], Pos[MAXN * MAXM], Pc;   bool VisA[MAXN], VisB[MAXM];   int Ans, Cnt;   int Val[MAXN * MAXM];   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; ++i) {       cin >> A[i];       A[i] <<= 1;     }     sort(A + 1, A + N + 1);     for (int j = 1; j <= M; ++j) {       cin >> B[j];       B[j] <<= 1;     }     sort(B + 1, B + M + 1);     for (int i = 1; i <= N; ++i)       for (int j = 1, p; j <= M; ++j) {         p = (A[i] + B[j]) >> 1;         if (!Id[p + 20000]) {           ++Pc;           Id[p + 20000] = Pc;           Pos[Pc] = p;         }       }     for (int a = 1; a <= N; ++a) {       for (int b = 1, p; b <= M; ++b) {         p = (A[a] + B[b]) >> 1;         for (int i = 1; i <= N; ++i) VisA[i] = false;         for (int j = 1; j <= M; ++j) VisB[j] = false;         for (int i = 1; i <= N; ++i)           for (int j = 1; j <= M; ++j) {             if (((A[i] + B[j]) >> 1) == p) {               VisA[i] = true;               VisB[j] = true;             }           }         Cnt = 0;         for (int i = 1; i <= N; ++i)           if (VisA[i]) ++Cnt;         for (int j = 1; j <= M; ++j)           if (VisB[j]) ++Cnt;         for (int i = Pc; i >= 1; --i) Val[i] = 0;         for (int i = 1; i <= N; ++i) {           if (VisA[i]) continue;           for (int j = 1; j <= M; ++j) {             if (j != 1 && B[j] == B[j - 1]) continue;             ++Val[Id[((A[i] + B[j]) >> 1) + 20000]];           }         }         for (int j = 1; j <= M; ++j) {           if (VisB[j]) continue;           for (int i = 1; i <= N; ++i) {             if (i != 1 && A[i] == A[i - 1]) continue;             ++Val[Id[((A[i] + B[j]) >> 1) + 20000]];           }         }         Ans = max(Ans, Cnt);         for (int i = Pc; i >= 1; --i) Ans = max(Ans, Val[i] + Cnt);       }     }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[105], C[105];   double f[105][105], s1[105][105], s2[105][105], s3[105][105];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();       if (ch == -1) return 0;     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   double ans;   int main() {     n = read(), k = read(), k = min(k, 900);     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) f[i][j] = a[i] > a[j];     for (int i = 1; i <= n; i++) C[i] = C[i - 1] + i;     while (k--) {       for (int j = 1; j <= n; j++) {         for (int i = 1; i <= j - 1; i++) s1[i][j] = s1[i - 1][j] + f[i][j];         for (int i = 1; i <= j - 1; i++) s1[i][j] += s1[i - 1][j];       }       for (int i = n; i >= 1; i--) {         for (int j = n; j >= i + 1; j--) s2[i][j] = s2[i][j + 1] + f[i][j];         for (int j = n; j >= i + 1; j--) s2[i][j] += s2[i][j + 1];       }       for (int j = 0; j <= n - 1; j++) {         for (int i = 1; i <= n - j; i++) s3[i][j] = s3[i - 1][j] + f[i][i + j];         for (int i = 1; i <= n - j; i++) s3[i][j] += s3[i - 1][j];       }       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++)           f[i][j] *= C[i - 1] + C[j - i - 1] + C[n - j],               f[i][j] += s1[j - 1][j] - s1[j - i - 1][j] - s1[i - 1][j] +                          s2[i][i + 1] - s2[i][j + 1] - s2[i][n + 2 - j + i] -                          s3[n + i - j][j - i] + s3[n - j][j - i] +                          s3[i - 1][j - i],               f[i][j] = (f[i][j] + i * (n + 1 - j)) / C[n];     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans += f[i][j];     printf( %.9lf n , ans);     return 0;   }
#include <bits/stdc++.h>   long long p[1000010] = {0}, cur[1000010 * 2] = {0};   inline long long read() {     char c;     while (!isdigit(c)) c = getchar();     long long x = 0;     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   int main() {     long long sum, ans, L, R, k, n;     scanf( %lld , &n);     sum = L = R = k = 0;     for (int i = 1; i <= n; i++) {       p[i] = read();       sum += abs(p[i] - i);       if (p[i] >= i) {         L++;         cur[p[i] - i]++;       } else         R++;     }     ans = sum;     for (int i = 0; i < n - 1; i++) {       L -= cur[i];       R += cur[i];       sum = sum - L + R - abs(p[n - i] - n - 1) + p[n - i] - 1;       cur[p[n - i] + i]++;       L++;       R--;       if (sum < ans) {         ans = sum;         k = i + 1;       }     }     printf( %lld %lld n , ans, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pow(long long a, int p) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long kek = pow(a, p / 2);       return kek * kek;     }     return pow(a, p - 1) * a;   }   int main() {     int n, m;     cin >> n >> m;     if (m == 0) {       cout << 2 * n;       return 0;     }     if (n == 0) {       cout << 3 * m;       return 0;     }     int a = n * 2, b = m * 3;     int k = min(n / 3, m / 2);     while (k > 0) {       if (a + 2 < b + 3) {         k--, a += 2;         if (a % 6 == 0 && a <= b) k++;       } else {         k--, b += 3;         if (b % 6 == 0 && b <= a) k++;       }     }     cout << max(a, b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long LINF = 2e16;   const int magic = 348;   const int MOD = 998244353;   const double eps = 1e-10;   const double pi = acos(-1);   struct fastio {     static const int S = 1e7;     char rbuf[S + 48], wbuf[S + 48];     int rpos, wpos, len;     fastio() { rpos = len = wpos = 0; }     inline char Getchar() {       if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin);       if (!len) return EOF;       return rbuf[rpos++];     }     template <class T>     inline void Get(T &first) {       char ch;       bool f;       T res;       while (!isdigit(ch = Getchar()) && ch !=  - ) {       }       if (ch ==  - )         f = false, res = 0;       else         f = true, res = ch -  0 ;       while (isdigit(ch = Getchar())) res = res * 10 + ch -  0 ;       first = (f ? res : -res);     }     inline void getstring(char *s) {       char ch;       while ((ch = Getchar()) <= 32) {       }       for (; ch > 32; ch = Getchar()) *++s = ch;       *(s + 1) =   0 ;     }     inline void flush() {       fwrite(wbuf, 1, wpos, stdout);       fflush(stdout);       wpos = 0;     }     inline void Writechar(char ch) {       if (wpos == S) flush();       wbuf[wpos++] = ch;     }     template <class T>     inline void Print(T first) {       char s[20];       int pt = 0;       if (first == 0)         s[++pt] =  0 ;       else         while (first) s[++pt] =  0  + first % 10, first /= 10;       while (pt) Writechar(s[pt--]);       Writechar(  n );     }     inline void printstring(char *s) {       int pt = 1;       while (s[pt] !=   0 ) Writechar(s[pt++]);     }   } io;   int n, ans;   int a[48];   string method[48];   inline bool solve(int pos) {     if (pos == ans + 1) {       if (a[pos] != n) return false;       io.Print(ans);       io.flush();       for (register int i = 1; i <= ans; i++) cout << method[i] << endl;       return true;     }     for (register int i = 1; i <= pos; i++)       for (register int j = 1; j <= pos; j++)         for (register int k = 1; k <= 8; k <<= 1) {           if (a[i] + k * a[j] <= a[pos] || a[i] + k * a[j] > n) continue;           a[pos + 1] = a[i] + k * a[j];           method[pos] =  lea e  + string(1,  a  + pos) +  x, [e  +                         string(1,  a  + i - 1) +  x +   + string(1,  0  + k) +                          *e  + string(1,  a  + j - 1) +  x] ;           if (solve(pos + 1)) return true;         }     for (register int i = 1; i <= pos; i++)       for (register int k = 1; k <= 8; k <<= 1) {         if (k * a[i] <= a[pos] || k * a[i] > n) continue;         a[pos + 1] = k * a[i];         method[pos] =  lea e  + string(1,  a  + pos) +  x, [  +                       string(1,  0  + k) +  *e  + string(1,  a  + i - 1) +  x] ;         if (solve(pos + 1)) return true;       }     return false;   }   int main() {     memset(a, 0, sizeof(a));     a[1] = 1;     io.Get(n);     for (;; ++ans)       if (solve(1)) break;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200200;   int n;   const long long neutro = 0;   struct RMQ {     int sz;     long long tope;     long long t[4 * MAXN];     long long &operator[](int p) { return t[sz + p]; }     void init(int n, long long tope_) {       sz = 1 << (32 - __builtin_clz(n));       tope = tope_;       for (int i = (0); i < (2 * sz); i++) t[i] = neutro;     }     void updall() {       for (int i = sz - 1; i >= 0; i--) t[i] = (t[2 * i] + t[2 * i + 1]);     }     long long get(int i, int j) {       if (j <= i) return 0;       return get(i, j, 1, 0, sz);     }     long long get(int i, int j, int n, int a, int b) {       if (j <= a || i >= b) return neutro;       if (i <= a && b <= j) return t[n];       int c = (a + b) / 2;       return (get(i, j, 2 * n, a, c) + get(i, j, 2 * n + 1, c, b));     }     void set(int p, long long val) {       p += sz;       val = min(tope, t[p] + val);       for (; p > 0 && t[p] != val;) {         t[p] = val;         p /= 2;         val = (t[p * 2] + t[p * 2 + 1]);       }     }   } rmqa, rmqb;   int k, a, b, q;   int main() {     ios::sync_with_stdio(0);     while (cin >> n >> k >> a >> b >> q) {       rmqa.init(n, a);       rmqb.init(n, b);       for (int _ = (0); _ < (q); _++) {         int t;         cin >> t;         if (t == 1) {           int d, a;           cin >> d >> a;           rmqa.set(d - 1, a);           rmqb.set(d - 1, a);         } else {           int p;           cin >> p;           p--;           cout << rmqb.get(0, p) + rmqa.get(p + k, n) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   const int N2 = 2e6 + 5;   long long cs[N2], csn[N2];   int main() {     int n, x, y;     scanf( %d%d%d , &n, &x, &y);     int mx = 0;     for (int i = 0, a; i < n; i++) {       scanf( %d , &a);       cs[a]++;       mx = max(mx, a);     }     long long temp = 0;     int am = 0;     for (int i = 1; i < N2; i++) {       if (cs[i]) am += cs[i];       cs[i] += cs[i - 1];       csn[i] = temp;       temp += am;     }     int d = x / y;     for (int i = d - 2; i <= d + 2; i++) {       if (1LL * i * y < x) d = i;     }     long long ans = 1e18;     for (int i = 2; i < N2; i++) {       int h = min(d, i - 1), g = 0;       long long s = 0;       for (int j = i; j < N2; j += i) {         g += cs[j] - cs[max(j - h - 1, 0)];         s += csn[j] - csn[max(j - h - 1, 0)] -              cs[max(j - h - 1, 0)] * 1LL * (h + 1);       }       ans = min(ans, y * s + x * 1LL * (n - g));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int sum = 0;       for (int i = 0; i < 3; i++) {         long long int temp;         cin >> temp;         sum += temp;       }       cout << sum / 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:512000000 )   using namespace std;   using li = long long;   using ld = long double;   void solve(bool);   void precalc();   clock_t start;   int main() {     start = clock();     int t = 1;     cout.sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     cout << fixed;     precalc();     while (t--) {       solve(true);     }     cout.flush();     return 0;   }   template <typename T>   T binpow(T q, T w, T mod) {     if (!w) return 1 % mod;     if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;     return binpow(q * 1LL * q % mod, w / 2, mod);   }   template <typename T>   T gcd(T q, T w) {     while (w) {       q %= w;       swap(q, w);     }     return q;   }   template <typename T>   T lcm(T q, T w) {     return q / gcd(q, w) * w;   }   template <typename T>   void make_unique(vector<T>& vec) {     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());   }   template <typename T>   void relax_min(T& cur, T val) {     cur = min(cur, val);   }   template <typename T>   void relax_max(T& cur, T val) {     cur = max(cur, val);   }   mt19937 rng(       (unsigned long long)chrono::steady_clock::now().time_since_epoch().count());   void precalc() {}   void solve(__attribute__((unused)) bool read) {     string s;     cin >> s;     li n = (li)s.length();     li res = n * (n + 1) / 2;     for (li l = 0; l < n; ++l) {       bool flag = false;       for (li r = l; r < n && !flag; ++r) {         for (li i = r - 2; i >= l; i -= 2) {           if (s[i] == s[r] && s[i] == s[i + (r - i) / 2]) {             flag = true;             break;           }         }         if (flag) {           break;         }         --res;       }     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num, sum = 0;     for (int i = 0; i < 5; ++i) {       cin >> num;       sum += num;     }     if (!(sum % 5) && sum > 0)       cout << sum / 5 << endl;     else       cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double dp[4005][4005];   long double absf(long double a) {     if (a < 0) return a * (-1);     return a;   }   long double solve(vector<long double> &a, long long idx, long long left) {     if (idx >= a.size()) return left == 0 ? 0 : 100000;     if (dp[idx][left] != -100000) {       return dp[idx][left];     }     long double cur_up = ceil(a[idx]);     long double cur_down = floor(a[idx]);     if (left > 0) {       long double pt1 = a[idx] - cur_down + solve(a, idx + 1, left - 1);       long double pt2 = a[idx] - cur_up + solve(a, idx + 1, left);       if (absf(pt1) < absf(pt2)) {         return dp[idx][left] = pt1;       } else {         return dp[idx][left] = pt2;       }     } else {       long double pt2 = a[idx] - cur_up + solve(a, idx + 1, left);       return dp[idx][left] = pt2;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long double> a;     for (long long i = 0; i < 2 * n; i++) {       long double temp;       cin >> temp;       a.push_back(temp);     }     for (long long i = 0; i < 4005; i++) {       for (long long j = 0; j < 4005; j++) {         dp[i][j] = -100000;       }     }     long double res = abs(solve(a, 0, n));     cout << fixed << setprecision(3);     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cur, hasans, ptr;   vector<int> adj[500004];   vector<int> ans(500004);   void dfs(int now) {     cur--;     for (auto u : adj[now]) {       if (u == cur) {         dfs(u);       } else {         hasans = 0;       }     }     ans[ptr++] = now;   }   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n + 1; i++) {       adj[i].clear();       ans[i] = 0;     }     cur = n + 1, hasans = 1, ptr = 1;     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == -1) a[i] = i + 1;     }     for (int i = 1; i <= n; i++) {       adj[a[i]].push_back(i);     }     for (int i = 1; i <= n + 1; i++) {       sort(adj[i].begin(), adj[i].end(), greater<int>());     }     dfs(n + 1);     if (!hasans) {       cout <<  -1 n ;     } else {       vector<int> res(n + 1);       for (int i = 1; i <= n; i++) {         res[ans[i]] = i;       }       for (int i = 1; i <= n; i++) {         cout << res[i] <<    ;       }       cout <<   n ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _print(long long int t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(unordered_map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   const long long int MOD = 1e9 + 7;   const long long int MX = 1e5 + 1;   long long int n;   long long int arr[MX];   long long int a, b, c, d, e, f, g, h;   void sourav() {     int cnt1 = 0, cnt2 = 0;     string s;     cin >> s;     if (s.size() & 1) {       cout <<  NO n ;       ;       return;     }     for (long long int i = 0; i < s.size(); i++) {       if (s[i] ==  A ) {         cnt1++;       } else if (s[i] ==  C ) {         cnt2++;       }     }     if ((cnt1 + cnt2) == (s.size() - (cnt1 + cnt2))) {       cout <<  YES n ;       ;     } else {       cout <<  NO n ;       ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       sourav();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100005];   int sum = 0, m;   char s[10005][105];   void f(int target, int n) {     int i, j, k, l;     m = max((a[n].first - target), ((sum - n * target) / 2));     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) s[i][j] =  0 ;       s[i][j] =   0 ;     }     int total = sum - n * target;     for (i = n, j = 0, k = 0, l = 1; l <= total || k < 2;) {       s[j][a[i].second - 1] =  1 ;       a[i].first--;       if (a[i].first <= target && i > 1) i--;       j++;       l++;       if (j >= m) {         j = 0;         k++;       }     }     return;   }   int main() {     int i, j, k, l, n;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       int val;       scanf( %d , &val);       a[i] = make_pair(val, i);       sum += a[i].first;     }     sort(a + 1, a + n + 1);     for (i = a[1].first; i >= 1; i--) {       if ((sum - n * i) / 2 >= (a[n].first - i)) break;     }     f(i, n);     cout << i << endl << m << endl;     for (i = 0; i < m; i++) printf( %s n , s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 310;   int a[N][N], n, p[N], vis[N];   void dfs(int v) {     vis[v] = 1;     for (int i = 1; i <= n; i++) {       if (a[v][i] && !vis[i]) {         dfs(i);       }     }   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &p[i]);     }     scanf(  n );     char ch;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         ch = getchar();         if (ch ==  0 ) {           a[i][j] = 0;         } else {           a[i][j] = 1;         }       }       scanf(  n );     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         vis[j] = 0;       }       dfs(i);       int pos = -1;       for (j = i; j <= n; j++) {         if (vis[j]) {           if ((pos == -1) || (p[pos] > p[j])) {             pos = j;           }         }       }       swap(p[pos], p[i]);     }     for (i = 1; i <= n; i++) {       printf( %d  , p[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int inf = 0x3f3f3f3f;   const long long int INF = 1e15;   const int mod = 1e9 + 7;   const int maxn = 2e3 + 5;   int cas = 1;   int sum[maxn];   vector<int> v;   map<int, int> mp;   void solve() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       memset(sum, 0, sizeof(sum));       v.clear();       mp.clear();       for (int i = 1; i <= n; i++) {         int u;         scanf( %d , &u);         sum[i] = sum[i - 1] + u;       }       sort(sum + 1, sum + 1 + n);       int len = unique(sum + 1, sum + 1 + n) - (sum + 1);       for (int i = 1; i <= k; i++) {         int u;         scanf( %d , &u);         for (int j = 1; j <= len; j++) {           v.push_back(u - sum[j]);         }       }       sort(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         mp[v[i]]++;       }       int res = 0;       for (int i = 0; i < v.size(); i++) {         if (mp[v[i]] >= k) {           res++;           mp[v[i]] = 0;         }       }       printf( %d n , res);     }   }   int main() {     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAX_N = 200002;   int n;   int a[MAX_N], t[MAX_N];   void solve() {     vector<pair<int, int>> v;     for (int i = 0; i < n; ++i) v.emplace_back(a[i], t[i]);     sort(v.begin(), v.end());     ll cur = -1;     int idx = 0;     multiset<ll> eq;     ll ans = 0, sum = 0;     while (idx < n || !eq.empty()) {       if (eq.empty()) cur = v[idx].first;       while (idx < n && v[idx].first == cur) {         sum += v[idx].second;         eq.insert(-v[idx].second);         idx++;       }       sum += *eq.begin();       eq.erase(eq.begin());       ans += sum;       cur++;     }     cout << ans <<   n ;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> t[i];     solve();     return 0;   }