ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx){
				mx=ru[i];
				f=i;
			}
		}
		int cen=0,f1=0,f2=0;
		for(int i=1;i<n;i++){
			if(a[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f1=b[i];
			}
			if(b[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f2=a[i];
			}
		}
		if(cen>=3){
			f=f1;
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
//		cout<<"ru:  ";
//		for(int i=1;i<=n;i++) cout<<ru[i]<<' ';
//		cout<<endl;
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx){
				mx=ru[i];
				f=i;
			}
		}
//		cout<<"f:  "<<f<<endl;
		int cen=0,f1=0,f2=0;
		for(int i=1;i<n;i++){
			if(a[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f1=b[i];
			}
			if(b[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f2=a[i];
			}
		}
		if(cen>=2){
			f=f1;
			
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>=mx){
				mx=ru[i];
				f=i;
			}
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>=mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx){
				mx=ru[i];
				f=i;
			}
		}
		int cen=0,f1=0,f2=0;
		for(int i=1;i<n;i++){
			if(a[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f1=b[i];
			}
			if(b[i]==f&&ru[a[i]]==ru[b[i]]){
				cen++;
				f2=a[i];
			}
		}
		if(cen>=3){
			f=f1;
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx){
				mx=ru[i];
				f=i;
			}
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}

Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>=mx){
				mx=ru[i];
				f=i;
			}
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>=mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    string s;

    cin >> t;

    while (t--) {

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto &[cur, p] = dq.front();

            dq.pop_front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    string s;

    cin >> t;

    while (t--) {

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto &[cur, p] = dq.front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

            dq.pop_front();

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

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


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto [cur, p] = dq.front();

            dq.pop_front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto [cur, p] = dq.front();

            dq.pop_front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

}

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

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    string s;

    cin >> t;

    while (t--) {

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto &[cur, p] = dq.front();

            dq.pop_front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    string s;

    cin >> t;

    while (t--) {

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto &[cur, p] = dq.front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({(cur + 2) % 9, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({(cur + 6) % 9, {p.first, p.second - 1}});

            }

            dq.pop_front();

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

}

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

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

    int t;

    string s;

    cin >> t;

    while (t--) {

        cin >> s;

        int sum = 0;

        int two = 0, three = 0;

        for (auto x : s) {

            sum += x - '0';

            if (x == '2') {

                two++;

            }

            if (x == '3') {

                three++;

            }

        }

        int diff = sum % 9;

        deque<pair<int, pair<int, int>>> dq;

        dq.push_back({0, {two, three}});

        bool yes = false;

        while (!dq.empty()) {

            auto &[cur, p] = dq.front();

            if ((cur + diff) % 9 == 0) {

                cout << "YES\n";

                yes = true;

                break;

            }

            if (p.first) {

                dq.push_back({cur + 2, {p.first - 1, p.second}});

            }

            if (p.second) {

                dq.push_back({cur + 6, {p.first, p.second - 1}});

            }

            if (cur > 1024) break;

            dq.pop_front();

        }

        if (!yes) {

            cout << "NO\n";

        }

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

using namespace std;



// Short forms

#define rall(x)             x.rbegin(), x.rend()

#define lli                 long long int

#define ll                  long long

#define ull                 unsigned long long

#define nl                  '\n'

#define ff                  first

#define ss                  second

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

#define sz(x)               (int)(x).size()

#define pb                  push_back

#define mp                  make_pair



// Loops

#define nlp(i, n)           for (int i = 0; i < (int)(n); ++i)

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

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

#define llp(i,a,b)          for (ll i= (ll)(a); i < (ll)(ll)(b); ++i)



// STLs

#define pii                 pair<int, int>

#define vi                  vector<int>

#define vll                 vector<ll>

#define vvi                 vector<vector<int>>

#define vvl                 vector<vector<ll>>



// Outputs

#define yes                 cout<<"YES"<<nl

#define no                  cout<<"NO"<<nl

#define dbg(x)              cerr << #x <<" " << x << endl;



// Constants

#define PI                  3.141592653589793238

#define INF                 LONG_LONG_MAX

#define MOD                 1e9+7



// Faster Input Output

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



// Maths

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

ll nPr(ll n, ll r)     { return fact(n) / fact(n - r); }

ll nCr(ll n, ll r)     { return fact(n) / (fact(r) * fact(n - r)); }

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

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

ll mypow(ll a, ll b)   { ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }

bool isPrime(ll n)     { if(n <= 1) return false; for(ll i = 2; i <= sqrt(n); i++) if(n % i == 0) return false; return true; }



int main() {

       int t;

       cin>>t;

       while(t--)

       {

              int n;

              cin>>n;

              string str;

              cin>>str;

              bool ans=true;

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

                     if(str[i]=='s' && str[i+1]=='p') ans=false;

                     if(str[i]=='p' && str[i+1]=='s') ans=false;

              }  

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

                     if(str[i]=='p' && str[i+1]=='s') ans=false;

              }     

            if(ans) yes;

            else no;

       }

            

       return 0;

}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T,n;
    while(T--)
    {
        cin>>n;
        ll tot=0,sum=0;
        for(int i=1,t;i<=n;i++)
        {
            cin>>t;
            if(i%2==1)
                tot+=t;
            else
                sum+=t;
        }
        if(tot%((n+1)/2)!=0 or sum%(n/2)!=0 or (tot/((n+1)/2))!=sum/(n/2))
            cout<<"No\n";
        else
            cout<<"YES\n";
    }
    
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T,n;
    cin>>T;
    while(T--)
    {
        cin>>n;
        ll tot=0,sum=0;
        for(int i=1,t;i<=n;i++)
        {
            cin>>t;
            if(i%2==1)
                tot+=t;
            else
                sum+=t;
        }
        if(tot%((n+1)/2)!=0 or sum%(n/2)!=0 or (tot/((n+1)/2))!=sum/(n/2))
            cout<<"No\n";
        else
            cout<<"YES\n";
    }
    
    return 0;
}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T,n;
    while(T--)
    {
        cin>>n;
        ll tot=0,sum=0;
        for(int i=1,t;i<=n;i++)
        {
            cin>>t;
            if(i%2==1)
                tot+=t;
            else
                sum+=t;
        }
        if(tot%(n+1)/2!=0 or sum%(n/2)!=0 or(tot/(n+1)/2)!=sum/(n/2))
            cout<<"No\n";
        else
            cout<<"YES\n";
    }
    
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T,n;
    while(T--)
    {
        cin>>n;
        ll tot=0,sum=0;
        for(int i=1,t;i<=n;i++)
        {
            cin>>t;
            if(i%2==1)
                tot+=t;
            else
                sum+=t;
        }
        if(tot%((n+1)/2)!=0 or sum%(n/2)!=0 or (tot/((n+1)/2))!=sum/(n/2))
            cout<<"No\n";
        else
            cout<<"YES\n";
    }
    
    return 0;
}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T,n;
    while(T--)
    {
        cin>>n;
        ll tot=0,sum=0;
        for(int i=1,t;i<=n;i++)
        {
            cin>>t;
            if(i%2==1)
                tot+=t;
            else
                sum+=t;
        }
        if(tot%(n+1)/2!=0 or sum%(n/2)!=0 or(tot/(n+1)/2)!=sum/(n/2))
            cout<<"No\n";
        else
            cout<<"YES\n";
    }
    
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
//https://codeforces.com/problemset/problem/2052/A
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m, k;
int a[N];
int b[N];
void solve() {
    cin>>n;
    for(int i = 1; i<= n; ++i) {
        cin>>a[i];
        b[i] = i;
    }
    set<pair<int,int>> s;
    vector<pair<int,int>> ans;
    for(int i = 1; i<= n; ++i) {
        int  p = 0;
        for(int j = i; j <= n; ++j) {
            if(b[j] == a[i]) {
                p = j;
                break;
            }
        }
        for(int j = p; j > i; --j) {
            int jj = j - 1;
            int t1 = b[j],t2 = b[jj];
            ans.push_back({t1,t2});
            if(t2 > t1) swap(t1,t2);
            swap(b[j],b[jj]);
            s.insert({t1,t2});
        }
    }
    for(int i = 1; i< n; ++i) {
        int t1 = b[i],t2 = b[i+1];
        if (t2 > t1) swap(t1, t2);
        if(!s.count({t1,t2})) {
            ans.push_back({t1,t2});
            ans.push_back({t2,t1});
        }
    }
    cout<<ans.size()<<"\n";
    for(auto [x,y] : ans) {
        cout<<x <<' '<<y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}

Submission (verdict: Wrong answer on test 4):
//https://codeforces.com/problemset/problem/2052/A
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m, k;
int a[N];
int b[N];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = i;
    }
    set<pair<int, int>> s;
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; ++i) {
        int  p = 0;
        for (int j = i; j <= n; ++j) {
            if (b[j] == a[i]) {
                p = j;
                break;
            }
        }
        for (int j = p; j > i; --j) {
            int jj = j - 1;
            int t1 = b[j], t2 = b[jj];
            ans.push_back({ t1,t2 });
            if (t2 > t1) swap(t1, t2);
            swap(b[j], b[jj]);
            s.insert({ t1,t2 });
        }
    }
    int t = 0;
    vector<int> tt;
    for (int i = 1; i <= n; ++i) {
        if (b[i] > t) {
            t = b[i];
        } else {
            t = b[i];
            tt.clear();
        }
        tt.push_back(t);
        if (tt.size() >= 2) {
            int pp = tt.size();
            while (pp--)
                for (int j = tt.size() - 1; j >= 1; --j) {
                    ans.push_back({ tt[j],tt[j - 1] });
                    swap(tt[j], tt[j - 1]);
                }
        }
    }
    cout << ans.size() << "\n";
    for (auto [x, y] : ans) {
        cout << x << ' ' << y << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}