malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long a_na_b_mod_c(long long a, long long b, long long c) {     if (b == 0) return 1;     long long t = a_na_b_mod_c(a, (b / 2), c) % c;     if (b % 2 == 0)       return (t * t) % c;     else       return (((t * t) % c) * (a % c)) % c;   }   long long ip(long long a) { return a_na_b_mod_c(a, mod - 2, mod); }   vector<long long> f(1, 1), fi;   long long nCk(long long n, long long k) {     return (((f[n] * fi[k]) % mod) * fi[n - k]) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long k;     cin >> n >> k;     if (!k) {       cout <<  0 n ;       return 0;     }     for (int i = 1; i < n + 79; i++) f.push_back((f.back() * i) % mod);     fi.resize(n + 79);     for (int i = 0; i < n + 79; i++) fi[i] = ip(f[i]);     vector<int> h(n);     for (int i = 0; i < n; i++) {       cin >> h[i];     }     h.push_back(h[0]);     long long eq = 0;     for (int i = 1; i <= n; i++) {       if (h[i] == h[i - 1]) eq++;     }     long long dif = n - eq;     if (!dif) {       cout <<  0 n ;       return 0;     }     long long all = 0;     long long i2 = ip(2);     long long p2 = a_na_b_mod_c(2, dif, mod);     long long kp2 = 1;     for (long long z = 0; z < dif; z++) {       long long non_zero = dif - z;       long long good = p2;       long long zero = non_zero % 2 == 1 ? 0 : nCk(non_zero, non_zero >> 1);       good = ((good - zero + mod) * i2) % mod;       all += (((good * nCk(dif, z)) % mod) * kp2) % mod;       all %= mod;       p2 = (p2 * i2) % mod;       kp2 = (kp2 * (k - 2)) % mod;     }     cout << (all * a_na_b_mod_c(k, eq, mod)) % mod <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     s.insert(0);     int a;     for (int i = 1; i <= n; i++) {       cin >> a;       if (s.find(a) != s.end()) {         s.erase(a);       }       s.insert(i);     }     cout << s.size();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100050;   struct node {     int sa, ea, sb, eb;   } a[N];   int t[N << 1], rt1[N << 1], rt2[N << 1], lc[N * 80], rc[N * 80], tot, n, m1, m2;   bool cnt[N * 80], addv[N * 80];   inline bool cmp1(const node &a, const node &b) { return a.ea < b.ea; }   inline bool cmp2(const node &a, const node &b) { return a.sa < b.sa; }   int add(int pre, int L, int R, int x, int y) {     if (addv[pre]) return pre;     int o = ++tot;     cnt[o] = 1;     if (x <= L && y >= R) {       addv[o] = 1;       lc[o] = lc[pre];       rc[o] = rc[pre];     } else {       int M = L + R >> 1;       addv[o] = 0;       if (x <= M)         lc[o] = add(lc[pre], L, M, x, y);       else         lc[o] = lc[pre];       if (y > M)         rc[o] = add(rc[pre], M + 1, R, x, y);       else         rc[o] = rc[pre];     }     return o;   }   bool ask(int o, int L, int R, int x, int y) {     if (addv[o]) return 0;     if (x <= L && y >= R) return !cnt[o];     int M = L + R >> 1;     return (x > M || ask(lc[o], L, M, x, y)) &&            (y <= M || ask(rc[o], M + 1, R, x, y));   }   inline bool check() {     int i, k = 1;     memset(rt1, 0, sizeof(rt1));     memset(rt2, 0, sizeof(rt2));     tot = 0;     sort(a + 1, a + n + 1, cmp1);     for (i = 1; i <= (m1); ++i) {       rt1[i] = rt1[i - 1];       for (; k <= n && a[k].ea == i; ++k)         rt1[i] = add(rt1[i], 1, m2, a[k].sb, a[k].eb);     }     sort(a + 1, a + n + 1, cmp2);     k = n;     for (i = m1; i >= (1); --i) {       rt2[i] = rt2[i + 1];       for (; k && a[k].sa == i; --k)         rt2[i] = add(rt2[i], 1, m2, a[k].sb, a[k].eb);     }     for (i = 1; i <= (n); ++i)       if (!ask(rt1[a[i].sa - 1], 1, m2, a[i].sb, a[i].eb) ||           !ask(rt2[a[i].ea + 1], 1, m2, a[i].sb, a[i].eb)) {         puts( NO );         return 0;       }     return 1;   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= (n); ++i) {       scanf( %d%d%d%d , &a[i].sa, &a[i].ea, &a[i].sb, &a[i].eb);       t[(i << 1) - 1] = a[i].sa;       t[i << 1] = a[i].ea;     }     sort(t + 1, t + (n << 1) + 1);     m1 = unique(t + 1, t + (n << 1) + 1) - t - 1;     for (i = 1; i <= (n); ++i) {       a[i].sa = lower_bound(t + 1, t + m1 + 1, a[i].sa) - t;       a[i].ea = lower_bound(t + 1, t + m1 + 1, a[i].ea) - t;     }     for (i = 1; i <= (n); ++i) {       t[(i << 1) - 1] = a[i].sb;       t[i << 1] = a[i].eb;     }     sort(t + 1, t + (n << 1) + 1);     m2 = unique(t + 1, t + (n << 1) + 1) - t - 1;     for (i = 1; i <= (n); ++i) {       a[i].sb = lower_bound(t + 1, t + m2 + 1, a[i].sb) - t;       a[i].eb = lower_bound(t + 1, t + m2 + 1, a[i].eb) - t;     }     if (!check()) return 0;     for (i = 1; i <= (n); ++i) {       swap(a[i].sa, a[i].sb);       swap(a[i].ea, a[i].eb);     }     swap(m1, m2);     if (check()) puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }   long long oo = 1e18;   long long const M = 1e9 + 7, N = 3e5 + 9;   int n, m, d;   string s =   ;   int ans = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> d;     vector<int> v;     set<int> s;     map<int, int> mb;     int x;     for (int i = 0; i < n; i++) {       cin >> x;       s.insert(x);       v.push_back(x);     }     int day = 1, cofe = 0;     while (s.size()) {       if (s.lower_bound(cofe) != s.end()) {         cofe = *s.lower_bound(cofe);         s.erase(s.lower_bound(cofe));         mb[cofe] = day;         cofe += d + 1;       } else {         cofe = 0;         day++;       }     }     cout << day << endl;     for (int i = 0; i < n; i++) {       cout << mb[v[i]] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int maxn = 1005;   int c[10], n, s;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1, x; i <= n; i++) scanf( %d , &x), c[x]++;     int ans = INF, I, K, J, t;     for (int i = s / n; i >= 0; i--)       for (int j = (s - c[3] * i) / (n - c[3]); j >= i; j--) {         int k = (s - c[3] * i - c[4] * j) / c[5];         if (k * c[5] - j * c[4] >= ans) break;         if (i * c[3] + j * c[4] + k * c[5] == s &&             ans > (t = abs(i * c[3] - j * c[4]) + abs(j * c[4] - k * c[5])))           ans = t, I = i, J = j, K = k;       }     if (ans != INF)       printf( %d %d %d n , I, J, K);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > data;   vector<bool> parallel;   vector<int> father;   vector<int> spec;   vector<int> opt;   vector<long long> ans;   void dfs(int vertex) {     if (parallel[vertex]) {       int tot = 0;       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs(to);         tot += opt[to];       }       opt[vertex] = tot;     } else {       if (spec[vertex] != -1) {         opt[vertex] = 1;         return;       }       int mn = 1e9;       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs(to);         mn = min(mn, opt[to]);       }       opt[vertex] = mn;     }   }   void dfs2(int vertex, long long need) {     if (parallel[vertex]) {       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs2(to, need);       }     } else {       if (spec[vertex] != -1) {         ans[spec[vertex]] = need;         return;       }       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         if (opt[to] == opt[vertex]) {           dfs2(to, need);           return;         }       }     }   }   void solve() {     int first;     cin >> first;     data = {{}}, father = {-1}, spec = {-1}, parallel = {false};     int cur = 0, u = 0;     while (true) {       char ch =    ;       while (ch ==    ) cin >> ch;       if (ch ==  ( ) {         data.push_back({});         father.push_back(cur), parallel.push_back(false), spec.push_back(-1);         int index = data.size() - 1;         data[cur].push_back(index);         cur = index;       }       if (ch ==  * ) {         data.push_back({});         father.push_back(cur), parallel.push_back(false), spec.push_back(u++);         int index = data.size() - 1;         data[cur].push_back(index);       }       if (ch ==  P ) parallel[cur] = true;       if (ch ==  ) ) {         cur = father[cur];       }       if (cur == 0) break;     }     ans.assign(u, 0);     opt.assign(data.size(), -1);     dfs(1);     long long need = (long long)first * opt[1];     dfs2(1, need);     cout <<  REVOLTING  ;     for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; ++i) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long int c[2020][2020];   int main() {     long long int n, k, sum = 0;     cin >> n >> k;     for (int i = 0; i < ((int)(n)); i++) {       c[i][i] = -1;     }     if (k >= 3) {       long long int tmp;       for (int i = 0; i < ((int)(n - 1)); i++) {         for (int j = (int)(i + 1); j < ((int)(n)); j++) {           scanf( %I64d , &tmp);           sum += tmp;         }       }     } else {       for (int i = 0; i < ((int)(n - 1)); i++) {         for (int j = (int)(i + 1); j < ((int)(n)); j++) {           cin >> c[i][j];           c[j][i] = c[i][j];           if (c[i][j] > -1) {             sum += c[i][j];           }         }       }     }     if (k != 2) {       double ress = (double)(sum * 2) / (double)n;       cout << (long long int)(floor(ress)) << endl;     } else {       long long int res = 0;       for (int i = 0; i < ((int)(n)); i++) {         vector<long long int> pl;         for (int j = 0; j < ((int)(n)); j++) {           if (c[i][j] > -1) pl.push_back(c[i][j]);         }         for (int j = 0; j < ((int)(((long long int)(pl).size()))); j++) {           res += pl[j] * (((long long int)(pl).size()) - 1);         }       }       double ress = (double)(res) / (double)(n * (n - 1) / 2);       cout << (int)(floor(ress)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i, t;     vector<int> a;     for (i = 0; i < n; i++) {       cin >> t;       a.push_back(t);     }     for (i = 0; i < n - 1; i++) {       if (a[i] % 2 != 0) {         a[i] %= 2;         a[i + 1]--;         if (a[i + 1] < 0) {           cout <<  NO ;           return 0;         }       }     }     if (a[i] & 1) {       cout <<  NO ;       return 0;     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Q = 1e9 + 7;   long long poww(long long a, long long b) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > Q) x %= Q;       }       y = (y * y);       if (y > Q) y %= Q;       b /= 2;     }     return x;   }   long long C[52][52];   void binomialCoeff() {     long long i, j;     for (i = 0; i <= 50; i++) {       for (j = 0; j <= 50; j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long ans = 0;     if (m == 1) {       ans = 1;     } else if (k == 1 || k > n) {       ans = poww(m, n);     } else if (n == k) {       ans = poww(m, (k + 1) / 2);       ans %= Q;     } else if (k % 2 != 0) {       ans = m * m;       ans %= Q;     } else {       ans = m;       ans %= Q;     }     ans %= Q;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> ar(n + 1, 1e10);     vector<long long> cur(n + 1, 1);     for (long long i = 1; i <= n; i++) {       cin >> ar[i];       if (ar[i] == ar[i - 1]) cur[i] = cur[i - 1] + 1;     }     long long ans = 0;     for (long long i = 1; i <= n; i++) ans += cur[i];     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     string s;     for (int i = 1; i <= n; i++) {       string str;       ostringstream temp;       temp << i;       s += temp.str();     }     cout << s[n - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char i = getchar();     long long f = 1, res = 0;     while (i <  0  || i >  9 ) {       if (i ==  - ) f = -1;       i = getchar();     }     while (i >=  0  && i <=  9 ) {       res = res * 10 + i -  0 ;       i = getchar();     }     return res * f;   }   const int N = 1e5 + 50;   long long h[N], a[N], n, m, k, p;   struct bamboo {     long long time, id;     bool operator<(const bamboo& A) const { return time > A.time; }     bamboo(long long T, long long ID) : time(T), id(ID) {}   };   priority_queue<bamboo> q;   long long cnt[N];   bool pd(long long mid) {     while (!q.empty()) {       q.pop();     }     memset(cnt, 0, sizeof(cnt));     for (register int i = 1; i <= n; ++i) {       if (mid - a[i] * m < h[i]) {         q.push(bamboo(mid / a[i], i));       }     }     for (register int i = 1; i <= m; ++i) {       if (q.empty()) {         break;       }       for (register int j = 1; j <= k; ++j) {         if (q.empty()) {           break;         }         bamboo now = q.top();         q.pop();         if (now.time < i) {           return false;         }         cnt[now.id]++;         if (mid + cnt[now.id] * p - a[now.id] * m < h[now.id]) {           q.push(bamboo((mid + cnt[now.id] * p) / a[now.id], now.id));         }       }     }     return q.empty();   }   int main() {     n = read();     m = read();     k = read();     p = read();     long long l = 0, r = -10, ans = -1, mid;     for (register int i = 1; i <= n; ++i) {       h[i] = read();       a[i] = read();       r = max(r, h[i] + a[i] * m);     }     while (l <= r) {       mid = (l + r) >> 1;       if (pd(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tostr(const T& t) {     ostringstream os;     os << t;     return os.str();   }   int adj[110][110];   int adj2[110][110];   int N, M;   set<int> emp[110];   bool are_connected2(int a, int b) {     set<int>::iterator it;     for (it = emp[a].begin(); it != emp[a].end(); ++it) {       int x = *it;       if (emp[b].count(x)) return true;     }     return false;   }   void floyd() {     for (int k = (int)(0); k <= (int)(N - 1); ++k)       for (int i = (int)(0); i <= (int)(N - 1); ++i)         for (int j = (int)(0); j <= (int)(N - 1); ++j) {           if (adj[i][k] == 9999999 || adj[k][j] == 9999999) continue;           adj[i][j] = 1;         }   }   bool are_connected(vector<int>& comp1, vector<int>& comp2) {     for (int i = (int)(0); i <= (int)(comp1.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp2.size() - 1); ++j) {         if (adj[comp1[i]][comp2[j]] != 9999999) return true;       }     }     return false;   }   vector<vector<int> > find_scc() {     floyd();     vector<int> colors = vector<int>(N, -1);     int cur_color = -1;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (adj[i][j] != 9999999 && adj[j][i] != 9999999) {           if (colors[i] != -1)             colors[j] = colors[i];           else {             ++cur_color;             colors[i] = colors[j] = cur_color;           }         }       }     }     for (int i = (int)(0); i <= (int)(colors.size() - 1); ++i)       if (colors[i] == -1) colors[i] = ++cur_color;     int ncolors = cur_color + 1;     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj2[i][j] = 9999999;     vector<vector<int> > comp_list = vector<vector<int> >(ncolors);     for (int i = (int)(0); i <= (int)(ncolors - 1); ++i) {       for (int j = (int)(0); j <= (int)(N - 1); ++j) {         if (colors[j] == i) comp_list[i].push_back(j);       }     }     for (int i = (int)(0); i <= (int)(comp_list.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp_list.size() - 1); ++j) {         if (are_connected(comp_list[i], comp_list[j])) {           adj2[i][j] = 1;         }       }     }     return comp_list;   }   int main() {     cin >> N >> M;     bool nonZero = false;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       int k;       cin >> k;       for (int j = (int)(0); j <= (int)(k - 1); ++j) {         int a;         cin >> a;         --a;         emp[i].insert(a);         if (a != 0) nonZero = true;       }     }     if (!nonZero) {       cout << N << endl;       return 0;     }     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj[i][j] = 9999999;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (are_connected2(i, j)) {           adj[i][j] = 1;           adj[j][i] = 1;         }       }     }     vector<vector<int> > scc = find_scc();     int ans = (int)scc.size() - 1;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   }   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> items;     for (int i = 0; i < n; i++) {       int item;       cin >> item;       items.push_back(item);     }     sort(items.rbegin(), items.rend());     set<long long> st;     long long cnt = 0;     for (int i = n - 1; i >= 0; i--) {       while (items[i]) {         if (st.count(items[i]) == 0) {           cnt += items[i];           st.insert(items[i]);           break;         }         items[i]--;       }     }     cout << cnt << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     cout.tie(nullptr);     cin.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     int pause;     cin >> pause;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007, BIG = 0x3f3f3f3f;   int n;   vector<int> a;   vector<int> Process() {     vector<int> ans = {0};     int x = 0;     for (int i = 0; i < n; i++) {       if (a[i] < 0 && ++x > 2) {         x = 1;         ans.push_back(0);       }       ans.back()++;     }     return ans;   }   void Output() {     const vector<int> ans = Process();     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (cin >> n) {       a.resize(n);       for (int i = 0; i < n; i++) cin >> a[i];       Output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int i, t;     char str[25];     while (~scanf( %s , str)) {       int len = strlen(str);       t = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  4  || str[i] ==  7 ) {           t++;         }       }       if (t == 4 || t == 7)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n, a[200001], mp[200001], x, y;   vector<int> to[200001], t2[200001];   int fa[200001], d[200001], sz[200001], son[200001];   int top[200001], dfn[200001], cnt;   int f[200001], v[200001], p[200001], g[200001];   int st[200001], tp, s, sum, ans;   bool in[200001];   inline int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; }   inline int sub(int x, int y) { return x < y ? x + mod - y : x - y; }   inline int power(int a, int n) {     int tp = 1;     while (n) {       if (n & 1) tp = 1ll * tp * a % mod;       a = 1ll * a * a % mod, n >>= 1;     }     return tp;   }   inline bool cmp(int i, int j) { return dfn[i] < dfn[j]; }   inline void dfs1(int i) {     sz[i] = 1;     dfn[i] = ++cnt;     for (int j : to[i]) {       if (j == fa[i]) continue;       fa[j] = i, d[j] = d[i] + 1;       dfs1(j);       sz[i] += sz[j];       if (sz[son[i]] < sz[j]) son[i] = j;     }   }   inline void dfs2(int i) {     if (son[i]) top[son[i]] = top[i], dfs2(son[i]);     for (int j : to[i])       if (j != fa[i] && j != son[i]) top[j] = j, dfs2(j);   }   inline int lca(int x, int y) {     while (top[x] != top[y]) {       if (d[top[x]] < d[top[y]]) swap(x, y);       x = fa[top[x]];     }     return d[x] < d[y] ? x : y;   }   inline int dfs(int i) {     g[i] = 0;     if (in[i]) g[i] = v[i];     int ans = 0;     for (int j : t2[i]) {       ans = add(ans, dfs(j)), g[i] = add(g[i], g[j]);       ans = (ans + 1ll * (d[j] - d[i]) * g[j] % mod * sub(sum, g[j])) % mod;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , a + i), mp[a[i]] = i;     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       to[x].push_back(y), to[y].push_back(x);     }     dfs1(1), top[1] = 1, dfs2(1);     f[1] = 1;     for (int i = 2; i <= n; i++) {       if (f[i]) continue;       f[i] = i - 1;       for (int j = 2 * i; j <= n; j += i) {         if ((j / i) % i)           f[j] = f[i] * f[j / i];         else           f[j] = i * f[j / i];       }     }     for (int i = 1; i <= n; i++) v[i] = f[a[i]];     for (int i = 1; i <= n; i++) f[i] = 1ll * i * power(f[i], mod - 2) % mod;     for (int i = 1; i <= n; i++)       for (int j = 2 * i; j <= n; j += i) f[j] = sub(f[j], f[i]);     for (int t = 1; t <= n; t++) {       sum = s = 0;       for (int i = t; i <= n; i += t)         p[++s] = mp[i], sum = add(sum, v[mp[i]]), in[mp[i]] = 1;       sort(p + 1, p + s + 1, cmp);       st[tp = 1] = p[1], t2[p[1]].clear();       for (int i = 2; i <= s; i++) {         int x = lca(p[i], st[tp]), lt = 0;         while (d[st[tp]] > d[x]) {           if (lt) t2[st[tp]].push_back(lt);           lt = st[tp--];         }         if (st[tp] != x) st[++tp] = x, t2[x].clear();         if (lt) t2[x].push_back(lt);         st[++tp] = p[i], t2[p[i]].clear();       }       while (tp > 1) t2[st[tp - 1]].push_back(st[tp]), tp--;       ans = (ans + 1ll * dfs(st[1]) * f[t]) % mod;       for (int i = 1; i <= s; i++) in[p[i]] = 0;     }     cout << 2ll * ans * power(1ll * n * (n - 1) % mod, mod - 2) % mod;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n;     string str;     string ans =   ;     while (cin >> n) {       cin >> str;       int now = 0;       int vis[26];       ans =   ;       while (now < str.length()) {         char tmp = str[now];         int diff = 0;         memset(vis, 0, sizeof vis);         int flag = 0;         for (int i = now + 1; i < str.length(); i++) {           if (str[i] != tmp) {             flag = 1;             ans.push_back(tmp);             ans.push_back(str[i]);             now = i + 1;             break;           }           if (!vis[str[i] -  a ]) {             diff++;             if (diff > 2) {               flag = 1;               now = now + 1;               break;             }           }         }         if (flag == 0) {           break;         }       }       cout << str.length() - ans.length() << endl;       cout << ans << endl;     }   }