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

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

typedef pair <int, int> ii;

const int Maxn = 1005;

int n;
vector <ii> res;

void Solve(const vector <int> &seq)
{
    if (seq.empty()) return;
    int mn = 0;
    for (int i = 0; i < seq.size(); i++)
        if (seq[i] < seq[mn]) mn = i;
    vector <int> tmp;
    for (int i = 0; i < seq.size(); i++)
        if (i != mn) tmp.push_back(seq[i]);
    Solve(tmp);
    for (int i = 0; i < tmp.size(); i++)
        res.push_back({tmp[i], seq[mn]});
    for (int i = int(seq.size()) - 1; i > mn; i--)
        res.push_back({seq[mn], seq[i]});
}

int main()
{
    scanf("%d", &n);
    vector <int> seq;
    for (int i = 1; i <= n; i++) {
        int num; scanf("%d", &num);
        seq.push_back(num);
    }
    Solve(seq);
    printf("%d\n", int(res.size()));
    for (int i = 0; i < res.size(); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    return 0;
}


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

typedef pair <int, int> ii;

const int Maxn = 1005;

int n;
int c[Maxn];
vector <ii> res;

void Solve(int l, int r)
{
    if (l > r) return;
    int mn = l;
    for (int i = l; i <= r; i++)
        if (c[i] < c[mn]) mn = i;
    for (int i = l; i <= r; i++)
        if (i != mn)
            res.push_back({c[i], c[mn]});
    Solve(l, mn - 1);
    Solve(mn + 1, r);
    for (int i = r; i > mn; i--)
        res.push_back({c[mn], c[i]});
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &c[i]);
    Solve(1, n);
    printf("%d\n", int(res.size()));
    for (int i = 0; i < res.size(); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    return 0;
}


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

Code 1:
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		if(a[i] < i) {
			for(int j = a[i];j < i;j ++) {
				ans.push_back({a[j], a[i]});
			}
		} else {
			if(i == 1) break;
			int idx = -1;
			for(int j = i;j >= 1;j --) {
				if(a[j] < j) {
					idx = j + 1;
					break;
				}
			}
			if(idx == -1) idx = 1;
			vector<pii> tmp;
			int len = i - idx;
			int cnt = 0;
			while(cnt < len) {
				int j = i;
				for(;j > idx + cnt;j --) {
					tmp.push_back({a[j], a[j - 1]});
					ans.push_back({a[j], a[j - 1]});
					swap(a[j], a[j - 1]);
					
				}
				cnt ++;
			}
			reverse(tmp.begin(), tmp.end());
			for(auto t : tmp) {
				ans.push_back({t.second, t.first});
			}
			i = idx;
		}
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}



Code 2:
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	set<int> S;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
		S.insert(i);
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		for(int j = a[i] - 1;j >= 1;j --) {
			if(S.count(j) == 0) continue;
			ans.push_back({a[i], j});
		}
		S.erase(a[i]);
		for(auto t : S) {
			ans.push_back({t, a[i]});
		}
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    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>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fix(x) fixed<<setprecision(x)
#define int long long
#define endl '\n' 
using namespace std;
using vei = vector<int>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;

