Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
sum = 1
for num in input().split():
    sum *= int(num)
    if sum == 0:
        print(0)
        exit()
if len(str(sum)) > 19:
    print(-1)
    exit()
elif len(str(sum)) == 19:
    if str(sum).count("1") == 1 and str(sum).count("0") == 18:
        pass
    else:
        print(-1)
        exit()
print(sum)


### FIXED CODE ###

N = int(input())
sum = 1
keta = 0

numbers = input().split()
if not ("0" in numbers):
    for num in numbers:
        keta += len(num) - 1
        if keta > 19:
            print(-1)
            exit()
        sum *= int(num)
        if len(str(sum)) > 19:
            print(-1)
            exit()
        
    if len(str(sum)) == 19:
        if str(sum).count("1") == 1 and str(sum).count("0") == 18:
            pass
        else:
            print(-1)
            exit()
else:
    print(0)
    exit()
print(sum)
### BUGGY CODE ###

def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1), reverse=True)
    
    schedule = [0] * M
    now = 0
    for a, b in AB:
        if a > M:
            continue

        tmp = M - a
        while tmp >= 0:
            if schedule[tmp] == 0:
                schedule[tmp] = b
                now += 1
                break
            tmp -= 1

        if now >= M:
            break

    print(sum(schedule))

main()

### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

    for _ in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(-b)

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)
    
    print(ans)

main()
### BUGGY CODE ###


def resolve():
    nnn = int(input())
    for h in range(1, 3501):
        for w in range(1, 3501):
            div = 4 * h * w - nnn * h - nnn * w
            if div == 0:
                continue
            n = nnn * h * w / div
            if int(n) == n and 0 < n:
                print(h, w, int(n))
                return

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

N = int(input())

for i in range(1,3500):
    for j in range(1,3500):
        if 4 * i * j - N * i - N * j == 0:
            continue
        k = N * i * j / (4 * i * j - N * i - N * j)
        if k > 0 and k == int(k):
            print(i, j, int(k))
            exit()
### BUGGY CODE ###

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [max(A[: n+1]) for n in range(N)]
C = [max(A[N - n - 1:]) for n in range(N)][::-1]

for n in range(N):
    if n == 0:
        print(C[n+1])
    elif n == N - 1:
        print(B[n-1])
    else:
        print(max(B[n-1], C[n+1]))


### FIXED CODE ###

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))
### BUGGY CODE ###

N , K = map(int, input().split())
A = sorted(map(int, input().split()))
syurui = set(A)
goukei = []
ans = 0
for i in syurui:
    goukei.append(A.count(i))

goukei.sort()

if len(syurui) <= K:
    print(ans)
else:
    for i in range(len(syurui)-K):
        ans += goukei[i]
    print(ans)

### FIXED CODE ###

import collections
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
hint = collections.Counter(A)
ans = 0
bb = hint.most_common()
if K >= len(bb):
    print(ans)
else:
    for i in range(-1, -(len(bb)-K)-1, -1):
        ans += bb[i][1]
    print(ans)
### BUGGY CODE ###

import os
import sys
from collections import defaultdict
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

import time

st = time.time()

N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

# グラフつくる
nodes = set()
sources = set()
graph = defaultdict(list)
ins = defaultdict(int)
for i in range(N):
    for j in range(N - 2):
        a, b = i, A[i][j] - 1
        a, b = min(a, b), max(a, b)
        c, d = i, A[i][j + 1] - 1
        c, d = min(c, d), max(c, d)

        graph[a * N + b].append(c * N + d)
        ins[c * N + d] += 1
        sources.add(a * N + b)

        nodes.add(a * N + b)
        nodes.add(c * N + d)

# トポロジカルソート
S = []
for v in sources:
    if ins[v] == 0:
        S.append(v)
L = []
while S:
    v = S.pop()
    L.append(v)
    for u in graph[v]:
        ins[u] -= 1
        if ins[u] == 0:
            S.append(u)

if len(L) != len(nodes):
    print(-1)
    exit()

seen = []


@lru_cache(maxsize=None)
def dfs(v):
    ret = 0
    for u in graph[v]:
        ret = max(ret, dfs(u))
    return ret + 1


ans = 0
for v in sources:
    ans = max(ans, dfs(v))
print(ans)


### FIXED CODE ###

import os
import sys
from collections import defaultdict, deque
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

graph = [[] for _ in range(N ** 2)]
ins = [0] * (N ** 2)
for i in range(N):
    for j in range(N - 2):
        a, b = i, A[i][j] - 1
        c, d = i, A[i][j + 1] - 1

        if a > b:
            a, b = b, a
        if c > d:
            c, d = d, c

        graph[a * N + b].append(c * N + d)
        ins[c * N + d] += 1

zeros = []
seen = []
for v, cnt in enumerate(ins):
    if cnt == 0:
        zeros.append(v)
        seen.append(v)

ans = 0
while zeros:
    nz = []
    for v in zeros:
        for u in graph[v]:
            ins[u] -= 1
            if ins[u] == 0:
                nz.append(u)
                seen.append(u)
    zeros = nz
    ans += 1
if len(seen) == len(graph):
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
log_l = [0]
i = 0
count = 0
flag = False
while i != 1: 
    i = a[i]-1
    count +=1
    if i in log_l: break
    else: log_l.append(i)
    if i == 1:
        flag = True
        break
if flag: print(count)
else: print(-1)

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
i = 0
j = 0
count = -1
while i < n:
    j = a[j]-1
    i += 1
    if j == 1:
        count = i
        break
print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from functools import lru_cache
sys.setrecursionlimit(10**8)

MOD = 998244353  # type: int


def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    # 和がSとなるように選択する
    # DP[i][wa] ... i文字目まで見て和がwaとなる個数
    DP = [[0]*(S+1) for i in range(N+1)]
    DP[0][0] = 1
    for i in range(1, N+1):
        DP[i][0] = 1
        for wa in range(S+1):
            DP[i][wa] = DP[i-1][wa]
            if 0 <= wa-A[i-1] <= S:
                DP[i][wa] += DP[i-1][wa-A[i-1]]
                DP[i][wa] %= MOD

    # print(*DP, sep="\n")

    # 組み合わせはDP[N][S]個存在する。
    # DPを逆に辿って集合を得る
    # 集合を含むような部分集合を数えあげる

    @lru_cache(maxsize=None)
    def reconstruct(n, wa):
        # nまで見て、和がwaとなるような集合のサイズのリストを返す
        # print("(n, wa)", n, wa)
        ans = []
        if wa < 0 or n < 0 or DP[n][wa] == 0:
            return ans
        if n-1 >= 0 and DP[n-1][wa] != 0:
            ans.extend(reconstruct(n-1, wa))
        if DP[n][wa] != DP[n-1][wa]:
            # 文字の追加がある
            if wa-A[n-1] == 0:
                ans.append(1)
            else:
                if n-1 >= 0 and DP[n-1][wa-A[n-1]] != 0:
                    b = reconstruct(n-1, wa-A[n-1])
                    ans.extend([bb+1 for bb in b])
        return ans

    ans = 0
    for s in reconstruct(N, S):
        ans += pow(2, N - s, MOD)
        ans %= MOD
    print(ans)

    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from functools import lru_cache
sys.setrecursionlimit(10**8)

MOD = 998244353  # type: int


def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    DP = [[0]*(S+1) for i in range(N+1)]
    DP[0][0] = 1
    for i in range(1, N+1):
        for wa in range(S+1):
            DP[i][wa] = 2*DP[i-1][wa]
            DP[i][wa] %= MOD
            if 0 <= wa-A[i-1] <= S:
                DP[i][wa] += DP[i-1][wa-A[i-1]]
                DP[i][wa] %= MOD

    print(DP[N][S])
    return


if __name__ == '__main__':
    main()
### BUGGY CODE ###

INF = 1000000000
def solve(s,g,E,n):
  D = [INF for i in range(n)]
  D[s] = 0
  U = [0 for i in range(n)]
  V = [s]
  while V:
    v = V.pop(0)
    U[v] = 1
    if v == g:
      break
    for e in E[v]:
      if U[e[0]] == 0 and D[v] + e[1] < D[e[0]]:
        D[e[0]] = D[v] + e[1]
        V.append(e[0])
    V = sorted(V,key=lambda x:D[x])
  if D[g] >= INF:
    print(-1)
  else:
    print(D[g])
  
  
while True:
  try:
    n,k = list(map(int,input().split()))
    if n == 0 and k == 0:
      break
    E = [[] for i in range(n)]
    for i in range(k):
      lst = list(map(int,input().split()))
      a = min(lst[1],lst[2])
      b = max(lst[1],lst[2])
      if lst[0] == 0:
        solve(a - 1, b - 1, E, n)
      elif lst[0] == 1:
        E[a - 1].append([b - 1, lst[3]])
        E[b - 1].append([a - 1, lst[3]])
  except EOFError:
    break


### FIXED CODE ###

from heapq import heappush,heappop

def dij(s,g,E):
  h = []
  U = []
  heappush(h,(0,s))
  while h:
    v = heappop(h)
    if v[1] == g:
      if v[0] >= INF:print(-1)
      else:print(v[0])
      break
    U.append(v[1])
    for e in E[v[1]]:
      if not e[0] in U:
        heappush(h,(v[0] + e[1],e[0]))
  else:print(-1)
INF = 100000000
while True:
  try:
    n,k = map(int,input().split())
    if n == 0 and k == 0: break
    E = [[] for i in range(n)]
    for _ in range(k):
      lst = list(map(int,input().split()))
      if lst[0] == 0:
        dij(lst[1] - 1, lst[2] - 1, E)
      else:
        E[lst[1] - 1].append([lst[2] - 1, lst[3]])
        E[lst[2] - 1].append([lst[1] - 1, lst[3]])

  except EOFError:
    break
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
ans=[]
for i in range(q):
	x,y=map(int,input().split())
	ans.append(s[x-1:y].count('AC'))
for i in ans:
	print(i)

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
	t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for i in range(q):
	l,r=map(int,input().split())
	print(t[r-1]-t[l-1])
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
     for j in range(i + 1,n-1):
          flag = True
          for k in range(j + 1,n):
               if l[i] + l[j] > l[k] and flag :
                    ans += 1
               else:
                    flag = False
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
     for j in range(i + 1,n-1):
          ans += bisect.bisect_left(l,l[i] + l[j]) - j - 1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [[] for _ in range(N)]
edges = dict()
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].append(b)
    adj[b].append(a)
    edges[(a, b)] = i
    colors[(a, b)] = 0
    ed.append([a, b])

col = max(len(v) for v in adj)
cand = set([v for v in range(1, col+1)])

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1, set()]]
while Q:
    cur, prev, NG = Q.pop()
    for nex in adj[cur]:
        if nex == prev:
            continue
        colors[(min(cur, nex), max(cur, nex))] = min(cand-NG)
        Q.append([nex, cur, {min(cand-NG)}])
        NG.add(min(cand-NG))
print(col)
for a, b in ed:
    print(colors[(a, b)])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [set() for _ in range(N)]
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    ed.append([a, b])

col = max(len(v) for v in adj)

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1, -1]]
while Q:
    cur, prev, NG = Q.pop()
    c = 0
    for nex in adj[cur]:
        if nex == prev:
            continue
        else:
            c += 1
        if c == NG:
            c += 1
        colors[min(cur, nex)*N + max(cur, nex)] = c
        Q.append([nex, cur, c])
print(col)
for a, b in ed:
    print(colors[a*N + b])
### BUGGY CODE ###

import collections as col

n = int(input())

a = list(map(int, input().split()))
cnt = 0
b = 0
c = [0]
for i in range(n):
    b += a[i]
    c.append(b)
    
d = col.Counter(c)
i=0
ncm=0

while i<len(d):
    m = d.most_common()[i][1]
    if m > 1:
        ncm += m*(m-1)//2
        i += 1
    else:
        break

print(ncm)

### FIXED CODE ###


n = int(input())

a = list(map(int, input().split()))
cnt = 0
b = 0
c = [0]
for i in range(n):
    b += a[i]
    c.append(b)

c.sort()
i=0
ncm=0
m = 1
while True:
    i += 1
    if i == n+1:
        ncm += m*(m-1)//2
        break        
    if c[i] == c[i-1]:
        m += 1
        continue
    else:
        ncm += m*(m-1)//2
        m = 1

print(ncm)
### BUGGY CODE ###

s = input()
k = int(input())
n = len(s)

ansset= set()

for i in range(1,n+1):
    for j in range(n-i+1):
        ansset.add(s[j:j+i])

anslist = sorted(list(ansset))

print(anslist[k-1])


### FIXED CODE ###

s = input()
k = int(input())
n = len(s)

ansset= set()
for i in range(1,k+1):
    for j in range(n-i+1):
        ansset.add(s[j:j+i])

anslist = sorted(list(ansset))

print(anslist[k-1])
### BUGGY CODE ###

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

cnt = [[num, a.count(num)] for num in set(a)]
k = len(cnt)

if k%2 ==0:
  print(k-1)
else:
  print(k)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a = set(a)

k = len(a)

if k%2 ==0:
  print(k-1)
else:
  print(k)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque
import numpy as np

def agc033_a():
    H, W = map(int, readline().split())
    grid = np.full((H+2, W+2), '#', dtype=object)
    for i, ln in enumerate(read().split()):
        grid[i+1, 1:W+1] = [str(x) for x in ln.strip().decode('UTF-8')]

    que = deque()
    dist = np.ones((H+2, W+2), dtype=int)
    dist *= -1

    for i in range(1, H+1):
        for j in range(1, W+1):
            if grid[i, j] == '#':
                que.append((i, j))
                dist[i, j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if grid[i, j] == '#': continue
            if dist[i, j] != -1: continue
            dist[i, j] = dist[x, y] + 1
            que.append((i, j))

    ans = dist.max()
    print(ans)

agc033_a()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

def agc033_a():
    H, W = map(int, readline().split())
    dist = [[-1] * W for _ in range(H)]
    que = deque()
    for i, ln in enumerate(read().split()):
        for j, c in enumerate(ln.strip().decode('UTF-8')):
            if c == '#':
                que.append((i, j))
                dist[i][j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if i < 0 or H-1 < i or j < 0 or W-1 < j: continue
            if dist[i][j] != -1: continue
            dist[i][j] = dist[x][y] + 1
            que.append((i, j))

    ans = 0
    for row in dist:
        ans = max(max(row), ans)
    print(ans)

agc033_a()
### BUGGY CODE ###

N,M = input().split()
N = int(N)
M = int(M)
price_list = input().split()
 
price_list = [int(i) for i in price_list]
 
for m in range(M):
  price_list.sort(reverse=True)
  price_list[0] = int(price_list[0] / 2)
print(sum(price_list))

### FIXED CODE ###

import heapq

N,M = input().split()
N = int(N)
M = int(M)
price_list = input().split()
 
heap_list = []
for i in price_list:
  heapq.heappush(heap_list, int(i) * (-1))

for _ in range(M):
  max_num = heapq.heappop(heap_list)
  heapq.heappush(heap_list, int(max_num /2))
  
print(sum(heap_list) * (-1))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))

import fractions

X = A[0]
for i in range(1, N):
    X = X*A[i] // fractions.gcd(X, A[i]) 

output = 0
D =10**9+7
for i in range(N):
    output += X*pow(A[i],D-2,D)%D
    output = output % (10**9+7)
print(int(output))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

import fractions

X = A[0]
for i in range(1, N):
    X = X*A[i] // fractions.gcd(X, A[i])

output = 0
D =10**9+7
X = X%D

for i in range(N):
    output += X*pow(A[i],D-2,D)%D
    output = output % (10**9+7)
print(int(output))
### BUGGY CODE ###

n=int(input())
cnt=1
a=list(map(int,input().split()))
for it in a:
  cnt*=it
if cnt>1000000000000000000:
  print(-1)
else:
  print(cnt)


### FIXED CODE ###

n=int(input())
cnt=1
a=sorted(list(map(int,input().split())))
for it in a:
  cnt*=it
  if cnt>1000000000000000000:
    print(-1)
    exit()
if cnt>1000000000000000000:
  print(-1)
else:
  print(cnt)
### BUGGY CODE ###

#!/usr/bin/env python
import collections
from operator import mul
from functools import reduce
N, M = map(int, input().split())

def cmb(n, r):
    r = min(r, n-r)
    if r==0: return 1
    over = reduce(mul, range(n, n-r, -1))
    under = reduce(mul, range(1, r+1))
    return over // under

ps = []
tmp = M
for m in range(2, M+1):
    while tmp % m == 0:
        tmp /= m
        ps.append(m)
    if int(tmp) == 1:
        break
ps = collections.Counter(ps)

ans = 1
mod = 10**9+7
for c in ps.values():
    ans *= cmb(c+N-1, c) % mod
    if ans > mod:
        ans %= mod

print(ans)


### FIXED CODE ###

#!/usr/bin/env python
import collections
from operator import mul
from functools import reduce
N, M = map(int, input().split())

def cmb(n, r):
    r = min(r, n-r)
    if r==0: return 1
    over = reduce(mul, range(n, n-r, -1))
    under = reduce(mul, range(1, r+1))
    return over // under

