malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using ld = long double;   const int MN = 5e5 + 5, MM = 1e6 + 3;   vector<int> bs;   struct Lady {     int a, b, c;   } ladies[MN];   int bit[MN];   int n;   void update(int i, int v) {     for (i = MN - i; i < MN; i += i & -i) bit[i] = max(bit[i], v);   }   int query(int i) {     int ret = 0;     for (i = MN - i; i; i ^= i & -i) ret = max(ret, bit[i]);     return ret;   }   void getb(int &b) {     b = lower_bound((bs).begin(), (bs).end(), b) - bs.begin() + 1;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &ladies[i].a);     for (int i = 1; i <= n; i++)       scanf( %d , &ladies[i].b), bs.push_back(ladies[i].b);     for (int i = 1; i <= n; i++) scanf( %d , &ladies[i].c);     sort((bs).begin(), (bs).end());     for (Lady &l : ladies) getb(l.b);     sort(ladies + 1, ladies + 1 + n, [](Lady a, Lady b) { return a.a > b.a; });     vector<Lady> toadd;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (ladies[i].a != ladies[i - 1].a) {         for (Lady &l : toadd) update(l.b, l.c);         toadd.clear();       }       toadd.push_back(ladies[i]);       ans += query(ladies[i].b + 1) > ladies[i].c;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<double, double> > a;   pair<double, double> cur;   double r;   void findmax(pair<double, double> p) {     double y =         sqrt(2 * r * 2 * r - abs(p.first - cur.first) * abs(p.first - cur.first));     y += p.second;     cur.second = max(cur.second, y);   }   void doit(double x) {     for (double k = 0; k < a.size(); k++) {       if (abs(x - a[k].first) <= 2 * r) findmax(a[k]);     }     a.push_back(cur);   }   int main() {     double x, n;     cin >> n >> r;     for (double k = 0; k < n; k++) {       cin >> x;       cur.first = x;       cur.second = r;       doit(x);     }     for (double k = 0; k < a.size(); k++)       cout << setprecision(17) << a[k].second <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int b[100];     for (int i = 0; i < 100; i++) b[i] = 0;     int x;     for (int i = 0; i < n; i++) {       cin >> x;       b[x - 1] += 1;     }     x = b[0];     for (int i = 0; i < 100; i++) {       if (b[i] > x) {         x = b[i];       }     }     if (x % k == 0)       x = x / k;     else       x = x / k + 1;     x = x * k;     k = 0;     for (int i = 0; i < 100; i++)       if (b[i]) {         k += x - b[i];       }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int point, w;   } p[30][30];   int n, m;   int s[30][30], w[30][30], Min[30], f[3000000];   int Get() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   void init(int x, int y) {     int t1 = 0, t2 = 0, mx = 0;     for (int i = 1; i <= n; i++)       if (s[i][y] == s[x][y]) {         t1 |= 1 << (i - 1);         t2 += w[i][y];         mx = max(mx, w[i][y]);       }     p[x][y] = (node){t1, t2 - mx};   }   int Getlow(int x) {     int ss[200];     int num = 0;     if (x == 0) return 1;     while (x) {       ss[++num] = x % 2;       x /= 2;     }     ss[++num] = 0;     for (int i = 1; i <= num; i++)       if (ss[i] == 0) return i;   }   int main() {     for (int i = 1; i <= 29; i++) Min[i] = 19240012;     for (int i = 1; i <= 3000000 - 1; i++) f[i] = 30000000;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) s[i][j] = Get();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> w[i][j];         Min[i] = min(Min[i], w[i][j]);       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) init(i, j);     f[0] = 0;     for (int i = 0; i < (1 << n); i++) {       int p_ = Getlow(i);       f[i | (1 << (p_ - 1))] = min(f[i | (1 << (p_ - 1))], f[i] + Min[p_]);       for (int j = 1; j <= m; j++)         f[i | p[p_][j].point] = min(f[i | p[p_][j].point], f[i] + p[p_][j].w);     }     cout << f[(1 << n) - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int ctra = 0;     int ctrb = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  A ) {         ctra++;       } else {         ctrb++;       }     }     if (ctra > ctrb) {       cout <<  Anton ;     } else if (ctra < ctrb) {       cout <<  Danik ;     } else {       cout <<  Friendship ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z;     cin >> a >> b >> c;     cin >> x >> y >> z;     a -= x;     b -= y;     c -= z;     if (a >= 0) a /= 2;     if (b >= 0) b /= 2;     if (c >= 0) c /= 2;     if (a + b + c >= 0)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, tot, Trie[2000000 + 5][2], Num[2000000 + 5];   long long x;   char s[9], ch[20];   int main() {     for (scanf( %d , &n); n; n--) {       scanf( %s , s);       if (s[0] ==  ? ) {         scanf( %s , ch);         int len = strlen(ch), u = 0, ans;         for (int i = 1; i <= 19; i++) {           int j = 0;           if (i <= len) {             j = ch[len - i] -  0 ;             ch[len - i] =   0 ;           }           if (!Trie[u][j]) {             u = -1;             break;           }           u = Trie[u][j];         }         if (!~u)           ans = 0;         else           ans = Num[u];         printf( %d n , ans);       } else {         scanf( %I64d , &x);         for (int i = 0, u = 0; i <= 18 || x; i++, x /= 10) {           int j = (x % 10) & 1;           if (!Trie[u][j]) Trie[u][j] = ++tot;           u = Trie[u][j];           Num[u] += (s[0] ==  +  ? 1 : -1);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[300100], l[300100];   vector<int> e[300100];   int f(int x) {     while (x != p[x]) {       x = p[x] = p[p[x]];     }     return x;   }   pair<int, int> L(int x, int p) {     int lon = 0, h1 = 0, h2 = 0, S = e[x].size();     pair<int, int> R;     for (int i = 0; i < S; i++) {       if (p == e[x][i]) continue;       R = L(e[x][i], x);       if (R.first > h1) {         h2 = max(h1, h2);         h1 = R.first;       } else if (R.first > h2) {         h2 = R.first;       }       if (R.second > lon) lon = R.second;     }     lon = max(h1 + h2, lon);     return pair<int, int>(h1 + 1, lon);   }   int main() {     stringstream ss;     memset(l, 0, sizeof(l));     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < n; i++) p[i] = i;     int a, b;     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       a--;       b--;       e[a].push_back(b);       e[b].push_back(a);     }     bitset<300100> B;     queue<int> Q;     for (int i = 0; i < n; i++) {       if (!B.test(i)) {         B.set(i);         Q.push(i);         while (!Q.empty()) {           int x = Q.front();           Q.pop();           for (int j = 0; j < e[x].size(); j++) {             if (!B.test(e[x][j])) {               B.set(e[x][j]);               Q.push(e[x][j]);               p[e[x][j]] = i;             }           }         }         l[i] = L(i, i).second;       }     }     int c, x, y;     for (int i = 0; i < q; i++) {       scanf( %d , &c);       if (c == 2) {         scanf( %d %d , &x, &y);         x--;         y--;         x = f(x);         y = f(y);         if (x != y) {           int m = max(l[x], l[y]);           l[x] = max(m, (l[x] + 1) / 2 + (l[y] + 1) / 2 + 1);           p[y] = x;         }       } else if (c == 1) {         scanf( %d , &x);         x--;         printf( %d n , l[f(x)]);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 3e5 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000005329;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 555;   int n;   long long a, b, c, mx, ans, nw;   string s[MAX];   int main() {     cout << fixed << setprecision(10);     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) cin >> s[i];     for (char tgt =  a ; tgt <=  z ; ++tgt) {       nw = 0;       for (long long i = 1; i <= n; ++i) {         a = b = c = mx = 0;         reverse(s[i].begin(), s[i].end());         for (char j : s[i]) {           if (j != tgt) break;           ++a;         }         reverse(s[i].begin(), s[i].end());         for (char j : s[i]) {           if (j != tgt) break;           ++b;         }         for (char j : s[i]) {           if (j != tgt)             c = 0;           else             ++c, mx = max(c, mx);         }         if (mx == s[i].size())           nw = min(MOD, nw + (nw + 1) * mx);         else           nw = max(nw ? a + b + 1 : 0, mx);       }       ans = max(ans, nw);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       map<string, int> m;       int ans = 0;       vector<string> a, b;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         if (m[s] != 0) ans++;         m[s]++;         b.push_back(s);       }       for (int i = 0; i < n; i++) {         string s;         s = b[i];         if (m[s] != 1) {           m[s]--;           while (true) {             if (s[3] ==  9 )               s[3] =  0 ;             else               s[3] = ((int)s[3] + 1);             if (m[s] == 0) {               m[s]++;               a.push_back(s);               break;             }           }         } else {           a.push_back(s);         }       }       cout << ans << endl;       for (int i = 0; i < a.size(); i++) {         cout << a[i] << endl;       }     }     return 0;   }
#define _CRT_SECURE_NO_WARNINGS    #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   #define all(x) x.begin(), x.end()   #define rall(x) x.rbegin(), x.rend()   //#define endl   n    #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }      ll mod = 998244353;      ll binpow(ll a, ll n) {    ll res = 1;    while (n) {     if (n & 1)      res = (1LL * res * a) % mod;     a = (1LL * a * a) % mod;        n >>= 1;    }    return res;   }      signed main() {    int q = 1;    //cin >> q;    while (q--) {     int n;     cin >> n;     vector<ll> dp(n + 3, 0);     dp[1] = 1, dp[2] = 1;     for (int i = 3; i <= n; ++i) {      dp[i] = dp[i - 1] + dp[i - 2];      if (dp[i] >= mod) dp[i] -= mod;     }     cout << (dp[n] * binpow(binpow(2, n), mod - 2)) % mod;    }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100;   int n, k[N];   double p[N], p_log[N], p_log_1[N];   priority_queue<pair<double, int>> s;   inline double P(int i, int k) {     double x = pow(p[i], k);     if (x > 1e-6) return log(1 - x);     x = -x;     return x - x * x / 2 + x * x * x / 3;   }   void add(int i) { s.push(make_pair(P(i, k[i] + 1) - P(i, k[i]), i)); }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     if (n == 1) {       puts( 1 );       return 0;     }     for (int i = 0; i < (int)(n); i++) {       int a;       cin >> a;       p[i] = 1 - a * 1e-2;       p_log[i] = log(p[i]);       p_log_1[i] = log(1 - p[i]);     }     double sum = 0;     int cnt = n;     for (int i = 0; i < (int)(n); i++) sum += P(i, k[i] = 1);     double res = exp(sum) * cnt;     for (int i = 0; i < (int)(n); i++) add(i);     while (cnt <= 1e6) {       cnt++;       int i = s.top().second;       s.pop();       sum -= P(i, k[i]);       double x = cnt * exp(sum + p_log[i] * k[i]) * (1 - p[i]);       res += x;       sum += P(i, ++k[i]);       add(i);     }     printf( %.15f n , (double)res);     fprintf(stderr,  time = %.2f, cnt = %d n , 1. * clock() / CLOCKS_PER_SEC,             cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f);     for (x = ch ^ 48; isdigit(ch = getchar());          x = (x << 3) + (x << 1) + (ch ^ 48))       ;     return x * f;   }   const long long N = 2e5 + 66;   long long n, m, k, A, B, C, AB, tmp1, tmp2, a[N], b[N], tag[N], taga[N],       tagb[N], tagab[N];   long long n1[N], n2[N], n3[N];   long long suma[N], sumb[N], sumc[N], sum, ans;   bool visa[N], visb[N];   struct seg {     long long a, b, c;   } tr[N << 2];   void up(long long o) {     tr[o].a = tr[(o << 1 | 1)].a;     tr[o].b = tr[(o << 1 | 1)].b;     tr[o].c = tr[(o << 1 | 1)].c;   }   void build(long long o, long long l, long long r) {     if (l == r) {       tr[o].a = n1[l];       tr[o].b = n2[l];       tr[o].c = n3[l];       return;     }     build((o << 1), l, ((l + r) >> 1));     build((o << 1 | 1), ((l + r) >> 1) + 1, r);     up(o);   }   long long query(long long o, long long l, long long r, long long a) {     if (l == r)       return suma[max(tr[o].a, a)] + sumb[max(tr[o].b, a)] + sumc[tr[o].c] -              b[l] * (max(tr[o].a, a) + max(tr[o].b, a) + tr[o].c + k - a - m);     long long t =         max(tr[(o << 1)].a, a) + max(tr[(o << 1)].b, a) + tr[(o << 1)].c + k - a;     if (t >= m)       return query((o << 1), l, ((l + r) >> 1), a);     else       return query((o << 1 | 1), ((l + r) >> 1) + 1, r, a);   }   signed main() {     n = read();     m = read();     k = read();     for (long long i = 1; i <= n; i++) a[i] = read(), b[i] = a[i];     sort(b + 1, b + 1 + n);     long long cur = unique(b + 1, b + 1 + n) - b - 1;     for (long long i = 1; i <= n; i++)       a[i] = lower_bound(b + 1, b + 1 + cur, a[i]) - b;     tmp1 = read();     for (long long i = 1; i <= tmp1; i++) visa[read()] = 1;     tmp2 = read();     for (long long i = 1; i <= tmp2; i++) visb[read()] = 1;     for (long long i = 1; i <= n; i++) {       if (visa[i] && visb[i])         tagab[++AB] = b[a[i]];       else if (visa[i])         taga[++A] = b[a[i]], n1[a[i]]++;       else if (visb[i])         tagb[++B] = b[a[i]], n2[a[i]]++;       else         tag[++C] = b[a[i]], n3[a[i]]++;     }     if (k > m || (AB + A < k) || (AB + B < k)) {       puts( -1 );       return 0;     }     sort(tagab + 1, tagab + 1 + AB);     sort(taga + 1, taga + 1 + A);     sort(tagb + 1, tagb + 1 + B);     sort(tag + 1, tag + 1 + C);     for (long long i = 1; i <= cur; i++)       n1[i] += n1[i - 1], n2[i] += n2[i - 1], n3[i] += n3[i - 1];     for (long long i = 1; i <= A; i++) suma[i] = suma[i - 1] + taga[i];     for (long long i = 1; i <= B; i++) sumb[i] = sumb[i - 1] + tagb[i];     for (long long i = 1; i <= C; i++) sumc[i] = sumc[i - 1] + tag[i];     build(1, 0, cur);     sum = 0;     ans = 1ll << 60;     for (long long i = 0, tmp; i <= min(AB, m); i++) {       sum += tagab[i];       if (min(A, B) >= k - i && 2 * k - i <= m && i + A + B + C >= m)         ans = min(ans, sum + (tmp = query(1, 0, cur, k - i)));     }     if (ans == (1ll << 60))       puts( -1 );     else       printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int x, index;   } a[1010];   bool cmp(node x, node y) {     if (x.x != y.x)       return x.x > y.x;     else       return x.index > y.index;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].x);       a[i].index = i;     }     sort(a + 1, a + n + 1, cmp);     int SUM = 0;     for (int i = 1; i <= n; i++) {       SUM += ((i - 1) * a[i].x + 1);     }     printf( %d n , SUM);     for (int i = 1; i <= n; i++) {       printf( %d  , a[i].index);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long int n, a, b, x, y;       cin >> n;       x = 1 + (n - 1) / 3;       long long int sum = 0, k = 1;       while (sum < x) {         sum += k;         k <<= 2;       }       k >>= 2;       sum -= k;       y = a = (x - sum - 1 + k);       int c[] = {0, 2, 3, 1};       k = 1, b = 0;       while (y) {         b += c[y % 4] * k;         k <<= 2;         y >>= 2;       }       x = a ^ b;       if (n % 3 == 1) {         cout << a << endl;       } else if (n % 3 == 2) {         cout << b << endl;       } else         cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   namespace _c {   const double pi = acos(-1.0);   namespace min {   const int i8 = -128;   const int i16 = -32768;   const int i = -2147483647 - 1;   const long long l = -9223372036854775807LL - 1;   }  // namespace min   namespace max {   const int i8 = 127;   const int i16 = 32767;   const int i = 2147483647;   const long long l = 9223372036854775807LL;   }  // namespace max   }  // namespace _c   namespace _f {   template <typename T>   inline const T gcd(T m, T n) {     while (n != 0) {       T t = m % n;       m = n;       n = t;     }     return m;   }   template <typename T>   inline const T max(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline const T min(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline const T abs(const T &a) {     return a > 0 ? a : -a;   }   }  // namespace _f   namespace io {   template <typename T>   inline void read(T &t) {     register T res = 0, neg = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = -1;       }     }     for (; isdigit(c); c = getchar()) {       res = res * 10 + c -  0 ;     }     t = res * neg;   }   inline int in() {     register int T;     read(T);     return T;   }   inline long long in_ll() {     register long long T;     read(T);     return T;   }   }  // namespace io   int n;   double a[110], ans;   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; i++) {       scanf( %lf , a + i);     }     if (~n & 1) {       ans = a[n / 2];     }     for (int i = 0; i * 2 <= n; i++) {       for (int j = n; j > n / 2; j--) {         ans = _f::max(ans,                       ((n - 2 * i) * a[j] + (2 * j - n) * a[i]) / (2 * (j - i)));       }     }     printf( %.9lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   const int INF = 1 << 30;   int n, m, D;   int a[MAX];   vector<int> v[MAX];   int down[MAX];   inline void Down(int x, int fa) {     int res = -1;     for (int i = 0; i < v[x].size(); i++) {       int next = v[x][i];       if (next == fa) continue;       Down(next, x);       res = max(res, down[next]);     }     if (res != -1) down[x] = max(down[x], res + 1);   }   int up[MAX];   inline void Up(int x, int fa) {     int max1 = -1, max2 = -1;     for (int i = 0; i < v[x].size(); i++) {       int next = v[x][i];       if (next == fa) continue;       if (down[next] > max1)         max2 = max1, max1 = down[next];       else if (down[next] > max2)         max2 = down[next];     }     int res = -1;     for (int i = 0; i < v[x].size(); i++) {       int next = v[x][i];       if (next == fa) continue;       if (up[x] != -1) up[next] = max(up[next], up[x] + 1);       int val = (down[next] == max1 ? max2 : max1);       if (val != -1) up[next] = max(up[next], val + 2);       Up(next, x);     }   }   int main() {     scanf( %d%d%d , &n, &m, &D);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     memset(down, -1, sizeof(down));     memset(up, -1, sizeof(up));     for (int i = 1; i <= m; i++) down[a[i]] = up[a[i]] = 0;     Down(1, 0);     Up(1, 0);     int ans = 0;     for (int i = 1; i <= n; i++)       if (up[i] <= D && down[i] <= D) ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   double Max(double x, double y, double d) {     double temp = (x - d) * (y + d);     temp = max((x - d) * (y - d), temp);     temp = max((x + d) * (y - d), temp);     temp = max((x + d) * (y + d), temp);     return temp;   }   double Min(double x, double y, double d) {     double temp = (x - d) * (y - d);     temp = min((x - d) * (y + d), temp);     temp = min((x + d) * (y - d), temp);     temp = min((x + d) * (y + d), temp);     return temp;   }   bool check(double x) {     double l1 = Min(a, d, x);     double r1 = Max(a, d, x);     double l2 = Min(b, c, x);     double r2 = Max(b, c, x);     if (l1 <= r2 && r1 >= l2) return true;     return false;   }   int main() {     while (~scanf( %d %d %d %d , &a, &b, &c, &d)) {       double r = max(max(abs(a), abs(b)), max(abs(c), abs(d)));       double l = 0.0;       int num = 1000000;       while (num--) {         double mid = (l + r) / 2.0;         if (check(mid))           r = mid;         else           l = mid;       }       printf( %.11lf n , l);     }   }
#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   long long quick_mod(long long a, long long b) {     long long ans = 1;     a %= p;     while (b) {       if (b & 1) {         ans = ans * a % p;         b--;       }       b >>= 1;       a = a * a % p;     }     return ans;   }   long long C(long long n, long long m) {     if (m > n) return 0;     long long ans = 1;     for (int i = 1; i <= m; i++) {       long long a = (n + i - m) % p;       long long b = i % p;       ans = ans * (a * quick_mod(b, p - 2) % p) % p;     }     return ans;   }   long long Lucas(long long n, long long m) {     if (m == 0) return 1;     return C(n % p, m % p) * Lucas(n / p, m / p) % p;   }   int main() {     long long ans = 1;     int n, cnt, x;     scanf( %d%d , &n, &cnt);     for (int i = 2; i <= n; i++) {       scanf( %d , &x);       long long t = C(cnt + x - 1, x - 1) % p;       ans = ans * t % p;       cnt += x;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int cnt = 0, rem = m;     int arr[10000];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       if (rem >= arr[i])         rem -= arr[i];       else {         cnt++;         rem = m;         rem -= arr[i];       }     }     cout << cnt + 1;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200500];   long long res[200500];   long long n;   bool check(long long x) {     for (long long i = 0; i < n; i++) {       res[i] = 0;     }     for (long long i = n - 1; i >= 2; i--) {       long long f = (a[i] + res[i]) - x;       if (f < 0) {         return false;       }       long long k = min((f / 3), (a[i] / 3));       res[i - 1] += k;       res[i - 2] += 2 * k;     }     if (a[0] + res[0] < x) {       return false;     }     if (a[1] + res[1] < x) {       return false;     }     return true;   }   signed main() {     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i < n; i++) {         cin >> a[i];       }       long long l = 0, r = 2000000000;       while (r - l > 1) {         long long mid = (l + r) / 2;         if (check(mid)) {           l = mid;         } else {           r = mid;         }       }       cout << l <<   n ;     }   }