Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False
        else s_chr < t_chr:
            return True


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')


Fixed submission:
from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False
        elif s_chr < t_chr:
            return True


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')

Buggy python submission (verdict: Runtime Error):
from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None or s_chr < t_chr:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')

Fixed submission:
from itertools import zip_longest

def twoAnagrams(s, t):
    s_str = ''.join(sorted(s))
    t_str = ''.join(sorted(t, reverse=True))

    if t_str.startswith(s_str):
        if len(s_str) < len(t_str):
            return True
        # this implies s and t is the same string
        else:
            return False

    for s_chr,t_chr in zip_longest(s_str, t_str):
        if s_chr is None:
            return True
        elif t_chr is None or t_chr < s_chr:
            return False
        elif s_chr < t_chr:
            return True


s = list(input())
t = list(input())

print('Yes' if twoAnagrams(s,t) else 'No')
Buggy python submission (verdict: Runtime Error):

n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))

result = -100000000

# opening schedule for my shop.
# start from 1(only open Mon.AM) to 1023(open all day)
for b in range(1, 1<<10):

    profit = 0
    # compare with other shops
    for i in range(n):

        common_opening = 0
        # compare time
        for j in range(10):

            if 1&(b>>j) and f[i][j] == 1:
            
                common_opening += 1
        profit += p[i][common_opening]

    result = max(result, profit)

print(result)


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

print(a*n if b > a*n else b)
Buggy python submission (verdict: Runtime Error):
nums = [int(num) for num in input()]

target = 7

if sum(nums) == target:
    symbols = '+++'
elif nums[0] + nums[1] + nums[2] - nums[3] == target:
    symbols = '++-'
elif nums[0] + nums[1] - nums[2] + nums[3] == target:
    symbols = '+-+'
elif nums[0] + nums[1] - nums[2] - nums[3] == target:
    symbols = '+--'
elif nums[0] - nums[1] + nums[2] + nums[3] == target:
    symbols = '-++'
elif nums[0] - nums[1] + nums[2] - nums[3] == target:
    symbols = '-+-'
elif nums[0] - nums[1] - nums[2] + nums[3] == target:
    symbols = '--+'
elif nums[0] - nums[1] - nums[2] - nums[3] == target:
    symbols = '---'

print(f'{nums[0]}{symbols[0]}{nums[1]}{symbols[1]}{nums[2]}{symbols[2]}{nums[3]}=7')

Fixed submission:
nums = [int(num) for num in input()]

target = 7

if sum(nums) == target:
    symbols = '+++'
elif nums[0] + nums[1] + nums[2] - nums[3] == target:
    symbols = '++-'
elif nums[0] + nums[1] - nums[2] + nums[3] == target:
    symbols = '+-+'
elif nums[0] + nums[1] - nums[2] - nums[3] == target:
    symbols = '+--'
elif nums[0] - nums[1] + nums[2] + nums[3] == target:
    symbols = '-++'
elif nums[0] - nums[1] + nums[2] - nums[3] == target:
    symbols = '-+-'
elif nums[0] - nums[1] - nums[2] + nums[3] == target:
    symbols = '--+'
elif nums[0] - nums[1] - nums[2] - nums[3] == target:
    symbols = '---'

result = ''
for i in range(len(symbols)):
    result += str(nums[i])
    result += symbols[i]
result += str(nums[-1])

print('{}=7'.format(result))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

max_mids = max(mids)
max_bottoms = max(bottoms)

tops = [t for t in tops if t < max_mids]
mids = [m for m in mids if m < max_bottoms]

sets = []

# for t,m,b in product(tops,mids,bottoms):
#     if t < m and m < b:
#         sets.append((t,m,b))

for t in tops:
    for m in mids:
        if t < m:
            for b in bottoms:
                if m < b:
                    sets.append((t,m,b))

print(len(sets))

Fixed submission:
import bisect

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

tops.sort()
bottoms.sort()

nos_sets = 0

for m in mids:
    t = bisect.bisect_left(tops, m)
    b = n - bisect.bisect_right(bottoms, m)
    nos_sets += t * b

print(nos_sets)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

max_mids = max(mids)
max_bottoms = max(bottoms)

tops = [t for t in tops if t < max_mids]
mids = [m for m in mids if m < max_bottoms]

sets = []

for t,m,b in product(tops,mids,bottoms):
    if t < m and m < b:
        sets.append((t,m,b))

print(len(sets))

Fixed submission:
import bisect

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

tops.sort()
bottoms.sort()

nos_sets = 0

