malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 10000 + 20;   int sa[N], cc[N], t1[N], t2[N], height[N], rk[N];   int n;   char s[N], t[N];   bool cmp(int *y, int a, int b, int k) {     int a1 = y[a], a2 = (a + k >= n) ? -1 : y[a + k];     int b1 = y[b], b2 = (b + k >= n) ? -1 : y[b + k];     return a1 == b1 && a2 == b2;   }   void buildSa(int m) {     int *x = t1, *y = t2;     for (int i = 0; i < m; i++) cc[i] = 0;     for (int i = 0; i < n; i++) cc[x[i] = s[i]]++;     for (int i = 1; i < m; i++) cc[i] += cc[i - 1];     for (int i = n - 1; i >= 0; i--) sa[--cc[x[i]]] = i;     for (int k = 1; k <= n; k <<= 1) {       int p = 0;       for (int i = n - k; i < n; i++) y[p++] = i;       for (int i = 0; i < n; i++)         if (sa[i] >= k) y[p++] = sa[i] - k;       for (int i = 0; i < m; i++) cc[i] = 0;       for (int i = 0; i < n; i++) cc[x[y[i]]]++;       for (int i = 1; i < m; i++) cc[i] += cc[i - 1];       for (int i = n - 1; i >= 0; i--) sa[--cc[x[y[i]]]] = y[i];       swap(x, y);       x[sa[0]] = 0;       m = 1;       for (int i = 1; i < n; i++) {         x[sa[i]] = cmp(y, sa[i], sa[i - 1], k) ? m - 1 : m++;       }       if (m >= n) break;     }   }   void buildH() {     for (int i = 0; i < n; i++) rk[sa[i]] = i;     height[0] = 0;     int k = 0;     for (int i = 0; i < n; i++) {       if (!rk[i]) continue;       int j = sa[rk[i] - 1];       if (k) k--;       while (s[i + k] == s[j + k]) k++;       height[rk[i]] = k;     }   }   int main() {     scanf( %s , t);     int len1 = strlen(t);     for (int i = 0; t[i]; i++) s[n++] = t[i];     s[n++] =  # ;     scanf( %s , t);     for (int i = 0; t[i]; i++) s[n++] = t[i];     buildSa(1000);     buildH();     int ans = 1e9 + 7;     for (int i = 1; i < n; i++) {       if (height[i]) {         if ((sa[i] >= len1 && sa[i - 1] < len1) ||             (sa[i] < len1 && sa[i - 1] >= len1)) {           if (height[i - 1] < height[i] && height[i + 1] < height[i])             ans = min(ans, max(height[i - 1], height[i + 1]) + 1);         }       }     }     if (ans == 1e9 + 7) ans = -1;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   string s;   int sz;   vector<pair<int, string> > e;   int v[2][200009];   int c[200009];   int Call(int in, int count) {     if (c[in] != -1) {       Call(c[in] - 1, count + 1);     } else {       int i;       printf(  n%d  , count + 1);     }   }   int Pr(int in) {     printf( %d  , in + 1);     if (c[in] != -1) {       Pr(c[in] - 1);       c[in] = 0;     } else {       c[in] = 0;     }   }   int main() {     int i, j, k = 0, n = 0, m = 0;     cin >> s;     sz = s.size();     for (i = 0; i < sz; i++) {       if (s[i] - 48 == 0)         v[0][n++] = i + 1;       else         v[1][m++] = i + 1;     }     int u = 0;     for (i = 0, j = 0; i < sz; i++) {       if (s[i] - 48 == 0) {         if (j == m)           c[i] = -1;         else if (i + 1 > v[1][j])           return 0 * printf( -1 );         else {           c[i] = v[1][j];           j++;         }       } else {         while (i + 1 > v[0][u]) {           u++;           if (u >= n) return 0 * printf( -1 );         }         c[i] = v[0][u];         u++;       }     }     string q;     for (i = 0; i < sz; i++)       if (c[i] == -1) k++;     printf( %d , k);     for (i = 0; i < sz; i++) {       q = i + 1 + 48;       if (c[i] == -1)         printf(  n1 %d , i + 1);       else if (c[i] != 0) {         Call(i, 0);         Pr(i);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int tc;   long long temp;   long long dp[100005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, k;     cin >> t >> k;     for (int i = 0; i < k; i++) dp[i] = 1;     for (int i = k; i < 100005; i++) {       dp[i] = (dp[i - 1] % 1000000007 + dp[i - k] % 1000000007) % 1000000007;     }     dp[0] = 0;     for (int i = 1; i < 100005; i++) {       dp[i] = dp[i] % 1000000007 + dp[i - 1] % 1000000007;       dp[i] %= 1000000007;     }     while (t--) {       int a, b;       cin >> a >> b;       if (dp[b] >= dp[a - 1])         cout << (dp[b] - dp[a - 1]) % 1000000007 <<   n ;       else         cout << (dp[b] - dp[a - 1] + 1000000007) % 1000000007 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     int n, m;     cin >> n >> m;     vector<int> ans(n);     for (int i = 0; i < n; i++) {       ans[i] = i + 1;     }     vector<int> check;     do {       int sm = 0;       for (int i = 0; i < n; i++) {         for (int j = i; j < n; j++) {           int mn = INF;           for (int y = i; y <= j; y++) {             mn = min(mn, ans[y]);           }           sm += mn;         }       }       check.push_back(sm);     } while (next_permutation(ans.begin(), ans.end()));     int mx = -1;     for (int i = 0; i < check.size(); i++) {       mx = max(mx, check[i]);     }     int now = 0, s = 0;     for (int i = 0; i < check.size(); i++) {       if (check[i] == mx) {         now++;         if (now == m) {           break;         }       }       next_permutation(ans.begin(), ans.end());     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 5;   const int INF = 1e9 + 5;   const int mod = 1000000007;   const double eps = 1e-7;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long a, b, k;     while (cin >> k >> a >> b) {       if (b <= 0) {         a = -a;         b = -b;         swap(a, b);       }       long long ans = b / k - a / k;       if (a % k == 0 || a < 0) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int M = 7;   int n, p, k;   int s[N + 1][M + 1];   long long dp[N + 1][1 << M + 1];   pair<int, int> a[N + 1];   long long go(int idx, int mask) {     if (idx > n) {       if (mask == ((1 << p) - 1)) {         return 0;       } else {         return -1e18;       }     }     if (dp[idx][mask] != -1) {       return dp[idx][mask];     }     int players = __builtin_popcount(mask);     int aud = idx - players - 1;     long long ans = 0;     if (players < p) {       for (int i = 0; i < p; i++) {         int val = mask & (1 << i);         if (!val) {           ans = max(ans, 1LL * s[a[idx].second][i + 1] +                              1LL * go(idx + 1, mask | (1 << i)));         }       }     }     if (aud < k) {       ans = max(ans, 1LL * a[idx].first + 1LL * go(idx + 1, mask));     } else {       ans = max(ans, go(idx + 1, mask));     }     return dp[idx][mask] = ans;   }   int main() {     cin >> n >> p >> k;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[i] = {x, i};     }     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= p; j++) {         cin >> s[i][j];       }     }     memset(dp, -1, sizeof(dp));     cout << go(1, 0);   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<short> g[10003];   int main() {     scanf( %d , &n);     int maxi;     for (maxi = 1; ((maxi * maxi - maxi) >> 1) <= n; maxi++)       ;     maxi--;     int end = 1;     int i, j;     for (i = 1; i < maxi; i++) {       for (j = 0; j < maxi - i; j++) g[i].push_back(end + j);       for (j = i + 1; j <= maxi; j++) g[j].push_back(end + (j - i - 1));       end += maxi - i;     }     printf( %d n , maxi);     for (i = 1; i <= maxi; i++) {       printf( %d , (int)g[i][0]);       for (j = 1; j < g[i].size(); j++) printf(  %d , (int)g[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     if (x < y) swap(x, y);     while (y > 0) {       T f = x % y;       x = y;       y = f;     }     return x;   }   template <typename T>   pair<T, T> exgcd(T x, T y) {     if (x < y) swap(x, y);     pair<T, T> r = make_pair(1, 0);     while (y > 0) {       T f = x % y;       r = make_pair(r.second, r.first - (x / y) * r.second);       x = y;       y = f;     }     return r;   }   const int maxn = 1e5;   int n;   int P[maxn + 1], T[maxn + 1];   int SP[maxn + 1];   int TP[maxn + 1];   int lvl[maxn + 1];   vector<int> child[maxn + 1];   int bg[maxn + 1];   int ed[maxn + 1];   int tt = 0;   void dfs(int u, bool sp = false) {     bg[u] = tt++;     for (auto c : child[u]) lvl[c] = lvl[u] + 1, dfs(c);     ed[u] = tt++;   }   bool isAsc(int u, int v) { return bg[u] <= bg[v] && ed[v] <= ed[u]; }   int main(int argc, char *argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     {       for (int i = 1; i <= n; i++) {         cin >> P[i] >> T[i];         if (T[i] == 0) {           SP[i] = SP[P[i]];           TP[i] = i;         } else if (T[i] == 1) {           SP[i] = i;           TP[i] = TP[P[i]];         } else {           TP[i] = i;           SP[i] = i;         }         bg[i] = ed[i] = 0;       }       for (int i = 1; i <= n; i++) {         if (P[i] != -1) {           child[P[i]].push_back(i);         }       }       tt = 1;       for (int i = 1; i <= n; i++) {         if (!bg[i]) {           lvl[i] = 1;           dfs(i);         }       }       int q;       cin >> q;       while (q--) {         int t, u, v, ov;         cin >> t >> u >> v;         if (u == v) {           cout <<  NO  << endl;           continue;         }         if (t == 1) {           if ((isAsc(u, v) && lvl[SP[v]] <= lvl[u]))             cout <<  YES  << endl;           else             cout <<  NO  << endl;         } else {           int av = TP[v];           if (av != v && (isAsc(av, u) && lvl[SP[u]] <= lvl[av]))             cout <<  YES  << endl;           else {             int au = SP[u];             if (au != v && isAsc(au, v) && lvl[TP[v]] <= lvl[au])               cout <<  YES  << endl;             else               cout <<  NO  << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 300010, modP = 1e9 + 7, oo = 23041997, maxB = 600;   const double PI = acos(-1);   int prime[maxN], a[maxN], cnt[maxN], n, POW[maxN], res, p[maxN], maxv;   void sieve() {     for (int i = 2; i <= maxv; ++i)       if (prime[i] == 0) {         int s = 2 * i;         while (s <= maxv) {           prime[s] = i;           s += i;         }       }   }   void factorize(int x) {     p[0] = 0;     while (prime[x]) {       p[++p[0]] = prime[x];       x /= prime[x];     }     p[++p[0]] = x;   }   int main() {     cin >> n;     maxv = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       maxv = max(maxv, a[i]);       for (int j = 1; j <= (int)sqrt(a[i]); ++j)         if (a[i] % j == 0) {           ++cnt[j];           if (a[i] / j != j) ++cnt[a[i] / j];         }     }     POW[0] = 1;     for (int i = 1; i <= n; ++i) POW[i] = (1ll * POW[i - 1] * 2) % modP;     sieve();     res = POW[n] - 1;     for (int i = 2; i <= maxv; ++i) {       factorize(i);       bool check = true;       for (int j = 2; j <= p[0]; ++j)         if (p[j] == p[j - 1]) check = false;       if (check && cnt[i]) {         int tmp = (((POW[cnt[i]] - 1) % modP) + modP) % modP;         if ((p[0] % 2) == 0)           res = (res + tmp) % modP;         else           res = (((res - tmp) % modP) + modP) % modP;       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string ans;       for (int i = 0; i < n; i++) {         ans += s[2 * i];       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using pcc = pair<char, char>;   using pdd = pair<double, double>;   using vi = vector<int>;   using vs = vector<string>;   using vll = vector<ll>;   using vpii = vector<pii>;   using vc = vector<char>;   using vd = vector<double>;   bool cmp(pii a, pii b) {     if (a.second * b.first < b.second * a.first) return true;     return false;   }   int main(int argc, char* argv[]) {     ll t, a, b, p, i, j, l;     char str[200100];     scanf( %d%*c , &(t));     while (t--) {       scanf( %lld %lld %lld , &a, &b, &p);       scanf( %s , str);       l = strlen(str);       ll pre = 0, tot = 0;       for (i = 1; i < l; i++) {         if (str[i] != str[pre]) {           if (str[pre] ==  A ) {             tot += a;           } else             tot += b;           pre = i;         }       }       if (pre < l - 1) {         if (str[pre] ==  A ) {           tot += a;         } else           tot += b;       }       pre = 0;       for (i = 0; i < l; i++) {         if (tot <= p) break;         if (str[i] != str[pre]) {           if (str[pre] ==  A ) {             tot -= a;           } else             tot -= b;           pre = i;         }       }       if (tot > p)         pre = l;       else         pre++;       printf( %lld , (pre)), printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, d;     cin >> n >> d;     long long k = 0, c = 0, a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     c = 0;     for (long long i = 1; i < n; i++) {       if (a[i - 1] < a[i]) continue;       k = a[i - 1] - a[i] + d;       c += k / d;       a[i] += (k / d) * d;     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, z, l, i, lc;     cin >> n >> m >> z;     l = max(n, m);     for (i = l; i <= n * m; i += l) {       if (i % n == 0 && i % m == 0) break;     }     cout << z / i;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> g(n + 1);     vector<int> a(n);     for (int i = 0; i < m; i++) {       int maxj = 0;       for (int j = 0; j < n; j++) {         cin >> a[j];         if (a[j] > a[maxj])           maxj = j;         else if (a[j] == a[maxj]) {           if (j < maxj) maxj = j;         }       }       g[maxj + 1]++;       a.resize(n);     }     int ma = 0;     for (int i = 1; i <= n; i++) {       if (g[i] > g[ma])         ma = i;       else if (g[i] == g[ma]) {         if (i < ma) ma = i;       }     }     cout << ma;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int len = str.length();     int mx = 0;     for (int j = 0; j < len; j++) {       char ch = str[j];       str[j] =  V ;       int ans = 0;       bool flag = false;       for (int i = 0; i < len; i++) {         if (str[i] ==  V )           flag = true;         else {           if (str[i] ==  K  && flag) {             ans++;             flag = false;           } else             flag = false;         }       }       str[j] = ch;       mx = max(ans, mx);     }     for (int j = 0; j < len; j++) {       char ch = str[j];       str[j] =  K ;       int ans = 0;       bool flag = false;       for (int i = 0; i < len; i++) {         if (str[i] ==  V )           flag = true;         else {           if (str[i] ==  K  && flag) {             ans++;             flag = false;           } else             flag = false;         }       }       str[j] = ch;       mx = max(ans, mx);     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n;       cin >> n;       vector<long long int> a(n);       for (long long int i = 0; i < n; i++) cin >> a[i];       vector<long long int> t(n);       t[0] = 1;       for (long long int i = 1; i < n; i++) t[i] = max(a[i] + 1, t[i - 1]);       for (int i = n - 2; i >= 0; i--) t[i] = max(t[i + 1] - 1, t[i]);       long long s = 0;       for (long long int i = 0; i < n; i++) s += t[i] - a[i] - 1;       cout << s;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int inf = 1061109567;   const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   map<int, int> mp[100005], vis;   int tot;   int lowbit(int x) { return x & (-x); }   void update(int t, int x, int val) {     for (int i = t; i <= 1e9 + 2; i += lowbit(i)) {       mp[x][i] += val;     }   }   int query(int t, int x) {     int ret = 0;     for (int i = t; i > 0; i -= lowbit(i)) {       ret += mp[x][i];     }     return ret;   }   int main() {     int n, sign, t, x;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &sign, &t, &x);       if (!vis[x]) {         vis[x] = ++tot;       }       if (sign == 1) {         update(t, vis[x], 1);       } else if (sign == 2) {         update(t, vis[x], -1);       } else {         printf( %d n , query(t, vis[x]));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   int a[100005];   int main() {     int n;     scanf( %d , &n);     bool one = true;     for (int i = 0; i < n + 1; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] > 1 && a[i] > 1) {         one = false;         break;       }     }     if (one) {       cout <<  perfect ;       return 0;     }     cout <<  ambiguous n0  ;     int c = 2;     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] == 1) {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       } else {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       }     }     cout <<   n0  ;     c = 2;     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] == 1) {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       } else {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - ((j + 1) % a[i - 1]) - 1);         }         c += a[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD9 = 1e9 + 7;   const int MOD91 = 1e9 + 9;   const unsigned long long MOD12 = 1e12 + 39LL;   const unsigned long long MOD15 = 1e15 + 37LL;   const int INF = 1e9;   const int base = 1e9;   const int MAX = 2e5;   const long double EPS = 1e-10;   string second;   int n, k;   int a[30][30];   int dpt[101][30][101];   int dp(int pos, int prev, int left) {     if (pos == second.size()) {       return 0;     }     if (dpt[pos][prev][left] != -1) {       return dpt[pos][prev][left];     }     if (left == 0) {       return dpt[pos][prev][left] = dp(pos + 1, second[pos] -  a , left) +                                     a[prev][second[pos] -  a ];     }     int b = -INF;     for (int i = (0); i < (26); ++i) {       b = max(b,               dp(pos + 1, i, left - (i != int(second[pos] -  a ))) + a[prev][i]);     }     return dpt[pos][prev][left] = b;   }   int main() {     cin >> second >> k;     cin >> n;     memset(dpt, -1, sizeof(dpt));     for (int i = (0); i < (n); ++i) {       char x, y;       int xx;       cin >> x >> y >> xx;       a[x -  a ][y -  a ] = xx;     }     cout << dp(0, 27, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 85;   double l[N], r[N], ans[N][N], ago[N], now[N], dp[N][N];   int main() {     vector<double> g;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &l[i], &r[i]);       g.push_back(l[i]), g.push_back(r[i]);     }     sort(g.begin(), g.end());     g.erase(unique(g.begin(), g.end()), g.end());     vector<pair<double, double> > p;     for (int i = 0; i < g.size() - 1; ++i) p.push_back(make_pair(g[i], g[i + 1]));     for (int t = 0; t < p.size(); ++t) {       for (int i = 1; i <= n; ++i) {         double L = p[t].first, R = p[t].second;         if (!(l[i] >= R || r[i] <= L)) {           for (int j = 0; j <= n; ++j)             for (int k = 0; k <= n; ++k) dp[j][k] = 0.0;           dp[0][0] = 1.0;           int cnt = 0;           vector<int> used;           for (int k = 1; k <= n; ++k) {             if (l[k] >= R || r[k] <= L) {               now[k] = 0.0;               if (r[k] <= L) cnt++;             } else               now[k] = (R - L) / (r[k] - l[k]), used.push_back(k);           }           int m = used.size();           for (int _ = 0; _ < m; ++_) {             int x = used[_];             if (x == i) continue;             for (int k = _ + 1; k >= 0; --k)               for (int o = _ + 1 - k; o >= 0; --o) {                 dp[k + 1][o] += dp[k][o] * ago[x];                 dp[k][o + 1] += dp[k][o] * now[x];                 dp[k][o] *= 1.0 - now[x] - ago[x];               }           }           for (int j = 0; j < m; ++j)             for (int k = 0; k < m - j; ++k) {               ans[i][cnt + j] += dp[j][k] * now[i] / (1 + k);               ans[i][cnt + j + k + 1] -= dp[j][k] * now[i] / (1 + k);             }         }       }       for (int i = 1; i <= n; ++i) ago[i] += now[i];     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < n; ++j) {         if (j) {           ans[i][j] += ans[i][j - 1];         }         printf( %.12f%c , ans[i][j], j == n - 1 ?   n  :    );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double p, e[100010], dp[100010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf , &p);       e[i] = p * (e[i - 1] + 1);       dp[i] = dp[i - 1] + (2 * e[i - 1] + 1) * p;     }     printf( %.9lf , dp[n]);   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   const ll MAX = 1e5 + 100;   const ll inf = 1e9;   const ll mod = 998244353;   ll a[MAX], c[MAX], t[MAX];   string b[] = { 50 ,  25 ,  75 ,  00 };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ll tc = 1, n, m, ans = 0, v, r;     cin >> n >> m;     for (ll i = 1; i < n + 1; i++) cin >> c[i] >> t[i];     ll ini = 1, time = 0;     while (m--) {       cin >> v;       while (v > time + c[ini] * t[ini]) time += c[ini] * t[ini], ini++;       cout << ini << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000006, LG = 21, mod = 1e9 + 7, M = N;   const double eps = 1e-3, pi = acos(-1.0);   const long long INF = 1123456789123456789LL;   int main() {     string str;     cin >> str;     char mi =  a ;     bool ans = true;     for (char c : str)       if (c > mi + 1) {         ans = false;         break;       } else         mi = max(mi, c);     if (ans && str[0] ==  a )       printf( YES n );     else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005], n, s, ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     while (n--) {       long long x;       cin >> x;       s += x;       a[x]++;     }     if (s == 1 or s == 2 or s == 5) return cout << -1, 0;     while (a[1] > 0 and a[2] > 0) {       a[3]++;       ans++;       a[1]--;       a[2]--;     }     if (a[1] > 0) {       ans += a[1] - a[1] / 3;       if (a[1] == 1 and a[3] == 0) ans++;     }     if (a[2] > 0) {       ans += a[2] - a[2] / 3;       if (a[2] % 3 == 1 and a[4] == 0) ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, A[50], B[1001], i, X, C[50], t = 0;     scanf( %d , &n);     for (i = 0; i <= 1000; i++) {       B[i] = 0;     }     for (i = 0; i < n; i++) {       scanf( %d , &A[i]);       X = A[i];       B[X] += 1;     }     for (i = 0; i < n; i++) {       X = A[i];       if (B[X] == 1) {         C[t] = X;         t++;       } else {         B[X] -= 1;       }     }     printf( %d n , t);     for (i = 0; i < t; i++) {       if (i == t - 1) {         printf( %d n , C[i]);       } else {         printf( %d  , C[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     if (a.size() > 26) {       cout <<  -1 n ;     } else {       int count = 0;       int hash[26] = {0};       for (int i = 0; i < a.size(); i++) {         if (hash[a[i] - 97])           count++;         else           hash[a[i] - 97]++;       }       cout << count <<   n ;     }   }