ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#include <vector>

using namespace std;



void solve()

{

    int n;

    cin >> n;

    vector<int> a(n);



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

    {

        cin >> a[i];

    }



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

    {

        if (a[i] > a[i + 1]) 

        {

            int diff = a[i] - a[i + 1];

            a[i] -= diff;  // Reduce both a[i] and a[i+1] by 'diff'

            a[i + 1] -= diff;

        }

        if (a[i] > a[i + 1]) 

        {

            cout << "NO" << endl;

            return;

        }

    }



    cout << "YES" << endl;

}



int main()

{

    int t;

    cin >> t;



    while (t--) 

    {

        solve();

    }



    return 0;

}



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

using namespace std;

using ll = long long;



void solve() {

    ll n;

    cin >> n;

    vector<ll> a(n);

    

    for (ll &x : a) cin >> x;



    ll last = 0;

    

    // Find the last position where a[i] > a[i+1]

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

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

    }



    // If already sorted, return YES

    if (last == 0) {

        cout << "YES\n";

        return;

    }



    // Apply the operation

    for (ll i = 0; i < last; i++) {

        ll min_val = min(a[i], a[i + 1]);

        a[i] -= min_val;

        a[i + 1] -= min_val;

    }



    // Check if sorted after operations

    cout << (is_sorted(a.begin(), a.end()) ? "YES" : "NO") << '\n';

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    ll t;

    cin >> t;

    while (t--) solve();

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#include<vector>



using namespace std;



void solve()

{

    int n;

    

    cin>>n;

    

    vector<int> a(n);

    

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

    {

        cin >> a[i];

    }

    

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

    {

        if(a[i]>a[i+1])

        {

            cout << "NO"<<endl;

            return;

        }

    }

    

    cout << "YES"<<endl;

}



int main()

{

    int t;

    

    cin>>t;

    

    while(t--)

    {

        solve();

    }

    

    return 0;

}

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

#include <vector>

using namespace std;



void solve()

{

    int n;

    cin >> n;

    vector<int> a(n);



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

    {

        cin >> a[i];

    }



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

    {

        if (a[i] > a[i + 1]) 

        {

            int diff = a[i] - a[i + 1];

            a[i] -= diff;  // Reduce both a[i] and a[i+1] by 'diff'

            a[i + 1] -= diff;

        }

        if (a[i] > a[i + 1]) 

        {

            cout << "NO" << endl;

            return;

        }

    }



    cout << "YES" << endl;

}



int main()

{

    int t;

    cin >> t;



    while (t--) 

    {

        solve();

    }



    return 0;

}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

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

#define ll long long

#define ull unsigned long long

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

#define pqueue priority_queue

using namespace std;

ll get(ll n, ll i) { return (n&(1ll<<i)) ? 1 : 0; }

ll on(ll n, ll i) { return (n|(1ll<<i)); }

ll off(ll n, ll i) { return (n&(~(1ll<<i))); }

ll flip(ll n, ll i) { return (n^(1ll<<i)); }

void setIO(string name = "") {

    if (name.size()) {

        freopen((name + ".in").c_str(), "r", stdin);

        freopen((name + ".out").c_str(), "w", stdout);

    }

}

int main ()

{

    fast;

    //setIO("guess");

    int t; cin>>t;

    while (t--)

    {

        int n, pos = 0; cin>>n;

        string s, ans = "YES\n"; cin>>s;

        map<int, int> mp, mp2;

        ++mp2[s[0]];

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

            if (s[i] == 's')

                ++mp[n-i], ++mp2[s[i]];

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

            if (s[i] == 'p')

            {

                ++mp[i+1], ++mp2[s[i]];

                if (mp[i+1] > 1)

                    ans = "NO\n";

            }

        if (mp2['s'] and mp2['p'])

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

                if (s[i] == 'p')

                    pos = 1;

                else if (s[i] == 's' and pos)

                    ans = "NO\n";

        cout<<ans;

    }

}

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

#define ll long long

#define ull unsigned long long

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

#define pqueue priority_queue

using namespace std;

ll get(ll n, ll i) { return (n&(1ll<<i)) ? 1 : 0; }

ll on(ll n, ll i) { return (n|(1ll<<i)); }

