ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

string s;

cin>>s;

int n=s.size();

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

int num=s[i]-'0',ind=0;

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

if(s[j]-'0'&&s[j]-'0'-(j-i)>num){num=s[j]-'0'-(j-i);ind=j;}

}

if(ind!=0){

for(int j=ind;j>i;j--)s[j]=s[j-1];

s[i]='0'+num;

}

}

cout<<s<<"\n";

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) {

solve();

}

return 0;

}



Submission (verdict: Accepted):
#include <iostream>

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

string s;

cin>>s;

int n=s.size();

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

int num=s[i]-'0',ind=0;

for(int j=i+1;j<min(n,i+9);j++){

if(s[j]-'0'&&s[j]-'0'-(j-i)>num){num=s[j]-'0'-(j-i);ind=j;}

}

if(ind!=0){

for(int j=ind;j>i;j--)s[j]=s[j-1];

s[i]='0'+num;

}

}

cout<<s<<"\n";

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) {

solve();

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

string s;

cin>>s;

int n=s.size();

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

int num=s[i]-'0',ind=0;

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

if(s[i]-'0'&&s[j]-'0'-(j-i)>num){num=s[j]-'0'-(j-i);ind=j;}

}

if(ind!=0){

for(int j=ind;j>i;j--)s[j]=s[j-1];

s[i]='0'+num;

}

}

cout<<s<<"\n";

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) {

solve();

}

return 0;

}



Submission (verdict: Time limit exceeded on test 6):
#include <iostream>

#include<bits/stdc++.h>

#define ll long long

using namespace std;

void solve() {

string s;

cin>>s;

int n=s.size();

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

int num=s[i]-'0',ind=0;

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

if(s[j]-'0'&&s[j]-'0'-(j-i)>num){num=s[j]-'0'-(j-i);ind=j;}

}

if(ind!=0){

for(int j=ind;j>i;j--)s[j]=s[j-1];

s[i]='0'+num;

}

}

cout<<s<<"\n";

}

int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) {

solve();

}

return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
using namespace std;
auto compare = [](const pair<int, int>& a, const pair<int, int>& b) {
    return a.second > b.second;
    };
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>umap;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        umap[num]++;
    }   
    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(compare)> pq(compare);
    for(auto const&pairs:umap){
        pq.push(make_pair(pairs.first,pairs.second));
    }
    while(k>0&&pq.size()>0){
        auto top = pq.top();
        pq.pop();
        if(k>=top.second){
            k-=top.second;
        }
        else{
            pq.push(top);
            break;
        }
    }
    if(pq.size()!=0)
        cout<<pq.size()<<"\n";
    else
        cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){      
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
using namespace std;
auto compare = [](const pair<int, int>& a, const pair<int, int>& b) {
    return a.second < b.second;
    };
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>umap;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        umap[num]++;
    }   
    vector<pair<int,int>>pq;
    for(auto const&pairs:umap){
        pq.push_back(make_pair(pairs.first,pairs.second));
    }
    sort(pq.begin(),pq.end(),compare);
    int i=0;
    while(k>0&&pq.size()>0){
        auto top = pq[i];
        if(k>=top.second){
            k-=top.second;
            pq[i++].second=0;
        }
        else{
            break;
        }
    }
    int account=0;
    for(int j=0;j<pq.size();j++){
        if(pq[j].second!=0){
            account++;
        }
    }
    if(account!=0)
        cout<<account<<"\n";
    else
        cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){      
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
using namespace std;
auto compare = [](const pair<int, int>& a, const pair<int, int>& b) {
    return a.second < b.second;
    };
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>umap;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        umap[num]++;
    }   
    vector<pair<int,int>>pq;
    for(auto const&pairs:umap){
        pq.push_back(make_pair(pairs.first,pairs.second));
    }
    sort(pq.begin(),pq.end(),compare);
    int i=0;
    while(k>0&&pq.size()>0){
        auto top = pq[i];
        if(k>=top.second){
            k-=top.second;
            pq[i++].second=0;
        }
        else{
            break;
        }
    }
    int account=0;
    for(int j=0;j<pq.size();j++){
        if(pq[j].second!=0){
            account++;
        }
    }
    if(account!=0)
        cout<<account<<"\n";
    else
        cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){      
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> nums(n,0);
    for(int i=0;i<n;i++){
        cin>>nums[i];
    }
    sort(nums.begin(),nums.end());
    vector<int>sum={1};
    for(int i=1;i<n;i++){
        if(nums[i]==nums[i-1]){
            sum.back()++;
        }
        else{
            sum.push_back(1);
        }
    }
    sort(sum.begin(),sum.end());
    for(int i=0;i<sum.size();i++){
        if(k<sum[i]){
            cout<<sum.size()-i<<"\n";
            return;
        }
        k-=sum[i];
    }
    cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){      
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
using namespace std;
auto compare = [](const pair<int, int>& a, const pair<int, int>& b) {
    return a.second > b.second;
    };
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>umap;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        umap[num]++;
    }   
    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(compare)> pq(compare);
    for(auto const&pairs:umap){
        pq.push(make_pair(pairs.first,pairs.second));
    }
    while(k>0&&pq.size()>0){
        auto top = pq.top();
        pq.pop();
        if(k>=top.second){
            k-=top.second;
        }
        else{
            pq.push(top);
            break;
        }
    }
    if(pq.size()!=0)
        cout<<pq.size()<<"\n";
    else
        cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){      
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

#define       forn(i, n)             for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
#define            pb                push_back
#define            vi                vector<int>
#define            vvi               vector<vector<int>>
#define            vll               vector<ll>
#define            vvll              vector<vector<ll>>
#define            ll                long long
// #define int long long
void lilAref()
{
 cin.tie(0);
 cout.tie(0);
 ios_base::sync_with_stdio(false);
}

ll modProd(ll a, ll b, ll mod)
{
    if (a < 0)
        a += mod;
    if (b < 0)
        b += mod;
    a *= b;
    if (a >= mod)
        a %= mod;
    return a;
}

ll modPow(int a, ll b,ll mod) {
    int result = 1;
    while (b) {
        if (b & 1)
            result = modProd(result, a,mod);
        a = modProd(a, a,mod);
        b >>= 1;
    }
    return result;
}

vector<ll> divisors(ll n) {
    vector<ll>divis;
    for (ll i = 1;i * i <= n;i++) {
        if (n % i == 0) {
            divis.push_back(i);
            if (n != i * i)divis.push_back(n / i);
        }
    }
    return divis;
}

signed main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    lilAref();
    int tt;cin>>tt;
    while (tt--) {
        int n,l,r;cin>>n>>l>>r;
        vector<int>vec(n);
        for (auto &it:vec)cin>>it;
        sort(all(vec));
        int cnt = r-l+1;
        int tot=0;
        for (int i{};i<cnt;i++) {
            tot+=vec[i];
        }
        cout<<tot<<endl;
    }

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
using ll = long long;
ll a[N],b[N];
void solve()
{
    int n ,l ,r;
    cin >> n>> l>>r;
    for(int i = 1 ;i<=n ;i++)
    {
        cin >> a[i];
        b[i]=a[i];
    }
    ll ansl=0 ,ansr=0;
    sort(a+1 ,a+r);
    sort(b+l ,b+n+1);

    for(int i = 1 ,cnt = 0;i<=r && cnt < r-l+1 ;i++)
    {
        ansl+=a[i],cnt++;
    }
    for(int i = l ,cnt = 0;i<=n && cnt < r-l+1 ; i++)
    {
        ansr += b[i],cnt++;
    }

    cout << min(ansl , ansr) << endl;

}

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

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
using ll = long long;
ll a[N],b[N];
void solve()
{
    int n ,l ,r;
    cin >> n>> l>>r;
    for(int i = 1 ;i<=n ;i++)
    {
        cin >> a[i];
        b[i]=a[i];
    }
    ll ansl=0 ,ansr=0;
    sort(a+1 ,a+r+1);
    sort(b+l ,b+n+1);

    for(int i = 1 ,cnt = 0;i<=r && cnt < r-l+1 ;i++)
    {
        ansl+=a[i],cnt++;
    }
    for(int i = l ,cnt = 0;i<=n && cnt < r-l+1 ; i++)
    {
        ansr+=b[i],cnt++;
    }

    cout << min(ansl , ansr) << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
using ll = long long;
ll a[N];

void solve()
{
    int n ,l ,r;
    cin >> n>> l>>r;
    for(int i = 0 ;i<n ;i++)
    {
        cin >> a[i];
    }
    sort(a ,a+n);
    ll sum =0;
    for(int i = 0; i<r-l+1 ;i++)
    {
        sum+=a[i];
    }
    cout << sum << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

#define N 100005

using namespace std;

using ll = long long;

struct node{

    ll data;

    int tag;

};

bool cmp(const node a, const node b)

{

    return  a.data < b.data;

}

node a[N];



node findmin(const node a[], int size) {

    node mx = {-1,-1};

    for (int i = 1; i <= size; i++)

        if (a[i].data < mx.data && a[i].tag != 2)

            mx = a[i];

    return mx;

}

void solve()

{

    int n ,l ,r;

    cin >> n>> l>>r;

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

    {

        cin >> a[i].data;

        if(i<l)

            a[i].tag = 0;

        else if(i > r)

            a[i].tag = 1;

        else

            a[i].tag = 2;

    }

    sort(a+1, a+n+1,cmp);

    int dir=-1,j=1;

    while(dir == -1)

    {

        if(a[j].tag!=2)

            dir=a[j].tag;

        j++;

    }



    ll sum = 0 ,cnt = 0;

    for(int i = 1 ;i <= n && cnt<=r - l ;i++)

    {

        if(a[i].tag == dir || a[i].tag == 2)

            sum += a[i].data,cnt++;

    }

    cout << sum << endl;

}



int main()

{

    int t;

    cin >> t;

    while (t--)

        solve();

    return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
using ll = long long;
ll a[N],b[N];
void solve()
{
    int n ,l ,r;
    cin >> n>> l>>r;
    for(int i = 1 ;i<=n ;i++)
    {
        cin >> a[i];
        b[i]=a[i];
    }
    ll ansl=0 ,ansr=0;
    sort(a+1 ,a+r);
    sort(b+l ,b+n+1);

    for(int i = 1 ,cnt = 0;i<=r && cnt < r-l+1 ;i++)
    {
        ansl+=a[i],cnt++;
    }
    for(int i = l ,cnt = 0;i<=n && cnt < r-l+1 ; i++)
    {
        ansr += b[i],cnt++;
    }

    cout << min(ansl , ansr) << endl;

}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
using ll = long long;
ll a[N];

void solve()
{
    int n ,l ,r;
    cin >> n>> l>>r;
    for(int i = 0 ;i<n ;i++)
    {
        cin >> a[i];
    }
    sort(a ,a+n);
    ll sum =0;
    for(int i = 0; i<r-l+1 ;i++)
    {
        sum+=a[i];
    }
    cout << sum << endl;
}

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

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

#define N 100005

using namespace std;

using ll = long long;

struct node{

    ll data;

    int tag;

};

bool cmp(const node a, const node b)

{

    return  a.data < b.data;

}

node a[N];



node findmin(const node a[], int size) {

    node mx = {-1,-1};

    for (int i = 1; i <= size; i++)

        if (a[i].data < mx.data && a[i].tag != 2)

            mx = a[i];

    return mx;

}

void solve()

{

    int n ,l ,r;

    cin >> n>> l>>r;

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

    {

        cin >> a[i].data;

        if(i<l)

            a[i].tag = 0;

        else if(i > r)

            a[i].tag = 1;

        else

            a[i].tag = 2;

    }

    sort(a+1, a+n+1,cmp);

    int dir=-1,j=1;

    while(dir == -1)

    {

        if(a[j].tag!=2)

            dir=a[j].tag;

        j++;

    }



    ll sum = 0 ,cnt = 0;

    for(int i = 1 ;i <= n && cnt<=r - l ;i++)

    {

        if(a[i].tag == dir || a[i].tag == 2)

            sum += a[i].data,cnt++;

    }

    cout << sum << endl;

}



int main()

{

    int t;

    cin >> t;

    while (t--)

        solve();

    return 0;

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


Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <vector>
using namespace std;

void solve() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = i;
		if (a[i] >= i) {
			if (i == 1) ans += a[i] - i;
			else ans += a[i] - i + 2;
		}
	}
	for (int i = 1; i <= n; i++) {
		int j;
		if (i == 1) cout << ans << endl;
		for (j = a[i]; j >= i - 1 && j > 1; j--) {
			cout << b[j] << " " << b[j - 1] << endl;
			swap(b[j], b[j - 1]);
		}
		if (i > 1 && j >= i - 1) {
			cout << b[i] << " " << b[i - 1] << endl;
			swap(b[i], b[i - 1]);
		}
	}
}

int main()
{
	int 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 <iostream>
#include <vector>
using namespace std;

void solve() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		b[i] = i;
		cin >> a[i];
}
	vector<pair<int, int>> p;	
	for (int i = n; i >= 1; i--) {
		int flag = -1;
		for (int j = 1; j <= n; j++) {
			if (b[j] == a[i]) {
				flag = j;
				break;
			}
		}
		for (int j = flag; j > 1; j--) {
			p.push_back({ b[j - 1],b[j] });
			swap(b[j - 1], b[j]);
		}
	}
	cout << p.size() << endl;
	for (auto v : p) {
		cout << v.first << " " << v.second << endl;
	}
}

int main()
{
	int t = 1;
	while (t--)
		solve();

	return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
using namespace std;

void solve() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		b[i] = i;
		cin >> a[i];
}
	vector<pair<int, int>> p;	
	for (int i = n; i >= 1; i--) {
		int flag = -1;
		for (int j = 1; j <= n; j++) {
			if (b[j] == a[i]) {
				flag = j;
				break;
			}
		}
		for (int j = flag; j > 1; j--) {
			p.push_back({ b[j],b[j - 1] });
			swap(b[j], b[j - 1]);
		}
	}
	cout << p.size() << endl;
	for (auto v : p) {
		cout << v.first << " " << v.second << endl;
	}
}

int main()
{
	int 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 <iostream>
#include <vector>
using namespace std;

void solve() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = i;
		if (a[i] >= i) {
			if (i == 1) ans += a[i] - i;
			else ans += a[i] - i + 2;
		}
	}
	for (int i = 1; i <= n; i++) {
		int j;
		if (i == 1) cout << ans << endl;
		for (j = a[i]; j >= i - 1 && j > 1; j--) {
			cout << b[j] << " " << b[j - 1] << endl;
			swap(b[j], b[j - 1]);
		}
		if (i > 1 && j >= i - 1) {
			cout << b[i] << " " << b[i - 1] << endl;
			swap(b[i], b[i - 1]);
		}
	}
}