void solve() 
{
    int n;cin>>n;
    auto a=vei(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    vector<pii>f;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(a[j]<a[j+1])
            {
                swap(a[j],a[j+1]);
                f.push_back({a[j],a[j+1]});
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(a[j]>a[j+1])
            {
                swap(a[j],a[j+1]);
                f.push_back({a[j],a[j+1]});
            }
        }
    }
    reverse(f.begin(),f.end());
    cout<<f.size()<<'\n';
    for(auto [x,y]:f) cout<<x<<" "<<y<<"\n";

}
signed main() 
{
    IOS;

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

Code 2:
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fix(x) fixed<<setprecision(x)
#define int long long
#define endl '\n' 
using namespace std;
using vei = vector<int>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;

void solve() 
{
    int n;cin>>n;
    auto a=vei(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    vector<pii>f;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(a[j]<a[j+1])
            {
                swap(a[j],a[j+1]);
                f.push_back({a[j],a[j+1]});
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(a[j]>a[j+1])
            {
                swap(a[j],a[j+1]);
                f.push_back({a[j],a[j+1]});
            }
        }
    }
    reverse(f.begin(),f.end());
    cout<<f.size()<<'\n';
    for(auto [x,y]:f) cout<<y<<" "<<x<<"\n";

}
signed main() 
{
    IOS;

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

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

Code 1:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<deque>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define int long long
using namespace std;
 
const int N=1100,mod=1e9+7;
int a[N],b[N];
int s=0,n=0;
pair<int,int> ans[N];

void go(int cur,int begin,int end) {
    for (int i=begin;i<n;++i) {
        ans[++s]={b[i+1],b[i]};
        swap(b[i],b[i+1]);
    }
    for (int i=n;i>end;--i) {
        ans[++s]={b[i],b[i-1]};
        swap(b[i],b[i-1]);
    }
}

signed main() {
    cin>>n;
    for (int i=1;i<=n;++i) cin>>a[i];
    for (int i=1;i<=n;++i) b[i]=i;
    for (int i=1;i<=n;++i) {
        int pos;
        for (int j=1;j<=n;++j) {
            if (a[i]==b[j]) pos=j;
        }
        go(a[i],pos,i);
        //cout<<a[i]<<" "<<pos<<" "<<i<<endl;
    }
    cout<<s<<endl;
    for (int i=1;i<=s;++i) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
	return 0;
}

Code 2:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<deque>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define int long long
using namespace std;
 
const int N=1000000,mod=1e9+7;
int a[N],b[N];
int s=0,n=0;
pair<int,int> ans[N];

void go(int cur,int begin,int end) {
    for (int i=begin;i<n;++i) {
        ans[++s]={b[i+1],b[i]};
        swap(b[i],b[i+1]);
    }
    for (int i=n;i>end;--i) {
        ans[++s]={b[i],b[i-1]};
        swap(b[i],b[i-1]);
    }
}

signed main() {
    cin>>n;
    for (int i=1;i<=n;++i) cin>>a[i];
    for (int i=1;i<=n;++i) b[i]=i;
    for (int i=1;i<=n;++i) {
        int pos;
        for (int j=1;j<=n;++j) {
            if (a[i]==b[j]) pos=j;
        }
        go(a[i],pos,i);
        //cout<<a[i]<<" "<<pos<<" "<<i<<endl;
    }
    cout<<s<<endl;
    for (int i=1;i<=s;++i) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
	return 0;
}

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

Code 1:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <limits.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n) ,final_(n);
    
    // n = 4;
    // final_ = {2,3,1,4};
    // v = {4,3,2,1};
    
    for(int i=0;i<n;i++){
        int a ;
        cin>>a;
        final_[a-1] = i+1;
        v[i] = n-i;
        v[n-i] = i;
    }

    // for(int i=0;i<n;i++)cout<<final_[i]<<' ';
    // cout<<endl;
    // for(int i=0;i<n;i++)cout<<v[i]<<' ';
    // cout<<endl;

    // cout<<"reached"<<endl;
    vector<pair<int,int>> swaps;
    for(int i=n-1;i>=0;i--){
        int j = i-1;
        while(v[i] != final_[i]){
            swap(v[i],v[j]);
            // cout<<i<<' '<<j<<' '<<v[i]<<' '<<final_[i]<<' '<<v[j]<<endl;
            swaps.push_back({j+1,i+1});
            j--;
        }
        // cout<<"reached"<<endl;
        // if(j<-1)cout<<"Error"<<endl;
    }

    int num = n*(n-1)/2 + swaps.size();
    cout<<num<<endl;
    for(int i=0;i<n;i++){
        for(int j=i+1 ;j<n ;j++){
            cout<<j+1<<' '<<i+1<<endl;
        }
    }

    for(pair<int,int> &p:swaps) 
        cout<<p.first<<' '<<p.second<<endl;

    // cout<<endl;

    return 0;
}

Code 2:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <limits.h>
using namespace std;

