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

import numpy as np
N,K = map(int, input().split())
L = list()
R = list()
for _ in range(K):
    a,b = map(int, input().split())
    for _1 in range(_):
        x,y = L[_1],R[_1]
        if x <= a <= y or x <= b <= y :
            L[_1] = min(a,x)
            R[_1] = max(b,y)
            break
    else:
        L.append(a)
        R.append(b)
sep = len(L)


MOD = 998244353
dp = np.zeros(N+10,dtype=np.int64)
dp[1] = 1
for i in range(1,N+1):
    for l, r in zip(L,R):
        dp[min(N + 1, i + l):min(N + 1, i + r + 1)] += dp[i]
        # print(dp)

print(dp[N]%MOD)




### FIXED CODE ###

N,K = map(int, input().split())
L,R = [0]*K, [0]*K

count = 0
for _ in range(K):
    a,b = map(int, input().split())
    for _1 in range(_):
        x,y = L[_1],R[_1]
        if x <= a <= y or x <= b <= y :
            L[_1] = min(a,x)
            R[_1] = max(b,y)
            break
    else:
        L[_],R[_] =a,b
        count += 1
L,R = L[0:count+1],R[0:count+1]

MOD = 998244353
dp = [0]*(4*10**5+100)
for l, r in zip(L, R):
    dp[min(N + 1, 1 + l)] += 1
    dp[min(N + 1, 1 + r + 1)] -= 1

for i in range(2,N+1):
    number = dp[i-1] + dp[i]
    if number > MOD:
        number -= MOD
    dp[i] = number
    for l, r in zip(L,R):
        dp[i + l] += number
        dp[i + l] %= MOD
        dp[i + r +1] -= number
        dp[i + r +1] %= MOD

print(dp[N]%MOD)
### BUGGY CODE ###

# import sys
# input = sys.stdin.readline
# import re
import itertools

def main():
    n, k = input_list()
    p = input_list()

    pp = []
    for v in itertools.combinations(p, k):
        pp.append(sum(v))
    print(min(pp))

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


### FIXED CODE ###

# import sys
# input = sys.stdin.readline
# import re
import itertools

def main():
    n, k = input_list()
    p = input_list()

    p.sort()
    print(sum(p[:k]))

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

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

def main():
	H, W = map(int, input().split())
	S = [""]*H
	visit = [[False for _ in range(W)] for _ in range(H) ]
	for i in range(H):
		S[i] = input()

	stack = []
	for i in range(H):
		for j in range(W):
			if visit[i][j]:
				continue
			stack.append([i, j])
			while stack:
				current = stack.pop()
				if S[current[0]][current[1]] == ".":
					continue

				if current[1] < W-1 and S[current[0]][current[1]+1] == "#":
					stack.append([current[0], current[1]+1])
					visit[current[0]][current[1]+1] = True
					visit[current[0]][current[1]] = True
				if current[0] < H-1 and S[current[0]+1][current[1]] == "#":
					stack.append([current[0]+1, current[1]])
					visit[current[0]+1][current[1]] = True
					visit[current[0]][current[1]] = True

	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				if not visit[i][j]:
					print("No")
					return


	print("Yes")



if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()

	for i in range(H):
		for j in range(W):
			if S[i][j] == ".":
				continue
			if (
				(i > 0 and S[i-1][j] == "#")
				or (j > 0 and S[i][j-1] == "#")
				or (i < H-1 and S[i+1][j] == "#")
				or (j < W-1 and S[i][j+1] == "#")
				):
				continue
			print("No")
			return

	print("Yes")


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

n=int(input())
L=list(map(int, input().split()))
s=max(L)
from operator import mul
from functools import reduce

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

c=0
for i in range(n):	
	d=cmb(s,L[i])
	if d>=c and L[i]!=s:
		c=d
		a=L[i]
A=[s, a]
print(*A)


### FIXED CODE ###

n=int(input())
L=list(map(int, input().split()))
a=max(L)
b=a
c=0
for i in range(n):
	if b>=abs(L[i]-a/2) and L[i]!=a:
		b=abs(L[i]-a/2)
		c=L[i]


print(a,c)
### BUGGY CODE ###

