ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

// int dp[1001][1001];
// int valid[1001][1001];
// int t;

// int minChangedChars(string a, string b, string c)
// {
//   int i = a.size(), j = b.size();
//   if (valid[i][j] == t)
//     return dp[i][j];
//   valid[i][j] = t;
//   int acnt = 0, bcnt = 0;
//   if (a.size() == 0)
//   {
//     for (int i = 0; i < c.size(); i++)
//     {
//       if (c[i] != b[i])
//         bcnt++;
//     }
//     return dp[i][j] = bcnt;
//   }

//   if (b.size() == 0)
//   {
//     for (int i = 0; i < c.size(); i++)
//     {
//       if (c[i] != a[i])
//         acnt++;
//     }
//     return dp[i][j] = acnt;
//   }
//   acnt = minChangedChars(a.substr(1), b, c.substr(1));
//   if (a[0] != c[0])
//     acnt++;
//   bcnt = minChangedChars(a, b.substr(1), c.substr(1));
//   if (b[0] != c[0])
//     bcnt++;
//   return dp[i][j] = min(acnt, bcnt);
// }

// dp[i][j] = min(dp[i - 1][j] + a != c, dp[i][j - 1] + b != c)

int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    string a, b, c;
    cin >> a >> b >> c;
    vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, INT_MAX));
    dp[0][0] = 0;
    for (int i = 0; i <= a.size(); i++)
    {
      for (int j = 0; j <= b.size(); j++)
      {
        if (i > 0)
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[i + j - 1]));
        if (j > 0)
          dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
      }
    }
    cout << dp[a.size()][b.size()] << endl;
    // cout << minChangedChars(a, b, c) << endl;
  }
  return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int dp[1001][1001];

int minChangedChars(string a, string b, string c)
{
  int i = a.size(), j = b.size();
  if (dp[i][j] != -1)
    return dp[i][j];
  int acnt = 0, bcnt = 0;
  if (a.size() == 0)
  {
    for (int i = 0; i < c.size(); i++)
    {
      if (c[i] != b[i])
        bcnt++;
    }
    return dp[i][j] = bcnt;
  }

  if (b.size() == 0)
  {
    for (int i = 0; i < c.size(); i++)
    {
      if (c[i] != a[i])
        acnt++;
    }
    return dp[i][j] = acnt;
  }
  acnt = minChangedChars(a.substr(1), b, c.substr(1));
  if (a[0] != c[0])
    acnt++;
  bcnt = minChangedChars(a, b.substr(1), c.substr(1));
  if (b[0] != c[0])
    bcnt++;
  return dp[i][j] = min(acnt, bcnt);
}

int main()
{
  ll t;
  cin >> t;
  while (t--)
  {
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i <= a.size(); i++)
      for (int j = 0; j <= b.size(); j++)
        dp[i][j] = -1;
    cout << minChangedChars(a, b, c) << endl;
  }
  return 0;
}

Answer: 1
Problem: 2050E - Three Strings
Language: python

Code 1:
for _ in[1]*int(input()):
 s,t,u=input(),input(),input();n,m=len(s),len(t)
 inf=10**9
 d=[[inf]*(m+1)for _ in range(n+1)]
 d[0][0]=0
 for i in range(n+1):
  for j in range(m+1):
   if i==j==0:continue
   k=i+j-1
   if k>=len(u):continue
   if i>0:
    c=d[i-1][j]+(s[i-1]!=u[k])
    if c<d[i][j]:d[i][j]=c
   if j>0:
    c=d[i][j-1]+(t[j-1]!=u[k])
    if c<d[i][j]:d[i][j]=c
 print(d[n][m])

Code 2:
for _ in [0]*int(input()):
    x = input()
    y = input()
    z = input()
    n, m = len(x), len(y)
    from functools import lru_cache
    @lru_cache(None)
    def f(i, j):
        if i == j == 0:
            return 0
        k = i + j - 1
        if k >= len(z):
            return 1e9
        r = 1e9
        if i > 0:
            r = min(r, f(i - 1, j) + (x[i - 1] != z[k]))
        if j > 0:
            r = min(r, f(i, j - 1) + (y[j - 1] != z[k]))
        return r
    print(int(f(n, m)))

Answer: 1
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;

int dp[1001][1001];

int minChange(int aIndex, int bIndex, string &a, string &b, string &c) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    memset(dp, -1, sizeof dp);
    cout << minChange(0, 0, a, b, c) << endl;
  }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    return dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define MAX
