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

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [list(map(int, readline().split())) for _ in range(n)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] -= 1
    ls = [0] * n
    ql = collections.deque()
    for i in range(n):
        ql.append([0, i])

    for i in range(10 ** 10):
        fq = [True] * n
        while ql:
            d, ps = ql.popleft()
            if d == i:
                if ls[ps] < n - 1 and fq[ps]:
                    fq[ps] = False
                    nw = a[ps][ls[ps]]
                    rw = a[nw][ls[nw]]
                    if ps == rw and fq[nw]:
                        ls[ps] += 1
                        ql.append([d+1, ps])
                        ls[nw] += 1
                        ql.append([d+1, nw])
                        fq[nw] = False
            else:
                if d > i:
                    ql.appendleft([d, ps])
                    break
        if len(ql) == 0 or sum(ls) == n * (n - 1):
            print(i + 1 if sum(ls) == n * (n - 1) else -1)
            exit()


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ad = [0] * n
    dq = collections.deque([[0, i + 1] for i in range(n)])
    for i in range(10 ** 15):
        fd = {}
        while True:
            if len(dq) != 0:
                d, q = dq.popleft()
                q -= 1
                if d <= i:
                    if ad[q] < n - 1:
                        qq = a[q][ad[q]] - 1
                        tq = a[qq][ad[qq]] - 1
                        if q == tq and qq not in fd and tq not in fd:
                            ad[qq] += 1
                            ad[tq] += 1
                            if ad[qq] < n - 1:
                                dq.append([d + 1, qq + 1])
                            if ad[tq] < n - 1:
                                dq.append([d + 1, tq + 1])
                            fd[qq] = 0
                            fd[tq] = 0
                else:
                    dq.append([d, q + 1])
                    break
            else:
                break
        if len(dq) == 0:
            b = True
            for v in ad:
                if v != n - 1:
                    b = False
                    break
            if b:
                print(i + 1)
                exit()
            else:
                print(-1)
                exit()


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

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

history = []

index = 0
cnt = 0
loop_start_city_index = 0
while True:
    if cnt == k:
        print(index+1)
        exit()

    if index in history:    # すでに訪れた街にきた
        loop_start_city_index = index
        break
    history.append(index)
    index = a[index] - 1
    cnt += 1

from_start_to_loop_start = history.index(loop_start_city_index)
loop_length = len(history) - from_start_to_loop_start

print(history[from_start_to_loop_start + (k-from_start_to_loop_start)%loop_length] + 1)

### FIXED CODE ###

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

history = []
is_visited = [False] * n

index = 0
cnt = 0
loop_start_city_index = 0
for i in range(k+1):
    if i == k:
        print(index+1)
        exit()

    if is_visited[index]:    # すでに訪れた街にきた
        loop_start_city_index = index
        break
    
    is_visited[index] = True
    history.append(index)
    index = a[index] - 1
    cnt += 1

from_start_to_loop_start = history.index(loop_start_city_index)
loop_length = len(history) - from_start_to_loop_start

print(history[from_start_to_loop_start + (k-from_start_to_loop_start)%loop_length] + 1)
### BUGGY CODE ###

#Red Scarf
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
output = ''

def binary(A, p):
    if not np.all(A==0) :
        return binary( (A-A%2)/2 , p+1 ) + ((A%2).sum())%2 * 2**p
    return ((A%2).sum())%2 * 2**p

for i in range(N):
    ken = (np.delete(A,i))
    output += str(int(binary(ken,0)))
    if i != N-1:
        output += ' '

print(output)

### FIXED CODE ###

#Red Scarf
N = int(input())
A = list(map(int, input().split()))
output = list()

axor = A[0]
for i in range(1,N):
    axor ^= A[i]

for i in range(N):
    output.append(axor^A[i])
print(*output)
### BUGGY CODE ###

N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*(N)
dp[0] = 0

for i in range(1,N):
    for j in range(max(i-K,0),i):
        dp[i] = min(abs(h[i]-h[j])+dp[j],dp[i])

print(dp[N-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),i)])

print(dp[N-1])
### BUGGY CODE ###

from itertools import combinations


N, M = map(int,input().split())
ferris = [list(map(int, input().split())) for i in range(M)]

