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

q=[]
h,w=map(int,input().split())
arr=[[True]*(w+2)]
arr.extend([[True]+[s!='.' for s in input()]+[True] for _ in range(h)])
arr.append([True]*(w+2))
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]:
      q.append([i,j])
ans=0
while 1:
  nq=[]
  for y,x in q:
    if not arr[y-1][x]:
      nq.append([y-1,x])
      arr[y-1][x]=True
    if not arr[y][x-1]:
      nq.append([y,x-1])
      arr[y][x-1]=True
    if not arr[y+1][x]:
      nq.append([y+1,x])
      arr[y+1][x]=True
    if not arr[y][x+1]:
      nq.append([y,x+1])
      arr[y][x+1]=True
  if len(nq)==0:
    break
  else:
    q=nq
    ans+=1
print(ans)

### FIXED CODE ###

import collections
q=collections.deque()
h,w=map(int,input().split())
arr=[[] for _ in range(h+2)]
for i in range(w+2):
  arr[0].append('#')
for i in range(h):
  arr[i+1].append('#')
  for j in input():
    arr[i+1].append(j)
  arr[i+1].append('#')
for i in range(w+2):
  arr[h+1].append('#')
dx=[-1,0,1,0]
dy=[0,-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]=='#':
      q.append([i,j,0])
while 1:
  y,x,cnt=q.popleft()
  for i in range(4):
    if arr[y+dy[i]][x+dx[i]]=='.':
      q.append([y+dy[i],x+dx[i],cnt+1])
      arr[y+dy[i]][x+dx[i]]='#'
  if len(q)==0:
    print(cnt)
    break
### BUGGY CODE ###

import sys
sys.setrecursionlimit(3 * 10 ** 5)


def main() -> None:
    def dfs(v, par, cnt):
        ans[v] = cnt + vs[v]
        for c in edges[v]:
            if c == par:
                continue
            dfs(c, v, ans[v])

    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        edges[a].append(b)
        edges[b].append(a)
    vs = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        vs[p - 1] += x
    ans = [0] * N
    dfs(0, -1, 0)
    print(*ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(3 * 10 ** 5)
input = sys.stdin.buffer.readline


def main() -> None:
    def dfs(v, par, cnt):
        ans[v] = cnt + vs[v]
        for c in edges[v]:
            if c == par:
                continue
            dfs(c, v, ans[v])

    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        edges[a].append(b)
        edges[b].append(a)
    vs = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        vs[p - 1] += x
    ans = [0] * N
    dfs(0, -1, 0)
    print(*ans)


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

import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)
# print(uni)
# print(cou)
com=[]
for i in range(len(cou)):
    nforc=cou[i]
    c=nforc*(nforc-1)//2
    com.append(c)
# com=np.array(com)
# print(com)
totalcombination=sum(com)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''
for j in range (N):
    n=A[j] #nはAの数列の数字
    f=np.where(uni==n)[0][0]
    t=com[f]
    e=(cou[f]-1)*(cou[f]-2)//2
    print(totalcombination-t+e)

### FIXED CODE ###

import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)

# print(uni)
# print(cou)
dic0={}
dic1={}
dic={} #回答用

com=[]
for i in range(len(cou)):
    c=cou[i]*(cou[i]-1)//2
    dic0[uni[i]]=cou[i]
    dic1[uni[i]]=c
    com.append(c)
    dic.setdefault(uni[i])

# print(com)
totalcombination=sum(com)

# print(com)
# print(dic1)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''

for j in range (N):
    n=A[j] #nはAの数列の数字
    if dic[n]==None:
        e=(dic0[n]-1)*(dic0[n]-2)//2
        t=totalcombination-dic1[n]+e
        dic[n]=t
        print(t)
    else:
        print(dic[n])
### BUGGY CODE ###

import sys; sys.setrecursionlimit(50000)
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

result = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if x * y * z > K: continue
            result.append(A[x]+B[y]+C[z])
result.sort(reverse=True)
for i in range(K):
    print(result[i])


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

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

V, E = map(int, raw_input().split())
g = [[] for i in xrange(V)]
cost = {}
for i in xrange(E):
    s, t, d = map(int, raw_input().split())
    g[s].append((t, d))
    cost[s,t] = d
