ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define vi vector<ll>
#define pb push_back
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define endl "\n"
const ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//.......................................................................................................................................................................................................................................................................
 

void solve(){ 
     
 ll q;
 cin>>q;
 vector<ll>adj(q+1,0);
 for(int i=0;i<q-1;i++){
    ll x,y;
    cin>>x>>y;
    adj[x]++;
    adj[y]++; 
 }
 
 ll count=0;
 multiset<ll>st;
 for(auto it:adj){
   st.insert(it);
 }
 debug(st);
 if(st.size()<=3){
    cout<<0<<endl;
    return;
 }
 ll maxi=*st.rbegin();
 st.erase(st.find(maxi));
 ll smaxi=*st.rbegin();
 if(smaxi==1){
   cout<<maxi-1<<endl;
 }else{
   cout<<maxi+smaxi-1<<endl; 
 }
 





} 

 
 
int main() {

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("ooutput.txt", "w", stdout);
#endif
 
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0); 
ll t;
cin>>t; 
 
  
while (t--) { 
    
solve();
}

 
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 1):
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <vector>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <numeric>  
#include <queue>
#include <stack>
#include <limits.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define ASORT(a, n) sort(a, a + n)
// nonstrict lower bound of x in a
#define LB(a, x) lower_bound(a.begin(), a.end(), x)
#define UB(a, x) upper_bound(a.begin(), a.end(), x)
// returns a pair of iterators representing [first, last)]
#define ER(a, x) equal_range(a.begin(), a.end(), x)

const int MOD = 1000000007;
const char nl = '\n';

template <typename Container>
void print(const Container& c) {
    for (const auto& elem : c) {
        cout << elem << " ";
    }
    cout << nl;
}

void solve() {
    int n, m; cin >> n >> m;
    multiset<int> a;
    multiset<int> b;
    int x;
    FOR(i, 0, n) {
        cin >> x; a.insert(x);
    }
    FOR(i, 0, m) {
        cin >> x; 
        if (a.count(x)) a.erase(a.find(x));
        else b.insert(x);
    }
    // remove all overlaps with a and b
    // take the maximum of b repeatedly 
    while (a.size() > b.size()) {
        x = *prev(b.end());
        if (x < *prev(a.end())) {
            // impossible to recoover
            break;
        }
        b.erase(x);
        int y = x/2;
        int z = (x+1)/2;
        if (a.count(y)) a.erase(a.find(y));    
        else b.insert(y);
        if (a.count(z)) a.erase(a.find(z));    
        else b.insert(z);
    }


    if (a.size() == 0) cout << "YES" << nl;
    else cout << "NO" << nl;

    // we will resign when size(a) > size(b)
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    int t; cin >> t;
    FOR(i, 0, t) {
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        int n;
        cin >> n;  // Length of the array
        vector<int> a(n);

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

        // Check only the first two elements
        if (a[0] <= a[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

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

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        int n;
        cin >> n;  // Length of the array
        vector<int> a(n);

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

        // Check only the first two elements
        if (a[0] <= a[1]) {
            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;  // Number of test cases

    while (t--) {
        int n;
        cin >> n;  // Length of the array
        vector<int> a(n);

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

        // Check conditions between the first two elements
        if (a[0] < a[1]) {
            cout << "YES" << endl;  // Condition 1: 1st is smaller than 2nd
        } else if (a[0] == a[1]) {
            cout << "No" << endl;  // Condition 2: 1st is equal to 2nd
        } else {
            cout << "NO" << endl;   // Condition 3: 1st is greater than 2nd
        }
    }

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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        int n;
        cin >> n;  // Length of the array
        vector<int> a(n);

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

        // Check conditions between the first two elements
        if (a[0] < a[1]) {
            cout << "YES" << endl;  // Condition 1: 1st is smaller than 2nd
        } else if (a[0] == a[1]) {
            cout << "No" << endl;  // Condition 2: 1st is equal to 2nd
        } else {
            cout << "NO" << endl;   // Condition 3: 1st is greater than 2nd
        }
    }

    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
using namespace std;

bool sol() {
    int n;
    cin >> n;  // Length of the array
    vector<int> a(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];  // Input the array elements
    }

    for (int i = 0; i < n - 1; ++i) {
        if (a[i] > a[i + 1]) {
            return false;  // If a[i] > a[i+1], the sequence can't be non-decreasing
        }
        a[i + 1] -= a[i];  // Subtract a[i] from a[i+1]
    }

    return true;  // If the loop completes, the sequence can be made non-decreasing
}

int main() {
    int t;
    cin >> t;  // Number of test cases

    while (t--) {
        cout << (sol() ? "YES" : "NO") << endl;
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else if(n==1)
            cout<<"1"<<endl;
        else {
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        
        int t=l;
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                cout<<t<<endl;
                break;
            }
            else if(k==fq[i])
            {
                cout<<t-1<<endl;
                break;
            }
            else{
                k=k-fq[i];
                t--;
            }
        }           
       
        }
    }
    return 0;
}   

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        bool printed=false;
        cin>>n>>k;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a.begin(),a.end());
        vector<int>c={1};
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])
                c.back()++;
            else
                c.emplace_back(1);
        }
        sort(c.begin(),c.end());
        int l=c.size();
        for(int i=0;i<l-1;i++)
        {
            if(c[i]>k)
            {
            cout<<l-i<<endl;
            printed=true;
            break;
            }
            else
            k=k-c[i];
        }
        if(printed==false)
        cout<<1<<endl;

    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 13):
