Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit(1)

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
# R,C=7,8
# startY,startX = map(int,input().split())
startY=0
startX=0
# startY,startX = 1,1
# goalY,goalX = map(int,input().split())
goalX=W-1
goalY=H-1
# goalY,goalX = 3,4
F = list(list(input()) for _ in range(H))
# F = [
# '########',
# '#......#',
# '#.######',
# '#..#...#',
# '#..##..#',
# '##.....#',
# '########']
reached = [[False for i in range(W)] for i in range(H)]
count=0
# for i in range (R):
#     print("".join(F[i]))
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
# result=0
# for i in range(H):
#     for j in range(W):
#         if F[i][j]=="#":
#             result+=1
# print(result)
bfs(startY,startX,count)
# print(QUE)


Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
startY=0
startX=0
goalX=W-1
goalY=H-1
F = list(list(input()) for _ in range(H))
reached = [[False for i in range(W)] for i in range(H)]
count=0
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
bfs(startY,startX,count)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())

H,W = map(int,input().split())
# R,C=7,8
# startY,startX = map(int,input().split())
startY=0
startX=0
# startY,startX = 1,1
# goalY,goalX = map(int,input().split())
goalX=W-1
goalY=H-1
# goalY,goalX = 3,4
F = list(list(input()) for _ in range(H))
# F = [
# '########',
# '#......#',
# '#.######',
# '#..#...#',
# '#..##..#',
# '##.....#',
# '########']
reached = [[False for i in range(W)] for i in range(H)]
count=0
# for i in range (R):
#     print("".join(F[i]))
xQUE =  deque(maxlen=100000)
yQUE =  deque(maxlen=100000)
cQUE =  deque()
# result=0
# for i in range(H):
#     for j in range(W):
#         if F[i][j]=="#":
#             result+=1
# print(result)
bfs(startY,startX,count)
# print(QUE)
print("-1")

Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
startY=0
startX=0
goalX=W-1
goalY=H-1
F = list(list(input()) for _ in range(H))
reached = [[False for i in range(W)] for i in range(H)]
count=0
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
bfs(startY,startX,count)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())

H,W = map(int,input().split())
# R,C=7,8
# startY,startX = map(int,input().split())
startY=0
startX=0
# startY,startX = 1,1
# goalY,goalX = map(int,input().split())
goalX=W-1
goalY=H-1
# goalY,goalX = 3,4
F = list(list(input()) for _ in range(H))
# F = [
# '########',
# '#......#',
# '#.######',
# '#..#...#',
# '#..##..#',
# '##.....#',
# '########']
reached = [[False for i in range(W)] for i in range(H)]
count=0
# for i in range (R):
#     print("".join(F[i]))
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
# result=0
# for i in range(H):
#     for j in range(W):
#         if F[i][j]=="#":
#             result+=1
# print(result)
bfs(startY,startX,count)
# print(QUE)
print("-1")

Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
startY=0
startX=0
goalX=W-1
goalY=H-1
F = list(list(input()) for _ in range(H))
reached = [[False for i in range(W)] for i in range(H)]
count=0
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
bfs(startY,startX,count)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())

H,W = map(int,input().split())
# R,C=7,8
# startY,startX = map(int,input().split())
startY=0
startX=0
# startY,startX = 1,1
# goalY,goalX = map(int,input().split())
goalX=W-1
goalY=H-1
# goalY,goalX = 3,4
F = list(list(input()) for _ in range(H))
# F = [
# '########',
# '#......#',
# '#.######',
# '#..#...#',
# '#..##..#',
# '##.....#',
# '########']
reached = [[False for i in range(W)] for i in range(H)]
count=0
# for i in range (R):
#     print("".join(F[i]))
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
# result=0
# for i in range(H):
#     for j in range(W):
#         if F[i][j]=="#":
#             result+=1
# print(result)
bfs(startY,startX,count)
# print(QUE)

Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
from collections import deque
def bfs(Y,X,count):
    # print("now",Y+1,X+1)
    # print(count,"手目")
    reached[Y][X]=True

    if Y==goalY and X==goalX:
        result=0
        for i in range(H):
            for j in range(W):
                if F[i][j]=="#":
                    result+=1
        print(H*W - result - count -1)
        exit()

    if Y < H-1 :
        if F[Y+1][X]=="." and reached[Y+1][X]==False:
            # print(Y+1+1,X+1,"を積みます")
            yQUE.appendleft(Y+1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y+1][X]=True
    if X < W-1 :
        if F[Y][X+1]=="." and reached[Y][X+1]==False:
            # print(Y+1,X+1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X+1)
            cQUE.appendleft(count+1)
            reached[Y][X+1]=True
    if 0 < Y :
        if F[Y-1][X]=="." and reached[Y-1][X]==False:
            # print(Y-1+1,X+1,"を積みます")
            yQUE.appendleft(Y-1)
            xQUE.appendleft(X)
            cQUE.appendleft(count+1)
            reached[Y-1][X]=True
    if 0 < X :
        if F[Y][X-1]=="." and reached[Y][X-1]==False:
            # print(Y+1,X-1+1,"を積みます")
            yQUE.appendleft(Y)
            xQUE.appendleft(X-1)
            cQUE.appendleft(count+1)
            reached[Y][X-1]=True    
    try:
        bfs(yQUE.pop(),xQUE.pop(),cQUE.pop())
    except IndexError:
        print("-1")

H,W = map(int,input().split())
startY=0
startX=0
goalX=W-1
goalY=H-1
F = list(list(input()) for _ in range(H))
reached = [[False for i in range(W)] for i in range(H)]
count=0
xQUE =  deque(maxlen=1000000000)
yQUE =  deque(maxlen=1000000000)
cQUE =  deque()
bfs(startY,startX,count)