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

H, W = map(int, input().split())
S = [input() for _ in range(H)]

# そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			if j == 0:
				L[i][j] = 1
			else:
				L[i][j] = L[i][j - 1] + 1

for i in range(H):
	for j in range(W - 1, -1, -1):
		if S[i][j] == ".":
			if j == W - 1:
				R[i][j] = 1
			else:
				R[i][j] = R[i][j + 1] + 1

for j in range(W):
	for i in range(H - 1, -1, -1):
		if S[i][j] == ".":
			if i == H - 1:
				D[i][j] = 1
			else:
				D[i][j] = D[i + 1][j] + 1

for j in range(W):
	for i in range(H):
		if S[i][j] == ".":
			if i == 0:
				U[i][j] = 1
			else:
				U[i][j] = U[i - 1][j] + 1


ans = 0
X = [[0] * W for _ in range(H)]
for i in range(H):
	for j in range(W):
		X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
	ans = max(ans, max(X[i]))

print(ans)


### FIXED CODE ###

def calculate(h, w, arr):
    L = [[0]*w for i in range(h)]
    U = [[0]*w for i in range(h)]
    D = [[0]*w for i in range(h)]
    R = [[0]*w for i in range(h)]

    for ih in range(h):
        for iw in range(w):
            if ih == 0:
                U[ih][iw] = 1
            if iw == 0:
                L[ih][iw] = 1

            if arr[ih][iw] == 1:
                L[ih][iw] = 0
                U[ih][iw] = 0

            else:
                if iw > 0:
                    L[ih][iw] = L[ih][iw - 1] + 1
                if ih > 0:
                    U[ih][iw] = U[ih - 1][iw] + 1

            rih = h - 1 - ih
            riw = w - 1 - iw

            if rih == h - 1:
                D[rih][riw] = 1
            if riw == w - 1:
                R[rih][riw] = 1

            if arr[rih][riw] == 1:
                D[rih][riw] = 0
                R[rih][riw] = 0
            else:
                if riw < w - 1:
                    R[rih][riw] = R[rih][riw + 1] + 1
                if rih < h - 1:
                    D[rih][riw] = D[rih + 1][riw] + 1

    max = 0
    for ih in range(h):
        for iw in range(w):
            value = L[ih][iw] + R[ih][iw] + U[ih][iw] + D[ih][iw] - 3
            if value > max:
                max = value
    print(int(max))


S = input().split(" ")
H = int(S[0])
W = int(S[1])

arr = []
for i in range(H):
    q = input()
    tmp = []
    for qs in q:
        if qs == "#":
            tmp.append(1)
        if qs == ".":
            tmp.append(0)
    arr.append(tmp)

calculate(H, W, arr)
### BUGGY CODE ###

N,X,Y = map(int,input().split())
D = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i,N):
        D[i][j] = j-i
D[X-1][Y-1] = 1
for i in range(N):
    for j in range(i,N):
        c,d = max(i,X-1),min(i,X-1)
        e,f = max(Y-1,j),min(j,Y-1)
        a = min(D[i][j],D[d][c]+D[f][e]+1)
        D[i][j] = a
A = [0]*(N-1)
for i in range(N):
    for j in range(i,N):
        k = D[i][j]
        if k == 0:
            continue
        A[k-1] += 1
for a in A:
    print(a)

### FIXED CODE ###

N,X,Y = map(int,input().split())
D = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1,N):
        D[i][j] = j-i
D[X-1][Y-1] = 1
A = [0]*(N-1)
for i in range(N):
    for j in range(i+1,N):
        c,d = max(i,X-1),min(i,X-1)
        e,f = max(Y-1,j),min(j,Y-1)
        a = min(D[i][j-1]+1,D[d][c]+D[f][e]+1)
        D[i][j] = a
        if a == 0:
            continue
        A[a-1] += 1
for a in A:
    print(a)
### BUGGY CODE ###

N=input()
A=[ input() for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)





### FIXED CODE ###

import sys


