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

Code 1:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int> pos(n+1);
    vector<int> v(n+1);

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

    vector<pair<int,int> > ans;

    for(int i=1;i<=n;i++){
        int car = i;
        stack<pair<int,int> > st1;

        for(int j = pos[car] + 1; j<=n;j++){
            if(v[j] < car){
                // cout<<car<<" : "<<car<<" -> "<<j<<endl;
                st1.push(make_pair(car, v[j]));
            }
        }   

        while(!st1.empty()){
            pair<int,int> p = st1.top();
            st1.pop();
            // cout<<i<<" "<<car<<" -> "<<j<<endl;
            ans.push_back(make_pair(p.first, p.second));
        }



        stack<pair<int,int> > st;

        for(int j = pos[car]-1; j>=1; j--){
            if(v[j] < car){
                // cout<<i<<" "<<car<<" -> "<<j<<endl;
                ans.push_back(make_pair(car, v[j]));
                st.push(make_pair(car, v[j]));
            }
        }

        while(!st.empty()){
            pair<int,int> p = st.top();
            st.pop();
            // cout<<i<<" "<<car<<" -> "<<j<<endl;
            ans.push_back(make_pair(p.second, p.first));
        }

    }

    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>
#define ll long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int> pos(n+1);

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

    vector<pair<int,int> > ans;

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(pos[i] < pos[j]){
                ans.push_back(make_pair(j,i));
                ans.push_back(make_pair(i,j));
            }else{
                ans.push_back(make_pair(j,i));
            }
        }
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    
    return 0;
}

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

Code 1:
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	long long n, i, j;

	cin >> n;

	long long* c = new long long[n];

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

	long long num_inverse = 0;

	for (i = 0; i < n; i++)
	{
		for (j = i; j < n; j++)
		{
			if (c[i] > c[j])
			{
				num_inverse++;
			}
		}
	}
	
	long long num_pass = n * (n - 1) - num_inverse;

	vector<long long> arr;

	long long* pos_arr = new long long[n + 1];

	for (i = 0; i < n; i++)
	{
		arr.push_back(i + 1);

		pos_arr[i + 1] = i;
	}

	cout << num_pass << endl;

	for (i = 1; i < n + 1; i++)
	{
		long long pos = pos_arr[c[i - 1]];

		for (j = pos + 1; j < n; j++)
		{
			cout << arr[j] << " " << c[i - 1] << endl;
		}

		for (j = n - 1; j >= i; j--)
		{
			if (j != pos)
			{
				cout << c[i - 1] << " " << arr[j] << endl;
			}
			
			if (j < pos)
			{
				pos_arr[arr[j]]++;
			}
		}

		arr.erase(arr.begin() + pos);

		arr.insert(arr.begin() + pos, c[i - 1]);

		pos_arr[c[i - 1]] = i - 1;
	}

	return 0;
}

Code 2:
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	long long n, i, j;

	cin >> n;

	long long* c = new long long[n];

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

	long long num_inverse = 0;

	for (i = 0; i < n; i++)
	{
		for (j = i; j < n; j++)
		{
			if (c[i] > c[j])
			{
				num_inverse++;
			}
		}
	}
	
	long long num_pass = n * (n - 1) - num_inverse;

	vector<long long> arr;

	long long* pos_arr = new long long[n + 1];

	for (i = 0; i < n; i++)
	{
		arr.push_back(i + 1);

		pos_arr[i + 1] = i;
	}

	cout << num_pass << endl;

	for (i = 1; i < n + 1; i++)
	{
		long long pos = pos_arr[c[i - 1]];

		for (j = pos + 1; j < n + 1 - i; j++)
		{
			cout << arr[j] << " " << c[i - 1] << endl;
		}

		for (j = n - i; j >= 0; j--)
		{
			if (j != pos)
			{
				cout << c[i - 1] << " " << arr[j] << endl;
			}
			
			if (j > pos)
			{
				pos_arr[arr[j]]--;
			}
		}

		arr.erase(arr.begin() + pos);
	}

	return 0;
}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ns;
vector<int> cur;
vector<int> pos;
vector<int> x;
vector<vector<bool>> v;
bool d = false;

