import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static int N, M;
public static int[][] map;
public static int count = 0;
public static int[] dr = {-1, 0, 1, 0};
public static int[] dc = {0, 1, 0, -1};
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
map = new int[N][M];
st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < M; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
robot(r, c, d);
System.out.print(count);
}
public static void robot(int row, int col, int direction) {
if (map[row][col] == 0) {
map[row][col] = 2;
count++;
}
int before = direction;
boolean flag = false;
for (int i = 0; i < 4; i++) {
int nextD = (direction + 3) % 4;
int nextR = row + dr[nextD];
int nextC = col + dc[nextD];
if (nextR > 0 && nextC > 0 && nextR < N && nextC < M) {
if (map[nextR][nextC] == 0) {
robot(nextR, nextC, nextD);
flag = true;
break;
}
}
direction = (direction + 3) % 4;
}
if (!flag) {
int nextD = (before + 2) % 4;
int nextR = row + dr[nextD];
int nextC = col + dc[nextD];
if (nextR > 0 && nextC > 0 && nextR < N && nextC < M) {
if (map[nextR][nextC] != 1) {
robot(nextR, nextC, before);
}
}
}
}
}