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

# coding: utf-8
#解法4 二分探索
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)


def bin_isOK(P):
    cnt=0
    value=0
    for i in range(X):
        for j in range(Y):
            for k in range(Z):
                if A[i]+B[j]+C[k]<P:
                    break
                cnt+=1
                if cnt>=K:
                    return True
    return False


def binary_search():
    ng = A[0]+B[0]+C[0]
    ok = -1

    while abs(ok - ng) >1:
        mid = (ok + ng)//2
        
        if bin_isOK(mid):
            ok = mid
        else:
            ng = mid
    
    return ok

border=binary_search()
ABC=[]

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if A[i]+B[j]+C[k]>=border:
                ABC.append(A[i]+B[j]+C[k])
            if len(ABC)>=K:
                break

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

    


### FIXED CODE ###

# coding: utf-8
#解法1 ABのK番まで　＋　CのK番まで
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()))

AB=[]

for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])

AB.sort(reverse=True)
C.sort(reverse=True)

ABC=[]

for i in range(min(K,X*Y)):
    for j in range(min(K,Z)):
        ABC.append(AB[i]+C[j])

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

from sys import stdin
S = input()
N = int(input())
Q =  [list(map(str, stdin.readline().split())) for _ in range(N)]
flag = True
for i in range(N):
    if Q[i][0]=="1":
        flag = not(flag)                
    else: 
        if (Q[i][1] == "2") == (flag == True):
             S = "".join([S,Q[i][2]])#先頭
        else :
            S1 = "".join([Q[i][2],S])
            S = S1

if flag == True:
    print(S)
else:
    print(S[::-1])  


### FIXED CODE ###

from sys import stdin
S = input()
x = S
y =str()   
N = int(input())
Q =  [list(map(str, stdin.readline().split())) for _ in range(N)]
flag = True
for i in range(N):
    if Q[i][0]=="1":
        flag = not(flag)                
    else: 
        if (Q[i][1] == "2") == (flag == True):
            x += Q[i][2]#先頭
        else :
            y += Q[i][2]
M = "".join([y[::-1],x])
if flag == True:
    print(M)
else:
    print(M[::-1])
### BUGGY CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation = 0
for i in range(N-1):
    for j in range(i+1,N):
        summation += (B[i] * B[j]) % x
print(summation % x)


### FIXED CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import bisect

n=int(input())
a= list(map(int, input().split()))
a1= [list(map(int, input().split())) for i in range(n-1)]

g=[[] for i in range(n)]

for x,y in a1:
    g[x-1].append(y-1)
    g[y-1].append(x-1)


vis = [0] * n
order = []
parent = [0] * n
s = [0]

while len(s):
    x = s.pop()
    vis[x] = 1
    order.append(x)
    for y in g[x]:
        if vis[y]: continue
        s.append(y)
        parent[y] = x


ans=[0]*n
LIS = [[0] for i in range(n)]

for x in order:
    LIS[x]=LIS[parent[x]][:]
    if a[x] > LIS[x][-1]:
        LIS[x].append(a[x])
    else:
        LIS[x][bisect.bisect_left(LIS[x], a[x])] = a[x]
    ans[x]=len(LIS[x])-1

for i in ans:
    print(i)

### FIXED CODE ###

from bisect import bisect_left
from collections import deque

N = int(input())
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for u, v in X:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)
INF=float('inf')
dp = [INF] * (N + 1)
dp[0] = -INF
rb = [[] for _ in range(N)]
ans = [0] * N

# DFS
q = deque([(0, 0)])  # (current, parent)
while q:
    u, p = q.pop()

    # Roll back
    if p is None:
        i, x = rb[u].pop()
        dp[i] = x
        continue

    # Update dp
    i = bisect_left(dp, A[u])
    rb[u].append((i, dp[i]))
    dp[i] = A[u]

    # Calc ans
    ans[u] = max(i,ans[p])

    # Go to next
    q.append((u, None))
    for v in graph[u]:
        if v == p:
            continue
        q.append((v, u))

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

from collections import deque
import math

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

    A.sort()

    Amax=max(A)

    dp=[True for _ in range(Amax)]

    tmp=-1
    res=0
    for i in range(len(A)):
        a=A.pop(0)
        if a==tmp:
            continue
        if dp[a-1]==True:
            if len(A)>0:
                if A[0]!=a:
                    res+=1
            else:
                res+=1
            m=1
            while (a*m)<=Amax:
                dp[a*m-1]=False
                m+=1
        tmp=a

    print(res)