using namespace std;
using ll = long long;

int na, nb;
string a, b, c;

/*
7
a
b
cb
ab
cd
acbd
ab
ba
aabb
xxx
yyy
xyxyxy
a
bcd
decf
codes
horse
codeforces
egg
annie
egaegaeg
*/

int dfs(int p1, int p2, int i, vector<vector<vector<int>>>& vis)
{
    // dfs() ----- 在当前情形下 最少还需要变几个字符
    if (vis[p1][p2][i]) {
        return vis[p1][p2][i];
    }
    if (i == na + nb) {
        if (p1 < na) {
            return vis[p1][p2][i] = (a[p1] == c[i] ? 0 : 1);
        }
        else {
            return vis[p1][p2][i] = (b[p2] == c[i] ? 0 : 1);
        }
    }
    int d = 0x3f3f3f3f;
    if (p1 < na) {
        d = dfs(p1+1, p2, i+1, vis) + (a[p1] == c[i] ? 0 : 1);
    }
    if (p2 < nb) {
        d = min(d, dfs(p1, p2+1, i+1, vis) + (b[p2] == c[i] ? 0 : 1));
    }
    return vis[p1][p2][i] = d;
}

void solve()
{
    cin >> a >> b >> c;
    na = a.length(); nb = b.length();
    vector<vector<vector<int>>> vis(na + 1, vector<vector<int>>(nb + 1, vector<int>(na + nb + 1, 0)));
    cout << dfs(0, 0, 0, vis) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen("in.txt", "r", stdin);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    system("pause");
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#define MAX
using namespace std;
using ll = long long;
#define FIND(x) (vis.find(x) != vis.end())
#define KEY(p1, p2) ((p2)*(na+1) + (p1))
#define FINDKEY(p1, p2) (FIND(KEY((p1), (p2))))

int na, nb;
string a, b, c;

/*
7
a
b
cb
ab
cd
acbd
ab
ba
aabb
xxx
yyy
xyxyxy
a
bcd
decf
codes
horse
codeforces
egg
annie
egaegaeg
*/

int dfs(int p1, int p2, int i, unordered_map<int, int>& vis)
{
    // dfs() ----- 在当前情形下 最少还需要变几个字符
    // i一定等于p1+p2 记忆化不需要考虑i
    if (FINDKEY(p1, p2)) {
        return vis[KEY(p1, p2)];
    }
    if (i == na + nb - 1) {
        if (p1 < na) {
            return vis[KEY(p1, p2)] = (a[p1] == c[i] ? 0 : 1);
        }
        else {
            return vis[KEY(p1, p2)] = (b[p2] == c[i] ? 0 : 1);
        }
    }
    int d = 0x3f3f3f3f;
    if (p1 < na) {
        d = dfs(p1+1, p2, i+1, vis) + (a[p1] == c[i] ? 0 : 1);
    }
    if (p2 < nb) {
        d = min(d, dfs(p1, p2+1, i+1, vis) + (b[p2] == c[i] ? 0 : 1));
    }
    return vis[KEY(p1, p2)] = d;
}

void solve()
{
    cin >> a >> b >> c;
    na = a.length(); nb = b.length();
    // vector<vector<vector<int>>> vis(na + 1, vector<vector<int>>(nb + 1, vector<int>(na + nb + 1, 0)));
    unordered_map<int, int> vis;
    cout << dfs(0, 0, 0, vis) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen("in.txt", "r", stdin);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    system("pause");
    return 0;
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;

vector<string> s;

void func(string &a, string &b, string &c, int inda, int indb) {
    if (inda == a.size() && indb == b.size()) {
        s.push_back(c); 
        return;
    }

    if (inda < a.size()) {
        string m =  c + a[inda];
        func(a, b,m, inda + 1, indb);
    }

    if (indb < b.size()) {
        string n =  c + b[indb];
        func(a, b,n, inda, indb + 1);
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >>c;

        s.clear(); 
        string m ="";
        func(a, b, m, 0, 0);

        // for (auto ele : s) {
        //     cout << ele << endl;
        // }
        int final_ct =10000000;
        for(auto ele :s){
            int ct = 0;
            for(int i = 0 ; i < ele.size(); ++i){
                if(c[i]!=ele[i])ct++;
            } 
            final_ct = min(ct,final_ct);
        }
        cout<<final_ct<<endl;
        
        
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        int m = a.size(), n = b.size();
        vector<vector<int>> dp(m + 1, vector<int>(n + 1, INT_MAX));

        // Base case
        dp[0][0] = 0;

        // Fill DP table
        for (int i = 0; i <= m; ++i) {
            for (int j = 0; j <= n; ++j) {
                if (i > 0) {
                    dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i+j-1] != a[i-1]));
                }
                if (j > 0) {
                    dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i+j-1] != b[j-1]));
                }
            }
        }

        // Output the result for this test case
        cout << dp[m][n] << endl;
    }

    return 0;
}


Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
 
