ShaysXIA/CodeInsightBench huggingface dataset:
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 int long long



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = 0;

    if(a[0] < a[1]) {

        cout << "YES" << endl;

        return;

    }

    if(a[0] > a[1]){

        cout << "NO" << endl;

        return;

    }

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

        if(a[i-1] > a[i]) idx = i;

    }

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

        int mini = min(a[i], a[i+1]);

        a[i] -= mini;

        a[i+1] -= mini;

    }

    cout << (is_sorted(all(a)) ? "YES" : "NO") << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

}

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

using namespace std;



#define int long long



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = 0;



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

        if(a[i-1] > a[i]) idx = i;

    }

    if(idx == 0){

        cout << "YES" << endl;

        return;

    }

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

        int mini = min(a[i], a[i+1]);

        a[i] -= mini;

        a[i+1] -= mini;

    }

    cout << (is_sorted(all(a)) ? "YES" : "NO") << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int t;

    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 1):
#include <bits/stdc++.h>

using namespace std;



#define int long long



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = -1;

    if(a[0] < a[1]) {

        cout << "YES" << endl;

        return;

    }

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

        if(a[0] == a[i]) idx = i;

        else break;

    }

    cout << idx << endl;

    if(idx == -1 || idx == n-1 || a[idx+1] < a[idx+2]) cout << "YES" << endl;

    else cout << "NO" << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

}

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

using namespace std;



#define int long long



#define all(a) a.begin(), a.end()

#define pb push_back

#define yes cout << "Yes\n"

#define no cout << "No\n"

#define F first

#define S second



const int MOD = 1e9 + 7;



template <typename T>

istream &operator>>(istream &istream, vector<T> &v){

    for (auto &it : v)

        cin >> it;

    return istream;

}

template <typename T>

ostream &operator<<(ostream &ostream, vector<T> &v){

    for (auto &it : v)

        cout << it << ' ';

    return ostream;

}



template <typename T>

vector<T> prefixsum(const vector<T> &a){

    int n = a.size();

    vector<T> psum(n, 0);

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

        psum[i] = psum[i - 1] + a[i];

    return psum;

}





void solve(){

    int n;

    cin >> n;

    vector<int> a(n);

    cin >> a;

    int idx = -1;

    if(a[0] < a[1]) {

        cout << "YES" << endl;

        return;

    }

    if(a[0] > a[1]){

        cout << "NO" << endl;

        return;

    }

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

        if(a[0] == a[i]) idx = i;

        else break;

    }

    // cout << idx << endl;

    if(idx == -1 || idx == n-1 || a[idx+1] < a[idx+2]) cout << "YES" << endl;

    else cout << "NO" << endl;

}



int32_t main(){



    ios::sync_with_stdio(false);

    cin.tie(nullptr);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int t;

    cin >> t;



    while (t--)

        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;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(a[i] - a[i - 1] <= a[i + 1]){
                        a[i] -= a[i - 1];
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}
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;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(i >= 2 && a[i] - a[i - 1] + a[i - 2] <= a[i + 1]){
                        a[i] -= a[i - 1];
                        a[i - 1] = 0;
                    }
                    else if(a[i] - a[i - 1] <= a[i + 1]){
                        a[i] -= a[i - 1];
                        a[i - 1] = 0;
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        for (int i = 1; i < n; i++ ){
            int k = min(a[i], a[i - 1]);
            a[i] -= k;
            a[i - 1] -= k;
        }
        bool yes = true;
        for (int i = 1; i < n; i++){
            if(a[i] < a[i - 1]){
                yes = false;
                break;
            }
        }
        if(yes)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}
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;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(a[i] - a[i - 1] <= a[i + 1]){
                        a[i] -= a[i - 1];
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(a[i] - a[i - 1] <= a[i + 1] && (i + 1) % 2 == 0){
                        a[i] -= a[i - 1];
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}
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;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(a[i] - a[i - 1] <= a[i + 1] && (i + 1) % 2 == 0){
                        a[i] -= a[i - 1];
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        if(a[0] > a[1]){
            cout << "NO" << endl;
            continue;
        }
        else{
            bool yes = true;
            for (int i = 1; i < n - 1; i++){
                if(a[i + 1] < a[i]){
                    if(i >= 2 && a[i] - a[i - 1] + a[i - 2] <= a[i + 1]){
                        a[i] -= a[i - 1];
                        a[i - 1] = 0;
                    }
                    else if(a[i] - a[i - 1] <= a[i + 1]){
                        a[i] -= a[i - 1];
                        a[i - 1] = 0;
                    }
                    else{
                        yes = false;
                        continue;
                    }
                }
            }
            if(yes)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

vector<pair<int, int>> inversionCount(vector<int> &arr) {
    int n = arr.size(); 
    int invCount = 0; 
    vector<pair<int, int>>resp;
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] > arr[j])
                resp.push_back({arr[i], arr[j]});
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] <= arr[j]){
                resp.push_back({arr[i], arr[j]});
                resp.push_back({arr[j], arr[i]});
            }
    return resp;
}

