ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;

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

		sort(arr,arr+n);
		vector <int> count{1};
		for(int i=0;i<n-1;i++){
			if(arr[i]==arr[i+1]){
				count.back()++;
			}
			else{
				count.emplace_back(1);
			}
		}
		int size=count.size();
		for(int i=0;i<size-1;i++){
			if(count[i]>k){
				cout<<size-i<<"\n";
				break;
			}
			k-=count[i];
		}
		if(k>0)
		cout<<1<<"\n";
	

		



	}
}

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

void solve(){
	int n,k;
		cin>>n>>k;

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

		sort(arr,arr+n);
		vector <int> count{1};
		for(int i=0;i<n-1;i++){
			if(arr[i]==arr[i+1]){
				count.back()++;
			}
			else{
				count.emplace_back(1);
			}
		}
		sort(count.begin(),count.end());
		int size=count.size();
		for(int i=0;i<size-1;i++){
			if(count[i]>k){
				cout<<size-i<<"\n";
				return;
			}

			k-=count[i];
		}
		
		cout<<1<<"\n";
}

int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 8):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    int right;
    int left;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            right = s[j]-'0';
            left = s[j-1]-'0';
            if(right == 0){
                break;
            }
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}

Submission (verdict: Accepted):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    int right;
    int left;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            right = s[j]-'0';
            left = s[j-1]-'0';
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }else{
                break;
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 8):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            int right = s[j]-'0';
            int left = s[j-1]-'0';
            if(right == 0){
                break;
            }
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}

Submission (verdict: Time limit exceeded on test 8):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    int right;
    int left;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            right = s[j]-'0';
            left = s[j-1]-'0';
            if(right == 0){
                break;
            }
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            int right = s[j]-'0';
            int left = s[j-1]-'0';
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            int right = s[j]-'0';
            int left = s[j-1]-'0';
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}

Submission (verdict: Time limit exceeded on test 8):
#include<iostream>
using namespace std;
long long t;
string s;
void zad(){
    cin>>s;
    for(int i=1; i<s.size(); i++){
        for(int j=i; j>0; j--){
            int right = s[j]-'0';
            int left = s[j-1]-'0';
            if(right == 0){
                break;
            }
            if(right-1 > left){
                s[j-1] = (right-1)+'0';
                s[j] = left+'0';
            }
        }
    }
    cout<<s<<'\n';
}

int main(){
    cin>>t;
    for(long long i=0; i<t; i++){
        zad();
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

signed main()
{
	int t;
	cin >> t;
	string x;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = -1;
			}
		}
		cout << x << endl;
	}
	return 0;
}

Submission (verdict: Runtime error on test 1):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

signed main()
{
	int t;
	cin >> t;
	string x;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = i - 2;
			}
		}
		cout << x << endl;
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 1):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

string x;
signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = i - 2;
			}
		}
		cout << x << endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string x;
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				if(i>=1)  i = i - 2;
			}
		}
		cout << x << endl;
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 1):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

signed main()
{
	int t;
	cin >> t;
	string x;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = i - 2;
			}
		}
		cout << x << endl;
	}
	return 0;
}

Submission (verdict: Runtime error on test 1):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

string x;
signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = i - 2;
			}
		}
		cout << x << endl;
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 5):
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;