int main(){
    int n,a;
    cin>>n;

    // n = 4;
    vector<int> v(n);
    vector<int> final_(n);
    vector<int> index_v(n+1);
    vector<int> index_f(n+1);
    
    for(int i=0;i<n;i++){
        cin>>a;
        final_[a-1] = i+1;
        v[i] = n-i;
        // index[n-i] = i;
    }

    // final_ = {2,3,1,4};
    // final_ = {1,4,2,3};
    // v =      {4,3,2,1};

    for(int i=0;i<n;i++){
        index_v[n-i] = i;
        index_f[final_[i]] = i;
    }

    // cout<<"reached"<<endl;
    vector<pair<int,int>> swaps;
    for(int a = n ;a > 0 ;a--){
        while( v[index_f[a]] != a){
            int b = v[index_f[a]];
            swap(v[index_v[b]],v[index_v[b+1]]);
            swaps.push_back({index_v[b+1]+1,index_v[b]+1});
            swap(index_v[b],index_v[b+1]);
            // cout<<a<<' '<<index_[a]<<' '<<index[a-1]<<endl;
        }
        // cout<<"reached "<<a<<endl;
        // for(int b:v)cout<<b<<' ';
        // cout<<endl;
        // for(int b:index_v)cout<<b<<' ';
        // cout<<endl;
        // if(j<-1)cout<<"Error"<<endl;
    }

    int num = n*(n-1)/2 + swaps.size();
    cout<<num<<endl;
    for(int i=0;i<n;i++){
        for(int j=i+1 ;j<n ;j++){
            cout<<j+1<<' '<<i+1<<endl;
        }
    }

    for(pair<int,int> &p:swaps) 
        cout<<p.first<<' '<<p.second<<endl;

    // cout<<endl;

    return 0;
}

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

Code 1:
// code for finding maximum number of overtakes
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;            // number of cars
    cin >> n;         // taking input of number of cars
    vector<int> a(n); // array of size n to store the positions of the cars
    vector<int> b(n); // array of size n to store the positions of the cars
    vector<int> c;
    for (int i = 0; i < n; i++)
    {
        b[i] = i + 1; // initialising the positions of the cars
    }
    for (int i = 0; i < n; i++) // loop to take input of the positions of the cars
    {
        cin >> a[i];
    }
    int count = 0; // intialising counter
    for(int i=1;i<=n;i++)
    {
        int init_position=find(b.begin(),b.end(),i)-b.begin();
        for(int j=init_position;j<n-1;j++)
        {
            if(i>b[find(b.begin(),b.end(),i)-b.begin()+1] && find(a.begin(),a.end(),i)<find(a.begin(),a.end(),b[find(b.begin(),b.end(),i)-b.begin()+1]))
            {
                break;
            }
            swap(b[j],b[j+1]);
            c.push_back(b[j]);c.push_back(b[j+1]);
            count++;
        }
        while(find(a.begin(),a.end(),i)-a.begin()<find(a.begin(),a.end(),b[find(b.begin(),b.end(),i)-b.begin()-1])-a.begin() && find(b.begin(),b.end(),i)-b.begin()!=0)
        {
            int j=find(b.begin(),b.end(),i)-b.begin()-1;
            int k=find(b.begin(),b.end(),i)-b.begin();
            swap(b[k],b[j]);
            c.push_back(b[j]);c.push_back(b[k]);
            count ++;
        }
    }
    cout<<count<<endl;
    for(int i=0;i<c.size();i+=2)
    {
        cout<<c[i]<<" "<<c[i+1]<<endl;
    }
    return 0;
}

Code 2:
// code for finding maximum number of overtakes
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;            // number of cars
    cin >> n;         // taking input of number of cars
    vector<int> a(n); // array of size n to store the positions of the cars
    vector<int> b(n); // array of size n to store the positions of the cars
    vector<int> c;
    for (int i = 0; i < n; i++)
    {
        b[i] = i + 1; // initialising the positions of the cars
    }
    for (int i = 0; i < n; i++) // loop to take input of the positions of the cars
    {
        cin >> a[i];
    }
    int count = 0; // intialising counter
    for(int i=1;i<=n;i++)
    {
        int init_position=find(b.begin(),b.end(),i)-b.begin();
        for(int j=init_position;j<n-1;j++)
        {
            if(i>b[find(b.begin(),b.end(),i)-b.begin()+1] && find(a.begin(),a.end(),i)<find(a.begin(),a.end(),b[find(b.begin(),b.end(),i)-b.begin()+1]))
            {
                break;
            }
            swap(b[j],b[j+1]);
            c.push_back(b[j]);c.push_back(b[j+1]);
            count++;
        }
    }
    cout<<count<<endl;
    for(int i=0;i<c.size();i+=2)
    {
        cout<<c[i]<<" "<<c[i+1]<<endl;
    }
    return 0;
}