get = cost.get
INF = 10**9
ALL = 2**V-1
dp = {}
def dfs(state, v, s):
    key = (state, v)
    if key in dp:
        return dp[key]
    if state == ALL:
        res = get((v, s), INF)
        dp[key] = res
        return res
    res = INF
    for t, d in g[v]:
        if not state & (1 << t):
            res = min(res, dfs(state | (1 << t), t, s) + d)
    dp[key] = res
    return res
def solve(v):
    global dp
    dp = {}
    return dfs(1<<v, v, v)
res = min(solve(v) for v in xrange(V))
print res if res<INF else -1

### FIXED CODE ###

import sys
readline = sys.stdin.readline
V, E = map(int, readline().split())
g = [[] for i in xrange(V)]
cost = {}
to = [0]*V
for i in xrange(E):
    s, t, d = map(int, readline().split())
    g[s].append((t, d))
    cost[s,t] = d
    to[s] |= 1 << t
get = cost.get
INF = 10**9
ALL = 2**V-1
dp = {}
start = 0
def dfs(state, v):
    key = (state, v)
    if key in dp: return dp[key]
    if state == ALL:
        dp[key] = res = get((v, start), INF)
        return res
    dp[key] = res = min((dfs(state | (1 << t), t) + d for t, d in g[v] if not state & (1 << t))) if state & to[v] != to[v] else INF
    return res
res = dfs(1, 0)
print res if res<INF else -1
### BUGGY CODE ###

n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

#import numpy as np

#a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
#b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(h[j]-h[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[10000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

### FIXED CODE ###

n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

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

n,w = map(int,input().split())
dp = [-1] * (w + 1)
dp[0] = 0
for i in range(n):
  weight,value = map(int,input().split())
  for j in range(w,-1,-1):
    if dp[j] != -1 and weight + j <= w:
      dp[weight+j] = max(dp[weight+j],dp[j] + value)
print(max(dp))

### FIXED CODE ###

def dp():
    n,w = map(int,input().split())
    lis = (map(int,input().split()) for i in range(n))
    
    dpp = [0] * (w + 1)
    for weight, value in lis:
        for j in range(w,weight-1,-1):
            dp = dpp[j-weight] + value
            if dpp[j] < dp:
                dpp[j] = dp
    return max(dpp)
print(dp())
### BUGGY CODE ###


def create_count_dic(text):
    count_dic = {}
    for t in text:
        if t in count_dic:
            count_dic[t] += 1
        else:
            count_dic[t] = 1
    return count_dic

def is_anagram(text1, text2):
    text1_dic = create_count_dic(text1)
    text2_dic = create_count_dic(text2)
    if text1_dic == text2_dic:
        return True
    else:
        return False

N = int(input())
S = [input() for x in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1, N):
        if is_anagram(S[i], S[j]):
            ans += 1

print(ans)


### FIXED CODE ###

from collections import defaultdict
counter = defaultdict(int)
N = int(input())
for i in range(N):
    counter[tuple(sorted(list(input())))] += 1
ans = 0
for n in counter.values():
    ans += n * (n - 1) // 2
print(ans)
### BUGGY CODE ###

import itertools

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

passwords = list(itertools.combinations(S, 3))

print(len(set(passwords)))

### FIXED CODE ###

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

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)
### BUGGY CODE ###

icase=0
if icase==0:
    a,b,k=map(int,input().split()) 
    ab=[]
    for i in range(a,b+1):
#        print(i,a+k-1,b-k+1)
        if i<=a+k-1 or b-k+1<=i:
            ab.append(i)
    for i in range(len(ab)):
        print(ab[i])
        


### FIXED CODE ###

icase=0
if icase==0:
    a,b,k=map(int,input().split()) 
    if a+k-1<b-k+1:
        for i in range(a,a+k):
            print(i)
        for i in range(b-k+1,b+1):
            print(i)
    else:
        for i in range(a,b+1):
            print(i)
### BUGGY CODE ###

from collections import Counter
from numba import jit

def main():
    n = int(input().strip())
    L = list(map(int, input().strip().split()))
    seen = Counter()
    
    
    for x in L:
        seen[x]+=1
    @jit
    def loop():
        ans=0
        for x in L:
            if seen[x]>1 or x!=1 and 1 in seen:
                continue
        
            tmp=2
            while tmp**2<=x:
                if x%tmp==0 and (tmp in seen or x/tmp in seen):
                    break
                tmp+=1
            else:
                ans+=1
        return ans
    print(loop())