void f(int it, int y, int j){
    int co = 0;
    it--;
    if(it != - 1){
        while((cur[it] <= j && !v[cur[it]][cur[it+1]] && !v[cur[it+1]][cur[it]]) || (d && it >= y)){
            v[cur[it+1]][cur[it]] = true;
            ns.push_back({cur[it+1], cur[it]});
            swap(cur[it], cur[it+1]);
            it--;
            if(it == -1){
                break;
            }
        }
    }
    it++;
    while(it < y){
        v[cur[it+1]][cur[it]] = true;
        ns.push_back({cur[it+1], cur[it]});
        swap(cur[it], cur[it+1]);
        it++;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    v.resize(n+1, vector<bool>(n+1));
    x.resize(n);
    pos.resize(n+1);
    for(int i = 0; i < n; i++){
        cin >> x[i];
        pos[x[i]] = i;
    }
    cur.resize(n);
    for(int i = 0; i < n; i++){
        cur[i] = i+1;
    }
    for(int y = 0; y < n; y++){
        int it = 0;
        for(int i = 0; i < n; i++){
            if(cur[i] == x[y]){
                it = i;
                break;
            }
        }
        for(int i = y; i <= it; i++){
            d = false;
            if(i == it){
                d = true;
            }
            f(i, y, cur[i]);
        }
    }
    cout << ns.size() << "\n";
    for(int y = 0; y < ns.size(); y++){
        cout << ns[y].first << " " << ns[y].second << "\n";
    }
    return 0;
}

//3 1 4 2
//1 2 3 4
//2 1 3 4
//2 3 1 4
//3 2 1 4
//3 1 2 4
//3 1 4 2
//3 4 1 2
//4 3 1 2
//3 4 1 2
//3 1 4 2


Code 2:
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ns;
vector<int> cur;
vector<int> x;

void f(int it, int y, int j){
    int co = 0;
    it--;
    if(it != - 1){
        while(cur[it] <= j){
            ns.push_back({cur[it+1], cur[it]});
            swap(cur[it], cur[it+1]);
            it--;
            if(it == -1){
                break;
            }
        }
    }
    it++;
    while(it < y){
        ns.push_back({cur[it+1], cur[it]});
        swap(cur[it], cur[it+1]);
        it++;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    x.resize(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    cur.resize(n);
    for(int i = 0; i < n; i++){
        cur[i] = i+1;
    }
    for(int y = 0; y < n; y++){
        int it = 0;
        for(int i = 0; i < n; i++){
            if(cur[i] == x[y]){
                it = i;
                break;
            }
        }
        for(int i = y; i <= it; i++){
            f(i, y, cur[i]);
        }
    }
    cout << ns.size() << "\n";
    for(int i = 0; i < ns.size(); i++){
        cout << ns[i].first << " " << ns[i].second << "\n";
    }
    return 0;
}

//5
//1 2 3
//2 3 1
//

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

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

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n;
    cin>>n;
    vector<ll>a(n), b;
    for(auto&i:a) cin>>i;
    b = a;
    vector<pair<ll, ll>>v;
    for(ll i = 0; i<n; i++) {
        for(ll j = 0; j<n-1; j++) {
            if(b[j]<b[j+1]){
                swap(b[j], b[j+1]);
                v.push_back({b[j], b[j+1]});
            }
        }
    }
    for(ll i = 0; i<n; i++) {
        for(ll j = 0; j<n-1; j++) {
            if(b[j]>b[j+1]){
                swap(b[j], b[j+1]);
                v.push_back({b[j], b[j+1]});
            }
        }
    }
    reverse(v.begin(), v.end());

    cout<<v.size()<<"\n";
    for(auto&i:v) cout<<i.first<<" "<<i.second<<"\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) solve();

    return 0;
}

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

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n;
    cin>>n;
    vector<ll>a(n), b;
    for(auto&i:a) cin>>i;
    b = a;
    vector<pair<ll, ll>>v;
    for(ll i = 0; i<n; i++) {
        for(ll j = 0; j<n-1; j++) {
            if(b[j]<b[j+1]){
                swap(b[j], b[j+1]);
                v.push_back({b[j], b[j+1]});
            }
        }
    }
    for(ll i = 0; i<n; i++) {
        for(ll j = 0; j<n-1; j++) {
            if(b[j]>b[j+1]){
                swap(b[j], b[j+1]);
                v.push_back({b[j], b[j+1]});
            }
        }
    }
    reverse(v.begin(), v.end());

    cout<<v.size()<<"\n";
    for(auto&i:v) cout<<i.second<<" "<<i.first<<"\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) solve();

    return 0;
}

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

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

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;

    set<int> s;
    for (int i = 0; i < n; i++)
    {
        for (int j = v[i]+1; j <= n; j++)
        {
            if(s.find(j)!=s.end()) continue;
            ans.push_back({j,v[i]});
        }
        for (int j = n; j >= 1; j--)
        {
            if(j==v[i]) continue;
            if(s.find(j)!=s.end()) continue;
            ans.push_back({v[i],j});
        }
        s.insert(v[i]);
    }
    

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

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

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;
    for (int i = 1; i <= n; i++)
    {
        // bool flag=true;
        for (int j = 0; j < n; j++)
        {
            if(v[j]==i){
                // flag=false;
                break;
            }
            if(v[j]>i){
                ans.push_back({v[j],i});
            }
            else if(v[j]<i){
                ans.push_back({i,v[j]});
                ans.push_back({v[j],i});
            }
        }
        
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

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

Code 1:
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>arr(n+1,0);
	vector<int>brr(n);
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;
		for(int j=1;j<brr[i];j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}

}

	for(int i=0;i<=n;i++){
		arr[i]=0;
	}

	cout<<cnt<<endl;

	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;

		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cout<<j<<" "<<brr[i]<<endl;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
		for(int j=1;j<brr[i];j++){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
	}

}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>arr(n+1,0);
	vector<int>brr(n);
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;
		for(int j=1;j<brr[i];j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}

}

	for(int i=0;i<=n;i++){
		arr[i]=0;
	}

	cout<<cnt<<endl;

	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;

		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cout<<j<<" "<<brr[i]<<endl;
			}
		}
		for(int j=n;j>=brr[i];j--){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
		for(int j=brr[i]-1;j>0;j--){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
	}

}

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

