ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define I inline
#define reg register
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define i128 __int128
#define uint unsigned int
constexpr int N=1100;
int n,c[N],p[N],vis[N][N];
stack<pii>st;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=n;i++)p[c[i]]=i;
  for(int i=n;i;i--)
    for(int j=p[i]+1;j<=i;j++)
      vis[c[j-1]][c[j]]=1,vis[c[j]][c[j-1]]=1,
      st.push(mp(c[j-1],c[j])),swap(c[j-1],c[j]);
  for(int i=n;i;i--){
    int j=0;
    for(j=i-1;j&&!vis[c[j]][c[j+1]];j--)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<i;j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
  }
  cout<<st.size()<<'\n';
  while(!st.empty()){
    pii u=st.top();
    cout<<u.se<<' '<<u.fi<<'\n';
    st.pop();
  }
  return 0;
}

Submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define I inline
#define reg register
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define i128 __int128
#define uint unsigned int
constexpr int N=1100;
int n,c[N],p[N],vis[N][N];
stack<pii>st;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=n;i++)p[c[i]]=i;
  for(int i=n;i;i--)
    for(int j=p[i]+1;j<=i;j++)
      vis[c[j-1]][c[j]]=1,vis[c[j]][c[j-1]]=1,
      st.push(mp(c[j-1],c[j])),swap(c[j-1],c[j]);
  for(int i=n;i;i--){
    int j=0;
    for(j=i-1;j&&!vis[c[j]][c[j+1]];j--)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<i;j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
  }
  cout<<st.size()<<'\n';
  while(!st.empty()){
    pii u=st.top();
    cout<<u.fi<<' '<<u.se<<'\n';
    st.pop();
  }
  return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define I inline
#define reg register
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define i128 __int128
#define uint unsigned int
constexpr int N=1100;
int n,c[N],p[N],vis[N][N];
stack<pii>st;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=n;i++)p[c[i]]=i;
  for(int i=n;i;i--)
    for(int j=p[i]+1;j<=i;j++)
      vis[c[j-1]][c[j]]=1,vis[c[j]][c[j-1]]=1,p[c[j]]=j-1,
      st.push(mp(c[j-1],c[j])),swap(c[j-1],c[j]);
  for(int i=n;i;i--){
    int j=0;
    for(j=i-1;j&&!vis[c[j]][c[j+1]];j--)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j+=1;j<i;j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
  }
  cout<<st.size()<<'\n';
  while(!st.empty()){
    pii u=st.top();
    cout<<u.fi<<' '<<u.se<<'\n';
    st.pop();
  }
  return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define I inline
