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

Solution 1 (runtime: 249 ms):
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define rep(i, n)  for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define sum(v) reduce(all(v))
#define pb push_back
#define int long long int
typedef  long double ld;
// 1e7 1e9+7 1e18

int range_sum(int l,int r) {
    if (l > r) return 0;
    return (l + r) * (r - l + 1) / 2;
}
void pv(vector<int> nums) {
    for(auto e: nums) cout << e<<" ";
    cout <<"\n";
}
vector<string> split(const string& str, char delimiter) {
    vector<string> tokens;
    string token;
    istringstream stream(str);
    while (getline(stream, token, delimiter)) {
        tokens.push_back(token);
    }
    return tokens;
}

// Helper function for single argument
template <typename T>
std::string to_string(const T& t) {
    std::ostringstream oss;
    oss << t;
    return oss.str();
}

// Variadic template for multiple arguments
template <typename T, typename... Args>
std::string to_string(const T& first, const Args&... rest) {
    return to_string(first) + ", " + to_string(rest...);
}

// Macro for easy usage
#define print(...) (std::cout << to_string(__VA_ARGS__) << std::endl)


void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    //bubble
    //pv(a);
    vector<pair<int,int>> otks;
    for(int i = 0; i<n; i++) {
        for(int j = 0; j<n-1; j++) {
            if(a[j]<a[j+1]) {
                swap(a[j],a[j+1]);
                otks.push_back({a[j+1],a[j]});
            }
        }
    }
    for(int i = 0; i<n; i++) {
        for(int j = 0; j<n-1; j++) {
            if(a[j]>a[j+1]) {
                swap(a[j],a[j+1]);
                otks.push_back({a[j+1],a[j]});
            }
        }
    }
    reverse(otks.begin(), otks.end());
    print(otks.size());
    for(auto [a,b]: otks) {
        cout << a << " " <<b <<"\n";
    }
}
 
int32_t main() {
    fast;
    solve();
    return 0;
}



Solution 2 (runtime: 280 ms):
// Away... beyond all concepts of wrong-doing and right-doing
// There is a field, I will meet you there.


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
 
typedef long long ll;
#define pb push_back
#define endl '\n'
#define rev(v) reverse(v.begin(), v.end())
#define srt(v) sort(v.begin(), v.end())
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define vll vector<ll>
#define pll = pair<ll, ll>;

const ll mod = 1000000007;
const ll md = 998244353;

void vin(vector<ll> &a, int n)
{
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        a.push_back(x);
    }
}

void solve() {
    ll n; cin>>n;
    vll c; vin(c, n);
    vector<pair<ll, ll>>ans; ll cnt = 0;
    for (ll i = 0; i<n; i++){
        for (ll j = n-1; j>i; j--){
            if (c[j-1]< c[j]){
                ans.push_back({c[j-1], c[j]});
                cnt++;
                swap(c[j-1], c[j]);
            }
        }
    }
    for (ll i = 0; i<n; i++){
        for (ll j = n-1; j>i; j--){
            if (c[j-1]>c[j]){
                ans.push_back({c[j-1], c[j]});
                cnt++;
                swap(c[j-1], c[j]);
            }
        }
    }
    cout<<cnt<<endl; reverse(ans.begin(), ans.end());
    for (auto x: ans) cout<<x.first<<" "<<x.second<<endl;

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll t=1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}