#include<bits/stdc++.h>
#define endl '\n'
#define int long long int
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else {
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;
        }
    }
    return 0;
}   

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else if(n==1)
            cout<<"1"<<endl;
        else {
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        
        int t=l;
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                cout<<t<<endl;
                break;
            }
            else if(k==fq[i])
            {
                cout<<t-1<<endl;
                break;
            }
            else{
                k=k-fq[i];
                t--;
            }
        }           
       
        }
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define endl '\n'
#define int long long int
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;
    }
    return 0;
}   

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else if(k=0)
            cout<<"n"<<endl;
        else    
        {unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;}
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include<bits/stdc++.h>
#define endl '\n'
#define int long long int
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else if(k=0)
            cout<<"n"<<endl;
        else    
        {unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;}
    }
    return 0;
}   

Submission (verdict: Time limit exceeded on test 13):
#include<bits/stdc++.h>
#define endl '\n'
#define int long long int
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,l,ans=1;
        cin>>n>>k;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        if(k>=n)
            cout<<"1"<<endl;
        else {
        unordered_map <int,int> mp;
        vector<int>fq;
        for(int i=0;i<n;i++)
            mp[arr[i]]++;
        for (auto& i : mp)
            {
                fq.emplace_back(i.second);
            }  
        sort(fq.begin(),fq.end());  
        l=fq.size();
        for(int i=0;i<l-1;i++)
        {
            if(k<fq[i])
            {
                ans++;
            }
            else{
                k=k-fq[i];
            }
        }           
        cout<<ans<<endl;
        }
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        vector<int> a(n);
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        for(int i = 0; i < n - 1; i++){
            if (a[i] != 0) p = 1;
        }
        if (p == 0)cout << "yes\n"; else cout << "no\n";
    }

    return 0;
}

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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        int a[n];
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        cout << (is_sorted(a, a + n) ? "YES\n" : "NO\n");
    }

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


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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        int a[n];
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        for(int i = 0; i < n - 1; i++){
            if (a[i] != 0) p = 1;
        }
        if (p == 0)cout << "yes\n"; else cout << "no\n";
    }

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

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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        int a[n];
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        cout << (is_sorted(a, a + n) ? "YES\n" : "NO\n");
    }

    return 0;
}

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

using namespace std;
int t, a[200009], n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> t;
    
    while(t--){
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        cout << (is_sorted(a, a + n) ? "YES\n" : "NO\n");
    }

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

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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        int a[n];
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        for(int i = 0; i < n - 1; i++){
            if (a[i] != 0) p = 1;
        }
        if (p == 0)cout << "yes\n"; else cout << "no\n";
    }

    return 0;
}

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

using namespace std;


int main() {
   int t;
    cin >> t;
    
    while(t--){
        int n, p = 0;
        vector<int> a(n);
        cin >> n;
        
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        for(int i = 0; i < n - 1; i++){
            int k = min(a[i], a[i + 1]);
            a[i] -= k;
            a[i + 1] -= k;
        }
        
        for(int i = 0; i < n - 1; i++){
            if (a[i] != 0) p = 1;
        }
        if (p == 0)cout << "yes\n"; else cout << "no\n";
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 4):
// Problem: A. Adrenaline Rush
// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
// URL: https://codeforces.com/problemset/problem/2052/A
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, long long> pil;
typedef pair<long long, int> pli;

const int M = 1e9+7;
const int N = 2e6 + 10;
int a[N], b[N];
int l[N], r[N];
char g[110][110];
char mapp[110][110];
bool st[110][110];
int n, m;

void solve() {
	cin >> n;
	for(int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	
	vector<pii> ans;
	
	for(int i = n;i >= 1;i --) {
		if(a[i] < i) {
			for(int j = a[i] + 1;j <= i;j ++) {
				ans.push_back({j, a[i]});
			}
		} else {
			if(i == 1) break;
			ans.push_back({a[i], a[i - 1]});
			ans.push_back({a[i - 1], a[i]});
		}
	}
	
	cout << ans.size() << endl;
	for(auto t : ans) {
		cout << t.first << " " << t.second << endl;
	}
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}