ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
void solve() {
    int n;
    cin >> n;
    vector<int> vec(n + 1);
    vector<int> mp(n + 1);

    for (int i = 1; i <= n; i++)
        vec[i] = i;

    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        mp[x] = i;
    }
    map<int,int> curr;
    for(int i=1;i<=n;i++)
    curr[i]=i;
    vector<pair<int,int>> ans;
    for(int k=1;k<=n;k++)
    {
        int i=curr[k];
        int val = vec[i];
        for (int j = i - 1; j >= 1; j--) {
            ans.push_back({val, vec[j]});
            swap(vec[j],vec[j+1]);
        }
        for (int j = 2; j <= n; j++) {
            if(mp[vec[j]]>mp[val]) break;
            ans.push_back({vec[j], val});
            swap(vec[j-1],vec[j]);
        }
        for(int l=1;l<=n;l++)
        {
          curr[vec[l]]=l;
        }
    }

    cout << (int)ans.size() << "\n";
    for (auto &p : ans) {
        cout << p.first << " " << p.second << "\n";
    }
}

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

    int test = 1;
    // cin >> test; // If multiple test cases are needed, uncomment this.
    while (test--) {
        solve();
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

struct PairHash {
    template <typename T1, typename T2>
    size_t operator()(const pair<T1, T2>& p) const {
        return hash<T1>()(p.first) ^ (hash<T2>()(p.second) << 1);
    }
};

void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vector<int> a(n + 1), mp(n + 1);
    for (int i = 1; i <= n; i++)
        a[i] = i;

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

    unordered_set<pair<int, int>, PairHash> st;
    for (int i = 1; i <= n; i++) {
        int shift = mp[a[i]] - i;
        if (shift <= 0) continue;
        int val2 = a[i];
        int pos = i;
        while (shift--) {
            a[pos] = a[pos + 1];
            if (st.find({a[pos + 1], val2}) != st.end()) {
                st.erase({a[pos + 1], val2});
            } else {
                st.insert({val2, a[pos + 1]});
            }
            pos++;
        }
        a[mp[val2]] = val2;
        i--;
    }

    vector<pair<int, int>> ans;
    vector<int> vec(n + 1);
    for (int i = 1; i <= n; i++)
        vec[i] = i;

    for (int i = 2; i <= n; i++) {
        int val = vec[i];
        for (int j = i - 1; j >= 1; j--) {
            ans.push_back({val, vec[j]});
            vec[j + 1] = vec[j];
        }
        vec[1] = val;

        for (int j = 2; j <= i; j++) {
            if (st.find({vec[j], val}) != st.end()) {
                vec[j - 1] = val;
                break;
            }
            ans.push_back({vec[j], val});
            vec[j - 1] = vec[j];
            if (j == i) vec[j] = val;
        }
    }

    cout << (int)ans.size() << "\n";
    for (auto &p : ans) {
        cout << p.first << " " << p.second << "\n";
    }
}

int main() {
    solve();
    return 0;
}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include<bits/stdc++.h>

using namespace std;
using pii=pair<int,int>;

signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    cout.tie(nullptr)->sync_with_stdio(0);
    int n;
    cin>>n;
    vector<int> lst(n+1);
    vector<int> now(n+1);
    for(int i=1; i<=n ; i++){
        cin>>lst[i];
        now[i]=i;
    }
    vector<pii> ans;
    vector<vector<bool>> vis(n+1,vector<bool>(n+1,true));
    for(int i=1; i<=n ; i++){
        if(now[i]!=lst[i]){
            int p=0;
            int tar=lst[i];
            for(int j=i+1; j<=n ; j++){
                if(now[j]==tar){
                    p=j; break;
                }
            }
            for(int j=p ; j>i ; j--){
                ans.push_back({now[j],now[j-1]});
                swap(now[j],now[j-1]);
                vis[now[j]][now[j-1]]=vis[now[j-1]][now[j]]=false;
            }
        }
    }
    //cout<<"!!"<<' '<<ans.size()<<'\n';
    //for(auto it: now) cout<<it<<' ';
    //cout<<'\n';
    for(int i=1; i<n ; i++){
        int j=i+1;
        for(int v ; j<=n; j++){
            v=now[j];
            if(vis[now[j-1]][v]){
                //cout<<"??"<<u<<' '<<v<<'\n';
                ans.push_back({v,now[j-1]});
                swap(now[j],now[j-1]);
                vis[now[j-1]][v]=vis[v][now[j-1]]=false;
            }
            else{
                break;
            }
        }
        j--;
        for(int v; j>i ; j--){
            //cout<<"NMSL "<<i<<' '<<j<<'\n';
            v=now[j];
            ans.push_back({now[j],now[j-1]});
            swap(now[j],now[j-1]);
        }
    }
    cout<<ans.size()<<'\n';
    for(auto x :ans ){
        cout<<x.first<<' '<<x.second<<'\n';
    }
}

