malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int pwr(long long int base, long long int p, long long int mod) {     long long int ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n;     scanf( %d , &n);     int a[n + 1];     int par[300005];     int cnt = 0;     int lvl = 0, flag = 0, p = -1;     vector<int> g[n + 2];     for (int i = 0; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 1; j <= a[i]; j++) {         g[i].push_back(++cnt);         par[cnt] = lvl;       }       lvl = cnt;       if (i >= 1) {         if (a[i] > 1 && a[i - 1] > 1) flag = i;       }     }     if (flag == 0) {       printf( perfect n );       return 0;     }     printf( ambiguous n );     for (int i = 1; i <= cnt; i++) {       printf( %d  , par[i]);     }     printf(  n );     par[g[flag][0]] = g[flag - 1][0];     for (int i = 1; i <= cnt; i++) {       printf( %d  , par[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 1e5 + 10;   vector<long long> adj[max_n];   long long par[max_n], st[max_n], p[max_n], ft[max_n], doc[max_n], x[max_n],       l[max_n], r[max_n], cnt, tmp, k, n, m;   bool mark[max_n];   int get_par(int u) { return par[u] == u ? u : par[u] = get_par(par[u]); }   void dfs(long long v) {     st[v] = cnt++;     for (auto u : adj[v]) dfs(u);     ft[v] = cnt;   }   bool cmp(long long v, long long u) {     if (get_par(v) == get_par(u) && st[v] >= st[u] && ft[v] <= ft[u])       return true;     else       return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       par[i] = i;       p[i] = i;     }     while (m--) {       int t;       cin >> t;       long long v, u;       if (t == 1) {         cin >> v >> u;         par[v] = u;         p[v] = u;       } else if (t == 2) {         cin >> v;         l[tmp] = v;         r[tmp++] = get_par(v);       } else {         cin >> x[k] >> doc[k];         doc[k++]--;       }     }     for (int i = 1; i <= n; ++i) {       if (p[i] != i) adj[p[i]].push_back(i);     }     for (int i = 1; i <= n; ++i) {       if (p[i] == i) {         cnt = 0;         dfs(i);       }     }     for (int i = 0; i < k; ++i) {       if (cmp(l[doc[i]], x[i]) && cmp(x[i], r[doc[i]]))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     string s1;     string s2;     cin >> s1 >> s2;     string ans =   ;     for (int i = s2.length() - 1; i >= 0; --i) {       ans += s2[i];     }     if (s1 == ans) {       cout <<  YES             <<   n ;     } else {       cout <<  NO             <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int Abs(int x) {     if (x < 0) return -x;     return x;   }   int N, M, K;   bool no[2001][2001] = {false}, visited[2001] = {false}, rooted[2001] = {false},        notgo[2001];   vector<int> G[2001], g[2001];   int cn = 0;   bool run = true;   void dfs(int r) {     if (!run) return;     cn++;     visited[r] = true;     rooted[r] = true;     for (int i = 0; i < g[r].size(); i++) {       notgo[g[r][i]] = true;     }     for (int i = 0; i < G[r].size(); i++) {       if (notgo[G[r][i]]) run = false;       if (!visited[G[r][i]]) dfs(G[r][i]);     }   }   int main() {     scanf( %d , &N);     scanf( %d , &M);     for (int i = 0; i < M; i++) {       int v, u;       scanf( %d%d , &v, &u);       G[v].push_back(u);       G[u].push_back(v);     }     scanf( %d , &K);     for (int i = 0; i < K; i++) {       int v, u;       scanf( %d%d , &v, &u);       g[v].push_back(u);       g[u].push_back(v);     }     int ans = 0;     for (int i = 1; i <= N; i++) {       cn = 0;       run = true;       memset(visited, false, sizeof(visited));       memset(notgo, false, sizeof(notgo));       dfs(i);       if (run) ans = max(ans, cn);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5, mod = 1e9 + 7;   int n, m, k;   long long fact[maxn], dp[maxn], inv[maxn];   long long qpow(long long n, int p) {     long long res = 1;     while (p) {       if (p & 1) res = res * n % mod;       n = n * n % mod;       p >>= 1;     }     return res;   }   long long COM(int n, int m) {     if (m > n) return 0;     return fact[n] * inv[m] % mod * inv[n - m] % mod;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     fact[0] = 1;     for (int i = 1; i < maxn; ++i) fact[i] = fact[i - 1] * i % mod;     inv[maxn - 1] = qpow(fact[maxn - 1], mod - 2);     for (int i = maxn - 2; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;     printf( %lld n , COM(n - 1, k << 1) * COM(m - 1, k << 1) % mod);   }
#include <bits/stdc++.h>   int Max(int n);   int main(void) {     long n, i, j;     long long m;     scanf( %ld , &n);     m = Max(n);     j = m;     for (i = 1; i <= 4; i++) {       m = m * j;       m %= 100000;     }     if (m == 0) {       printf( 00000 n );     } else if (m < 10) {       printf( 0000%lld n , m);     } else if (m < 100) {       printf( 000%lld n , m);     } else if (m < 1000) {       printf( 00%lld n , m);     } else if (m < 10000) {       printf( 0%lld n , m);     } else {       printf( %lld n , m);     }   }   int Max(int n) {     int i, j, k, l, m;     i = n / 10000;     j = (n / 1000) % 10;     k = (n / 100) % 10;     l = (n / 10) % 10;     m = n % 10;     return (i * 10000 + k * 1000 + m * 100 + l * 10 + j);   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1600;   int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};   int n, m, pr[M][M], pc[M][M];   char g[M][M], f[M][M];   bool dfs(int r, int c) {     int u = (r % n + n) % n, v = (c % m + m) % m;     if ( #  == g[u][v]) return 0;     if (f[u][v]) return r != pr[u][v] || c != pc[u][v];     f[u][v] = 1, pr[u][v] = r, pc[u][v] = c;     for (int d = 0; d < 4; ++d)       if (dfs(r + dr[d], c + dc[d])) return 1;     return 0;   }   int main(void) {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> g[i];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if ( S  == g[i][j])           cout << (dfs(i + n * 2, j + m * 2) ?  Yes  :  No ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool visited[2010];   vector<int> g[2010];   int dfs(int src) {     visited[src] = true;     int ans = 0;     for (auto x : g[src]) {       if (!visited[x]) {         ans = max(ans, dfs(x));       }     }     return ans + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == -1) x = 0;       g[i + 1].push_back(x);       g[x].push_back(i + 1);     }     cout << dfs(0) - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const long long mod = 1e9 + 7;   int prime[maxn], g[maxn], last[maxn], num[maxn], cnt[maxn];   long long fac[maxn], invf[maxn];   int t[500];   bool vis[maxn];   long long fpow(long long a, long long b, long long p = mod) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % p;       a = a * a % p;       b >>= 1;     }     return ans;   }   void init() {     int cnt = 0;     g[1] = 1;     last[1] = 1;     fac[1] = 1;     fac[0] = 1;     for (int i = 2; i < maxn; i++) {       fac[i] = fac[i - 1] * i % mod;       if (!vis[i]) prime[++cnt] = i, g[i] = i - 1, last[i] = 1;       for (int j = 1; j <= cnt && i * prime[j] < maxn; j++) {         int x = i * prime[j];         vis[x] = true;         if (i % prime[j] == 0) {           last[x] = last[i];           if (last[x] == 1)             g[x] = x - i;           else             g[x] = g[x / last[x]] * g[last[x]];           break;         }         last[x] = i;         g[x] = g[i] * g[prime[j]];       }     }     invf[maxn - 1] = fpow(fac[maxn - 1], mod - 2);     for (int i = maxn - 2; i >= 0; i--) invf[i] = invf[i + 1] * (i + 1) % mod;   }   long long C(int n, int m) {     return n < m ? 0 : fac[n] * invf[m] % mod * invf[n - m] % mod;   }   int getfac(int x) {     int len = 0;     for (int i = 1; i * i <= x; i++) {       if (x % i) continue;       t[++len] = i;       if (i * i != x) t[++len] = x / i;     }     sort(t + 1, t + 1 + len);     return len;   }   int main() {     std::ios::sync_with_stdio(false);     cout.tie(0);     init();     int n, k, q;     cin >> n >> k >> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       num[x]++;     }     for (int i = maxn - 1; i >= 1; i--) {       for (int j = i; j < maxn; j += i) cnt[i] += num[j];     }     long long ans = 0;     for (int i = 1; i < maxn; i++) {       ans = (ans + C(cnt[i], k) * g[i] % mod) % mod;     }     while (q--) {       int x;       cin >> x;       int len = getfac(x);       for (int i = len; i > 0; i--) {         long long dert = C(cnt[t[i]] + 1, k) - C(cnt[t[i]], k);         dert *= g[t[i]];         ans = (ans + dert + mod) % mod;         cnt[t[i]]++;       }       ans = (ans % mod + mod) % mod;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[1 << 18];   char str[20];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int x, y;     cin >> x >> y;     int a, b, c, ans = 0;     a = b = c = y;     while (a < x) {       swap(a, b);       swap(b, c);       c = a + b - 1;       ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[100005], b[100005];   int k, n, m, maxim;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int nr;       cin >> nr;       b[nr]++;       v[b[nr]]++;       if (v[b[nr]] == n)         cout << 1;       else         cout << 0;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& o, pair<T1, T2> x) {     return o << x.first <<     << x.second;   }   template <class T1, class T2>   istream& operator>>(istream& o, pair<T1, T2>& x) {     return o >> x.first >> x.second;   }   template <class T1, class T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <class T1, class T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T1, class T2>   void operator+=(pair<T1, T2>& a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;   }   template <class T1, class T2>   void operator-=(pair<T1, T2>& a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;   }   template <long long int D, typename T>   struct Vec : public vector<Vec<D - 1, T>> {     static_assert(D >= 1,  Vector dimension must be greater than zero! );     template <typename... Args>     Vec(long long int n = 0, Args... args)         : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}   };   template <typename T>   struct Vec<1, T> : public vector<T> {     Vec(long long int n = 0, const T& val = T()) : vector<T>(n, val) {}   };   const long long int md = 998244353;   inline long long int add(long long int x, long long int y) {     x += y;     if (x >= md) x -= md;     return x;   }   inline long long int sub(long long int x, long long int y) {     x -= y;     if (x < 0) x += md;     return x;   }   inline long long int mul(long long int x, long long int y) {     return (x * y) % md;   }   inline long long int power(long long int x, long long int y) {     long long int res = 1;     for (; y; y >>= 1, x = mul(x, x)) {       if (y & 1) res = mul(res, x);     }     return res;   }   inline long long int inv(long long int a) { return power(a, md - 2); }   void solve() {     long long int a, b, x, y, ans;     cin >> a >> b >> x >> y;     ans = max(b * max(x, a - x - 1), a * (max(y, b - y - 1)));     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T;     cin >> T;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int search(int a[], int x, int n) {     int lo = 0;     int hi = n;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (a[mid] >= x && a[mid - 1] < x)         return mid;       else if (a[mid] > x)         hi = mid - 1;       else         lo = mid + 1;     }     return 0;   }   int main() {     int n, m;     int a[100000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     cin >> m;     int b[100000];     int ans[100000];     for (int i = 0; i < m; i++) {       cin >> b[i];     }     for (int i = 1; i < n; i++) {       a[i] += a[i - 1];     }     for (int i = 0; i < m; i++) {       ans[i] = search(a, b[i], n);     }     for (int i = 0; i < m; i++) {       cout << ans[i] + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int res[50010], cot;   int main() {     string a, b;     int n;     cin >> n;     cin >> a;     cin >> b;     int s1, s2, s3;     s1 = s2 = s3 = 0;     int sa = 0, sb = 0;     for (int i = 0; i < n; i++) {       if (a[i] ==  1 ) sa++;       if (b[i] ==  1 ) sb++;       if (a[i] ==  1  && b[i] ==  1 )         s3++;       else if (a[i] ==  1 )         s1++;       else if (b[i] ==  1 )         s2++;     }     int ans[5];     int flag = -1, s4 = n - s1 - s2 - s3;     for (int i = 0; flag == -1 && i <= min(s3, n / 2); i++) {       int res1 = i, res2 = (s3 - i);       if (res1 + s1 < res2) continue;       if (res2 + s2 < res1) continue;       memset(ans, 0, sizeof ans);       ans[3] += res1;       int ss1 = s1, ss2 = s2;       if (res1 < res2) {         ss1 -= (res2 - res1);         ans[1] += res2 - res1;         res1 = res2;         int temp = min(ss1, ss2);         ans[1] += temp;         ss1 -= temp;         ss2 -= temp;         if (s4 >= max(ss1, ss2)) {           if (ss1) {             ans[4] += (s4 + ss1) / 2;           } else {             ans[2] += ss2;             ans[4] += (s4 - (s4 + ss2) / 2);           }           flag = 1;         }       } else {         ss2 -= (res1 - res2);         res2 = res1;         int temp = min(ss1, ss2);         ans[1] += temp;         ss1 -= temp;         ss2 -= temp;         if (s4 >= max(ss1, ss2)) {           if (ss1) {             ans[4] += (s4 + ss1) / 2;           } else {             ans[2] += ss2;             ans[4] += (s4 - (s4 + ss2) / 2);           }           flag = 1;         }       }     }     if (flag == -1)       puts( -1 );     else {       for (int i = 0; i < n; i++) {         if (a[i] ==  1  && b[i] ==  1  && ans[3]) {           res[++cot] = i + 1;           ans[3]--;           continue;         }         if (a[i] ==  1  && b[i] ==  0  && ans[1]) {           res[++cot] = i + 1;           ans[1]--;           continue;         }         if (a[i] ==  0  && b[i] ==  1  && ans[2]) {           res[++cot] = i + 1;           ans[2]--;           continue;         }         if (a[i] ==  0  && b[i] ==  0  && ans[4]) {           res[++cot] = i + 1;           ans[4]--;           continue;         }       }       for (int i = 1; i <= cot; i++) cout << res[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using std::max;   const int MAXN = 500111;   int N;   struct Data {     int Cnt, Id;     long long Val;     int next;     Data() {}     Data(int _c, int _i, long long _v) {       Cnt = _c;       Id = _i;       Val = _v;     }   } T[MAXN << 2];   int Tcnt;   namespace Map {   struct Vert {     int FE;     long long Val;   } V[MAXN];   struct Edge {     int x, y;     long long l;     int next;   } E[MAXN];   int Ecnt;   void addE(int a, int b, long long c) {     ++Ecnt;     E[Ecnt].x = a;     E[Ecnt].y = b;     E[Ecnt].l = c;     E[Ecnt].next = V[a].FE;     V[a].FE = Ecnt;   }   void DFS(int at) {     for (int k = V[at].FE, to; k > 0; k = E[k].next) {       to = E[k].y;       V[to].Val = V[at].Val + E[k].l;       DFS(to);     }   }   }  // namespace Map   namespace Tree {   struct Vert {     int FE;     int Fa, Son;     int Dep, Len;     int Head;     long long Ans;   } V[MAXN];   struct Edge {     int x, y, next;   } E[MAXN << 1];   int Ecnt;   void addE(int a, int b) {     ++Ecnt;     E[Ecnt].x = a;     E[Ecnt].y = b;     E[Ecnt].next = V[a].FE;     V[a].FE = Ecnt;   }   void DFS1(int at) {     for (int k = V[at].FE, to; k > 0; k = E[k].next) {       to = E[k].y;       if (to == V[at].Fa) continue;       V[to].Dep = V[at].Dep + 1;       V[to].Fa = at;       DFS1(to);       V[at].Len = max(V[at].Len, V[to].Len + 1);       if (V[at].Son <= 0 || V[V[at].Son].Len < V[to].Len) V[at].Son = to;     }   }   void Merge(int p, Data &A, Data &d) {     d.Val += 1LL * V[p].Dep * A.Cnt;     A.Val += 1LL * V[p].Dep * d.Cnt;     Map::addE(A.Id, d.Id, d.Val - A.Val);     A.Cnt += d.Cnt;   }   void DFS2(int at) {     if (V[at].Son) DFS2(V[at].Son);     T[++Tcnt] = Data(1, at, 0);     V[at].Head = Tcnt;     T[Tcnt].next = V[V[at].Son].Head;     for (int k = V[at].FE, to; k > 0; k = E[k].next) {       to = E[k].y;       if (to == V[at].Fa || to == V[at].Son) continue;       DFS2(to);       for (int a = T[V[at].Head].next, p = V[to].Head; p > 0;            a = T[a].next, p = T[p].next) {         Merge(at, T[a], T[p]);       }     }   }   void DFS3(int at) {     for (int k = V[at].FE, to; k > 0; k = E[k].next) {       to = E[k].y;       if (to == V[at].Fa) continue;       V[to].Ans = V[at].Ans + Map::V[to].Val + V[at].Dep;       DFS3(to);     }   }   }  // namespace Tree   int main() {     scanf( %d , &N);     int Root;     for (int i = 1, f; i <= N; ++i) {       scanf( %d , &f);       if (f == 0)         Root = i;       else {         Tree::addE(i, f);         Tree::addE(f, i);       }     }     Tree::V[Root].Dep = 1;     Tree::DFS1(Root);     Tree::DFS2(Root);     for (int p = Tree::V[Root].Head; p > 0; p = T[p].next) {       Map::V[T[p].Id].Val = T[p].Val;       Map::DFS(T[p].Id);     }     Tree::DFS3(Root);     for (int i = 1; i <= N; ++i) printf( %I64d  , Tree::V[i].Ans);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read();   int n;   char t[102];   int w[102][102], rnk[102][102], pos[102];   vector<int> p[102];   queue<int> q;   void init(int t) {     for (int i = 1; i <= n; ++i) {       p[i].clear(), p[i + n].clear();       for (int j = 1; j <= n; ++j) p[i].push_back(j + n), p[i + n].push_back(j);       sort(p[i].begin(), p[i].end(),            [&](int a, int b) { return w[i][a - n] > w[i][b - n] ^ t; });       sort(p[i + n].begin(), p[i + n].end(),            [&](int a, int b) { return w[a][i] < w[b][i] ^ t; });       q.push(i), pos[i] = 0, pos[i + n] = n;       for (int j = 0; j < n; ++j)         rnk[j][p[i][j]] = j, rnk[i + n][p[i + n][j]] = j;     }     while (!q.empty()) {       int u = q.front(), v;       while (pos[v = p[u][pos[u]]] < rnk[v][u]) ++pos[u];       if (pos[v] < n) q.push(p[v][pos[v]]);       pos[v] = rnk[v][u], q.pop();     }   }   int main() {     for (int T = read(); T; --T) {       n = read();       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) w[i][j] = read();       puts( B ), fflush(stdout), scanf( %s , t);       if (t[0] ==  I )         for (int i = 1; i <= n; ++i)           for (int j = 1; j <= n; ++j) w[i][j] = -w[i][j];       int u;       for (init((u = read()) > n); ~u; u = read())         printf( %d n , p[u][pos[u]]), fflush(stdout);     }     return 0;   }   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) f = (c ==  - ) ? -1 : f, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }
#include <bits/stdc++.h>   using namespace std;   long long prime[1000005];   long long fac[1000005];   int mul(int a, int b) {     int res = 0;     while (b) {       if (b & 1) res = (res + a);       a = (a + a);       b = b / 2;     }     return res;   }   int bexp(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = mul(res, a);       a = mul(a, a);       b = b / 2;     }     return res;   }   int inv(int a) { return bexp(a, 1000000007 - 2); }   int nCr(int n, int r) { return mul(fac[n], mul(inv(fac[n - r]), inv(fac[r]))); }   long long power(long long a, long long b, long long c) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b /= 2;     }     return res % c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     long long a[n];     vector<pair<long long, long long>> v;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long p = n - k;     if (p == 0) {       cout << n << endl;       return 0;     }     for (int i = 2; i <= n; i++)       v.push_back(make_pair(a[i] - a[i - 1] + 1, i - 1));     sort(v.begin(), v.end());     long long count = 0;     long long sum = 0;     vector<pair<long long, long long>> final;     for (int i = 0; i < v.size(); i++) {       sum += v[i].first;       final.push_back(make_pair(v[i].second, v[i].first));       count++;       if (count == p) break;     }     long long check = 2;     sort(final.begin(), final.end());     for (int i = 1; i < final.size(); i++) {       if (final[i].first - final[i - 1].first == 1) {         sum -= 1;         check += 1;       } else         check += 2;     }     cout << sum + n - check << endl;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 100;   int const M = 900;   typedef double (*F)[N];   int a[N];   double _f[N][N], _g[N][N];   F f = _f, g = _g;   inline int c2(int n) { return n * (n + 1) >> 1; }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     int n2 = c2(n);     for (k = min(k, M); k--;) {       for (int i = 0; i < n; ++i)         for (int j = i + 1; j < n; ++j) {           g[i][j] = (c2(i) + c2(n - 1 - j) + c2(j - i - 1)) * f[i][j];           for (int x = i; x < i + j; ++x) {             int a = max(0, x - j + 1), b = min(i, x - i);             g[i][j] += (b - a + 1) * f[x - i][j];           }           for (int x = i + j + 1; x < n + j; ++x) {             int a = max(i + 1, x - n + 1), b = min(j, x - j);             g[i][j] += (b - a + 1) * f[i][x - j];           }           for (int x = j; x < n + i; ++x) {             int a = max(0, x - n + 1), b = min(i, x - j);             g[i][j] += (b - a + 1) * (1 - f[x - j][x - i]);           }           g[i][j] /= n2;         }       swap(f, g);     }     double e = 0;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j) {         e += a[i] > a[j] ? 1 - f[i][j] : f[i][j];       }     printf( %.16f n , e);     return 0;   }