ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define MAXN 1000005

typedef long long int ll;
using namespace std;

void solve(){
    string n;
    int six = 0, two = 0;

    cin >> n;
    for(auto& c : n){
        if(c == '2') ++two;
        if(c == '3') ++six;
    }

    while(n.size() > 1){
        int temp = 0;
        string newn;
        for(auto& c : n)
            temp += c - '0';
        while(temp != 0){
            newn.push_back(temp % 10 + '0');
            temp /= 10;
        }
        n = newn;
    }
    int digit = n[0] - '0';

//    cout << "DOS: " << two << "  SEIS: " << six << "\n";
    bool ans = false;
    if(digit % 9 == 0) ans = true;
    int x = 9 - digit, lim = two * 2 + six * 6;
    for(int sum = 0; sum <= lim && !ans; sum += 9){
        int num = x + sum;
//        cout << "NUMERO A BUSCAR: " << num << "\n";
        if(num % 2 == 0){
            if(num / 2 <= two)
                ans = true;
            else{
                int sum_six = 6 * min(num / 6, six);
                if((num - sum_six) % 2 == 0 && (num - sum_six) / 2 <= two)
                    ans = true;
            }
        }
    }

    cout << (ans ? "YES" : "NO") << "\n";
}

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

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

    return 0;
}

/**
   (\---/)
   /` _ ´\
  /  |T|  \
  `   -   ´
    Soria
**/


Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int sum=0;
        map<int,int>m;
        for(int i=0;i<s.size();i++){
            int k=s[i]-'0';
            sum+=(s[i]-'0');
            m[k]++;
        }
        int c=sum%9;
        if(c==0){
            cout<<"YES"<<endl;
        }
        else{
            c=9-c;
            vector<int>v3,v2;
            v3={0,6,3};
            v2={0,2,4,6,8,1,3,5,7};
            bool f=0;
            for(int i=0;i<3;i++){
                for(int j=0;j<9;j++){
                    if(m[3]>=i&&m[2]>=j){
                        if((v3[i]+v2[j])%9==c){
                            f=1;
                            break;
                        }
                    }
                }
            }
            if(f==1){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
            
        }
        
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;
    vector<ll> a(n);
    
    for (ll i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> first(a.begin(), a.begin() + l - 1);
    // cout << "first size: " << first.size() << endl;
    vector<ll> second(a.begin() + l - 1, a.begin() + r);
    // cout << "second size: " << second.size() << endl;
    vector<ll> last(a.begin() + r, a.end());
    // cout << "last size: " << last.size() << endl;

    sort(first.begin(), first.end());
    sort(second.begin(), second.end(), greater<ll>());
    sort(last.begin(), last.end());

    // cout << "first: ";
    // for (int x : first) cout << x << " ";
    // cout << endl;

    // cout << "second: ";
    // for (int x : second) cout << x << " ";
    // cout << endl;

    // cout << "last: ";
    // for (int x : last) cout << x << " ";
    // cout << endl;

    ll initial_sum = 0;
    for (ll x: second) initial_sum += x;


    ll left_delta = 0;
    for (ll i = 0; i < min(first.size(), second.size()); i++){
        if (first[i] > second[i]){
            break;
        }
        else{
            left_delta +=  first[i] - second[i] ;
        }
    }

    ll right_delta = 0;
    for (ll i = 0; i < min(last.size(), second.size()); i++){
        if (last[i] > second[i]){
            break;
        }
        else{
            right_delta -= second[i] - last[i];
        }
    }

    ll delta = min(left_delta, right_delta);
    delta = min(delta, 0ll);
    ll res = initial_sum + delta;
    // cout << "left delta: " << left_delta <<  " right delta: " << right_delta << endl;

    cout << res << endl;
}

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

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

Solution 2 (runtime: 186 ms):
#include<bits/stdc++.h>



using namespace std;



using ll = long long;



ll t, n, l, r, a[100000];



int main() {

    cin >> t;

    while (t--) {

        cin >> n >> l >> r;

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

            cin >> a[i];

        }

        vector<ll> v1, v2;

        v1.clear();

        v2.clear();

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

            v1.push_back(a[i]);

        }

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

            v2.push_back(a[i]);

        }

        sort(v1.begin(), v1.end());

        sort(v2.begin(), v2.end());

        ll ans1 = 0;

        ll ans2 = 0;

        for (int i = 0; i < r - l + 1; ++i) {

            ans1 += v1[i];

            ans2 += v2[i];

        }

        cout << min(ans1, ans2) << '\n';

    }

    return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