void solve(){
    int n; cin >> n;
    vector<int> vt(n);
    for (int &i : vt) cin >> i;
    vector<pair<int, int>> ans;
    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            ans.push_back({j, i});
    vector<bool> b(n + 1, false);
    for (int i = n - 1; ~i; i--){
        for (int j = vt[i] - 1; j >= 1; j--){
            if (!b[j])
                ans.push_back({j, vt[i]});
        }
        b[vt[i]] = true;
    }
    cout << ans.size() << '\n';
    for (auto &[x, y] : ans)
        cout << x << ' ' << y << '\n';
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n; cin >> n;
    vector<int> vt(n);
    for (int &i : vt) cin >> i;
    set<pair<int, int>> ans;
    // 1, 2, 3 -> 2, 1, 3
    vector<int> form(n);
    for (int i = 0; i < n; i++)
        form[i] = i + 1;
    for (int i = 0; i < n; i++){
        int idx = i;
        for (; idx < n; idx++)
            if (form[idx] == vt[i])
                break;
        if (idx + 1 < n){
            ans.insert({form[idx], form[idx + 1]});
            ans.insert({form[idx + 1], form[idx]});
        }
        for (int j = idx; j > i; j--){
            ans.insert({form[j], form[j - 1]});
            swap(form[j], form[j - 1]);
        }
    }
    cout << ans.size() << '\n';
    for (auto &p : ans)
        cout << p.first << " " << p.second << '\n';
}

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

Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define all(X) (X).begin(), (X).end()
#define sz(X) ((int)(X).size())

#define st first
#define nd second

using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;

void solvesub(int n, const vector<int>& pos, vector<int>& curr, vector<pll>& ans) {
    int i = n - 1;
    while(i > 0 && pos[curr[i]] < pos[curr[i - 1]]) {
        ans.push_back({curr[i], curr[i - 1]});
        swap(curr[i], curr[i - 1]);
        i--;
    }
    for(int j = i - 1; j >= 0; j--) {
        ans.push_back({curr[i], curr[j]});
    }
    for(int j = 0; j < i; j++) {
        ans.push_back({curr[j], curr[i]});
    }

    cout << "\n\n";
    for(auto v : curr) {
        cout << v + 1 << " ";
    }
    cout << "\n\n";
}

void solve() {
    int n;
    cin >> n;
    vector<int> pos(n);
    for(int i = 0; i < n; i++) {
        int v;
        cin >> v;
        v--;
        pos[v] = i;
    }
    vector<int> curr(n);
    iota(curr.begin(), curr.end(), 0);
    vector<pll> ans;
    for(int i = 1; i < n; i++) {
        solvesub(i + 1, pos, curr, ans);
    }

    cout << ans.size() << "\n";
    for(auto v : ans) {
        cout << v.first + 1 << " " << v.second + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    solve();
    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;

#define all(X) (X).begin(), (X).end()
#define sz(X) ((int)(X).size())

#define st first
#define nd second

using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;

void solvesub(int n, const vector<int>& pos, vector<int>& curr, vector<pll>& ans) {
    int i = n - 1;
    while(i > 0 && pos[curr[i]] < pos[curr[i - 1]]) {
        ans.push_back({curr[i], curr[i - 1]});
        swap(curr[i], curr[i - 1]);
        i--;
    }
    for(int j = i - 1; j >= 0; j--) {
        ans.push_back({curr[i], curr[j]});
    }
    for(int j = 0; j < i; j++) {
        ans.push_back({curr[j], curr[i]});
    }
}

void solve() {
    int n;
    cin >> n;
    vector<int> pos(n);
    for(int i = 0; i < n; i++) {
        int v;
        cin >> v;
        v--;
        pos[v] = i;
    }
    vector<int> curr(n);
    iota(curr.begin(), curr.end(), 0);
    vector<pll> ans;
    for(int i = 1; i < n; i++) {
        solvesub(i + 1, pos, curr, ans);
    }

    cout << ans.size() << "\n";
    for(auto v : ans) {
        cout << v.first + 1 << " " << v.second + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    solve();
    return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++) ans.push_back({j,i});
 }
 vector<ll>crr(n+1);
 for(ll i=n;i>=1;i--) crr[i]=n-i+1;
 while(true)
 { bool flag=false;
    for(ll i=1;i<=n-1;i++)
    {
        ll a=crr[i]; ll b=crr[i+1];
if((b<a && mp[a]>mp[b]) ) {flag=true; swap(crr[i],crr[i+1]); ans.push_back({b,a});}
    }
    if(!flag) break;
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++)
    {
        if(mp[j]<mp[i]) {ans.push_back({j,i}); }
        else {
            ans.push_back({j,i}); 
            ans.push_back({i,j}); 
        }
    }
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}

Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN
#define pb push_back


void solve() {
	int n;
	cin >> n;
	vector<int> final(n);


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

if(n == 1){
	cout << 0 << '\n';
	return;
}
	vector<int>v(n);

	for(int i = n - 1; i >= 0; i--){
		v[i] = i + 1;
	}

	reverse(all(v));
	vector<int>store1;
	vector<int>store2;
int count = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			count++;
			store1.push_back(j);
			store2.pb(i);

		}
	}

	for(int i = 0; i < n; i++){
		int j = i;
		while(v[j] != final[i]){
			j++;
		}


		for(int k = j; k > i; k--){
			count++;
			store1.pb(v[k]);
			store2.pb(v[k - 1]);
			swap(v[k],v[k - 1]);

		}


	}