for m in mids:
    t = bisect.bisect_left(tops, m)
    b = n - bisect.bisect_right(bottoms, m)
    nos_sets += t * b

print(nos_sets)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

sets = []

for t,m,b in product(tops,mids,bottoms):
    if t < m and m < b:
        sets.append((t,m,b))

print(len(sets))

Fixed submission:
import bisect

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

tops.sort()
bottoms.sort()

nos_sets = 0

for m in mids:
    t = bisect.bisect_left(tops, m)
    b = n - bisect.bisect_right(bottoms, m)
    nos_sets += t * b

print(nos_sets)
Buggy python submission (verdict: Runtime Error):
s = input()
a, b, c = [int(x) for x in s.split(' ')]
if a+b < c:
    echo('No')
else:
    echo('Yes')

Fixed submission:
s = input()
a, b, c = [int(x) for x in s.split(' ')]
if a+b < c:
    print('No')
else:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
s = input()
a, b, c = [int(x) for x in s.split(' ')]
if a+b < c:
    return 'No'
else:
    return 'Yes'

Fixed submission:
s = input()
a, b, c = [int(x) for x in s.split(' ')]
if a+b < c:
    print('No')
else:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
a, b, c = input().split(' ')
if a+b < c:
    return 'No'
else:
    return 'Yes'

Fixed submission:
s = input()
a, b, c = [int(x) for x in s.split(' ')]
if a+b < c:
    print('No')
else:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, raw_input().split())
return "Yes" if a + b >= c else "No"

Fixed submission:
a, b, c = map(int, raw_input().split())
print "Yes" if a + b >= c else "No"
Buggy python submission (verdict: Runtime Error):
s = input()

if s[0] == s[1] == s[2] or s[1] == s[2] == s[3]
    print('Yes')
else:
    print('No')

Fixed submission:
n = input()
if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
A=input()
A=int(A)
B=input()
B=int(B)
C=input()
C=int(C)

if A+B >= C:
    print('Yes')
else:
    print('No')


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

           
if nums[0]+nums[1] >= nums[2]:
    print('Yes')
else:
    print('No')

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

if A+B >= C:
    print('Yes')
else:
    print('No')


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

           
if nums[0]+nums[1] >= nums[2]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
R=input()
G=input()
print(2*G-R)

Fixed submission:
R=int(input())
G=int(input())
print(2*G-R)

Buggy python submission (verdict: Runtime Error):
R=input()
G=input()
if R<G:
  print(2*G-R)
elif R>G:
  print(-1*(2*G-R))

Fixed submission:
R=int(input())
G=int(input())
print(2*G-R)
Buggy python submission (verdict: Runtime Error):
s=input()
print(s[i]-s[-7])

Fixed submission:
s=input()
print(s[:-8])
Buggy python submission (verdict: Runtime Error):
s=input()
print (s.count(1))

Fixed submission:
print (input().count("1"))
Buggy python submission (verdict: Runtime Error):
a=input().split()
if(a[0]==a[2]):
 print("Yes")
else:
 print("No")

Fixed submission:
a = input()
a.split()

if(a[0] == a[2]):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a=input().split
if(a[0]==a[2]):
 print("Yes")
else:
 print("No")

Fixed submission:
a = input()
a.split()

if(a[0] == a[2]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A=int(input()) % 3
B=int(input()) % 3
C=A + B
 
if  A==0 or B==0 or C==0: print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=a+b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=A + B
 
if  A%3==0 or B%3==0 or C%3==0: print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=A + B

if  A % 3 == 0 or B % 3 == 0 or C % 3 == 0:
 print("Possible")
else:
 print("Impossible")


Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=A + B

if  A % 3 == 0 : print("Possible")
else: print("Impossible")
if B % 3 == 0 : print("Possible")
else: print("Impossible")
if C % 3 == 0 : print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")

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

if  A % 3 == 0 : print("Possible")
else: print("Impossible")
if B % 3 == 0 : print("Possible")
else: print("Impossible")
if A+B % 3 == 0 : print("Possible")
else: print("Impossible")

Fixed submission:
a,b=map(int,input().split())
c=a + b
 
if  a%3==0 or b%3==0 or c%3==0: print("Possible")
else: print("Impossible")
Buggy python submission (verdict: Runtime Error):
a = int(input("coinA:"))
b = int(input("coinB:"))
c = int(input("priceC:"))

if a + b >= c:
	print("Yes")
else:
	print("No")

Fixed submission:
a, b, c = map(int, input().split())

if a + b >= c:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points)

idx = 0
if get_point % 10 != 0:
    print(get_point)