void solve () 
{
   string s ; 
   cin>> s ;   
   int n = s.length() ;
   if(n == 1) 
   {
    cout<< s<< endl;  
    return ;   
   }  
   int i  = n-2;  
   while(i >= 0 ) 
   {
    int ch = s[i]-'0' ;  
    int j = i+1 ;  
    while(j < n && ch+1 < s[j]-'0' ) 
    {
        s[j-1] = s[j]-1 ;  
        j++ ;  
    } 
    j--;
    s[j] = ch+'0' ;  
    i--;
   }
   cout<< s << endl ;  
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t ; 
cin>>t  ; 
while(t--)
{
     solve() ;
}
 return 0;
}

Solution 2 (runtime: 78 ms):
#include<iostream>
#include<algorithm>
using namespace std;

int t;

void solve()
{
	string str;
	cin >> str;
	for(int i = str.size() - 1;i > 0;i--)
	{
	    if(str[i] > str[i - 1] + 1 && str[i - 1] != 0 )
	    {
	    	str[i]--;
	    	swap(str[i],str[i - 1]);
	    	for(int j = i;j < str.size() - 1;j++)
	    	{
	    		if(str[j + 1] > str[j] + 1 && str[j] != 0)
	    		{
	    			str[j + 1] --;
	    			swap(str[j + 1],str[j]);
				}
				else break;
			}
		}
	}
	cout << str << endl; 
}

int main()
{
	cin >> t;
	while(t--) solve();
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
// Pura Gente del Coach Moy
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define ROF(i, a, b) for (int i = (int)a - 1; i >= (int)b; --i)
#define endl '\n'

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};  // abajo, derecha, arriba, izquierda



void solve(){
	
	int l,r;
	cin>>l>>r;
	int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
	cout<<a<<" "<<b<<" "<<c<<endl;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
  
  	int t;
	cin>>t;
	
	while(t--)solve();	
	
  return 0;
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using uLL = unsigned long long;
#define PII pair<int,int>
const int N = 1e+9;

void solve(){
    int l, r; cin >> l >> r;
    int a = 0, b = 0, c = 0;
    for(int i = 29; i >= 0; i--){
        if((l ^ r) >> i & 1){
            a |= (1 << i);
            b |= (1 << i) - 1;
            break;
        }
        else{
            a |= l & (1 << i);
            b |= l & (1 << i);
        }
    }
    c = l;
    while(c == a || c == b) c++;
    cout << a << ' ' << b << ' ' << c << '\n';
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _ =1;
    cin >> _;
    while(_--)solve();
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
    ll n;
    cin >> n;
    vector < ll > a(n);

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

    for (int i = 0; i < n - 1; i++) {
        if (a[i] > a[i + 1]) {
            cout << "NO" << endl;
            return;
        } else {
            int temp = min(a[i], a[i + 1]);
            a[i] -= temp;
            a[i + 1] -= temp;
        }
    }
    cout << "YES" << endl;
}

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

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

Solution 2 (runtime: 374 ms):
#include <bits/stdc++.h>

using namespace std;



#define ll unsigned long long



int main(){

    int t;

    cin >> t;

    while(t--){

        ll n;

        cin >> n;

        vector<ll> x(n+1);

    

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

        cin >> x[i];        

        }

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

            int m=min(x[i],x[i-1]);

            x[i]-=m;x[i-1]-=m;

        }

        bool flag=false;

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

            if(flag) break;

            else{

                if(x[i-1]>x[i]) flag=true;

            }

        }

        if(!flag) cout << "YES\n";

        else cout << "NO\n";

    }

    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 281 ms):