N = int(input())
conv = [0]*(N+1)
for i in range(1,N+1):
    for j in range(1,N//i+1):##その数の倍数をメモ
        conv[i*j-1] += 1
   
##print(conv)
print(sum([(i+1)*conv[i] for i in range(N)]))

### FIXED CODE ###

N = int(input())
conv = [0]*(N+1)
for i in range(1,N+1):
    for j in range(1,N//i+1):##その数の倍数をメモ
        conv[i*j-1] += 1
   
##print(conv)
print(sum([(i+1)*conv[i] for i in range(N)]))
### BUGGY CODE ###

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

for i in range(1,n):
	if p[i] <= min(p[:i]):
		a+=1
	else:
		pass
print(a+1)

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))
a=0
b=10**10
for i in range(n):
	if p[i] <= b:
		a+=1
		b=p[i]
	else:
		pass
print(a)
### BUGGY CODE ###

N=int(input())

E=[[] for i in range(N+1)]

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

mod=10**9+7

from collections import deque
Q=deque()

USE=[0]*(N+1)
Q.append(1)
H=[0]*(N+1)
H[1]=1
USE[1]=1

while Q:
    x=Q.pop()
    for to in E[x]:
        if USE[to]==0:
            USE[to]=1
            H[to]=H[x]+1
            Q.append(to)

EH=[(h,ind+1) for ind,h in enumerate(H[1:])]
EH.sort(reverse=True)

COME=[1]*(N+1)
USE=[0]*(N+1)

for h,ind in EH:
    USE[ind]=1
    for to in E[ind]:
        if USE[to]==0:
            COME[to]+=COME[ind]

ANS=0
for i in range(1,N+1):
    SCORE=[]
    for j in E[i]:
        if COME[j]<COME[i]:
            SCORE.append(COME[j])

    if sum(SCORE)<N-1:
        SCORE.append(N-sum(SCORE)-1)

    AV=1

    for s in SCORE:
        AV+=pow(2,s,mod)-1

    ANS+=pow(2,N-1,mod)-AV
    #print(SCORE,AV)

print((ANS*pow(pow(2,N,mod),mod-2,mod))%mod)

### FIXED CODE ###

N=int(input())

E=[[] for i in range(N+1)]

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

mod=10**9+7

from collections import deque
Q=deque()

USE=[0]*(N+1)
Q.append(1)
H=[0]*(N+1)
H[1]=1
USE[1]=1

while Q:
    x=Q.pop()
    for to in E[x]:
        if USE[to]==0:
            USE[to]=1
            H[to]=H[x]+1
            Q.append(to)

EH=[(h,ind+1) for ind,h in enumerate(H[1:])]
EH.sort(reverse=True)

COME=[1]*(N+1)
USE=[0]*(N+1)

for h,ind in EH:
    USE[ind]=1
    for to in E[ind]:
        if USE[to]==0:
            COME[to]+=COME[ind]

ANS=0

POW2=[1]
for i in range(N+1):
    POW2.append(POW2[-1]*2%mod)

for i in range(1,N+1):
    SCORE=[]
    for j in E[i]:
        if COME[j]<COME[i]:
            SCORE.append(COME[j])

    if sum(SCORE)<N-1:
        SCORE.append(N-sum(SCORE)-1)

    AV=1

    for s in SCORE:
        AV+=POW2[s]-1

    ANS+=POW2[N-1]-AV
    #print(SCORE,AV)

print((ANS*pow(POW2[N],mod-2,mod))%mod)
### BUGGY CODE ###

import numpy as np
n = int(input())
A = [[ord(i) for i in input()] for j in range(n)]
count = 0
for a in range(n):
    arr = np.array(A[a:][:] + A[:a][:])
    arrT = arr.T
    for i in range(n):
        if list(arr[i][i+1:]) != list(arrT[i][i+1:]):
            break
    else:
        count += n
print(count)

### FIXED CODE ###

n = int(input())
A = [input() for _ in range(n)]
# AT = list(map(''.join,zip(*A)))
count = 0
for a in range(n):
    arr = A[a:][:] + A[:a][:]
    arrT = list(map(''.join, zip(*arr)))
    for i in range(n):
        if arr[i][i+1:] != arrT[i][i+1:]:
            break
    else:
        count += n