else:
    while points_sorted[idx] % 10 == 0:
        idx += 1
        if idx == N - 1:
            print(0)
    print(get_point - points_sorted[idx])

Fixed submission:
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))

Buggy python submission (verdict: Runtime Error):
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points)

idx = 0
if get_point % 10 != 0:
    print(get_point)
else:
    while points_sorted[idx] % 10 == 0:
        idx += 1
        if idx == N:
            print(0)
    print(get_point - points_sorted[idx])

Fixed submission:
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))

Buggy python submission (verdict: Runtime Error):
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points)
if get_point % 10 != 0:
    print(get_point)
else:
    cand1 = get_point - points_sorted[0]
    cand2 = get_point - points_sorted[1]
    if (cand1 > cand2) and (cand1 % 10 != 0):
        print(cand1)
    elif (cand2 % 10 != 0):
        print(cand2)
    else:
        print(0)

Fixed submission:
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))

Buggy python submission (verdict: Runtime Error):
inputs = list(input().split())

n = inputs[0]
points = [int(s) for s in inputs[1:]]

get_point = sum(points)

while get_point % 10 == 0:
    get_point -= min(points)
    if get_point <= 0:
        break

print(get_point)

Fixed submission:
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))
Buggy python submission (verdict: Runtime Error):
N=int(input())
NCount = 0
while N =>0:
    NCount+= 1
    N -=3
print(NCount-1)

Fixed submission:
N=int(input())
NCount = 0
while N >=0:
    NCount+= 1
    N -=3