if __name__=="__main__":
    main()

### FIXED CODE ###

from collections import deque
import math

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

    A.sort(reverse=True)

    Amax=max(A)

    dp=[0]*Amax

    tmp=-1
    res=0
    for i in range(len(A)):
        a=A.pop()
        if a==tmp:
            continue
        if dp[a-1]==0:
            if len(A)>0:
                if A[len(A)-1]!=a:
                    res+=1
            else:
                res+=1
            m=2
            while (a*m)<=Amax:
                dp[a*m-1]=1
                m+=1
        tmp=a

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

def counting(k, v, square):
    square += 1
    for _ in range(square):

        for r in range(k, k + square):
            if r > len(matrix) - 1:
                return False
            for c in range(v, v + square):
                if c > len(matrix[k]) - 1:
                    return False
                if matrix[r][c] == '1':
                    return False
        return True


line = input().split(' ')

answer = [[0 for _ in range(int(line[1]))] for _ in range(int(line[0]))]
matrix = []
maximum = 0
is_over = False
ggg = 0
for _ in range(int(line[0])):
    row = input().split(' ')
    matrix.append(row)

for i in range(len(matrix)):
    for j in range(len(matrix[i])):
        ggg += 1
        for m in range(min(int(line[0]), int(line[1]))):
            res = counting(i, j, maximum)
            if res:
                maximum += 1
            else:
                break

print(maximum * maximum)

### FIXED CODE ###

def solve2():
    r, c = map(int, input().split(' '))

    ans_matrix = [[0 for _ in range(c + 1)] for _ in range(r + 1)]
    input_matrix = []

    for _ in range(r):
        input_matrix.append(list(map(int, input().split(' '))))

    largest_square = 0

    for i in range(len(input_matrix)):
        for j in range(len(input_matrix[i])):
            new_i, new_j = i + 1, j + 1
            if input_matrix[i][j] == 0:
                ans_matrix[new_i][new_j] = min(ans_matrix[new_i - 1][new_j], ans_matrix[new_i][new_j - 1], ans_matrix[new_i - 1][new_j - 1]) + 1
                largest_square = ans_matrix[new_i][new_j] if ans_matrix[new_i][new_j] > largest_square else largest_square
            else:
                ans_matrix[new_i][new_j] = 0

    print(largest_square ** 2)


def main():
    solve2()


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

import numpy as np

H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
que = []
visited = [[-1]*W for _ in range(H)]
direction = [[1,0], [-1,0], [0,1], [0,-1]]

for i in range(H):
  for j in range(W):
    item = G[i][j]
    if item == '#':
      que.append((i,j))
      visited[i][j] = 0
    else:
      continue
while que:
  h,w = que.pop(0)
  for dh, dw in direction:
    if h+dh<0 or H<=h+dh or w+dw<0 or W<=w+dw:
      continue
    elif visited[h+dh][w+dw] != -1:
      continue
    que.append((h+dh,w+dw))
    visited[h+dh][w+dw] = visited[h][w] +1
print(np.max(visited))

### FIXED CODE ###