print(count)
### BUGGY CODE ###

import collections

N = int(input())
S = input()

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for i in range(N):
    for j in range(1, (N - 1) // 2 + 1):
        if i + 2 * j < N:
            if len({S[i], S[i + j], S[i + 2 * j]}) == 3:
                ans -= 1
    

print(ans)

### FIXED CODE ###

import collections

N = int(input())
S = input()

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

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

from itertools import combinations
from bisect import bisect_right

N = int(input())
*L, = map(int, input().split())
L = sorted(L)
ans = 0
for i, j in combinations(reversed(range(N)), 2): # i > j
    cand = L[:j]
    if not cand: continue
    idx = bisect_right(cand, abs(L[i] - L[j]))
    ans += j - idx
print(ans)

### FIXED CODE ###

from itertools import combinations
from bisect import bisect_left

N = int(input())
*L, = map(int, input().split())
L = sorted(L)
ans = 0
for i, j in combinations(range(N), 2): # i < j
    idx = bisect_left(L, L[i] + L[j])
    ans += idx - j - 1
print(ans)
### BUGGY CODE ###

N = int(input())
R = [int(input()) for i in list(range(N))]
maxv = -1000000000

for j in list(range(1, N)):
    for i in list(range(0, j)):
        maxv = max(maxv, R[j] - R[i])

print(maxv)

### FIXED CODE ###

N = int(input())
R = [int(input()) for i in list(range(N))]
maxv = -1000000000
minr = R[0]

for i in list(range(1, N)):
    maxv = max(maxv, R[i] - minr)
    minr = min(minr, R[i])

print(maxv)
### BUGGY CODE ###

import sys

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

######################################################

H, W, D = [int(_) for _ in input().split()]

A = [[int(_) for _ in input().split()]
     for _ in range(H)]

B = [-1] * (H * W)
for i in range(H):
    h = i * W
    for j in range(W):
        B[h + j] = (A[i][j], (i, j))
B = sorted(B, key=lambda x: x[0])
C = [b[0] for b in B]

import bisect

for i in range(int(input())):

    l, r = [int(_) for _ in input().split()]
    pre = None
    pre_n = 0
    ans = 0
    while l <= r:
        ni = bisect.bisect_left(C, l, pre_n)
        # print(B[ni])
        if pre is not None:
            ans += abs(B[ni][1][0] - pre[0]) + abs(B[ni][1][1] - pre[1])
        pre_ni = ni
        l = l + D
        pre = (B[ni][1])
    print(ans)


### FIXED CODE ###

import sys

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

######################################################

H, W, D = [int(_) for _ in input().split()]

A = [[int(_) for _ in input().split()]
     for _ in range(H)]

B = [None] * (H * W + 1)
for i in range(H):
    h = i * W
    for j in range(W):
        B[h + j] = (A[i][j], (i, j))
B[H * W] = (0, (-1, -1))
B = sorted(B, key=lambda x: x[0])
costs = [0] * (H * W + 1)
for i in range(H * W, 0, -1):
    if i + D <= H * W:
        costs[i] = costs[i + D] + abs(B[i][1][0] - B[i + D][1][0]) + abs(B[i][1][1] - B[i + D][1][1])

for i in range(int(input())):
    l,r = [int(_) for _ in input().split()]
    print(costs[l] - costs[r])
### BUGGY CODE ###

N, K = map(int, input().split())
XY = [list(map(int, input().split())) for i in range(N)]
ans = float('inf')
for i in range(N):
    for j in range(N):
        if XY[i][0] >= XY[j][0]:
            continue
        for k in range(N):
            for l in range(N):
                cnt = 0
                if XY[k][1] >= XY[l][1]:
                    continue
                for x, y in XY:
                    if (XY[i][0] <= x <= XY[j][0]) and (XY[k][1] <= y <= XY[l][1]):
                        cnt += 1
                    if cnt == K:
                        ans = min(ans, (XY[j][0]-XY[i][0]) * (XY[l][1]-XY[k][1]))
                        break
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
XY = []
YX = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append([x, y, i])
    YX.append([y, x, i])
XY.sort()
YX.sort()

x_order = {}
for xo, p in enumerate(XY):
    x, y, i = p
    x_order[i] = xo

cums = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(N):
    y, x, pi = YX[i]
    xo = x_order[pi]
    for j in range(N + 1):
        cums[i + 1][j] = cums[i][j] + (1 if j > xo else 0)

ans = float('inf')

for i in range(N-1):
    for j in range(i+1, N):
        for k in range(N-1):
            for l in range(k+1, N):
                if cums[l+1][j+1] - cums[l+1][i] - cums[k][j+1] + cums[k][i] >= K:
                        ans = min(ans, (XY[j][0]-XY[i][0]) * (YX[l][0]-YX[k][0]))

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

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

ans=-1

def dfs(start,goal):
    distance=[[-1]*H for j in range(W)]
    li_x=[1,-1,0,0]
    li_y=[0,0,1,-1]
    q = queue.Queue()
    q.put(start)
    distance[start[0]][start[1]]=0

    while not q.empty():
        hoge=q.get()
        x=hoge[0]
        y=hoge[1]
        dis=distance[x][y]

        for i in range(4):
            x1=x+li_x[i]
            y1=y+li_y[i]
            if (0 <=x1 < W and 0 <= y1 < H):
                if distance[x1][y1] == -1:
                    if S[y1][x1]=='.':
                        q.put([x1,y1])
                        distance[x1][y1]=dis+1

    return distance[goal[0]][goal[1]]

for sx in range(W):
    for gx in range(W):
        for sy in range(H):
            for gy in range(H):
                if S[sy][sx]=='.' and S[gy][gx]=='.':
                    re=dfs([sx,sy],[gx,gy])
                    if re > ans:
                        ans=re

print(ans)


### FIXED CODE ###

import queue
from itertools import product

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

ans=-1

def bfs(start):
    distance=[[-1]*H for j in range(W)]
    li_x=[1,-1,0,0]
    li_y=[0,0,1,-1]
    q = queue.Queue()
    q.put(start)
    distance[start[0]][start[1]]=0

    while not q.empty():
        hoge=q.get()
        x=hoge[0]
        y=hoge[1]
        dis=distance[x][y]

        for i in range(4):
            x1=x+li_x[i]
            y1=y+li_y[i]
            if (0 <=x1 < W and 0 <= y1 < H):
                if distance[x1][y1] == -1:
                    if S[y1][x1]=='.':
                        q.put([x1,y1])
                        distance[x1][y1]=dis+1
    m=[]
    for i in range(W):
        m.extend(distance[i])
    return max(m)

for sx,sy in product(range(W),range(H)):

                if S[sy][sx]=='.':
                    re=bfs([sx,sy])
                    if re > ans:
                        ans=re

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

N , K , Q = map(int,input().split())
A = [0] * Q
score = [K] * N

for i in range(Q):
  A[i] = int(input())

for i in range(Q):
  score = [score[i] - 1 for i in range(N)] 
  score[A[i] - 1] += 1

for i in range(N):
  if score[i]>0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

N , K , Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
score = [K-Q] * N
for i in range(Q):
  score[A[i] - 1] += 1

for i in range(N):
  if score[i]>0:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

N = int(input())
S = input()

Rs = []
Gs = []
Bs = []
for i, il in enumerate(S):
    if il == 'R':
        Rs.append(i)
    if il == 'G':
        Gs.append(i)
    if il == 'B':
        Bs.append(i)
num = 0
for i in Rs:
    for j in Gs:
        for k in Bs:
            if (2*i - j - k)*(2*j - k - i)*(2*k - i - j):
                num += 1
print(num)


### FIXED CODE ###

N = int(input())
S = input()

Rs = 0
Gs = 0
Bs = 0
for il in S:
    if il == 'R':
        Rs += 1
    if il == 'G':
        Gs += 1
    if il == 'B':
        Bs += 1
num = 0
for i in range(N):
    for step in range(1, N):
        j = i + step
        k = i + 2*step
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            num += 1
print(Rs*Gs*Bs - num)
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int,input().split()))
    '''
    count = 0
    result = list()
    r_apeend = result.append

    for i in range(N):
        Pj = P[0:i+1]
        min_P = min(Pj)
        r_append(min_P)
#        print(min_P)
#        if(P[i] == min_P):
#            count += 1

    print(len(set(result)))
    '''

    count = 0
    flag = True

    for i in range(N):
        for j in range(i):
            if(P[i] > P[j]):
                flag = False
                break
        if(flag):
            count += 1
        flag = True
    print(count)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline

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

    #result = list()

    minimum = P[0]
    count = 1
    for i in range(N):
        if(minimum > P[i]):
            minimum = P[i]
            count += 1
    print(count)