Code 2:
#include<bits/stdc++.h>

using namespace std;
using pii=pair<int,int>;

signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    cout.tie(nullptr)->sync_with_stdio(0);
    int n;
    cin>>n;
    vector<int> lst(n+1);
    vector<int> now(n+1);
    for(int i=1; i<=n ; i++){
        cin>>lst[i];
        now[i]=i;
    }
    // for(auto it:now) cout<<it<<' ';
    // cout<<'\n';
    vector<pii> ans;
    vector<vector<bool>> vis(n+1,vector<bool>(n+1,true));
    for(int i=1 ; i<n ; i++){
        for(int j=n ; j>i ;  j--){
            ans.push_back({now[j],now[j-1]});
            swap(now[j],now[j-1]);
        }
    }
    for(int i=1; i<=n; i++){
        if(now[i]!=lst[i]){
            int p,tar=lst[i];
            for(int j=i+1 ; j<=n ; j++){
                if(now[j]==tar){
                    p=j;
                    break;
                }
            }
            for(int j=p ; j>i ; j--){
                    ans.push_back({now[j],now[j-1]});
                swap(now[j],now[j-1]);
            }
        }
    }
    // for(auto it:now) cout<<it<<' ';
    // cout<<'\n';
    cout<<ans.size()<<'\n';
    for(auto x :ans ){
        cout<<x.first<<' '<<x.second<<'\n';
    }
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: python

Code 1:
import sys

def max_num(order, n):
    if n == 0:
        return 0, ""
    counted = set()
    m = 0
    string = ""
    i = order[0]
    before = ""
    after = ""
    for j in sorted(order, reverse=True):
        if i < j:
            m += 2
            string = f"\n{j} {i}"+string
            before += f"\n{i} {j}"
        elif i > j:
            m += 1
            after += f"\n{i} {j}"
    string += before + after
    m2, s2 = max_num(order[1:], n-1)
    m += m2
    string += s2
    return m, string
    # for i in range(n):
    #     for j in reversed(range(n)):
    #         if j+1 not in counted:
    #             if j+1 > order[i]:
    #                 m += 2
    #                 string += f"{j+1} {order[i]}\n{order[i]} {j+1}\n"
    #             elif j+1 < order[i]:
    #                 m += 1
    #                 string += f"{order[i]} {j+1}\n"
    #     counted.add(order[i])

i = 0
for line in sys.stdin.readlines():
    if i==0:
        n = int(line)
    else:
        order = [int(x) for x in line.split(" ")]
        m, string = max_num(order, n)
        print(f"{m}{string}")
    i+=1

Code 2:
import sys

def max_num(order, n):
    counted = set()
    m = 0
    string = ""
    for i in order:
        before = ""
        after = ""
        m += n - len(counted)-1
        for j in reversed(range(1,n+1)):
            if j not in counted and j != i:
                if i < j:
                    m += 1
                    before = f"\n{j} {i}"+before
                before += f"\n{i} {j}"
        string += before + after
        counted.add(i)
    print(f"{m}{string}")
    return m, string

i = 0
for line in sys.stdin.readlines():
    if i==0:
        n = int(line)
    else:
        order = [int(x) for x in line.split(" ")]
        max_num(order, n)
    i+=1

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include <iostream>
#include <vector>
using namespace std;

int n;
int c[1100];
int main()
{

    vector<pair<int, int>> ans;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    for (int i = 1; i < n; i++)
        if (c[i] < c[i + 1])
        {
            ans.push_back({c[i], c[i + 1]});
            ans.push_back({c[i + 1], c[i]});
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n - i; j++)
        {
            if (c[j] > c[j + 1])
            {
                ans.push_back({c[j], c[j + 1]});
                swap(c[j + 1], c[j]);
            }
        }

    cout << ans.size() << endl;
    for (int i = (int)ans.size() - 1; i >= 0; i--)
        cout << ans[i].first << " " << ans[i].second << endl;

    system("pause");
    return 0;
}

Code 2:
#include <iostream>
#include <vector>
using namespace std;

