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

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++)
    {
        if(mp[j]<mp[i]) {ans.push_back({j,i}); }
        else {
            ans.push_back({j,i}); 
            ans.push_back({i,j}); 
        }
    }
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}

Submission (verdict: Wrong answer on test 7):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++)
    { ll ei=mp[i]; ll ej=mp[final[j]];
        if(mp[j]<mp[i]) {ans.push_back({j,i}); }
        else {
            ans.push_back({j,i}); 
            
        }
    }
    for(ll j=n;j>=i+1;j--)
    {
        if(mp[j]>mp[i]){ans.push_back({i,j});}
    }
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}
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 long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++)
    { ll ei=mp[i]; ll ej=mp[final[j]];
        if(mp[j]<mp[i]) {ans.push_back({j,i}); }
        else {
            ans.push_back({j,i}); 
            
        }
    }
    for(ll j=n;j>=i+1;j--)
    {
        if(mp[j]>mp[i]){ans.push_back({i,j});}
    }
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++) ans.push_back({j,i});
 }
 vector<ll>crr(n+1);
 for(ll i=n;i>=1;i--) crr[i]=n-i+1;
 while(true)
 { bool flag=false;
    for(ll i=1;i<=n-1;i++)
    {
        ll a=crr[i]; ll b=crr[i+1];
if((b<a && mp[a]>mp[b]) ) {flag=true; swap(crr[i],crr[i+1]); ans.push_back({b,a});}
    }
    if(!flag) break;
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 5):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;
void solve(vector<ll>&current,vector<ll>&final,vector<pair<ll,ll>>&ans,vector<vector<ll>>&done)
{
for(ll i=0;i<current.size()-1;i++)
{
    if(current[i]==final[i])
    {
        if(done[current[i]][current[i+1]]==0 && done[current[i+1]][current[i]]==0)
        {
            ans.push_back({current[i+1],current[i]});
            done[current[i+1]][current[i]]++;
            swap(current[i],current[i+1]);
solve(current,final,ans,done);
        }
    }
        else {
            ans.push_back({current[i+1],current[i]});
            done[current[i+1]][current[i]]++;
             swap(current[i],current[i+1]);
solve(current,final,ans,done);
        }
   
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n);
 for(ll i=0;i<n;i++) cin>>final[i];
 vector<pair<ll,ll>>ans;
 vector<ll>initial(n);
 for(ll i=0;i<n;i++) initial[i]=i+1;
 vector<vector<ll>>done(n+1,vector<ll>(n+1,0));
 solve(initial,final,ans,done);
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> qa, qb;
    ll sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty() && !qb.empty())
    {
        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qa.pop(), qb.pop();
        if(a < b){
            qa.push(a);
            while(!qa.empty())
            {
                auto t1 = qa.top();
                qa.pop();

                if(t1 == b) break;

                auto t2 = qa.top();
                qa.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qa.push(t1 + t2);
            }
        }else if(a > b){
            qb.push(b);
            while(!qb.empty())
            {
                auto t1 = qb.top();
                qb.pop();

                if(t1 == a) break;

                auto t2 = qb.top();
                qb.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qb.push(t1 + t2);
            }
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

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

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int> qa, qb;
    ll sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty())
    {
        if(qb.empty()) break;

        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qb.pop();

        if(b < a){
            cout << "NO" << endl;
            return;
        }
        if(b == a) qa.pop();
        else{
            qb.push(b / 2);
            qb.push((b + 1) / 2);
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 2):
#include <bits/stdc++.h>

// #define int long long
#define PII pair<int, int>
#define ll long long

using namespace std;

int T, n, m;

void solve()
{
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> qa, qb;
    int sa = 0, sb = 0;
    for(int i = 0, x;i < n;i ++){
        cin >> x;
        sa += x;
        qa.push(x);
    }
    for(int i = 0, x;i < m;i ++){
        cin >> x;
        sb += x;
        qb.push(x);
    }
    if(sa != sb){
        cout << "NO" << endl;
        return;
    }
    while(!qa.empty() && !qb.empty())
    {
        auto a = qa.top(), b = qb.top();
        // cout << a << " " << b << endl;
        qa.pop(), qb.pop();
        if(a < b){
            qa.push(a);
            while(!qa.empty())
            {
                auto t1 = qa.top();
                qa.pop();

                if(t1 == b) break;

                auto t2 = qa.top();
                qa.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qa.push(t1 + t2);
            }
        }else if(a > b){
            qb.push(b);
            while(!qb.empty())
            {
                auto t1 = qb.top();
                qb.pop();

                if(t1 == a) break;

                auto t2 = qb.top();
                qb.pop();
                if(t2 - t1 > 1){
                    cout << "NO" << endl;
                    return;
                }
                qb.push(t1 + t2);
            }
        }
    }
    if(qa.empty() && qb.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

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

			if (i==x||i==y){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				t^=1;

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<t<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		if (n%2==1){

			for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

			cout<<2<<" ";

		}

		else for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<i%2<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}

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

using namespace std;

const int N=505;

int t,n,x,y;

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		if (n%2==1){

			for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

			cout<<2<<" ";

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<i%2<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				t^=1;

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<t<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		if (n%2==1){

			for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

			cout<<2<<" ";

		}

		else for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				t^=1;

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<t<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		if (n%2==1){

			for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

			cout<<2<<" ";

		}

		else for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				t^=1;

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<t<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}

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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		if (n%2==1){

			for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

			cout<<2<<" ";

		}

		else for (int i=1;i<=n-1;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

		if (a%2==0){

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

				if (i==x){

					cout<<2<<" ";

					continue;

				}

				cout<<i%2<<" ";

			}	

		}

		else for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


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

using namespace std;

const int N=505;

int t,n,x,y;

int cha(int a,int b){

	if (a>b) swap(a,b);

	return min(b-a,a+n-b);

}

void solve(){

	cin>>n>>x>>y;

	if (x>y) swap(x,y);

	int a=y-x,b=x+n-y;

	if (a>b) swap(a,b);

	if (a==1){

		for (int i=1;i<=n;i++) cout<<i%2<<" ";

		cout<<'\n';

		return;

	}

	if (a%2==b%2){

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

			if (i==x||i==y){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

		return;

	}

	if (a%2!=b%2){

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

			if (i==x){

				cout<<2<<" ";

				continue;

			}

			t^=1;

			cout<<t<<" ";

		}

		cout<<'\n';

	}

}

int main(){

	cin>>t;

	while (t--) solve();

	return 0;

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


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

#define int long long
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair<int, int> pII;
typedef tuple<int, int, int> pIII;
#define x first
#define y second
#define all(x) x.begin(), x.end()
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f, base = 131;
int t, n, m, q, k;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
struct PII {
  int x, y;
  bool operator< (const PII &tmp) const {
    return x < tmp.x;
  }
};

void solve() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++ ) cin >> a[i];
  vector<pII> res;
  int cnt = 0;
  for (int i = 0; i < n; i ++ )
    for (int j = i + 1; j < n; j ++ )
      if (a[i] > a[j]) {
        res.push_back({a[i], a[j]});
      }
  for (int i = 0; i < n; i += 2) {
    if (i + 1 >= n) break;
    res.push_back({a[i], a[i + 1]});
    res.push_back({a[i + 1], a[i]});
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i ++ )
    cout << res[i].x << ' ' << res[i].y << '\n';
} 

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  // cin >> t;
  t = 1;
  while (t -- ) solve();
  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;

#define int long long
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair<int, int> pII;
typedef tuple<int, int, int> pIII;
#define x first
#define y second
#define all(x) x.begin(), x.end()
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f, base = 131;
int t, n, m, q, k;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
struct PII {
  int x, y;
  bool operator< (const PII &tmp) const {
    return x < tmp.x;
  }
};

void solve() {
  cin >> n;
  vector<int> a(n);
  map<int, int> pos;
  for (int i = 0; i < n; i ++ ) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  vector<pII> res;
  set<pII> st;
  vector<int> p(n);
  for (int i = 0; i < n; i ++ ) p[i] = i + 1;
  for (int j = 0; j < n; j ++ ) {
    for (int i = 0; i < n - 1; i ++ ) {
      int x = p[i + 1], y = p[i];
      if (x > y) swap(x, y);
      if (st.count({x, y})) continue;
      st.insert({x, y});
      res.push_back({p[i + 1], p[i]});
      if (pos[p[i]] > pos[p[i + 1]]) swap(p[i], p[i + 1]);
      else res.push_back({p[i], p[i + 1]});
    }
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i ++ )
    cout << res[i].x << ' ' << res[i].y << '\n';
} 

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  // cin >> t;
  t = 1;
  while (t -- ) solve();
  return 0;
}

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

#define int long long
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair<int, int> pII;
typedef tuple<int, int, int> pIII;
#define x first
#define y second
#define all(x) x.begin(), x.end()
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f, base = 131;
int t, n, m, q, k;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
struct PII {
  int x, y;
  bool operator< (const PII &tmp) const {
    return x < tmp.x;
  }
};

void solve() {
  cin >> n;
  vector<pII> res;
  vector<bool> st(n + 1);
  for (int i = 1; i <= n; i ++ ) {
    int x; cin >> x;
    st[x] = true;
    for (int j = x + 1; j <= n; j ++ )
      if (!st[j]) res.push_back({j, x});
    for (int j = n; j >= 1; j -- )
      if (!st[j]) res.push_back({x, j});
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i ++ )
    cout << res[i].x << ' ' << res[i].y << '\n';
} 

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  // cin >> t;
  t = 1;
  while (t -- ) solve();
  return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

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

#define int long long
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair<int, int> pII;
typedef tuple<int, int, int> pIII;
#define x first
#define y second
#define all(x) x.begin(), x.end()
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f, base = 131;
int t, n, m, q, k;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
struct PII {
  int x, y;
  bool operator< (const PII &tmp) const {
    return x < tmp.x;
  }
};

void solve() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++ ) cin >> a[i];
  vector<pII> res;
  int cnt = 0;
  for (int i = 0; i < n; i ++ )
    for (int j = i + 1; j < n; j ++ )
      if (a[i] > a[j]) {
        res.push_back({a[i], a[j]});
      }
  for (int i = 0; i < n; i += 2) {
    if (i + 1 >= n) break;
    res.push_back({a[i], a[i + 1]});
    res.push_back({a[i + 1], a[i]});
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i ++ )
    cout << res[i].x << ' ' << res[i].y << '\n';
} 

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  // cin >> t;
  t = 1;
  while (t -- ) solve();
  return 0;
}

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

#define int long long
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair<int, int> pII;
typedef tuple<int, int, int> pIII;
#define x first
#define y second
#define all(x) x.begin(), x.end()
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f, base = 131;
int t, n, m, q, k;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
struct PII {
  int x, y;
  bool operator< (const PII &tmp) const {
    return x < tmp.x;
  }
};

void solve() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++ ) cin >> a[i];
  vector<pII> res;
  int cnt = 0;
  for (int i = 0; i < n; i ++ )
    for (int j = i + 1; j < n; j ++ )
      if (a[i] > a[j]) {
        res.push_back({a[i], a[j]});
      }
  for (int i = 0; i < n; i += 2) {
    if (i + 1 >= n) break;
    res.push_back({a[i + 1], a[i]});
    res.push_back({a[i], a[i + 1]});
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i ++ )
    cout << res[i].x << ' ' << res[i].y << '\n';
} 

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  // cin >> t;
  t = 1;
  while (t -- ) solve();
  return 0;
}