malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct Node {     long long l, r;     mutable long long val;     Node(long long l = 0, long long r = 0, long long v = 0)         : l(l), r(r), val(v) {}     bool operator<(const Node& rv) const { return l < rv.l; }   };   long long n, m;   set<Node> t;   long long a[100005];   long long seed;   long long vmax;   long long qpow(long long x, long long p, long long m) {     long long ans = 1;     long long base = x;     while (p) {       if (p & 1) ans = (ans * base) % m;       base = (base * base) % m;       p >>= 1;     }     return ans;   }   long long rnd() {     long long ans = seed;     seed = (seed * 7 + 13) % 1000000007;     return ans;   }   set<Node>::iterator split(long long p) {     set<Node>::iterator it = t.lower_bound(Node(p));     if (it != t.end() && it->l == p) {       return it;     }     --it;     long long l = it->l, r = it->r, val = it->val;     t.erase(it);     t.insert(Node(l, p - 1, val));     return t.insert(Node(p, r, val)).first;   }   void assign(long long l, long long r, long long v) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     t.erase(begin, end);     t.insert(Node(l, r, v));   }   void add(long long l, long long r, long long k) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     for (set<Node>::iterator it = begin; it != end; ++it) {       it->val += k;     }   }   long long kth(long long l, long long r, long long k) {     vector<pair<long long, long long> > v;     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     for (set<Node>::iterator it = begin; it != end; ++it) {       v.push_back(make_pair(it->val, it->r - it->l + 1));     }     sort(v.begin(), v.end());     for (long long i = 0; i < v.size(); ++i) {       k -= v[i].second;       if (k <= 0) return v[i].first;     }     return -1;   }   long long power(long long l, long long r, long long k, long long mod) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     long long ans = 0;     for (set<Node>::iterator it = begin; it != end; ++it) {       ans = (ans +              (((qpow(it->val % mod, k, mod) % mod) * (it->r - it->l + 1 % mod)) %               mod)) %             mod;     }     return ans % mod;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> m >> seed >> vmax;     for (long long i = 1; i <= n; ++i) {       a[i] = (rnd() % vmax) + 1;       t.insert(Node(i, i, a[i]));     }     for (long long i = 1; i <= m; ++i) {       long long opt = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1,                 x, y;       if (l > r) swap(l, r);       if (opt == 3)         x = (rnd() % (r - l + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (opt == 4) y = (rnd() % vmax) + 1;       if (opt == 1) {         add(l, r, x);       } else if (opt == 2) {         assign(l, r, x);       } else if (opt == 3) {         cout << kth(l, r, x) << endl;       } else {         cout << power(l, r, x, y) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxp = 22;   const long double EPS = 1e-18;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   const int N = 2e5 + 1;   void yesno(bool a) {     if (a) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   long long power(long long x, long long n, long long m) {     if (n == 0) return 1;     long long u = power(x, n / 2, m);     u = (u * u) % m;     if (n % 2) u = (u * x) % m;     return u;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     long long i, arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     if (n == 1) {       cout << 1 <<     << 1 <<   n ;       cout << -arr[0] <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       return 0;     }     cout << 1 <<     << n - 1 <<   n ;     for (i = 0; i < n - 1; i++) {       long long num = arr[i] % n;       cout << num * (n - 1) <<    ;       arr[i] += num * (n - 1);     }     cout <<   n ;     cout << n <<     << n <<   n ;     long long num = arr[n - 1] % n;     cout << (n - num) <<   n ;     arr[n - 1] += n - num;     cout << 1 <<     << n <<   n ;     for (i = 0; i < n; i++) cout << -arr[i] <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     char c[n][n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         cin >> c[i][j];       }     }     bool re = 1, ce = 1;     for (long long i = 0; i < n; i++) {       re = 1;       for (long long j = 0; j < n; j++) {         if (c[i][j] !=  E ) {           re = 0;         }       }       if (re == 1) {         break;       }     }     for (long long j = 0; j < n; j++) {       ce = 1;       for (long long i = 0; i < n; i++) {         if (c[i][j] !=  E ) {           ce = 0;         }       }       if (ce == 1) {         break;       }     }     if (re == 1 && ce == 1) {       cout <<  -1 ;       return 0;     }     if (re == 1) {       for (long long j = 0; j < n; j++) {         for (long long i = 0; i < n; i++) {           if (c[i][j] !=  E ) {             cout << i + 1 <<     << j + 1 <<   n ;             break;           }         }       }     } else {       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           if (c[i][j] !=  E ) {             cout << i + 1 <<     << j + 1 <<   n ;             break;           }         }       }     }   }
#include <bits/stdc++.h>   int main() {     int n;     std::string s;     std::cin >> n >> s;     int cnt = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 )         cnt++;       else {         std::cout << cnt;         cnt = 0;       }     }     std::cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[105][105][2];   struct seg {     int a;     long long len;     bool operator<(const seg &p) const { return a < p.a; }   } a[105];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%lld , &a[i].a, &a[i].len);     }     sort(a + 1, a + n + 1);     long long ans = 0;     a[0].a = -2e9;     for (int i = 0; i <= n; ++i)       for (int j = 0; j <= i; ++j) {         for (int k = 0; k <= 1; ++k) {           ans = max(ans, f[i][j][k]);           int pr = a[j].a + k * a[j].len;           int R, x;           for (int p = i + 1, mx = -2e9; p <= n; ++p) {             for (int q = 0; q <= 1; ++q) {               int r = a[p].a + q * a[p].len;               if (r > mx) mx = r, R = p, x = q;               f[p][R][x] =                   max(f[p][R][x],                       f[i][j][k] + min(a[p].len, (long long)r - pr) + (mx - r));             }           }         }       }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int maxn = 1e5 + 10, lg = 18;   int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg],                           comp[maxn], c1;   bool dp[maxn][lg];   vector<int> G[maxn];   bool mark[maxn];   void dfs1(int a, int p) {     par[a][0] = p;     for (int i = 1; i < lg; i++) {       par[a][i] = par[par[a][i - 1]][i - 1];     }     low[a] = H[a];     mark[a] = 1;     for (int b : G[a]) {       if (!mark[b]) {         H[b] = H[a] + 1;         comp[b] = comp[a];         dfs1(b, a);         low[a] = min(low[a], low[b]);       } else if (b != p) {         low[a] = min(low[a], H[b]);       }     }   }   void dfs2(int a) {     mark[a] = 1;     for (int b : G[a]) {       if (!mark[b]) {         if (low[b] >= H[a]) {           cid[b] = csize++;         } else {           cid[b] = cid[a];         }         dfs2(b);       } else if (H[a] > H[b]) {         int dis = H[a] - H[b];         if ((dis & 1) == 0) {           ok[cid[a]] = 1;         }       }     }   }   void dfs3(int a) {     mark[a] = 1;     dp[a][0] = (ok[cid[a]]);     for (int b : G[a]) {       if (!mark[b]) {         dfs3(b);       }     }   }   bool lca(int a, int b) {     bool ans = 0;     if (H[a] > H[b]) swap(a, b);     for (int i = lg - 1; i >= 0; i--) {       if (H[par[b][i]] >= H[a]) {         ans |= dp[b][i];         b = par[b][i];       }     }     if (a == b) {       return ans;     }     for (int i = lg - 1; i >= 0; i--) {       if (par[b][i] != par[a][i]) {         ans |= dp[a][i];         ans |= dp[b][i];         a = par[a][i];         b = par[b][i];       }     }     ans |= dp[a][0];     ans |= dp[b][0];     return ans;   }   int32_t main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (!mark[i]) {         comp[i] = c1++;         dfs1(i, i);       }     }     fill(mark, mark + n, 0);     for (int i = 0; i < n; i++) {       if (!mark[i]) {         cid[i] = csize++;         dfs2(i);       }     }     fill(mark, mark + n, 0);     for (int i = 0; i < n; i++) {       if (!mark[i]) {         dfs3(i);       }     }     for (int j = 0; j < lg - 1; j++) {       for (int i = 0; i < n; i++) {         dp[i][j + 1] = dp[i][j] | dp[par[i][j]][j];       }     }     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       if (H[a] > H[b]) swap(a, b);       if (a == b || comp[a] != comp[b]) {         printf( No n );         continue;       }       if ((H[b] - H[a]) & 1) {         printf( Yes n );         continue;       }       bool ans = lca(a, b);       printf(ans ?  Yes n  :  No n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n];     int count[5005] = {0};     for (int i = 0; i < n; i++) {       cin >> a[i];       count[a[i]]++;     }     int c[n];     int d = 1;     for (int i = 1; i <= 5000; i++) {       if (count[i] > k) {         cout <<  NO               <<   n ;         return 0;       }     }     cout <<  YES           <<   n ;     if (k == 1) {       for (int i = 0; i < n; i++) {         cout <<  1               <<    ;       }     } else {       for (int i = 1; i <= 5000; i++) {         for (int j = 0; j < n; j++) {           if (a[j] == i) {             c[j] = d;             d++;           }           if (d > k) d = d % k;         }       }       for (int i = 0; i < n; i++) {         cout << c[i] <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const long long int LINF = 1LL * INF * INF;   const int MAXN = 2e5 + 10;   const int MAXM = 5e3 + 10;   priority_queue<int> pq;   vector<vector<int> > graph;   queue<int> que;   pair<int, int> A[20];   long long int dp[20][(1 << 20)];   long long int sum[(1 << 20)];   long long int solve(int here, int cur, int n) {     if (dp[here][cur] != -1) return dp[here][cur];     long long int res = 0;     for (int i = 0; i < n; i++) {       if (i == here) continue;       if ((1 << i) & cur) {         if (A[i].second == A[here].second) continue;         res += solve(i, cur ^ (1 << here), n);         res %= 1000000007;       }     }     return dp[here][cur] = res;   }   int main() {     int n, m, k, a, b, x, y;     int cnt = 0;     int mx = 0;     int mn = INF;     int cur = 0, idx = -1;     int T;     cin >> n >> T;     for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second;     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++) dp[i][j] = -1;     for (int i = 0; i < n; i++) dp[i][(1 << i)] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++) solve(i, j, n);     for (int i = 0; i < (1 << n); i++)       for (int j = 0; j < n; j++)         if ((1 << j) & i) sum[i] += (long long int)A[j].first;     long long int res = 0;     for (int i = 0; i < (1 << n); i++) {       if (sum[i] != T) continue;       for (int j = 0; j < n; j++)         if ((1 << j) & i) {           res += (long long int)dp[j][i];           res %= 1000000007;         }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q[1000005];   long long i, j, t, tot, C, cnt;   long long loc[10005], op[10005];   long long n, m, k, H, x, y, ans, tmp;   long long a[100005], w[100005], e[25], dis[10005], heap[10005];   bool used[100005], f[10005];   map<long long, long long> A;   map<long long, long long>::iterator it;   void Spfa(long long s) {     long long i, head, tail, x, v;     for (i = 1; i <= k; i++) {       dis[i] = 1999999999999999999LL;       f[i] = false;     }     dis[s + 1] = 1;     f[s + 1] = true;     q[1] = s + 1;     head = 1;     tail = 2;     while (head != tail) {       x = q[head];       f[x] = false;       for (i = 1; i <= tot; i++)         if (dis[x] + e[i] < dis[(dis[x] + e[i]) % k + 1]) {           v = (dis[x] + e[i]) % k + 1;           dis[v] = dis[x] + e[i];           if (!f[v]) {             q[tail] = v;             f[v] = true;             tail++;           }         }       head++;     }   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &H, &n, &m, &k);     for (i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i], &w[i]);     tot = 0;     memset(used, false, sizeof used);     x = 1 % k;     for (i = 1; i <= n; i++) {       if (a[i] % k == x) {         used[i] = true;         it = A.find(w[i]);         if (it == A.end())           A.insert(make_pair(w[i], 1));         else           A[w[i]]++;       }     }     for (t = 1; t <= m; t++) {       scanf( %I64d , &C);       if (C == 1) {         scanf( %I64d , &x);         e[++tot] = x;         Spfa(1 % k);         for (i = 1; i <= n; i++)           if (dis[a[i] % k + 1] <= a[i]) {             if (!used[i]) {               used[i] = true;               it = A.find(w[i]);               if (it == A.end())                 A.insert(make_pair(w[i], 1));               else                 A[w[i]]++;             }           }       } else if (C == 2) {         scanf( %I64d%I64d , &x, &y);         if (used[x]) {           it = A.find(w[x]);           tmp = it->second;           if (tmp == 1)             A.erase(w[x]);           else             A[w[x]]--;           w[x] -= y;           it = A.find(w[x]);           if (it != A.end())             A[w[x]]++;           else             A.insert(make_pair(w[x], 1));         } else           w[x] -= y;       } else {         if (A.size() == 0) {           printf( 0 n );           continue;         }         it = A.end();         it--;         ans = it->first;         printf( %I64d n , ans);         tmp = it->second;         if (tmp == 1)           A.erase(ans);         else           A[ans]--;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int r = min(a / 3, min(b / 2, c / 2));     a -= 3 * r;     b -= 2 * r;     c -= 2 * r;     int ans = 7 * r;     int cnt1 = 0;     for (int i = 0; i < 14; i++) {       int a1 = a, b1 = b, c1 = c, cnt = 0;       for (int j = i; j < 14; j++) {         if (j == 0 || j == 3 || j == 6 || j == 7 || j == 10 || j == 13) a1--;         if (j == 1 || j == 5 || j == 8 || j == 12) b1--;         if (j == 2 || j == 4 || j == 9 || j == 11) c1--;         if (a1 < 0 || b1 < 0 || c1 < 0) {           cnt1 = max(cnt1, cnt);           break;         }         cnt++;       }     }     cout << ans + cnt1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[100000], arr1[100000], n, x, z, co = 0, co1 = 0, k, m,                                                   fin = 1000000;     map<long long, long long> left;     map<long long, long long> right;     cin >> n;     if (n % 2 == 0)       k = n / 2;     else       k = (n / 2) + 1;     for (int i = 0; i < n; i++) {       cin >> x >> z;       if (x == z) {         if (left[x] == 0) {           arr[co++] = x;           left[x]++;         } else           left[x]++;       } else {         if (left[x] == 0) {           arr[co++] = x;           left[x]++;         } else           left[x]++;         if (right[z] == 0) {           arr1[co1++] = z;           right[z]++;         } else           right[z]++;       }     }     for (int i = 0; i < co; i++) {       m = 1000001;       if ((left[arr[i]] + right[arr[i]]) >= k) {         m = k - left[arr[i]];         if (m < 0) {           cout <<  0 ;           exit(0);         }       }       if (m < fin) {         fin = m;       }     }     if (fin == 1000000) {       for (int i = 0; i < co1; i++) {         if (right[arr1[i]] >= k) {           cout << k;           exit(0);         }       }     }     if (fin == 1000000)       cout <<  -1 ;     else       cout << fin;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N6 = 1e6 + 6;   using namespace std;   long long n, m, x, y, sum1, sum2, ans1, ans2;   int main() {     cin >> n >> x >> y;     if (n > y) {       cout << -1;       return 0;     }     sum1 = y - n + 1;     sum1 *= sum1;     sum1 += (n - 1);     if (sum1 >= x) {       for (int i = 1; i < n; ++i) {         cout << 1 <<    ;       }       cout << y - n + 1;     } else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1050;   int dp[maxn][9], nxt[maxn][9][maxn], a[maxn], n, cnt[9];   inline int ask(int k) { return (1 << (k - 1)); }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= 8; ++j) cnt[j] = 0;       for (int j = 1; j <= 8; ++j)         for (int k = 1; k <= n; ++k) nxt[i][j][k] = 1e9;       for (int j = i; j <= n; ++j) nxt[i][a[j]][++cnt[a[j]]] = j;     }     int ans = 0;     for (int num = 0; num * 8 <= n; ++num) {       for (int i = 0; i < 256; ++i)         for (int k = 0; k <= 8; ++k) dp[i][k] = 1e9;       dp[0][0] = 1;       for (int i = 0; i < 256; ++i)         for (int j = 0; j <= 8; ++j)           for (int k = 1; k <= 8; ++k) {             if (dp[i][j] > n || ask(k) & i) continue;             dp[i ^ ask(k)][j] = min(dp[i ^ ask(k)][j], nxt[dp[i][j]][k][num] + 1);             dp[i ^ ask(k)][j + 1] =                 min(dp[i ^ ask(k)][j + 1], nxt[dp[i][j]][k][num + 1] + 1);           }       for (int i = 0; i <= 8; ++i)         if (dp[255][i] <= n + 1) ans = max(ans, 8 * num + i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using lint = long long;   using ldouble = long double;   void solve() {     int n, d;     std::cin >> n >> d;     std::vector<int> vs(n, 1);     int diff = n * (n - 1) / 2 - d;     if (diff < 0) {       std::cout <<  NO  << std::endl;       return;     }     int head = 1;     for (int v = n - 1; v > head; --v) {       int to = std::max(v - diff, head);       --vs[v];       ++vs[to];       diff -= v - to;       if (diff == 0) break;       while (vs[head] == (1 << head)) ++head;     }     if (diff > 0) {       std::cout <<  NO  << std::endl;       return;     }     std::cout <<  YES  << std::endl;     int p = 1;     for (int i = 1; i < n; ++i) {       int v = p, ch = 0;       for (int j = 0; j < vs[i]; ++j) {         std::cout << v <<    ;         if (++ch == 2) {           ++v;           ch = 0;         }       }       p += vs[i - 1];     }     std::cout << std::endl;   }   int main() {     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::ios::sync_with_stdio(false);     int q;     std::cin >> q;     while (q--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       k++;       long long A[n];       for (long long i = 0; i < n; i++) {         cin >> A[i];         long long t = 1;         while (A[i]--) {           t *= 10;         }         A[i] = t;       }       long long ans = 0;       for (long long i = 0; i < n; i++) {         long long cnt = k;         if (i != n - 1) {           cnt = min(cnt, A[i + 1] / A[i] - 1);         }         ans += A[i] * 1LL * cnt;         k -= cnt;         if (k == 0) break;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void r(int b, int p, int f, int h, int c);   int main() {     int b, p, f, h, c, t;     cin >> t;     while (t--) {       cin >> b >> p >> f >> h >> c;       r(b, p, f, h, c);     }   }   void r(int b, int p, int f, int h, int c) {     int i, j, k, t = 0;     i = b / 2;     if (i == 0) {       cout << 0 << endl;     } else {       if (i >= (p + f)) {         t = (p * h) + (c * f);         cout << t << endl;       } else {         if (h >= c) {           if (p >= i) {             t = (i * h);             cout << t << endl;           } else {             t = (h * p);             i = i - p;             t = t + (i * c);             cout << t << endl;           }         } else {           if (f >= i) {             t = (i * c);             cout << t << endl;           } else {             t = (c * f);             i = i - f;             t = t + (i * h);             cout << t << endl;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   bool is_simple(int a) {     for (int i = 2; i < a; ++i) {       if (a % i == 0) return false;     }     return true;   }   int elems[200009] = {0};   int addings[200009] = {0};   int removes[200009] = {0};   vector<string> orders;   int main() {     int n;     double current_mean = 0.;     long long cur_num = 1;     scanf( %d , &n);     char buf[100];     gets(buf);     orders.reserve(n);     for (int i = 1; i < n + 1; ++i) {       gets(buf);       orders.push_back(string(buf));       int t = orders[i - 1][0] -  0 ;       addings[i] = addings[i - 1];       removes[i] = removes[i - 1];       if (t == 2) addings[i]++;       if (t == 3) removes[i]++;     }     for (int i = 0; i < n; ++i) {       stringstream ss(orders[i]);       int t;       ss >> t;       if (t == 1) {         int x, a;         ss >> a >> x;         double ttt = current_mean * cur_num;         ttt += a * x;         current_mean = ttt / cur_num;         int start_change = cur_num - (removes[n] - removes[i]);         if (start_change < 0) start_change = 0;         for (int i = start_change; i < a && i < cur_num; ++i) elems[i] += x;       }       if (t == 2) {         int k;         ss >> k;         elems[cur_num] = k;         cur_num++;         double ttt = current_mean * (cur_num - 1);         ttt += k;         current_mean = ttt / cur_num;       }       if (t == 3) {         double ttt = current_mean * (cur_num);         ttt -= elems[cur_num - 1];         cur_num--;         current_mean = ttt / cur_num;       }       printf( %.6f n , current_mean);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   long long sum[30];   char fir[210000], sec[210000];   int main() {     int len, i;     double ans, cnt;     scanf( %d , &len);     scanf( %s%s , fir, sec);     cnt = 1LL * len * (len + 1) * (2 * len + 1) / 6;     ans = 0;     memset(sum, 0, sizeof(sum));     for (i = len - 1; i >= 0; i--) {       sum[fir[i] -  A ] += len - i;       ans += sum[sec[i] -  A ] * (i + 1) / cnt;     }     memset(sum, 0, sizeof(sum));     for (i = len - 1; i >= 0; i--) {       ans += sum[fir[i] -  A ] * (i + 1) / cnt;       sum[sec[i] -  A ] += len - i;     }     printf( %.15lf n , 1.0 * ans);     return 0;   }