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

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

#include <vector>

using namespace std;

int main() {

    int t;cin>>t;

    while(t--){

        string s;cin>>s;

        int sum=0;

        int count=0;

        int three=0;

        for(char ch:s){

            if(ch=='2') count++;

            if(ch=='3') three++;

            else sum=sum+ch-48;

        } 

        three%=3;

        bool found=false;

        int a=sum;

        int b=sum;

        if(sum%9==0) found=true;

        if(three==1){

            if(sum%9==6) found=true;

            a+=3;

        }

        if(three==2){

            if(sum%9==3 || sum%9==6) found=true;

            a+=6;

        }

        while(count--){

            sum+=2;

            a+=2;

            b+=2;

            if(sum%9==0 || a%9==0 || b%9==0) found=true;

        }

        if(found) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

    }

    return 0;

}

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

#include <vector>

using namespace std;

int main() {

    int t;cin>>t;

    while(t--){

        string s;cin>>s;

        int sum=0;

        int count=0;

        int three=0;

        for(char ch:s){

            if(ch=='2') count++;

            if(ch=='3') three++;

            else sum=sum+ch-48;

        } 

        three%=3;

        bool found=false;

        int a=sum;

        int b=sum;

        int c=sum;

        if(sum%9==0) found=true;

        if(three==1){

            if(sum%9==6) found=true;

            a+=3;

        }

        if(three==2){

            if(sum%9==3 || sum%9==6) found=true;

            a+=6;

            c+=3;

        }

        while(count--){

            sum+=2;

            a+=2;

            b+=2;

            c+=2;

            if(sum%9==0 || a%9==0 || b%9==0 || c%9==0) found=true;

        }

        if(found) cout<<"YES"<<endl;

        else cout<<"NO"<<endl;

    }

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;
 
// --- Helper functions --- // 
 
// Convert a vector of numbers into a string (to use as a key for memoization).
string vecToStr(const vector<long long>& v) {
    string s;
    s += to_string(v.size());
    s.push_back('|');
    for (auto num : v){
        s += to_string(num) + ",";
    }
    return s;
}
 
// Return the sum of all elements in a vector.
long long vecSum(const vector<long long>& v) {
    long long s = 0;
    for (auto x : v)
        s += x;
    return s;
}
 
// Given a vector v, return the vector of consecutive differences.
vector<long long> diffVec(const vector<long long>& v) {
    vector<long long> res;
    for (size_t i = 0; i + 1 < v.size(); i++){
        res.push_back(v[i+1] - v[i]);
    }
    return res;
}
 
// Return the reversed vector.
vector<long long> revVec(const vector<long long>& v) {
    vector<long long> res = v;
    reverse(res.begin(), res.end());
    return res;
}
 
// --- DFS with memoization --- // 
 
// memo: maps a state (encoded as a string) to the set of scores obtainable from it.
unordered_map<string, set<long long>> memo;
 
// DFS: from the current state (sequence) return a set of possible final scores
// obtainable by applying any sequence of operations.
set<long long> dfsState(const vector<long long>& state) {
    string key = vecToStr(state);
    if(memo.find(key) != memo.end()){
        return memo[key];
    }
    
    set<long long> res;
    // Option: stop now. (Remember that “do nothing” means you simply sum the elements.)
    long long currentSum = vecSum(state);
    res.insert(currentSum);
    
    // If the state has more than one element, we can apply our two operations.
    if(state.size() > 1) {
        // Option 1: Reverse the current sequence.
        vector<long long> revState = revVec(state);
        set<long long> resRev = dfsState(revState);
        res.insert(resRev.begin(), resRev.end());
 
        // Option 2: Replace the sequence with its difference sequence.
        vector<long long> diffState = diffVec(state);
        set<long long> resDiff = dfsState(diffState);
        res.insert(resDiff.begin(), resDiff.end());
    }
    
    memo[key] = res;
    return res;
}
 
// --- Main --- //
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t; 
    cin >> t;
    while(t--){
        int n; 
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        memo.clear();  // clear memo for each test case
 
        // Start DFS from the original sequence.
        set<long long> outcomes = dfsState(a);
 
        // Our answer is the maximum score achievable.
        long long ans = -LLONG_MAX;
        for(auto x: outcomes) {
            if(x > ans)
                ans = x;
        }
        cout << ans << "\n";
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int t = 1;

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    int cnt = 0;

    int prev = INT_MIN;
    int maxi = stoll(s);
    while (prev != maxi) {
        prev = maxi;
        for (int i = 1; i < n - cnt; i++) {
            if ((s[i] - '0') - 1 > (s[i - 1] - '0')) { 
                s[i] = (s[i] - '0' - 1) + '0';        
                swap(s[i], s[i - 1]);
                maxi = max(maxi, stoll(s));           
            }
        }
    }

    cout << maxi << endl;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    if (t) cin >> t; else t = 1;
    while (t--) solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int t = 1;

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    int cnt = 0;

    int prev = INT_MIN;
    int maxi = stoll(s);
    while (prev != maxi) {
        prev = maxi;
        for (int i = 1; i < n - cnt; i++) {
            if ((s[i] - '0') - 1 > (s[i - 1] - '0')) { 
                s[i] = (s[i] - '0' - 1) + '0';        
                swap(s[i], s[i - 1]);
                maxi = max(maxi, stoll(s));           
            }
        }
    }

    cout << maxi << endl;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    if (t) cin >> t; else t = 1;
    while (t--) solve();
    return 0;
}


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

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

    int prev = -1;
    int maxi = 0;

    try {
        maxi = stoll(s); 
    } catch (const out_of_range&) {
        return;
    }

    while (prev != maxi) {
        prev = maxi;
        for (int i = 1; i < n; i++) {
            if ((s[i] - '0') - 1 > (s[i - 1] - '0')) { 
                s[i] = (s[i] - '0' - 1) + '0'; // Decrease the digit
                swap(s[i], s[i - 1]);         // Swap with previous character
                
                try {
                    maxi = max(maxi, stoll(s));
                } catch (const out_of_range&) {
                    // Undo invalid changes
                    s[i] = (s[i] - '0' + 1) + '0';
                    swap(s[i], s[i - 1]);
                }
            }
        }
    }

    cout << maxi << endl;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

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

    int prev = -1;
    int maxi = 0;

    try {
        maxi = stoll(s); 
    } catch (const out_of_range&) {
        return;
    }

    while (prev != maxi) {
        prev = maxi;
        for (int i = 1; i < n; i++) {
            if ((s[i] - '0') - 1 > (s[i - 1] - '0')) { 
                s[i] = (s[i] - '0' - 1) + '0'; // Decrease the digit
                swap(s[i], s[i - 1]);         // Swap with previous character
                
                try {
                    maxi = max(maxi, stoll(s));
                } catch (const out_of_range&) {
                    // Undo invalid changes
                    s[i] = (s[i] - '0' + 1) + '0';
                    swap(s[i], s[i - 1]);
                }
            }
        }
    }

    cout << maxi << endl;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}


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

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

    while (true) {
        bool changed = false;

        for (int i = 1; i < n; i++) {
            if ((s[i] - '0') - 1 >= 0 && (s[i] - 1) > s[i - 1]) {
                s[i] = (s[i] - '0' - 1) + '0'; 
                swap(s[i], s[i - 1]);         
                changed = true;
            }
        }

        if (!changed) break;
    }

    cout << s << endl;
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

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