int main()
{
	int t = 1;
	while (t--)
		solve();

	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
using namespace std;

void solve() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		b[i] = i;
		cin >> a[i];
}
	vector<pair<int, int>> p;	
	for (int i = n; i >= 1; i--) {
		int flag = -1;
		for (int j = 1; j <= n; j++) {
			if (b[j] == a[i]) {
				flag = j;
				break;
			}
		}
		for (int j = flag; j > 1; j--) {
			p.push_back({ b[j - 1],b[j] });
			swap(b[j - 1], b[j]);
		}
	}
	cout << p.size() << endl;
	for (auto v : p) {
		cout << v.first << " " << v.second << endl;
	}
}

int main()
{
	int t = 1;
	while (t--)
		solve();

	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: Python 3


Submission (verdict: Time limit exceeded on test 42):
n = int(input())
firs = [_ for _ in range(1, n+1)]     #1 2 3 4
fina = list(map(int, input().split()))#2 1 4 3
fina.reverse()
reve = fina.copy()  #第一轮超车后的排序 # 3 4 1 2
fina.reverse()
ans = [] #已经排好的数组
res = [] #超车数组
count = 0
for i in range(n):  #2 1 4 3
    for j in range(fina[i]+1, n+1):  #如果有大于他的，就超过他
        if j in ans:       #如果大于他的数已经排好了，就跳过他
            continue
        res.append((j,fina[i]))
        count += 1
    ans.append(fina[i])
for k in range(n-1, 0, -1): # 3 4 1 2
    for t in range(1, k+1):
        res.append((reve[k], reve[k-t]))
        count += 1
print(count)
for i in range(len(res)):
    print(res[i][0], res[i][1])
Problem: 2052A - Adrenaline Rush
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 42):
n = int(input())
firs = [_ for _ in range(1, n+1)]     #1 2 3 4
fina = list(map(int, input().split()))#2 1 4 3
fina.reverse()
reve = fina.copy()  #第一轮超车后的排序 # 3 4 1 2
fina.reverse()
ans = [] #已经排好的数组
res = [] #超车数组
count = 0
for i in range(n):  #2 1 4 3
    for j in range(fina[i]+1, n+1):  #如果有大于他的，就超过他
        if j in ans:       #如果大于他的数已经排好了，就跳过他
            continue
        res.append((j,fina[i]))
        count += 1
    ans.append(fina[i])
