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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def yakusu(n):
    yakusu = []
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            yakusu.append(i)
            if n // i != i:
                yakusu.append(n//i)
    return yakusu
     
baisu = [False] * (10**6 + 1)
def main():
    N = I()
    A = LI()

    ok = 0
    for a in A:
        if baisu[a]:
            continue
        if not baisu[a]:
            num = a + a
            while num < 10**6+1:
                baisu[num] = True
                num += a
    s = collections.Counter(A)
    for a in A:
        if not baisu[a]:
            if s[a] > 1:
                continue
            ok += 1
    print(ok)
main()



### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def yakusu(n):
    yakusu = []
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            yakusu.append(i)
            if n // i != i:
                yakusu.append(n//i)
    return yakusu
     
baisu = [False] * (10**6 + 1)
def main():
    N = I()
    A = LI()

    ok = 0
    for a in set(A):
        if baisu[a]:
            continue
        if not baisu[a]:
            num = a + a
            while num < 10**6+1:
                baisu[num] = True
                num += a
    s = collections.Counter(A)
    for a in A:
        if not baisu[a]:
            if s[a] > 1:
                continue
            ok += 1
    print(ok)
main()
### BUGGY CODE ###

import sys
N = int(input().strip())
D = list(map(int, input().strip().split(" ")))
print(N, len(D), file=sys.stderr)

M = int(input().strip())
T = list(map(int, input().strip().split(" ")))
print(M, len(T), file=sys.stderr)

for t in T:
    if t not in D:
        print("NO")
        exit(0)
    D.remove(t)
print("YES")
exit(0)


### FIXED CODE ###

import sys
N = int(input().strip())
D = list(map(int, input().strip().split(" ")))
print(N, len(D), file=sys.stderr)

import collections
Dd = collections.defaultdict(int)
for d in D:
    Dd[d] += 1

M = int(input().strip())
T = list(map(int, input().strip().split(" ")))
print(M, len(T), file=sys.stderr)
Td = collections.defaultdict(int)
for t in T:
    Td[t] += 1

for k,v in Td.items():
    if Dd[k] < v:
        print("NO")
        exit(0)
print("YES")
exit(0)
### BUGGY CODE ###

n,m = map(int, input().split())
mod = 10**9 + 7
a = list(map(int, input().split()))
dp = [[[0]*256 for _ in range(n+1)]for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  x = a[i]
  dp[i+1][0] = dp[i][0][:]
  for j in range(n):
    for k in range(256):
      dp[i+1][j+1][k] = (dp[i][j+1][k] + dp[i][j][k^x])%mod
f = 1
ans = 0
for j in range(1,n+1):
  f = f*j%mod
  ans += dp[n][j][m]*f
  ans %= mod
print(ans)

### FIXED CODE ###

n,m = map(int, input().split())
mod = 10**9 + 7
a = list(map(int, input().split()))
dp = [[[0]*256 for _ in range(n+1)]for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  x = a[i]
  dp[i+1][0] = dp[i][0][:]
  for j in range(n):
    for k in range(256):
      dp[i+1][j+1][k] = (dp[i][j+1][k] + dp[i][j][k^x])%mod
f = 1
ans = 0
for j in range(1,n+1):
  f = f*j%mod
  ans += dp[n][j][m]*f
  ans %= mod
print(ans)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
cout=[]
sa=list(set(a))
for i in range(len(sa)):
    if a.count(sa[i])%2==1:
        cout.append(1)
print(len(cout))

### FIXED CODE ###

import collections
n=int(input())
a=[int(input()) for i in range(n)]
ad=collections.Counter(a)
counter=0
for i in ad.values():
    if i%2==1:
        counter+=1
print(counter)
### BUGGY CODE ###

n,k=map(int,input().split())
num=list(map(int,input().split()))
a=[0]*n
for x in num:
    a[x-1]+=1
a=sorted(a)
for i in range(n):
    if a[i]!=0:
        del a[:i]
        break
ans=0
while len(a)>k:
    ans+=a[0]
    a.pop(0)
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
num=list(map(int,input().split()))
a=[0]*n
for x in num:
    a[x-1]+=1
a=sorted(a)
for i in range(n):
    if a[i]!=0:
        del a[:i]
        break
ans=0
i=0
while len(a)-i>k:
    ans+=a[i]
    i+=1
print(ans)
### BUGGY CODE ###

x = int(input())
ans = 1

for i in range(1, x):
    for j in range(2, x):
        if i**j <= x:
            ans = max(ans, i**j)
print(ans)

### FIXED CODE ###

x = int(input())
ans = 1

for i in range(1, 100):
    for j in range(2, 100):
        tmp = i**j
        if tmp <= x:
            ans = max(ans, tmp)
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
  B,C=map(int,input().split())
  for j in range(len(A)):
    if A[j]==B:
      A[j]=C
  print(sum(A))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=sum(A)
check=[0]*(10**5+1)
for key in A:
  check[key]+=1
Q=int(input())
for i in range(Q):
  B,C=map(int,input().split())
  if check[B]==0:
    print(ans)
  else:
    x=C-B
    ans+=check[B]*x
    print(ans)
    check[C]+=check[B]
    check[B]=0
### BUGGY CODE ###

from collections import deque

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

seen = [0] * N
q = deque()
group = []

for i in range(N):
    if seen[i]:
        continue
    q.append(i)
    seen[i] = 1
    k = 1
    while q:
        t = q.pop()
        for j in range(M):
            if AB[j][0] == i + 1 and seen[AB[j][1] - 1] != 1:
                q.append(AB[j][1])
                seen[AB[j][1] - 1] = 1
                k += 1
            if AB[j][1] == i + 1 and seen[AB[j][0] - 1] != 1:
                q.append(AB[j][0] - 1)
                seen[AB[j][0] - 1] = 1
                k += 1
    group.append(k)

print(max(group))


### FIXED CODE ###

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

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):  # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):  # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def size(self, x):  # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def members(self, x):  # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # グループの数を返す
        return len(self.roots())

    def all_group_members(self):  # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):  # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(N)
for i in range(M):
    uf.union(AB[i][0] - 1, AB[i][1] - 1)
l = []
for i in range(N):
    l.append(uf.size(i))
print(max(l))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
rank = []

for i in range(1,N+1):
    print(A.count(i))

### FIXED CODE ###

N = int(input())
A = input().split()

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[str(i)])
### BUGGY CODE ###

m_d = list()    # 魔法移動距離
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i,j) not in [(0,0),(-1,0),(0,-1),(1,0),(0,1)]:
            m_d += [(i,j)]

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+4, w+4), INF)
dist = [[INF for j in range(w+4)] for i in range(h+4)]

# マップ境界を壁で囲む
S = ['##{}##'.format(s_row) for s_row in s]
S = ['##{}##'.format('#' * (w+4))]*2 + S
S = S + ['##{}##'.format('#' * (w+4))]*2

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置、終了位置を調整
si, sj = si+1, sj+1
ti, tj = ti+1, tj+1
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q.popleft()
    d = dist[i][j]
    for di, dj in [(-1,0),(0,-1),(1,0),(0,1)]:
        ni, nj = di+i, dj+j
        if (S[ni][nj]=='#'):
            continue # 壁
        if (dist[ni][nj]<=d):
            continue # 探索済みコスト以上
        dist[ni][nj] = d
        q.appendleft((ni,nj))

    for di, dj in m_d:
        ni, nj = di+i, dj+j
        if (S[ni][nj]=='#'):
            continue # 壁
        if (dist[ni][nj]<=d):
            continue # 探索済みコスト以上
        dist[ni][nj] = d+1
        q.append((ni,nj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)


### FIXED CODE ###

h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 移動Aで探索する方向
d_a = [(-1,0), (0,-1),(1,0),(0,1)]
# 移動Bで探索する方向
d_b = [ (i, j) for j in range(-2, 3) for i in range(-2, 3)]

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+2, w+2), INF)
dist = [[INF for j in range(w+2)] for i in range(h+2)]

# マップ境界と壁を距離0にして探索させない
for i in range(h+2):
    dist[i][0] = 0
    dist[i][-1] = 0
for j in range(w+2):
    dist[0][j] = 0
    dist[-1][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#': dist[i+1][j+1] = 0
#dist = [[INF for j in range(w)] for i in range(h)]

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q[0]
    d = dist[i][j]
    q.popleft()
    # 移動Aによるコスト
    for v in range(len(d_a)):
        di, dj = d_a[v][0]+i, d_a[v][1]+j
        if (di, dj) == (ti, tj):
            print(d)
            exit(0)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d
        q.appendleft((di, dj))
    # 移動Bによるコスト
    for v in range(len(d_b)):
        # マップ境界で2以上移動したときに、反対の境界に向かうように剰余を取る
        di, dj = (d_b[v][0]+i)%(h+2), (d_b[v][1]+j)%(w+2)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d+1
        q.append((di, dj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)
### BUGGY CODE ###

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

blue_count = 0
while n != 0:
    # 青
    if n > a:
        n -= a
        blue_count += a
    else:
        blue_count += n
        n = 0
    if n > b:
        n -= b
    else:
        n = 0

print(blue_count)


### FIXED CODE ###

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

blue_count = a * (n // (a + b))
n -= (a + b) * (n // (a + b))
if n >= a:
    blue_count += a
else:
    blue_count += n
print(blue_count)
### BUGGY CODE ###

N,M,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*M]
CD = [list(map(int,input().split())) for _ in [0]*K]

import sys
sys.setrecursionlimit(10**7)

class UnionFind:
    def __init__(self,N):
        self.Parent = list(range(N))
    def get_Parent(self,n):
        if self.Parent[n] == n:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

U = UnionFind(N)
E_f = [[] for _ in [0]*N]
for a,b in AB:
    a -= 1
    b -= 1
    U.merge(a,b)
    E_f[a].append(b)
    E_f[b].append(a)
group = [set() for _ in [0]*N]
for i in range(N):
    p = U.get_Parent(i)
    group[p].add(i)

E_b = [[] for _ in [0]*N]
for c,d in CD:
    c -= 1
    d -= 1
    E_b[c].append(d)
    E_b[d].append(c)

ans = [0]*N
for i in range(N):
    p = U.get_Parent(i)
    tmp = group[p].copy()
    for b in E_b[i]:
        if b in tmp:tmp.remove(b)
    ans[i] = len(tmp) - len(E_f[i]) - 1

print(*ans)

### FIXED CODE ###

N,M,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*M]
CD = [list(map(int,input().split())) for _ in [0]*K]

import sys
sys.setrecursionlimit(10**7)

class UnionFind:
    def __init__(self,N):
        self.Parent = list(range(N))
    def get_Parent(self,n):
        if self.Parent[n] == n:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

U = UnionFind(N)
E_f = [[] for _ in [0]*N]
for a,b in AB:
    a -= 1
    b -= 1
    U.merge(a,b)
    E_f[a].append(b)
    E_f[b].append(a)
group = [set() for _ in [0]*N]
for i in range(N):
    p = U.get_Parent(i)
    group[p].add(i)

E_b = [[] for _ in [0]*N]
for c,d in CD:
    c -= 1
    d -= 1
    E_b[c].append(d)
    E_b[d].append(c)

ans = [0]*N
for i in range(N):
    p = U.get_Parent(i)
    cnt = 0
    for b in E_b[i]:
        if b in group[p]: cnt += 1
    ans[i] = len(group[p]) -cnt - len(E_f[i]) - 1

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

import sys
sys.setrecursionlimit(10**7)

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

dp = [float("inf")]*n

def rec(i):#全探索+メモ化
    if dp[i] != float("inf"):
        return dp[i]
    if i <= 0:
        return 0
    else:
        for l in range(1,k+1):
            if i-l < 0:continue
            dp[i] = min(dp[i],rec(i-l) + abs(h[i]-h[i-l]))
    return dp[i]

print(rec(n-1))
            

### FIXED CODE ###

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

dp = [float("inf")]*n

#初期条件
dp[0] = 0

#漸化式
for i in range(1,n):
    for l in range(1,k+1):
        if i-l < 0:continue
        dp[i] = min(dp[i],dp[i-l] + abs(h[i-l]-h[i]))

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

import math
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10 ** 9 + 7

ans = 0

def com(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
  if N - 1 - i >= K - 1:
    ans -= A[i] * com(N - 1 - i, K - 1)
    ans += A[- i - 1] * com(N - 1 - i, K - 1)
    ans = ans % MOD
    
print(ans % MOD)

### FIXED CODE ###

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10 ** 9 + 7

ans = 0

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N2 = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N2 + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

#print(cmb(n, r, p))
for i in range(len(A)):
  if N - 1 - i >= K - 1:
    ans += (A[- i - 1] - A[i]) * cmb(N - 1 - i, K - 1, MOD)
    ans = ans % MOD
    
    
print(ans % MOD)
### BUGGY CODE ###

num=[]
for i in range(32):
  stack=i*i
  while stack<=1000:
    num.append(stack)
    stack*=i
num.sort()
num.reverse()
n=int(input())
for i in num:
  if i<=n:
    print(i)
    exit()

### FIXED CODE ###

num=[1]
for i in range(2,32):
  stack=i*i
  while stack<=1000:
    num.append(stack)
    stack*=i
num.sort()
num.reverse()
n=int(input())
for i in num:
  if i<=n:
    print(i)
    exit()
### BUGGY CODE ###

import bisect
A, B, Q = map(int,input().split())
s = [-10**20] + [int(input()) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(input()) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(input())
    print(min(
        max(s[bisect.bisect_left(s,x)],t[bisect.bisect_left(t,x)])-x,
        x-min(s[bisect.bisect_left(s,x)-1],t[bisect.bisect_left(t,x)-1]),
        s[bisect.bisect_left(s,x)]-x + s[bisect.bisect_left(s,x)]-t[bisect.bisect_left(t,x)-1],
        t[bisect.bisect_left(t,x)]-x + t[bisect.bisect_left(t,x)]-s[bisect.bisect_left(s,x)-1],
        x-s[bisect.bisect_left(s,x)-1] + t[bisect.bisect_left(t,x)]-s[bisect.bisect_left(s,x)-1],
        x-t[bisect.bisect_left(t,x)-1] + s[bisect.bisect_left(s,x)]-t[bisect.bisect_left(t,x)-1]))


### FIXED CODE ###

import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))
### BUGGY CODE ###

X, Y, Z, K = list(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 A:
  for j in B:
    ab.append(i + j)

ab.sort(reverse = True)

abc = []
for i in ab[:3000]:
  for j in C:
    abc.append(i + j)

abc.sort(reverse = True)

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


### FIXED CODE ###

X, Y, Z, K = list(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)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
### BUGGY CODE ###

import sys
import heapq
from typing import List, Tuple, Dict
from dataclasses import dataclass, field

import scipy
import numpy as np
from numba import jit

D = int(input())  # 日数 D = 365
C = np.array(list(map(int, input().split())), dtype='int32')  # 満足度の下がりやすさ 26個
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype='int32')  # d日目にコンテストiを行ったときの満足度


@dataclass()
class Node:
    value: int
    plan: List[int]
    last: List[int]

    def __lt__(self, other) -> bool:
        return self.value > other.value  # PriorityQueueで最大値が欲しいので逆に


def calc_last(plan: List[int]) -> List[int]:
    res = [0 for _ in range(26)]

    for d, p in enumerate(plan):
        res[p - 1] = d + 1

    return res


def calc_satisfaction(plan: List[int]) -> int:
    assert len(plan) == D
    res = 0
    last = [0 for _ in range(26)]

    for d in range(D):
        p = plan[d] - 1
        res += S[d][p]
        last[p] = d + 1

        for i in range(26):
            res -= C[i] * (d + 1 - last[i])

    return res


def calc_score(plan: List[int]) -> int:
    return max(10 ** 6 + calc_satisfaction(plan), 0)


def calc_dissatisfaction(d: int, last: List[int]) -> int:
    return sum([C[i] * (d - last[i]) for i in range(26)])


CAPACITY = 26

queue: List[Node] = [Node(0, [], [0 for _ in range(26)])]
for d in range(D):
    next_queue: List[Node] = []

    heapq.heapify(queue)
    cnt = 0
    while queue and cnt < CAPACITY:
        cnt += 1
        node = heapq.heappop(queue)
        dis = calc_dissatisfaction(d + 1, node.last)

        for i in range(26):
            s = S[d][i] + C[i] * (d + 1 - node.last[i]) - dis

            next_queue.append(
                Node(
                    node.value + s,
                    node.plan + [i + 1],
                    node.last[:i] + [d + 1] + node.last[i + 1:]
                ),
            )

    queue = next_queue

res_node = heapq.heappop(queue)
print(res_node, file=sys.stderr)
print('\n'.join(map(str, res_node.plan)))


### FIXED CODE ###

from dataclasses import dataclass, field

import scipy
import numpy as np
from numba import jit


@dataclass()
class Node:
    date: int
    value: int
    result: list = field(default_factory=list)

    def __lt__(self, other) -> bool:
        return self.value < other.value

    def output(self) -> str:
        assert len(self.result) == 365
        return '\n'.join(self.result)


D = int(input())  # 日数 D = 365
C = np.array(list(map(int, input().split())), dtype=int)  # 満足度の下がりやすさ 26個
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)  # d日目にコンテストiを行ったときの満足度

for d in range(D):
    t = 0
    max_s = 0
    for i, s in enumerate(S[d]):
        if s > max_s:
            t = i
            max_s = s

    print(t + 1)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, t = map(int, input().split())
    ab = []
    for _ in range(n):
        a, b = map(int, input().split())
        ab.append((a, b))
    ab.sort()
    dp = [0] * (t + 1)
    for a, b in ab:
        mx = 0
        for i in range(t - 1, -1, -1):
            dpi = dp[i]
            if dpi > mx: mx = dpi
            if i - a >= 0:
                dp[i] = max(dpi, dp[i - a] + b)
        dp[t] = max(dp[t], mx + b)
    print(dp[t])
    # print(dp)

main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, t = map(int, input().split())
    ab = []
    for _ in range(n):
        a, b = map(int, input().split())
        ab.append((a, b))
    ab.sort()
    dp = [0] * (t + 1)
    for a, b in ab:
        mx = 0
        for i in range(t - 1, -1, -1):
            dpi = dp[i]
            if dpi > mx: mx = dpi
            if i - a >= 0:
                dp[i] = max(dpi, dp[i - a] + b)
        dp[t] = max(dp[t], mx + b)
    print(dp[t])
    # print(dp)

main()
### BUGGY CODE ###

N, W = map(int, input().split(" "))
wv = [[int(i) for i in input().split(" ")] for _ in range(N)]

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

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

### FIXED CODE ###

import numpy as np
N, W = map(int, input().split(" "))

dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int, input().split(" "))
    dp[w:] = np.maximum(dp[w:], dp[:-w]+v)
print(int(dp[-1]))