import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  G = [['#' == x for x in input()] for _ in range(H)]
 
  black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
 
  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not G[bi - 1][bj]:
        G[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not G[bi][bj - 1]:
        G[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not G[bi + 1][bj]:
        G[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not G[bi][bj + 1]:
        G[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
rank = [0] * n
for idx in range(n) :
    rank[idx] = a.index(idx+1)
    print(rank[idx]+1,end=" ")


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
rank = [0] * n
for idx in range(n) :
    rank[a[idx]-1] = idx + 1

for i in range(n) :
    print(rank[i], end=" ")
### BUGGY CODE ###

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

while(m>0):
    max_index=a.index(max(a))
    a[max_index] = a[max_index]//2
    m-=1
print(sum(a))

### FIXED CODE ###

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

from heapq import heappush, heappop
hq=[]

for a_val in a:
    # heappopで最も小さい値が取り出されるため、(-1)をかけて入れる
    heappush(hq, -a_val)
for _ in range(m):
    heappush(hq, -(heappop(hq)//(-2)))
print(-sum(hq))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
del a[n:len(a)-1]
result = []
[print(a.count(i+1)) for i in range(n)]


### FIXED CODE ###

import sys
import collections
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
for i in range(n):
    print(c[i+1])
### BUGGY CODE ###

from scipy.misc import comb


N, M = map(int, input().split())
MOD = 10**9+7

# 逆元
# a^{-1} mod を計算する
def mod_inv(a, m):
    return pow(a, m-2, m) % m


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)

    # 10C3 = (10*9*8)/(3*2*1)
    # 10*9*8 -> ans_mul
    # 3*2*1 -> ans_div
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    # ans_mul / ans_div をやりたい
    # ans_div の逆元を使って求める
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


# M を素因数分解
m_nokori = M
ans = 1
for i in range(2, M+1):
    if m_nokori == 1:
        break
    cnt = 0
    while m_nokori % i == 0:
        cnt += 1
        m_nokori //= i
    # cnt が 2^X とか 3^X の X の部分
    ans *= comb(N+cnt-1, N-1, exact=True)
    ans %= MOD

print(ans)


### FIXED CODE ###

# 逆元
# a^{-1} mod を計算する
def mod_inv(a, m):
    return pow(a, m-2, m)


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)

    # 10C3 = (10*9*8)/(3*2*1)
    # 10*9*8 -> ans_mul
    # 3*2*1 -> ans_div
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    # ans_mul / ans_div をやりたい
    # ans_div の逆元を使って求める
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


N, M = map(int, input().split())
MOD = 10**9+7
# M を素因数分解
rest = M
ans = 1
for i in range(2, int(M ** 0.5) + 1):
    cnt = 0
    while rest % i == 0:
        cnt += 1
        rest //= i
    # cnt が 2^X 1とか 3^X の X の部分
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD
if rest != 1:
    cnt = 1
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD

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

#!/usr/bin/env python3
#ABC97 C

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

lst = []
s = input()
k = I()
n = len(s)
for i in range(n):
    for j in range(i+1,n+1):
        lst.append(s[i:j])
lst = list(set(lst))
lst.sort()
print(lst[k-1])


### FIXED CODE ###

#!usr/bin/env python3
s = input()
K = int(input())

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])
l = list(l)

l.sort()

print(l[K-1])
### BUGGY CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, P = lr()
    S = sr()
    ans = 0
    for i in range(N):
        for j in range(i+1, N+1):
            if int(S[i:j])%P == 0:
                ans += 1
    print(ans)
resolve()

### FIXED CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, P = lr()
    S = list(map(int, list(sr())))
    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if S[i]%P == 0:
                ans += i+1
        print(ans)
        return
    S = S[::-1]
    lp = [0]*P
    c = 0
    for i in range(N):
        d = S[i]*pow(10,i,P)
        c = (c+d)%P
        lp[c] += 1
    ans = lp[0]
    for i in range(P):
        ans += lp[i]*(lp[i]-1)//2
    print(ans)
resolve()
### BUGGY CODE ###

def p_c():
    N, K, Q = map(int, input().split())

    l = [K] * N

    for _ in range(Q):
        A = int(input())
        for i in range(N):
            if i == A - 1:
                continue
            l[i] -= 1

    for a in l:
        if a > 0:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    p_c()


### FIXED CODE ###

from collections import defaultdict


def p_c():
    N, K, Q = map(int, input().split())

    l = defaultdict(int)

    for _ in range(Q):
        A = int(input())
        l[A - 1] += 1

    for i in range(N):
        if K - Q + l[i] > 0:
            print("Yes")
        else:
            print("No")


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

n = int(input())
a = list(map(int, input().split()))
for i in range(1, n+1):
  print(a.index(i) + 1,end=" ")

### FIXED CODE ###

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

n, m = map(int,input().split())
M = [[0 for _ in range(n)] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    M[a][b] = 1
    M[b][a] = 1
    
cnt = 0   
for i in range(n-1):
    if all(M[i][j] == 0 for j in range(1+i, n)):
        cnt += 1

print(cnt)

### FIXED CODE ###

from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

dist = [-1]*n
q = deque([])
cnt = 0

#連結成分のカウント

for i in range(n):
    if dist[i] != -1:
        continue
    dist[i] = 0
    q.append(i)
    while q:
        v = q.pop()
        s = g[v]
        for j in s:
            if dist[j] != -1:
                continue
            dist[j] = 0
            q.append(j)
    cnt += 1

print(cnt - 1)
### BUGGY CODE ###

s=input()
l=len(s)
a=[-1]*l
stack=[]
for i in range(l):
    if s[i]=='A':
        a[i]=1
        stack.append(i)
    elif s[i]=='B':
        a[i]=2
    else:
        a[i]=3
count=0
while stack:
    i=stack.pop(0)
    if i<l-2:
        if a[i]==1 and a[i+1]==2 and a[i+2]==3:
            count+=1
            a[i]=2
            a[i+1]=3
            a[i+2]=1
            stack.append(i+2)
            if (i-1>=0):
                if(a[i-1]==1):
                    stack.append(i-1)
            #print(a)
print(count)

### FIXED CODE ###

s=input()
l=[]
i=0
while i < len(s):
    if i<len(s)-1:
        if s[i]=='B' and s[i+1]=='C':
            l.append('D')
            i+=2
        else:
            l.append(s[i])
            i+=1
    else:
        l.append(s[i])
        i+=1
n=len(l)
ca=0
count=0
for i in range(n):
    if l[i]=='A':
        ca+=1
    elif l[i]=='D':
        count+=ca
    else:
        ca=0
print(count)
### BUGGY CODE ###

N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
  p, y = map(int, input().split())
  P.append(p)
  Y.append(y)
  if p in D:
    D[p].append(y)
  else:
    D[p] = [y]

for i in D.keys():
  D[i].sort()

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]].index(Y[i])+1).zfill(6)
  print(a+b)

