Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:K])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)


Fixed submission:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
sum = 0
max = 0
index = 0
value = 0

for i in range(n - k + 1):
    sum = 0
    for j in range(k):
        sum += p_list[i + j]
    if sum > max:
        max = sum
        index = i

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)


Fixed submission:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
sum = 0
max = 0
index = 0
value = 0.000000000000

for i in range(n - k + 1):
    sum = 0
    for j in range(k):
        sum += p_list[i + j]
    if sum > max:
        max = sum
        index = i

for i in range(k):
    for j in range(p_list[index + i]):
        value += (j + 1) / p_list[index + i]

print(value)


Fixed submission:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)

Buggy python submission (verdict: Time Limit Exceeded):
import decimal

n, k = map(int, input().split())
p_list = list(map(int, input().split()))
sum = 0
max = 0
index = 0
value = 0

for i in range(n - k + 1):
    sum = 0
    for j in range(k):
        sum += p_list[i + j]
    if sum > max:
        max = sum
        index = i

for i in range(k):
    for j in range(p_list[index + i]):
        value += (decimal.Decimal(j + 1) / decimal.Decimal(p_list[index + i]))

print(value)


Fixed submission:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)
Buggy python submission (verdict: Runtime Error):
def solve(n,k) :
    if n <= 9 and k == 1 :
        return n
    elif n <= 9 and k >= 2 :
        return 0
    else :
        m = n //10
        r = n % 10
        return  r * solve(m,k-1) + (9 - r) * solve(m-1,k-1) + solve(m,k)

n = int(input())
k = int(input())
print(solve(n,k))


Fixed submission:
def solve(n,k) :
    if n <= 9 and k == 1 :
        return n
    elif n <= 9 and k >= 2 :
        return 0
    elif k == 0:
        return 1
    else :
        m = n //10
        r = n % 10
        return  r * solve(m,k-1) + (9 - r) * solve(m-1,k-1) + solve(m,k)

n = int(input())
k = int(input())
print(solve(n,k))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=list(map(int,input().split()))
ans=1
def solve(arr,ans):
    for i in arr:
        ans*=i
    if(ans>10**18):
        return(-1)
    return(ans)
print(solve(arr,ans))


Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
ans=1
arr=sorted(arr)
def solve(arr,ans):
    for i in arr:
        ans*=i
        if(ans>10**18):
            return(-1)
        if(ans==0):
            return(0)
    if(ans>10**18):
        return(-1)
    return(ans)
print(solve(arr,ans))

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
ans=1
for i in arr:
    if ans*i<=10**18:
        ans*=i
    else:
        print(-1)
        return(0)
print(ans)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
ans=1
arr=sorted(arr)
def solve(arr,ans):
    for i in arr:
        ans*=i
        if(ans>10**18):
            return(-1)
        if(ans==0):
            return(0)
    if(ans>10**18):
        return(-1)
    return(ans)
print(solve(arr,ans))
Buggy python submission (verdict: Runtime Error):
import math
r=int(input())
print(2*pi*r)

Fixed submission:
from math import pi
r=int(input())
print(2*pi*r)
Buggy python submission (verdict: Runtime Error):
n,m=int(input().split())
if n<=1:
    n=0
if m<=1:
    m=0