signed main()
{
	int t;
	cin >> t;
	string x;
	while (t--)
	{
		cin >> x;
		for (int i = 0; i < x.size() - 1; i++)
		{
			if (x[i] < x[i + 1] - 1)
			{
				swap(x[i], x[i + 1]);
				x[i]--;
				i = -1;
			}
		}
		cout << x << endl;
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: Python 3

Previous submission (verdict: Wrong answer on test 2):
t = int(input())
for i in range(t):
        n = input()
        if int(n)%9 == 0:
                print('yes')
                continue
        tw = n.count('2')
        th = n.count('3')
        n = int(n)
        tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
        if tn-tw > 0 and (tw < (tn)%3 or ((tn-tw)+(tn-tw)%3)/3 > th):
                print('no')
        else:
                print('yes')

Submission (verdict: Wrong answer on test 1):
t = int(input())
for i in range(t):
	n = input()
	if int(n)%9 == 0:
		print('yes')
		continue	
	tw = n.count('2')
	th = n.count('3')
	n = int(n)
	tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
	d = tn - tw
	if d > 0 and ((tw < 3-d%3 or (d+3-d%3)/3 > th) or (d%3==0 and d/3 > th)):
		print('no')
	else:
		print('yes')
Problem: 2050C - Uninteresting Number
Language: Python 3


Submission (verdict: Wrong answer on test 2):
t = int(input())
for i in range(t):
        n = input()
        if int(n)%9 == 0:
                print('yes')
                continue
        tw = n.count('2')
        th = n.count('3')
        n = int(n)
        tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
        if tn-tw > 0 and (tw < (tn)%3 or ((tn-tw)+(tn-tw)%3)/3 > th):
                print('no')
        else:
                print('yes')
Problem: 2050C - Uninteresting Number
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t = int(input())
for i in range(t):
	n = input()
	if int(n)%9 == 0:
		print('yes')
		continue	
	tw = n.count('2')
	th = n.count('3')
	n = int(n)
	tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
	d = tn - tw
	if d > 0 and ((tw < 3-d%3 or (d+3-d%3)/3 > th) or (d%3==0 and d/3 > th)):
		print('no')
	else:
		print('yes')
	


Submission (verdict: Accepted):
t = int(input())
for i in range(t):
	n = input()
	if int(n)%9 == 0:
		print('yes')
		continue	
	tw = n.count('2')
	th = n.count('3')
	n = int(n)
	tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
	d = tn - tw
	if d > 0 and ((d%3!=0 and (tw<3-d%3 or (d+3-d%3)/3 > th)) or (d%3==0 and d/3 > th)):
		print('no')
	else:
		print('yes')
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#ifdef local
    #include "/home/enzo/Documents/Prog/OBItraining/debug.h"
    #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__)
    #define prs(...) debug_nameless(__VA_ARGS__)
#else
    #define pr(...) 69
    #define prs(...) 69
#endif
typedef long long ll;


void solve(){

    int n; cin >> n;
    vector<int> grafo(n+1);

    vector<pair<int,int>> edges;
    for(int i = 0; i < n-1; i++){
        int a,b; cin >> a >> b;
        edges.push_back({a,b});
        grafo[a]++, grafo[b]++;
    }   

    int ans = 1;
    int id = max_element(grafo.begin(), grafo.end()) - grafo.begin();
    ans += grafo[id]-1;
    fill(grafo.begin(), grafo.end(), 0);

    for(int i = 0; i < n-1; i++){
        auto [a,b] = edges[i];
        if(a == id || b == id) continue;
        grafo[a]++;
        grafo[b]++;
    }

    id = max_element(grafo.begin(), grafo.end()) - grafo.begin();
    ans += grafo[id]-1;

    cout << ans << '\n';

}


int main(){
    cin.tie(0), ios_base::sync_with_stdio(false);

    int t; cin >> t;
    while(t--) solve();

}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#ifdef local
    #include "/home/enzo/Documents/Prog/OBItraining/debug.h"
    #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__)
    #define prs(...) debug_nameless(__VA_ARGS__)
#else
    #define pr(...) 69
    #define prs(...) 69
#endif
typedef long long ll;


void solve(){

    int n; cin >> n;
    vector<int> grafo(n+1);

    vector<pair<int,int>> edges;
    for(int i = 0; i < n-1; i++){
        int a,b; cin >> a >> b;
        edges.push_back({a,b});
        grafo[a]++, grafo[b]++;
    }   

    int ans = 1;
    int id = max_element(grafo.begin(), grafo.end()) - grafo.begin();
    ans += grafo[id]-1;
    fill(grafo.begin(), grafo.end(), 0);

    for(int i = 0; i < n-1; i++){
        auto [a,b] = edges[i];
        if(a == id || b == id) continue;
        grafo[a]++;
        grafo[b]++;
    }

    id = max_element(grafo.begin(), grafo.end()) - grafo.begin();
    ans += grafo[id]-1;

    cout << ans << '\n';

}


int main(){
    cin.tie(0), ios_base::sync_with_stdio(false);

    int t; cin >> t;
    while(t--) solve();

}   

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#ifdef local
    #include "/home/enzo/Documents/Prog/OBItraining/debug.h"
    #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__)
    #define prs(...) debug_nameless(__VA_ARGS__)
#else
    #define pr(...) 69
    #define prs(...) 69
#endif
typedef long long ll;


void solve(){

    int n; cin >> n;
    vector<int> out(n+1);
    vector<vector<int>> grafo(n+1);
    vector<pair<int,int>> edges;
    for(int i = 0; i < n-1; i++){
        int a,b; cin >> a >> b;
        edges.push_back({a,b});
        out[a]++, out[b]++;
        grafo[a].push_back(b);
        grafo[b].push_back(a);
    }   

    int ans = 0;
    for(int i = 1; i <= n; i++){
        int cur = 1;  
        
        for(auto a : grafo[i]) out[a]--;
        cur += (out[i]-1);
        out[i] = 0;
        
        cur += (*max_element(out.begin(), out.end()) - 1);
        for(auto a : grafo[i]) out[a]++;
        out[i] = grafo[i].size();

        ans = max(ans, cur);
    }   

    cout << ans << '\n';

}


int main(){
    cin.tie(0), ios_base::sync_with_stdio(false);

    int t; cin >> t;
    while(t--) solve();

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using i80 = __int128;
using i64 = long long;
using f80 = long double;
void work() {
    i64 l, r;
    std::cin >> l >> r;
    if (r - l == 2) {
        std::cout << l << " " << l + 1 << " " << r << "\n";
        return;
    }
    i64 pre = 0;
    for (i64 k = 30; k; --k) {
        pre += (l & (1ll << k));
        if ((l & (1ll << k)) < (r & (1ll << k))) {
            if (l - pre + 1 == 1ll << k) {
                // std::cerr << l << "?";
                ++l;
                pre += (1ll << k);
                continue;
            }
            // std::cout << l << "," << pre << "\n";
            i64 a = pre, b = pre, c = pre + (1ll << k);
            for (i64 p = k - 1; p >= 0; --p) {
                a += (1ll << p);
                if ((l & (1ll << p))) {
                    b += (1ll << p);
                }
            }
            std::cout << a << " " << b << " " << c << "\n";
            return;
        }
    }
    return;
}
void init() {
}
int main() {
    init();
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr), std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) {
        work();
    }
    return 0;
}
/*


*/


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using i80 = __int128;
using i64 = long long;
using f80 = long double;
int make(int a, int b, int c) {
    return (a ^ b) + (b ^ c) + (a ^ c);
}
void work() {
    i64 l, r;
    std::cin >> l >> r;
    if (r - l == 2) {
        std::cout << l << " " << l + 1 << " " << r << "\n";
        return;
    }
    i64 pre = 0;
    for (i64 k = 30; k; --k) {
        pre += (l & (1ll << k));
        if ((l & (1ll << k)) < (r & (1ll << k))) {
            if (l - pre + 1 == 1ll << k) {
                std::cout << l << " " << l + 1 << " " << l + 2 << "\n";
                return;
            }
            i64 a = pre, b = pre, c = pre + (1ll << k);
            for (i64 p = k - 1; p >= 0; --p) {
                a += (1ll << p);
                if ((l & (1ll << p))) {
                    b += (1ll << p);
                }
            }
            std::cout << a << " " << b << " " << c << "\n";
            return;
        }
    }
    return;
}
void init() {
}
int main() {
    init();
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr), std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) {
        work();
    }
    return 0;
}
/*


*/
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using i80 = __int128;
using i64 = long long;
using f80 = long double;