cout << count << '\n';
	for(int i = 0; i < store1.size(); i++){
		cout << store1[i] << " " << store2[i] << '\n';
	}



  
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN
#define pb push_back


void solve() {
	int n;
	cin >> n;
	vector<int> final(n);


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

if(n == 1){
	cout << 0 << '\n';
	return;
}
	vector<int>v(n);

	for(int i = n - 1; i >= 0; i--){
		v[i] = i + 1;
	}

	reverse(all(v));

	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			cout << j << " " << i  << '\n';

		}
	}

	for(int i = 0; i < n; i++){
		int j = i;
		while(v[j] != final[i]){
			j++;
		}


		for(int k = j; k > i; k--){
			cout << v[k] << " " << v[k - 1] << '\n';
			swap(v[k],v[k - 1]);

		}


	}



  
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
#define mod 1000000007

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) {
        cin>>v[i];
    }
    bool arr[n+1] = {false};
    vector<pair<int,int>> ans;
    for(int i=n-1; i>=0; i--) {
        arr[v[i]] = true;
        for(int j=v[i]-1; j>0; j--) {
            if(!arr[j]) ans.push_back({v[i],j});
        }
        for(int j=1; j<=n; j++) {
            if(!arr[j]) ans.push_back({j,v[i]});
        }
        
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) {
        cout<<x.first<<" "<<x.second<<endl;
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
#define mod 1000000007

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) {
        cin>>v[i];
    }
    bool arr[n+1] = {false};
    vector<pair<int,int>> ans;
    for(int i=n-1; i>=0; i--) {
        arr[v[i]] = true;
        for(int j=v[i]-1; j>0; j--) {
            if(!arr[j]) ans.push_back({v[i],j});
        }
        for(int j=1; j<=i+1; j++) {
            if(!arr[j]) ans.push_back({j,v[i]});
        }
        
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) {
        cout<<x.first<<" "<<x.second<<endl;
    }
    return 0;
}

Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
   ll n;
   cin>>n;
   vector<ll>pos(n+1);
   vector<ll>cur(n+1);
   vector<ll>a(n+1);
   for(ll i = 1;i<=n;i++)
   {
     cin>>a[i];
     pos[a[i]] = i;
     cur[i] = i;
   }
   vector<pair<ll,ll>>ans;
   for(ll i = 1;i<=n;i++)
   {
     for(ll j = 1;j<n;j++)
     {
        if(pos[cur[j]] < pos[cur[j+1]])
        {
           ans.push_back({cur[j+1],cur[j]});
           swap(cur[j],cur[j+1]);
        }
     }
   }
   for(ll i = 1;i<=n;i++)
   {
     for(ll j = 1;j<n;j++)
     {
        if(pos[cur[j]] > pos[cur[j+1]])
        {
          ans.push_back({cur[j+1],cur[j]});
          swap(cur[j+1],cur[j]);
        }
     }
   }
   cout<<ans.size()<<endl;
   for(auto [x,y] : ans)
   cout<<x<<" "<<y<<endl;
   return 0;
}