print((n*(n-1)//2)+(m*(m-1)//2))

Fixed submission:
n,m=map(int,input().split())

print((n*(n-1)//2)+(m*(m-1)//2))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
if N==M:
    print("Yes")
else:
    print("No")

Fixed submission:
N,M=map(int,input().split())
if N==M:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a=input()
s="abcdefghijklmnopqrstuvwxyz"
for i in range(len(s)-1)
  if s[i]==a:
	print(s[i+1])

Fixed submission:
a=input()
s="abcdefghijklmnopqrstuvwxyz"
for i in range(len(s)-1):
	if s[i]==a:
		print(s[i+1])
Buggy python submission (verdict: Runtime Error):
s,t=map(input().split())
if s>=t:
  print(t+s)
else:
  print(s+t)

Fixed submission:
s,t=map(str,input().split())
print(t+s)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S,T=map(input().split())
a=""
for i in range(N):
  a+=S[i]+T[i]
print(a)

Fixed submission:
N=int(input())
S,T=map(str,input().split())
a=""
for i in range(N):
  a+=S[i]+T[i]
print(a)
Buggy python submission (verdict: Runtime Error):
arr=list(map(int,input().split()))
s=0
for i in range(1,4):
  for j in range(2):
    if arr[j]==i:
      s+=(4-i)*100000
if arr[0]==arr[1] and arr[1]=1:
  s+=400000
print(s)
  


Fixed submission:
arr=list(map(int,input().split()))
s=0
for i in range(1,4):
  for j in range(2):
    if arr[j]==i:
      s+=(4-i)*100000
if arr[0]==arr[1] and arr[1]==1:
  s+=400000
print(s)
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=input()
if N%2==1:
  print("No")
else:
  for i in range(N):
    if s[i]!=s[N-i-1]:
      print("No")
      return(0)
  print("Yes")

Fixed submission:
N=int(input())
s=input()
if N%2==1:
  print("No")
else:
  b=1
  for i in range(N//2):
    if s[i]!=s[N//2+i]:
      print("No")
      b=0
      break
      
  if b==1:
  	print("Yes")
Buggy python submission (verdict: Runtime Error):
N=int(input())
def f(N):
	for i in range(1,10):
  		j=N//i
        if i*j==N and j>=1 and j<=9:
          return(True)
   	return(False)
if f(N):
  print("YES")
else:
  print("NO")
      


Fixed submission:
N=int(input())
def f(N):
  for i in range(1,10):
    j=N//i
    if i*j==N and (j>=1 and j<=9):
      return(True)
  return(False)
if f(N):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
N=int(input())
def f(N):
	for i in range(1,10):
  		for j in range(1,10):
    		if i*j==N:
              return(True)
   	return(False)
if f(N):
  print("YES")
else:
  print("NO")
      

Fixed submission:
N=int(input())
def f(N):
  for i in range(1,10):
    j=N//i
    if i*j==N and (j>=1 and j<=9):
      return(True)
  return(False)
if f(N):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
def f(x):
  s=0
  while x!=0:
    s+=x%10
    x//=10
  return(s)
minn=50
for i in range(1,N/2):
  minn=min(f(i)+f(N-i),minn)
print(minn)

Fixed submission:
N=int(input())
def f(x):
  s=0
  while x!=0:
    s+=x%10
    x//=10
  return(s)
minn=50
for i in range(1,N):
  minn=min(f(i)+f(N-i),minn)
print(minn)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
maxx=-
def got(a,al):
	for i in a:
    	if i==al:
      		return(True)
	return(False)
for i in range(n):
	a=s[:i]
  	b=s[i:]
  	cnt=0
  	alp="abcdefghijklmnopqrstuvwxyz"
  	for al in alp:
    	if got(a,al) and got(b,al):
      		cnt+=1
  	maxx=max(maxx,cnt)
print(maxx)

Fixed submission:
n=int(input())
s=input()
maxx=-1
def got(a,al):
    for i in a:
        if i==al :
      	    return(True)
    return(False)
for i in range(n):
    a=s[:i]
    b=s[i:]
    cnt=0
    alp="abcdefghijklmnopqrstuvwxyz"
    for al in alp:
        if got(a,al) and got(b,al):
      	    cnt+=1
    maxx=max(maxx,cnt)
print(maxx)
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
A =  [int(i) for i in input().split()]
ans = 1

for i in range(N):
    ans *= A[i]

if(10**18<ans):
    print(-1)
else:
    print(ans)


Fixed submission:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
A =  [int(i) for i in input().split()]
ans = 1
flag = 0

for i in range(N):
    ans *= A[i]
    if(10**18<ans):
        flag = 1
        break

if(0 in A):
    print(0)
elif(flag == 1):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]

S = str(input())
Q = int(input())
flag = 0


for i in range(Q):
  Que = str(input()).split()
  if(int(Que[0])==1):
    flag = 1 - flag
  else:
    if(flag == 1):
      if(int(Que[1])==1):
        S = S + Que[2]
      else:
        S = Que[2] + S
    else:
      if(int(Que[1])==1):
        S = Que[2] + S
      else:
        S = S + Que[2]

if(flag == 1):
  S = S[::-1]

print(S)


Fixed submission:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]

S = str(input())
Q = int(input())
flag = 0

S2 = deque(S)

#print(S2)

for i in range(Q):
  Que = str(input()).split()
  if(int(Que[0])==1):
    flag = 1 - flag
  else:
    if(flag == 1):
      if(int(Que[1])==1):
        S2.append(Que[2])
      else:
        S2.appendleft(Que[2])
    else:
      if(int(Que[1])==1):
        S2.appendleft(Que[2])
      else:
        S2.append(Que[2])

S = "".join(list(S2))

if(flag == 1):
  S = S[::-1]

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
N = int(input())
P = str(input()).split()
PP = []
# S = [[0 for i in range(W)] for j in range(H)]
val = 1

for i in range(N):
  PP.append(int(P[i]))

for i in range(N):
  #print(max(PP[:i+1]))
  #print(PP[i])
  if(i==0):
    i=0
  elif(min(PP[:i])>=PP[i]):
    val += 1

print(val)



Fixed submission:
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
N = int(input())
P = str(input()).split()
PP = []
# S = [[0 for i in range(W)] for j in range(H)]
val = 0

for i in range(N):
  PP.append(int(P[i]))

MIN = PP[0]

for i in range(N):
  #print(max(PP[:i+1]))
  #print(PP[i])
  MIN = min(MIN, PP[i])
  if(MIN>=PP[i]):
    val += 1

print(val)
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
ans = 0

for i in range(N):
  ans += i

print(ans)


Fixed submission:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
ans = (N-1)*(N)//2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
#a = [int(x) for x in input().split()]


NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])

for i in reversed(range(1,M)):
  f = M/i
  if(f.is_integer() == True):
    #print(i)
    if(N*i<=M):
      ans = i
      break


print(ans)


Fixed submission:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

#素因数分解
def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a



#X = str(input()).split()
#a = [int(x) for x in input().split()]


NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])