N=input()
A=[  int(sys.stdin.readline()) for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

C = [[A[0]]]
head = [A[0]]
for i in range(N-1):
    nex = A[i+1]
    for j in range(len(head)):
        if nex > head[j]:
            # C[j].append(A[i+1])
            head[j] = nex
            break
    else:        
        C.append([nex])  # new color
        head.append(nex)

print(len(C))


### FIXED CODE ###

import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

def LIS(A):
    """
    returns Longest Increasing Subsequence of list A.
    """
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_left(B, A[i+1])
            B[index] = A[i+1]
    return B

def LDS(A):
    """
    returns Longest Decreasing Subsequence of list A.
    """
    A = A[::-1]
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_right(B, A[i+1])
            B[index] = A[i+1]
    return B[::-1]


print(len(LDS(A)))
### BUGGY CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

N, M = map(int, rl().split())
li = [[] for _ in range(N)]
deg = [0] * N
for _ in range(M):
    a, b = map(int, rl().split())
    a -= 1
    b -= 1
    li[a].append(b)
    deg[b] = 1
deg = [i for i in range(N) if deg[i] == 0]
dp = [0] * N
for i in deg:
    for j in li[i]:
        if dp[j] < dp[i] + 1:
            dp[j] = dp[i] + 1
        deg.append(j)
print(max(dp))





        




### FIXED CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

def a():
    N, M = map(int, rl().split())
    li = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M):
        a, b = map(int, rl().split())
        a -= 1
        b -= 1
        li[a].append(b)
        deg[b] += 1
    d = collections.deque([i for i in range(N) if deg[i] == 0])
    dp = [0] * N
    while d:
        i = d.popleft()
        for j in li[i]:
            deg[j] -= 1
            if deg[j] == 0:
                dp[j] = max(dp[j] ,dp[i] + 1)
                d.append(j)
    print(max(dp))
a()
### BUGGY CODE ###

from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if bit[0] < bit[1] and s[bit[0]:bit[1]] not in anss:
        anss.append(s[bit[0]:bit[1]])

anss.sort()
print(anss[k-1])


### FIXED CODE ###

from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if k >= bit[1] - bit[0] > 0:
        if bit[0] < bit[1] and s[bit[0]:bit[1]] not in anss:
            anss.append(s[bit[0]:bit[1]])

anss.sort()
print(anss[k-1])
### BUGGY CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])
AB.sort()

DP = [float('inf') for i in range(2*10**4 + 1)]
DP[0] = 0
for i in range(H):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))


### FIXED CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])
AB.sort()

DP = [float('inf') for i in range(2*10**4 + 1)]
DP[0] = 0
for i in range(H):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))
### BUGGY CODE ###

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

for i in range(n):
    for j in range(i+1,n):
        if a[i] == a[j]:
            print('NO')
            exit()
print('YES')

### FIXED CODE ###

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

a.sort()

for i in range(n-1):
    if a[i] == a[i+1]:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N = I()
    S = SI()
    Q = I()
    K = LI()
    ans = []
    for k in K:
        D = 0; M = 0; C = 0
        now = 0
        for i in range(N):
            s = S[i]
            if s == "D":
                D += 1
            elif s == "M":
                M += 1
                now += D
            elif s == "C":
                C += now
            if i>=k-1:
                if S[i-k+1] == "D":
                    D -= 1
                    now -= M
                elif S[i-k+1] == "M":
                    M -= 1
#        print(D, M, C)
#        ans.append(C)
        print(C)
#    for v in ans:
#        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

### FIXED CODE ###

def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N = I()
    S = SI()
    Q = I()
    K = LI()
    ans = []
    for k in K:
        D = 0; M = 0; C = 0
        now = 0
        for i in range(N):
            s = S[i]
            if s == "D":
                D += 1
            elif s == "M":
                M += 1
                now += D
            elif s == "C":
                C += now
            if i>=k-1:
                if S[i-k+1] == "D":
                    D -= 1
                    now -= M
                elif S[i-k+1] == "M":
                    M -= 1
#        print(D, M, C)
#        ans.append(C)
        print(C)
#    for v in ans:
#        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""
### BUGGY CODE ###

# coding: utf-8

n, q = map(int, input().split())
s = input()

for i in range(q):
    f,e = (map(int, input().split()))
    st = s[f-1:e]
    # print(st.count('AC'))
    count = 0
    for j in range(len(st)-1):
        if st[j] == 'A' and st[j+1] == 'C':
            count += 1
    print(count)