void work() {
    i64 l, r;
    std::cin >> l >> r;
    if (r - l == 2) {
        std::cout << l << " " << l + 1 << " " << r << "\n";
        return;
    }
    if (l + 1 == 1 << (std::__lg(l) + 1)) {
        ++l;
    }
    int pre = 0;
    for (int k = 29; k; --k) {
        if ((l & (1 << k)) < (r & (1 << k))) {
            int a = pre, b = pre, c = pre + (1 << k);
            for (int p = k - 1; p >= 0; --p) {
                a += (1 << p);
                if ((l & (1 << p))) {
                    b += (1 << p);
                }
            }
            std::cout << a << " " << b << " " << c << "\n";
            return;
        } else {
            pre += (l & (1 << k));
        }
    }

    return;
}
void init() {
}
int main() {
    init();
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr), std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) {
        work();
    }
    return 0;
}
/*


*/


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using i80 = __int128;
using i64 = long long;
using f80 = long double;
void work() {
    i64 l, r;
    std::cin >> l >> r;
    if (r - l == 2) {
        std::cout << l << " " << l + 1 << " " << r << "\n";
        return;
    }
    i64 pre = 0;
    for (i64 k = 30; k; --k) {
        pre += (l & (1ll << k));
        if ((l & (1ll << k)) < (r & (1ll << k))) {
            if (l - pre + 1 == 1ll << k) {
                // std::cerr << l << "?";
                ++l;
                pre += (1ll << k);
                continue;
            }
            // std::cout << l << "," << pre << "\n";
            i64 a = pre, b = pre, c = pre + (1ll << k);
            for (i64 p = k - 1; p >= 0; --p) {
                a += (1ll << p);
                if ((l & (1ll << p))) {
                    b += (1ll << p);
                }
            }
            std::cout << a << " " << b << " " << c << "\n";
            return;
        }
    }
    return;
}
void init() {
}
int main() {
    init();
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr), std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) {
        work();
    }
    return 0;
}
/*


*/
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using i80 = __int128;
using i64 = long long;
using f80 = long double;