# print(ans)
    
if '__main__' == __name__:
    main()

### FIXED CODE ###

def main():
    n = int(input().strip())
    L = list(map(int, input().strip().split()))
    L.sort()
    max_=L[-1]
    isDivisible = [False]*(max_) # 1-Lmax
    
    for i,x in enumerate(L):
        if i!=n-1 and x==L[i+1]:
            isDivisible[x-1]=True
            continue
        j=2*x
        while j<=max_:
            isDivisible[j-1]=True
            j+=x
    ans=0
    for x in L:
        if not isDivisible[x-1]:
            ans+=1
    print(ans)
# print(ans)
    
if '__main__' == __name__:
    main()
### BUGGY CODE ###

n = int(input())
a = input().split()
a_int = [int(n) for n in a]
ans = 1
for num in a_int:
    ans *= num
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N = int(input())
A = map(int, input().split())
 
res = 1
 
for a in sorted(A):
    res *= a
    if res > 10 ** 18:
        print("-1")
        exit()
print(res)
### BUGGY CODE ###

N = int(input())
A = list(map(int,list(input().split())))
Q = int(input())
s = []
for i in range(Q):
    B,C = map(int,(input().split()))
    r = 0
    for j in range(N):
        if A[j] == B:
            A[j] = C
        r += A[j]
    s.append(r)
for i in range(Q):
    print(s[i])



### FIXED CODE ###

import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    nb = Ac[B]
    Ac[C] += Ac[B]
    Ac[B] = 0

    if i==0:
        ans = 0
        for key,val in Ac.items():
            ans += key*val
    else:
        ans +=nb*C - nb*B
    
    print(ans)
### BUGGY 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())

dp = [[0] * (W + 1) for _ in range(N + 1)]

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

print(dp[N][W])

### 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())

dp = [[0] * (W + 1) for _ in range(N + 1)]

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

print(dp[N][W])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys


S = list(input())
N = len(S)
MOD = 2019
#%%
A = [0]*(N+1)
R = [0]*(2030)

R[0] += 1
base = 1
for i in range(N):
    A[i+1] = A[i] + base*int(S[N-1-i])
    base *= 10
    A[i+1] %= MOD
    R[A[i+1]] += 1

ans = 0
for r in R:
    ans += r*(r-1)//2
print(ans)
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys


S = list(input())
N = len(S)
MOD = 2019
#%%
A = [0]*(N+1)
R = [0]*(2030)

R[0] += 1
base = 1
for i in range(N):
    A[i+1] = A[i] + base*int(S[N-1-i])
    base *= 10
    base %= MOD
    A[i+1] %= MOD
    R[A[i+1]] += 1

ans = 0
for r in R:
    ans += r*(r-1)//2
print(ans)
### BUGGY CODE ###

# 入力は二行でそれぞれ[数値]

input_nums = int(input())
input_line = input()

result = 0

for k in range(input_nums):
    for j in range(k):
        for i in range(j):
            if(j-i != k-j):
                if(input_line[i] != input_line[j] and input_line[i] != input_line[k] and input_line[j] != input_line[k]):
                    result = result + 1

print(result)


### FIXED CODE ###

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 = j-i + j
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1

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

K,S = (int(x) for x in input().split())
count = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            #print(x,y,z)
            if x + y + z == S:
                count += 1
                #print(x,y,z)


print(count)

### FIXED CODE ###

K,S = (int(x) for x in input().split())
count = 0

for x in range(K+1):
    if x > S:
        break
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K:
            count += 1
        elif x + y > S:
            break


print(count)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
sub = [0]*N
for i in range(N):
  sub[i] = A.count(i+1)
for j in range(N):
  print(sub[j])

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = {}
for i in A:
  if i not in B:
    B[i] = 0
  B[i] += 1
  
for j in range(1,N+1):
  try:
    print(B[j])
  except KeyError:
    print(0)
### BUGGY CODE ###

from math import sqrt
def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
    return s

