ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt2+1 && i<1000; i++){

        for(int j=0; j<cnt1+1 && cnt1<1000; j++){

            if((sm+6*i+2*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}



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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt2+1 && i<5000; i++){

        for(int j=0; j<cnt1+1 && cnt1<5000; j++){

            if((sm+6*i+2*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt2+1 && i<20; i++){

        for(int j=0; j<cnt1+1 && cnt1<20; j++){

            if((sm+6*i+2*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt1+1 && i<10; i++){

        for(int j=0; j<cnt2+1 && cnt1<10; j++){

            if((sm+2*i+6*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}



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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt1+1 && i<10; i++){

        for(int j=0; j<cnt2+1 && i<10; j++){

            if((sm+2*i+6*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt2+1 && i<5000; i++){

        for(int j=0; j<cnt1+1 && cnt1<5000; j++){

            if((sm+6*i+2*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

}



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



#define int long long



const int mod = 1e9 + 7;

const int inf = 1e18;



using namespace std;



void solve() 

{

    string a;

    cin >> a;

    int sm=0,cnt1=0,cnt2=0;

    for(auto &i:a) {

        sm+=(i-'0');

        if(i=='2') cnt1++;

        if(i=='3') cnt2++;

    }

    if(sm%9==0){

        cout << "YES";

        return;

    }

    for(int i=0; i<cnt1+1 && i<10; i++){

        for(int j=0; j<cnt2+1 && cnt1<10; j++){

            if((sm+2*i+6*j)%9==0){

                cout << "YES";

                return;

            }

        }

    }

    cout << "NO";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t = 1;

    cin >> t;



    while (t--) {

        solve();

        cout << "\n";

    }

    return 0;

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


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

#define all(v) v.begin(), v.end()
#define left id << 1
#define right id << 1 | 1
#define sz(x) (int)x.size()
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define DEBUG cout << "TESTCASE " << tc << ": ";

template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}

const int lg2 = 20;
const int N = 2010;
const int mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f3f3f3f;

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll gcd(ll x, ll y) {
    if (!y) return x;
    return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
    return (x * y) / gcd(x, y);
}

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

template <class T>
bool ckmin(T &a, T b) {
	if (a > b)
		return (a = b);
	return 0;
}

template <class T>
bool ckmax(T &a, T b) {
	if (a < b)
		return (a = b);
	return 0;
}

ll binpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res *= a;
		b >>= 1;
		a *= a;
	}
	return res;
}

void add(ll &a, ll b) {
	a += b;
	if (a >= mod) 
		a -= mod;
}

void sub(ll &a, ll b) {
	a -= b;
	if (a < 0) 
		a += mod;
}

void solve() {
	int n, l, r; see(n, l, r);
    vector<int> a(n);
    for (int &e: a) cin >> e;
    sort(all(a));
    ll sum = 0;
    for (int i = 0; i < r - l + 1; ++i) {
        sum += a[i];
    }
    cout << sum << '\n';
}

/*
	
*/

int32_t main() {

	// if (fopen("input.inp", "r")) {
	// 	freopen("input.inp", "r", stdin);
	// 	freopen("output.out", "w", stdout);
	// }
	
	ios::sync_with_stdio(NULL);
	cin.tie(0); cout.tie(0);


	int tc = 1;
	cin >> tc;
	while (tc--) {
		solve();
	}

	return 0;
}

/*
	nice bin string
	1 must go with 0
	0 must go with 1
 */
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#include<unordered_map>	
using namespace std;
#define ll long long int
#define vi vector<ll> 
#define all(v) v.begin() , v.end()
#define srt(v) sort(v.begin(), v.end())
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define co(c) cout<<c<<"\n"
#define rn return 
#define acc(v) accumulate(v.begin() , v.end() , 0)


template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; }
template<class T, class U> ostream& operator<<(ostream &os, const pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for(auto x : vec) os << x << " "; return os; }

void solve(){
    int n ; 
     cin >> n ; 
     int a, b; 
     cin >> a >> b;
     vi arr(n, 0 );
     cin >> arr;
     
     sort(arr.begin() , arr.begin() + a);
     sort(arr.begin() + a , arr.begin() + b);
     sort(arr.begin() + b , arr.end());

     int cnt = b - a  +1;
     a--;
     b--;
     int curr = 0;
     int i = 0; 
     int j = a;
     int first = 0;
     

     while(curr < cnt){
        
         if( i < a && (arr[i] < arr[j]  || j > b)){
            first += arr[i];
            i++;
         }
         else if( j <= b && (arr[j] <= arr[i] || i >= a)){
            first += arr[j];
            j++;
        }

        curr++;
     }

     int last = first ;
     i = b+1;
     first = 0;
     //a = n;
     curr = 0;
     j = a;

     while(curr < cnt){
           
         if(i < n && ( arr[i] < arr[j] || j> b)){
            first += arr[i++];      
         } 
         else if( j <= b && (arr[j] <= arr[i] || i>=n)){
            first += arr[j++];
         } 
            curr++;
     } 
   

     co(min(last,first));


     
  
}


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

   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int testcases;
    cin >> testcases;

    //testcases = 1;
    while (testcases--) {
       solve();
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#include<unordered_map>	
using namespace std;
#define ll long long int
#define vi vector<ll> 
#define all(v) v.begin() , v.end()
#define srt(v) sort(v.begin(), v.end())
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define co(c) cout<<c<<"\n"
#define rn return 
#define acc(v) accumulate(v.begin() , v.end() , 0)


template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; }
template<class T, class U> ostream& operator<<(ostream &os, const pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for(auto x : vec) os << x << " "; return os; }

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

  vi adj[n+1];
  vi out(n+1 , 0);

  for(int i= 0 ; i < n -1 ; i++){
     int a, b;
     cin >> a >> b;
     
     adj[a].push_back(b);
     adj[b].push_back(a);

     out[a]++;
     out[b]++;
  }
  int ans = 1;
  int ind = max_element(out.begin(), out.end()) - out.begin();
  
  int d = out[ind];
  out[ind] = -1;
  
  ans += (d -1);
  
  for(auto t: adj[ind]){
      out[t]--;  
  }

  ind = max_element(out.begin(), out.end() ) - out.begin();

  d = out[ind];
  
  ans += (d - 1);

  co(ans);
}

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

   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int testcases;
    cin >> testcases;

    //testcases = 1;
    while (testcases--) {
       solve();
    }
    
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

#define SIZE 20000 + 11
string arr;

void solve(){
	cin >> arr;
	int n = arr.size();

	assert(n < 200000);

	for(int j=1; j < n ; j++){
		// bool flag = false;
		for(int i=1; i < n; i++){
			int a = arr[i-1] - '0';
			int b = arr[i] - '0';
			// cout << "found a and b: " << a << ' ' << b << endl;
			if(b > a and abs(a-b) > 1){
				arr[i-1] = (b - 1) + '0';
				arr[i] = a + '0';
				// flag = true;
			}
			// cout << arr << endl;
		}
		// if(flag) break;
	}
	cout << arr << '\n';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

Submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>
using namespace std;

#define SIZE 20000 + 11
string arr;

void solve(){
	cin >> arr;
	int n = arr.size();

	assert(n < 200000);

	for(int i=0; i<n; i++){
		int pos = i;
		int best = arr[i] - '0';
		for(int j=i; j < min(i + 10, n); j++){
			if(((arr[j] - '0') - (j - i)) > best){
				best = arr[j] - '0' - (j - i);
				pos = j;
			}
		}

		while(pos > i){
			swap(arr[pos], arr[pos-1]);
			pos--;
		}

		arr[i] = char(best + '0');
	}

	cout << arr << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

Previous submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>
using namespace std;

#define SIZE 20000 + 11
string arr;

void solve(){
	cin >> arr;
	int n = arr.size();

	assert(n < 200000);

	for(int i=0; i<n; i++){
		int pos = i;
		int best = arr[i] - '0';
		for(int j=i; j < min(i + 10, n); j++){
			if(((arr[j] - '0') - (j - i)) > best){
				best = arr[j] - '0' - (j - i);
				pos = j;
			}
		}

		while(pos > i){
			swap(arr[pos], arr[pos-1]);
			pos--;
		}

		arr[i] = char(best + '0');
	}

	cout << arr << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

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

#define SIZE 20000 + 11
string arr;

void solve(){
	cin >> arr;
	int n = arr.size();

	assert(n <= 200000);

	for(int i=0; i<n; i++){
		int pos = i;
		int best = arr[i] - '0';
		for(int j=i; j < min(i + 10, n); j++){
			if(((arr[j] - '0') - (j - i)) > best){
				best = arr[j] - '0' - (j - i);
				pos = j;
			}
		}

		while(pos > i){
			swap(arr[pos], arr[pos-1]);
			pos--;
		}

		arr[i] = char(best + '0');
	}

	cout << arr << endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

#define SIZE 20000 + 11
string arr;

void solve(){
	cin >> arr;
	int n = arr.size();

	assert(n < 200000);

	for(int j=1; j < n ; j++){
		// bool flag = false;
		for(int i=1; i < n; i++){
			int a = arr[i-1] - '0';
			int b = arr[i] - '0';
			// cout << "found a and b: " << a << ' ' << b << endl;
			if(b > a and abs(a-b) > 1){
				arr[i-1] = (b - 1) + '0';
				arr[i] = a + '0';
				// flag = true;
			}
			// cout << arr << endl;
		}
		// if(flag) break;
	}
	cout << arr << '\n';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		solve();
	}
}
Problem: 2062C - Cirno and Operations
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

int update(int a[], int n) {
    n -= 1;
    for (int i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

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

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                int temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (abs(a[0]) > sum) sum = abs(a[0]);
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}

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

int update(ll a[], int n) {
    n -= 1;
    for (int i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

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

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                int temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (abs(a[0]) > sum) sum = abs(a[0]);
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
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

int update(ll a[], int n) {
    n -= 1;
    for (int i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

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

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                int temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (abs(a[0]) > sum) sum = abs(a[0]);
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}

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

ll update(ll a[], ll n) {
    n -= 1;
    for (ll i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

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

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                ll temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (a[0] > sum) {sum = a[0];}
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

int update(int a[], int n) {
    n -= 1;
    for (int i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

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

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                int temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (abs(a[0]) > sum) sum = abs(a[0]);
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
#define all(s) s.begin(), s.end()
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector <int> c(n), mp(n + 2, 0);
    for (auto &i : c) cin >> i; //thứ tự gần vạch xuất phát của từng xe
    vector <pii> ans;
    for (int i = n - 1; i >= 0; --i)
    {
        mp[c[i]] = 1;
        for (int j = c[i] - 1; j > 0; --j)
            if (!mp[j])
                ans.eb(c[i], j);
        for (int j = n - 1; j > i; --j)
            ans.eb(c[i], c[j]);
    }
    cout << ans.size() << '\n';
    for (auto &[u, v] : ans)
        cout << u << ' ' << v << '\n';
}

int main()
{
    if (ifstream(task".inp")) nx
    fast

    int t;
    while(t--) solve();
}

/*
c[i] là khoảng cách của xe đến vạch xuất phát ban đầu (1 <= c[i] <= n, c[i] != c[j] với i != j)
- Nếu mà c[i] < c[j] và i > j tức là xe c[j] về đích trước c[i] => c[j] vược c[i], c[i] không vượt
được c[j]
- Nếu c[i] < c[j] và i < j thì về đúng thứ tự tăng dần của khoảng cách đến vạch xuất phát
=> hoặc 2 thằng không vượt hoặc j vượt i rồi i vượt lại. Do đề yêu cầu dãy lệnh dài nhất
nên lấy TH2
Nếu có thứ tự về đích là c1, c2, ..., cn thì xét ngược lại cn, cn-1, ...., c1
ci sẽ vượt qua những xe về đích sau nó (tức là các xe đoạn [i + 1, n]) (*)
và vượt qua các xe có c nhỏ hơn nó và về đích trước nó trước khi bị các xe đó vượt lại ở TH '(*)' (**)
*/

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
#define all(s) s.begin(), s.end()
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector <int> c(n), mp(n + 2, 0);
    for (auto &i : c) cin >> i; //thứ tự gần vạch xuất phát của từng xe
    vector <pii> ans;
    for (int i = n - 1; i >= 0; --i)
    {
        mp[c[i]] = 1;
        for (int j = c[i] - 1; j > 0; --j)
            if (!mp[j])
                ans.eb(c[i], j);
        for (int j = n - 1; j > i; --j)
            ans.eb(c[i], c[j]);
    }
    cout << ans.size() << '\n';
    for (auto &[u, v] : ans)
        cout << u << ' ' << v << '\n';
}

int main()
{
    if (ifstream(task".inp")) nx
    fast

    solve();
}