int main() {
    
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int temp;
            cin>>temp;
            mp[temp]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}


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


int main() {
    
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int temp;
            cin>>temp;
            mp[temp]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


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

int main() {
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int t;
            cin>>t;
            mp[t]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

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

int main() {
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int t;
            cin>>t;
            mp[t]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}


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


int main() {
    
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int t;
            cin>>t;
            mp[t]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

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


int main() {
    
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int t;
            cin>>t;
            mp[t]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}


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


int main() {
    
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;
    
    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;
        
        //int a[n];
        unordered_map<int, int> mp;
        
        for(i=0;i<n;i++)
        {
            int temp;
            cin>>temp;
            mp[temp]++;
        }
        
        
        totaluniq=mp.size();
        
        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }
        
        sort(pq.begin(), pq.end());
        int ctr=0;
        
        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;
            
            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }
        
        cout<<totaluniq<<endl;
        }
    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;



#define ll long long int

#define ull unsigned long long int

#define ld long double

#define vi vector<int>

#define vll vector<ll>

#define pii pair<int, int>

#define pll pair<ll, ll>

#define mp make_pair

#define pb push_back

#define F first

#define S second

#define ALL(v) v.begin(), v.end()

#define SORT(v) sort(ALL(v))

#define REVERSE(v) reverse(ALL(v))

#define FOR(i, a, b) for (int i = a; i < b; ++i)

#define FORD(i, a, b) for (int i >= b; --i)

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)



const ll MOD = 1e9 + 7;

const ll INF = 1e18;

const ld EPS = 1e-9;



ll gcd(ll a, ll b) {

    while (b != 0) {

        ll temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}



ll lcm(ll a, ll b) {

    return (a / gcd(a, b)) * b;

}



ll mod_exp(ll base, ll exp, ll mod) {

    ll result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod;

        }

        base = (base * base) % mod;

        exp /= 2;

    }

    return result;

}