def main():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for x in a:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
    ans = 0
    for v in a:
        if dic[v] > 1:
            continue
        tmp = Divisor_Set(v)
        if v in tmp:
            tmp.remove(v)
        f = True
        for x in tmp:
            if x in dic or ((x > 1) and ((v//x) in dic)):
                f = False
                break
        if f:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from math import sqrt
from random import randint
def Divisor_Set(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def main1():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for x in a:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
    ans = 0
    a.sort()
    for i in range(n):
        v = a[i]
        if dic[v] > 1:
            continue
        lim = v//2 + 1
        f = True
        for j in range(i):
            if a[j] > lim:
                break
            if a[i] % a[j] == 0:
                f = False
                break
        if f:
            ans += 1
    print(ans)

def main2():
    n = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for x in a:
        if x in dic:
            dic[x] += 1
        else:
            dic[x] = 1
    ans = 0
    for v in a:
        if dic[v] > 1:
            continue
        tmp = Divisor_Set(v)
        tmp.remove(v)
        f = True
        for x in tmp:
            if x in dic:
                f = False
                break
        if f:
            ans += 1
    print(ans)

if __name__ == "__main__":
    if randint(1, 2) == 1:
        main1()
    else:
        main2()
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

dp = [0] * (N + 1)
dp[0] = 1

for i in range(N):
    if i + 1 not in A:
        dp[i + 1] += dp[i]
    if i + 2 <= N and i + 2 not in A:
        dp[i + 2] += dp[i]

print(dp[N] % mod)
# print(dp)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N, M = map(int, input().split())
#a = [0 for _ in range(N + 1)]
dp = [-1 for _ in range(N + 1)]
dp[0] = 1
for _ in range(M):
    a = int(input())
    dp[a] = 0
mod = 10**9 + 7

def f(n):
    if n < 0:
        return 0
    if dp[n] == -1:
        dp[n] = (f(n - 1) + f(n - 2)) % mod
    return dp[n]
print(f(N))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

def solve():

    from heapq import heappop, heappush


    X,Y,Z,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    sum_list = []
    seen_list = set()
    ans = []

    heappush(sum_list, (-(A[0]+B[0]+C[0]), 0, 0, 0))
    seen_list.add((0, 0, 0))

    while sum_list:
        s, i, j, k = heappop(sum_list)
        
        ans.append(-s)

        if i+1 < len(A) and (i+1, j, k) not in seen_list:
            heappush(sum_list, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
            seen_list.add((i+1, j, k))

        if j+1 < len(B) and (i, j+1, k) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
            seen_list.add((i, j+1, k))

        if k+1 < len(C) and (i, j, k+1) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
            seen_list.add((i, j, k+1))

    for i in range(0, K):
        print(ans[i])

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

def main():

    from heapq import heappop, heappush, heapify
    X,Y,Z,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    sum_list = []
    seen_list = set()
    ans = []

    heappush(sum_list, (-(A[0]+B[0]+C[0]), 0, 0, 0))
    seen_list.add((0, 0, 0))

    for _ in range(K):
        s, i, j, k = heappop(sum_list)
        
        ans.append(-s)

        if i+1 < len(A) and (i+1, j, k) not in seen_list:
            heappush(sum_list, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
            seen_list.add((i+1, j, k))

        if j+1 < len(B) and (i, j+1, k) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
            seen_list.add((i, j+1, k))

        if k+1 < len(C) and (i, j, k+1) not in seen_list:
            heappush(sum_list, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
            seen_list.add((i, j, k+1))

    for i in range(0, K):
        print(ans[i])

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

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
a = [0]+LIST()
a_acc = list(accumulate(a))
dp = [[None]*(N+1) for _ in range(N+1)]

def rec(l, r):
    if dp[l][r]: return dp[l][r] 
    if l == r:
        return 0
    mi = INF
    for i in range(l, r):
        mi = min(mi, rec(l, i)+rec(i+1, r))
    dp[l][r] = mi + (a_acc[r]-a_acc[l-1])
    return dp[l][r]

print(rec(1, N))


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
a = [0]+LIST()
a_acc = list(accumulate(a))
dp = [[None]*(N+1) for _ in range(N+1)]

def rec(l, r):
    if dp[l][r]: return dp[l][r] 
    if l == r:
        return 0
    mi = INF
    for i in range(l, r):
        mi = min(mi, rec(l, i)+rec(i+1, r))
    dp[l][r] = mi + (a_acc[r]-a_acc[l-1])
    return dp[l][r]

print(rec(1, N))
### BUGGY CODE ###

n = int(input())
a = list(int(input()) for _ in range(n))
a.sort()

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))


### FIXED CODE ###

from collections import Counter

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

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)