### FIXED CODE ###

# coding: utf-8

n, q = map(int, input().split())
s = input()

t = [0]*(n+1)
for i in range(n):
    if s[i:i+2] == 'AC':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for i in range(q):
    l,r = (map(int, input().split()))
    ans = t[r-1] - t[l-1]
    print(ans)
### BUGGY CODE ###

import bisect

num = int(input())
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])


res = 0
for i in top:
    index = bisect.bisect_right(middle, i)
    if index != len(middle):
        for j in middle[index:]:
            index2 = bisect.bisect_right(bottom, j)
            if index2 != len(bottom):
                res += len(bottom) - index2
print(res)

### FIXED CODE ###

import bisect

num = int(input())
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])


# middleの配列でループを回したほうが早い(topとbottomを同時に処理できるため)
res = 0
for i in middle:
    index = bisect.bisect_left(top, i)
    index2 = len(bottom)-bisect.bisect_right(bottom, i)
    res += index*index2

print(res)
### BUGGY CODE ###

# C - pushpush
N = int(input())
a = list(map(int,input().split()))

S = sum(a)
lst = [0]*N
x = 0
y = 0

for i in range(N):
    x = sum(a[0:i])
    y = S - x
    lst[i] = abs(x-y)
lst.pop(0)

ans = min(lst)
print(ans)


### FIXED CODE ###

# C - Splitting Pile
N = int(input())
a = list(map(int,input().split()))

lst = [0]*(N-1)
x = [a[0]]*(N-1)
y = [sum(a)-a[0]]*(N-1)
lst[0] = abs(x[0]-y[0])

for i in range(1,N-1):
    x[i] = x[i-1]+a[i] 
    y[i] = y[i-1]-a[i]
    lst[i] = abs(x[i]-y[i])
"""
print(x)
print(y)
print(lst)
"""
ans = min(lst)
print(ans)
### BUGGY CODE ###

N = int(input())
S = input().rstrip('#').lstrip('.')
intS = []
def xor(A,B):
    #print(A)
    #print(B)
    num = 0
    for a,b in zip(A,B):
        if a^b :
            num = num + 1
    return num
for s in S :
    intS.append(0 if s=='.' else 1)
minC = N

mask = [1 for j in range(len(intS) + 2)]
for i in range(len(intS) + 2):
    mask[i] = 0
    c = xor(mask[1::],intS)
    if c < minC:
        minC = c

print(minC)
# def dl(_S):
    

#     l = '.'
#     r = '#'
    
#     _S = _S.lstrip(l).rstrip(r)
#     print(_S)
#     if len(_S) == 0:
#         return 0
#     _S2W = _S.lstrip(r)
#     _S2B = _S.rstrip(l)
#     _S2 =  _S2W if len(_S2W) <= len(_S2B) else _S2B
#     return len(_S) - len(_S2) + dl(_S2)
# print(dl(S))






### FIXED CODE ###

_ = input()
S = input()
numc = S.count('.')
numcmin = numc
for s in S:
    if s == '#':
        numc = numc + 1
    else:
        numc = numc -1
        if numc < numcmin:
            numcmin = numc
print(numcmin)
### BUGGY CODE ###

max = 10**18

n = int(input())
A = list(map(int,input().split()))
ans = 1
for i in A:
    ans *= i

if ans > max:
    print('-1')
else:
    print(ans)


### FIXED CODE ###

MAX = pow(10,18)
def main():
    N = int(input())
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

    ans = 1
    for a in A:
        ans *= a
        if ans > MAX:
            print(-1)
            return

    print(ans)

main()
### BUGGY CODE ###

n = int(input())
a = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(1,n+1):
  l,r = i,i
  while a[l-1] > a[i]:
    l -= 1
  while a[r+1] > a[i]:
    r += 1
  ans += a[i]*(i-l+1)*(r-i+1)
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)
### BUGGY CODE ###

#from collections import defaultdict
n,W=list(map(int,input().split()))
li=[]
wr=[0]*n
vr=[0]*n
#dd=defaultdict(lambda:0)
for i in range(n):
	w,v=map(int,input().split())
	wr[i]=w
	vr[i]=v
