SuperCowHorse @ 2022-07-21 13:01:53
#include<bits/stdc++.h>
#define int long long
#define LeftUp work(a+n-1,b+n-1,a,b,n)
#define RightUp work(a+n-1,b+n,a,b+n,n)
#define LeftDown work(a+n,b+n-1,a+n,b,n)
#define RightDown work(a+n,b+n,a+n,b+n,n)
using namespace std;
int k,x,y,n;
void work(int a,int b,int x,int y,int n){
if(n==1) return;
n>>=1;
if(x<=a+n-1&&y<=b+n-1){
printf("%lld %lld 1\n",x+n,y+n);
work(x,y,a,b,n);
LeftDown;
RightUp;
RightDown;
}
else if(x<=a+n-1&&y>b+n-1){
printf("%lld %lld 2\n",x+n,y+n-1);
work(x,y,a,b+n,n);
LeftUp;
RightUp;
RightDown;
}
else if(x>a+n-1&&y<=b+n-1){
printf("%lld %lld 3\n",x+n+1,y+n);
work(x,y,a+n,b,n);
LeftUp;
LeftDown;
RightDown;
}
else if(x>a+n-1&&y>b+n-1){
printf("%lld %lld 4\n",x+n+1,y+n+1);
work(x,y,a+n,b+n,n);
LeftUp;
LeftDown;
RightUp;
}
}
signed main(){
scanf("%lld%lld%lld",&k,&x,&y);
n=pow(2,k);
work(1,1,x,y,n);
return 0;
}