f = combinations(ferris, 2)
flag = 0
for f_ in f:
    if (f_[0][0]==1 and f_[1][1]==N and f_[0][1]==f_[1][0]) or (f_[1][0]==1 and f_[0][1]==N and f_[0][0]==f_[1][1]):
        print('POSSIBLE')
        flag = 1
        break

if flag==0:
    print('IMPOSSIBLE')


### FIXED CODE ###

N, M = map(int, input().split())
ferry = [list(map(int, input().split())) for i in range(M)]

from_1 = [0 for i in range(N)]
to_N = [0 for i in range(N)]

for f in ferry:
    if f[0]==1:
        from_1[f[1]-1] = 1
    if f[1]==N:
        to_N[f[0]-1] = 1


flag = 0

for k in range(N):
    if from_1[k]==1 and to_N[k]==1:
        print('POSSIBLE')
        flag = 1
        break

if flag==0:
    print('IMPOSSIBLE')
### BUGGY CODE ###

n,m = map(int,input().split())
k = m//n
while k > 0:
	if m%k == 0:
		print(k)	
		break
	k -= 1 


### FIXED CODE ###

n,m = map(int,input().split())
k = m//n
ans = 1
i = 1
while i**2 <= m:
	if m%i==0:
		j = m//i
		if j <= k:
			print(j);exit()
		if i <= k:
			ans = max(ans,i)
	i += 1
print(ans)
### BUGGY CODE ###

from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = [i for i, x in enumerate(x2) if x == "B"]

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

### FIXED CODE ###

from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)
### BUGGY CODE ###

import itertools

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

for pair in itertools.combinations(A, 2):
    ans += pair[0] * pair[1]

print(ans % 1000000007)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
SUM = sum(A) % MOD
ans = 0

for n in A:
    SUM -= n
    SUM %= MOD
    ans += SUM * n
    ans %= MOD

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

import sys
input=sys.stdin.readline
N,W=map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
dp=[[float('inf') for i in range(V+1)] for j in range(N+1)]

dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=dp[i][j-v[i]]+w[i]
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])

for j in range(V+1):
    if dp[N][j]<=W:
        res=j
print(res)

### FIXED CODE ###

N,W=map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
dp=[[float('inf') for i in range(V+1)] for j in range(N+1)]

dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=dp[i][j-v[i]]+w[i]
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])

for j in range(V+1):
    if dp[N][j]<=W:
        res=j
print(res)
### BUGGY CODE ###

import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = II()
S = input()

ans = 0
for i in range(1, N-2):
    for j in range(2, N):
        if j < i:
            continue
        for k in range(3, N+1):
            if k < j:
                continue
            if j-i != k-j and S[i-1] != S[j-1] and S[i-1] != S[k-1] and S[k-1] != S[j-1]:
                    ans+=1
print(ans)

### FIXED CODE ###

import sys
import math
from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1,N-1):
    k=2*j-i
    if k>=N:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      ans-=1
print(ans)
### BUGGY CODE ###

NUM_CITY = 6

def is_finish(state):
    return sum(state[:-1]) == 0

def solve():
    N = int(raw_input())
    A = int(raw_input())
    B = int(raw_input())
    C = int(raw_input())
    D = int(raw_input())
    E = int(raw_input())
    state = [0] * NUM_CITY
    state[0] = N
    cnt = 0
    while not is_finish(state):
        cnt += 1
        f1to2 = min(state[0], A)
        f2to3 = min(state[1], B)
        f3to4 = min(state[2], C)
        f4to5 = min(state[3], D)
        f5to6 = min(state[4], E)
        state[0] -= f1to2
        state[1] = state[1] + f1to2 - f2to3
        state[2] = state[2] + f2to3 - f3to4
        state[3] = state[3] + f3to4 - f4to5
        state[4] = state[4] + f4to5 - f5to6
        state[5] += f5to6
    print cnt

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def get_input():
    N = int(raw_input())
    A = int(raw_input())
    B = int(raw_input())
    C = int(raw_input())
    D = int(raw_input())
    E = int(raw_input())
    return N, A, B, C, D, E

def solve2():
    N, A, B, C, D, E = get_input()
    X = min(A, B, C, D, E)
    NdivX = (N  + X - 1) / X
    ret = 5 + NdivX - 1
    print ret

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

n = int(input())
s = input()

p = [0] * n
for i in range(n):
    p[i] = s[:i].count('W') + s[i:].count('E')
print(min(p))


### FIXED CODE ###

n = int(input())
s = input()

p = [0] * n
p[0] = s[1:].count('E')
for i in range(1, n):
    p[i] = p[i-1]
    if s[i-1] == 'W':
        p[i] += 1
    if s[i] == 'E':
        p[i] -= 1
print(min(p))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
Nc = 1
if A.count(0) >= 2:
    Nc *= 0
else:
    for i in range(N):
        if (N-A[i]) >= 1:
                if A.count(i+1) == 2:
                    Nc = Nc*2%1000000007
                elif A.count(i+1) == 0:
                    Nc *= 1
                else:
                    Nc *= 0
                    break
        else:
            Nc *= 0
            break

print(Nc)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Nc = 1
e = 0
B = [0]*N
for i in A:
    if (N-i-1) < 0:
        e = 1
        Nc = 0
        break
if e ==0:
    if A.count(0) >= 2:
        Nc *= 0
    else:
        if A.count(0) == 1:
            A.remove(0)
        for i in A:
            B[i] = B[i] + 1
        for i in B:
            if i == 2:
                Nc *= 2
            elif i == 0:
                Nc *= 1
            else:
                Nc *= 0
                break
print(Nc%1000000007)
### BUGGY CODE ###

def search(list, item):
  low = 0
  high = len(list) - 1
  while(low <= high):
    mid = (low + high) // 2
    guess = list[mid]
    if(guess == item):
      return mid
    if(guess > item):
      high = mid - 1
    else:
      low = mid + 1
  list.insert(low, item)
  return None

n = int(input())
item = []
for i in range(n):
  s = input()
  search(item, s)
print(len(item))
  



### FIXED CODE ###

n = int(input())
item = set()
for i in range(n):
  s = input()
  item.add(s)
print(len(item))
### BUGGY CODE ###

import itertools
N = list(map(int,input().split()))
# print(N)

ari = 0
kingaku = 0
ass = list(range(N[0]+1))
for i, j, k in itertools.product(ass,ass,ass):
    kingaku += 1000 * k + 5000 * j + 10000 * i
    if kingaku == N[1]:
        if (k + j + i) == N[0]:
            print(i,j,k)
            ari = 1
            break
                   
                
    kingaku = 0

if ari == 0:
    print(-1,-1,-1)

### FIXED CODE ###

N , Y= map(int,input().split())

for a in range(N + 1):
    be = N - a 
    for b in range(be + 1):
        c = N - b - a
        kingaku = 1000 * c + 5000 * b + 10000 * a

        if kingaku == Y:
            print(a,b,c)
          
            break
    else:
        continue
    break
                   

else:
    print(-1,-1,-1)
### BUGGY CODE ###

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

mul = 1
for i in range(k):
	mul *= a[i]
last = mul
for i in range(k, n):
	mul //= a[i-k]
	mul *= a[i]
	if mul > last:
		print("Yes")
	else:
		print("No")
	last = mul


### FIXED CODE ###

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

buff = []
mul = 1
# for i in range(k):
	# mul *= a[i]
# last = mul
for i in range(k, n):
	if a[i] > a[i-k]:
		buff.append("Yes")
	else:
		buff.append("No")
print('\n'.join(buff))
### BUGGY CODE ###

from collections import Counter

N=int(input())
A=sorted(list(map(int,input().split())))
nmax=10**6
iscop=[True]*(nmax+1)
cnt=[0]*(nmax+1)

