malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   map<int, int> mpp;   map<int, int> tmp;   multiset<int> adj[200005];   multiset<pair<int, int> > pairs;   int cnt[200005];   int arra[100005];   int arrb[100005];   list<int> ans;   void addpair(int u, int v) {     pairs.insert(make_pair(u, v));     pairs.insert(make_pair(v, u));   }   void removepair(int u, int v) {     pairs.erase(pairs.find(make_pair(u, v)));     pairs.erase(pairs.find(make_pair(v, u)));   }   int ispair(int u, int v) {     if (pairs.find(make_pair(u, v)) == pairs.end()) return 0;     return 1;   }   void bit() {     printf( -1 n );     exit(0);   }   int main() {     clock_t start = clock();     scanf( %d , &n);     for (int i = 0; i < 2 * n; i++) cnt[i] = 0;     for (int i = 0; i < n - 1; i++) {       scanf( %d , arra + i);     }     for (int i = 0; i < n - 1; i++) {       scanf( %d , arrb + i);     }     for (int i = 0; i < n - 1; i++) {       int a = arra[i], b = arrb[i];       int ai = i * 2, bi = i * 2 + 1;       if (a > b) bit();       if (tmp.count(a))         ai = tmp[a];       else {         tmp[a] = ai;         mpp[ai] = a;       }       if (tmp.count(b))         bi = tmp[b];       else {         tmp[b] = bi;         mpp[bi] = b;       }       cnt[ai]++;       cnt[bi]++;       addpair(ai, bi);       adj[ai].insert(bi);       adj[bi].insert(ai);     }     int tek1 = -1;     int tek2 = -1;     for (int i = 0; i < 2 * n; i++) {       if (cnt[i] % 2 == 1) {         if (tek2 != -1)           bit();         else if (tek1 != -1)           tek2 = i;         else           tek1 = i;       }     }     if (tek1 != -1 && tek2 == -1) assert(0);     list<int> ans;     if (tek1 == -1) {       tek1 = 0;     }     stack<int> st;     st.push(tek1);     while (!st.empty()) {       int node = st.top();       if (adj[node].size() == 0) {         ans.push_back(mpp[node]);         st.pop();       } else {         st.push(*adj[node].begin());         adj[*adj[node].begin()].erase(adj[*adj[node].begin()].find(node));         adj[node].erase(adj[node].begin());       }     }     for (int i = 0; i < 2 * n; i++) {       if (adj[i].size() != 0) bit();     }     for (list<int>::iterator it = ans.begin(); it != ans.end(); ++it) {       printf( %d  , *it);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, ans = 1, p, m;   string s;   set<int> buy, sell, extra;   int main() {     cin >> n;     while (n--) {       cin >> s >> p;       if (s ==  ACCEPT ) {         if (extra.find(p) != extra.end()) {           for (auto it : extra) {             if (it < p)               buy.insert(it);             else if (it > p)               sell.insert(it);           }           ans = (ans + ans) % 1000000007;           extra.clear();         } else if (buy.find(p) != buy.end()) {           auto it = buy.end();           it--;           if (*it != p) ans = 0;           it = buy.find(p);           buy.erase(it);           for (auto it : extra) {             sell.insert(it);           }           extra.clear();         } else {           auto it = sell.find(p);           assert(it != sell.end());           if (it != sell.begin()) ans = 0;           sell.erase(it);           for (auto it : extra) {             buy.insert(it);           }           extra.clear();         }       } else {         if (buy.empty()) {           if (sell.empty()) {             extra.insert(p);           } else {             auto it = sell.begin();             if (p > *it)               sell.insert(p);             else               extra.insert(p);           }         } else {           auto it = buy.end();           it--;           if (sell.empty()) {             if (p < *it)               buy.insert(p);             else               extra.insert(p);           } else {             auto jt = sell.begin();             if (p > *it && p < *jt)               extra.insert(p);             else if (p < *it)               buy.insert(p);             else               sell.insert(p);           }         }       }     }     long long int res = ((ans * 1LL) * (extra.size() + 1)) % 1000000007;     return cout << res <<   n , false;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   template <class T, class U>   inline void Max(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   inline void Min(T &a, U b) {     if (a > b) a = b;   }   inline void add(int &a, int b) {     a += b;     while (a >= 1000000007) a -= 1000000007;   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = ans * (long long)a % 1000000007;       a = (long long)a * a % 1000000007;       b >>= 1;     }     return ans;   }   pair<int, pair<int, int> > b[200010];   int v[200010], f[200010], ans[200010];   int query(int first) {     int ans = 0;     while (first < 200010) ans += f[first], first += first & -first;     return ans;   }   void upd(int first) {     while (first > 0) f[first]++, first -= first & -first;   }   int main() {     int i, j, k, n, m = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &j, &k);       v[m++] = j;       b[i].first = k;       b[i].second = make_pair(j, i);     }     sort(v, v + m);     m = unique(v, v + m) - v;     sort(b, b + n);     for (i = 0; i < n; i++) {       k = lower_bound(v, v + m, b[i].second.first) - v + 1;       ans[b[i].second.second] = query(k);       upd(k);     }     for (i = 0; i < n; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[105];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %1d , &num[i]);     }     int sum = 0;     int flag = 0;     for (int i = 1; i <= n; i++) {       sum += num[i];       int t = 0;       flag = 0;       for (int j = i + 1; j <= n; j++) {         if (num[j] == 0 && t == 0 && flag == 1) {           if (j == n) {             puts( YES );             return 0;           }           continue;         }         t += num[j];         if (t > sum) {           break;         } else if (t == sum) {           t = 0;           flag = 1;           if (j == n) {             puts( YES );             return 0;           }         }       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, l, r;   };   bool f(point a, point b) { return a.r > b.r; }   point a[5000];   int par[5000];   void init(int n) {     for (int i = 1; i <= n; i++) par[i] = i;   }   int root(int n) {     if (par[n] == n) return n;     return par[n] = root(par[n]);   }   int main() {     int n, m, maxx = 0;     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i].x >> a[i].y >> a[i].l >> a[i].r;     sort(a + 1, a + m + 1, f);     for (int i = 1; i <= m; i++) {       init(n);       for (int j = 1; j <= m; j++) {         if (a[j].l > a[i].l) continue;         int q1 = root(a[j].x), q2 = root(a[j].y);         if (q1 != q2) par[q1] = q2;         if (root(1) == root(n)) maxx = max(maxx, a[j].r - a[i].l + 1);       }     }     if (!maxx)       cout <<  Nice work, Dima!  << endl;     else       cout << maxx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int na, ma, nb, mb;     cin >> na >> ma;     char ch1[na + 5][ma + 5];     for (int i = 1; i <= na; i++) {       for (int j = 1; j <= ma; j++) {         cin >> ch1[i][j];       }     }     cin >> nb >> mb;     char ch2[nb + 5][mb + 5];     for (int i = 1; i <= nb; i++) {       for (int j = 1; j <= mb; j++) {         cin >> ch2[i][j];       }     }     int x = -1, y = -1, mx = -1;     for (int xx = -50; xx <= 50; xx++) {       for (int yy = -50; yy <= 50; yy++) {         int sum = 0;         for (int i = 1; i <= na; i++) {           for (int j = 1; j <= ma; j++) {             if (((i + xx) >= 1 && (i + xx) <= nb) &&                 ((j + yy) >= 1 && (j + yy) <= mb)) {               sum += (ch1[i][j] -  0 ) * (ch2[i + xx][j + yy] -  0 );             }           }         }         if (sum > mx) {           mx = sum;           x = xx;           y = yy;         }       }     }     cout << x <<     << y <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, sum, s;     cin >> a >> b >> s;     sum = abs(a) + abs(b);     if (sum <= s && (s - sum) % 2 == 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = (1 << 9) + 3;   int k;   int a[MAXN][MAXN];   void dien(int x) {     if (x == 1) return;     dien(x / 2);     for (int i = 1; i <= x / 2; i++) {       for (int j = 1; j <= x / 2; j++) {         a[i + x / 2][j] = a[i][j + x / 2] = a[i][j];         a[i + x / 2][j + x / 2] = 1 - a[i][j];       }     }   }   int main() {     cin >> k;     dien(1 << k);     for (int i = 1; i <= 1 << k; i++) {       for (int j = 1; j <= 1 << k; j++) {         if (a[i][j] == 0)           cout <<  * ;         else           cout <<  + ;       }       cout << endl;     }     return 0;   }
//To debug :  g++ -g file.cpp -o code   //to flush output : fflush(stdout) or cout.flush()   //cout<<setprecision(p)<<fixed<<var   //use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll   //take care of precedence rule of operators    //do not forget to change the sizes of arrays and value of contants and other things after debugging         #include<bits/stdc++.h>   using namespace std;   #define ll long long   #define rep(i,a,n) for(i=a;i<n;++i)   #define irep(i,n,a) for(i=n;i>a;--i)   #define mod 1000000007   #define pb push_back   #define big 9223372036854775807   #define big1 LONG_MAX   #define big2 ll_MAX   #define big3 1000000000   #define sma1 LONG_MIN   #define sma2 ll_MIN   #define sma3 -1000000000   #define mp make_pair   #define dub double   #define ivec vector<ll>   #define lvec vector<long long>   #define cvec vector<char>   #define svec vector<string>   #define mt make_tuple   #define MOD 998244353   #define ld long double   #define pi acos(-1.0)       #define SZ(x)  (ll)(x.size())       //comment the below if not required       /*       #define ss second.second   #define ff first.first   #define f first   #define s second   #define sf second.first   #define fs first.second   */       #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)       //cout<< Case # <<c<< :  <<ans<<  n  ;      const ll N = 150001;      ll a[5][N],n[5],x,y,temp,val,i,j,ans=LLONG_MAX;      set<pair<ll,ll>> m;      vector<ll> v[5][N];      int main()   {    IOS;       rep(i,1,5)     cin>>n[i];       rep(i,1,5)     rep(j,1,n[i]+1)      cin>>a[i][j];       rep(i,1,4)    {     cin>>val;        rep(j,1,val+1)     {      cin>>x>>y;      v[i+1][y].pb(x);     }       }       rep(i,2,5)    {     m.clear();        rep(j,1,n[i-1]+1)     {      if(a[i-1][j]!=-1)       m.insert({a[i-1][j],j});     }        rep(j,1,n[i]+1)     {      for(auto u : v[i][j])      {       if(a[i-1][u]!=-1)       {        auto it = m.find({a[i-1][u],u});        m.erase(it);       }      }         if(SZ(m))      {       auto it = m.begin();       a[i][j]+=(*it).first;      }      else       a[i][j]=-1;         for(auto u : v[i][j])      {       if(a[i-1][u]!=-1)        m.insert({a[i-1][u],u});      }        }       }          rep(i,1,n[4]+1){        if(a[4][i]==-1)      continue;        ans = min(ans,a[4][i]);    }       if(ans==LLONG_MAX)     ans = -1;       cout<<ans<<  n ;          return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   struct greaterr {     template <class T>     bool operator()(T const &a, T const &b) const {       return a > b;     }   };   int main() {     int n;     scanf( %d , &n);     char ans[n];     int x, y;     long long int suma = 0, sumb = 0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &y, &x);       if (suma + y - sumb <= 500) {         suma += y;         printf( A );       } else {         sumb += x;         printf( G );       }     }     return 0;   }
#include <bits/stdc++.h>   long double pi = acos(-1);   long long z = 1000000007;   long long power(long long a, long long b) {     if (b == 0) return 1;     long long c = power(a, b / 2);     if (b % 2 == 0)       return c * c;     else       return c * c * a;   }   using namespace std;   const int N = 1e6 + 7;   void solve() {     long long n;     cin >> n;     long long k;     cin >> k;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       m[x]++;     }     if (m.size() <= k)       cout << 1 << endl;     else if (k == 1 && m.size() > 1)       cout << -1 << endl;     else {       long long ans = (m.size() - k) / (k - 1) + 1;       if ((m.size() - k) % (k - 1) != 0) ans++;       cout << ans << endl;     }   }   int main() {     long long t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int get(long long a) {     if (a < 4) return 0;     if (a < 16) return 1;     if (a < 82) return 2;     if (a < 6724) return 0;     if (a < 50626) return 3;     if (a < 2562991876) return 1;     return 2;   }   int main() {     int cur = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long t;       cin >> t;       cur ^= get(t);     }     if ((cur) != 0)       cout <<  Furlo ;     else       cout <<  Rublo ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, l;   int pre[200010], other[200010], last[100010];   int flag[100010];   void connect(int x, int y) {     pre[++l] = last[x];     last[x] = l;     other[l] = y;   }   int dfs(int x, int fa) {     flag[x] = 1;     int cur(0);     for (int p = last[x]; p; p = pre[p]) {       if (other[p] == fa) continue;       if (flag[other[p]] == 2) continue;       int edge;       if (!flag[other[p]])         edge = dfs(other[p], x);       else         edge = 0;       if (edge)         printf( %d %d %d n , x, other[p], edge);       else if (cur)         printf( %d %d %d n , cur, x, other[p]), cur = 0;       else         cur = other[p];     }     flag[x] = 2;     return cur;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       connect(x, y);       connect(y, x);     }     if (m & 1)       printf( No solution n n );     else       dfs(1, -1);     return 0;   }
#include <bits/stdc++.h>   const int MAX_N = (int)1e5 + 123;   const double eps = 1e-6;   const int inf = (int)1e9 + 123;   using namespace std;   int n;   vector<int> ans[MAX_N];   int k;   int main() {     cin >> n;     ans[1].push_back(1), ans[2].push_back(1);     for (int i = 3, now = 2;; i++) {       if (n - now + 1 >= i - 1) {         k = i;         for (int j = 1; j < i; j++) {           ans[j].push_back(now);           ans[i].push_back(now);           now++;         }       } else         break;     }     cout << k << endl;     for (int i = 1; i <= k; i++) {       for (auto j : ans[i]) cout << j <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1001][1001], ans[1001];   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int x = (n + 1) / 2 + 1 * ((n + 1) & 1);     vector<pair<int, int> > v;     for (int j = 1; j <= x; j++) {       if (v.size() == n) break;       v.push_back(make_pair(1, j));     }     for (int i = 2; i <= x; i++) {       if (v.size() == n) break;       v.push_back(make_pair(i, x));     }     cout << x <<   n ;     for (pair<int, int> x : v) {       cout << x.first <<     << x.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > adj[100005];   long long int sp = 0, mst = 0, p = 100003;   int n, m;   int main() {     cin >> n >> m;     long long int c = p - (n - 2);     adj[1].push_back({2, c});     m--;     for (int i = 2; i <= n - 2 + 1; i++, m--) adj[i].push_back({i + 1, 1});     if (m != 0) {       for (int i = 1; i < n && m != 0; i++) {         for (int j = i + 2; j <= n; j++) {           adj[i].push_back({j, 1e7});           m--;           if (m == 0) break;         }       }     }     cout << p <<     << p << endl;     for (int i = 1; i < n; i++) {       for (int j = 0; j < adj[i].size(); j++)         cout << i <<     << adj[i][j].first <<     << adj[i][j].second << endl;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;      int main()   {      int t,n; cin >> t;            while(t--)      {          cin >> n; int ans=0,k=n,p=n,h=0;                              while(ceil(sqrt(k))>=2 && k>2)          {              ans++; k=ceil(sqrt(k));          }                    cout << ans+n-2 << endl; k=n; int i=k-1;          while(k>2)          {                 int p=ceil(sqrt(k));              while(i>p)              {                 cout << i <<    << k << endl; i--;               }                      cout<< k <<     << i << endl; cout << k <<     << i << endl;               k=ceil(sqrt(k)); i=k-1;          }      }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     long long int i;     cin >> n;     std::vector<long long int> v;     long long int s = 0;     for (long long int i = 0; i < n; i++) {       long long int val;       cin >> val;       s += val;       if (i != (n - 1)) v.push_back(s);     }     if (s % 2 == 1) {       cout << 0 << endl;       return 0;     }     long long int c = 0;     for (i = 0; i < v.size(); i++) {       if (v[i] == s - v[i]) c++;     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 35, M = 100005;   int n, m, f, ans, e;   char a[N][M];   int len[N], z[M], b[N][M], p[N][M];   vector<int> v[M];   void dfs(int pos) {     if (f) return;     z[pos] = 2;     for (auto &i : v[pos])       if (!z[i])         dfs(i);       else if (z[i] == 2) {         f = 1;         return;       }     z[pos] = 1;   }   bool check(int s, int t) {     f = e = 0;     z[0] = 0;     v[0].clear();     for (int i = b[s][1]; i <= b[t][len[t]]; i++) v[i].clear(), z[i] = 0;     for (int i = s; i <= t; i++) {       v[0].push_back(b[i][1]);       for (int j = s; j <= t; j++) {         int l = 0;         for (int k = 1; k <= len[i]; k++) {           while (k + l <= len[i] && l + 1 <= len[j] && a[i][k + l] == a[j][l + 1])             ++l;           if (l) {             if (len[i] - k + 1 < len[j] && l == len[i] - k + 1)               v[b[i][k]].push_back(b[j][l + 1]);             if (len[j] < len[i] - k + 1 && l == len[j])               v[b[i][k]].push_back(b[i][k + l]);             if (k > 1 && len[i] - k + 1 == len[j] && l == len[j])               v[b[i][k]].push_back(0);             l = p[j][l];           }         }       }     }     if (!z[0]) dfs(0);     if (f) return 0;     for (int i = b[s][1]; i <= b[t][len[t]]; i++)       if (!z[i]) {         dfs(i);         if (f) return 0;       }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> (a[i] + 1);       len[i] = strlen(a[i] + 1);       for (int j = 1; j <= len[i]; j++) b[i][j] = ++m;     }     for (int i = 1; i <= n; i++) {       int k = 0;       for (int j = 2; j <= len[i]; j++) {         while (k && a[i][k + 1] != a[i][j]) k = p[i][k];         if (a[i][k + 1] == a[i][j]) ++k;         p[i][j] = k;       }     }     int j = 1;     for (int i = 1; i <= n; i++) {       if (i > j) j = i;       while (j <= n && check(i, j)) ++j;       ans += j - i;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out << p.first <<     << p.second;     return out;   }   template <class T1, class T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& x : v) in >> x;     return in;   }   template <class T>   ostream& operator<<(ostream& out, vector<vector<T>>& v) {     for (auto& x : v) out << x <<   n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (auto x : v) out << x <<    ;     return out;   }   void solve() {     int n;     cin >> n;     vector<int> a(n), b(n);     cin >> a;     iota(b.begin(), b.end(), 0);     sort(b.begin(), b.end(), [&](int i, int j) {       if (a[i] != a[j]) {         return a[i] < a[j];       }       return i < j;     });     vector<pair<int, int>> ans;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n - 1; j++) {         if (b[j] > b[j + 1]) {           ans.push_back({b[j + 1], b[j]});           swap(b[j], b[j + 1]);         }       }     }     cout << ans.size() <<   n ;     for (auto p : ans) {       cout << p.first + 1 <<     << p.second + 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);     ;     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   FILE *in = stdin, *out = stdout;   using namespace std;   int n, ans[100005], N;   int alpha[30];   char a[2005], b[2005], c[2005];   void input() {     fscanf(in,  %d , &n);     fscanf(in,  %s , &a[1]);     fscanf(in,  %s , &b[1]);   }   int most_fit(int start) {     for (int i = (start); i <= (n); i++)       if (a[i] == b[start]) return i;     return 0;   }   void method1(int l, int r) {     ans[++N] = r;     ans[++N] = l;     ans[++N] = r;     for (int i = (1); i <= (r); i++) c[i] = a[l + i];     int t = l;     for (int i = (r + 1); i <= (n); i++) c[i] = a[t--];     for (int i = (1); i <= (n); i++) a[i] = c[i];   }   void method2(int A, int B, int C) {     ans[++N] = C;     ans[++N] = A + B;     ans[++N] = C;     ans[++N] = A;     for (int i = (A + 1); i <= (A + C); i++) c[i] = a[i + B];     int t = A + B;     for (int i = (A + C + 1); i <= (n); i++) c[i] = a[t--];     for (int i = (A + 1); i <= (n); i++) a[i] = c[i];   }   void pro() {     for (int i = (1); i <= (n); i++) alpha[a[i] -  a ]++, alpha[b[i] -  a ]--;     for (int i = (0); i <= (25); i++)       if (alpha[i] != 0) {         fprintf(out,  -1 );         return;       }     for (int i = (1); i <= (n); i++) {       for (int j = (i); j <= (n); j++) {         if (a[j] == b[n - i + 1]) {           ans[++N] = n;           ans[++N] = j - 1;           ans[++N] = 1;           c[1] = a[j];           for (int k = (2); k <= (j); k++) c[k] = a[k - 1];           int t = n;           for (int k = (j + 1); k <= (n); k++) c[k] = a[t--];           for (int k = (1); k <= (n); k++) a[k] = c[k];           break;         }       }     }     fprintf(out,  %d n , N);     for (int i = (1); i <= (N); i++) {       fprintf(out,  %d  , ans[i]);     }   }   int main() {     input();     pro();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const long long INF = 1e18;   int n;   int p[N];   long long dif[N];   long long ans = INF;   int id;   void add(int l, int r, int val) {     dif[l] += val;     dif[r + 1] -= val;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long res = 0;     for (int i = 1; i <= n; i++) {       cin >> p[i];       res += (1LL) * abs(p[i] - i);       if (p[i] >= i) {         add(2, i, 1);         add(i + 1, i + 1, (n - p[i]) - (p[i] - 1));         add(i + 2, i + 2 + (n - p[i]) - 1, -1);         add(i + 2 + (n - p[i]), n, 1);       } else {         add(2, i - p[i] + 1, -1);         add(i - p[i] + 2, i, 1);         add(i + 1, i + 1, (n - p[i]) - (p[i] - 1));         add(i + 2, n, -1);       }     }     for (int i = 1; i <= n; i++) {       dif[i] += dif[i - 1];       res += dif[i];       if (res < ans) {         ans = res, id = n - i + 1;         if (id == n) id = 0;       }     }     cout << ans <<     << id <<   n ;     return 0;   }