malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int MAXN = 1000000007;   const int z = 0;   using namespace std;   int main() {     int k, l, m, n, d, ans = 0;     cin >> k >> l >> m >> n >> d;     for (int i = 1; i <= d; i++) {       if (i % k == 0 or i % l == 0 or i % m == 0 or i % n == 0) {         ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt, c = 0;     cin >> tt;     while (tt) {       int n = tt;       set<int> data;       while (n % 2 == 0) {         data.insert(2);         n = n / 2;       }       for (int i = 3; i <= sqrt(n); i = i + 2) {         while (n % i == 0) {           data.insert(i);           n = n / i;         }       }       if (n > 2) data.insert(n);       if (data.size() == 2) {         c++;       }       tt--;     }     cout << c << endl;     cerr <<  Time :   << (float)clock() / CLOCKS_PER_SEC <<   s  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   constexpr int INF = 1001001001;   constexpr int mod = 1000000007;   template <class T>   inline bool chmax(T& x, T y) {     if (x < y) {       x = y;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& x, T y) {     if (x > y) {       x = y;       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     vector<int> a(n + 2), ban(k + 2);     a[0] = -1e+7, a[n + 1] = INF;     ban[0] = 0, ban[k + 1] = n + 1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] -= i;     }     for (int i = 1; i <= k; ++i) cin >> ban[i];     int ans = 0;     for (int i = 0; i <= k; ++i) {       int lb = a[ban[i]], ub = a[ban[i + 1]];       if (ub - lb < 0) {         cout << -1 << endl;         return 0;       }       vector<int> vals;       int cnt = 0;       int s = ban[i] + 1, t = ban[i + 1];       for (int j = s; j < t; ++j) {         if (a[j] < lb || a[j] > ub)           ++cnt;         else           vals.emplace_back(a[j]);       }       int m = vals.size();       vector<int> dp(m, INF);       for (int j = 0; j < m; ++j) {         *upper_bound(dp.begin(), dp.end(), vals[j]) = vals[j];       }       cnt += dp.end() - lower_bound(dp.begin(), dp.end(), INF);       ans += cnt;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[1000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long int answer = 0;     for (int i = 0; i < (n - 1); i++) {       if (a[i] == 1 && a[i + 1] == 2) {         answer += 3;       } else if (a[i] == 1 && a[i + 1] == 3) {         answer += 4;       } else if (a[i] == 2 && a[i + 1] == 1) {         answer += 3;       } else if (a[i] == 2 && a[i + 1] == 3) {         cout <<  Infinite ;         return 0;       } else if (a[i] == 3 && a[i + 1] == 1) {         answer += 4;         if (i < n - 2 && a[i + 2] == 2) {           answer -= 1;         }       } else if (a[i] == 3 && a[i + 1] == 2) {         cout <<  Infinite ;         return 0;       }     }     cout <<  Finite  << endl;     cout << answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a = (s.size() + 1) / 2 - 1;     int b = s.size() / 2 - 1;     bool f00 = false, f01 = false, f10 = false, f11 = false;     int cq = 0, c0 = 0, c1 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 )         c0++;       else if (s[i] ==  1 )         c1++;       else         cq++;     }     if (cq + c1 >= a + 2) f11 = true;     if (c1 <= a) f00 = true;     if (c1 <= a + 1 and c1 + cq >= a + 1) {       int q1 = (a + 1) - c1;       int q0 = cq - q1;       if (s.back() ==  ? ) {         if (q1) f01 = true;         if (q0) f10 = true;       } else if (s.back() ==  0 )         f10 = true;       else         f01 = true;     }     if (f00) printf( 00 n );     if (f01) printf( 01 n );     if (f10) printf( 10 n );     if (f11) printf( 11 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     double a, b, Zero = 0.5, One = 1.0;     scanf( %d , &t);     while (t--) {       scanf( %lf%lf , &a, &b);       if (a == 0 && b == 0)         printf( %.10lf n , One);       else if (a == 0)         printf( %.10lf n , Zero);       else if (b == 0)         printf( %.10lf n , One);       else if (a >= 4 * b) {         float area = 0.5 * 4 * b * b;         area = 2 * a * b - area;         area /= 2 * a * b;         printf( %.10lf n , area);       } else {         float area = 0.5 * a * a * 0.25 + a * b;         area /= 2 * a * b;         printf( %.10lf n , area);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e5 + 5, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131,             MOD2 = 1000136437;   const double EPS = 1e-9;   long double w, h, theta;   complex<double> rotate(complex<double> &p, double a) {     return p * polar(1.0, a);   }   int doubleComp(const double &a, const double &b) {     return fabs(a - b) < EPS ? 0 : a < b ? -1 : 1;   }   bool lineInter(const complex<double> &A, const complex<double> &B,                  const complex<double> &P, const complex<double> &Q,                  complex<double> &R, bool isSegA = false, bool isSegB = false) {     double d1 = ((conj(P - A) * (B - A)).imag());     double d2 = ((conj(Q - A) * (B - A)).imag());     if (fabs(d1 - d2) < EPS) return false;     R = (d1 * Q - d2 * P) / (d1 - d2);     if (isSegA &&         doubleComp(hypot(A.real() - B.real(), A.imag() - B.imag()),                    hypot(A.real() - R.real(), A.imag() - R.imag()) +                        hypot(B.real() - R.real(), B.imag() - R.imag())) != 0)       return false;     if (isSegB &&         doubleComp(hypot(P.real() - Q.real(), P.imag() - Q.imag()),                    hypot(P.real() - R.real(), P.imag() - R.imag()) +                        hypot(Q.real() - R.real(), Q.imag() - R.imag())) != 0)       return false;     return true;   }   void polygonCut(const complex<double> &a, const complex<double> &b,                   const vector<complex<double> > &v,                   vector<complex<double> > &ret) {     ret.clear();     for (int i = 0; i < (int)(v).size(); i++) {       int j = (i + 1) % (int)(v).size();       if (((conj(((b) - (a))) * (((v[i]) - (a)))).imag()) >= 0)         ret.push_back(v[i]);       complex<double> r;       if (lineInter(a, b, v[i], v[j], r, 0, 1)) ret.push_back(r);     }   }   void polygonIntersection(const vector<complex<double> > &poly1,                            const vector<complex<double> > &poly2,                            vector<complex<double> > &ret) {     vector<complex<double> > r2;     ret = poly1;     for (int i = 0; i < (int)(poly2).size(); i++) {       int j = (i + 1) % (int)(poly2).size();       polygonCut(poly2[i], poly2[j], ret, r2);       ret = r2;     }   }   double areaPolygon(vector<complex<double> > p) {     double area = 0.0;     for (int i = 0, n = (int)(p).size(); i < n; i++)       area += ((conj(p[i]) * (p[(i + 1) % n])).imag());     return abs(area) / 2.0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> w >> h >> theta;     vector<complex<double> > p, p2, ans;     w /= 2;     h /= 2;     p.push_back(complex<double>(w, h));     p.push_back(complex<double>(-w, h));     p.push_back(complex<double>(-w, -h));     p.push_back(complex<double>(w, -h));     p2 = p;     theta = (theta / 180.0) * (2 * acos(0));     for (auto &i : p2) i = rotate(i, theta);     polygonIntersection(p, p2, ans);     cout << fixed << setprecision(6) << areaPolygon(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[1 << 21], *p1 = buf, *p2 = buf;   int read() {     int w = 0, f = 1;     char c =    ;     while (c <  0  || c >  9 )       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++),       f = c ==  -  ? -1 : f;     while (c >=  0  && c <=  9 )       w = w * 10 + c - 48,       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     return w * f;   }   int n, m, a[1000005];   long long val[1000005 << 2], mod;   vector<long long> minn[1000005 << 2];   const long long inf = 1e18;   void pushup(int p, int l, int r, int mid) {     int ls = p << 1, rs = p << 1 | 1, it1 = 0, it2 = 0;     while (it1 <= mid - l + 1) {       while (it2 <= r - mid) {         long long L = max(minn[ls][it1], minn[rs][it2] - val[ls] + mod * it1),                   R = it1 == mid - l + 1 ? inf : minn[ls][it1 + 1] - 1;         if (L > R) break;         minn[p][it1 + it2] = min(minn[p][it1 + it2], L), it2++;       }       it2 = max(it2 - 1, 0), it1++;     }     val[p] = val[ls] + val[rs];   }   void build(int p, int l, int r) {     minn[p].resize(r - l + 2);     minn[p][0] = -inf;     for (int i = 1; i <= r - l + 1; i++) minn[p][i] = inf;     if (l == r) {       minn[p][1] = mod - a[l];       val[p] = a[l];       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     pushup(p, l, r, mid);   }   long long query(int p, int x, int y, long long v, int l, int r) {     if (x <= l && r <= y) {       int L = 0, R = r - l + 1, res = 0;       while (L <= R) {         int mid = (L + R) >> 1;         if (minn[p][mid] <= v)           res = mid, L = mid + 1;         else           R = mid - 1;       }       return v + val[p] - mod * res;     }     int mid = (l + r) >> 1;     if (y <= mid) return query(p << 1, x, y, v, l, mid);     if (x > mid) return query(p << 1 | 1, x, y, v, mid + 1, r);     return query(p << 1 | 1, x, y, query(p << 1, x, y, v, l, mid), mid + 1, r);   }   signed main() {     n = read(), m = read(), mod = read();     for (int i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     int l, r;     while (m--) {       l = read(), r = read();       printf( %lld n , query(1, l, r, 0, 1, n));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[601000];   long long m;   long long ans = 0;   long long len;   long long ll;   long long mod = 1;   long long reget(long long x) {     long long reans = (10 * (ll - ((long long)(s[x] -  0 ) * mod) % m + m) % m +                        (long long)(s[x] -  0 ) + m) %                       m;     return reans;   }   long long get(long long l, long long r) {     long long t = l;     long long temp = 0;     while (t <= r) {       if (temp >= m) temp = (temp % m + m) % m;       while (temp < m && t <= r) {         temp = temp * 10 + (long long)(s[t] -  0 );         t++;       }     }     temp = (temp + m) % m;     return temp;   }   int main() {     cin >> s;     len = strlen(s);     cin >> m;     ans = get(0, len - 1);     for (long long i = 1; i < len; i++) mod = (mod * 10 + m) % m;     ll = ans;     for (long long i = 0; i < len - 1; i++) {       ll = reget(i);       if (s[i + 1] ==  0 ) continue;       ans = min(ll, ans);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   const long long int N = 2e5 + 10;   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int n;     cin >> n;     string second;     cin >> second;     set<char> x;     if (n > 26) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       x.insert(second[i]);     }     cout << n - x.size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s;   struct substring {     int f, b;     bool operator>(const substring &o) const {       int cmp = s.compare(f, b - f + 1, s, o.f, o.b - o.f + 1);       return cmp != 0 ? cmp > 0 : f > o.f;     }   };   string kthSubstring(int k) {     priority_queue<substring, vector<substring>, greater<substring>> pq;     int len = s.length();     for (int i = 0; i < len; i++) {       pq.push({i, i});     }     while (!pq.empty()) {       int f = pq.top().f, b = pq.top().b;       pq.pop();       if (--k == 0) return s.substr(f, b - f + 1);       if (++b < len) {         pq.push({f, b});       }     }     return   ;   }   int main() {     int k;     cin >> s >> k;     int len = s.length();     long long possible = ((long long)len * (len + 1)) / 2;     if (k > possible)       cout <<  No such line.  <<   n ;     else       cout << kthSubstring(k) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   map<long long, pair<int, int> > mm;   int a[maxn];   int b[maxn];   long long s[maxn], s1[maxn];   int main() {     int i, j, n;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = s[i - 1] + a[i];     }     for (i = 1; i <= n; i++) {       scanf( %d , &b[i]);       s1[i] = s1[i - 1] + b[i];     }     int p = n;     if (s[n] <= s1[n]) {       i = n;       while (i >= 0) {         if (s[i] < s1[p]) {           p--;           continue;         }         if (mm.find(s[i] - s1[p]) != mm.end()) {           pair<int, int> p2 = mm[s[i] - s1[p]];           printf( %d n , p2.first - i);           for (j = i + 1; j <= p2.first; j++) printf( %d  , j);           printf(  n );           printf( %d n , p2.second - p);           for (j = p + 1; j <= p2.second; j++) printf( %d  , j);           printf(  n );           return 0;         }         mm[s[i] - s1[p]] = make_pair(i, p);         i--;       }     } else {       i = n;       while (i >= 0) {         if (s1[i] < s[p]) {           p--;           continue;         }         if (mm.find(s1[i] - s[p]) != mm.end()) {           pair<int, int> p2 = mm[s1[i] - s[p]];           printf( %d n , p2.second - p);           for (j = p + 1; j <= p2.second; j++) printf( %d  , j);           printf(  n );           printf( %d n , p2.first - i);           for (j = i + 1; j <= p2.first; j++) printf( %d  , j);           printf(  n );           return 0;         }         mm[s1[i] - s[p]] = make_pair(i, p);         i--;       }     }     printf( -1 n );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5;   int n;   int fa[N], r[N];   int rt[N], ls[N * 30], rs[N * 30], siz[N * 30], tot;   long long sum[N * 30], ans;   void update(int &rt, int l, int r, int p) {     if (!rt) rt = ++tot;     if (l == r) {       siz[rt] = 1, sum[rt] = p;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(ls[rt], l, mid, p);     else       update(rs[rt], mid + 1, r, p);     siz[rt] = siz[ls[rt]] + siz[rs[rt]];     sum[rt] = sum[ls[rt]] + sum[rs[rt]];   }   int merge(int x, int y) {     if (!x || !y) return x | y;     ans -= sum[ls[x]] * siz[rs[x]] + sum[ls[y]] * siz[rs[y]];     ls[x] = merge(ls[x], ls[y]);     rs[x] = merge(rs[x], rs[y]);     ans += sum[ls[x]] * siz[rs[x]];     siz[x] += siz[y];     sum[x] += sum[y];     return x;   }   inline int findf(int x) { return x == fa[x] ? x : fa[x] = findf(fa[x]); }   void unify(int x, int y) {     x = findf(x), y = findf(y);     fa[y] = x;     ans -= sum[rt[x]] * x + sum[rt[y]] * y;     rt[x] = merge(rt[x], rt[y]);     ans += sum[rt[x]] * x;     r[x] = r[y];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= 400000; i++) fa[i] = i, r[i] = i;     for (int i = 1, a, b; i <= n; i++) {       scanf( %d%d , &a, &b);       int p = rt[a] ? r[findf(a)] + 1 : a;       ans -= 1ll * a * b;       ans += 1ll * p * b;       update(rt[p], 1, n, b);       if (rt[p - 1]) unify(p - 1, p);       if (rt[p + 1]) unify(p, p + 1);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int d[1005][1005][15][2];   char a[1005], b[1005];   int max(int a, int b) {     if (a < b) return b;     return a;   }   int main() {     int n, m, k, i, j, l;     scanf( %d %d %d , &n, &m, &k);     for (i = 1; i <= n; i++) scanf(  %c , &a[i]);     for (i = 1; i <= m; i++) scanf(  %c , &b[i]);     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         for (l = 1; l <= k; l++) {           d[i][j][l][1] = max(d[i - 1][j][l][1], d[i][j - 1][l][1]);           if (a[i] == b[j]) {             d[i][j][l][0] = max(d[i][j][l][0], d[i - 1][j - 1][l - 1][1] + 1);             d[i][j][l][0] = max(d[i][j][l][0], d[i - 1][j - 1][l][0] + 1);             d[i][j][l][1] = max(d[i][j][l][1], d[i - 1][j - 1][l][0] + 1);             d[i][j][l][1] = max(d[i][j][l][1], d[i][j][l][0]);           }         }       }     }     printf( %d , d[n][m][k][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     double r = (1 - 1.0 * a / b) * (1 - 1.0 * c / d);     r = 1.0 / (1 - r);     printf( %.10f n , r * a / b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, v, t, no = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p >> v >> t;       if (p + v + t >= 2) {         no++;       }     }     cout << no <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, t, a, b, da, db;     scanf( %d%d%d%d%d%d , &x, &t, &a, &b, &da, &db);     if (x == 0 || (x <= a && x > a - da * t && (a - x) % da == 0) ||         (x <= b && x > b - db * t && (b - x) % db == 0)) {       cout <<  YES  << endl;       return 0;     }     for (int i = 0; i < t; i++) {       for (int j = 0; j < t; j++) {         if ((a - j * da) + (b - i * db) == x) {           printf( YES );           return 0;         }       }     }     printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 100005;   int n, k;   char s[NMAX];   int sum[NMAX];   int get(int l, int r) {     l = max(1, l);     r = min(r, n);     return sum[r] - sum[l - 1];   }   int main() {     cin.sync_with_stdio(false);     cin >> n >> k;     cin >> (s + 1);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (s[i] ==  0 );     int ans = 1 << 30;     for (int i = 1; i <= n; i++)       if (s[i] ==  0 ) {         int l = 1;         int r = n;         int sol = -1;         while (l <= r) {           int mi = (l + r) / 2;           if (get(i - mi, i - 1) + get(i + 1, i + mi) >= k) {             sol = mi;             r = mi - 1;           } else             l = mi + 1;         }         if (sol != -1) ans = min(ans, sol);       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, f = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   const int P = 998244353;   const int N = 1e7 + 5;   long long fsp(long long x, int y = P - 2) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % P;       x = x * x % P, y >>= 1;     }     return ans;   }   long long inv[N];   int n, m, a[N], b[N], f[N];   void Add(int &x, int y) {     x += y;     if (x < 0) x += P;     if (x >= P) x -= P;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read(), m += a[i];     b[n] = m;     inv[1] = 1;     for (int i = 2; i <= m; i++) inv[i] = (P - P / i) * inv[P % i] % P;     long long im = fsp(m), in = fsp(n - 1);     for (int i = 1; i < m; i++) {       long long inv1 = inv[m - i] * m % P * (n - 1) % P;       long long inv2 = (1 - im * in % P * (m - i) % P * (n - 2) % P + P) % P;       f[i + 1] =           inv1 * (inv2 * f[i] % P - i * im % P * (f[i - 1] + 1) % P + P) % P;     }     int ans = 0;     for (int i = 1; i <= n; i++) Add(ans, f[a[i]]);     for (int i = 1; i <= n; i++) Add(ans, P - f[b[i]]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ans[300][300];   string s;   int cnt[300];   int bal[300];   int n, m;   void f(int l, int r, int ll, int rr) {     if (l + 1 == r) {       for (int i = 0; i < n / 2 - bal[r]; ++i) {         ans[n / 2 + i][ll] =  | ;         ans[n / 2 - i][ll] =  | ;         ans[n / 2 + i][rr] =  | ;         ans[n / 2 - i][rr] =  | ;       }       ans[bal[l] - 1][ll] =  + ;       ans[n - bal[l]][ll] =  + ;       ans[bal[l] - 1][rr] =  + ;       ans[n - bal[l]][rr] =  + ;       ans[bal[l] - 1][ll + 1] =  - ;       ans[n - bal[l]][ll + 1] =  - ;       ans[bal[l] - 1][rr - 1] =  - ;       ans[n - bal[l]][rr - 1] =  - ;       if (ll + 4 != rr) {         throw 1;       }       return;     }     int q = l;     int bl = 0;     for (q = l; q <= r; ++q) {       if (s[q] ==  [ ) {         ++bl;       } else {         --bl;       }       if (bl == 0) {         break;       }     }     if (q == r) {       for (int i = 0; i < n / 2 - bal[r]; ++i) {         ans[n / 2 + i][ll] =  | ;         ans[n / 2 - i][ll] =  | ;         ans[n / 2 + i][rr] =  | ;         ans[n / 2 - i][rr] =  | ;       }       ans[bal[l] - 1][ll] =  + ;       ans[n - bal[l]][ll] =  + ;       ans[bal[l] - 1][rr] =  + ;       ans[n - bal[l]][rr] =  + ;       ans[bal[l] - 1][ll + 1] =  - ;       ans[n - bal[l]][ll + 1] =  - ;       ans[bal[l] - 1][rr - 1] =  - ;       ans[n - bal[l]][rr - 1] =  - ;       f(l + 1, r - 1, ll + 1, rr - 1);       return;     }     int qq = ll + q - l + (cnt[q] - cnt[l]) * 3;     f(l, q, ll, qq);     f(q + 1, r, qq + 1, rr);   }   int main() {     memset(ans,    , sizeof(ans));     int qwe;     cin >> qwe;     cin >> s;     int bl = 0;     int mx = 0;     for (int i = 0; i < s.size(); ++i) {       if (s[i] ==  [ ) {         ++bl;         mx = max(mx, bl);       } else {         if (s[i - 1] ==  [ ) {           cnt[i] = 1;         }         --bl;       }       bal[i] = bl;       cnt[i] += i > 0 ? cnt[i - 1] : 0;     }     n = mx * 2 + 1;     m = s.size() + cnt[s.size() - 1] * 3;     f(0, s.size() - 1, 0, m - 1);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cout << ans[i][j];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, t, sum = 0, a, b, p;     cin >> t;     while (t--) {       bool fg = 0;       p = 0;       k = 0;       sum = 0;       cin >> a >> b;       string s;       cin >> s;       n = s.size();       for (long long int i = 0; i <= n - 1; i++) {         if (s[i] ==  1 ) {           if (fg == 0) {             p += a;             fg = 1;             k = 0;           } else if (k > 0) {             p += min(k * b, a);             k = 0;             continue;           }         } else           k++;       }       cout << p << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a;   int main() {     scanf( %d%d , &n, &m);     if (n == 1)       printf( 1 n );     else {       if (m > n / 2)         printf( %d n , m - 1);       else         printf( %d n , m + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string ALICE =  Alice , BOB =  Bob ;   void solve_case() {     int N, K;     cin >> N >> K;     if (K % 3 != 0) {       cout << (N % 3 != 0 ? ALICE : BOB) <<   n ;       return;     }     N %= K + 1;     cout << (N % 3 == 0 && N < K ? BOB : ALICE) <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T-- > 0) solve_case();   }
#include <bits/stdc++.h>   using namespace std;   int a[105][105], u[105], v[105];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     for (int j = 0; j < m; j++) {       int cnt[105] = {};       for (int i = 0; i < n; i++)         if (!u[i]) ++cnt[a[i][j]];       for (int i = 0; i < n; i++)         if (!u[i] && a[i][j]) {           if (v[a[i][j]])             u[i] = j + 1;           else if (cnt[a[i][j]] >= 2)             u[i] = v[a[i][j]] = j + 1;         }     }     for (int i = 0; i < n; i++) printf( %d n , u[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (2 * m >= n)       cout << 0;     else       cout << n - 2 * m;     cout <<    ;     for (long long i = 0; i <= n; i++) {       if ((i * (i - 1)) / 2 >= m) {         cout << n - i;         break;       }     }     return 0;   }