#        Pj = list(P[j] for j in range(i+1))
        #print(Pj)
        #Pj = P[0:i+1]
#        min_P = min(Pj)
#        result.append(min_P)
#        print(min_P)
#        if(P[i] == min_P):
#            count += 1

    '''
    count = 0
    flag = True

    for i in range(N):
        for j in range(i):
            if(P[i] > P[j]):
                flag = False
                break
        if(flag):
            count += 1
        flag = True
    print(count)
    '''

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

A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if A == B:
  print("YES")
  exit()

if W >= V:
  print("NO")
  exit()
  
if A > B:
  V *= -1
  W *= -1
    
  for t in range(T):
    A += V
    B += W
    if A <= B:
      print("YES")
      exit()
  
else:
  for t in range(T):
    A += V
    B += W
    if A >= B:
      print("YES")
      exit()
      
print("NO")


### FIXED CODE ###

A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if A == B:
  print("YES")
  exit()

if W >= V:
  print("NO")
  exit()
  
if A > B:
  V *= -1
  W *= -1

  A = A + V * T
  B = B + W * T
  if A <= B:
    print("YES")
    exit()

else:
  A = A + V * T
  B = B + W * T
  
  if A >= B:
    print("YES")
    exit()
      
print("NO")
### BUGGY CODE ###