for k in range(n-1, 0, -1): # 3 4 1 2
    for t in range(1, k+1):
        res.append((reve[k], reve[k-t]))
        count += 1
print(count)
for i in range(len(res)):
    print(res[i][0], res[i][1])

Submission (verdict: Time limit exceeded on test 43):
def count(li):
    su = 0
    for i in range(len(li)-1, 0, -1):
        for j in range(i):
            if li[j] > li[i]:
                su += 1
            else:
                su += 2
    return su


n = int(input())
firs = [_ for _ in range(1, n+1)]     #1 2 3 4
fina = list(map(int, input().split()))#2 1 4 3
fina.reverse()
reve = fina.copy()  #第一轮超车后的排序 # 3 4 1 2
fina.reverse()
ans = [] #已经排好的数组
print(count(fina))

for i in range(n):  #2 1 4 3
    for j in range(fina[i]+1, n+1):  #如果有大于他的，就超过他
        if j in ans:       #如果大于他的数已经排好了，就跳过他
            continue
        print(j,fina[i])

    ans.append(fina[i])
for k in range(n-1, 0, -1): # 3 4 1 2
    for t in range(1, k+1):
        print(reve[k], reve[k-t])
Problem: 2052A - Adrenaline Rush
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 43):
def count(li):
    su = 0
    for i in range(len(li)-1, 0, -1):
        for j in range(i):
            if li[j] > li[i]:
                su += 1
            else:
                su += 2
    return su


