malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long loo = 1ll << 62;   const int mods = 1e9 + 7;   const int MAXN = 1000005;   const int INF = 0x3f3f3f3f;   inline int read() {     int f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   int a[45], g[45], f[MAXN][45], id[MAXN];   int upd(int x, int y) { return x + y >= mods ? x + y - mods : x + y; }   signed main() {     int n = read(), m, flag = 0;     if (n == 2) {       puts( 1 );       return 0;     }     for (m = 0; 1 << m <= n; m++) a[m] = 1 << m;     m--;     if (a[m] * 3 / 2 <= n) {       flag = 1;       for (int i = 0; i < m; i++) a[m + i + 1] = a[i] * 3;       m = m + m;     }     sort(a, a + m + 1, [&](int x, int y) { return x > y; });     for (int i = 0; i <= m; i++) id[a[i]] = i;     for (int i = 0; i <= m; i++) g[i] = n / a[i];     f[1][0] = 1;     if (flag) f[1][1] = 1;     for (int i = 1; i < n; i++)       for (int j = 0; j < m; j++) {         f[i + 1][j] = upd(f[i + 1][j], 1ll * f[i][j] * max(g[j] - i, 0) % mods);         if (a[j] % 2 == 0)           f[i + 1][id[a[j] / 2]] =               upd(f[i + 1][id[a[j] / 2]],                   1ll * f[i][j] * max(g[id[a[j] / 2]] - g[j], 0) % mods);         if (a[j] % 3 == 0)           f[i + 1][id[a[j] / 3]] =               upd(f[i + 1][id[a[j] / 3]],                   1ll * f[i][j] * max(g[id[a[j] / 3]] - g[j], 0) % mods);       }     int ans = 0;     for (int i = n, fac = 1; i >= 1; i--)       ans = upd(ans, 1ll * fac * f[i][m] % mods),       fac = 1ll * fac * (n - i + 1) % mods;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c;       scanf( %lld%lld%lld , &a, &b, &c);       long long ans = 0x7f7f7f7f7f7f7f7f;       long long ca, cb, cc;       for (long long i = 1ll; i <= 15000ll; i++) {         long long a1, c1;         long long minx1 = 0x7f7f7f7f7f7f7f7f;         for (long long j = 1; j <= sqrt(i); j++) {           if (i % j == 0) {             if (minx1 > abs(i / j - a)) {               minx1 = abs(i / j - a);               a1 = i / j;             }             if (minx1 > abs(j - a)) {               minx1 = abs(j - a);               a1 = j;             }           }         }         if (abs(max(c / i, 1ll) * i - c) > abs((c / i + 1) * i - c)) {           c1 = (c / i + 1) * i;         } else {           c1 = max(c / i, 1ll) * i;         }         if (abs(a1 - a) + abs(i - b) + abs(c1 - c) < ans) {           ans = abs(a1 - a) + abs(i - b) + abs(c1 - c);           ca = a1, cb = i, cc = c1;         }       }       printf( %lld n , ans);       printf( %lld %lld %lld n , ca, cb, cc);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, adj[25], pode[1 << 23];   int main() {     scanf( %d%d , &n, &m);     if (m == n * (n - 1) / 2) {       puts( 0 );       return 0;     }     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       adj[i] |= 1 << i, pode[1 << i] = 1;     for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));          i += 1 - 2 * ((0) > (m))) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       adj[u] |= 1 << v;       adj[v] |= 1 << u;     }     int ans = (1 << n) - 1;     for (__typeof((1 << n)) i = (1) - ((1) > ((1 << n)));          i != ((1 << n)) - ((1) > ((1 << n))); i += 1 - 2 * ((1) > ((1 << n))))       if (__builtin_popcount(i) < __builtin_popcount(ans) && pode[i]) {         int cur = 0;         for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > (n));              j += 1 - 2 * ((0) > (n)))           if (i & (1 << j)) cur |= adj[j];         if (__builtin_popcount(cur) == n) ans = i;         for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > (n));              j += 1 - 2 * ((0) > (n)))           if ((cur & (1 << j)) && !(i & (1 << j))) pode[i | (1 << j)] = 1;       }     printf( %d n , __builtin_popcount(ans));     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       if (ans & (1 << i)) printf( %d  , i + 1);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int col[501];   int tcol[501];   int edge[501][501];   void docol(int v, int c) {     col[v] = c;     for (int i = 1; i <= v; ++i) {       if (edge[v][i] && col[i] == -1) {         docol(i, c);       }     }   }   int main(void) {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int k;     cin >> k;     memset(tcol, -1, sizeof(tcol));     memset(col, -1, sizeof(col));     memset(edge, 0, sizeof(edge));     for (int i = 1; i <= k; ++i) {       int a, b;       cin >> a >> b;       edge[a][b] = 1;       edge[b][a] = 1;     }     int b = 0;     for (int i = 1; i <= n; ++i) {       bool flag = true;       for (int j = 1; j <= n; ++j) {         if (i == j) continue;         if (edge[i][j] == 0) {           flag = false;           break;         }       }       if (flag) {         tcol[i] = 1;         b++;       }     }     if (b == n) {       cout <<  Yes n ;       for (int i = 1; i <= n; ++i) cout <<  b ;       return 0;     }     for (int i = 1; i <= n; ++i) {       if (tcol[i] != -1) continue;       memset(col, -1, sizeof(col));       for (int j = 1; j <= n; ++j) col[j] = tcol[j];       docol(i, 0);       for (int j = 1; j <= n; ++j) {         if (col[j] == -1) col[j] = 2;       }       bool flag = false;       for (int ii = 1; ii <= n && !flag; ++ii) {         for (int j = 1; j <= n && !flag; ++j) {           if (ii == j) continue;           if (edge[ii][j] == 0) {             if ((col[ii] == 0 && col[j] == 2) || (col[ii] == 2 && col[j] == 0))               continue;             else {               flag = true;               break;             }           }           if (col[ii] == 1 || col[j] == 1) continue;           if (col[ii] == 0 && (col[j] == 0 || col[j] == 1)) continue;           if (col[ii] == 2 && (col[j] == 2 || col[j] == 1)) continue;           flag = true;           break;         }       }       if (flag) continue;       cout <<  Yes n ;       for (int ii = 1; ii <= n; ++ii)         cout << (col[ii] == 0 ?  a  : col[ii] == 1 ?  b  :  c );       return 0;     }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int max_points = -(50 * 50 + 1);     string leader;     for (int i = 0; i < n; i++) {       string handle;       int plus, minus, a, b, c, d, e;       cin >> handle >> plus >> minus >> a >> b >> c >> d >> e;       if (plus * 100 - minus * 50 + a + b + c + d + e > max_points)         max_points = plus * 100 - minus * 50 + a + b + c + d + e, leader = handle;     }     cout << leader <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod(long long a, long long b) {     long long ans;     if (b == 0)       return -1;     else {       ans = (a < 0 ? mod(((a % b) + b), b) : a % b);     }     return ans;   }   vector<int> cntl(100003, 0), cntr(100003, 0), cntt(100003, 0), cntb(100003, 0);   int n, m, d;   void solve() {     int cl, cb, cr, ct;     cin >> d >> n >> m;     vector<int> x1(d + 1), x2(d + 1), y1(d + 1), y2(d + 1);     for (int i = 1; i < d + 1; i++) {       cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];       cntl[min(x1[i], x2[i])]++;       cntr[max(x1[i], x2[i])]++;       cntt[min(y1[i], y2[i])]++;       cntb[max(y1[i], y2[i])]++;     }     for (int i = 1; i < 100003; i++) {       cntl[i] += cntl[i - 1];       cntt[i] += cntt[i - 1];     }     for (int i = 100001; i >= 1; i--) {       cntb[i] += cntb[i + 1];       cntr[i] += cntr[i + 1];     }     cin >> cl >> cr >> ct >> cb;     vector<pair<pair<int, int>, pair<int, int> > > cnt(d);     for (int i = 1; i < d + 1; i++) {       cnt[i - 1].first.first = cntl[max(x1[i], x2[i]) - 1] - (x1[i] != x2[i]);       cnt[i - 1].first.second = cntr[min(x1[i], x2[i]) + 1] - (x1[i] != x2[i]);       cnt[i - 1].second.first = cntt[max(y1[i], y2[i]) - 1] - (y1[i] != y2[i]);       cnt[i - 1].second.second = cntb[min(y1[i], y2[i]) + 1] - (y1[i] != y2[i]);     }     pair<pair<int, int>, pair<int, int> > target = {{cl, cr}, {ct, cb}};     if (find((cnt).begin(), (cnt).end(), target) != cnt.end()) {       cout << distance(cnt.begin(), find((cnt).begin(), (cnt).end(), target)) + 1            << endl;     } else       cout << -1 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10][10];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &a[i][j]);       }     }     for (int k = 0; k < n; ++k) {       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           a[i][j] = min(a[i][j], a[i][k] + a[k][j]);         }       }     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         ans = max(ans, a[i][j]);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( -ffloat-store )   using namespace std;   const long long mod = 998244353;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   vector<long long> v;   long long n, k;   void solve(long long l, long long r) {     if (k == 0 || l + 1 == r) {       return;     }     long long mid = l + (r - l) / 2;     k -= 2;     swap(v[mid], v[mid - 1]);     solve(l, mid);     solve(mid, r);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       cin >> n >> k;       if (k % 2 == 0) {         cout << -1;         return 0;       }       for (long long i = 1; i <= n; i++) v.push_back(i);       k--;       if (k > 0) {         solve(0, n);       }       if (k > 0) {         cout << -1;         return 0;       }       for (long long i = 0; i < n; i++) cout << v[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int MAXN = 1000100;   long long mpow(long long b, int e) {     if (e == 0) return 1;     long long v = mpow(b, e / 2);     v = (v * v) % MOD;     if (e & 1) v = (v * b) % MOD;     return v;   }   long long inv(long long b) { return mpow(b % MOD, MOD - 2); }   int N;   vector<int> v[MAXN];   int ct[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 0; i < N; i++) {       int K;       cin >> K;       for (int j = 0; j < K; j++) {         int x;         cin >> x;         v[i].push_back(x);         ct[x]++;       }     }     long long res = 0;     for (int i = 0; i < N; i++) {       for (int cv : v[i]) {         long long prob = (inv(v[i].size() * (long long)N)) % MOD;         prob = (prob * ct[cv]) % MOD;         prob = (prob * inv(N)) % MOD;         res = (res + prob) % MOD;       }     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int t;   vector<vector<int> > nod;   vector<int> sol;   void bfs(int n) {     sol = vector<int>(n + 10);     sol[1] = 1;     queue<int> Q;     Q.push(1);     while (!Q.empty()) {       int a = Q.front();       Q.pop();       for (int j = 0; j < nod[a].size(); j++)         if (!sol[nod[a][j]]) {           sol[nod[a][j]] = sol[a] + 1;           Q.push(nod[a][j]);         }     }   }   int main() {     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       nod = vector<vector<int> >(n + 5);       for (int i = 1; i <= m; i++) {         int nod1, nod2;         cin >> nod1 >> nod2;         nod[nod1].push_back(nod2);         nod[nod2].push_back(nod1);       }       bfs(n);       vector<int> nr1, nr2;       for (int i = 1; i <= n; i++) {         if (sol[i] & 1)           nr1.push_back(i);         else           nr2.push_back(i);       }       if (nr1.size() < nr2.size()) {         cout << nr1.size() <<   n ;         for (int i = 0; i < nr1.size(); i++) cout << nr1[i] <<    ;         cout <<   n ;       } else {         cout << nr2.size() <<   n ;         for (int i = 0; i < nr2.size(); i++) cout << nr2[i] <<    ;         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int seq[60];     int yea[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};     for (int i = 1; i <= 12; i++) {       seq[i - 1] = yea[i - 1];       seq[12 + i - 1] = yea[i - 1];       seq[24 + i - 1] = yea[i - 1];       seq[36 + i - 1] = yea[i - 1];       seq[48 + i - 1] = yea[i - 1];     }     seq[25] = 29;     int n;     cin >> n;     int que[n];     for (int i = 0; i < n; i++) {       cin >> que[i];     }     int k = 0;     for (int i = 0; i < 60; i++) {       if (seq[i] == que[0]) {         int j = 1;         for (j = 1; j < n; j++) {           if (seq[i + j] != que[j]) break;         }         if (j == n) {           k = 1;         }       }       if (k == 1) break;     }     if (k == 1)       cout <<  Yes ;     else       cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[3] = {6, 10, 15};   int main() {     ios::sync_with_stdio(false);     cin >> n;     if (n == 2) return cout << -1, 0;     if (n == 1) return cout << 2, 0;     cout << a[0] << endl << a[1] << endl << a[2] << endl;     for (int i = 3; i < n; i++) cout << i * a[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e7 + 5;   const int MAXM = 105;   int st[MAXN], top, tree_cnt;   int ls[MAXN], rs[MAXN], rt[MAXM], val[200005];   inline int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   inline int get() { return top ? st[top--] : ++tree_cnt; }   void modify(int l, int r, int p, int &cur) {     if (!cur) cur = ++tree_cnt;     if (l == r) return;     int mid = (l + r) >> 1;     if (p <= mid)       modify(l, mid, p, ls[cur]);     else       modify(mid + 1, r, p, rs[cur]);   }   void merge(int &x, int &y) {     if (!x || !y) return x |= y, y = 0, void();     merge(ls[x], ls[y]), merge(rs[x], rs[y]), st[++top] = y, y = 0;   }   void change(int l, int r, int ql, int qr, int &pre, int &cur) {     if (!pre) return;     if (ql <= l && qr >= r) return merge(cur, pre);     if (!cur) cur = get();     int mid = (l + r) >> 1;     if (ql <= mid) change(l, mid, ql, qr, ls[pre], ls[cur]);     if (qr > mid) change(mid + 1, r, ql, qr, rs[pre], rs[cur]);     if (!ls[pre] && !rs[pre]) st[++top] = pre, pre = 0;   }   void dfs(int l, int r, int cur, int c) {     if (!cur) return;     if (l == r) return val[l] = c, void();     int mid = (l + r) >> 1;     dfs(l, mid, ls[cur], c);     dfs(mid + 1, r, rs[cur], c);   }   int main() {     int n = read();     for (int i = 1; i <= n; i++) modify(1, n, i, rt[read()]);     int m = read();     for (int i = 1; i <= m; i++) {       int l = read(), r = read();       int x = read(), y = read();       if (x == y) continue;       change(1, n, l, r, rt[x], rt[y]);     }     for (int i = 1; i <= 100; i++) dfs(1, n, rt[i], i);     for (int i = 1; i <= n; i++) printf( %d%c , val[i],    n [i == n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200001, MOD = 1000000007;   int n, l, r;   long long one = 0, two = 0, zero = 0, dp[MAXN][3];   int main() {     cin >> n >> l >> r;     for (; l % 3 != 0 && l <= r; l++)       if (l % 3 == 1)         one++;       else if (l % 3 == 2)         two++;     for (; r % 3 != 0 && r >= l; r--)       if (r % 3 == 1)         one++;       else if (r % 3 == 2)         two++;     if (l <= r) {       one += r / 3 - l / 3;       two += r / 3 - l / 3;       zero += r / 3 - l / 3 + 1;     }     dp[1][0] = zero, dp[1][1] = one, dp[1][2] = two;     for (int i = 2; i <= n; i++) {       dp[i][0] = (dp[i - 1][0] * zero % MOD + dp[i - 1][1] * two % MOD +                   dp[i - 1][2] * one % MOD) %                  MOD;       dp[i][1] = (dp[i - 1][0] * one % MOD + dp[i - 1][1] * zero % MOD +                   dp[i - 1][2] * two % MOD) %                  MOD;       dp[i][2] = (dp[i - 1][0] * two % MOD + dp[i - 1][1] * one % MOD +                   dp[i - 1][2] * zero % MOD) %                  MOD;     }     cout << dp[n][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p[500002], d[200004], c, n, fix[200004];   vector<pair<long long, long long> > g;   vector<long long> v[200005];   void go(long long x, long long par, long long dep) {     p[x] = par;     d[x] = dep;     for (int i = 0; i < v[x].size(); i++)       if (v[x][i] != par) go(v[x][i], x, dep + 1);   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     go(1, 0, 0);     for (int i = 1; i <= n; i++) v[i].clear();     for (int i = 2; i <= n; i++) v[p[i]].push_back(i);     for (int i = 1; i <= n; i++) {       g.push_back(make_pair(d[i], i));     }     sort(g.begin(), g.end());     reverse(g.begin(), g.end());     for (int id = 0; id < g.size(); id++) {       long long x = g[id].second, par = p[x];       if (fix[x]) continue;       if (x == 1) {         cout <<  !   << x << endl;         return 0;       }       if (v[par].size() > 1) {         long long y = 0;         if (v[par][0] == x)           y = v[par][1];         else           y = v[par][0];         fix[x] = 1;         fix[y] = 1;         cout <<  ?   << x <<     << y << endl;         cin >> c;         if (c == x) {           cout <<  !   << x << endl;           return 0;         }         if (c == y) {           cout <<  !   << y << endl;           return 0;         }         for (int i = 0; i < v[par].size(); i++) {           if (v[par][i] == x || v[par][i] == y) {             swap(v[par][i], v[par][(int)v[par].size() - 1]);             v[par].pop_back();             i--;             continue;           }         }       } else {         if (par == 1) {           cout <<  ?   << x <<     << 1 << endl;           cin >> c;           cout <<  !   << c << endl;           return 0;         }         long long y = p[par];         cout <<  ?   << x <<     << y << endl;         cin >> c;         if (c == par) {           cout <<  !   << c << endl;           return 0;         }         if (c == x) {           cout <<  !   << c << endl;           return 0;         }         fix[x] = 1;         fix[par] = 1;         for (int i = 0; i < v[y].size(); i++)           if (v[y][i] == par) {             swap(v[y][i], v[y][(int)v[y].size() - 1]);             v[y].pop_back();             break;           }       }     }     return 0;   }
#include <bits/stdc++.h>   const int N = 300010;   int n, m, i, j, js, root, mx;   int a[N], x[N], y[N], num[N], f[N], next[N * 2], last[N * 2], tov[N * 2],       bh[N * 2], ans[N * 2];   bool dir[N * 2], bz[N];   int gf(int xx) {     if (f[xx] == xx) return xx;     int jl = gf(f[xx]);     f[xx] = jl;     return jl;   }   void ins(int xx, int yy) {     js++;     tov[js] = yy;     next[js] = last[xx];     last[xx] = js;     bh[js] = i;   }   void suan(int t) {     int k = last[t];     while (k) {       int p = tov[k];       if (!bz[p]) {         bz[p] = true;         suan(p);         if (dir[k])           ans[bh[k]] = a[p];         else           ans[bh[k]] = -a[p];         a[t] += a[p];         a[p] = 0;       }       k = next[k];     }   }   int main() {     scanf( %d , &n);     int l = 0;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       l += a[i];     }     if (l != 0) {       printf( Impossible );       return 0;     }     scanf( %d , &m);     for (i = 1; i <= n; i++) {       f[i] = i;     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &x[i], &y[i]);       int x1 = gf(x[i]), y1 = gf(y[i]);       if (x1 != y1) {         ins(x[i], y[i]);         dir[js] = true;         ins(y[i], x[i]);         dir[js] = false;         f[x1] = y1;         num[x[i]]++;         num[y[i]]++;       }     }     mx = 0;     for (i = 1; i <= n; i++) {       if (mx < num[i]) {         mx = num[i];         root = i;       }     }     int bj = 0;     memset(bz, false, sizeof(bz));     bz[root] = true;     suan(root);     printf( Possible n );     for (i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int ar[7];   int N, K;   map<vector<int>, double> M[5];   int bit[20];   void update(int x) {     while (x <= N) {       bit[x] += 1;       x += (x & -x);     }   }   int qry(int x) {     int rs = 0;     while (x) {       rs += bit[x];       x -= (x & -x);     }     return rs;   }   int way;   double tot;   double solve(vector<int> v, int pos) {     if (pos == K) {       way++;       memset(bit, 0, sizeof bit);       double rs = 0;       for (int i = 0; i < N; i++) {         rs += qry(N) - qry(v[i]);         update(v[i] + 1);       }       tot += rs;       return 0;     }     int i, j, x, y;     double res = 0;     for (i = 0; i < N; i++) {       for (j = i; j < N; j++) {         vector<int> tmp = v;         x = i;         y = j;         while (y > x) {           swap(tmp[x], tmp[y]);           x++, y--;         }         solve(tmp, pos + 1);       }     }     return res;   }   int main() {     int i, j, k;     cin >> N >> K;     vector<int> v;     for (int i = 0; i < N; i++) {       cin >> k;       k--;       v.push_back(k);     }     {       solve(v, 0);       double res = tot;       tot /= (double)way;       cout << setprecision(13) << fixed;       cout << tot + 1e-15 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     static int x;     static char ch;     static bool pd;     pd = true;     x = 0;     for (ch = getchar(); ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) pd = false;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return pd ? x : -x;   }   vector<pair<int, int> > ans;   int n, a[100010], L, R, st, ed, cnt;   int main() {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();     L = 1, R = n, st = 1, ed = a[n] + 1;     while (L <= R) {       for (int i = 1; i <= a[L] - a[L - 1]; ++i) {         for (int j = st + 1; j <= ed; ++j) ans.push_back(make_pair(st, j)), cnt++;         st++;       }       L++;       ed = a[--R] + 1;     }     cout << cnt << endl;     for (int i = 0; i < cnt; ++i)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }