Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n_ = 2 * 10**6 + 5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod


def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod


def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    return u % mod


inv26 = modinv(26, mod)

K = int(input())
S = input()
M = len(S)

ans = 0
po = 1
poo = pow(26, K, mod)
for i in range(K+1):
    ans = (ans + po * poo % mod * nCr(i+M-1, i)) % mod
    po = po * 25 % mod
    poo = poo * inv26 % mod
print(ans)


Fixed submission:
n_ = 2 * 10**6 + 5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod


def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod


def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    return u % mod


inv26 = modinv(26, mod)

K = int(input())
S = input()
M = len(S)

ans = 0
po = 1
poo = pow(26, K, mod)
for i in range(K+1):
    ans = (ans + po * poo % mod * nCr(i+M-1, i)) % mod
    po = po * 25 % mod
    poo = poo * inv26 % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from numba import njit

P = 10**9+7

nn = 2002002
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P


def C(a, b): return fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0


@njit('i8(i8, i8, i8)', cache=True)
def mod_pow(x, a, MOD):
    ret = 1
    cur = x
    while a:
        if a & 1:
            ret = ret * cur % MOD
        cur = cur * cur % MOD
        a >>= 1
    return ret


K = int(input())
S = input()
M = len(S)

ans = 0
po = 1
poo = 26 ** K
for i in range(K+1):
    ans += (C(i+M-1, i) * mod_pow(25, i, P) % P * mod_pow(26, K-i, P)) % P
    ans %= P
print(ans)


Fixed submission:
n_ = 2 * 10**6 + 5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod


def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod


def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    return u % mod


inv26 = modinv(26, mod)

K = int(input())
S = input()
M = len(S)

ans = 0
po = 1
poo = pow(26, K, mod)
for i in range(K+1):
    ans = (ans + po * poo % mod * nCr(i+M-1, i)) % mod
    po = po * 25 % mod
    poo = poo * inv26 % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
print(a * b)

Fixed submission:
a, b = map(int, input().split())
print(str(a * b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
ans = 1
for a in A:
    ans *= a
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)


Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
ans = 1
if 0 in A:
    print(0)
    exit(0)
for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(-1)
        exit(0)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, X = input().split()
C, A = [], []
for _ in range(N):
    tmp = [int(a) for a in input().split()]
    C.append(tmp[0])
    A.append(tmp[1:])

mi = 1 << 100
for binary in range(1 << N):
    B = [0] * M
    c = 0
    for i in range(N):
        if binary >> N & 1:
            c += C[i]
            for j in range(M):
                B[j] += A[i][j]
    if min(B) >= X:
        mi = min(c, mi)
print(mi if mi < 1 << 99 else -1)


Fixed submission:
N, M, X = map(int, input().split())
A, C = [], []
for _ in range(N):
    tmp = input().split()
    C.append(int(tmp[0]))
    A.append([int(i) for i in tmp[1:]])
is_clear = False
min_cost = 10**10
for flg_number in range(2 ** N):
    flgs = format(flg_number, '0'+str(N)+'b')
    thr = [X] * M
    cost = 0
    for i in range(N):
        if flgs[i] == '1':
            cost += C[i]
            for j in range(M):
                thr[j] -= A[i][j]
    is_all_clear = True
    for j in range(M):
        if thr[j] > 0:
            is_all_clear = False
            break
    if is_all_clear:
        is_clear = True
        if min_cost > cost:
            min_cost = cost
if is_clear:
    print(min_cost)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

N = int(input())
A = [int(a) for a in input().split()]

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in d_j.keys():
    arr_i = d_i[key]
    arr_j = d_j[key]
    for i in arr_i:
        for j in arr_j:
            if i > j:
                cnt += 1
print(cnt)


Fixed submission:
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

N = int(input())
A = [int(a) for a in input().split()]

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in d_j.keys():
    arr_i = d_i[key]
    arr_j = d_j[key]
    cnt += len(arr_j) * len(arr_i)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
for i in range(N):
    for j in range(i):
        if i - j == A[i] + A[j]:
            cnt += 1
print(cnt)


Fixed submission:
from collections import defaultdict
d_i = defaultdict(list)
d_j = defaultdict(list)

N = int(input())
A = [int(a) for a in input().split()]

for i in range(N):
    d_i[i-A[i]].append(i)
    d_j[i+A[i]].append(i)

cnt = 0
for key in d_j.keys():
    arr_i = d_i[key]
    arr_j = d_j[key]
    cnt += len(arr_j) * len(arr_i)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(input())
    for a in range(1, n+1):
        for b in range(1, n+1):
            for c in range(1, n+1):
                res += gcd_3(a, b, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()


Fixed submission:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(input())
    for a in range(1, n+1):
        for b in range(1, n+1):
            m = gcd(a, b)
            if m == 1:
                res += 1*n
            else:
                for c in range(1, n+1):
                    res += gcd(m, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin


def main():
    res = 0
    n = int(input())
    s = str(input())
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue
            else:
                for k in range(j+1, n):
                    if s[i] == s[k] or s[j] == s[k]:
                        continue
                    if j - i == k - j:
                        continue
                    res += 1
    print(res)


def input(): return stdin.readline().rstrip()


main()


Fixed submission:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin


def main2():
    res = 0
    n = int(input())
    s = str(input())
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue
            else:
                for k in range(j+1, n):
                    if s[i] == s[k] or s[j] == s[k]:
                        continue
                    if j - i == k - j:
                        continue
                    res += 1
    print(res)


def main():
    res = 0
    n = int(input())
    s = str(input())
    r = [i for i in range(n) if s[i] == "R"]
    g = [i for i in range(n) if s[i] == "G"]
    b = [i for i in range(n) if s[i] == "B"]

    for i in range(n):
        if s[i] == "R":
            res += sum(x > i for x in g) * sum(x > i for x in b)
        elif s[i] == "G":
            res += sum(x > i for x in r) * sum(x > i for x in b)
        elif s[i] == "B":
            res += sum(x > i for x in r) * sum(x > i for x in g)
        for j in range(i+1, n):
            k = (j-i)+j
            if k >= n:
                continue
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                res -= 1
    print(res)


def input(): return stdin.readline().rstrip()


main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    re = 1
    if K %2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        re =  (re*10)%K
        k = (k+7*re)%K
        count += 1


main()


Fixed submission:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    re = 1
    if K % 2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        re =  (re*10)%K
        k = (k+7*re)%K
        count += 1
        if count >= 10**7:
            print(-1)
            return


main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    if K %2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        k = (k+7*(10**count))%K
        count += 1


main()


Fixed submission:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    re = 1
    if K % 2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        re =  (re*10)%K
        k = (k+7*re)%K
        count += 1
        if count >= 10**7:
            print(-1)
            return


main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))



def main():
    count = 0
    A,B,C = inpl()
    K = int(input())
    while True:
        if A < B < C:
            print('Yes')
            return
        if B < A:
            B *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return
        if C < B:
            C *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return
main()


Fixed submission:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))



def main():
    count = 0
    A,B,C = inpl()
    K = int(input())
    for i in range(K+1):
        for j in range(K+1-i):
            k = K-i-j
            a = A*(2**i)
            b = B*(2**j)
            c = C*(2**k)
            if a < b < c:
                print('Yes')
                return

    print('No')
    """while True:
        if A < B < C:
            print('Yes')
            return
        if B < A:
            B *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return
        if C < B:
            C *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return"""
main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
"""ans = 1
for a in A:
    ans = ans*a
    if ans == 0:
        break"""
from functools import reduce
ans = reduce(lambda x,y:x*y,A)
if ans >10**18:
    print(-1)
else:
    print(ans)


Fixed submission:
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans = ans*a
        if ans > 10**18:
            break
    """from functools import reduce
    ans = reduce(lambda x,y:x*y,A)"""
    """import numpy as np
    A = np.array(A)
    ans = np.prod(A)"""
    if ans >10**18:
        print(-1)
    else:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
ans = 1
for a in A:
    ans = ans*a
    if ans == 0:
        break


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


Fixed submission:
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans = ans*a
        if ans > 10**18:
            break
    """from functools import reduce
    ans = reduce(lambda x,y:x*y,A)"""
    """import numpy as np
    A = np.array(A)
    ans = np.prod(A)"""
    if ans >10**18:
        print(-1)
    else:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
ans = 1
for a in A:
    ans = ans*a
    if ans == 0:
        break


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


Fixed submission:
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans = ans*a
        if ans > 10**18:
            break
    """from functools import reduce
    ans = reduce(lambda x,y:x*y,A)"""
    """import numpy as np
    A = np.array(A)
    ans = np.prod(A)"""
    if ans >10**18:
        print(-1)
    else:
        print(ans)

Buggy python submission (verdict: Runtime Error):

N = int(input())
A = list(map(int, stdin.readline().split()))
ans = 1
for a in A:
    ans = ans* a
    if ans >= 10**18:
        break

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


Fixed submission:
from sys import stdin
N = int(input())
A = list(map(int, stdin.readline().split()))
if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans = ans*a
        if ans > 10**18:
            break
    """from functools import reduce
    ans = reduce(lambda x,y:x*y,A)"""
    """import numpy as np
    A = np.array(A)
    ans = np.prod(A)"""
    if ans >10**18:
        print(-1)
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,X = map(int, input().split())
grid = [[]]
for i in range(N):
    ls = list(map(int, input().split()))
    grid.append(ls)

def rec(r,progress,result):
    if r == N:
        progress = progress 
        result.append(progress)
        progress = progress + [grid[N]]
        result.append(progress)
        return
    else:
        rec(r+1,progress,result)
        progress = progress + [grid[r]]
        rec(r+1,progress,result)

def rap():
    result = []
    progress = []
    rec(0,progress,result)
    ans = float('inf')
    for item in result:
        stals = [0]*(M+1)
        for item2 in item:
            for i, j in enumerate(item2):
                stals[i] += j
        f = True
        for  m in stals[1:]:
            if m < X:
                f = False
        if f:
            ans = min(ans,stals[0])
            
    if  ans == float('inf'):
        print(-1)
    else:
        print(ans)
            
    return 
    
rap()

Fixed submission:
S = str(input())
T = str(input())

T = T[:(len(T)-1)]
if S == T:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
N,M,X = map(int, input().split())
grid = [[]]
for i in range(N):
    ls = list(map(int, input().split()))
    grid.append(ls)

def rec(r,progress,result):
    if r == N:
        progress = progress 
        result.append(progress)
        progress = progress + [grid[N]]
        result.append(progress)
        return
    else:
        rec(r+1,progress,result)
        progress = progress + [grid[r]]
        rec(r+1,progress,result)

def rap():
    result = []
    progress = []
    rec(0,progress,result)
    ans = float('inf')
    for item in result:
        stals = [0]*(M+1)
        for item2 in item:
            for i, j in enumerate(item2):
                stals[i] += j
        f = True
        for  m in stals[1:]:
            if m < X:
                f = False
        if f:
            ans = min(ans,stals[0])
            
    if  ans == float('inf'):
        print(-1)
    else:
        print(ans)
            
    return 
    
rap()

Fixed submission:
S = str(input())
T = str(input())

T = T[:(len(T)-1)]
if S == T:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
ls = list(map(int, input()))
anls = [0]*(N+1)
for i in ls:
    anls[i] += 1
for i in range(1,N+1):
    print(anls[i])


Fixed submission:
N = int(input())
ls = list(map(int, input().split()))
anls = [0]*(N+1)
for i in ls:
    anls[i] += 1
for i in range(1,N+1):
    print(anls[i])
Buggy python submission (verdict: Runtime Error):
n, m = input().split()
a = n*(n-1)/2 + m*(m-1)/2
print(a)

Fixed submission:
n, m = map(int, input().split())
a = n*(n-1)/2 + m*(m-1)/2
print(int(a))

Buggy python submission (verdict: Runtime Error):
def out(m, n):
  a = m*(m-1)%2 + n*(n-1)%2
  return a

m, n = list(input())
a = out(m,n)

print(a)

Fixed submission:
n, m = map(int, input().split())
a = n*(n-1)/2 + m*(m-1)/2
print(int(a))

Buggy python submission (verdict: Runtime Error):
def out(m, n):
  a = m*(m-1)%2 + n*(n-1)%2
  return a

m, n = int(input())
a = out(m,n)

print(a)

Fixed submission:
n, m = map(int, input().split())
a = n*(n-1)/2 + m*(m-1)/2
print(int(a))

Buggy python submission (verdict: Runtime Error):
def out(m, n):
  a = m*(m-1)%2 + n*(n-1)%2
  return a