print(NCount-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
NCount = 0
while N =>0:
    NCount+= 1
    N -=3
print(NCount-1)

Fixed submission:
a=int(input())
b=input()
if 'Y' in b:
    print("Four")
else:
    print("Three")
Buggy python submission (verdict: Runtime Error):
lista=input().split
a=int(lista[0])
b=int(lista[1])
c=int(lista[2])
if a+b>=c:
  print('Yes')
else:
  print('No')

Fixed submission:
lista=input().split()
a=int(lista[0])
b=int(lista[1])
c=int(lista[2])
if a+b>=c:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = {}
for i in range(n):
    a=input()
    if a in d:
        d[a]+=1
    else:
        d[a]=1
m = int(input())
for i in range(n):
    a=input()
    if a in d:
        d[a]-=1
    else:
        d[a]=-1
print(max(d.values()))


Fixed submission:
n = int(input())
d = {}
for i in range(n):
    a=input()
    if a in d:
        d[a]+=1
    else:
        d[a]=1
m = int(input())
for i in range(m):
    a=input()
    if a in d:
        d[a]-=1
    else:
        d[a]=-1
m=max(d.values())
if m<0:
    m=0
print(m)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = a * b
d = c % 2
if d == 0 :
    print('Even')
else :
    print('Odd')


Fixed submission:
x = input().split()
#x = [3,4]
#x[0] = 3, x[1] = 4

a = int(x[0])
b = int(x[1])
c = a * b
d = c % 2
if d == 0 :
    print('Even')
else :
    print('Odd')
Buggy python submission (verdict: Runtime Error):
import numpy as np
N,M=map(int,input().split())

A=np.zeros((N,M))
def re(x,y):
    global A
    try:
        if x>=0 and y>=0:
            if A[x][y]==0:
                A[x][y]=1
            else:
                A[x][y]=0
    except:
        pass
    return A


for i in range(N):
    for j in range(M):
        for X in range(-1,2):
            for Y in range(-1,2):
                re(i+X,j+Y)

print(np.count_nonzero(A))



Fixed submission:
N,M=map(int,input().split())

if N==1 and M==1:
    print(1)
elif N==1 or M==1:
    print(max(N,M)-2)
else:
    print((N-2)*(M-2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [int(x) for x in input().split()]

res = 'Three'
if 'Y' in s:
  res = 'Four'

print(res)


Fixed submission:
n = int(input())
s = input().split()

res = 'Three'
if 'Y' in s:
  res = 'Four'

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

res = 0

a.sort()
cnt = 0
nex = 0
find = a[0]
for i in range(len(a)):
  find = a[nex]
  for v in a[nex:]:
    if v == find:
      cnt += 1
      nex += 1
    else:
      break
  if cnt >= find:
    res += cnt - find
  else:
    res += cnt
  cnt = 0
  if nex > len(a) - 1:
    break

print(res)


Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

res = 0

find = a[0]
cnt = {a[0]: 0}
for v in a:
  if v not in cnt:
    cnt[v] = 0
  cnt[v] += 1

for k,v in cnt.items():
  if v >= k:
    res += v - k
  else:
    res += v

print(res)
Buggy python submission (verdict: Runtime Error):

A,B = input().split(' ')
num = 0
for i in range(int(A), int(B)+1):
    s = str(i)
    for j in range(len(s)//2):
        if s[j] != s[len(s)-1-j]:
            break
        if j == len(s)//2 - 1:
            num += 1
print(num

Fixed submission:
A,B = input().split(' ')
num = 0
for i in range(int(A), int(B)+1):
    s = str(i)
    for j in range(len(s)//2):
        if s[j] != s[len(s)-1-j]:
            break
        if j == len(s)//2 - 1:
            num += 1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):

N,M = map(int, input().split(' '))
num = 0
for n in range(N):
    if (n == 0 and n+1 == N) or (n > 0 and n < N-1):
        if M < 2:
            num += 1
        else:
            num += M - 2 
print(num)

Fixed submission:

import sys

N,M = map(int, input().split(' '))
num = 0
if N == 1:
    if M < 2:
        print(1)
        sys.exit()
    print(str(M-2))
    sys.exit()
elif N == 2:
    print(0)
    sys.exit()
else:
    if M < 2:
        num = N-2
    else:
        num = (M-2)*(N-2) 
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split(' '))
mass = [[True for i in range(M)] for j in range(N)]
for n in range(N):
    for m in range(M):
        if n > 0:
            if m > 0:
                mass[n-1][m-1] = not mass[n-1][m-1]
            mass[n-1][m] = not mass[n-1][m]
            if m < M-1:
                mass[n-1][m+1] = not mass[n-1][m+1]
        if n < N-1:
            if m > 0:
                mass[n+1][m-1] = not mass[n+1][m-1]
            mass[n+1][m] = not mass[n+1][m]
            if m < M-1:
                mass[n+1][m+1] = not mass[n+1][m+1]
        if m > 0:
            mass[n][m-1] = not mass[n][m-1]
        mass[n][m] = not mass[n][m]
        if m < M-1:
            mass[n][m+1] = not mass[n][m+1]
num = 0
for n in range(N):
    for m in range(M):
        if not mass[n][m]:
            num += 1
print(num)

Fixed submission:

import sys

N,M = map(int, input().split(' '))
num = 0
if N == 1:
    if M < 2:
        print(1)
        sys.exit()
    print(str(M-2))
    sys.exit()
elif N == 2:
    print(0)
    sys.exit()
else:
    if M < 2:
        num = N-2
    else:
        num = (M-2)*(N-2) 
    print(num)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split(' '))
S = [input() for i in range(H)]
M = [[10000]*W for i in range(H)]
M[0][0] = 0
for k in range(H*W):
    for i in range(H):
        for j in range(W):
            if M[i][j] == k:
                if i > 0 and M[i-1][j] > k+1 and S[i-1][j] == '.':
                    M[i-1][j] = k+1
                if i < H-1 and M[i+1][j] > k+1 and S[i+1][j] == '.':
                    M[i+1][j] = k+1
                if j > 0 and M[i][j-1] > k+1 and S[i][j-1] == '.':
                    M[i][j-1] = k+1
                if j < W-1 and M[i][j+1] > k+1 and S[i][j+1] == '.':
                    M[i][j+1] = k+1
if M[-1][-1] == 10000:
    print(-1)
    sys.exit()
minDis = M[-1][-1] + 1
numWhite = 0
for line in S:
    numWhite += line.count('.')
print(numWhite-minDis)

Fixed submission:
import sys
import math

H, W = map(int, input().split(' '))
S = [input() for i in range(H)]
M = [[10000]*W for i in range(H)]
M[0][0] = 0
for k in range(H*W):
    for i in range(H):
        for j in range(W):
            if M[i][j] == k:
                if i > 0 and M[i-1][j] > k+1 and S[i-1][j] == '.':
                    M[i-1][j] = k+1
                if i < H-1 and M[i+1][j] > k+1 and S[i+1][j] == '.':
                    M[i+1][j] = k+1
                if j > 0 and M[i][j-1] > k+1 and S[i][j-1] == '.':
                    M[i][j-1] = k+1
                if j < W-1 and M[i][j+1] > k+1 and S[i][j+1] == '.':
                    M[i][j+1] = k+1
if M[-1][-1] == 10000:
    print(-1)
    sys.exit()
minDis = M[-1][-1] + 1
numWhite = 0
for line in S:
    numWhite += line.count('.')
print(numWhite-minDis)