Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
M=list(["*"]+list(input())+["*"] for i in range(h))
M.append(["*"]*(w+2))
M.insert(0,["*"]*(w+2))
add=[]
def go(a,b):
    root=[[1,0],[-1,0],[0,1],[0,-1]]
    for x,y in root:
        A,B=a+x,b+y
        if M[A][B]==".":
            M[A][B]="*"
            go(A,B)
            add.append((A,B))
    return add

cnt=0
if (h,w) in go(1,1):
    for i in range(1,h+1):
        for j in range(1,w+1):
            if M[i][j]=="#":cnt +=1
    print((h*w)-(h+w+cnt-1))
else:print(-1)

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
M=list(["*"]+list(input())+["*"] for i in range(h))
M.append(["*"]*(w+2))
M.insert(0,["*"]*(w+2))
add=[]
def go(a,b):
    root=[[1,0],[-1,0],[0,1],[0,-1]]
    for x,y in root:
        A,B=a+x,b+y
        if M[A][B]==".":
            M[A][B]="*"
            go(A,B)
            add.append((A,B))
    return add

cnt=0
if (h,w) in go(1,1):
    for i in range(1,h+1):
        for j in range(1,w+1):
            if M[i][j]=="#":cnt +=1
    print((h*w)-(h+w+cnt-1))
else:print(-1)

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
box=[list(input()) for i in range(h)]
count=h*w-(w+h-1)
for i in range(h):
    for j in range(w):
        if box[i][j]=="#":
            count -=1

another_box=[["#"]+box[i]+["#"] for i in range(h)]
another_box.insert(0,["#"]*(w+2))
another_box.append(["#"]*(w+2))
another_box[h][w]="G"

def maper(another_box,strat_x,strat_y):
    another_box[strat_x][strat_y]="#"
    for xx,yy in [[0,1],[0,-1],[1,0],[-1,0]]:
        n_x,n_y=strat_x+xx,strat_y+yy
        if another_box[n_x][n_y]==".":
            maper(another_box,n_x,n_y)
        elif another_box[n_x][n_y]=="G":
            another_box[n_x][n_y]="C"
    return another_box

flag=0
answer_box=maper(another_box,1,1)
for i in range(h+2):
    for j in range(w+2):
        if answer_box[i][j]=="C":
            flag=1

if flag==1:print(count)
else:print(-1)

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
box=[list(input()) for i in range(h)]
count=h*w-(w+h-1)
for i in range(h):
    for j in range(w):
        if box[i][j]=="#":
            count -=1

another_box=[["#"]+box[i]+["#"] for i in range(h)]
another_box.insert(0,["#"]*(w+2))
another_box.append(["#"]*(w+2))
another_box[h][w]="G"
print(np.array(another_box))
def maper(another_box,strat_x,strat_y):
    another_box[strat_x][strat_y]="#"
    for xx,yy in [[0,1],[0,-1],[1,0],[-1,0]]:
        n_x,n_y=strat_x+xx,strat_y+yy
        if another_box[n_x][n_y]==".":
            maper(another_box,n_x,n_y)
        elif another_box[n_x][n_y]=="G":
            another_box[n_x][n_y]="C"
    return another_box

flag=0
answer_box=maper(another_box,1,1)
for i in range(h+2):
    for j in range(w+2):
        if answer_box[i][j]=="C":
            flag=1

if flag==1:print(count)
else:print(-1)

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
box=[list(input()) for i in range(h)]
count=h*w-(w+h-1)
for i in range(h):
    for j in range(w):
        if box[i][j]=="#":
            count -=1

another_box=[["#"]+box[i]+["#"] for i in range(h)]
another_box.insert(0,["#"]*(w+2))
another_box.append(["#"]*(w+2))
another_box[h][w]="G"

def maper(another_box,strat_x,strat_y):
    another_box[strat_x][strat_y]="#"
    for xx,yy in [[0,1],[0,-1],[1,0],[-1,0]]:
        n_x,n_y=strat_x+xx,strat_y+yy
        if another_box[n_x][n_y]==".":
            maper(another_box,n_x,n_y)
        elif another_box[n_x][n_y]=="G":
            another_box[n_x][n_y]="C"
    return another_box

flag=0
answer_box=maper(another_box,1,1)
for i in range(h+2):
    for j in range(w+2):
        if answer_box[i][j]=="C":
            flag=1

if flag==1:print(count)
else:print("-1")

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
box=[list(input()) for i in range(h)]
count=h*w-(w+h-1)
for i in range(h):
    for j in range(w):
        if box[i][j]=="#":
            count -=1

another_box=[["#"]+box[i]+["#"] for i in range(h)]
another_box.insert(0,["#"]*(w+2))
another_box.append(["#"]*(w+2))
another_box[h][w]="G"

def maper(another_box,strat_x,strat_y):
    another_box[strat_x][strat_y]="#"
    for xx,yy in [[0,1],[0,-1],[1,0],[-1,0]]:
        n_x,n_y=strat_x+xx,strat_y+yy
        if another_box[n_x][n_y]==".":
            maper(another_box,n_x,n_y)
        elif another_box[n_x][n_y]=="G":
            another_box[n_x][n_y]="C"
    return another_box

flag=0
answer_box=maper(another_box,1,1)
for i in range(h+2):
    for j in range(w+2):
        if answer_box[i][j]=="C":
            flag=1

if flag==1:print(count)
else:print(-1)

Fixed submission:
h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)