def maxv(i,w):
	#if dd[(i,w)]!=0:
#		return dd[(i,w)]
	if i==n:
		return 0
	if w+wr[i]>W:
		m=maxv(i+1,w)
		#dd[(i,w)]=m
		return m
	a=vr[i]+maxv(i+1,w+wr[i])
	b=maxv(i+1,w)
	c=max(a,b)
	return c
print(maxv(0,0))



### FIXED CODE ###

n,W=map(int,input().split())
dp=[0]*(W+1)
dd=dp.copy()
for i in range(n):
	w,v=map(int,input().split())
	for j in range(W):
		cw=j+w
		cv=dp[j]+v
		if cw <=W and dd[cw]<cv:
			dd[cw]=cv
	dp=dd.copy()
print(dp[W])
### BUGGY CODE ###

N,P = map(int,input().split())
ans=1
if N==1:
  print(P)
  exit()
elif P==1|N>=40:
  print(1)
  exit()
else:
  i=1
  while i<=P**(1/N):
    count = 0
    while P%i==0:
      P=P//i
      count+=1
    cn=count//N
    ans*=i**cn
    if i==2:
      i+=1
    else:
      i+=2
print(int(ans))
exit()

### FIXED CODE ###

N,P = map(int,input().split())
i = round(P**(1/N))
res = []
if N == 1:
  print(P)
elif P == 1:
  print(1)
else:
  for i in range(i,0,-1):
    if P%i**N==0:
      print(i)
      break
### BUGGY CODE ###

def main():
  d = {}
  input()
  l = list(map(int, input().split()))
  for i in range(len(l)):
    d[l[i]] = i+1
  result = ""
  for i in range(len(l)):
    result = result + str(d[i+1]) + " "
  print(result.rstrip())

main()

### FIXED CODE ###

def main():
  d = {}
  input()
  l = list(map(int, input().split()))
  result_list = [0] * len(l)
  for i in range(len(l)):
    result_list[l[i] - 1] = i+1
  print(' '.join(map(str,result_list)))

main()
### BUGGY CODE ###

import math
import copy
import numpy as np

n = int(input())
a = [int(i) for i in input().split()] 

num_list = []

i = n
while i > math.ceil(n/2):
  if a[i-1] == 1:
    num_list.append(i)
  i -= 1

i = math.ceil(n/2)
while i > 0:
  count = 0
  if a[i-1] == 1:
    for x in num_list:
      if x % i == 0:
        count += 1

    if count % 2 == 0:
      num_list.append(i)
  else:
    for x in num_list:
      if x % i == 0:
        count += 1

    if count % 2 == 1:
      num_list.append(i)
  i -= 1

l = (len(num_list))

if l == 0:
  print(0)
else:
  print(l)
  print(' '.join([str(n) for n in num_list]))

### FIXED CODE ###

import math
import copy
import numpy as np

n = int(input())
a = [int(i) for i in input().split()] 
x = a
num_list = []

i = n
while i > math.ceil(n/2):
  if a[i-1] == 1:
    num_list.append(i)
  i -= 1

i = math.ceil(n/2)
while i > 0:
  count = 0
  tmp = [x[i] for i in range(2*i-1, n, i)]
  s = sum(tmp)%2
  if a[i-1] == s:
    x[i-1] = 0
  else:
    x[i-1] = 1
    num_list.append(i)
  i -= 1

l = (len(num_list))

if l == 0:
  print(0)
else:
  print(l)
  print(' '.join([str(n) for n in num_list]))
### BUGGY CODE ###

import numpy as np
from numba import njit
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)


@njit
def solve(N, K, A):
    # 一度照らされると二度目以降は確実に照らされるはず。
    for i in range(K):
        # j番目の電球を操作
        B = np.array([0] * N, dtype=np.int64)
        if list(set(A)) == [N]:
            break
        for j in range(N):
            if A[j] == N:
                B[j] = N
                continue
            maxA = j + A[j]
            minA = j - A[j]

            for k in range(max(0, minA), min(N, maxA + 1)):
                B[k] += 1
        A = B.copy()
    return A