Code 1:
#include<bits/stdc++.h>
using namespace std;
const int N=230000;
int n,a[N],ans,vis[N];
struct fa{
	int x,y;
}as[N*2];
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};
//		for(int j=a[i]-1;j>=1;j--)if(!vis[j])as[++ans]={a[i],j};
	}
//	sort(as+1,as+ans+1);
	cout<<ans<<endl;
	for(int i=1;i<=ans;i++){
		cout<<as[i].x<<' '<<as[i].y<<endl;
	}
	return 0;
}

Code 2:
#include<bits/stdc++.h>
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};
//		for(int j=a[i]-1;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: python

Code 1:
import sys
from queue import deque
from bisect import bisect_left, bisect_right
from heapq import *
from collections import *

sys.setrecursionlimit(10**5)

input = lambda: sys.stdin.readline().rstrip('\r\n')
iint = lambda: int(input())
mint = lambda: map(int, input().split())
aint = lambda: list(map(int, input().split()))

MOD = 10**9 + 7

def solve():
    n = iint()
    a = aint()
    rank = [0] * (n + 1)
    for i in range(n):
        rank[a[i]] = i+1
   
    mx_len = n * (n-1) // 2
    curr = list(range(n, 0, -1))
    sq = []
    for i in range(n):
        j = i
        while j>0 and rank[curr[j]] < rank[curr[j-1]]:
            sq.append([curr[j], curr[j-1]])
            curr[j], curr[j-1] = curr[j-1], curr[j]
            mx_len += 1
            j -= 1

    print(mx_len)
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            print(j, i)
    for a, b in sq:
        print(a, b)

solve()

Code 2:
import sys
from queue import deque
from bisect import bisect_left, bisect_right
from heapq import *
from collections import *

sys.setrecursionlimit(10**5)

input = lambda: sys.stdin.readline().rstrip('\r\n')
iint = lambda: int(input())
mint = lambda: map(int, input().split())
aint = lambda: list(map(int, input().split()))

MOD = 10**9 + 7

def solve():
    n = iint()
    a = aint()
    rank = [0] * (n + 1)
    for i in range(n):
        rank[a[i]] = i+1
   
    mx_len = n * (n-1) // 2
    curr = list(range(n, 0, -1))
    sq = []
    for i in range(n-1, -1, -1):
        j = i
        while j>0 and rank[curr[j]] < rank[curr[j-1]]:
            sq.append([curr[j], curr[j-1]])
            curr[j], curr[j-1] = curr[j-1], curr[j]
            mx_len += 1
            j -= 1

    print(mx_len)
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            print(j, i)
    for a, b in sq:
        print(a, b)

solve()

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

Code 1:
#include<bits/stdc++.h>
#include<stdio.h> 
#include<chrono>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds ; 
using ll = long long ;  
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds ; 
ll inf = (4e18L) + 100 ;
ll ninf = (-4e18L) - 100 ;
const ll mod = 1e9 + 7 ; // 998244353; 
const int MAXN = 2e5 + 100 ; 

