#include <iostream>
using namespace std;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}, ddx[4] = {0,1,0,-1}, ddy[4] = {-1,0,1,0}, ddx2[4]={-1,0,1,0}, ddy2[4]={0,-1,0,1}, ddx3[4]={1,0,-1,0}, ddy3[4]={0,-1,0,1}, ddx4[4]={0,-1,0,1}, ddy4[4]={1,0,-1,0}, ddx6[4] = {-1,0,1,0}, ddy6[4] = {0,1,0,-1}, ddx7[5] = {0,1,0,-1,0}, ddy7[5] =
{-1,0,1,0,1};
int a[20][20]={0}, vis[20][20]={0};
int main() {
int n, x, y, f, dir = 0, num = 1, c = 0;
cin >> n >> x >> y >> f;
a[x][y] = vis[x][y] = num++;
if(f == -1&& y!=0&&y!=n&&x!=n){
for(int i = 0; i < 4; i++){
dx[i] = ddx[i];
dy[i] = ddy[i];
}
}
else if(f == -1&& yn){
for(int i = 0; i < 4; i++){
dx[i] = ddx2[i];
dy[i] = ddy2[i];
}
}
else if(f == -1&& xn){
for(int i = 0; i < 4; i++){
dx[i] = ddx4[i];
dy[i] = ddy4[i];
}
}
else if(f == -1&& y1){
for(int i = 0; i < 4; i++){
dx[i] = ddx4[i];
dy[i] = ddy4[i];
}
}
else if(f == 1&& yn){
for(int i = 0; i < 4; i++){
dx[i] = ddx3[i];
dy[i] = ddy3[i];
}
}
else if(f == 1&& xn){
for(int i = 0; i < 4; i++){
dx[i] = ddx7[i];
dy[i] = ddy7[i];
}
}
if(f == 1&& y1){
for(int i = 0; i < 4; i++){
dx[i] = ddx6[i];
dy[i] = ddy6[i];
}
}
if(f == 1&& y3&&xn||y2&&xn&&f==1){
}
while(c <= 4){
int nx = x + dx[dir], ny = y + dy[dir];
if(vis[nx][ny] || nx < 1 || nx > n || ny < 1 || ny > n){
dir++;
c++;
}