A = solve(N, K, A)
for i in range(N):
    if i != (N - 1):
        print(A[i], end=" ")
    else:
        print(A[i])


### FIXED CODE ###

import numpy as np
from numba import njit
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)


@njit
def solve(N, K, A):
    # 一度照らされると二度目以降は確実に照らされるはず。
    for i in range(K):
        # j番目の電球を操作
        B = np.zeros(N + 1, dtype=np.int64)
        for j in range(N):
            # 左辺を確認
            B[max(j - A[j], 0)] += 1
            # 右辺を確認(なんで-1?)
            B[min(j + A[j] + 1, N)] -= 1

        A = np.cumsum(B)[:-1]

        if np.all(A == N):
            return A

    else:
        return A


A = solve(N, K, A)
for i in range(N):
    if i != (N - 1):
        print(A[i], end=" ")
    else:
        print(A[i])
### BUGGY CODE ###

import numpy as np
n,k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
 
cycles, check = [], [False]*n
for pi in p:
  if not check[pi-1]:
    curr, cycle = pi, []
    check[pi-1] = True
    while pi!=p[curr-1]:
      check[curr-1] = True
      cycle.append(c[curr-1])
      curr = p[curr-1]
  check[curr-1] = True
  cycles.append(cycle + [c[curr-1]])

scores = []
for cycle in (np.array(cycle) for cycle in cycles):
  for i in range(cycle.size):
    cum = np.roll(cycle, i).cumsum()
    if cum[-1] > 0 and k > cycle.size:
      scores.append(cum[-1]*(k//cycle.size-1) + np.concatenate([cum, cum[:k % cycle.size]+cum[-1]]).max())
    else:
      scores.append(cum[:min(k, cum.size)].max())

print(max(scores))

### FIXED CODE ###

import numpy as np
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
 
cycles, check = [], [False]*n
for pi in p:
    if not check[pi-1]:
        curr, cycle = pi, []
        check[pi-1] = True
        while pi != p[curr-1]:
            check[curr-1] = True
            cycle.append(c[curr-1])
            curr = p[curr-1]
        check[curr-1] = True
        cycles.append(cycle + [c[curr-1]])

scores = []
for cycle in (np.array(cycle) for cycle in cycles):
    for i in range(cycle.size):
        cum = np.roll(cycle, i).cumsum()
        if cum[-1] > 0 and k > cycle.size:
            scores.append(cum[-1]*(k//cycle.size-1) + np.concatenate([cum, cum[:k % cycle.size]+cum[-1]]).max())
        else:
            scores.append(cum[:min(k, cum.size)].max())

print(max(scores))
### BUGGY CODE ###

import numpy as np
X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))
A.sort()
B.sort()
C.sort()

AB = [ a+b for a in A for b in B] 
ABC = [ab+c for ab in AB for c in C]
ABC.sort()
ABC = ABC[::-1]
for i in range(K):
  print(ABC[i])

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

AB = [ a+b for a in A for b in B]
AB = sorted(AB, reverse=True)
AB = AB[:3000]
ABC = [ab+c for ab in AB for c in C]
ABCs = sorted(ABC, reverse=True)[:K]
for i in range(K):
  print(ABCs[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from itertools import combinations

N = int(input().rstrip())
s = [int(input().rstrip()) for _ in range(N)]
s.sort(reverse=1)

for i in range(N, 0, -1):
    for c in combinations(s, i):
        if sum(c) % 10 == 0:
            continue
        else:
            print(sum(c))
            exit()
else:
    print(0)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from itertools import combinations

N = int(input().rstrip())
score = [int(input().rstrip()) for _ in range(N)]
score.sort(reverse=1)

s_multiple_of_10 = [s for s in score if s % 10 == 0]
if len(s_multiple_of_10) == N: print(0)
s_not_multiple_of_10 = [s for s in score if s % 10 != 0]

# combinationsでも、先に１０の倍数を除外してから処理したらどうだろう
for i in range(len(s_not_multiple_of_10), 0, -1):
    for c in combinations(s_not_multiple_of_10, i):
        if sum(c) % 10 == 0:
            continue
        else:
            print(sum(c) + sum(s_multiple_of_10))
            exit()