Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03471 (python)

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
print(ans)

n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
print(input().cont("1"))
Problem p03434 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a[::2]) - sum(a[1::2]))

Buggy submission (verdict: Runtime Error):
N = input()
a = sorted(list(map(int,input().split())), reverse=True)

print(sum(a[::2]) - a[1::2] )
Problem p03448 (python)

Fixed submission:
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, X = map(int, input().split())

count = 0
for a in range(A+1):
  for b in range(B+1):
     for c in range(C+1):
        if a+b+c= X:
          count += 1

print(count)
Problem p03457 (python)

Fixed submission:
n = int(input())
for i in range(n):
    t,x,y=map(int,input().split())
    if (x + y) > t or (x + y + t) % 2:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(n)
  t,x,y=map(int,input().split())
  if (x+y) > t or (x+y+t)%2:
    print("NO")
    exit()
  print("YES")
Problem p03470 (python)

Fixed submission:
n = int(input())

di = set(map(int, [input() for i in range(n)]))

print(len(di))

Buggy submission (verdict: Runtime Error):
d = int(input()))
 
d = set(d)
print(len(d))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = int(input()))

d = set(d)
print(len(d))
Problem p03471 (python)

Fixed submission:
N, Y = map(int, input().split())
 
for x in range(N+1):
  for y in range(N+1-x):
        if x*10000 + y*5000 + (N-x-y)*1000 == Y:
           print(x, y, N-x-y)
           exit()
 
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
 
for x in range(N+1):
  for y in range(N+1-x):
        if x*10000 + y*5000 + (N+1-x-y)*1000 == Y:
           print(x, y, N+1-x-y)
       else:
           print(-1,-1,-1)

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())

for x in range(N+1):
  for y in range(N+1-x):
    for z in range(N+1-y):
        if x*10000 + y*5000 + z*1000 == Y:
           print(x, y, z)
       else:
           print(-1,-1,-1)
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
print(input.count('1'))

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

count = 0
if a%2==1:
  count += 1
if b%2 == 1:
  count += 1
if c%2 == 1:
  count +1
 
print(count)
Problem p03494 (python)

Fixed submission:
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Buggy submission (verdict: Runtime Error):
N = input()
A = list(map(int,input()))

ans=float("inf")
for i in A:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(ans)
Problem p03854 (python)

