malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, sum, dp[1 << 16], arc[16][16], d[16];   void Floyd() {     int k, i, j;     for (k = 0; k < n; k++)       for (i = 0; i < n; i++)         for (j = 0; j < n; j++) arc[i][j] = min(arc[i][j], arc[i][k] + arc[k][j]);   }   int getans() {     int i, j, x, t, totol;     Floyd();     for (i = 1; i < n; i++)       if (d[i] && arc[0][i] > 1000000007) return -1;     memset(dp, 0x7f, sizeof(dp));     dp[0] = 0;     totol = (1 << n) - 1;     for (t = 0; t <= totol; t++) {       for (i = 0; i < n; i++)         if (d[i] % 2 && (t & (1 << i))) break;       if (i == n) dp[t] = 0;       for (i = 0; i < n; i++)         if (d[i] % 2 && !(t & (1 << i)))           for (j = i + 1; j < n; j++)             if (d[j] % 2 && !(t & (1 << j)) && arc[i][j] < 1000000007)               dp[t | (1 << i) | (1 << j)] =                   min(dp[t | (1 << i) | (1 << j)], dp[t] + arc[i][j]);     }     if (dp[totol] > 1000000007) return -1;     return sum + dp[totol];   }   int main() {     int m;     while (~scanf( %d%d , &n, &m)) {       sum = 0;       memset(arc, 0x3f, sizeof(arc));       memset(d, 0, sizeof(d));       for (int i = 1; i <= m; i++) {         int x, y, l;         scanf( %d%d%d , &x, &y, &l);         sum += l;         x--, y--;         arc[y][x] = arc[x][y] = min(arc[x][y], l);         d[x]++, d[y]++;       }       printf( %d n , getans());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      typedef long long ll;   const int maxn=1e6+7;   const int inf=2e9;   const ll inff=1e18;   const ll mod=1e9+7;   #define pii pair<int,int>   #define mkp make_pair   #define F first   #define S second   #define pb push_back   #define sz(v) ((int)(v).size())   #define all(v) (v).begin(),(v).end()   //#define int ll      int32_t main(){    ios::sync_with_stdio(0); cin.tie(0);       int t; cin>>t;       while (t--) {           int n; cin>>n;           vector<int> v(n);           for (int &i:v) cin>>i;           sort(all(v));              ll ans=0;           for (int i=1;i<n;i++) ans+=(v[i]-v[i-1]);           for (int i=1;i<n;i++) {               ans-=i*1LL*(n-i)*(v[i]-v[i-1]);           }           cout<<ans<<  n ;       }   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   bool f(long long x, long long y, long long z) {     if ((k - x - y - z) < 0 || (k - x - y - z) % 3 != 0) return false;     long long m = max(x, max(y, z)), p = n - (k + 3 * m - (x + y + z));     if (p < 0 || p % 3 != 0) return false;     return true;   }   int main() {     int t;     ios_base::sync_with_stdio(0);     cin >> t;     for (int i = 0; i < t; i++) {       long long d1, d2;       cin >> n >> k >> d1 >> d2;       long long d = max(d1, d2);       if (f(0ll, d1, d1 + d2) || f(d1 + d2, d2, 0ll) || f(d1, 0ll, d2) ||           f(d - d1, d, d - d2))         cout <<  yes  << endl;       else         cout <<  no  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N, K, S;   int q[153];   vector<vector<int> > prev_, next_;   const int INF = 1e9;   int main() {     scanf( %d%d%d , &N, &K, &S);     S = min(S, N * (N - 1) / 2);     for (int i = 1; i <= N; i++) scanf( %d , &q[i]);     prev_ = vector<vector<int> >(K + 1, vector<int>(S + 1, INF));     prev_[0][0] = 0;     for (int i = 1; i <= N; i++) {       next_ = prev_;       for (int j = 1; j <= min(K, i); j++)         for (int k = 0; k <= S; k++) {           if (k + abs(i - j) <= S)             next_[j][k + abs(i - j)] =                 min(next_[j][k + abs(i - j)], prev_[j - 1][k] + q[i]);         }       swap(prev_, next_);     }     int ans = INF;     for (int i = 0; i <= S; i++) ans = min(ans, prev_[K][i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const double eps = 1e-9;   const double INF = inf;   const double EPS = eps;   vector<long long> V;   int cmp(long long b, long double d, long long a) {     if (d > 2e18) return 1;     if (b > a) return 1;     if (b == a) return 0;     return -1;   }   int calc(long long n, long long p, long long k) {     long double d = (2.0 * k + 1.0) * (k + p - 1ll);     long long l = (2ll * k + 1) * (k + p - 1ll);     return cmp(l, d, n);   }   void solve(long long n, long long p) {     p = (1ll << p);     if (p - 1 > n) return;     long long l = 0, r = n + 1;     while (r - l > 1) {       long long m = (l + r) / 2;       (calc(n, p, m) <= 0) ? (l = m) : (r = m);     }     if (calc(n, p, l) == 0) V.push_back(p * (2ll * l + 1ll));   }   int main() {     long long n;     int i;     scanf( %I64d , &n);     for (i = 0; i < 60; i++) solve(n, i);     sort(V.begin(), V.end());     if (!V.size()) {       puts( -1 );       return 0;     }     for (i = 0; i < (int)V.size(); i++) printf( %I64d n , V[i]);     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double sn = 1e-6;   int n;   int arr[35];   int res;   bool visited[310][310];   bool notAgain[310][310][35][8];   pair<int, int> dirs[8] = {{0, 1},  {1, 1},   {1, 0},  {1, -1},                             {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};   void dfs(int dir, int sx, int sy, int sc) {     if (notAgain[sx][sy][sc][dir]) return;     notAgain[sx][sy][sc][dir] = true;     for (int i = 0; i < arr[sc]; i++) {       sx += dirs[dir].first;       sy += dirs[dir].second;       if (!visited[sx][sy]) {         visited[sx][sy] = true;         res++;       }     }     if (sc < n - 1) {       dfs(dir != 7 ? dir + 1 : 0, sx, sy, sc + 1);       dfs(dir != 0 ? dir - 1 : 7, sx, sy, sc + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     dfs(0, 155, 155, 0);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const signed long long int LINF = LLONG_MAX;   const double EPS = 1e-9;   const int MOD = 1000000007;   const int MAXN = 100001;   const int ALPH = 26;   const int DALPH = 52;   int q;   map<string, string> match, rmatch;   set<string> current;   int main() {     scanf( %d , &q);     while (q--) {       string s1, s2;       cin >> s1 >> s2;       if (current.find(s1) == current.end()) {         current.insert(s2);         match[s1] = s2;         rmatch[s2] = s1;       } else {         current.erase(s1);         current.insert(s2);         match[rmatch[s1]] = s2;         rmatch[s2] = rmatch[s1];         rmatch.erase(s1);       }     }     printf( %d n , (int)(match).size());     for (pair<string, string> p : match) {       cout << p.first <<     << p.second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005, maxm = 200005;   vector<int> g[maxn];   int tmp, vis[maxn], dis[maxn], mp[maxn][maxn];   int n, m, ans, cnt, tot, res, ecnt, info[maxn], nx[maxm], v[maxm];   int id, en, dfn[maxn], low[maxn], ori[maxn], sta[maxn], outd[maxn];   void add(int u1, int v1) {     nx[++ecnt] = info[u1];     info[u1] = ecnt;     v[ecnt] = v1;   }   void targin(int x, int fa) {     dfn[x] = low[x] = ++id;     sta[++en] = x;     for (int i = info[x]; i; i = nx[i]) {       if (v[i] == fa) continue;       if (!dfn[v[i]])         targin(v[i], x), low[x] = min(low[x], low[v[i]]);       else         low[x] = min(low[x], dfn[v[i]]);     }     if (low[x] == dfn[x]) {       int v;       cnt++;       do v = sta[en--], ori[v] = cnt;       while (v != x);     }   }   void dfs(int x, int fa) {     vis[x] = 1;     dis[x] = dis[fa] + 1;     if (dis[tmp] < dis[x]) tmp = x;     for (int i = 0, lim = g[x].size(); i < lim; i++)       if (g[x][i] != fa) dfs(g[x][i], x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, u1, v1; i <= m; i++)       scanf( %d%d , &u1, &v1), add(u1, v1), add(v1, u1);     for (int i = 1; i <= n; i++)       if (!dfn[i]) targin(i, 0);     if (cnt == 1) {       printf( %d n , n - 1);       return 0;     }     for (int x = 1; x <= n; x++)       for (int i = info[x]; i; i = nx[i])         if (!mp[ori[x]][ori[v[i]]] && ori[x] != ori[v[i]]) {           mp[ori[x]][ori[v[i]]] = 1;           g[ori[x]].push_back(ori[v[i]]);           outd[ori[x]]++;         }     for (int i = 1; i <= cnt; i++)       if (outd[i] == 1) res++;     for (int i = 1, p1, p2; i <= cnt; i++)       if (!vis[i]) {         tot++;         tmp = 0;         dfs(i, 0);         p1 = tmp;         tmp = 0;         dfs(p1, 0);         p2 = tmp;         if (dis[p2] < 2)           res++;         else           res += dis[p2] - 2;       }     printf( %d n , n - res + tot - 1);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int M = 5e3 + 10;   const int mod = 1e9 + 7;   int cnt[M][M];   void init() {     for (int i = 1; i < M; i++) {       int p = i;       for (int j = 1; j <= i; j++) cnt[i][j] = cnt[i - 1][j];       for (int j = 2; j <= p; j++) {         if (p % j == 0) {           while (p % j == 0) p /= j, cnt[i][j]++;         }       }     }   }   int n, f[M], v[M], siz[M];   int main() {     init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       v[x]++;     }     long long ans = 0;     for (int i = 1; i < M; i++)       for (int j = 1; j <= i; j++)         if (cnt[i][j]) f[i] = j, ans += 1ll * v[i] * cnt[i][j];     while (1) {       memset(siz, 0, sizeof(siz));       for (int i = 1; i < M; i++) siz[f[i]] += v[i];       int mx = 0, pl = 1;       for (int i = 1; i < M; i++)         if (siz[i] > mx) {           mx = siz[i];           pl = i;         }       if (pl == 1) break;       if (2 * mx <= n) break;       ans = ans + n - 2 * mx;       for (int i = 1; i < M; i++) {         if (f[i] != pl)           f[i] = 1;         else {           cnt[i][f[i]]--;           while (!cnt[i][f[i]] && f[i] > 1) f[i]--;         }       }     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {     fin >> pr.first >> pr.second;     return fin;   }   template <class T0, class T1, class T2>   inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {     fin >> get<0>(t) >> get<1>(t) >> get<2>(t);     return fin;   }   template <class T>   inline istream& operator>>(istream& fin, vector<T>& a) {     for (auto& u : a) fin >> u;     return fin;   }   template <class T, size_t n>   inline istream& operator>>(istream& fin, array<T, n>& a) {     for (auto& u : a) fin >> u;     return fin;   }   void f538() {     size_t n;     cin >> n;     vector<int> a(n);     cin >> a;     vector<int> acc(n);     for (size_t j = 1; j < n; ++j)       if (a[j] < a[0]) ++acc[j];     for (size_t i = 1; i < n; ++i)       for (size_t l = i + 1, r = i + 2, k = 1; r - i - 1 < n;            l += i, r += i + 1, ++k)         for (size_t j = max(l, r - i - 1); j < min(r, n); ++j)           if (a[j] < a[i]) ++acc[k], --acc[(j + i - 1) / i];     partial_sum(begin(acc) + 1, end(acc), ostream_iterator<int>(cout,    ));   }   int main(const int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     f538();     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   const int bigp = 1000000007;   int N, K, ans;   int a[105];   int dp[105][105][2];   int main() {     scanf( %d , &K);     N = 0;     while (K > 0) {       ++N, a[N] = K % 2, K /= 2;     }     for (int i = 1; i <= N / 2; i++) swap(a[i], a[N + 1 - i]);     memset(dp, 0, sizeof(dp));     dp[0][0][1] = 1;     dp[1][0][0] = 1;     for (int i = 0; i < N; i++)       for (int j = 0; j <= N; j++) {         if (dp[i][j][0] != 0) {           dp[i + 1][j + 1][0] = (dp[i + 1][j + 1][0] + dp[i][j][0]) % bigp;           dp[i + 1][j][0] =               (dp[i + 1][j][0] + (long long)dp[i][j][0] * (1 << j)) % bigp;         }         if (dp[i][j][1] != 0) {           if (a[i + 1] == 1)             dp[i + 1][j + 1][1] = (dp[i + 1][j + 1][1] + dp[i][j][1]) % bigp;           if (j > 0) {             if (a[i + 1] == 1) {               dp[i + 1][j][1] =                   (dp[i + 1][j][1] + (long long)dp[i][j][1] * (1 << (j - 1))) %                   bigp;               dp[i + 1][j][0] =                   (dp[i + 1][j][0] + (long long)dp[i][j][1] * (1 << (j - 1))) %                   bigp;             } else               dp[i + 1][j][1] =                   (dp[i + 1][j][1] + (long long)dp[i][j][1] * (1 << (j - 1))) %                   bigp;           }         }       }     ans = 0;     for (int i = 0; i <= N; i++)       ans = (ans + dp[N][i][0]) % bigp, ans = (ans + dp[N][i][1]) % bigp;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef vector<int> vi;   typedef pair<int, int> ii;   using namespace std;   int n, q, len = 0, nxt[100005], nxtb[100005], disb[100005];   int main() {     int a, b, c, op;     scanf( %d%d , &n, &q);     len = n / 327 + 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a);       if (i + a <= n)         nxt[i] = i + a;       else         nxt[i] = n + 1;     }     for (int i = 1; i <= n; i += 327) {       b = min(n, i + 327 - 1);       for (int j = b; j >= i; --j) {         if (nxt[j] <= b) {           nxtb[j] = nxtb[nxt[j]];           disb[j] = disb[nxt[j]] + 1;         } else {           nxtb[j] = j;           disb[j] = 1;         }       }     }     while (q--) {       scanf( %d , &op);       if (op == 0) {         scanf( %d%d , &a, &b);         if (a + b <= n)           nxt[a] = a + b;         else           nxt[a] = n + 1;         b = a / 327 * 327;         c = min(n, b + 327);         for (int i = a; i > b; --i) {           if (nxt[i] <= c) {             nxtb[i] = nxtb[nxt[i]];             disb[i] = disb[nxt[i]] + 1;           } else {             nxtb[i] = i;             disb[i] = 1;           }         }       } else if (op == 1) {         scanf( %d , &a);         b = disb[a];         a = nxtb[a];         while (nxt[a] <= n) {           b += disb[nxt[a]];           a = nxtb[nxt[a]];         }         printf( %d %d n , a, b);       } else         assert(0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)(1e9 + 7);   bool check(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); }   int main() {     int t;     cin >> t;     while (t--) {       int m, n;       cin >> m >> n;       int a[31][31];       pair<int, int> x[65];       for (int i = 0; i < 65; i++) {         x[i] = {0, 0};       }       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {           cin >> a[i][j];         }       }       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {           x[i + j].first += a[i][j];           x[i + j].second++;         }       }       int sum = 0;       for (int i = 2; 2 * i <= m + n + 1; i++) {         sum += min(x[i].first + x[m + n + 2 - i].first,                    x[i].second + x[m + n + 2 - i].second -                        (x[i].first + x[m + n + 2 - i].first));       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100010], new_arr[100010], new_arr1[100010], arr[100010];   int x = 1000000;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       new_arr[i] = min((i + 1), (n - i));       new_arr1[i] = a[i] - new_arr[i];       if (new_arr1[i] >= 0) {         arr[new_arr1[i]]++;       }     }     for (int i = 0; i < 100000; i++) {       x = min(x, n - arr[i]);     }     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string pixels;     getline(cin, pixels);     getline(cin, pixels);     int len = 0, flen = 0, last = pixels.at(0) -  0 ;     bool first = false;     for (int i = (0); i < (pixels.size()); i += (2)) {       if ((pixels.at(i) ==  0  && last == 0) ||           (pixels.at(i) ==  1  && last == 1))         len++;       else {         if (!first) {           flen = len;           first = true;         } else if (flen != len) {           printf( NO );           return 0;         }         len = 1;         last = 1 - last;       }     }     if (!flen || flen == len)       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[200010];   long long num[200010];   struct P {     int x, y, fl;     bool operator<(const P &hs) const {       if (x != hs.x)         return x < hs.x;       else         return y < hs.y;     }   } p[200010];   int row[200010];   int pre[200010];   int n, k;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d %d , &p[i].x, &p[i].y);       p[i].fl = 1;       p[i + n].x = p[i].x + k;       p[i + n].y = p[i].y;       p[i + n].fl = -1;       row[i] = p[i].y;       row[i + n] = row[i] + k;     }     sort(row, row + 2 * n);     int ro = 0;     for (int i = 1; i < 2 * n; i++)       if (row[i] != row[ro]) row[++ro] = row[i];     sort(p, p + 2 * n);     for (int i = 0; i < 2 * n; i++) {       int y = lower_bound(row, row + ro, p[i].y) - row;       for (int j = y; row[j] < row[y] + k; j++) {         if (cnt[j] > 0)           num[cnt[j]] += (long long)(row[j + 1] - row[j]) * (p[i].x - pre[j]);         cnt[j] += p[i].fl;         pre[j] = p[i].x;       }     }     for (int i = 1; i <= n; i++) printf( %I64d%c , num[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MM = 10000000000000001;   int n;   long long a[200005];   int rs[200005];   long long lazy[4 * 200005];   pair<long long, int> it[4 * 200005];   pair<long long, int> minp(pair<long long, int> A, pair<long long, int> B) {     if (A.first < B.first) return A;     if (A.first > B.first) return B;     if (A.second > B.second) return A;     return B;   }   void build(int x, int l, int r) {     if (l == r) {       it[x] = make_pair(a[l], l);       return;     }     int mid = (l + r) / 2;     build(2 * x, l, mid);     build(2 * x + 1, mid + 1, r);     it[x] = minp(it[2 * x], it[2 * x + 1]);   }   void lazy_upd(int x, int l, int r) {     it[x].first += lazy[x];     if (l != r) {       lazy[2 * x] += lazy[x];       lazy[2 * x + 1] += lazy[x];     }     lazy[x] = 0;   }   void update(int x, int l, int r, int u, int v, long long val) {     lazy_upd(x, l, r);     if ((r < u) || (v < l)) return;     if ((u <= l) && (r <= v)) {       lazy[x] += val;       lazy_upd(x, l, r);       return;     }     int mid = (l + r) / 2;     update(2 * x, l, mid, u, v, val);     update(2 * x + 1, mid + 1, r, u, v, val);     it[x] = minp(it[2 * x], it[2 * x + 1]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     for (int i = 1; i <= n; i++) {       pair<long long, int> p = it[1];       int id = p.second;       rs[id] = i;       update(1, 1, n, id, id, MM);       update(1, 1, n, id + 1, n, -i);     }     for (int i = 1; i <= n; i++) cout << rs[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int mx = *max_element(v.begin(), v.end());     int mn = *min_element(v.begin(), v.end());     int ind1 = 0, ind2 = 0;     for (int i = 0; i < n; i++) {       if (v[i] == mx && ind1 == 0)         ind1 = i + 1;       else if (v[i] == mn)         ind2 = i + 1;     }     ind2--;     ind1--;     if (ind1 > ind2) ind2++;     long long result = ind1 + n - ind2 - 1;     cout << result;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, i, j = 0, s = 0, a, b, x, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       a++;       b--;       if (b == 0 && b != y) b = n;       if (a == n + 1 && a != x) a = 1;       if (a == b) {         cout <<  yes ;         j = 1;         break;       }       if (a == x || b == y) break;     }     if (j != 1) cout <<  no ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   long long k;   long long a[maxn];   long long b[maxn], c[maxn], d[maxn];   int main() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     sort(a + 1, a + n + 1);     int m = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == a[m]) {         ++b[m];       } else {         a[++m] = a[i];         b[m] = 1;       }     }     n = m;     for (int i = 1; i <= n; i++) {       c[i] = c[i - 1] + b[i];     }     for (int i = n; i; i--) {       d[i] = d[i + 1] + b[i];     }     int l = 1, r = n;     long long L = a[l], R = a[r];     while (l != r) {       if (c[l] <= d[r]) {         if (c[l] * (a[l + 1] - a[l]) > k) {           L = a[l] + k / c[l];           break;         } else {           k -= c[l] * (a[l + 1] - a[l]);           L = a[++l];         }       } else {         if (d[r] * (a[r] - a[r - 1]) > k) {           R = a[r] - k / d[r];           break;         } else {           k -= d[r] * (a[r] - a[r - 1]);           R = a[--r];         }       }     }     printf( %lld n , R - L);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   double PI = 3.1415926535897932384626433832795;   const long long oo = (long long)1e9 + 1;   const double eps = 1e-9;   const long long mod = 1000000007;   string s;   long long nb, ns, nc, pb, ps, pc, R;   int main() {     cin >> s;     cin >> nb >> ns >> nc;     cin >> pb >> ps >> pc;     cin >> R;     int cb = 0, cs = 0, cc = 0;     for (int i = 0; s[i]; i++)       if (s[i] ==  B )         cb++;       else if (s[i] ==  S )         cs++;       else         cc++;     long long l = 0, r = 1e15, ret = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       if (max(cb * mid - nb, 0ll) * pb + max(cs * mid - ns, 0ll) * ps +               max(cc * mid - nc, 0ll) * pc <=           R)         ret = mid, l = mid + 1;       else         r = mid - 1;     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long palite, primeite;     std::cin >> palite >> primeite;     long long primes = 0, palindromes = 0, max;     static bool prime[12000001];     for (long long i = 0; i <= 12000000; i++) {       prime[i] = true;     }     prime[1] = false;     std::string str =  0 ;     for (long long i = 1; i <= 12000000; i++) {       if (prime[i]) {         primes += primeite;         for (long long j = i * i; j <= 12000000; j += i) {           prime[j] = false;         }       }       long long pos;       for (pos = str.length() - 1; pos >= 0; pos--) {         if (str[pos] ==  9 ) {           str[pos] =  0 ;         } else {           str[pos]++;           break;         }       }       if (pos == -1) {         str.insert(str.begin(),  1 );       }       palindromes += palite;       for (long long j = 0, back = str.length() - 1; back > j; j++, back--) {         if (str[j] != str[back]) {           palindromes -= palite;           break;         }       }       if (primes <= palindromes) {         max = i;       }     }     if (max == 12000000) {       std::cout <<  Palindromic tree is better than splay tree ;     } else {       std::cout << max;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     string s;     cin >> n;     cin >> s;     n = s.size();     for (i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) break;     }     if (i != n - 1) {       cout <<  YES             <<   n ;       cout << i + 1 <<     << i + 2 <<   n ;     } else {       cout <<  NO             <<   n ;     }   }
#include <bits/stdc++.h>   int main() {     char s[512];     scanf( %s , s);     int length = strlen(s);     int i;     int alpha_cnt = 0;     for (i = 0; i < length; i++) {       if (s[i] -  a  > alpha_cnt) {         puts( NO );         return 0;       }       if (s[i] -  a  == alpha_cnt) {         alpha_cnt++;       }     }     puts( YES );     return 0;   }