void solve() {
    int n;
    cin >> n;
    vector<int>arr(n);
    for (int & i : arr)
        cin >> i;
    vector<pair<int, int>> resp = inversionCount(arr);
    cout << resp.size() << '\n';
    for (auto & [x, y] : resp)
        cout << x << ' ' << y << '\n';
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    // 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>
#define int long long
using namespace std;

vector<pair<int, int>> inversionCount(vector<int> &arr) {
    int n = arr.size(); 
    int invCount = 0; 
    vector<pair<int, int>>resp;
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] > arr[j])
                resp.push_back({arr[i], arr[j]});
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] <= arr[j]){
                resp.push_back({arr[i], arr[j]});
                resp.push_back({arr[j], arr[i]});
            }
    return resp;
}

void solve() {
    int n;
    cin >> n;
    vector<int>arr(n);
    for (int & i : arr)
        cin >> i;
    vector<pair<int, int>> resp = inversionCount(arr);
    cout << resp.size() << '\n';
    for (auto & [x, y] : resp)
        cout << x << ' ' << y << '\n';
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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


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

vector<pair<int, int>> inversionCount(vector<int> &arr) {
    int n = arr.size(); 
    int invCount = 0; 
    vector<pair<int, int>>resp;
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] > arr[j])
                resp.push_back({arr[i], arr[j]});
    int sz = resp.size();
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] <= arr[j]){
                resp.push_back({arr[i], arr[j]});
                resp.push_back({arr[j], arr[i]});
            }
    reverse(resp.begin() + sz, resp.end());
    return resp;
}

void solve() {
    int n;
    cin >> n;
    vector<int>arr(n);
    for (int & i : arr)
        cin >> i;
    vector<pair<int, int>> resp = inversionCount(arr);
    cout << resp.size() << '\n';
    for (auto & [x, y] : resp)
        cout << x << ' ' << y << '\n';
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

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

vector<pair<int, int>> inversionCount(vector<int> &arr) {
    int n = arr.size(); 
    int invCount = 0; 
    vector<pair<int, int>>resp;
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] > arr[j])
                resp.push_back({arr[i], arr[j]});
    int sz = resp.size();
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (arr[i] <= arr[j]){
                resp.push_back({arr[i], arr[j]});
                resp.push_back({arr[j], arr[i]});
            }
    reverse(resp.begin() + sz, resp.end());
    return resp;
}

void solve() {
    int n;
    cin >> n;
    vector<int>arr(n);
    for (int & i : arr)
        cin >> i;
    vector<pair<int, int>> resp = inversionCount(arr);
    cout << resp.size() << '\n';
    for (auto & [x, y] : resp)
        cout << x << ' ' << y << '\n';
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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


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

void solve() {
    vector<int>a(1010);
	int n;
    cin >> n;
	for(int i=1; i<=n; ++i)
        cin >> a[i];
	vector<pair<int,int>> ans;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<n; ++j)
			if(a[j]<a[j+1])
				swap(a[j],a[j+1]),
				ans.push_back({a[j],a[j+1]});
	for(int i=1; i<=n; ++i)
		for(int j=1; j<n; ++j)
			if(a[j]>a[j+1])
				swap(a[j],a[j+1]),
				ans.push_back({a[j],a[j+1]});
	reverse(ans.begin(),ans.end());
	cout << ans.size() << '\n';
	for(auto [x,y]:ans)
        cout << y << ' ' << x << '\n';
}