n, w = list(map(int, input().split(' ')))

wv = []
for i in range(n):
    wv.append(list(map(int, input().split(' '))))


dp = [[0 for i in range(w + 1)] for j in range(n + 1)]

for i in range(1, n + 1):
    for j in range(1, w + 1):
        wi = wv[i - 1][0]
        vi = wv[i - 1][1]

        if j - wi >= 0:
            dp[i][j] = max([
                dp[i][j - 1],
                dp[i - 1][j - wi] + vi
            ])
            
        dp[i][j] = max([
            dp[i - 1][j],
            dp[i][j]
        ])

print(dp[n][w])


### FIXED CODE ###

n, w = list(map(int, input().split(' ')))

wv = []
for i in range(n):
    wv.append(list(map(int, input().split(' '))))


dp = [[0 for i in range(w + 1)] for j in range(n + 1)]

for i in range(1, n + 1):
    for j in range(1, w + 1):
        wi = wv[i - 1][0]
        vi = wv[i - 1][1]

        if j - wi >= 0:
            dp[i][j] = max([
                dp[i][j - 1],
                dp[i - 1][j - wi] + vi
            ])
            
        dp[i][j] = max([
            dp[i - 1][j],
            dp[i][j]
        ])

print(dp[n][w])
### BUGGY CODE ###

from collections import deque

Y, X = map(int,input().split())
# sy, sx = map(int, input().split())
# gy, gx = map(int, input().split())
sy,sx = 1,1
gy,gx = Y,X
s = [["#"]*(X+2) for _ in range(Y+2)]
for y in range(Y):
    s[y+1] = "#",*list(input()),"#"
inf = Y*X
c = [[inf]*X for _ in range(Y)]
c[sy-1][sx-1] = 0
drs = [(-1,0),(1,0),(0,-1),(0,1)]
q = deque([(sy-1, sx-1)])

while q:
    y,x = q.popleft()
    cost = c[y][x]
    for dx,dy in drs:
        x2 = x+dx
        y2 = y+dy
        if s[y2+1][x2+1] == "." and c[y2][x2] > cost:
            c[y2][x2] = cost+1
            q.appendleft((y2,x2))
if c[gy-1][gx-1] == inf:
    print("-1")
else:
    dots = 0
    for s1 in s:
        dots +=s1.count(".")
    print(dots-c[gy-1][gx-1]-1)

### FIXED CODE ###