Fixed submission:
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
  print("NO)
else:
  print("YES")

Buggy submission (verdict: Runtime Error):
s=input().replace("dream","").replace("dreamer","").replace("eraser","").replace("erase","")

if s:
print("NO")
else:
print("YES")
Problem p03455 (python)

Fixed submission:
a_, b_ = input().split()
a = (int)(a_)
b = (int)(b_)

if a%2==0:
    print("Even")
elif b%2==0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a_,b_=input().split()
a=(str)(a_)
b=(str)(b_)

if a%2==0:
  print("Even")
elif b%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b=input().split()

if a%2==0:
  print("Even")
elif b%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b=input().split()
if a%2==0:
  print("Even")
  exit(0)
if a%2==0:
  print("Even")
  exit(0)
print("Odd")

Buggy submission (verdict: Runtime Error):
a,b=input().split()
if not (int)(a)%2==0 and not (int)(b)%2==0:
  print("Odd")
  return
print("Even")

Buggy submission (verdict: Runtime Error):
a,b=input().split()
if not a%2==0 and not b%2==0:
  print("Odd")
  return
print("Even")
Problem p03471 (python)

Fixed submission:
N_,Y_=input().split()
N=(int)(N_)
Y=(int)(Y_)

count = 0
a_ = Y//10000
if a_>N:
    a_ = N
for a in range(a_+1):
    Y_ = Y-a*10000
    N_ = N-a
    b_ = Y_//5000
    if b_>N_ and b_>=0:
        b_ = N_
    for b in range(b_+1):
        Y__ = Y_-b*5000
        N__ = N_-b
        c_ = Y__//1000
        if Y__%1000==0:
            if c_==N__ and c_>=0:
                print((str)(a)+" "+(str)(b)+" "+(str)(c_))
                exit(0)
print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
N_,Y_=input().split()
N=(int)(N_)
Y=(int)(Y_)

count = 0
a_ = Y//10000
if a_>N:
    a_ = N
for a in range(a_+1):
    Y_ = Y-a*10000
    N_ = N-a
    b_ = Y_//5000
    if b_>N_ and b_>=0:
        b_ = N_
    for b in range(b_+1):
        Y_ = Y_-b*5000
        N_ = N_-b
        if c_%1000:
            c_ = Y_//1000
            if c_==N_ and c_>=0:
                print((str)(a)+" "+(str)(b)+" "+(str)(c_))
                exit(0)
print("-1 -1 -1")
Problem p03455 (python)

Fixed submission:
s = input().split()
a = int(s[0])
b = int(s[1])

if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
s = input().split()
a = s[0]
b = s[1]

if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03557 (python)

Fixed submission:
import bisect

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0
  for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
  print(ans)
  
if __name__=="__main__":
  main()

Buggy submission (verdict: Runtime Error):
def binary(list_a,item):
  low=0
  high=len(list_a)-1
  while (high-low)>1:
    mid=int((low+high)/2)
    tmp=list_a[mid]
    if tmp>item:
      high=mid
    elif tmp<item:
      low=mid
    elif tmp==item:
      eq=[i for i, x in enumerate(list_a) if x == tmp]
      high=eq[-1]
      low=eq[0]
      return low-1,high+1
  return low,high

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0
  for b in B:
    a_low,a_high=binary(A,b)
    c_low,c_high=binary(C,b)
    
    if b>A[a_high]:
      a_low=N-1
    elif b<A[a_low]:
      a_low=0
      
    if b<C[c_low]:
      c_high=0
    elif b>C[c_high]:
      c_high=N
    
    ans+=(a_low+1)*(N-c_high)
  print(ans)
  
if __name__=="__main__":
  main()

Buggy submission (verdict: Runtime Error):
def binary(list_a,item):
  low=0
  high=len(list_a)-1
  while (high-low)>1:
    mid=int((low+high)/2)
    tmp=list_a[mid]
    if tmp>item:
      high=mid
    elif tmp<item:
      low=mid
    elif tmp==item:
      eq=[i for i, x in enumerate(list_a) if x == tmp]
      high=eq[-1]
      low=eq[0]
      return low-1,high+1
  return low,high


def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  print(A)
  print(B)
  print(C)
  ans=0
  for b in B:
    a_low,a_high=binary(A,b)
    c_low,c_high=binary(C,b)
    
    if b>A[a_high]:
      a_low=N-1
    elif b<A[a_low]:
      a_low=0
      
    if b<C[c_low]:
      c_high=0
    elif b>C[c_high]:
      c_high=N
    
    print(a_low+1,N-c_high)
    ans+=(a_low+1)*(N-c_high)
  print(ans)
  
if __name__=="__main__":
  main()

Buggy submission (verdict: Runtime Error):
def binary_search(list_a,item):
  low=0
  high=len(list_a)-1
  while low<=high:
    mid=int((low+high)/2)
    guss=list_a[mid]
    if guss>item:
      high=mid-1
    elif guss<item:
      low=mid+1
    elif guss==item:
      return mid
  return mid

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0    
  for b in B:
    p=binary_search(A,b)
    if A[p]>b:
      tmp_p=p
    elif A[p]<b:
      tmp_p=p+1
    elif A[p]==b:
      while A[p]==A[p-1]:
        p-=1
      tmp_p=p
    q=binary_search(C,b)
    if C[q]>b:
      tmp_q=N-q
    elif C[q]<b:
      tmp_q=N-q-1
    elif C[q]==b:
      while C[q]==C[q+1]:
        q+=1
      tmp_q=N-q-1
    ans+=tmp_p*tmp_q
  print(ans)
  
if __name__=="__main__":
  main()
Problem p03434 (python)

Fixed submission:
from functools import reduce 
from operator import add
 
n = int(input())
arr = list(map(int, input().split()))
 
pt_a = 0
pt_b = 0
 
arr.sort(reverse=True)
 
for ind, num in enumerate(arr):
  if ind % 2 == 0:
    pt_a += num
  else:
    pt_b += num
 
print(pt_a - pt_b)

Buggy submission (verdict: Runtime Error):
from functools import reduce 
from operator import add
 
n = int(input())
arr = map(int, input().split())
 
pt_a = 0
pt_b = 0
 
arr.sort(reverse=True)
 
for ind, num in enumerate(arr):
  if ind % 2 == 0:
    pt_a += num
  else:
    pt_b += num
 
print(pt_a - pt_b)

Buggy submission (verdict: Runtime Error):
from functools import reduce 
from operator import add

n = int(input())
arr = map(int, input().split())

pt_a = 0
pt_b = 0

arr = arr.sort(reverse=True)

for ind, num in enumerate(arr):
  if ind % 2 == 0:
    pt_a += num
  else:
    pt_b += num

print(pt_a - pt_b)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
 
if a % 2 == 1 and b % 2 == 1:
  print('Odd')
else:
  print('Even')

Buggy submission (verdict: Runtime Error):
n = int(input())
 
flg = True
t_ = 0
x_ = 0
y_ = 0

for i in range(n):
  t, x, y = map(int, input().split())
  t_ = abs(t - t_)
  x_ = abs(x - x_)
  y_ = abs(y - y_)
  
  if t_ - x_ - y_ < 0:
    print('No')
    flg = False
    break
  elif (t_ - x_ - y_) % 2 != 0:
    print('No')
    flg = False
    break
  t_ = t
  x_ = x
  y_ = y
 
if flg:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
 
flg = True
t_ = 0
x_ = 0
y_ = 0
for i in range(n):
  t, x, y = map(int, input().split())
  t_ -= t
  x_ -= x
  y_ -= y
  
  if (t_ - x_ - y_) % 2 != 0:
    print('No')
    flg = False
    break
 
if flg:
  print('Yes')
Problem p03457 (python)

Fixed submission:
n = int(input())
 
flg = True
t_ = 0
x_ = 0
y_ = 0

for i in range(n):
  t, x, y = map(int, input().split())
  t_ = abs(t - t_)
  x_ = abs(x - x_)
  y_ = abs(y - y_)
  
  if t_ - x_ - y_ < 0:
    print('No')
    flg = False
    break
  elif (t_ - x_ - y_) % 2 != 0:
    print('No')
    flg = False
    break
  t_ = t
  x_ = x
  y_ = y
 
if flg:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())

