Buggy python submission (verdict: Runtime Error):
R,C=map(int,input().split())
sx,sy=1,1
gx,gy=R,C
count=0
mp = [[i for i in input().rstrip()] for i in range(R)]
for i in range(R):
  mp[i]=list(mp[i])
for i in range(R):
	for j in range(C):
		if(mp[i][j]=='#'):
			count+=1
ans=[[3000 for i in range(C)] for j in range(R)]
ans[sx-1][sy-1]=0
start=[sx-1,sy-1]
goal=[gx-1,gy-1]
nsx=[1,0,-1,0]
nsy=[0,1,0,-1]

def bfs(graph,st,end):
  queue=[st]
  while queue:
    nw=queue.pop(0)
    if nw==end:
      return ans[end[0]][end[1]]
    else:
      for i in range(4):
        ns1=nw[0]+nsx[i]
        ns2=nw[1]+nsy[i]
        if (0 <= ns1)and(ns1<=(R-1))and(0<=ns2)and(ns2<=(C-1)) and ans[ns1][ns2]==3000 and mp[ns1][ns2]==".":
          ans[ns1][ns2]=ans[nw[0]][nw[1]]+1
          queue.append([ns1,ns2])
  return

print(R*C-bfs(mp,start,goal)-1-count)


Fixed submission:
R,C=map(int,input().split())
sx,sy=1,1
gx,gy=R,C
count=0
mp = [[i for i in input().rstrip()] for i in range(R)]
for i in range(R):
  mp[i]=list(mp[i])
for i in range(R):
	for j in range(C):
		if(mp[i][j]=='#'):
			count+=1
ans=[[3000 for i in range(C)] for j in range(R)]
ans[sx-1][sy-1]=0
start=[sx-1,sy-1]
goal=[gx-1,gy-1]
nsx=[1,0,-1,0]
nsy=[0,1,0,-1]

def bfs(graph,st,end):
  queue=[st]
  while queue:
    nw=queue.pop(0)
    if nw==end:
      return ans[end[0]][end[1]]
    else:
      for i in range(4):
        ns1=nw[0]+nsx[i]
        ns2=nw[1]+nsy[i]
        if (0 <= ns1)and(ns1<=(R-1))and(0<=ns2)and(ns2<=(C-1)) and ans[ns1][ns2]==3000 and mp[ns1][ns2]=='.':
          ans[ns1][ns2]=ans[nw[0]][nw[1]]+1
          queue.append([ns1,ns2])
  return

while True:
	try:
		print(R*C-bfs(mp,start,goal)-1-count)
		break
	except (RuntimeError,TypeError,NameError):
		print(-1)
		break

Buggy python submission (verdict: Runtime Error):
from collections import Counter
R,C=map(int,input().split())
sx,sy=1,1
gx,gy=R,C
count=0
mp = [[i for i in input().rstrip()] for i in range(R)]
for i in range(R):
  mp[i]=list(mp[i])
for i in range(R):
	for j in range(C):
		if(mp[i][j]=='#'):
			count+=1
ans=[[3000 for i in range(C)] for j in range(R)]
ans[sx-1][sy-1]=0
start=[sx-1,sy-1]
goal=[gx-1,gy-1]
nsx=[1,0,-1,0]
nsy=[0,1,0,-1]

def bfs(graph,st,end):
  queue=[st]
  while queue:
    nw=queue.pop(0)
    if nw==end:
      return ans[end[0]][end[1]]
    else:
      for i in range(4):
        ns1=nw[0]+nsx[i]
        ns2=nw[1]+nsy[i]
        if (0 <= ns1)and(ns1<=(R-1))and(0<=ns2)and(ns2<=(C-1)) and ans[ns1][ns2]==3000 and mp[ns1][ns2]==".":
          ans[ns1][ns2]=ans[nw[0]][nw[1]]+1
          queue.append([ns1,ns2])
  return

print(R*C-bfs(mp,start,goal)-1-count)


Fixed submission:
R,C=map(int,input().split())
sx,sy=1,1
gx,gy=R,C
count=0
mp = [[i for i in input().rstrip()] for i in range(R)]
for i in range(R):
  mp[i]=list(mp[i])
for i in range(R):
	for j in range(C):
		if(mp[i][j]=='#'):
			count+=1
ans=[[3000 for i in range(C)] for j in range(R)]
ans[sx-1][sy-1]=0
start=[sx-1,sy-1]
goal=[gx-1,gy-1]
nsx=[1,0,-1,0]
nsy=[0,1,0,-1]

def bfs(graph,st,end):
  queue=[st]
  while queue:
    nw=queue.pop(0)
    if nw==end:
      return ans[end[0]][end[1]]
    else:
      for i in range(4):
        ns1=nw[0]+nsx[i]
        ns2=nw[1]+nsy[i]
        if (0 <= ns1)and(ns1<=(R-1))and(0<=ns2)and(ns2<=(C-1)) and ans[ns1][ns2]==3000 and mp[ns1][ns2]=='.':
          ans[ns1][ns2]=ans[nw[0]][nw[1]]+1
          queue.append([ns1,ns2])
  return

while True:
	try:
		print(R*C-bfs(mp,start,goal)-1-count)
		break
	except (RuntimeError,TypeError,NameError):
		print(-1)
		break