n = int(input())
firs = [_ for _ in range(1, n+1)]     #1 2 3 4
fina = list(map(int, input().split()))#2 1 4 3
fina.reverse()
reve = fina.copy()  #第一轮超车后的排序 # 3 4 1 2
fina.reverse()
ans = [] #已经排好的数组
print(count(fina))

for i in range(n):  #2 1 4 3
    for j in range(fina[i]+1, n+1):  #如果有大于他的，就超过他
        if j in ans:       #如果大于他的数已经排好了，就跳过他
            continue
        print(j,fina[i])

    ans.append(fina[i])
for k in range(n-1, 0, -1): # 3 4 1 2
    for t in range(1, k+1):
        print(reve[k], reve[k-t])

Submission (verdict: Accepted):
def count(li):
    su = 0
    for i in range(len(li)-1, 0, -1):
        for j in range(i):
            if li[j] > li[i]:
                su += 1
            else:
                su += 2
    return su


n = int(input())
firs = [_ for _ in range(1, n+1)]     #1 2 3 4
fina = list(map(int, input().split()))#2 1 4 3
fina.reverse()
reve = fina.copy()  #第一轮超车后的排序 # 3 4 1 2
fina.reverse()
ans = set() #已经排好的数组
print(count(fina))

for i in range(n):  #2 1 4 3
    for j in range(fina[i]+1, n+1):  #如果有大于他的，就超过他
        if j in ans:       #如果大于他的数已经排好了，就跳过他
            continue
        print(j,fina[i])

    ans.add(fina[i])
for k in range(n-1, 0, -1): # 3 4 1 2
    for t in range(1, k+1):
        print(reve[k], reve[k-t])