You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not occupied by an obstacle. You can't move beyond the boundaries of the labyrinth.

Unfortunately, your keyboard is about to break, so you can move left no more than x times and move right no more than y times. There are no restrictions on the number of moves up and down since the keys used to move up and down are in perfect condition.

Now you would like to determine for each cell whether there exists a sequence of moves that will put you from the starting cell to this particular one. How many cells of the board have this property?


-----Input-----

The first line contains two integers n, m (1 ≤ n, m ≤ 2000) — the number of rows and the number columns in the labyrinth respectively.

The second line contains two integers r, c (1 ≤ r ≤ n, 1 ≤ c ≤ m) — index of the row and index of the column that define the starting cell.

The third line contains two integers x, y (0 ≤ x, y ≤ 10^9) — the maximum allowed number of movements to the left and to the right respectively.

The next n lines describe the labyrinth. Each of them has length of m and consists only of symbols '.' and '*'. The j-th character of the i-th line corresponds to the cell of labyrinth at row i and column j. Symbol '.' denotes the free cell, while symbol '*' denotes the cell with an obstacle.

It is guaranteed, that the starting cell contains no obstacles.


-----Output-----

Print exactly one integer — the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself.


-----Examples-----
Input
4 5
3 2
1 2
.....
.***.
...**
*....

Output
10

Input
4 4
2 2
0 1
....
..*.
....
....

Output
7



-----Note-----

Cells, reachable in the corresponding example, are marked with '+'.

First example:  

+++..

+***.

+++**

*+++.

 

Second example:  

.++.

.+*.

.++.

.++.

Difficulty: competition

Starter code:

Solutions:
def main():
    n,m = list(map(int, input().split()))
    r,c = list(map(int, input().split()))
    L,R = list(map(int, input().split()))
    lab = [input() for _ in range(n)]
    
    r -= 1
    c -= 1
 
    inf = n*m+1
    dist = [[inf] * m for _ in range(n)]
    dist[r][c] = 0
    
    Q = [(r,c)]
    for x,y in Q:
        d = dist[x][y]
        if x < n - 1 and dist[x + 1][y] > d and lab[x + 1][y] == '.':
            dist[x + 1][y] = d
            Q.append((x + 1, y))
 
        if 0 < x and dist[x - 1][y] > d and lab[x - 1][y] == '.':
            dist[x - 1][y] = d
            Q.append((x - 1, y))
        
        if 0 < y and dist[x][y - 1] > d and lab[x][y - 1] == '.':
            dist[x][y - 1] = d + 1
            Q.append((x, y - 1))
        
        if y < m - 1 and dist[x][y + 1] > d and lab[x][y + 1] == '.':
            dist[x][y + 1] = d + 1
            Q.append((x, y + 1))
    ans=0
    for i in range(n):
        for j in range(m):
            d = dist[i][j]
            if d < inf:
                right = (d + (j - c))//2
                left =  (d - (j - c))//2
                if right <= R and left <= L:
                    ans+=1
    print(ans)
main()
#Code By:pajenegod


from collections import deque

def put():
    return list(map(int, input().split()))
def safe(i,j):
    return i>=0 and j>=0 and i<n and j<m and vis[i][j]==0 and mat[i][j]=='.'

n,m = put()
sx,sy = put()
l,r = put()
sx,sy = sx-1,sy-1
mat = [input() for _ in range(n)]

vis = [[0]*m for _ in range(n)]
q = deque()
move = [(-1,0), (1,0), (0,-1), (0,1)]
ans  = 0

if safe(sx,sy):
    vis[sx][sy]=1
    q.append((sx,sy,0))
while q:
    x,y,s = q.popleft()
    R = s+(y-sy)
    L = s-(y-sy)
    if R<=2*r and L<=2*l:
        ans+=1

    for dx,dy in move:
        i,j = x+dx, y+dy
        if safe(i, j):
            vis[i][j]=1
            if dx==0:
                q.append((i,j,s+1))
            else:
                q.appendleft((i,j,s))
            

print(ans)


from collections import deque

def put():
    return list(map(int, input().split()))
def safe(i,j):
    return i>=0 and j>=0 and i<n and j<m and vis[i][j]==0 and mat[i][j]=='.'