int n;
int c[1100];
int v[1100][1100] = {0};
int main()
{

    vector<pair<int, int>> ans;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n - i; j++)
        {
            if (c[j] < c[j + 1])
            {
                ans.push_back({c[j], c[j + 1]});
                swap(c[j + 1], c[j]);
            }
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n - i; j++)
        {
            if (c[j] > c[j + 1])
            {
                ans.push_back({c[j], c[j + 1]});
                swap(c[j + 1], c[j]);
            }
        }
    cout << ans.size() << endl;
    for (int i = (int)ans.size() - 1; i >= 0; i--)
        cout << ans[i].first << " " << ans[i].second << endl;

    system("pause");
    return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) cin >> c[i];

    vector<int> cars(n);
    iota(cars.begin(), cars.end(), 1); // Initialize cars as [1, 2, ..., n]

    vector<pair<int, int>> overtakes;

    // Perform Bubble Sort to count overtakes
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            if (cars[j] > cars[j + 1]) {
                swap(cars[j], cars[j + 1]);
                overtakes.push_back({cars[j + 1], cars[j]});
            }
        }
    }

    // Output the number of overtakes and the list of overtakes
    cout << overtakes.size() << endl;
    for (const auto& overtake : overtakes) {
        cout << overtake.first << " " << overtake.second << endl;
    }

    return 0;
}


Code 2:
#include <iostream>
using namespace std;
const int N=230000;
int n,a[N],ans,vis[N];
struct fa{
	int x,y;
}as[N*20];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		vis[a[i]]=1;
		for(int j=a[i]+1;j<=n;j++) if(!vis[j]) as[++ans]={j,a[i]};
		for(int j=n;j>=1;j--) if(!vis[j]) as[++ans]={a[i],j};
	}
	cout<<ans<<endl;
	for(int i=1;i<=ans;i++){
		cout<<as[i].x<<' '<<as[i].y<<endl;
	}
	return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,a[N],b[N];
vector<pair<int,int> > v;
void solve(){
	v.clear();
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			if(a[j]<a[j+1]){
				v.emplace_back(make_pair(a[j],a[j+1]));
				swap(a[j],a[j+1]);
			}
		}
	}
	for(int i=n;i>=1;i--){
		for(int j=i-1;j>=1;j--) v.emplace_back(make_pair(i,j));
	}
	reverse(v.begin(),v.end());
	cout<<v.size()<<"\n";
	for(auto x:v){
		cout<<x.first<<' '<<x.second<<'\n';
	}
}
int main(){
	int t=1;
//	cin>>t;
	while(t--) solve();
	return 0;
}
/*



*/


Code 2:
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,a[N],b[N];
vector<pair<int,int> > v;
void solve(){
	v.clear();
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			if(a[j]>a[j+1]){
				v.emplace_back(make_pair(a[j],a[j+1]));
				swap(a[j],a[j+1]);
			}
		}
	}
	reverse(v.begin(),v.end());
	for(int i=1;i<n;i++){
		if(b[i]<b[i+1]){
			v.emplace_back(b[i+1],b[i]);
			v.emplace_back(b[i],b[i+1]);
		}
	}
	cout<<v.size()<<"\n";
	for(auto x:v){
		cout<<x.first<<' '<<x.second<<'\n';
	}
}
int main(){
	int t=1;
//	cin>>t;
	while(t--) solve();
	return 0;
}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int,int>> ans;
    int an=0;
    for(int i=0;i<n;i++){
        int j;
        cin >> j;
        a[i]=j;
    }
    unordered_set<int> bks;
    for(int i=n-1;i>0;i--){
        int cur=a[i]-1;
        while(cur>0){
            if(bks.find(cur)==bks.end() && cur!=a[i]){
                ans.push_back(make_pair(a[i],cur));
                cur--;
            }else{
                cur--;
            }
        }
        cur=1;
        while(cur<=n){
            if(bks.find(cur)==bks.end()&&cur!=a[i]){
                ans.push_back(make_pair(cur,a[i]));
                cur++;
            }else{
                cur++;
            }
        }
        bks.emplace(a[i]);
    }
    cout << ans.size();
    cout << "\n";
    for(auto& [a,b]:ans){
        cout << a << " " << b << "\n";
    }
    return 0;
}


