malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 101111, maxm = 5011, inf = 2147000000;   struct orz {     int d, num;   } a[maxn];   int n, v, ans;   bool cmp(orz x, orz y) { return (x.d < y.d); }   int main() {     scanf( %d%d , &n, &v);     int i, j, x, y;     for (i = 1; i <= n; i++) scanf( %d%d , &a[i].d, &a[i].num);     sort(a + 1, a + n + 1, cmp);     x = 1;     for (i = 2; i <= n; i++)       if (a[i].d == a[x].d)         a[x].num += a[i].num;       else         a[++x] = a[i];     n = x;     a[0].d = -10;     int res;     int now = 1;     a[n + 1].d = -1;     for (i = 1; i <= 3100; i++) {       while (a[now].d < i - 1 && now < n) now++;       res = v;       if (a[now].d == i - 1 || a[now].d == i) {         if (a[now].num <= res) {           res -= a[now].num;           a[now].num = 0;         } else {           a[now].num -= res;           res = 0;         }       }       if (a[now].d == i - 1 && res) {         now++;         if (a[now].d == i) {           if (a[now].num <= res) {             res -= a[now].num;             a[now].num = 0;           } else {             a[now].num -= res;             res = 0;           }         }       }       ans += v - res;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e2 * 2;   const int TMXN = 1048576;   const long long INF = 1e9 + 7;   const long long INFL = 1e18;   struct query {     int l, r, id;   };   int n;   int a[TMXN];   long long ans[TMXN];   long long res;   int cnt[TMXN];   int m, k;   query q[TMXN];   bool cmp(query a, query b) {     if (a.l / 447 != b.l / 447) return (a.l / 447 < b.l / 447);     return a.r < b.r;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].l;       q[i].id = i;     }     int L = 0, R = -1;     sort(q + 1, q + m + 1, cmp);     for (int i = 1; i <= m; i++) {       while (q[i].r > R) {         R++;         res += (((cnt[a[R]] + 1) * (cnt[a[R]] + 1) * a[R])) -                ((cnt[a[R]] * cnt[a[R]]) * a[R]);         cnt[a[R]]++;       }       while (q[i].l < L) {         L--;         res += (((cnt[a[L]] + 1) * (cnt[a[L]] + 1) * a[L])) -                ((cnt[a[L]] * cnt[a[L]]) * a[L]);         cnt[a[L]]++;       }       while (q[i].r < R) {         res -= ((cnt[a[R]] * cnt[a[R]]) * a[R]) -                (((cnt[a[R]] - 1) * (cnt[a[R]] - 1) * a[R]));         cnt[a[R]]--;         R--;       }       while (q[i].l > L) {         res -= ((cnt[a[L]] * cnt[a[L]]) * a[L]) -                (((cnt[a[L]] - 1) * (cnt[a[L]] - 1) * a[L]));         cnt[a[L]]--;         L++;       }       ans[q[i].id] = res;     }     for (int i = 1; i <= m; i++) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int a, s, d;     long long x, y;     scanf( %d%d%d , &a, &s, &d);     x = a / d;     y = s / d;     if (x * d < a) x++;     if (y * d < s) y++;     printf( %lld , x * y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, b, c, res = LONG_LONG_MAX;   int main() {     cin >> n >> a >> b >> c;     if (n % 4 == 0) return puts( 0 );     if (n % 4 == 1) {       res = min(res, a * 3);       res = min(res, a + b);       res = min(res, c);     } else if (n % 4 == 2) {       res = min(res, a * 2);       res = min(res, b);       res = min(res, c * 2);     } else {       res = min(res, a);       res = min(res, b + c);       res = min(res, c * 3);     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> v[N];   vector<pair<int, int> > ans;   int deg[N], maxT;   void dfs(int x, int T, int u) {     ans.push_back({x, T});     int beginT = T;     for (auto it : v[x])       if (it != u) {         if (T == maxT) {           T = maxT - deg[x];           ans.push_back({x, T});         }         dfs(it, T + 1, x);         ans.push_back({x, ++T});       }     if (T >= beginT) ans.push_back({x, beginT - 1});   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);       deg[x]++;       deg[y]++;     }     for (int i = 1; i <= n; i++) maxT = max(maxT, deg[i]);     dfs(1, 0, 0);     ans.pop_back();     cout << ans.size() <<   n ;     for (auto it : ans) cout << it.first <<     << it.second <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const lint linf = 1e18 + 7;   const lint inf = 1e9 + 7;   const int MOD = 1000000007;   void press(vector<long long>& x) {     map<int, int> memo;     int n = x.size();     for (int i = 0; i < n; ++i) {       memo[x[i]] += 1;     }     int cur = 1;     for (auto& val : memo) {       val.second = cur;       ++cur;     }     for (int i = 0; i < n; ++i) {       x[i] = memo[x[i]];     }   }   void solve() {     int n;     cin >> n;     vector<lint> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     auto b = a;     press(b);     vector<vector<int>> dp(n + 5, vector<int>(3, 0));     vector<int> cnt(n + 5, 0);     for (int i = 0; i < n; ++i) cnt[b[i]] += 1;     int res = n - 1;     for (int i = 0; i < n; ++i) {       if (dp[b[i]][0] == 0) {         dp[b[i]][0] = max(dp[b[i] - 1][1], dp[b[i] - 1][2]) + 1;       }       if (dp[b[i]][1] + 1 < cnt[b[i]]) {         ++dp[b[i]][1];       } else {         dp[b[i]][2] = dp[b[i]][0] + dp[b[i]][1];         dp[b[i]][1] += 1;       }       int hoge = dp[b[i]][1] + cnt[b[i] + 1] - dp[b[i] + 1][1];       res = min(res, n - hoge);       hoge = cnt[b[i]] - dp[b[i]][1] + dp[b[i] - 1][2] + 1;       res = min(res, n - hoge);     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 3; ++j) {         res = min(res, n - dp[i][j]);       }     }     cout << res <<   n ;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 9;   struct edge {     int to, nxt;   } e[N * 2];   int hd[N], tot;   void add(int u, int v) {     e[++tot] = (edge){v, hd[u]};     hd[u] = tot;   }   int n, sz[N], msz[N];   void pre(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         pre(v, u);         sz[u] += sz[v];         if (sz[v] > sz[msz[u]]) msz[u] = v;       }     sz[u]++;   }   int f[N][2], mx[N];   void dfs1(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         dfs1(v, u);         int tmp = (sz[v] > n / 2 ? f[v][0] : sz[v]);         if (tmp > f[u][0])           f[u][1] = f[u][0], f[u][0] = tmp, mx[u] = v;         else if (tmp > f[u][1])           f[u][1] = tmp;       }   }   int g[N];   void dfs2(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         int tmp = (n - sz[v] > n / 2 ? g[u] : n - sz[v]);         g[v] = max(g[v], tmp);         if (v == mx[u])           g[v] = max(g[v], f[u][1]);         else           g[v] = max(g[v], f[u][0]);         dfs2(v, u);       }   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     pre(1, 0), dfs1(1, 0), dfs2(1, 0);     for (int i = 1; i <= n; i++) {       bool centroid = 1;       if (sz[msz[i]] > n / 2)         centroid = (sz[msz[i]] - f[i][0] <= n / 2);       else if (n - sz[i] > n / 2)         centroid = (n - sz[i] - g[i] <= n / 2);       cout << centroid <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T range(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   inline void setin(string s) { freopen(s.c_str(),  r , stdin); }   inline void setout(string s) { freopen(s.c_str(),  w , stdout); }   template <typename T>   void Min(T &a, T b) {     a = min(a, b);   }   template <typename T>   void Max(T &a, T b) {     a = max(a, b);   }   const int mod = 998244353;   const int inf = 0x3f3f3f3f;   const int N = 1e6 + 15;   int n;   vector<int> g[N];   int cnt[N], cl[N];   void dfs(int v, int p = -1) {     cnt[cl[v]]++;     for (int to : g[v]) {       if (to != p) {         cl[to] = cl[v] ^ 1;         dfs(to, v);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     cout << min(cnt[0], cnt[1]) - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int n, m, len1 = 1, len2 = 1, ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int a = 7; a < n; a *= 7) len1 += 1;     for (int b = 7; b < m; b *= 7) len2 += 1;     if (len1 + len2 <= 7) {       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           vector<int> used(7, 0);           for (int a = i, k = 0; k < len1; a /= 7, k++) used[a % 7] += 1;           for (int b = j, k = 0; k < len2; b /= 7, k++) used[b % 7] += 1;           if (*max_element(used.begin(), used.end()) <= 1) ans++;         }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char n[1000 + 2];   char m[1000 + 2];   int color_n[30];   int color_m[30];   int main() {     while (scanf( %s , n) != EOF) {       scanf( %s , m);       memset(color_n, 0, sizeof(color_n));       memset(color_m, 0, sizeof(color_m));       for (int i = 0; i < strlen(n); i++) color_n[n[i] -  a ]++;       for (int j = 0; j < strlen(m); j++) color_m[m[j] -  a ]++;       int ans = 0;       int flag = 1;       for (int i = 0; i < 30; i++) {         ans += min(color_n[i], color_m[i]);         if (color_m[i] && color_n[i] == 0) flag = 0;       }       if (ans == 0 || flag == 0)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int N, X, sum = 0;     std::cin >> N >> X;     for (int i = 0; i < N; i++) {       int tmp;       std::cin >> tmp;       sum += tmp;     }     if (sum + N - 1 == X)       std::cout <<  YES n ;     else       std::cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 10;   inline long long rd() {     long long x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int to[N], nt[N], hd[N], tot = 1;   inline void add(int x, int y) {     ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;   }   int n, m, k, a[N], len[N], ans;   int st[N], tt = -1;   inline void dfs(int x) {     ++tt, st[tt] = st[tt - 1] + len[x];     ans = max(ans, st[tt] - st[max(0, tt - m)]);     if (tt < m)       for (int i = hd[x]; i; i = nt[i]) dfs(to[i]);     --tt;   }   int main() {     n = rd(), m = rd(), k = rd();     for (int i = 1; i <= n; i++) a[i] = rd();     for (int i = 1, su = a[1], j = 1; i <= n; i++) {       while (j < n && su + a[j + 1] <= k) su += a[++j];       len[i] = j - i + 1, add(j + 1, i), su -= a[i];     }     dfs(n + 1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[1010];   int sum = 0;   int cnt = 0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     for (int i = 0; i < n; i++) {       if ((sum % 2) == (a[i] % 2)) {         cnt++;       }     }     printf( %d n , cnt);   }
#include <bits/stdc++.h>   using namespace std;   istream& in = cin;   int n;   int a[1000010];   void input() {     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i];   }   long long mod = (long long)1e9 + 7;   long long fac[1000010], inv[1000010];   long long quick_mod(long long a, long long p) {     long long ret = 1;     a %= mod;     while (p) {       if (p & 1) ret = ret * a % mod;       a = a * a % mod;       p /= 2;     }     return ret;   }   long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }   long long cale(int k) {     long long large = fac[k];     long long less = 1;     less = fac[n] * inv[k + 1] % mod;     return large * less % mod;   }   int main() {     fac[0] = 1;     for (int i = 1; i < 1000010; ++i) fac[i] = fac[i - 1] * i % mod;     inv[1000009] = quick_mod(fac[1000009], mod - 2);     for (int i = 1000008; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;     int TEST_CASE = 1;     while (TEST_CASE-- > 0) {       input();       sort(a + 1, a + n + 1);       long long ans = 0;       a[0] = -1;       int pos = 1, K = n;       while (pos <= n) {         int val = a[pos];         int num = 0;         while (a[pos] == val) {           pos++;           num++;         }         if (val != a[n]) ans = (ans + cale(K - 1) * num % mod * val % mod) % mod;         K -= num;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   int mod = 1000000007;   using namespace std;   bool isp(long long x) {     for (long long i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   void pog() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;   }   bool sortinrev(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first > b.first);   }   bool prime_check(long long n) {     bool flag = 1;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }   long long power(long long x, unsigned long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     pog();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) {         cin >> arr[i];       };       long long sum = arr[0] + arr[1];       long long flag = 0;       for (long long i = 2; i < n; i++)         if (sum <= arr[i]) {           flag = i + 1;           break;         }       if (flag)         cout << 1 <<     << 2 <<     << flag <<   n ;       else         cout << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int t1, t2;   int s1[100010], s2[100010];   pair<int, int> c1[100010], c2[100010];   bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     int n, v;     cin >> n >> v;     for (int i = 0; i < n; i++) {       int t, p;       cin >> t >> p;       if (t == 1) {         c1[t1++] = make_pair(p, i + 1);       } else         c2[t2++] = make_pair(p, i + 1);     }     sort(c1, c1 + t1, cmp);     sort(c2, c2 + t2, cmp);     s1[0] = s2[0] = 0;     for (int i = 0; i < t1; i++) {       s1[i + 1] = s1[i] + c1[i].first;     }     for (int i = 0; i < t2; i++) {       s2[i + 1] = s2[i] + c2[i].first;     }     int ans = -1;     int tmp = -1;     for (int i = 0; i <= t2; i++) {       if (i * 2 <= v && s1[min(v - i * 2, t1)] + s2[i] > ans) {         ans = s1[min(v - i * 2, t1)] + s2[i];         tmp = i;       }     }     cout << ans << endl;     for (int i = 0; i < min(v - tmp * 2, t1); i++) cout << c1[i].second << endl;     for (int i = 0; i < tmp; i++) cout << c2[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const long long N = 107, MOD = 1e9 + 7;   long long n, K, c;   bool s[N];   struct Mat {     long long val[N][N];     long long Max_n, Max_m;     Mat() {       memset(val, 0, sizeof(val));       Max_n = Max_m = 0;     }     Mat operator*(const Mat el) const {       Mat c;       for (long long i = 0; i <= Max_n; ++i)         for (long long j = 0; j <= el.Max_m; ++j)           for (long long k = 0; k <= Max_m; ++k)             c.val[i][j] =                 (c.val[i][j] + ((val[i][k] * el.val[k][j]) % MOD)) % MOD;       c.Max_n = Max_n, c.Max_m = el.Max_m;       return c;     }     inline void I(long long n) {       Max_n = Max_m = n;       for (long long i = 0; i <= n; ++i) val[i][i] = 1;     }   };   inline long long power(long long x, long long y) {     long long res = 1, base = x;     while (y) {       if (y & 1) res = (res * base) % MOD;       base = (base * base) % MOD;       y >>= 1;     }     return res;   }   signed main() {     n = read(), K = read();     for (long long i = 1; i <= n; ++i) s[i] = read(), c += (s[i] == 0);     Mat A, F;     long long t = 0;     for (long long i = 1; i <= c; ++i)       if (s[i] == 0) ++t;     F.val[0][t] = 1;     F.Max_n = 1, F.Max_m = c;     for (long long i = 0; i <= c; ++i) {       if (i != 0) A.val[i - 1][i] = (c - i + 1) * (c - i + 1);       A.val[i][i] = (c * (c - 1) / 2) + ((n - c) * (n - c - 1) / 2) +                     (i * (c - i)) + (c - i) * (n - c - c + i);       if (i != c) A.val[i + 1][i] = (i + 1) * (n - c - c + i + 1);     }     A.Max_n = A.Max_m = c;     long long y = K;     Mat res;     res.I(c);     while (y) {       if (y & 1) res = res * A;       A = A * A;       y >>= 1;     }     F = F * res;     long long ans = F.val[0][c], sum = 0;     for (long long i = 0; i <= c; ++i) sum = (sum + F.val[0][i]) % MOD;     ans = (ans * power(sum, MOD - 2)) % MOD;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     double lift[n], land[n];     for (int i = 0; i < (n); i++) cin >> lift[i] >> land[i];     double ans = 0;     for (int i = n - 1; i >= 0; i--) {       ans = (ans + m / land[(i + 1) % n]) / (1 - 1 / land[(i + 1) % n]);       if (ans < 0 || ans > 1e9) return !(cout << -1);       ans = (ans + m / lift[i]) / (1 - 1 / lift[i]);       if (ans < 0 || ans > 1e9) return !(cout << -1);     }     cout << fixed << setprecision(7) << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long int a[N], l[N];   int main() {     int n;     long long int ans(0);     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]), a[i]++;     long long int o(a[n] + 1);     for (int i = n; i >= 1; --i) l[i] = o = max(--o, a[i]);     for (int i = 1; i <= n; ++i) l[i] = max(l[i], l[i - 1]);     for (int i = 1; i <= n; ++i) ans += (l[i] - a[i]);     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int add(int a, int b, int m = 1000000007) {     a += b;     if (a >= m) a -= m;     return a;   }   inline int mul(int a, int b, int m = 1000000007) {     return (int)(((long long)a * (long long)b) % m);   }   inline int norm(int x, int m = 1000000007) {     if (x >= m) x %= m;     if (x < 0) x += m;     return x;   }   inline int neg(int x, int m = 1000000007) {     x = -x;     return norm(x);   }   int c[501];   int dp[501][501];   int f(int i, int j) {     if (i == j) return 1;     if (i == j - 1) return 2 - (int)(c[i] == c[j]);     int &ans = dp[i][j];     if (ans != -1) return ans;     ans = 1000000007;     for (int k = i; k <= j - 1; ++k) {       ans = min(ans, f(i, k) + f(k + 1, j));     }     if (c[i] == c[j]) ans = min(ans, f(i + 1, j - 1));     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> c[i];     memset(dp, -1, sizeof(dp));     cout << f(1, n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, rs, j;   vector<long long> ball;   vector<long long>::iterator pos;   int main() {     scanf( %lld , &n);     for (i = 0; i < n; i++) scanf( %lld , &j), ball.push_back(j);     sort(ball.begin(), ball.end());     rs = 0;     i = 0;     if (n % 2 == 0) {       j = ball[0] + ball[1];       pos = lower_bound(ball.begin() + 2, ball.end(), j);       ball.insert(pos, j);       rs += j;       i = 2;     }     for (; i < n - 1; i += 3) {       j = ball[i] + ball[i + 1] + ball[i + 2];       pos = lower_bound(ball.begin() + i + 3, ball.end(), j);       ball.insert(pos, j);       rs += j;       n++;     }     printf( %lld , rs);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   int main() {     char c;     scanf( %I64d%1c , &n, &c);     c -=  a ;     long long ans = 0;     n -= 1;     if (n % 4 <= 1) {       ans += ((n / 4) * 2 + n % 4) * 6 + n;     } else {       ans += ((n / 4) * 2 + (n % 4 - 2)) * 6 + n - 2;     }     if (c <= 2) {       ans += 4 + c;     } else {       ans += 6 - c;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10240000 )   using namespace std;   const int MAXN = 100010;   int a[MAXN], cnt[MAXN];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     memset(cnt, 0, sizeof(cnt));     int sta = 1, num = 0;     while (num < k) {       if (cnt[a[sta]] == 0) {         num++;       }       cnt[a[sta]]++;       sta++;       if (sta > n) {         break;       }     }     if (num < k) {       printf( -1 -1 n );     } else {       int old = 1, l = 1, r = sta - 1;       int m = r - l + 1;       for (int i = sta; i <= n; i++) {         int j = old + 1;         cnt[a[old]]--;         if (j < i) {           while (a[j] == a[old]) {             cnt[a[old]]--;             j++;             if (j == i) {               break;             }           }         }         if (cnt[a[old]] == 0) {           num--;         }         old = j;         j = i;         while (num < k) {           if (cnt[a[j]] == 0) {             num++;           }           cnt[a[j]]++;           j++;           if (j > n) {             break;           }         }         if (num < k) {           break;         }         i = j - 1;         int tmp = i - old + 1;         if (tmp < m) {           m = tmp;           l = old;           r = i;         }       }       memset(cnt, 0, sizeof(cnt));       for (int i = l; i <= r; i++) {         cnt[a[i]]++;       }       while (cnt[a[l]] > 1) {         cnt[a[l]]--;         l++;       }       printf( %d %d n , l, r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 1; i <= n; i++)       if (!(n % i)) reverse(s.begin(), (s.begin() + i));     cout << s <<   n ;     return 0;   }