flg = True
t_ = 0
x_ = 0
y_ = 0
for i in range(n):
  t, x, y = map(int, input().split())
  t_ -= t
  x_ -= x
  y_ -= y
  
  if (t_ - x_ - y_) % 2 != 0:
  	print('No')
  	flg = False
    break

if flg:
  print('Yes')
Problem p03470 (python)

Fixed submission:
n = int(input())
s = {input() for i in range(n)}
 
print(len(s))

Buggy submission (verdict: Runtime Error):
n, X = map(int, input().split())
 
for i in range(n+1):
  for j in range(n+1):
    if i+j > n:
      pass
    else:
      k = n-i-j
      otoshi = 10000*i + 5000*j + 1000*k
      if otoshi == X:
        print(i, j, k)
        break
  else:
    continue
  break

Buggy submission (verdict: Runtime Error):
n = input()
s = {input() for i in range(3)}

print(len(s))
Problem p03478 (python)

Fixed submission:
from functools import reduce 
from operator import add
n, a, b = map(int, input().split())

n_cond = 0

for i in range(1, n+1):
  i_str = str(i)

  if len(i_str) == 1:
    order_sum = i
    
  else:
    temp = list(map(int, i_str))
    order_sum = reduce(add, temp)
    
  if order_sum >= a and order_sum <= b:
    n_cond += i
print(n_cond)

Buggy submission (verdict: Runtime Error):

n, a, b = map(int, input().split())

n_cond = 0
for i in range(n+1):
  i_str = str(i)
  order_sum = map(sum, i_str)
  if order_sum >= a and order_sum <= b:
    n_cond += 1
Problem p03493 (python)

Fixed submission:
from collections import Counter
txt = input()

counter = Counter(txt)

print(counter['1'])

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))

num_dvd = 0
 
