#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
bool has_bit(int x, int bt)
{
return (x >> bt) & 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI p(1 << n);
FOR (i, 0, SZ(p))
cin >> p[i];
VI srt = p;
sort(ALL(srt));
vector<PII> ans;
FOR (en, 0, 1 << n)
{
int st = -1;
FOR (pos, en, 1 << n)
{
if (srt[en] == p[pos])
{
st = pos;
break;
}
}
FOR (i, 0, n)
{
if (has_bit(en, i) && !has_bit(st, i))
{
ans.PB({st, st | (1 << i)});
swap(p[st], p[st | (1 << i)]);
st |= 1 << i;
}
}
FOR (i, 0, n)
{
if (!has_bit(en, i) && has_bit(st, i))
{
ans.PB({st, st ^ (1 << i)});
swap(p[st], p[st ^ (1 << i)]);
st ^= 1 << i;
}
}
}
assert(is_sorted(ALL(p)));
assert(SZ(ans) <= n * (1 << n));
cout << SZ(ans) << '\n';
for (auto [i, j] : ans)
cout << i << ' ' << j << '\n';
return 0;
}
123