Code 2:
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int,int>> ans;
    int an=0;
    for(int i=0;i<n;i++){
        int j;
        cin >> j;
        a[i]=j;
    }
    int back=0;
    unordered_set<int> bks;
    for(int i=n-1;i>0;i--){
        int l=a[i]+i-1-back;//going all the way left&back to pos
        an+=l;
        int cur=back+1;
        while(cur>0){
            if(bks.find(cur)==bks.end() && cur!=a[i]){
                ans.push_back(make_pair(a[i],cur));
                cur--;
            }else{
                cur--;
            }
        }
        cur=1;
        while(cur<=i+1){
            if(bks.find(cur)==bks.end()&&cur!=a[i]){
                ans.push_back(make_pair(cur,a[i]));
                cur++;
            }else{
                cur++;
            }
        }
        back++;
        bks.emplace(a[i]);
    }
    cout << an;
    cout << "\n";
    for(auto& [a,b]:ans){
        cout << a << " " << b << "\n";
    }
    return 0;
}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
    
int main() {
   int z;
   cin>>z;
    int a[z];
    int b[z];
    vector<vector<int>> v(z,vector<int> (z,0));
    for(int i=0;i<z;i++){
      cin>>a[i];
      b[i]=i+1;
    }
    vector<pair<int,int>> ans;
    for(int i=0;i<z;i++){
      if(b[i]!=a[i]){
        int j=i;
        while(b[j]!=a[i]){
         j++;
        }
        while (j>i)
        {
         ans.push_back({a[i],b[j-1]});
         swap(b[j],b[j-1]);
         v[b[j]-1][b[j-1]-1]=1;
         j--;
        }
      }
    }
   for(int i=z-1;i>=1;i--){
     int j=i-1;
     while(j>=0&&v[b[i]-1][b[j]-1]==0&&v[b[j]-1][b[i]-1]==0){
      ans.push_back({b[i],b[j]});
      j--;
     }
     while(j<i-1){
      ans.push_back({b[j+1],b[i]});
      j++;
     }
   }
   cout<<ans.size()<<endl;
   for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
   }
   
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
    
int main() {
   int z;
   cin>>z;
    int a[z];
    int b[z];
    for(int i=0;i<z;i++){
      cin>>a[i];
      b[i]=z-i;
    }
    vector<pair<int,int>> ans;
    for(int i=z;i>=2;i--){
      for(int j=i-1;j>=1;j--){
         ans.push_back({i,j});
      }
    }
    for(int i=0;i<z-1;i++){
      int j=i;
      while(a[i]!=b[j]){
         j++;
      }
      while(j>i){
         ans.push_back({a[i],b[j-1]});
         swap(b[j],b[j-1]);
         j--;
      }
    }
   cout<<ans.size()<<endl;
   for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
   }
   
    return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({j,j+1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({j,j-1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({a[j+1],a[j]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({a[j],a[j-1]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}


Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<=b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
/*
  卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul array<int,3>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e5+5,yyx=998244353;
vector<PII> to[N];
int n,m,a[N],b[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
vector<PII> t;
void bfs(){
   rep_(i,n,1) rep_(j,i-1,1) t.push_back({i,j});
   rep(i,1,n) b[i]=n-i+1;
   rep(i,1,n){
    int z=1;
    rep(j,1,n) if(a[i]==b[j]) z=j;
    while(z>i){
        t.push_back({b[z],b[z-1]});
        swap(b[z],b[z-1]);
        z--;
    }
   }
}
inline void solve(){
  cin>>n;
  rep(i,1,n) cin>>a[i];
  bfs();
  cout<<t.size()<<endl;
  for(auto [x,y]:t) cout<<x<<" "<<y<<endl;
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  //cin>>_;
  while(_--)
  solve();
  return 0;
}

Code 2:
/*
  卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul array<int,3>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e5+5,yyx=998244353;
vector<int> to[N];
int n,m,a[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
inline void solve(){
  cin>>n;
  set<PII> s;
  vector<PII> t;
  rep(i,1,n) cin>>a[i];
  rep(i,1,n){
    rep(j,1,i-1){
        if(a[j]<a[i]) s.insert({a[i],a[j]}),s.insert({a[j],a[i]});
        else s.insert({a[j],a[i]});
    }
  }
  cout<<s.size()<<endl;
  for(auto [x,y]:s) t.push_back({x,y});
  sort(all(t),[&](PII x,PII y){
    return x.second==y.second?x.first<y.first:x.second<y.second;
  });
  for(auto [x,y]:t) cout<<x<<" "<<y<<endl;
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  //cin>>_;
  while(_--)
  solve();
  return 0;
}

Answer: 1