can_devide = True
temp_list = []
while can_devide:
  for num in nums:
    if num % 2 == 1:
      can_devide = False
      print(num_dvd)
      break
    else:
      temp_list.append(num // 2)
  num_dvd += 1
  nums, temp_list = temp_list, []

Buggy submission (verdict: Runtime Error):
n = input()
nums = map(int, input().split())
 
num_dvd = 0

can_devide = True
temp_list = []
while can_devide == True:
  for num in nums:
    if num % 2 == 1:
      print(num_dvd)
      can_devide == False
    else:
      temp_list.append(num // 2)
  num_dvd += 1
  nums, temp_list = temp_list, []
Problem p03494 (python)

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

num_dvd = 0
 
can_devide = True
temp_list = []
while can_devide:
  for num in nums:
    if num % 2 == 1:
      can_devide = False
      print(num_dvd)
      break
    else:
      temp_list.append(num // 2)
  num_dvd += 1
  nums, temp_list = temp_list, []

Buggy submission (verdict: Runtime Error):
n = input()
nums = map(int, input().split())
 
num_dvd = 0


temp_list = []
while can_devide == True:
  for num in nums:
    if num % 2 == 1:
      print(num_dvd)
      can_devide == False
    else:
      temp_list.append(num // 2)
  num_dvd += 1
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b)%2. == 0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
N = int(input())
t0, x0, y0 = 0, 0, 0
flag=True
for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
        print('No')
        flag=False

    elif (dist%2==0 and dt%2==0) or  (dist%2==1 and dt%2==1):
        t0, x0, y0 = t1, x1, y1

    else:
        print('No')
        flag=False

if flag:
    print('Yes')
Problem p03457 (python)

Fixed submission:
import sys

def main():
    N = int(input())
    t, x, y = 0, 0, 0

    for _ in range(N):
        next_t, next_x, next_y = [int(__) for __ in input().split()]

        delta_t = next_t - t
        distance = abs(next_x - x) + abs(next_y - y)

        if distance > delta_t:
            print("No")
            sys.exit()

        if (delta_t - distance) % 2 != 0:
            print("No")
            sys.exit()

        t, x, y = next_t, next_x, next_y

    print("Yes")

main()

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
t0, x0, y0 = 0, 0, 0

for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
        print('No')
	sys.exit()
    elif (dist -	dt)%2 ==1:
	print('No')
	sys.exit()

    else:
        t0, x0, y0 = t1, x1, y1



print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
t0, x0, y0 = 0, 0, 0
flag=True
for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
        print('No')
	break
    elif (dist -	dt)%2 ==1:
	print('No')
        break

    else:
        t0, x0, y0 = t1, x1, y1


if flag:
    print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
t0, x0, y0 = 0, 0, 0
flag=True
for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
        print('No')
        flag=False
	break

    elif (dist%2==0 and dt%2==0) or  (dist%2==1 and dt%2==1):
        t0, x0, y0 = t1, x1, y1

    else:
        print('No')
        flag=False
	break

if flag:
    print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
t0, x0, y0 = 0, 0, 0
flag=True
for i in range(N):
    t1,x1,y1 = [int(j) for j in input().split()]
    dt = t1 - t0
    dist = abs(x0-x1) + abs(y0-y1)

    if dist > dt:
	print('NO')
	flag=False

    elif (dist%2==0 and dt%2==0) or  (dist%2==1 and dt%2==1):
	t0, x0, y0 = t1, x1, y1

    else:
	print('NO')
	flag=False

if flag:
    print('YES')
Problem p03493 (python)

Fixed submission:
print(input().count('1'))

Buggy submission (verdict: Runtime Error):
print(input())print(input().count('1'))
Problem p03854 (python)

Fixed submission:
s = input()
flag = True
while flag:
    if s=='':
        flag==False
    if s[-7:]=='dreamer':
        s = s[:-7]

    elif s[-6:]=='eraser':
        s = s[:-6]

    elif s[-5:]=='dream' or s[-5:]=='erase':
        s = s[:-5]

    else:
        break


if s=='':
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
s = input()

str_list = ["eraser", "erase", "dream", "dreamer"]

for i in range(len(str_list)):
    if len(str_list[i])==7 and s[-7:]=='dreamer':
	s = s[:-7]

    elif len(str_list[i])==6 and s[-6:]=='eraser':
	s = s[:-6]
	
    elif s[-5:]=='erase' or s[-5:]=='dream':
	s = s[:-5]

if s=='':
    print('YES')
else:
    print('NO')
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b)%2 == 0:
  print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if (a*b)%2 == 0:
  print('Even')
  else:
    print('Odd')
Problem p03455 (python)

Fixed submission:
a,b = map(int, input().split())
if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')

Buggy submission (verdict: Runtime Error):
a,b = input().split()

cross = int((a * b)/2)

if cross == 0:
    print("even")

if cross != 0:
    print("odd")

Buggy submission (verdict: Runtime Error):
a = int(input())

b = int(input())


cross = int((a * b)/2)

if cross == 0:
    print("even")

if cross != 0:
    print("odd")

Buggy submission (verdict: Runtime Error):
a = int(input())

b = int(input())


cross = int((a * b)/2)

if cross == 0:
    print("even")

if cross != 0:
    print("odd")

Buggy submission (verdict: Runtime Error):

a = input()
aa = int(a)
b = input()
bb = int(b)

cross = int(aa * bb)

cd = int(cross / 2)

if cd == 0:
    print("even")

if cd != 0:
    print("odd")
Problem p03478 (python)

Fixed submission:
li = list(map(int,input().split()))


array = 0

for i in range(li[0]+1):
    l =[int(x) for x in list(str(i))]
    f = sum(l)
    if f >= li[1] and f <= li[2]:
        array = array + i

print(array)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())



    #x = sum(l)
array = 0

for i in range(N+1):
    l =[int(x) for x in list(str(i))]
    f = sum(l)
    if f >= A and f <= B:
        array = array + i

print(array)
Problem p03493 (python)

Fixed submission:
n = input()

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return array

b = digitSum(n)
a = 0
c = len(b)
for i in range(c):
    if b[i] == 1:
        a+=1
    else:
        a+=0

print(a)

Buggy submission (verdict: Runtime Error):

s1, s2, s3 = map(int, input().split())

a = 0

if s1 =1 or s2 =1 or s3 = 1:
  a += 1
else:
  a += 0

print(a)
Problem p03478 (python)

Fixed submission:
x = input()
n,a,b = [int(i) for i in x.split()]
s = 0
for x in range(1,n+1):
  if a <= sum([int(i) for i in str(x)]) <= b:
    s+= x
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
a,b = [int(i) for i in x.split()]
s = 0
for x in range(1,n+1):
  if a <= sum([int(i) for i in str(x)]) <= b:
    s+= x
print(s)
Problem p03436 (python)

Fixed submission:
dbflag=""

def next(b):
	result = []
	x,y = b
	if x -1 >= 0 and S[x-1,y]=='.' and depthS[x-1,y]== -1:
		result.append((x-1,y))
	if y -1 >= 0 and S[x,y-1]=='.' and depthS[x,y-1]== -1:
		result.append((x,y-1))
	if x +1 < H and S[x+1,y]=='.' and depthS[x+1,y]== -1:
		result.append((x+1,y))
	if y +1 < W and S[x, y+1]=='.' and depthS[x,y+1]== -1:
		result.append((x,y+1))
	
	return result

  
def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = -1

H, W = map(int, readline().split())

#２次元配列
import numpy as np

S= np.ndarray(shape=(H,W), dtype=object)

for i in range(0,H):
	S[i,0:W] =list(readline().rstrip())
	

wNum = S[S == "."].size
bNum = H * W - wNum

debug(H,W)
debug(S)
debug(wNum)



from collections import deque
queue = deque([])
#queue.append(A)
#queue.popleft()


depthS = np.full((H,W), -1, dtype=int)

depthS[0,0] = 0
queue.append((0,0))

while len(queue) > 0 and depthS[H-1,W-1]==-1:
	base = queue.popleft()
	baseDepth = depthS[base]

	debug("----")
	debug(base,baseDepth)
	debug("depthS")	
	debug(depthS)	


	neighbors = next(base)
	
	debug('depthS',depthS)
	for n in neighbors: depthS[n[0],n[1]]=baseDepth + 1

	debug('depthS2',depthS)
	debug('neighbors',neighbors)
	
	for n in neighbors:
		queue.append(n)
	debug("queue",queue)	


if depthS[H-1,W-1]!=-1:
	result = wNum - (depthS[H-1,W-1] + 1)
else:
	result = -1

print(result)

Buggy submission (verdict: Runtime Error):
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = -1

H, W = map(int, readline().split())

#２次元配列
import numpy as np

S= np.ndarray(shape=(H,W), dtype=object)

for i in range(0,H):
	S[i,0:W] =list(readline().rstrip())
	

wNum = S[S == "."].size
bNum = H * W - wNum

debug(H,W)
debug(S)
debug(wNum)



from collections import deque
queue = deque([])
#queue.append(A)
#queue.popleft()


depthS = np.full((H,W), -1, dtype=int)

depthS[0,0] = 0
queue.append((0,0))

while len(queue) > 0 and depthS[H-1,W-1]==-1:
	base = queue.popleft()
	baseDepth = depthS[base]

	debug("----")
	debug(base,baseDepth)
	debug("depthS")	
	debug(depthS)	


	neighbors = next(base)
	
	debug('depthS',depthS)
	for n in neighbors: depthS[n[0],n[1]]=baseDepth + 1

	debug('depthS2',depthS)
	debug('neighbors',neighbors)
	
	for n in neighbors:
		queue.append(n)
	debug("queue",queue)	


if depthS[H-1,W-1]!=-1:
	result = wNum - (depthS[H-1,W-1] + 1)
else:
	result = -1

print(result)


def next(b):
	result = []
	x,y = b
	if x -1 >= 0 and S[x-1,y]=='.' and depthS[x-1,y]== -1:
		result.append((x-1,y))
	if y -1 >= 0 and S[x,y-1]=='.' and depthS[x,y-1]== -1:
		result.append((x,y-1))
	if x +1 < H and S[x+1,y]=='.' and depthS[x+1,y]== -1:
		result.append((x+1,y))
	if y +1 < W and S[x, y+1]=='.' and depthS[x,y+1]== -1:
		result.append((x,y+1))
	
	return result