ll off(ll n, ll i) { return (n&(~(1ll<<i))); }

ll flip(ll n, ll i) { return (n^(1ll<<i)); }

void setIO(string name = "") {

    if (name.size()) {

        freopen((name + ".in").c_str(), "r", stdin);

        freopen((name + ".out").c_str(), "w", stdout);

    }

}

int main ()

{

    fast;

    //setIO("guess");

    int t; cin>>t;

    while (t--)

    {

        int n, p = 0, ss = 0; cin>>n;

        string s; cin>>s;

        if (s[n-1] == 'p')

            s[n-1] = '.';

        if (s[0] == 's')

            s[0] = '.';

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

            if (s[i] == 's')

                ss = 1;

            else if (s[i] == 'p')

                p = 1;

        if (ss and p)

            cout<<"NO\n";

        else

            cout<<"YES\n";

    }

}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

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

#define ll long long

#define ull unsigned long long

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

#define pqueue priority_queue

using namespace std;

ll get(ll n, ll i) { return (n&(1ll<<i)) ? 1 : 0; }

ll on(ll n, ll i) { return (n|(1ll<<i)); }

ll off(ll n, ll i) { return (n&(~(1ll<<i))); }

ll flip(ll n, ll i) { return (n^(1ll<<i)); }

void setIO(string name = "") {

    if (name.size()) {

        freopen((name + ".in").c_str(), "r", stdin);

        freopen((name + ".out").c_str(), "w", stdout);

    }

}

int main ()

{

    fast;

    //setIO("guess");

    int t; cin>>t;

    while (t--)

    {

        int n, pos = 0; cin>>n;

        string s, ans = "YES\n"; cin>>s;

        map<pair<int, int>, int> mp;

        map<char, int> mp2;

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

        {

            ++mp2[s[i]];

            if (s[i] == 'p' and i!=n-1)

            {

                ++mp[{1, i+1}];

                if (mp[{1, i+1}] == 2)

                    ans = "NO\n";

            }

            else if (s[i] == 's' and i)

            {

                ++mp[{1, n-i}];

                if (mp[{1, n-i}] == 2)

                    ans = "NO\n";

            }

        }

        if (mp2['s']>1 and mp2['p']>1)

            ans = "NO\n";

        if (mp2['s'] and mp2['p'])

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

                if (s[i] == 'p')

                    pos = 1;

                else if (s[i] == 's' and pos)

                    ans = "NO\n";

        cout<<ans;

    }

}

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

#define ll long long

#define ull unsigned long long

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

#define pqueue priority_queue

using namespace std;

ll get(ll n, ll i) { return (n&(1ll<<i)) ? 1 : 0; }

ll on(ll n, ll i) { return (n|(1ll<<i)); }

ll off(ll n, ll i) { return (n&(~(1ll<<i))); }

ll flip(ll n, ll i) { return (n^(1ll<<i)); }

void setIO(string name = "") {

    if (name.size()) {

        freopen((name + ".in").c_str(), "r", stdin);

        freopen((name + ".out").c_str(), "w", stdout);

    }

}

int main ()

{

    fast;

    //setIO("guess");

    int t; cin>>t;

    while (t--)

    {

        int n, pos = 0; cin>>n;

        string s, ans = "YES\n"; cin>>s;

        map<int, int> mp, mp2;

        ++mp2[s[0]];

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

            if (s[i] == 's')

                ++mp[n-i], ++mp2[s[i]];

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

            if (s[i] == 'p')

            {

                ++mp[i+1], ++mp2[s[i]];

                if (mp[i+1] > 1)

                    ans = "NO\n";

            }

        if (mp2['s'] and mp2['p'])

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

                if (s[i] == 'p')

                    pos = 1;

                else if (s[i] == 's' and pos)

                    ans = "NO\n";

        cout<<ans;

    }

}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)


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

#define ll long long

#define ull unsigned long long

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

#define pqueue priority_queue

using namespace std;

ll get(ll n, ll i) { return (n&(1ll<<i)) ? 1 : 0; }

ll on(ll n, ll i) { return (n|(1ll<<i)); }

ll off(ll n, ll i) { return (n&(~(1ll<<i))); }