# include <bits/stdc++.h>
using namespace std;
# define ll long long

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<ll> v(n);
        map<ll,ll> ct;
        set<ll> s;
        for(int i=0;i<n;++i){
            cin>>v[i];
            ct[v[i]]++;
            s.insert(v[i]);
        }

        ll m=s.size();
        int dt=m;

        vector<ll> a(m);
        ll idx=0;
        for( auto it:ct){
            
            a[idx]= it.second;
            idx++;

        }
        sort(a.begin(),a.end());
        for(int i=0;i<m-1;++i){
            if(k>=a[i]){
                k-=a[i];
                dt--;

            }
            else{
                break;
            }
        }

        // int ans=max(1,dt);

        cout<< dt <<endl;



    }
}

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	sort(x.begin(), x.end());
	vector<pair<ll, ll>> v;
	for (ll i = 0; i < n; i++) {
		if (v.empty() || v.back().first != x[i]) v.push_back({x[i], 1});
		else v.back().second++;
	}

	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	ll i = 0, res = 0;
	while (k > 0 || i < v.size()) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else {
			k = 0;
			++res;
		}
		++i;
	}
	// ll res = 0;
	// for (ll i = 0; i < v.size(); i++) {
	// 	if (v[i].second > 0) ++res;
	// }
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 ms):
#include <bits/stdc++.h>

using namespace std;



int main()

{

    int t ;

    cin>>t ;

    while(t--){

        int n ,l,r ;

        cin>>n>>l>>r ;

        vector<int> v(n) ;

        for(int i =0; i<n; i++)cin>>v[i];

        priority_queue <int, vector<int>, greater<int>> left,right ;

        priority_queue<int> mid,mid2 ;

        long long int sum = 0,ans,prev_diff = 0,left_sum = 0, right_sum =0 ,mid_sum=0 ;

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

            if(i<l-1){

                left.push(v[i]);

            }

            else if(i<r){

                mid.push(v[i]);

                mid2.push(v[i]);

                sum+=v[i];

            }

            else{

                right.push(v[i]);

            }

        }

        // cout<<left.size()<<mid.size()<<right.size();

        while(!left.empty() and !mid.empty()){

            left_sum += left.top();

            left.pop();

            mid_sum += mid.top();

            // mid2.push(mid.top());

            mid.pop();

            long long int diff = mid_sum - left_sum ;

            if(diff >  prev_diff) prev_diff = diff ;

        }

        //  while(!mid.empty()){

        //     mid2.push(mid.top());

        //     mid.pop();

        //  }

         mid_sum=0 ;

          while(!right.empty() and !mid2.empty()){

            right_sum += right.top();

            right.pop();

            mid_sum += mid2.top();

            mid2.pop();

            long long int diff = mid_sum - right_sum ;

            if(diff >  prev_diff) prev_diff = diff ;

        }

        cout<<endl<<sum- prev_diff<<endl ;

        

    }

    return 0;

}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>

#define int long long

#define vi vector<int>

#define vvi vector<vector<int>>

#define pi pair<int,int>

#define pii pair<pair<int,int>,int>

#define vpi vector<pair<int,int>>

#define mp make_pair

using namespace std;

const int inf = 1e18;

const int mod = 998244353;

int n,l,r;

void solve(){

    cin>>n>>l>>r;

    vi a, b;

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

    	int x;

    	cin>>x;

    	if(i <= r)a.push_back(x);

    	if(i >= l)b.push_back(x);

	}

	sort(a.begin(), a.end());

	sort(b.begin(), b.end());

	int sum1 = 0, sum2 = 0;

	for(int i = 0; i <= (r - l); i++){

		sum1 += a[i];

		sum2 += b[i];

	}

	cout<<min(sum1, sum2)<<"\n";

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int T = 1;

    cin>>T;

    while(T --){

        solve();

    }

    

    return 0;

} 