void work() {
    i64 l, r;
    std::cin >> l >> r;
    if (r - l == 2) {
        std::cout << l << " " << l + 1 << " " << r << "\n";
        return;
    }
    if (l + 1 == 1 << (std::__lg(l) + 1)) {
        ++l;
    }
    int pre = 0;
    for (int k = 29; k; --k) {
        if ((l & (1 << k)) < (r & (1 << k))) {
            int a = pre, b = pre, c = pre + (1 << k);
            for (int p = k - 1; p >= 0; --p) {
                a += (1 << p);
                if ((l & (1 << p))) {
                    b += (1 << p);
                }
            }
            std::cout << a << " " << b << " " << c << "\n";
            return;
        } else {
            pre += (l & (1 << k));
        }
    }

    return;
}
void init() {
}
int main() {
    init();
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr), std::cout.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) {
        work();
    }
    return 0;
}
/*


*/
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 4):
import math
mod=1000000007
mod1=998244353
inf=10**18+10
t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))
    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j
    # print(ind)

    ans=[]
    for j in range(1, j+1):
        ci=ind[j]
        for k in range(1, n+1):
            if j==k:
                continue
            if k>j and ind[k]<ci:
                ans.append([k,j])
            elif k>j and ind[k]>ci:
                ans.append([k,j])
                ans.append([j,k])
    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
import math
mod=1000000007
mod1=998244353
inf=10**18+10

def swap(l1,x,y):
    a=l1[x]
    l1[x]=l1[y]
    l1[y]=a

t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))
    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j

    l2=[j+1 for j in range(n)]
    st=set()

    ans=[]
    flag=1
    while flag:
        flag=0
        x=-1
        y=-1
        for j in range(n-1):
            if ind[l2[j+1]]<ind[l2[j]] and flag==0 and (l2[j], l2[j+1]) not in st:
                flag=1
                x,y=j, j+1
            if ind[l2[j+1]]>ind[l2[j]]:
                if (l2[j], l2[j+1]) not in st:
                    ans.append([l2[j+1],l2[j]])
                    ans.append([l2[j],l2[j+1]])
                    st.add((l2[j+1],l2[j]))
                    st.add((l2[j],l2[j+1]))

        if x!=-1:
            ans.append([l2[y], l2[x]])
            st.add((l2[y], l2[x]))
            # print(l2, ans)
            swap(l2, x, y)

    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)

Submission (verdict: Accepted):
import math
mod=1000000007
mod1=998244353
inf=10**18+10

def swap(l1,x,y):
    a=l1[x]
    l1[x]=l1[y]
    l1[y]=a

t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))

    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j

    l2=[j+1 for j in range(n)]
    st=set()

    ans=[]
    flag=1
    # print(l1)
    while flag:
        flag=0
        x=-1
        y=-1
        for j in range(n):
            for j1 in range(n-1):
                if l1[j1]<l1[j1+1]:
                    ans.append([l1[j1], l1[j1+1]])
                    swap(l1, j1, j1+1)
                if ind[l2[j1+1]]<ind[l2[j1]] and flag==0 and (l2[j1], l2[j1+1]) not in st:
                    # flag=1
                    x,y=j1, j1+1
                if ind[l2[j1+1]]>ind[l2[j1]]:
                    if (l2[j1], l2[j1+1]) not in st:
                        st.add((l2[j1+1],l2[j1]))
                        st.add((l2[j1],l2[j1+1]))
        # print(l1)
        for j in range(n):
            for j1 in range(n-1-j):
                if l1[j1]>l1[j1+1]:
                    ans.append([l1[j1], l1[j1+1]])
                    swap(l1, j1+1, j1)
        ans.reverse()
        if x!=-1:
            st.add((l2[y], l2[x]))
            # print(l2, ans)
            swap(l2, x, y)

    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)