signed main() {
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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


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

bool _t(const char &cc) {return cc=='-' || (cc<='9' && cc>='0');}

template <typename Tp> 
void read(Tp &a) {
    a=0;char c;bool flg=false;
    while(!_t(c=getchar())) ;
    if(c=='-') flg=true,c=getchar();
    while(_t(c) && c!='-') {a=a*10+(c-'0');c=getchar();}
    if(flg) a=-a;
}

int wstk[45]={},wtp;
template <typename Tp>
void write(Tp a) {
    if(!a) {putchar('0');return ;}
    if(a<0) {putchar('-');a=-a;}
    while(a) {wstk[++wtp]=a%10;a/=10;} 
    while(wtp) {putchar(wstk[wtp]+'0');--wtp;}
}

template <typename Tp> 
void writeln(const Tp a) {write(a);putchar(10);}

int n;
int a[1005];
typedef pair<int,int> pii;
vector<pii> ans;

void wk() {
    read(n);
    for(int i=1;i<=n;++i) read(a[i]);
    for(int i=1;i<=n;++i) {
        if(a[i]<a[i+1]) {
            ans.push_back((pii){a[i+1],a[i]});
            ans.push_back((pii){a[i],a[i+1]});
            ++i;
        } 
    }
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n-1;++j) {
            if(a[j]>a[j+1]) {
                ans.push_back((pii){a[j],a[j+1]});
                swap(a[j],a[j+1]);
            }
        }
    }
    writeln((int)ans.size());
    reverse(ans.begin(),ans.end());
    for(auto [x,y]:ans) write(x),putchar(32),writeln(y);
}

signed main() {
    wk();

    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;
typedef long long ll;

bool _t(const char &cc) {return cc=='-' || (cc<='9' && cc>='0');}

template <typename Tp> 
void read(Tp &a) {
    a=0;char c;bool flg=false;
    while(!_t(c=getchar())) ;
    if(c=='-') flg=true,c=getchar();
    while(_t(c) && c!='-') {a=a*10+(c-'0');c=getchar();}
    if(flg) a=-a;
}

int wstk[45]={},wtp;
template <typename Tp>
void write(Tp a) {
    if(!a) {putchar('0');return ;}
    if(a<0) {putchar('-');a=-a;}
    while(a) {wstk[++wtp]=a%10;a/=10;} 
    while(wtp) {putchar(wstk[wtp]+'0');--wtp;}
}

template <typename Tp> 
void writeln(const Tp a) {write(a);putchar(10);}

int n;
int a[1005];
typedef pair<int,int> pii;
vector<pii> ans;

void wk() {
    read(n);
    for(int i=1;i<=n;++i) read(a[i]);
    for(int i=1;i<=n;++i) {
        if(a[i]<a[i+1]) {
            ans.push_back((pii){a[i+1],a[i]});
            ans.push_back((pii){a[i],a[i+1]});
            ++i;
        } 
    }
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n-1;++j) {
            if(a[j]>a[j+1]) {
                ans.push_back((pii){a[j],a[j+1]});
                swap(a[j],a[j+1]);
            }
        }
    }
    writeln((int)ans.size());
    reverse(ans.begin(),ans.end());
    for(auto [x,y]:ans) write(x),putchar(32),writeln(y);
}

signed main() {
    wk();

    return 0;
}


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

bool _t(const char &cc) {return cc=='-' || (cc<='9' && cc>='0');}

template <typename Tp> 
void read(Tp &a) {
    a=0;char c;bool flg=false;
    while(!_t(c=getchar())) ;
    if(c=='-') flg=true,c=getchar();
    while(_t(c) && c!='-') {a=a*10+(c-'0');c=getchar();}
    if(flg) a=-a;
}

int wstk[45]={},wtp;
template <typename Tp>
void write(Tp a) {
    if(!a) {putchar('0');return ;}
    if(a<0) {putchar('-');a=-a;}
    while(a) {wstk[++wtp]=a%10;a/=10;} 
    while(wtp) {putchar(wstk[wtp]+'0');--wtp;}
}

template <typename Tp> 
void writeln(const Tp a) {write(a);putchar(10);}

int n;
int a[1005];
typedef pair<int,int> pii;
vector<pii> ans;

void wk() {
    read(n);
    for(int i=1;i<=n;++i) read(a[i]);
    for(int i=1;i<=n;++i) {
        if(a[i]<a[i+1]) {
            ans.push_back((pii){a[i],a[i+1]});
            ans.push_back((pii){a[i+1],a[i]});
            ++i;
        } 
    }
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=n-1;++j) {
            if(a[j]>a[j+1]) {
                ans.push_back((pii){a[j],a[j+1]});
                swap(a[j],a[j+1]);
            }
        }
    }
    writeln((int)ans.size());
    reverse(ans.begin(),ans.end());
    for(auto [x,y]:ans) write(x),putchar(32),writeln(y);
}

signed main() {
    wk();

    return 0;
}