H, W = map(int,input().split())
c = [["#"]*(W+2) for _ in range(H+2)]
dots = 0
for y in range(H):
    c[y+1] = "#",*list(input()),"#" 
    dots += c[y+1].count(".")
inf = H*W
m = [[inf]*W for _ in range(H)]
m[0][0] = 0
drs = [[-1,0],[1,0],[0,-1],[0,1]]

s = 0
yx = [[1, 1]]
notgoal = True
while notgoal and yx:
    yx2 = []
    s += 1
    for y,x in yx:
        for dy, dx in drs:
            x2 = x+dx
            y2 = y+dy
            if c[y2][x2] == "." and m[y2-1][x2-1] == inf:
                m[y2-1][x2-1] = s
                if (y2,x2) == (H,W):
                    notgoal = False
                else:
                    yx2.append([y2, x2])
    yx = yx2

if notgoal:
    print("-1")
else:
    print(dots-s-1)
### BUGGY CODE ###

import itertools
N = int(input())
s = [0] * N
answer = 0
for i in range(N):
    s[i] = int(input())
for i in range(1, N+1):  # 何問正解するか、0からN問まで
    for v in itertools.combinations(s, i):
        if sum(v) % 10 != 0:
            if answer <= sum(v):
                answer = sum(v)
        # print(v)

print(answer)
        

### FIXED CODE ###

import itertools
N = int(input())
s = [0] * N
not10 = []
answer = 0
for i in range(N):
    s[i] = int(input())

SUM = sum(s)
if SUM % 10 != 0:
    print(SUM)
    exit()
else:
    for i in range(N):
        if s[i] % 10 != 0:
            not10.append(s[i])
    not10.sort()
    if len(not10) == 0:
        print(0)
    else:
        print(SUM - not10[0])
    exit()
            
# print(not10)

# for i in range(1, N+1):  # 何問正解するか、0からN問まで
#     for v in itertools.combinations(s, i):
#         if sum(v) % 10 != 0 and answer <= sum(v):
#             answer = sum(v)
#         print(v, sum(v))

# print(answer)
### BUGGY CODE ###

n = int(input())

List = list(map(int, input().split()))

CountList = list(range(n))

for i in range(n):
    CountList[i] = List.count(i+1)

for j in CountList:
    print(j)

### FIXED CODE ###

import collections

n = int(input())
List = list(map(int, input().split()))
Col = collections.Counter(List)
Col2 = sorted(Col.items())
CountList = [0]*n
for i in Col2:
    CountList[i[0]-1] = i[1]
#CountList = list(Col2.values()) 
#for i in range(n-len(CountList)):
#    CountList.append(0)

for i in CountList:
    print(i)
### BUGGY CODE ###

from fractions import gcd
def lcm(a, b):
    return a // gcd(a, b) * b

def main():
    num = int(input())
    d = list(map(int, input().split()))
    k = 1
    MOD = 1000000007
    ans = 0
    for a in d:
        k = lcm(k, a)
    for a in d:
        ans += k // a % MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin

def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

def lcm(a, b):
    return (a * b) // gcd(a, b)

readline = stdin.readline
num = int(readline())
d = list(map(int, readline().split()))
k = 1
MOD = 1000000007
ans = 0
for a in d:
    k = lcm(k, a)
for a in d:
    ans += k // a
print(ans % MOD)
### BUGGY CODE ###

import fractions

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

gcd = 0
result = 1
holed_ints = []
for i in range(len(ints)):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(len(holed_ints)):
        gcd = fractions.gcd(gcd, holed_ints[j])
    if gcd > result:
        result = gcd

print(result)

### FIXED CODE ###

import fractions

integral_count = int(input())
blackboard_integers = list(map(int, input().split()))

gcd_integers = list(set(blackboard_integers))

gcd = 0
result = 1
for i in range(len(gcd_integers)):
    gcd = 0
    if blackboard_integers.count(gcd_integers[i]) >= 2:
        for n in gcd_integers:
            gcd = fractions.gcd(gcd, n)
    else:
        for n in gcd_integers[:i]:
            gcd = fractions.gcd(gcd, n)
        for n in gcd_integers[i+1:]:
            gcd = fractions.gcd(gcd, n)
    if gcd > result:
        result = gcd

print(result)