ll flip(ll n, ll i) { return (n^(1ll<<i)); }

void setIO(string name = "") {

    if (name.size()) {

        freopen((name + ".in").c_str(), "r", stdin);

        freopen((name + ".out").c_str(), "w", stdout);

    }

}

int main ()

{

    fast;

    //setIO("guess");

    int t; cin>>t;

    while (t--)

    {

        int n, pos = 0; cin>>n;

        string s, ans = "YES\n"; cin>>s;

        map<pair<int, int>, int> mp;

        map<char, int> mp2;

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

        {

            ++mp2[s[i]];

            if (s[i] == 'p' and i!=n-1)

            {

                ++mp[{1, i+1}];

                if (mp[{1, i+1}] == 2)

                    ans = "NO\n";

            }

            else if (s[i] == 's' and i)

            {

                ++mp[{1, n-i}];

                if (mp[{1, n-i}] == 2)

                    ans = "NO\n";

            }

        }

        if (mp2['s']>1 and mp2['p']>1)

            ans = "NO\n";

        if (mp2['s'] and mp2['p'])

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

                if (s[i] == 'p')

                    pos = 1;

                else if (pos)

                    ans = "NO\n";

        cout<<ans;

    }

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


Submission (verdict: Runtime error on test 2):
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <iterator>

using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define debug(x) cerr << #x << " = " << (x) << endl;
#define NN cout << '\n'
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

//************************************************************************************
//************************************************************************************

int32_t main()
{
    FAST int t = 1;
    int C = 1;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        int ans = 0;
        if(n==k){
            cout<<1;
            NN;
            continue;
        }
        map<int, int> freq;
        priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;

        int x;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            freq[x]++;
        }
        for (auto i = freq.begin(); i != freq.end(); i++)
        {
            pq.push(mp(i->ss, i->ff));
            ans++;
        }

        while (k)
        {
            int cur = pq.top().first;
            int s=pq.top().ss;
            if (k >= cur)
            {
                k -= cur;
                ans--;
                pq.pop();
            }
            else
                break;
        }
        cout << ans;
        NN;
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


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

vector<bool> is_prime;

void sieve(ll n) {
    is_prime.assign(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2; i * i <= n; i++) {
        if (is_prime[i]) {
            for (ll j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
}

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

/*
1. Read question carefully
2. generalize the logic
3. convert it to mathematical equation
4. !!!!! don't think  (CHECK) again until you get wrong answer
5. write the code
*/

void solve() {
     ll n;
    cin>>n; // number of nodes;
    vector<pair<ll,ll>>edges(n-1); 
    map<pair<ll,ll>,ll>mp;
    for(ll i=0;i<n-1;i++){
        cin>>edges[i].first>>edges[i].second;
        if(edges[i].first>edges[i].second){
            swap(edges[i].first,edges[i].second);
        }
        mp[{edges[i].first,edges[i].second}]=1;
    }

    // prepraing adjacency list 
    vector<ll>degree(n,0);
    vector<vector<ll>>list(n,vector<ll>());
    for(ll i=0;i<n-1;i++){
        ll a=edges[i].first;
        ll b=edges[i].second;
        a--;
        b--;

        list[a].push_back(b);
        list[b].push_back(a);
        degree[a]++;
        degree[b]++;

    }


    vector<pair<ll,ll>>ans;

    // degree,node

    for(ll i=0;i<n;i++){
        ans.push_back({degree[i],i});
    }
    sort(ans.rbegin(),ans.rend());
    
    ll s1=ans[0].first; // max degree
     ll s2=ans[1].first;// low 

    ll max1=ans[0].second;

    vector<ll>help;

    for(ll i=1;i<ans.size();i++){
        if(ans[i].first==s2){
            help.push_back(ans[i].second);
        }
    }
    // for(ll i=0;i<ans.size();i++){
        
    //        cout<<ans[i].first<<" "<<ans[i].second<<endl;
        
    // }
    

    // cout<<endl;
    // cout<<endl;

    
    vector<ll>unconet;
    vector<ll>con;

    for(ll i=0;i<help.size();i++){
        if(mp.find({max1+1,help[i]+1})!=mp.end() || mp.find({help[i]+1,max1+1})!=mp.end() ){
            con.push_back(help[i]);
        }
        else{
            unconet.push_back(help[i]);
            
        }
    }
    

    // for(auto it:unconet){
    //     cout<<it<<" ";
    // }
    // cout<<"||||";

    // cout<<'u'<<endl;

    // for(auto it:con){
    //     cout<<it<<" ";
    // }
    // cout<<endl;
    // cout<<1<<endl;;
    if(unconet.size()==0){

        ll a=con[0];
        ll dega=list[a].size();
        cout<<s1+dega-2<<endl;

    }
    else{

        ll a=unconet[0];
        // cout<<a<<" ";
        ll dega=list[a].size();
        cout<<s1+dega-1<<endl;

    }


  


  
}

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

    ll test = 1;
    cin >> test;
    while (test--) {
        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>
using namespace std;
#define int long long

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[x]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[z]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}
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 int long long

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[x]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[y],q[z]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[x]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

void swapping(vector<pair<int,int>>&q,vector<int>w,int y){
  int z=y;
  while(z>0){
    q.push_back({w[y],w[z-1]});
    z=z-1;
    
    
  }
  while(z<y){
    q.push_back({w[z],w[y]});
    z=z+1;
  }
}
int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n),w(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
      w[i]=i+1;
    }
    vector<pair<int,int>>q;
    for(int i=1;i<=n;i++){
      int x=-1,y=-1;
      for(int j=0;j<n;j++){
        if(v[j]==i) x=j;
      }
       for(int j=0;j<n;j++){
        if(w[j]==i) y=j;
      }
      if(x>=y){
        swapping(q,w,y);
        int z=y;
        while(z<x){
          q.push_back({w[z+1],w[z]});
          swap(w[z+1],w[z]);
          z++;
          
        }
        
      }
      else{
        int z=y;
        while(z>x){
          q.push_back({w[z],w[z-1]});
          swap(w[z],w[z-1]);
          z--;
        }
        swapping(q,w,x);
      }
      
      
      
    }
    cout<<q.size()<<endl;
    for(int i=0;i<q.size();i++){
      cout<<q[i].first<<" "<<q[i].second<<endl;
    }
}

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[x]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[y],q[z]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[z]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<pair<int,int>>ans;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
      vector<int>q;
      for(int j=i;j<n;j++){
        q.push_back(v[j]);
      }
      sort(q.begin(),q.end());
      int x=-1,y=q.size()-1;
      for(int j=0;j<q.size();j++){
        if(q[j]==v[i]) x=j;
      }
      int z=x;
      while(x<y){
        ans.push_back({q[x+1],q[z]});
        x++;
        
      }
      while(z<y){
        ans.push_back({q[z],q[y]});
        y--;
      }
      while(z>0){
        ans.push_back({q[z],q[z-1]});
        swap(q[z],q[z-1]);
        z--;
      }
      
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

void swapping(vector<pair<int,int>>&q,vector<int>w,int y){
  int z=y;
  while(z>0){
    q.push_back({w[y],w[z-1]});
    z=z-1;
    
    
  }
  while(z<y){
    q.push_back({w[z],w[y]});
    z=z+1;
  }
}
int32_t main() 
{
    int n;
    cin>>n;
    vector<int>v(n),w(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
      w[i]=i+1;
    }
    vector<pair<int,int>>q;
    for(int i=1;i<=n;i++){
      int x=-1,y=-1;
      for(int j=0;j<n;j++){
        if(v[j]==i) x=j;
      }
       for(int j=0;j<n;j++){
        if(w[j]==i) y=j;
      }
      if(x>=y){
        swapping(q,w,y);
        int z=y;
        while(z<x){
          q.push_back({w[z+1],w[z]});
          swap(w[z+1],w[z]);
          z++;
          
        }
        
      }
      else{
        int z=y;
        while(z>x){
          q.push_back({w[z],w[z-1]});
          swap(w[z],w[z-1]);
          z--;
        }
        swapping(q,w,x);
      }
      
      
      
    }
    cout<<q.size()<<endl;
    for(int i=0;i<q.size();i++){
      cout<<q[i].first<<" "<<q[i].second<<endl;
    }
}