#define reg register
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define i128 __int128
#define uint unsigned int
constexpr int N=1100;
int n,c[N],p[N],vis[N][N];
stack<pii>st;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=1;i<=n;i++)p[c[i]]=i;
  for(int i=n;i;i--){
    int j=0;
    for(j=p[i]-1;j&&c[j]<c[j+1];j--)
      vis[c[j+1]][c[j]]=1,vis[c[j]][c[j+1]]=1,
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<p[i];j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=p[i]+1;j<=i;j++)
      vis[c[j-1]][c[j]]=1,vis[c[j]][c[j-1]]=1,p[c[j]]=j-1,
      st.push(mp(c[j-1],c[j])),swap(c[j-1],c[j]);
    // for(int j=1;j<=n;j++)cout<<c[j]<<' ';cout<<'\n';
  }
  for(int i=n;i;i--){
    int j=0;
    for(j=i-1;j&&!vis[c[j]][c[j+1]];j--)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
    for(j=j+1;j<i;j++)
      st.push(mp(c[j],c[j+1])),swap(c[j],c[j+1]);
  }
  cout<<st.size()<<'\n';
  while(!st.empty()){
    pii u=st.top();
    cout<<u.fi<<' '<<u.se<<'\n';
    st.pop();
  }
  return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define co cout
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define ci cin
#define ins insert
#define pb push_back
#define intl int
#define fi first
#define sc second
#define RODI ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define beg begin()
#define ed end()
using namespace std;
int a[1000009];
int b[1000009];
int ac[100];
const int mod = 1e9+7;
const int siz=1e5;
bool ch=false;
string s,s1,s2,s3,s4,s5;
int t=0,sum=0,i,w,m=0,n=0,n2,n3,n4,x,y=0,k=-1,st=0,cc=0,q,sb,sa,zero=0,rodi,idx,cost,l,d,mode=1,N=1e5+1,mx=-1,z,r,cnt,mid,r2,l2,mid2,sum2,mi,j=0,r1,l1,f,x1,x2,y2;
bool check;
int ar[4009][4009];
int inf=1e9;
string arr[1009];
int p[10000009];
set<int>Se;
vector<int>vec;
map<int,multiset<int>>sm;
vector<int>vec1,vec2,vec3;
stack<int>stk;
vector<int>dpi(2e5,0);
vector<int>adj[200009];
map<int,int>freq,fr1,fr2;
map<int,set<int> >ind;
ll power(ll x , ll y)
{

ll res = 1;
//x %= mod;
while(y > 0)
{
if (y%2)res = (res*x);//%mod;
y /= 2;
x = (x*x);//%mod;
}
return res;
}
deque<int>deq;
vector<int>vis(2e5+9,0);
vector<int>dis(2e5+9,0);
string solver(string s1,string s2)
{
string   s3="";
for(int i=0;i<s1.size();i++)
{
if(s1[i]==s2[i])
s3+='0';
else
s3+='1';
}
return s3;
}
map<int,set<int>>fse;
void solve()
{

    freq.clear();
    Se.clear();
    vec1.clear();
    vec2.clear();
    vec3.clear();
        ci>>n>>l>>r;
        sum=0;
        sum2=0;
        for(i=1;i<=n;i++)
        {
            ci>>a[i];
            if(i<l)
                vec1.pb(a[i]);
            else if(i>r)
                vec3.pb(a[i]);
            else{
                vec2.pb(a[i]);
                sum+=a[i];
                sum2+=a[i];
        }
        }
        sort(vec1.rbegin(),vec1.rbegin());
        sort(vec2.begin(),vec2.begin());
        sort(vec3.rbegin(),vec3.rbegin());
        for(i=vec2.size()-1;i>=0&&vec1.size();i--)
        {
                    if(vec2[i]<vec1.back())
                        break;
                    sum-=vec2[i];
                    sum+=vec1.back();
                    vec1.pop_back();
        }


  for(i=vec2.size()-1;i>=0&&vec3.size();i--)
        {
                    if(vec2[i]<vec3.back())
                        break;
                    sum2-=vec2[i];
                    sum2+=vec3.back();
                    vec3.pop_back();
        }
        co<<min(sum,sum2)<<endl;




}
/*


*/


