ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using ll = long long;
using ull = unsigned long long;
 
const int MAXN = 2000001;
 
int n, m, i, j, l, r, x, a[MAXN];
 
void solve() {
    cin >> n;
    for (i=1; i<=n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] > a[2]) {
            cout << "NO" << endl;
        }
    }
    for (i=n; i>2; i--) {
        if (a[i] < a[i-1]) {
          x = min(a[i-1], a[i-2]);
          a[i-1] = a[i-2] -= x;
        }
    } 
    for (i=1; i<n; i++) {
        if (a[i] > a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
 
int main() {
    int t = 1; 
    cin >> t; 
    while (t--) solve(); return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using ll = long long;
using ull = unsigned long long;
 
const int MAXN = 2000001;
 
int n, m, i, j, l, r, x, a[MAXN];
 
void solve() {
    cin >> n;
    for (i=1; i<=n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] > a[2]) {
            cout << "NO" << endl;
            return;
        }
    }
    for (i=n; i>2; i--) {
        if (a[i] < a[i-1]) {
          x = min(a[i-1], a[i-2]);
          a[i-1] = a[i-2] -= x;
        }
    } 
    for (i=1; i<n; i++) {
        if (a[i] > a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
 
int main() {
    int t = 1; 
    cin >> t; 
    while (t--) solve(); return 0;
}

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

using ll = long long;
using ull = unsigned long long;
 
const int MAXN = 2000001;
 
int n, m, i, j, l, r, x, a[MAXN];
 
void solve() {
    cin >> n;
    for (i=1; i<=n; i++) cin >> a[i];
    if (n == 2) {
        if (a[1] > a[2]) {
            cout << "NO" << endl;
            return;
        }
    }
    x =  min(a[1], a[2]);
    a[1] -= x;
    a[2] -= x;
    for (i=1; i<=n-2; i++) {
        x = min(a[i+1], a[i+2]);
        if (a[i] <= a[i+1] - x) {
          a[i+1] -= x;
          a[i+2] -= x;
        }
    } 
    for (i=1; i<n; i++) {
        if (a[i] > a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
 
int main() {
    int t = 1; 
    cin >> t; 
    while (t--) solve(); return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

#define ll long long
#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    ll n;
    cin >> n;

    vector<ll> A(n);
    for (auto &a: A) {
        cin >> a;
    }

    bool yes = true;

    for (ll i = 1; ((i <= n - 1) && yes); ++i) {

        ll min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] < A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    ll tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}

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

#define ll long long
#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    ll n;
    cin >> n;

    ll max_n = 0;
    vector<ll> A(n);

    for (auto &a: A) {
        cin >> a;
        max_n = max(max_n, a);
    }

    A.push_back(max_n);

    bool yes = true;

    for (ll i = 1; ((i <= n) && yes); ++i) {

        ll min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] <= A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    ll tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    int n;
    cin >> n;

    vector<int> A(n);
    for (auto &a: A) {
        cin >> a;
    }

    bool yes = true;

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

        int min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] < A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    int tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    int n;
    cin >> n;

    vector<int> A(n);
    for (auto &a: A) {
        cin >> a;
    }

    bool yes = true;

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

        int min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] < A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    int tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}

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

#define ll long long
#define _RUN_MORE_THAN_ONCE
#define _FASTER_IO ios::sync_with_stdio(false); cin.tie(nullptr)

void SOLVE() {

    ll n;
    cin >> n;

    vector<ll> A(n);
    for (auto &a: A) {
        cin >> a;
    }

    bool yes = true;

    for (ll i = 1; ((i <= n - 1) && yes); ++i) {

        ll min_n = min(A[i - 1], A[i]);
        
        A[i] -= min_n;
        A[i - 1] -= min_n;

        if ((A[i - 1] > A[i]) && (A[i] < A[i + 1]) && (A[i] == 0)) {
            yes = false;
        }

    }

    cout << (yes ? "YES" : "NO") << '\n';

}

int main() {

    _FASTER_IO;

    ll tc;

    #ifndef _RUN_MORE_THAN_ONCE
        tc = 1;
    #else
        cin >> tc;
    #endif

    while (tc--) {
        SOLVE();
    }

    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
void solve(){
    string a,b;
    cin >> a >> b ;
    string c;
    cin >> c; 
    memset(dp,0,sizeof dp);
    int lena = a.size();
    int lenb = b.size() ;
    int lenc = c.size();
    a = '3' + a;
    b = '2' + b;
    c = '1' + c;
    for(int i = 0 ; i <= lena ; i ++ )
    {
        for(int j = 0 ; j <= lenb ; j ++ )
        {
            if(i == 0 && j == 0 )continue ;

            if(c[i + j] == a[i] && i > 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }else if(c[i + j] == b[j] && j > 0){
                dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }else {
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    
    cout << lenc - dp[lena][lenb] << endl; 
}


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

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
void solve(){
    string a,b;
    cin >> a >> b ;
    string c;
    cin >> c; 
    memset(dp,0,sizeof dp);


    int lena = a.size();
    int lenb = b.size() ;
    int lenc = c.size();
    a = '3' + a;
    b = '2' + b;
    c = '1' + c;
    for(int i = 1 ; i <= lena ; i ++ )
    {
        if(c[i] == a[i])dp[i][0] = dp[i-1][0] + 1;
    }
    for(int i = 1 ; i <= lenb ; i ++ )
    {
        if(c[i] == b[i])dp[0][i] = dp[0][i-1] + 1;
    }

    for(int i = 1 ; i <= lena ; i ++ )
    {
        for(int j = 1 ; j <= lenb ; j ++ )
        {
            if(i == 0 && j == 0 )continue ;
            if(c[i + j] == a[i] && i > 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i + j] == b[j] && j > 0){
                dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i+j]!=b[j] && c[i+j] != a[i]){
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            // cout << dp[i][j] << "  ";
        }
        // cout << endl;
    }
    
    cout << lenc - dp[lena][lenb] << endl; 
}


int main()
{
    int t ;
    cin >> t;
    while(t--)solve();
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
void solve(){
    string a,b;
    cin >> a >> b ;
    string c;
    cin >> c; 
    memset(dp,0,sizeof dp);


    int lena = a.size();
    int lenb = b.size() ;
    int lenc = c.size();
    a = '3' + a;
    b = '2' + b;
    c = '1' + c;
    for(int i = 1 ; i <= lena ; i ++ )
    {
        if(c[i] == a[i])dp[i][0] = dp[i-1][0] + 1;
    }
    for(int i = 1 ; i <= lenb ; i ++ )
    {
        if(c[i] == b[i])dp[0][i] = dp[0][i-1] + 1;
    }

    for(int i = 1 ; i <= lena ; i ++ )
    {
        for(int j = 1 ; j <= lenb ; j ++ )
        {
            if(i == 0 && j == 0 )continue ;
            if(c[i + j] == a[i] && i > 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i + j] == b[j] && j > 0){
                dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i+j]!=b[j] && c[i+j] != a[i]){
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            // cout << dp[i][j] << "  ";
        }
        // cout << endl;
    }
    
    cout << lenc - dp[lena][lenb] << endl; 
}


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

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
void solve(){
    string a,b;
    cin >> a >> b ;
    string c;
    cin >> c; 
    memset(dp,0,sizeof dp);


    int lena = a.size();
    int lenb = b.size() ;
    int lenc = c.size();
    a = '3' + a;
    b = '2' + b;
    c = '1' + c;
    for(int i = 1 ; i <= lena ; i ++ )
    {
        if(c[i] == a[i])dp[i][0] = dp[i-1][0] + 1;
        else dp[i][0] = dp[i-1][0];
    }
    for(int i = 1 ; i <= lenb ; i ++ )
    {
        if(c[i] == b[i])dp[0][i] = dp[0][i-1] + 1;
        else dp[0][i] = dp[0][i-1];
    }

    for(int i = 1 ; i <= lena ; i ++ )
    {
        for(int j = 1 ; j <= lenb ; j ++ )
        {
            if(i == 0 && j == 0 )continue ;
            if(c[i + j] == a[i] && i > 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i + j] == b[j] && j > 0){
                dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
            if(c[i+j]!=b[j] && c[i+j] != a[i]){
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
           
        }
    }
    
    cout << lenc - dp[lena][lenb] << endl; 
}


int main()
{
    int t ;
    cin >> t;
    while(t--)solve();
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int dp[2005][2005];
void solve(){
    string a,b;
    cin >> a >> b ;
    string c;
    cin >> c; 
    memset(dp,0,sizeof dp);
    int lena = a.size();
    int lenb = b.size() ;
    int lenc = c.size();
    a = '3' + a;
    b = '2' + b;
    c = '1' + c;
    for(int i = 0 ; i <= lena ; i ++ )
    {
        for(int j = 0 ; j <= lenb ; j ++ )
        {
            if(i == 0 && j == 0 )continue ;

            if(c[i + j] == a[i] && i > 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }else if(c[i + j] == b[j] && j > 0){
                dp[i][j] = max(dp[i][j],dp[i][j-1] + 1);
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }else {
                dp[i][j] = max(dp[i-1][j],dp[i][j]);
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    
    cout << lenc - dp[lena][lenb] << endl; 
}


int main()
{
    int t ;
    cin >> t;
    while(t--)solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);
	vector<int> v(n+1);
	vector<int> p(n+1);
	for(int i = 1; i <= n; i++){
		cin >> c[i];
		v[i] = i;
		p[i] = i;
	}


	if(n == 1){
		cout << "0\n";
		return 0;
	}
	vector<pair<int,int>> ans;
	for(int i = n; i > 0; i--){

		int a = c[i]; //koji auto na i-tom mestu na kraju
		int j = p[a]; //na kom mestu se trenutno nalazi taj auto


		while(j > 1){
			ans.push_back({v[j], v[j-1]});

			p[a] = j-1;
			p[v[j-1]] = j;
			swap(v[j], v[j-1]);

			j--;
		}

		while(c[j+1] < c[i]){
			ans.push_back({v[j+1], v[j]});

			p[a] = j+1;
			p[v[j+1]] = j;
			swap(v[j], v[j+1]);
			j++;
		}
	}



	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}

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

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1), v(n+1), p(n+1), e(n+1);
	for(int i = 1; i <= n; i++){

		cin >> c[i];
		e[c[i]] = i;
		v[i] = i;
		p[i] = i;
	}


	auto get = [&](){
		for(int i = 1; i <= n; i++) cout << v[i] << ' ';
		cout << '\n';
	};

	vector<pair<int,int>> ans;
	for(int i = n; i > 0; i--){

		int a = c[i]; //value of car that ends at position i
		int j = p[a]; //position of car a in array v

		while(j > 1){
			ans.push_back({v[j], v[j-1]}); // car at position j (a) overtakes the one ahead of it.

			swap(p[v[j]], p[v[j-1]]); //swap the positions of car v[j] (a) and the car ahead of it (v[j-1])
			swap(v[j], v[j-1]); // swap the values in the array
			//get();
			j--;
		}

		//important: keep going back while the ending position of current car e[a] is bigger than next car 
		while(j < n && e[a] > e[v[j+1]]){
			ans.push_back({v[j+1], v[j]});

			swap(p[v[j]], p[v[j+1]]); //swap the positions of car v[j] (a) and the car behind it j+1
			swap(v[j], v[j+1]); // swap the values in the array
			//get();
			j++;
		}
	}



	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);

	for(int i = 1; i <= n; i++){
		int a; cin >> a;
		c[a] = i;
	}
	set<pair<int,int>> used;
	vector<pair<int,int>> ans;

	vector<int> vl(n+1);
	for(int i = 1; i <= n; i++) vl[i] = i;
	for(int i = 1; i <= n; i++){
		bool sorted = true;

		for(int j = 1; j <= n; j++){
			if(j < c[vl[j]]){
				ans.emplace_back(vl[j+1], vl[j]);
				used.insert({vl[j+1], vl[j]});
				used.insert({vl[j], vl[j+1]});
				swap(vl[j], vl[j+1]);
				sorted = false;
			}
		}
		if(sorted) break;
	}

	for(int i = 1; i < n; i++){
		if(!used.count({vl[i], vl[i+1]})){
			used.insert({vl[i], vl[i+1]});
			used.insert({vl[i+1], vl[i]});
			ans.emplace_back(vl[i], vl[i+1]);
			ans.emplace_back(vl[i+1], vl[i]);
		}
	}

	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}

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

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);

	for(int i = 1; i <= n; i++){
		int a; cin >> a;
		c[a] = i;
	}
	set<pair<int,int>> used;
	vector<pair<int,int>> ans;

	vector<int> vl(n+1);
	for(int i = 1; i <= n; i++) vl[i] = i;
	for(int i = 1; i <= n; i++){
		bool sorted = true;

		for(int j = 1; j <= n; j++){
			if(j < c[vl[j]]){
				ans.emplace_back(vl[j+1], vl[j]);
				used.insert({vl[j+1], vl[j]});
				used.insert({vl[j], vl[j+1]});
				swap(vl[j], vl[j+1]);
				sorted = false;
			}
		}
		if(sorted) break;
	}
	for(int i = 1; i < n; i++){
		if(!used.count({vl[i], vl[i+1]})){
			used.insert({vl[i], vl[i+1]});
			used.insert({vl[i+1], vl[i]});
			ans.emplace_back(vl[i+1], vl[i]);
			ans.emplace_back(vl[i], vl[i+1]);
		}
	}

	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}
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;
const int maxn = 1005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);

	for(int i = 1; i <= n; i++){
		int a; cin >> a;
		c[a] = i;
	}
	set<pair<int,int>> used;
	vector<pair<int,int>> ans;

	vector<int> vl(n+1);
	for(int i = 1; i <= n; i++) vl[i] = i;
	for(int i = 1; i <= n; i++){
		bool sorted = true;

		for(int j = 1; j <= n; j++){
			if(j < c[vl[j]]){
				ans.emplace_back(vl[j+1], vl[j]);
				used.insert({vl[j+1], vl[j]});
				used.insert({vl[j], vl[j+1]});
				swap(vl[j], vl[j+1]);
				sorted = false;
			}
		}
		if(sorted) break;
	}
	for(int i = 1; i < n; i++){
		if(!used.count({vl[i], vl[i+1]})){
			used.insert({vl[i], vl[i+1]});
			used.insert({vl[i+1], vl[i]});
			ans.emplace_back(vl[i+1], vl[i]);
			ans.emplace_back(vl[i], vl[i+1]);
		}
	}

	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}

Submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);
	vector<int> v(n+1);
	vector<int> p(n+1);
	for(int i = 1; i <= n; i++){
		cin >> c[i];
		v[i] = i;
		p[i] = i;
	}
	vector<pair<int,int>> ans;
	for(int i = n; i > 0; i--){

		int a = c[i]; //koji auto na i-tom mestu na kraju
		int j = p[a]; //na kom mestu se trenutno nalazi taj auto


		while(j > 1){
			ans.push_back({v[j], v[j-1]});

			p[a] = j-1;
			p[v[j-1]] = j;
			swap(v[j], v[j-1]);

			j--;
		}

		while(c[j+1] < c[i]){
			ans.push_back({v[j+1], v[j]});

			p[a] = j+1;
			p[v[j+1]] = j;
			swap(v[j], v[j+1]);
			j++;
		}
	}



	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);

	for(int i = 1; i <= n; i++){
		int a; cin >> a;
		c[a] = i;
	}
	set<pair<int,int>> used;
	vector<pair<int,int>> ans;

	vector<int> vl(n+1);
	for(int i = 1; i <= n; i++) vl[i] = i;
	for(int i = 1; i <= n; i++){
		bool sorted = true;

		for(int j = 1; j <= n; j++){
			if(j < c[vl[j]]){
				ans.emplace_back(vl[j+1], vl[j]);
				used.insert({vl[j+1], vl[j]});
				used.insert({vl[j], vl[j+1]});
				swap(vl[j], vl[j+1]);
				sorted = false;
			}
		}
		if(sorted) break;
	}

	for(int i = 1; i < n; i++){
		if(!used.count({vl[i], vl[i+1]})){
			used.insert({vl[i], vl[i+1]});
			used.insert({vl[i+1], vl[i]});
			ans.emplace_back(vl[i], vl[i+1]);
			ans.emplace_back(vl[i+1], vl[i]);
		}
	}

	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);
	vector<int> v(n+1);
	vector<int> p(n+1);
	for(int i = 1; i <= n; i++){
		cin >> c[i];
		v[i] = i;
		p[i] = i;
	}
	vector<pair<int,int>> ans;
	for(int i = n; i > 0; i--){

		int a = c[i]; //koji auto na i-tom mestu na kraju
		int j = p[a]; //na kom mestu se trenutno nalazi taj auto


		while(j > 1){
			ans.push_back({v[j], v[j-1]});

			p[a] = j-1;
			p[v[j-1]] = j;
			swap(v[j], v[j-1]);

			j--;
		}

		while(c[j+1] < c[i]){
			ans.push_back({v[j+1], v[j]});

			p[a] = j+1;
			p[v[j+1]] = j;
			swap(v[j], v[j+1]);
			j++;
		}
	}



	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}

Submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> c(n+1);
	vector<int> v(n+1);
	vector<int> p(n+1);
	for(int i = 1; i <= n; i++){
		cin >> c[i];
		v[i] = i;
		p[i] = i;
	}


	if(n == 1){
		cout << "0\n";
		return 0;
	}
	vector<pair<int,int>> ans;
	for(int i = n; i > 0; i--){

		int a = c[i]; //koji auto na i-tom mestu na kraju
		int j = p[a]; //na kom mestu se trenutno nalazi taj auto


		while(j > 1){
			ans.push_back({v[j], v[j-1]});

			p[a] = j-1;
			p[v[j-1]] = j;
			swap(v[j], v[j-1]);

			j--;
		}

		while(c[j+1] < c[i]){
			ans.push_back({v[j+1], v[j]});

			p[a] = j+1;
			p[v[j+1]] = j;
			swap(v[j], v[j+1]);
			j++;
		}
	}



	cout << ans.size() << '\n';
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
}