n,m = put()
sx,sy = put()
l,r = put()
sx,sy = sx-1,sy-1
mat = [list(input()) for _ in range(n)]

vis = [[0]*m for _ in range(n)]
q = deque()
move = [(-1,0), (1,0), (0,-1), (0,1)]
ans  = 0

if safe(sx,sy):
    vis[sx][sy]=1
    q.append((sx,sy,0))
while q:
    x,y,s = q.popleft()
    R = s+(y-sy)
    L = s-(y-sy)
    if R<=2*r and L<=2*l:
        ans+=1

    for dx,dy in move:
        i,j = x+dx, y+dy
        if safe(i, j):
            vis[i][j]=1
            if dx==0:
                q.append((i,j,s+1))
            else:
                q.appendleft((i,j,s))
            

print(ans)


from collections import deque
n, m = list(map(int, input().split()))
sx, sy = list(map(int, input().split()))
x, y = list(map(int, input().split()))
smap = [input() for i in range(n)]


mp = [[-1] * m for i in range(n)]


sx, sy = sx - 1, sy - 1
mp[sx][sy] = 0
ans = 0

q = deque()

q.append((sx, sy))


def move(px, py, s, left):
  if (px >= 0 and px < n and py >= 0 and py < m):
    if (smap[px][py] == '.' and mp[px][py] == -1):
      mp[px][py] = s
      if left:
        q.appendleft((px, py))
      else:
        q.append((px, py))



while q:
  px, py = q.popleft()
  s = mp[px][py]
  #print(s)
  #print(s + py - r)
  #print(s - py + r)
  #print(s + py - r <= y * 2)
  #print(s - py + r <= x * 2)
  #print(x, y)
  #return
  ans += s + py - sy <= y * 2 and s - py + sy <= x * 2
  
  move(px + 1, py, s, left=True)
  move(px - 1, py, s, left=True)
  move(px, py + 1, s + 1, left=False)
  move(px, py - 1, s + 1, left=False)
  
print(ans)


from collections import deque
n,m = [int(x) for x in input().split()]
x,y = [int(x) for x in input().split()]
left,right = [int(x) for x in input().split()]
s=[]
d=[None]*2007
ans=0
for i in range(0,2007):
    d[i]=[]
    for j in range(0,2007):
        d[i].append(0)

for i in range(0,n):
    s.append(input())

q = deque()

q.append([x-1,y-1,left,right])

while(len(q)):
    v = q[0]
    q.popleft()
    
    if(v[0]<0 or v[0]>=n or v[1]<0 or v[1]>=m or d[v[0]][v[1]]==1 or v[2]<0 or v[3]<0 or s[v[0]][v[1]]=='*'): continue
    
    d[v[0]][v[1]]=1
    
    q.appendleft([v[0]+1,v[1],v[2],v[3]])
    q.appendleft([v[0]-1,v[1],v[2],v[3]])
    q.append([v[0],v[1]+1,v[2],v[3]-1])
    q.append([v[0],v[1]-1,v[2]-1,v[3]])
       
   
    
    
for i in range(0,n):
    for j in range(0,m):
        ans+=d[i][j]

print(ans)


from collections import deque
n,m = [int(x) for x in input().split()]
x,y = [int(x) for x in input().split()]
left,right = [int(x) for x in input().split()]
s=[]
ans=0
d=[None]*2007
for i in range(0,2007):
    d[i]=[0 for j in range(0,2007)]

for i in range(0,n):
    s.append(input())

q = deque()

q.append([x-1,y-1,left,right])

while(len(q)):
    v = q[0]
    q.popleft()
    
    if(v[0]<0 or v[0]>=n or v[1]<0 or v[1]>=m or d[v[0]][v[1]]==1 or v[2]<0 or v[3]<0 or s[v[0]][v[1]]=='*'): continue
    
    d[v[0]][v[1]]=1
    
    q.appendleft([v[0]+1,v[1],v[2],v[3]])
    q.appendleft([v[0]-1,v[1],v[2],v[3]])
    q.append([v[0],v[1]+1,v[2],v[3]-1])
    q.append([v[0],v[1]-1,v[2]-1,v[3]])
       
   
    
    
for i in range(0,n):
    for j in range(0,m):
        ans+=d[i][j]

print(ans)