//    /\_/\

//   (= ._.)

//   / >  \>
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<iostream>
#include<vector>
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<ll>input(n);
    REP(i,0,n) cin>>input[i];
    ll ans = -1e18;
    int size = n;
    REP(i,0,n){
        ll sum = 0;
        REP(j,0,size) sum+= input[j];
        if(i==0) ans = max(ans,sum);
        else ans = max(ans,max(sum,-sum));
        REP(j,0,size-1) input[j] = input[j+1]-input[j];
        size--;
    }
    cout<<ans<<endl;
}
int main(){
     int t;
     cin>>t;
     while(t--){
        solve();
     }
}

Solution 2 (runtime: 46 ms):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;
    
    while(t--) {
        int n;
        cin >> n;
        vector<long long> arr(n + 1);
        
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
        }
        
        int row = n;
        long long sum = -1e18;
        
        for(int j = 1; j <= n; j++) {
            long long ans = 0;
            for(int b = 1; b <= row; b++) {
                ans += arr[b];
            }
            
            if(j == 1) {
                sum = max(ans, sum);
            } else {
                sum = max(sum, max(-ans, ans));
            }
            
            for(int a = 1; a < row; a++) {
                arr[a] = arr[a + 1] - arr[a];
            }
            row--;
        }
        
        cout << sum << endl;
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 78 ms):
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

string s;
int main() {
    int T;
    cin >> T;
    while (T --) {
        cin >> s;
        for (int i = 1; i < s.size(); i ++) {
            for (int j = i; j; j --)
                if (s[j] > s[j - 1] + 1) {
                    s[j] --;
                    swap(s[j], s[j - 1]);
                } else {
                    break;
                }
        }
        cout << s << '\n';
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;

using ll = long long;
void setIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}




void solve() {
	string s; cin >> s;
	string ans = "";
	int n = s.length();


	set<int> getRid;
	for(int i = 0; i < n; i++) {
		int bestIndex = i;
		int bestAmt = 0;
		for(int j = i; j < min((int) s.size(), i+10); j++) {
			if(s[j] - '0' - (j-i) > bestAmt) {
				bestIndex = j;
				bestAmt = s[j] - '0' - (j-i);
			}
		}

		while (bestIndex > i) {
            swap(s[bestIndex], s[bestIndex- 1]);
            bestIndex--;
        }

		s[i] = char(bestAmt + '0');

	}

	cout << s << "\n";
}





int main() {
	setIO();
	int t; cin >> t;
	while(t--) {
    solve();
	}
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 125 ms):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007


ll factorial(ll n) {
    ll res = 1;
    for (ll i = 2; i <= n; i++) {
        res *= i;
    }
    return res;
}

ll factorial_mod(ll n) {
    ll res = 1;
    for (ll i = 2; i <= n; i++) {
        res = (res * i) % mod;
    }
    return res;
}

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

void solve() {
    ll n,l,r;
    cin>>n>>l>>r;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin>>a[i];
    }
    vector<ll> b;
    vector<ll> c;
    for(ll i = 0; i < r; i++) c.push_back(a[i]);
    for(ll i = l - 1; i < n; i++) b.push_back(a[i]);
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll reqd = r - l + 1;
    ll ans1 = 0;
    ll ans2 = 0;
    for(ll i = 0; i < reqd; i++) {
        ans1 += b[i];
        ans2 += c[i];
    }
    cout<<min(ans1, ans2)<<endl;

}

    

  

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

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

    return 0;
}


Solution 2 (runtime: 78 ms):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define ll long long
const int N = 1e5 + 8;

using namespace std;