for i in reversed(range(math.floor(M/N)+1)):
  f = M/i
  if(f.is_integer() == True):
    if(N*i<=M):
      ans = i
      break


print(ans)
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = xytuple[2] +1 #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = xytuple[2] +1 #探索した場所は探索できないようにする
        q.append(temptuple)
      #print(q)
  return mlength


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

H,W = map(int,input().split())
S = [list(map(str, input())) for i in range(H)]
ans = 0
n = 0

#print(S)

for i in range(H):
    for j in range(W):
        if(S[i][j]=="."):
            n += 1
#print(n)
bfs(S,0,0,H,W)
#print(S)
ans = n - S[H-1][W-1]

if(type(S[H-2][W-2]) is str and type(S[H-2][W-1]) is str and type(S[H-1][W-2]) is str):
    ans = -1



print(ans)


Fixed submission:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#幅優先探索（別ver）
def bfs(sx, sy):
  que = deque([[sy,sx]])
  D =  [(0,1), (1,0), (0,-1), (-1,0)]
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "#"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
  return


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

H,W = map(int,input().split())
G = [list(map(str, input())) for i in range(H)]
ans = 0
n = 0

#print(S)

for i in range(H):
    for j in range(W):
        if(G[i][j]=="."):
            n += 1
#print(n)
G[0][0] = 0
bfs(0,0)
#print(S)

if(type(G[H-1][W-1]) is str):
    ans = -1
else:
    ans = n - G[H-1][W-1]-1


print(ans)