Answer: 2
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;
    }
    int back=0;//inflation at back
    unordered_set<int> bks;
    for(int i=n-1;i>0;i--){
        if(bks.find(i+1)!=bks.end())back--;
        int l=a[i]+i-1-back;//going all the way left&back to pos
        an+=l;
        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++;
            }
        }
        if(a[i]<i+1)back++;
        bks.emplace(a[i]);
    }
    cout << an;
    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;
    }
    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;
}


Answer: 2
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;//inflation at back
    unordered_set<int> bks;
    for(int i=n-1;i>0;i--){
        if(bks.find(i+1)!=bks.end())back--;
        int l=a[i]+i-1-back;//going all the way left&back to pos
        an+=l;
        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<=i+1){
            if(bks.find(cur)==bks.end()&&cur!=a[i]){
                ans.push_back(make_pair(cur,a[i]));
                cur++;
            }else{
                cur++;
            }
        }
        if(a[i]<i+1)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++17 

Code 1:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define vec vector
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 998244353;
ll fpow(ll a, ll b, ll m = -1)
{
	if (m != -1)
		a %= m;
	ll res = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
		{
			if (m != -1)
				res = res * a % m;
			else
			{
				res *= a;
			}
		}
		a = a * a;
		if (m != -1)
		{
			a %= m;
		}
		b /= 2;
	}
	return res;
}
int main()
{
	fast;
	// freopen("pails.in", "r", stdin);
	// freopen("pails.out", "w", stdout);
	ll t = 1;
	// cin >> t;
end:;
	while (t--)
	{
		ll n, k;
		cin >> n;
		vec<ll> v(n);
		for (int i = 0; i < n; i++)
		{
			cin >> v[i];
		}
		set<ll> st;
		ll mx = 0;
		vec<pll> ans;
		for (int i = 0; i < n; i++)
		{
			for (int j = 1; j < v[i]; j++)
			{
				ans.push_back({v[i], j});
				if(st.count(j))
				{
					ans.push_back({j, v[i]});
				}
			}
			st.insert(v[i]);
		}
		cout << ans.size() << '\n';
		for (int i = 0; i < ans.size(); i++)
		{
			cout << ans[i].first << ' ' << ans[i].second << '\n';
		}
		
	}
	return 0;
}

Code 2:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define vec vector
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 998244353;
ll fpow(ll a, ll b, ll m = -1)
{
	if (m != -1)
		a %= m;
	ll res = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
		{
			if (m != -1)
				res = res * a % m;
			else
			{
				res *= a;
			}
		}
		a = a * a;
		if (m != -1)
		{
			a %= m;
		}
		b /= 2;
	}
	return res;
}
int main()
{
	fast;
	// freopen("pails.in", "r", stdin);
	// freopen("pails.out", "w", stdout);
	ll t = 1;
	// cin >> t;
end:;
	while (t--)
	{
		ll n, k;
		cin >> n;
		vec<ll> v(n);
		for (int i = 0; i < n; i++)
		{
			cin >> v[i];
		}
		set<ll> st;
		ll mx = 0;
		vec<pll> ans;
		for (int i = 0; i < n; i++)
		{
			for(int j = i - 1; j >= 0; j--)
			{
				swap(v[j+1], v[j]);
				ans.push_back({v[j+1], v[j]});
			}
			ll in = 0;
			while(in < i && v[in]> v[in+1])
			{
				swap(v[in], v[in+1]);
				ans.push_back({v[in+1], v[in]});
				in++;
			}
		}
		reverse(all(ans));
		cout << ans.size() << '\n';
		for (int i = 0; i < ans.size(); i++)
		{
			cout << ans[i].first << ' ' << ans[i].second << '\n';
		}
		
	}
	return 0;
}

Answer: 2