#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define nline "\n"
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()
// multiset
// typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// set
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define M_PI 3.14159265358979323846
const long long int N = 1e9 + 7;
// pascals triangle
// vvll dp(1003, vll(1003, -1));
// int pastri(ll n, ll k)
// {
// if (n < k)
// return 0;
// if (n == k or !k)
// return 1;
// if (dp[n][k] != -1)
// return dp[n][k];
// - return dp[n][k] = (pastri(n - 1, k) + pastri(n - 1, k - 1)) % N;
// }
ll fastMOd(ll a, ll b)
{
ll ans = 1;
while (b > 0)
{
if (b & 1)
ans = (ans * a) % N;
a = (a * a) % N;
b = b >> 1;
}
return ans;
}
bool isprime(ll n)
{
if (n <= 1)
return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
ll my_sqrt(ll tt)
{
ll left = 0, right = 2000000123;
while (right > left)
{
ll mid = (left + right) / 2;
if (mid * mid > tt)
right = mid;
else
left = mid + 1;
}
return left - 1;
}
// vll minp, primes;
void sieve(ll n)
{
// minp.assign(n + 1, 0);
// primes.clear();
// for (ll i = 2; i <= n; i++)
// {
// if (minp[i] == 0)
// {
// minp[i] = i;
// primes.push_back(i);
// }
// for (auto p : primes)
// {
// if (i * p > n)
// {
// break;
// }
// minp[i * p] = p;
// if (p == minp[i])
// {
// break;
// }
// }
// }
}
void solve()
{
ll n;
cin >> n;
vll a(n);
unordered_map<ll, ll> m;
for (int i = 0; i < n; i++)
{
cin >> a[i];
m[a[i]] = i;
}
vll b = a;
sort(all(b));
vvll ans;
for (int i = 0; i < n; i++)
{
if (a[i] == b[i])
continue;
// cout << a[i] << " " << b[i] << nline;
if (abs(m[b[i]] - i) >= n / 2)
{
ll i1 = i, i2 = m[b[i]];
m[a[i]] = i2;
m[b[i]] = i1;
swap(a[i1], a[i2]);
ans.push_back({i1, i2});
}
else
{
ll i1 = i, i2 = m[b[i]];
m[a[i]] = i2;
m[b[i]] = i1;
swap(a[i1], a[i2]);
ll k;
if (i + 1 > n / 2 && i2 + 1 > n / 2)
{
k = 0;
ans.push_back({k, i1});
ans.push_back({k, i2});
ans.push_back({k, i1});
}
else if (i + 1 > n / 2 && i2 + 1 <= n / 2)
{
ans.push_back({i1, 0});
ans.push_back({n - 1, 0});
ans.push_back({n - 1, i2});
ans.push_back({n - 1, 0});
ans.push_back({i1, 0});
}
else if (i + 1 <= n / 2 && i2 + 1 > n / 2)
{
ans.push_back({i1, n - 1});
ans.push_back({n - 1, 0});
ans.push_back({0, i2});
ans.push_back({n - 1, 0});
ans.push_back({i1, n - 1});
}
else
{
k = n - 1;
ans.push_back({k, i1});
ans.push_back({k, i2});
ans.push_back({k, i1});
}
}
// for (auto t : a)
// cout << t << " ";
// cout << nline;
}
cout << ans.size() << nline;
for (auto t : ans)
cout << t[0] + 1 << " " << t[1] + 1 << nline;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |
1832. Check if the Sentence Is Pangram | 1678. Goal Parser Interpretation |
1389. Create Target Array in the Given Order | 1313. Decompress Run-Length Encoded List |
1281. Subtract the Product and Sum of Digits of an Integer | 1342. Number of Steps to Reduce a Number to Zero |
1528. Shuffle String | 1365. How Many Numbers Are Smaller Than the Current Number |
771. Jewels and Stones | 1512. Number of Good Pairs |
672. Richest Customer Wealth | 1470. Shuffle the Array |
1431. Kids With the Greatest Number of Candies | 1480. Running Sum of 1d Array |
682. Baseball Game | 496. Next Greater Element I |
232. Implement Queue using Stacks | 844. Backspace String Compare |
20. Valid Parentheses | 746. Min Cost Climbing Stairs |
392. Is Subsequence | 70. Climbing Stairs |
53. Maximum Subarray | 1527A. And Then There Were K |
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers | 318. Maximum Product of Word Lengths |
448. Find All Numbers Disappeared in an Array | 1155. Number of Dice Rolls With Target Sum |