### FIXED CODE ###

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

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく

ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n')
### BUGGY CODE ###

n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

for i in range(n):
  t = a[i]
  a[i] = 0
  print(max(a))
  a[i] = t

### FIXED CODE ###

n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]
count= a.count(max)
for i in range(n):
  if a[i] == max:
    if count > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)
### BUGGY CODE ###

def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
n=int(input())
x=input()
xint=int(x, 2)
ones=0
for i in range(n):
  if x[i]=='1':
    ones+=1
for i in range(n):
  counter=0
  if x[i]=='0':
    temp=xint+pow(2,n-1-i)
    temp1=ones+1
  else:
    temp=xint-pow(2,n-1-i)
    temp1=ones-1
  ans=0
  while temp!=0:
    temp=temp%temp1
    temp2=base10toN(temp,2)
    temp1=0
    for i in range(len(temp2)):
      if temp2[i]=='1':
        temp1+=1
    ans+=1
  print(ans)
    

### FIXED CODE ###

def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
n=int(input())
pop=[0]*(2*10**5+1)
for i in range(1,2*10**5+1):
  temp=base10toN(i,2)
  ans=0
  for j in range(len(temp)):
    if temp[j]=='1':
      ans+=1
  r=i%ans
  pop[i]=pop[r]+1
x=input()
ones=0
ans1=[]
for i in range(n):
  if x[i]=='1':
    ones+=1
dividemore=0
divideless=0
for i in range(n):
  if x[i]=='1':
    dividemore=(pow(2,n-1-i,ones+1)+dividemore)%(ones+1)
    if ones>=2:
      divideless=(pow(2,n-1-i,ones-1)+divideless)%(ones-1)
for i in range(n):
  counter=0
  if x[i]=='0':
    temp=(dividemore+pow(2,n-1-i,ones+1))%(ones+1)
  else:
    if ones==1:
      ans1.append('0')
      continue
    else:
      temp=(divideless-pow(2,n-1-i,ones-1))%(ones-1)
  ans1.append(str(pop[temp]+1))
print(' '.join(ans1))
### BUGGY CODE ###

#! python3
# coding:utf-8

n = int(input())
for i in range(1,n+1):
    cnt=0

    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                eq = x**2 + y**2 + z**2 + x*y + y*z + z*x
                   
                if eq == i:
                    cnt+=1
    print(cnt)

### FIXED CODE ###

#! python3
# coding:utf-8
 
def main():
    n = int(input())
    ans = [0 for _ in range(n)]
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                eq = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if eq < n+1:
                    ans[eq-1]+=1
    for i in ans:   
        print(i)

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