for a in A:
    cnt[a]+=1
    if iscop[a]==False:
        continue

    for j in range(2,nmax//a+1):
        iscop[j*a]=False
ans=0
for a in A:
    if cnt[a]<2 and iscop[a]:
        ans+=1

print(ans)

### FIXED CODE ###

from collections import Counter

N=int(input())
A=Counter(list(map(int,input().split())))
nmax=10**6
iscop=[True]*(nmax+1)

for k in A.keys():
    if iscop[k]==False:
        continue

    for j in range(2,nmax//k+1):
        iscop[k*j]=False
ans=0
for k,v in A.items():
    if v<2 and iscop[k]:
        ans+=1

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

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
  if i!=0:
    ans=ans*i
  else:
    print(0)
    quit()
print(ans if ans<=10**18 else -1)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
count=a.count(0)
if count>0:
  print(0)
  quit()
else:
  for i in a:
    ans=ans*i
    if ans>10**18:
      print(-1)
      quit()
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right

N,Q=map(int, sys.stdin.readline().split())

S=[]
hq=[]	#x, xが答えになる開始時間, xが答えになる終了時間
for _ in range(N):
	s,t,x=map(int, sys.stdin.readline().split())
	heappush( hq, (x, max(0,s-x) , max(0,t-1-x)) )

D=[ int(sys.stdin.readline().strip()) for _ in range(Q) ]
D.sort()
ANS=[ float("inf") for _ in range(Q) ]

while hq:
	x,s,t=heappop(hq)

	start=bisect_left(D,s)
	end=bisect_right(D,t)

	for i in range(start,end):
		ANS[i]=min(ANS[i],x)


for x in ANS:
	if x==float("inf"):
		print -1
	else:
		print x



### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right

N,Q=map(int, sys.stdin.readline().split())

S=[]
event=[]	#x, s, t
for _ in range(N):
	s,t,x=map(int, sys.stdin.readline().split())
	heappush( event, (x, max(0,s-x) , max(0,t-1-x)) )


D=[ int(sys.stdin.readline().strip()) for _ in range(Q) ]
D.sort()
ans=[ float("inf") for _ in range(Q) ]

Next=[ i+1 for i in range(Q) ]	#Next


while event:
	x,s,t=heappop(event)
	start=bisect_left(D,s)
	end=bisect_right(D,t)

	i=start
	while i<end:
		ans[i]=min(ans[i],x)
		next=Next[i]
		Next[i]=end
		i=next

for x in ans:
	if x==float("inf"):
		print -1
	else:
		print x
### BUGGY CODE ###

import bisect

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

    ans = 0
    first = P[0]-1
    i = N
    while i != 0:
        ans += 1
        m = min(P[0:i])
        i = P.index(m)

    print(ans)

    return 0

if __name__ == '__main__':
    main()


### FIXED CODE ###

import bisect
import numpy as np

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


    ans = 1
    f = P[0]

    for i in range(1, N):
        f_o = P[i]
        if f >= f_o:
            ans+=1
            f = f_o
    print(ans)
    return 0


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

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

ans = 0
for i in range(n):
    if p_list[i] <= min(p_list[:i+1]):
        ans += 1
print(ans)


### FIXED CODE ###

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

ans = 0
now_min = p_list[0]
for i in range(n):
    if now_min > p_list[i]:
        now_min = p_list[i]
    if p_list[i] <= now_min:
        ans += 1
print(ans)
### BUGGY CODE ###

S=input()
N=len(S)
Sinfo=''
for i in range(0,N):
    if S[i]=='?':
        Sinfo+='0'
    else:
        Sinfo+=S[i]
first=int(Sinfo)%13
count=0
hatenadata=[]
for i in range(0,N):
    if S[i]=='?':
        count+=1
        hatenadata.append(i)

r=[[(i*10**(j-1))%13 for i in range(0,10)] for j in range(1,7)]

dp=[[0 for i in range(0,13)] for i in range(0,count+1)]

for i in range(0,13):
    if first==i:
        dp[0][i]=1

for i in range(1,count+1):
    digit=N-hatenadata[i-1]
    for j in range(0,13):
        dp[i][j]=sum(dp[i-1][(j-r[(digit-1)%6][k])%13] for k in range(0,10))%(10**9+7)


print(dp[count][5]%(10**9+7))


### FIXED CODE ###

S=input()
N=len(S)
count=0
hatenadata=[]
Sinfo=[]
for i in range(0,N):
    if S[i]=='?':
        Sinfo.append('0')
        count+=1
        hatenadata.append(i)
    else:
        Sinfo.append(S[i])
X=''.join(Sinfo)
first=int(X)%13

dp=[[0 for i in range(0,13)] for i in range(0,count+1)]

for i in range(0,13):
    if first==i:
        dp[0][i]=1

for i in range(1,count+1):
    digit=N-hatenadata[i-1]
    for j in range(0,13):
        dp[i][j]=sum(dp[i-1][(j-k*10**((digit-1)%6))%13] for k in range(0,10))%(10**9+7)

print(dp[count][5]%(10**9+7))
### BUGGY CODE ###

N , M = map(int,input().split())
list = []
for i in range (M):
    x ,y = map(int , input().split())
    if x == 1 or y == N:
        list.append([x,y])

ans = "IMPOSSIBLE"
for i in range(len(list)):
    if list[i][0] == 1:
        for j in range(len(list)):
            if list[i][1] == list[j][0]:
                if list[j][1] == N:
                    ans = "POSSIBLE"
print(ans)

### FIXED CODE ###

# coding: utf-8
from sys import stdin
input = stdin.readline

N , M = map(int,input().split())
start_input = set()
goal_input = set()

for _ in range(M):
    x , y = map(int,input().split())
    if x == 1:
        start_input.add(y)
    elif y == N:
        goal_input.add(x)
    
if start_input & goal_input:
    print("POSSIBLE")
else :
    print("IMPOSSIBLE")
### BUGGY CODE ###

h,w=map(int,input().split())
s=[input() for i in range(h)]
c=[[[0,0] for i in range(w)] for i in range(h)]
t=0
for H in range(h):
    for W in range(w):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                c[H][W-l][0]=t
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        c[H][-l][0]=t
    t=0    
for W in range(w):
    for H in range(h):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                c[H-l][W][1]=t
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        c[-l][W][1]=t
    t=0
ans=0
for i in c:
    for j in i:
        ans=max(sum(j),ans)
print(max(ans-1,0))

### FIXED CODE ###

h,w=map(int,input().split())
s=[input() for i in range(h)]
c=[[0 for i in range(w)] for i in range(h)]
t=0
for H in range(h):
    for W in range(w):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                c[H][W-l]=t
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        c[H][-l]=t
    t=0
ans=0
for W in range(w):
    for H in range(h):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                ans=max(c[H-l][W]+t,ans)
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        ans=max(c[-l][W]+t,ans)
    t=0
print(max(ans-1,0))
### BUGGY CODE ###

r, g, b, n = map(int, input().split())
ans = 0

for i in range(3001):
  for j in range(3001):
    v = i*r + j*g
    if (n >= v and (n - v) % b == 0):
      ans+=1
print(ans)

### FIXED CODE ###

r, g, b, n = map(int, input().split())
ans = 0

for i in range(3001):
  for j in range(3001):
    v = i*r + j*g
    if (n >= v and (n - v) % b == 0):
      ans+=1
print(ans)
### BUGGY CODE ###

from functools import lru_cache
import sys

S = input().strip()

MOD = 10 ** 9 + 7

lens = len(S)

sys.setrecursionlimit(10 ** 8)


@lru_cache(maxsize=None)
def solve(amari, keta):
    if keta == lens - 1:
        if S[keta] == "?":
            cnt = 0
            for i in range(9, -1, -1):
                if (amari + i) % 13 == 5:
                    cnt += 1
            return cnt
        else:
            if (amari + int(S[keta])) % 13 == 5:
                return 1
            else:
                return 0
    else:
        if S[keta] == "?":
            x = 0
            for i in range(9, -1, -1):
                x += solve((amari + (i * pow(10, (lens - 1 - keta), 13))) % 13, keta + 1)
                x %= MOD
            return x
        else:
            return solve((amari + (int(S[keta]) * pow(10, (lens - 1 - keta), 13))) % 13, keta + 1) % MOD


print(solve(0, 0) % MOD)


### FIXED CODE ###


S = input()

MOD = 10 ** 9 + 7
count = 0
S_len = len(S)

dp = [[0 for i in range(13)] for j in range(100006)]
c = -1
if S[0] != '?':
    c = int(S[0])
for j in range(10):
    if c == -1:
        dp[1][j] = 1
    else:
        dp[1][c] = 1

for i in range(2, S_len + 1):
    c = -1
    if S[i - 1] != '?':
        c = ord(S[i - 1]) - ord('0')

    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[i][(k * 10 + j) % 13] += dp[i - 1][k] % MOD


print(dp[S_len][5] % MOD)
### BUGGY CODE ###

n = int(input())
ss = [input() for _ in range(n)]
sorted_ss = [''.join(sorted(s)) for s in ss]
sorted_set = set([s for s in sorted_ss])

cnt = 0
for s in sorted_set:
	c = sorted_ss.count(s)
	cnt += c * (c - 1) // 2

print(cnt)

### FIXED CODE ###

from collections import Counter

n = int(input())
ss = [input() for _ in range(n)]

sorted_ss = [''.join(sorted(s)) for s in ss]
sorted_counter = Counter(sorted_ss)

cnt = sum([n * (n - 1) // 2 for n in sorted_counter.values()])
print(cnt)