m, n = int(input())
a = out(m,n)

print(a)

Fixed submission:
n, m = map(int, input().split())
a = n*(n-1)/2 + m*(m-1)/2
print(int(a))
Buggy python submission (verdict: Runtime Error):
D, G = map(int, input().split())
grid = [[0,0]]#インデックス合わせとく
for i in range(D):
    p,c = map(int, input().split())
    grid.append([p,c])

import itertools
kumi = list(itertools.product([0,1], repeat=D))
anls = []
fans = float('inf')
for item in kumi:
    count = 0
    ans = 0
    k = 0
    score = 0
    for i in item:
        count += 1
        if i == 1:
            score += grid[count][0]*100*count + grid[count][1]
            ans += grid[count][0]
        else:
            k = count

    if G <= score :
        fans = min(fans,ans)
    elif score+(k*100)*(grid[k][0]-1) >= G :
        a = int((G-score)/(k*100))
        if score+a*k*100=G:
            ans += a
        else:
            ans += (a+1)
        fans = min(fans,ans)
if fans != float('inf'):
    fans = int(fans)
print(fans)

Fixed submission:
D, G = map(int, input().split())
grid = [[0,0]]#インデックス合わせとく
for i in range(D):
    p,c = map(int, input().split())
    grid.append([p,c])

import itertools
kumi = list(itertools.product([0,1], repeat=D))
anls = []
fans = float('inf')
for item in kumi:
    count = 0
    ans = 0
    k = 0
    score = 0
    for i in item:
        count += 1
        if i == 1:
            score += grid[count][0]*100*count + grid[count][1]
            ans += grid[count][0]
        else:
            k = count

    if G <= score :
        fans = min(fans,ans)
    elif score+(k*100)*(grid[k][0]-1) >= G :
        a = int((G-score)/(k*100))
        if score+a*k*100==G:
            ans += a
        else:
            ans += (a+1)
        fans = min(fans,ans)
if fans != float('inf'):
    fans = int(fans)
print(fans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
field = []
countd = 0
for _ in range(H):
    ls = []
    st = str(input())
    for ss in st:
        ls.append(ss)
        if ss =='.':
            countd += 1
    field.append(ls)

from collections import deque

dis = [[float('inf')]*51 for i in range(51)]
que = deque([])
que.append([0,0,0])
dis[0][0] = 0
while len(que) > 0:
    pre = que.popleft()
    d = pre[0]
    x = pre[1]
    y = pre[2]
    for dx in [-1,1]:
        for dy in [-1,1]:
            if 0<=x+dx<=H-1:
                if field[x+dx][y]=='.':
                    dis[x+dx][y] = d+1
                    que.append([d+1,x+dx,y])
            if 0<=y+dy<=W-1:
                if field[x][y+dy]=='.':
                    dis[x][y+dy] = d+1
                    que.append([d+1,x,y+dy])

an = dis[H-1][W-1]
if an ==float('inf'):
    print(-1)
else:
    print(countd-an-1)


Fixed submission:
H,W = map(int, input().split())
field = []
countd = 0
for _ in range(H):
    ls = []
    st = str(input())
    for ss in st:
        ls.append(ss)
        if ss =='.':
            countd += 1
    field.append(ls)
import heapq

def caldis(field):#ある点を黒にして計算できる距離の中で際異端のものを求める
    used = [[False]*50 for i in range(50)]
    dis = [[float('inf')]*51 for i in range(51)]
    dis[0][0] = 0
    que = []
    heapq.heappush(que,[0,0,0])
    while len(que)>0:
        pre = heapq.heappop(que)
        d = pre[0]
        px = pre[1]
        py = pre[2]
        if used[px][py] ==True:
            continue
        used[px][py] = True
        dis[px][py] = d
        for dx in [-1,1]:
            for dy in [-1,1]:
                if 0<=px+dx<=H-1:
                    if field[px+dx][py]=='.':
                        heapq.heappush(que,[d+1,px+dx,py])
                if 0<=py+dy<=W-1:
                    if field[px][py+dy]=='.':
                        heapq.heappush(que,[d+1,px,py+dy])
    res = dis[H-1][W-1]
    return res
an = caldis(field)
if an==float('inf'):
    print(-1)
else:
    print(countd-an-1)