Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
List = []
queue = [(0,0,1)]
shape = 0
used ={(0,0)}
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y,c):
    if(x > W-1 or y > H-1):
        return
    if(List[y][x] == '#'):
        return
    if(x,y) in used:
        return
    queue.append((x,y,c+1))
    used.add((x,y))

flag = -1
while(len(queue) != 0):
    x,y,c = queue[0]
    if x==W-1 and y==H-1:
        flag = 1
        break
    queue.pop(0)
    check(x+1,y,c)
    check(x, y+1,c)
    check(x-1,y,c)
    check(x, y-1,c)
if(flag == 1):
    print(H*W - c - shape)
else:
    print(-1)

Fixed submission:
H,W = map(int, input().split())
List = []
queue = [(0,0,1)]
shape = 0
used ={(0,0)}
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y,c):
    if(x>W-1 or y>H-1 or x<0 or y<0):
        return
    if(List[y][x] == '#'):
        return
    if(x,y) in used:
        return
    queue.append((x,y,c+1))
    used.add((x,y))

flag = -1
while(len(queue) != 0):
    x,y,c = queue[0]
    if x==W-1 and y==H-1:
        flag = 1
        break
    queue.pop(0)
    check(x+1,y,c)
    check(x, y+1,c)
    check(x-1,y,c)
    check(x, y-1,c)
if(flag == 1):
    print(H*W - c - shape)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
List = []
queue = [(0,0)]
shape = 0
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y):
    if(x >= W-1 or y >= H-1):
        return
    if(List[y][x] == '#')
        return
    queue.append((x,y))

while(len(queue) != 0):
    x,y = queue[0]
    queue.pop(0)
    check(x+1,y)
    check(x, y+1)
if(flag == 1):
    print(H*W - (H-1 + W-1 + 1) - shape)
else:
    print(-1)


Fixed submission:
H,W = map(int, input().split())
List = []
queue = [(0,0,1)]
shape = 0
used ={(0,0)}
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y,c):
    if(x>W-1 or y>H-1 or x<0 or y<0):
        return
    if(List[y][x] == '#'):
        return
    if(x,y) in used:
        return
    queue.append((x,y,c+1))
    used.add((x,y))

flag = -1
while(len(queue) != 0):
    x,y,c = queue[0]
    if x==W-1 and y==H-1:
        flag = 1
        break
    queue.pop(0)
    check(x+1,y,c)
    check(x, y+1,c)
    check(x-1,y,c)
    check(x, y-1,c)
if(flag == 1):
    print(H*W - c - shape)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
List = []
queue = [(0,0)]
shape = 0
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y):
    if(x > W-1 or y > H-1):
        return
    if(List[y][x] == '#')
        return
    queue.append((x,y))

while(len(queue) != 0):
    x,y = queue[0]
    queue.pop(0)
    check(x+1,y)
    check(x, y+1)
if(flag == 1):
    print(H*W - (H-1 + W-1 + 1) - shape)
else:
    print(-1)


Fixed submission:
H,W = map(int, input().split())
List = []
queue = [(0,0,1)]
shape = 0
used ={(0,0)}
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y,c):
    if(x>W-1 or y>H-1 or x<0 or y<0):
        return
    if(List[y][x] == '#'):
        return
    if(x,y) in used:
        return
    queue.append((x,y,c+1))
    used.add((x,y))

flag = -1
while(len(queue) != 0):
    x,y,c = queue[0]
    if x==W-1 and y==H-1:
        flag = 1
        break
    queue.pop(0)
    check(x+1,y,c)
    check(x, y+1,c)
    check(x-1,y,c)
    check(x, y-1,c)
if(flag == 1):
    print(H*W - c - shape)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
List = []
queue = [(0,0)]
shape = 0
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)
while(len(queue) != 0):
    x,y = queue[0]
    queue.pop(0)
    if(x == H-1 and y == W-1):
        flag = 1
        break
    if(x < H-1):
        if(List[x+1][y] == '.'):
            queue.append((x+1,y))
    if(y < W-1):
        if(List[x][y+1] == '.'):
            queue.append((x,y+1))
if(flag == 1):
    print(H*W - (H-1 + W-1 + 1) - shape)
else:
    print(-1)


Fixed submission:
H,W = map(int, input().split())
List = []
queue = [(0,0,1)]
shape = 0
used ={(0,0)}
for i in range(H):
    x = input()
    shape += x.count('#')
    List.append(x)

def check(x,y,c):
    if(x>W-1 or y>H-1 or x<0 or y<0):
        return
    if(List[y][x] == '#'):
        return
    if(x,y) in used:
        return
    queue.append((x,y,c+1))
    used.add((x,y))

flag = -1
while(len(queue) != 0):
    x,y,c = queue[0]
    if x==W-1 and y==H-1:
        flag = 1
        break
    queue.pop(0)
    check(x+1,y,c)
    check(x, y+1,c)
    check(x-1,y,c)
    check(x, y-1,c)
if(flag == 1):
    print(H*W - c - shape)
else:
    print(-1)