def solve(S):
    print(sum(S[i] % (i+1) for i in range(N)))

N = int(input())
solve([N]+[i-1 for i in range(2, N+1)])



### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

import numpy as np
MAX_INT = 100

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

dp = np.array([[100]*(N) for i in range(N+1)])

if  N%2 == 0:
  hand = 0
else:
  hand = 1

for i in range(N):
  if hand == 0:
    dp[i][i] = -a[i]
  else:
    dp[i][i] = a[i]
  
for i in range(1,N+1):
  for j in range(N+1):
    if i+j < N:
      if (hand+i)%2 == 1: # 先手
        dp[j][i+j] = max(dp[j][i+j-1]+a[i+j],dp[j+1][i+j]+a[j])
      else:
        dp[j][i+j] = min(dp[j][i+j-1]-a[i+j],dp[j+1][i+j]-a[j])
    else:
      break  
print(dp[0][-1])

### FIXED CODE ###

MAX_INT = 100

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

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

if  N%2 == 0:
  hand = 0
else:
  hand = 1

for i in range(N):
  if hand == 0:
    dp[i][i] = -a[i]
  else:
    dp[i][i] = a[i]
  
for i in range(1,N+1):
  for j in range(N+1):
    if i+j < N:
      if (hand+i)%2 == 1: # 先手
        dp[j][i+j] = max(dp[j][i+j-1]+a[i+j],dp[j+1][i+j]+a[j])
      else:
        dp[j][i+j] = min(dp[j][i+j-1]-a[i+j],dp[j+1][i+j]-a[j])
    else:
      break  
print(dp[0][-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    if a.count(i) >= 1:
        p = 1
    else:
        p = 0
        
    cnt[i - 1] += p

for i in cnt:
    print(i)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i - 1] += 1

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

import sys


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

    Kcost = [0] * (N * N)
    for sn in range(N * N):
        row, clm = divmod(sn, N)
        Kcost[sn] = min(row, N - row - 1, clm, N - clm - 1)

    Sitting = [1] * (N * N)
    Kcount = 0


    def Kcheck(qsn, cdsn):
        if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
            Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
            queue.append(cdsn)


    for sn in P:
        csn = sn - 1
        Kcount += Kcost[csn]
        Sitting[csn] = 0
        queue = [csn]

        while queue:
            qsn = queue.pop()
            div, mod = divmod(qsn, N)
            if mod: Kcheck(qsn, qsn - 1)
            if mod != N - 1: Kcheck(qsn, qsn + 1)
            if div: Kcheck(qsn, qsn - N)
            if div != N - 1: Kcheck(qsn, qsn + N)

    print(Kcount)


if __name__ == '__main__':
    main()

sys.exit()


### FIXED CODE ###

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

Kcost = [min(row, N - 1 - row, clm, N - 1 - clm) for row in range(N) for clm in range(N)]

Sitting = [1] * (N * N)
Kcount = 0


def Kcheck(qsn, cdsn):
    if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
        Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
        queue.append(cdsn)


for sn in P:
    csn = sn - 1
    Kcount += Kcost[csn]
    Sitting[csn] = 0
    queue = [csn]

    while queue:
        qsn = queue.pop()
        div, mod = divmod(qsn, N)
        if mod: Kcheck(qsn, qsn - 1)
        if mod != N - 1: Kcheck(qsn, qsn + 1)
        if div: Kcheck(qsn, qsn - N)
        if div != N - 1: Kcheck(qsn, qsn + N)

print(Kcount)
### BUGGY CODE ###

r,g,b,n = map(int, input().split())
count = 0
c0,c1,c2 = sorted([r,g,b])
for i in range(1+n//c2):
    for j in range(1+n//c1):
        rest = n - i*c2 - j*c1
        if rest%c0 == 0 and rest >= 0:
            count += 1
print(count)

### FIXED CODE ###

r,g,b,n = map(int, input().split())
count = 0
c0,c1,c2 = sorted([r,g,b])
for i in range(1+n//c2):
    rest1 = n - i*c2
    if rest1 < 0:
        break
    for j in range(1+rest1//c1):
        rest = n - i*c2 - j*c1
        if rest <0:
            break
        elif rest%c0 == 0:
            count += 1
print(count)