#게임개발
n, m=map(int, input().split())
x, y, d=map(int, input().split())
check=0
v = [[0]*m for _ in range(n)]
v[x][y]=1
dx=[-1,0,1,0]
dy=[0,1,0,-1]
cnt=0
array = []
for i in range(n):
temp = list(map(int, input().split()))
array.append(temp)
while True:
if(array[x+dx[(d+3)%4]][y+dy[(d+3)%4]]==0):
if(v[x+dx[(d+3)%4]][y+dy[(d+3)%4]]==0):
x=x+dx[(d+3)%4]
y=y+dy[(d+3)%4]
v[x][y]=1
d=(d+3)%4
check=0
continue
#d=(d+3)%4
#check=check+1
#continue
d=(d+3)%4
check=check+1
#continue
if(check==4):
if(array[x+dx[(d+2)%4]][y+dy[(d+2)%4]]==1):
break
else:
x=x+dx[(d+2)%4]
y=y+dy[(d+2)%4]
check=0
for i in range(m):
for j in range(n):
if(1 == v[i][j]):
cnt=cnt+1
print(cnt)