int32_t main()
{
RODI;
t=1;
ci>>t;

while(t--){
solve();

}
return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(best + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/

Submission (verdict: Compilation error):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(best + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Compilation error):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(best + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(best + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(max + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        s[i] = char(max + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/

Submission (verdict: Accepted):
#include <bits/stdc++.h>

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        while (pos > i) {

            swap(s[pos], s[pos-1]);

            pos--;

        }

        s[i] = char(max + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	// for (int i = 1; i <= n; i++)
	// 	cout << a[i] << " ";
	// cout << endl;
	
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
			{
				ans++;
				ans_more[i].insert(b[j]);
			}
			else
			{
				ans += 2;
				ans_still[i].insert(b[j]);
			}
	cout << ans << endl;

	for (int i = 1; i <= n; i++)
		for (auto it = ans_more[i].begin(); it != ans_more[i].end(); it++)
			cout << *it << " " << i << endl;
	
	for (int i = 1; i <= n; i++)
	{
		for (auto it = ans_still[i].begin(); it != ans_still[i].end(); it++)
			cout << i << " " << *it << endl;
		for (auto it = ans_still[i].rbegin(); it != ans_still[i].rend(); it++)
			cout << *it << " " << i << endl;
	}

    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
				ans++;
			else
				ans += 2;
	cout << ans << endl;

	for (int i = n; i >= 1; i--)
		for (int j = i - 1; j >= 1; j--)
		    cout << i << " " << j << endl;

	for (int i = 1; i <= n; i++)
		for (int j = n; j > a[i]; j--)
			if (b[j] > i) ans_more[i].insert(b[j]);
	
	for (int i = n; i >= 1; i--)
		for (auto it = ans_more[i].begin(); it!= ans_more[i].end(); it++)
            cout << i << " " << *it << endl;

    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
				ans++;
			else
				ans += 2;
	cout << ans << endl;

	for (int i = n; i >= 1; i--)
		for (int j = i - 1; j >= 1; j--)
		    cout << i << " " << j << endl;

	for (int i = 1; i <= n; i++)
		for (int j = n; j > a[i]; j--)
			if (b[j] > i) ans_more[i].insert(b[j]);
	
	for (int i = n; i >= 1; i--)
		for (auto it = ans_more[i].rbegin(); it!= ans_more[i].rend(); it++)
            cout << i << " " << *it << endl;

    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
vector<ll> ans_more[1010];
vector<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	for (int i = 1; i <= n; i++)
		for (int j = n; j > a[i]; j--)
			if (b[j] > i) ans_more[i].push_back(b[j]);
	
	ll ans = n * (n - 1) / 2;
	for (int i = 1; i <= n; i++)
		ans += ans_more[i].size();
	cout << ans << endl;

	for (int i = n; i >= 1; i--)
		for (int j = i - 1; j >= 1; j--)
		    cout << i << " " << j << endl;
	
	for (int i = n; i >= 1; i--)
		for (auto it = ans_more[i].begin(); it != ans_more[i].end(); it++)
            cout << i << " " << *it << endl;

    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	// for (int i = 1; i <= n; i++)
	// 	cout << a[i] << " ";
	// cout << endl;
	
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
			{
				ans++;
				ans_more[i].insert(b[j]);
			}
			else
			{
				ans += 2;
				ans_still[i].insert(b[j]);
			}
	cout << ans << endl;

	for (int i = 1; i <= n; i++)
	{
		for (auto it = ans_still[i].begin(); it != ans_still[i].end(); it++)
			cout << i << " " << *it << endl;
		for (auto it = ans_still[i].rbegin(); it != ans_still[i].rend(); it++)
			cout << *it << " " << i << endl;
	}

	for (int i = 1; i <= n; i++)
		for (auto it = ans_more[i].begin(); it != ans_more[i].end(); it++)
			cout << *it << " " << i << endl;
	
    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	// for (int i = 1; i <= n; i++)
	// 	cout << a[i] << " ";
	// cout << endl;
	
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
			{
				ans++;
				ans_more[i].insert(b[j]);
			}
			else
			{
				ans += 2;
				ans_still[i].insert(b[j]);
			}
	cout << ans << endl;

	for (int i = 1; i <= n; i++)
		for (auto it = ans_more[i].begin(); it != ans_more[i].end(); it++)
			cout << *it << " " << i << endl;
	
	for (int i = 1; i <= n; i++)
	{
		for (auto it = ans_still[i].begin(); it != ans_still[i].end(); it++)
			cout << i << " " << *it << endl;
		for (auto it = ans_still[i].rbegin(); it != ans_still[i].rend(); it++)
			cout << *it << " " << i << endl;
	}

    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 400010

ll T;
ll n;
ll a[200010];
ll b[200010];
multiset<ll> ans_more[1010];
multiset<ll> ans_still[1010];

bool cmp(ll a, ll b)
{
	return a < b;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		a[b[i]] = i;
	}

	// for (int i = 1; i <= n; i++)
	// 	cout << a[i] << " ";
	// cout << endl;
	
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < a[i]; j++)
			if (b[j] > i)
			{
				ans++;
				ans_more[i].insert(b[j]);
			}
			else
			{
				ans += 2;
				ans_still[i].insert(b[j]);
			}
	cout << ans << endl;

	for (int i = 1; i <= n; i++)
	{
		for (auto it = ans_still[i].begin(); it != ans_still[i].end(); it++)
			cout << i << " " << *it << endl;
		for (auto it = ans_still[i].rbegin(); it != ans_still[i].rend(); it++)
			cout << *it << " " << i << endl;
	}

	for (int i = 1; i <= n; i++)
		for (auto it = ans_more[i].begin(); it != ans_more[i].end(); it++)
			cout << *it << " " << i << endl;
	
    return 0;
}


/*
____        ____     ____  ___          ___  ____   ____
|  |        |  |     |  |  \  \        /  /  |  |  /  /
|  |        |  |     |  |   \  \      /  /   |  |_/  /
|  |        |  |     |  |    \  \    /  /    |      /
|  |        |  |     |  |     \  \  /  /     |  |\  \
|  |_____   |  |_____|  |      \  \/  /      |  | \  \
|________|  |___________|       \____/       |__|  \__\
*/