void solve() {
    
    int n , l , r ; cin >> n >> l >> r;
    
    vector <int> a(n);
    
    for (int i = 0 ; i < n ; i ++) cin >> a[i];
    
    auto b = a;
    
    ll sum1 = 0, sum2 = 0;
    
    sort(a.begin() , a.begin() + r);
    
    for (int i = 0 ; i < r - l + 1; i ++) sum1 += a[i];
    
    sort(b.begin() + l - 1 , b.end());
    
    for (int i = l - 1 ; i < l - 1 + r - l + 1; i ++) sum2 +=b[i];
    
    ll ans = min(sum1, sum2);
    
    cout << ans << endl;
    
    
}


int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t ; cin >> t;
    while (t--)solve();
    
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;


int main(){
    long long int t,i,j,w,k,n,r,x,q,kib,l,z,y,f,g,c,p,a,b,d;
 string s;

map<long long int,long long int>m;


	cin>>t;
	for(i=0;i<t;++i){ cin>>s; k=s.size(); if(k==1){cout<<s<<endl; }
	else{ for(j=1;j<k;++j){
            for(p=j;p>0;--p){ char c1,c2; c1=s[p];
    c2=s[p-1]; l=c1-c2;    if(l>1){
        s[p]=s[p]-1; swap(s[p],s[p-1]);  } else{break; } }

         }


cout<<s<<endl;
         }
   }


}


Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;

string solve (string s){
    for(int i=0; i<s.size(); i++){
        int cur = s[i]-'0';
        int pos = i;
        for(int j=i; j<min(i+10, (int)s.length()); j++){
            if(s[j]-'0'-(j-i)>cur){
                pos=j;
                cur = s[j]-(j-i)-'0';
            }
        }

        while(pos > i){
            swap(s[pos], s[pos-1]);
            pos--;
        }
        s[i] = cur + '0';
        
    }
    return s;
}

int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("13")<< endl;
    

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1249 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> c(n);
  vector<int> o(n);
  vector<int> o2(n);

  for(int i=0;i<n;i++){
    cin>>c[i];
    o[i]=i+1;
  }
  o2=o;
  int ans=0;
  int takeout=0;
  for(int i=c.size()-1;i>0;i--){
    int count=0;
    for(int j=0;j<c[i]-1;j++){
      if(o[j]!=0){
        count++;
      }
    }
    ans=ans+count+i;
    o[c[i]-1]=0;
    takeout++;
  }

  cout<<ans<<endl;

  for(int i=c.size()-1;i>0;i--){
    for(int j=c[i]-2;j>=0;j--){
      if(o2[j]!=0){
        cout<<c[i]<<" "<<o2[j]<<endl;
      }
    }
    for(int j=0;j<o2.size();j++){
      if(o2[j]!=0 && o2[j]!=c[i]){
        cout<<o2[j]<<" "<<c[i]<<endl;
      }
    }
    o2[c[i]-1]=0;
  }
  return 0;
}

Solution 2 (runtime: 1561 ms):
//cd C:\Users\Ansh\Documents\work_folder\cp
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int arr[1001];
int seq[1001];
vector<vector<int>>ans;

void fix(int a, int b) {
    while (a != 0) {
        ans.push_back({seq[a], seq[a - 1]});
        swap(seq[a], seq[a - 1]);
        a--;
    }
    while (a != b) {
        ans.push_back({seq[a + 1], seq[a]});
        swap(seq[a + 1], seq[a]);
        a++;
    }
}


int main(){
    int n; cin>>n;
    for (int i = 1; i <= n; i++) {seq[i - 1] = i;}
    for (int i = 0; i < n; i++) {cin>>arr[i];}
    for (int i = n - 1; i >= 0; i--) {
        int c = arr[i];
        for (int j = 0; j < n; j++) {
            if (seq[j] == c) {
                fix(j, i); break;
            }
        }
    }
    cout<<ans.size()<<endl;
    for (vector<int>i: ans) {
        cout<<i[0]<<" "<<i[1]<<endl;
    }
    return 0;
}