bool is_prime(ll n) {

    if (n <= 1) return false;

    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (ll i = 5; i * i <= n; i += 6) {

        if (n % i == 0 || n % (i + 2) == 0) return false;

    }

    return true;

}



void solve() {

    // Your solution code here

    ll n,l,r;

    cin>>n>>l>>r;

    vll pre,seg,next;

    ll a;

    FOR(i,0,n){

        cin>>a;

        if(i<l-1){

          pre.push_back(a);

        }else if(i>=l-1 && i<r){

          seg.push_back(a);

        }else{

            next.push_back(a);

        }

    }



    SORT(pre);

    SORT(seg);

    REVERSE(seg);

    SORT(next);



    ll i = 0;

    ll j = 0;

    ll sum1 = 0;

    ll sum2 = 0;

    ll sol = INT_MIN;

    while(i<pre.size() && j<seg.size()){

        sum1+=pre[i];

        sum2+=seg[j];

        i++;

        j++;

        sol = max(sol,sum2-sum1);

    }

    i = 0;

    j = 0;

    sum1 = 0;

    sum2 = 0;

    while(i<next.size() && j<seg.size()){

       sum1+=next[i];

       sum2+=seg[j];

       sol = max(sol,sum2-sum1);

       i++;

       j++;

    }



    ll sum = accumulate(ALL(seg),0);

    if(sol>0){

        cout<<sum-sol<<endl;

    }else{

        cout<<sum<<endl;

    }

}



int main() {

    FAST_IO;



    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 1):
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define Yes cout<<"YES\n"
#define No cout<<"NO\n"
#define no cout<<"No\n"
#define yes cout<<"Yes\n"
#define all(v) v.begin(),v.end()
#define inp(arr) for(auto &it:arr) cin>>it;
#define outp(arr) for(auto &it:arr) cout<<it<<" ";cout<<endl;
#define sum(arr) accumulate(all(arr),0);
#define what_is(val1) cout<<#val1<<": "<<val1<<endl;
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mach_speed  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
const int mod=1000000007;
const int INF=1000000000;

void solve() {
  int n;cin>>n;
  int arr[n];
  inp(arr);
  vector<pair<int,int>> ans;
  int val=1;
  map<int,int> mp,mp2;
  for (int i = 0; i < n; i++)
  {
    mp2[arr[i]]++;
    for (int j = arr[i]; j <= n; j++)
    {
      if(mp2[j]==0){
        ans.push_back({arr[i],j});
        ans.push_back({j,arr[i]});
      }
    }
  }
  
  for (int i = 0; i < n; i++)
  {
    if(arr[i]>val){
      for (int j = arr[i]-1; j >= val; j--)
      {
        if(mp[j]==0)  ans.push_back({arr[i],j});
      }
    }
    else{
      mp[val]++;
      while (mp[val]>0)
      {
        val++;
      }
    }
    mp[arr[i]]++;
  }
  
  cout<<ans.size()<<endl;
  for(auto it:ans) cout<<it.first<<" "<<it.second<<endl;
}

int32_t main()
{
  mach_speed    
  // #ifdef LOCAL
  // #endif
  int t=1;
  // cin>>t;
  while (t--)
  {
    // cout<<t;
    solve();
  }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define Yes cout<<"YES\n"
#define No cout<<"NO\n"
#define no cout<<"No\n"
#define yes cout<<"Yes\n"
#define all(v) v.begin(),v.end()
#define inp(arr) for(auto &it:arr) cin>>it;
#define outp(arr) for(auto &it:arr) cout<<it<<" ";cout<<endl;
#define sum(arr) accumulate(all(arr),0);
#define what_is(val1) cout<<#val1<<": "<<val1<<endl;
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mach_speed  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
const int mod=1000000007;
const int INF=1000000000;

void solve() {
  int n;cin>>n;
  int arr[n];
  inp(arr);
  vector<pair<int,int>> ans;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n-1; j++)
    {
      if(arr[j]<arr[j+1]){
        ans.push_back({arr[j],arr[j+1]});
        swap(arr[j],arr[j+1]);
      }
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n-1; j++)
    {
      if(arr[j]>arr[j+1]){
        ans.push_back({arr[j],arr[j+1]});
        swap(arr[j],arr[j+1]);
      }
    }
  }
  reverse(all(ans));
  cout<<ans.size()<<endl;
  for(auto it:ans) cout<<it.first<<" "<<it.second<<endl;
}

int32_t main()
{
  mach_speed    
  // #ifdef LOCAL
  // #endif
  int t=1;
  // cin>>t;
  while (t--)
  {
    // cout<<t;
    solve();
  }
}