void solve_test_case() 
{     
    int n ; 
    cin >> n ; 
    
    vector<int> arr(n+1) ; 
    
    for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; 
    vector<pair<int,int>> ans ;
    vector<bool> visited(n,false) ; 
    for(int j = n  ; j > 0 ; j--) 
    {
        int x = arr[j] ; 
        visited[x] = true ; 
        
        for(int i = x-1 ; i > 0 ; i--) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({x,i}) ;  
        }
        for(int i = 1 ; i <= x-1 ; i++) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({i,x}) ; 
        }
        
        for(int i = x+1 ; i <= n ; i++) 
        {
            if(visited[i] == true) continue ;
            ans.push_back({i,x}) ; 
        }
    }
    
    cout << (int)ans.size() << endl; 
    
    for(auto v : ans) 
    {
        cout << v.first << " " << v.second << endl ;
    }
}


int32_t main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    // init_code() ;
    ll t = 1 ; 
    // cin >> t;  
    while(t--) solve_test_case() ; 
    return 0 ; 
}


Code 2:
#include<bits/stdc++.h>
#include<stdio.h> 
#include<chrono>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds ; 
using ll = long long ;  
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds ; 
ll inf = (4e18L) + 100 ;
ll ninf = (-4e18L) - 100 ;
const ll mod = 1e9 + 7 ; // 998244353; 
const int MAXN = 2e5 + 100 ; 

void solve_test_case() 
{     
    int n ; 
    cin >> n ; 
    
    vector<int> arr(n+1) ; 
    
    for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; 
    vector<pair<int,int>> ans ;
    vector<bool> visited(n+1,false) ; 
    for(int j = n  ; j > 0 ; j--) 
    {
        int x = arr[j] ; 
        visited[x] = true ; 
        
        for(int i = x-1 ; i > 0 ; i--) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({x,i}) ;  
        }
        for(int i = 1 ; i <= x-1 ; i++) 
        {
            if(visited[i] == true) continue ; 
            ans.push_back({i,x}) ; 
        }
        
        for(int i = x+1 ; i <= n ; i++) 
        {
            if(visited[i] == true) continue ;
            ans.push_back({i,x}) ; 
        }
        

    }
    
    cout << (int)ans.size() << endl; 
    
    for(auto v : ans) 
    {
        cout << v.first << " " << v.second << endl ;
    }
}


int32_t main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    // init_code() ;
    ll t = 1 ; 
    // cin >> t;  
    while(t--) solve_test_case() ; 
    return 0 ; 
}


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

Code 1:
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> val(n);
    for (int i = 0; i < n; i++)
    {
        cin >> val[i];
    }

    vector<pair<int, int>> ans;
    for (int i = 0; i < n; i++)
    {
        vector<pair<int, int>> v;
        vector<pair<int, int>> s;
        for (int j = i + 1; j < n; j++)
        {
            if (val[i] < val[j])
            {
                ans.push_back({val[j], val[i]});
                v.push_back({val[i], val[j]});
            }
            else
            {
                s.push_back({val[i], val[j]});
            }
        }
        reverse(v.begin(), v.end());
        for (int j = 0; j < v.size(); j++)
        {
            ans.push_back(v[j]);
        }

        for (int j = 0; j < s.size(); j++)
        {
            ans.push_back(s[j]);
        }
    }

    cout << ans.size() << endl;
    for (auto i : ans)
    {
        cout << i.first << " " << i.second << endl;
    }
    cout << endl;
}

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

Code 2:
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> val(n);
    for (int i = 0; i < n; i++)
    {
        cin >> val[i];
    }

    vector<pair<int, int>> ans;
    for (int i = 0; i < n; i++)
    {
        vector<pair<int, int>> v;
        vector<pair<int, int>> s;
        for (int j = i + 1; j < n; j++)
        {
            if (val[i] < val[j])
            {
                // ans.push_back({val[j], val[i]});
                v.push_back({val[i], val[j]});
            }
            else
            {
                s.push_back({val[i], val[j]});
            }
        }

        sort(v.begin(), v.end());
        for (int j = 0; j < v.size(); j++)
        {
            ans.push_back({v[j].second, v[j].first});
        }

        reverse(v.begin(), v.end());
        for (int j = 0; j < v.size(); j++)
        {
            ans.push_back(v[j]);
        }

        sort(s.begin(), s.end());
        reverse(s.begin(), s.end());
        for (int j = 0; j < s.size(); j++)
        {
            ans.push_back(s[j]);
        }
    }

    cout << ans.size() << endl;
    for (auto i : ans)
    {
        cout << i.first << " " << i.second << endl;
    }
    cout << endl;
}

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

Answer: 2