WA × 10
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200010];
int c[200010], ans;
struct node {
int x, y;
} d[200010];
int main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c[a[i]] = i;
}
for (int i = 1; i <= n; i++) {
if (i != a[i]) {
swap(a[c[i]], a[i]);
d[++ans].x = i, d[ans].y = c[i];
c[a[i]] = c[i];
c[i] = i;
}
}
cout << ans << endl;
for (int i = 1; i <= ans; i++) {
cout << d[i].x << ' ' << d[i].y << endl;
}
return 0;
}