Code 2:
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
   ll n;
   cin>>n;
   vector<ll>a(n);
   for(ll i = 0;i<n;i++)
   cin>>a[i];
   ll m = 0;
   vector<vector<ll>>greater(n+1,vector<ll>());
   vector<vector<ll>>smaller(n+1,vector<ll>());
   for(ll i = 0;i<n;i++)
   {
      for(ll j = i+1;j<n;j++)
      {
         if(a[j]<a[i])
        {
           m+=1;
           smaller[a[i]].push_back(a[j]);
        }
        else
        {
          m+=2;
          greater[a[i]].push_back(a[j]);
        }
      }
   }
   cout<<m<<endl;
   for(ll i = 0;i<n;i++)
   {
      for(auto it:greater[a[i]])
      {
        cout<<it<<" "<<a[i]<<endl;
      }
       for(ll j = greater[a[i]].size()-1;j>=0;j--)
      {
        cout<<a[i]<<" "<<greater[a[i]][j]<<endl;
      }

      for(auto it:smaller[a[i]])
      {
        cout<<a[i]<<" "<<it<<endl;
      }
   }

}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;

#define fastIO                                                                 \
    ios::sync_with_stdio(false);                                               \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
    cout.precision(numeric_limits<double>::max_digits10);
#define int long long 

void Bankai() {
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto &i:v)cin>>i;
    
    vector<vector<int>> vk(n+1,vector<int>(n+1,0));
    
    vector<int> rank(n+1);
    vector<int> temp(n);
    for(int i=0;i<n;i++){
    	rank[v[i]]=i+1;
    	temp[i]=i+1;
    }
    vector<pair<int,int>> vp;
    for(int i=0;i<n-1;i++){
    	int yh=0;
    	for(int j=0;j<n-1;j++){
    		if(rank[temp[j]]>rank[temp[j+1]]){
    			yh=1;
    			//cout<<temp[j+1]<<" "<<temp[j]<<endl;
    			swap(temp[j],temp[j+1]);
    			vp.push_back({temp[j],temp[j+1]});
    			
    		}else if(vk[temp[j]][temp[j+1]]==0){
    		 vp.push_back({temp[j+1],temp[j]});
    		 vp.push_back({temp[j],temp[j+1]});
    		}
    		vk[temp[j]][temp[j+1]]=1;
    		vk[temp[j+1]][temp[j]]=0;
    	}
    	if(yh==0)break;
    }

    cout<<vp.size()<<endl;
    if(vp.size())
	for(auto &i:vp){
		cout<<i.first<<" "<<i.second<<endl;
	}
    
}
 
int32_t main() {
    fastIO;
 
    int t = 1;
   // cin >> t;
   // int a=fac(200000);
    while (t--) {
        Bankai();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

#define fastIO                                                                 \
    ios::sync_with_stdio(false);                                               \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
    cout.precision(numeric_limits<double>::max_digits10);
#define int long long 

void Bankai() {
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto &i:v)cin>>i;
    
    vector<vector<int>> vk(n+1,vector<int>(n+1,0));
    
    vector<int> rank(n+1);
    vector<int> temp(n);
    for(int i=0;i<n;i++){
    	rank[v[i]]=i+1;
    	//temp[i]=i;
    }
    vector<pair<int,int>> vp;
    for(int i=0;i<n;i++){
    	int yh=rank[i+1];
    	for(int j=yh;j<n;j++){
    		if(v[j]>(i+1)){
    			vp.push_back({v[j],i+1});
    		}
    	}
    	for(int j=n-1;j>=yh;j--){
    		if(v[j]>(i+1)){
    			vp.push_back({i+1,v[j]});
    		}
    	}
    	for(int j=yh-2;j>=0;j--){
    		if(v[j]>(i+1)){
    			vp.push_back({i+1,v[j]});
    		}
    	}
    }

    cout<<vp.size()<<endl;
    if(vp.size())
	for (int i = vp.size() - 1; i >= 0; i--) cout << vp[i].second << " " << vp[i].first << endl;
    
}
 
int32_t main() {
    fastIO;
 
    int t = 1;
   // cin >> t;
   // int a=fac(200000);
    while (t--) {
        Bankai();
    }
    return 0;
}

Answer: 2