ps = []
tmp = M
for m in range(2, M+1):
    while tmp % m == 0:
        tmp /= m
        ps.append(m)
    if int(tmp) == 1:
        break
    if m*m > M:
        if N > 1:
            ps.append(M)
        break

ps = collections.Counter(ps)

ans = 1
mod = 10**9+7
for c in ps.values():
    ans *= cmb(c+N-1, c) % mod
    if ans > mod:
        ans %= mod

print(ans)
### BUGGY CODE ###


import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print(dp[-1][5] )



### FIXED CODE ###


import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        kurai %= 13

        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print(dp[-1][5] )
### BUGGY CODE ###

n = int(input())
alist = [int(input())-1 for _ in range(n)]

visitedlist = [0]
from_ = 0
for _ in range(n):
    to = alist[from_]
    if to in visitedlist:
        print(-1)
        break
    elif to == 1:
        print(len(visitedlist))
        break
    else:
        visitedlist.append(to)
        from_ = to

### FIXED CODE ###

n = int(input())
alist = [int(input())-1 for _ in range(n)]

now = 0
count = 0
while True:
    if now == 1:
        print(count)
        break
    elif count >= n:
        print(-1)
        break
    else:
        count += 1
        now = alist[now]
### BUGGY CODE ###

import math
r,g,b,n = map(int,input().split())

li = [r,g,b]
x = max([r,g,b])
li.remove(x)
y = max(li)
li.remove(y)
z = li[0]
ans = 0
for i in range(math.ceil(n/x)+1):
  for j in range(math.ceil((n-x*i)/y)+1):
    if (n - x*i - y*j)%z == 0 and n - x*i - y*j >= 0:
      ans += 1
print(ans)

### FIXED CODE ###

import math
r,g,b,n = map(int,input().split())
 
ans = 0
for i in range(math.ceil(n/r)+1):
  for j in range(math.ceil((n-r*i)/g)+1):
    if (n - r*i - g*j)%b == 0 and n - r*i - g*j >= 0:
      ans += 1
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# D

from collections import deque

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

data = [None] * H
for i in range(H):
    data[i] = input()
# print(data)

def judge(h, w, dist):
    if (h >=0) and (h < H) and (w >= 0) and (w < W):
        if data[h][w] == '.' and dist[h][w] == -1:
            return True
        else:
            return False
    return False


def bfs(h, w):
    dist = [[-1] * W for i in range(H)]
    q = deque()

    max_dist = 0
    dist[h][w] = 0
    q.append((h, w, 0))

    while len(q) > 0:
        h, w, val = q.popleft()
        dist[h][w] = val
        max_dist = max(max_dist, val)

        if judge(h+1, w, dist):
            q.append((h+1, w, val+1))
        if judge(h-1, w, dist):
            q.append((h-1, w, val+1))
        if judge(h, w+1, dist):
            q.append((h, w+1, val+1))
        if judge(h, w-1, dist):
            q.append((h, w-1, val+1))

    return max_dist


ans = 0
for h in range(H):
    for w in range(W):
        if data[h][w] == '.':
            res = bfs(h, w)
            # print(h, w, res)
            ans = max(ans, res)

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# D

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)
# BFSなのでdeque / queue使う・・・微妙に1つだけTLE残る

# 全ての地点から全ての地点への最短経路を求める

'''
3 5
...#.
.#.#.
.#...
'''

import sys
from collections import deque

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
# data = [ns() for _ in range(H)]

data = [list("#" * (W + 2))]
# 周りを'#'で埋めておく
for _ in range(H):
    data.append(["#"] + list(input()) + ["#"])
data += [list("#" * (W + 2))]


def bfs(h, w):
    dist = [[-1] * (W+2) for _ in range(H+2)]
    q = deque()

    max_dist = 0
    dist[h][w] = 0
    q.append((h, w, 0))

    # while len(q) > 0:
    while len(q) > 0:
        h, w, val = q.popleft()

        m = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        for dx, dy in m:
            h_new, w_new = h + dx, w + dy
            if data[h_new][w_new] == '.' and dist[h_new][w_new] == -1:
                q.append((h_new, w_new, val+1))
                dist[h_new][w_new] = val + 1
                max_dist = max(max_dist, val + 1)

    return max_dist


ans = 0
for h in range(H+2):
    for w in range(W+2):
        if data[h][w] == '.':
            res = bfs(h, w)
            if ans < res:
                ans = res

print(ans)