//BAEKJOON 15500
#include <stdio.h>
#include <stack>
using namespace std;
int idx[125], order[2][20000], cnt;
int main() {
stack<int> A, B;
int n;
scanf("%d", &n);
for(int i=0; i<n; i++) {
int a;
scanf("%d", &a);
idx[a]=1;
A.push(a);
}
while(n) {
while(!A.empty() && idx[n]==1) {
int TOP = A.top();
A.pop();
if(TOP==n) {
order[0][cnt]=1; order[1][cnt]=3;
idx[n--]=3;
}
else {
order[0][cnt]=1; order[1][cnt]=2;
idx[TOP]=2;
}
cnt++;
}
while(!B.empty() && idx[n]==2) {
int TOP = B.top();
B.pop();
if(TOP==n) {
order[0][cnt]=2; order[1][cnt]=3;
idx[n--]=3;
}
else {
order[0][cnt]=2; order[1][cnt]=1;
idx[TOP]=1;
}
cnt++;
}
}
printf("%d\n", cnt);
for(int i=0; i<cnt; i++)
printf("%d %d\n", order[0][i], order[1][i]);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: