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

# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for _ in range(m):
    b, c= map(int, input().split())
    if a[n-1] < c:
        for i in range(b):
            a.append(c)
        a.sort(reverse=True)
print(sum(a[:n]))


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = sorted(list(map(int, readline().split())))
bc = [tuple(map(int, readline().split())) for i in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
index = 0
cnt = 0
for i in range(n):
    if a[i] > bc[index][1]:
        break
    a[i] = bc[index][1]
    cnt += 1
    if cnt == bc[index][0]:
        cnt = 0
        index += 1
        if index == m:
            break
print(sum(a))
### BUGGY CODE ###

import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
d = getInputListInt()


def combinations_count(n, r):
    if n <= 1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

dic = {}

for key in d:
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

for i in range(n):
    ans=0
    tmp_key = d[i]
    for k in dic:
        if k == tmp_key:
            ans += combinations_count(dic[k]-1, 2)
        else:
            ans += combinations_count(dic[k], 2)
    print(ans)




### FIXED CODE ###

import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()
    c = collections.Counter(d)

    total = 0
    for v in c.values():
        total += v * (v - 1) // 2

    for i in range(n):
        v = c[d[i]]

        print(int(total - v + 1))


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

def onigokko():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    
    if B < A:
        swap = A
        A = B
        B = swap
    
    for i in range(T):
        # Aから一番遠い所へ移動
        B += W

        # Aを動かす
        # 一番遠い所へ移動
        A += V

        # もし、A>=Bなら鬼の勝ち
        if A >= B:
            print('YES')
            return
    print('NO')

onigokko()

### FIXED CODE ###

def onigokko():
    A,V = map(int, input().split())
    B,W = map(int, input().split())
    T = int(input())
    
    if B < A:
        swap = A
        A = B
        B = swap
    
    tikaduku = V - W
    
    # 遠ざかったらアウト
    if tikaduku < 1:
        return 'NO'
    
    kyori = B - A
    
    if kyori <= tikaduku * T:
        return 'YES'
    
    return 'NO'

print(onigokko())
### BUGGY CODE ###

import sys
n,k=map(int,input().split())
s=input()
snum=[]
now_si=""
now_sinum=0
for i in range(len(s)):
    if(now_si!=s[i]):
        now_si=s[i]
        snum.append(now_sinum)
        now_sinum=1
    else:
        now_sinum+=1
else:
    snum.append(now_sinum)
snum.pop(0)
#print(snum)

if(len(snum)<3):
    print(sum(snum)-1)
    sys.exit()

for i in range(k):
    min_threesum=9999999999999
    min_threesum_j=9999999999999

    for j in range(len(snum)-3,-1,-1):
        threesum=snum[j]+snum[j+1]+snum[j+2]
        if(threesum==3):
            snum[j]+=snum[j+1]+snum[j+2]
            snum.pop(j+1)
            snum.pop(j+1)
            break
        elif(min_threesum>threesum):
            min_threesum=threesum
            min_threesum_j=j
    else:
        snum[min_threesum_j]+=snum[min_threesum_j+1]+snum[min_threesum_j+2]
        snum.pop(min_threesum_j+1)
        snum.pop(min_threesum_j+1)

#    print(snum)
    if(len(snum)<3):
        print(sum(snum)-len(snum))
        sys.exit()


print(sum(snum)-len(snum))

### FIXED CODE ###

import sys
n,k=map(int,input().split())
s=input()
snum=[]
now_si=""
now_sinum=0
for i in range(len(s)):
    if(now_si!=s[i]):
        now_si=s[i]
        snum.append(now_sinum)
        now_sinum=1
    else:
        now_sinum+=1
else:
    snum.append(now_sinum)
snum.pop(0)

if(len(snum)<3):
    print(sum(snum)-1)
    sys.exit()

for i in range(k):
#    print(snum)
    if(len(snum)<3):
        snum=[sum(snum)]
        break

    snum[-3]+=snum[-2]+snum[-1]
    snum.pop(-1)
    snum.pop(-1)

print(sum(snum)-len(snum))
### BUGGY CODE ###

import copy

n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
mod = 10**9 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = []
for i in a:
    ar = factorization(i)
    arr.append(ar)
    for j,k in ar:
        if j not in d:
            d[j] = k
        else:
            d[j] = max(k, d[j])

for i in arr:
    d2 = copy.copy(d)
    tmp = 1
    for j,k in i:
        d2[j] -= k
    for k,v in d2.items():
        tmp *= pow(k,v,mod)
    ans += tmp
    ans %= mod

print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
mod = 10**9 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

for i in a:
    arr = factorization(i)
    for j,k in arr:
        if j not in d:
            d[j] = k
        else:
            d[j] = max(k, d[j])

l = 1
for k,v in d.items():
    l *= pow(k,v,mod)
    l %= mod

for i in a:
    ans += l * pow(i, mod-2, mod)
    ans %= mod

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

a = int(input())
b = list(map(int,input().split()))
for i in range(a):
    c = 0
    for num in range(len(b)):
        if i+1 == b[num]:
           c = c + 1
    print(c)
    



### FIXED CODE ###

a = int(input())
b = list(map(int,input().split()))
c = [0]*a
for i in b:
    c[i-1] += 1
for i in c:
    print(i)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
query = [input().split() for i in range(Q)]

for i in range(Q):
    tmp = S[int(query[i][0])-1:int(query[i][1])]
    print(len([i for i in range(len(tmp)-1) if tmp[i] == 'A' and tmp[i+1] == 'C']))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
query = [input().split() for i in range(Q)]
AC = [0 for i in range(N+1)]

for i in range(N):
    AC[i+1] = AC[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    L, R = int(query[i][0]), int(query[i][1])
    print(AC[R-1] - AC[L-1])
### BUGGY CODE ###


n, ww = map(int, input().split())

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

dp = {0:0}
for w, v in wv:
    dp_next = dp.copy()
    for key in dp:
        dp_next[key+v] = min(dp[key]+ w, dp.get(key+v, float("inf")))
    dp = dp_next
for key in sorted(dp.keys(), reverse=True):
    if dp[key] <= ww:
        print(key)
        exit()

### FIXED CODE ###

n, ww = map(int, input().split())

wv = [list(map(int, input().split())) for i in range(n)]
wv.sort(key=lambda x:x[1])
dp = {0:0}
for w, v in wv:
    dp_next = dp.copy()
    for key in dp:
        dp_next[key+v] = min(dp[key]+ w, dp.get(key+v, float("inf")))
    dp = dp_next
for key in sorted(dp.keys(), reverse=True):
    if dp[key] <= ww:
        print(key)
        exit()
### BUGGY CODE ###

q = int(input())

L = [True] * (10**5 + 1)

L[0], L[1] = False, False

for i in range(2, int((10**5) ** 0.5) + 1):
    if not L[i]:
        continue
    j = 2
    while i * j <= 10**5:
        L[i * j] = False
        j += 1

for i in range(q):
    l, r = map(int, input().split())
    ans = 0
    for j in range(l, r+1):
        if L[j] and L[(j + 1) // 2]:
            ans += 1
    print(ans)

### FIXED CODE ###

q = int(input())

L = [True] * (10**5 + 1)

L[0], L[1] = False, False

for i in range(2, int((10**5) ** 0.5) + 1):
    if not L[i]:
        continue
    j = 2
    while i * j <= 10**5:
        L[i * j] = False
        j += 1

A = [0] * (10**5 + 1)
for i in range(1, 10**5 + 1):
    if L[i] and L[(i+1)//2]:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

for i in range(q):
    l, r = map(int, input().split())
    if l == r:
        if L[l] and L[(l+1)//2]:
            print(1)
        else:
            print(0)
    else:
        if L[l] and L[(l+1)//2]:
            print(A[r] - A[l-1])
        else:
            print(A[r] - A[l])
### BUGGY CODE ###

from heapq import heappush, heappop

def main():
    INF = float("inf")

    N, *S = map(int, open(0).read().split())

    S.sort(reverse=True)

    P = [S[0]]
    for _ in range(N):
        Q = P[:]
        while Q:
            q = heappop(Q)

            for i, s in enumerate(S):
                if s < q:
                    heappush(P, s)
                    S[i] = INF
                    break
            else:
                print("No")
                quit()

    print("Yes")


main()


### FIXED CODE ###

INF = float("inf")

N, *S = map(int, open(0).read().split())
M = len(S)

S.sort(reverse=True)

Q = [S[0]]
S[0] = INF
for _ in range(N):
    Q.sort()
    T = Q[:]

    cur = 1
    while Q:
        p = Q.pop()
        while S[cur] >= p:
            cur += 1
            if cur == M:
                print("No")
                exit()
        T.append(S[cur])
        S[cur] = INF

    Q = T

print("Yes")
### BUGGY CODE ###

L, A, B, M = map(int, input().split())

s = [A + B * i for i in range(L)]

ret = 0
for i in range(L) :
    ret = int(str(ret) + str(s[i])) % M

print(ret)

### FIXED CODE ###

L, A, B, M = map(int, input().split())

def mat_pow(x, n) :
    y = [[0] * 3 for _ in range(3)]
        
    for i in range(3) :
        y[i][i] = 1
        
    while n > 0 :
        if n & 1 :
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1
        
    return y
    
def mat_mul(a, b) :
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I) :
        for j in range(J) :
            for k in range(K) :
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= M
    return c

n0 = -(-(10 ** 0 - A) // B)
n1 = -(-(10 ** 1 - A) // B)

ret = [[0], [A], [1]]

for d in range(1, 19) :
    mat = [[10**d, 1, 0], [0, 1, B], [0, 0, 1]]
    if n0 < 0 and 0 < n1 :
        n0 = 0
        
    if 0 <= n0 < n1 :
        ret = mat_mul(mat_pow(mat, n1 - n0), ret)
    n0, n1 = n1, min(-(-(10 ** (d + 1) - A) // B), L)

print(ret[0][0])
### BUGGY CODE ###

n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=0
for i in range(60):
    ichi=0
    for j in range(n):
        if (a[j]>>i)&1:
            ichi+=1
    zero=n-ichi
    s=ichi*zero*pow(2,i,mod)%mod# xorをしたあとi桁目が1になる組み合わせの個数 x 2**i
    ans+=s
    ans%=mod
print(ans)


### FIXED CODE ###

n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=0
for i in range(60):
    ichi=0
    for j in range(n):
        if (a[j]>>i)&1:
            ichi+=1
    zero=n-ichi
    s=ichi*zero*pow(2,i,mod)%mod# xorをしたあとi桁目が1になる組み合わせの個数 x 2**i
    ans+=s
    ans%=mod
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
num_list = list(map(int, input().split(' ')))

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += num_list[i] * num_list[j]

print(ans % (10**9 + 7))

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
num_list = list(map(int, input().split(' ')))

list_sum = sum(num_list)

ans = 0
for i in range(N-1):
    list_sum -= num_list[i]
    ans += num_list[i] * list_sum

print(ans % (10**9 + 7))
### BUGGY CODE ###

from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
listA = list(listA.values())
listA.sort()
times = len(listA) - K
# print(times,len(listA),K)
num = 0

if times <= 0:
    num = 0
else:
    for _ in range(times):
        num += listA.pop(0)

print(num)



### FIXED CODE ###

from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
times = len(listA) - K

num = 0

if times <= 0:
    num = 0
else:
    for i in range(times):
        num += listA[i]

print(num)
### BUGGY CODE ###

from collections import defaultdict
 
n = int(input())
V = defaultdict(list)

for _ in range(n-1):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,c])

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=-1:
                continue
            dist[b[0]] = dist[a] + b[1]
            q.append(b[0])
    return dist

q,k = map(int, input().split())

for i in range(q):
    x,y = map(int,input().split())
    print(dfs(x)[k]+dfs(y)[k])

### FIXED CODE ###

from collections import defaultdict
 
n = int(input())
V = defaultdict(list)

for _ in range(n-1):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,c])

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=-1:
                continue
            dist[b[0]] = dist[a] + b[1]
            q.append(b[0])
    return dist

q,k = map(int, input().split())
dk = dfs(k)

for i in range(q):
    x,y = map(int,input().split())
    print(dk[x]+dk[y])
### BUGGY CODE ###

import sys
from functools import lru_cache
# N = int(input())
X, Y = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)


@lru_cache(maxsize=None)
def solve(x, y):
    if x <= 0 or y <= 0:
        return 0
    if (x, y) == (1, 2) or (x, y) == (2, 1):
        return 1
    return (solve(x-1, y-2) + solve(x-2, y-1)) % (10**9+7)


print(solve(X, Y))



### FIXED CODE ###

import sys
# N = int(input())
X, Y = [int(i) for i in input().split()]
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a_3 = 2 * Y - X
b_3 = 2 * X - Y
if a_3 % 3 != 0 or b_3 % 3 != 0 or a_3 < 0 or b_3 < 0:
    print(0)
    sys.exit(0)
a = a_3//3
b = b_3//3
print(cmb(a+b,a,mod))
### BUGGY CODE ###

def main():
  n = int(input())
  s = input()
  memo = []
  for i in range(10):
    for j in range(10):
      for k in range(10):
        memo.append(str(i) + str(j) + str(k))
  ans = 0
  for i in memo:
    x = 0
    for j in range(n):
      if i[x] == s[j]:
        x += 1
        if x == 3:
          ans += 1
          break

  print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

n = int(input())
s = input()

num = [0,1,2,3,4,5,6,7,8,9]
memo = []
for i in num:
  for j in num:
    for k in num:
      memo.append(str(num[i]) + str(num[j]) + str(num[k]))

ans = 0

for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        break
  if x == 3:
    ans += 1
    
print(ans)
### BUGGY CODE ###

import numpy as np
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=np.array([int(10e8)]*n)

dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])


### FIXED CODE ###

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

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

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

from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << (N + 1))]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state << 1][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1
        stateX <<= 1
        stateY <<= 1

    cx = costX[stateX]
    cy = costY[stateY]

    cost = 0
    for x, y in zip(costX[stateX], costY[stateY]):
        cost += min(x, y)

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

import itertools
n = int(input())
s = input()
p = {i for i in itertools.combinations(s,3)}
print(len(p))


### FIXED CODE ###

n = int(input())
s = input()
ans = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j),a+1)
        if b == -1:
            continue
        for k in range(10):
            if s.find(str(k),b+1) != -1:
                ans += 1
print(ans)
### BUGGY CODE ###

import bisect

def solve():
    N, Q = [int(_) for _ in raw_input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in raw_input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = []
    for i in xrange(Q):
        D.append((int(raw_input()), i))
    STX.sort(key = lambda x:x[2], reverse=True)
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    for i in xrange(N):
        Li, Ri, Xi = STX[i]
        if len(D) == 0:
            break
        it = bisect.bisect_left(D, (Li, -1))
        while it < len(D):
            if D[it][0] >= Ri:
                break
            ans[D[it][1]] = Xi
            it += 1
    for i in xrange(Q):
        print ans[i]

if __name__ == '__main__':
    solve()


### FIXED CODE ###

import bisect

def solve():
    N, Q = [int(_) for _ in raw_input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in raw_input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = []
    for i in range(Q):
        D.append((int(raw_input()), i))
    STX.sort(key = lambda x:x[2])
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    l = [None] * Q
    for i in range(N):
        Li, Ri, Xi = STX[i]
        lit = bisect.bisect_left(D, (Li, -1))
        rit = bisect.bisect_left(D, (Ri, -1))
        while lit < rit:
            if l[lit] is not None:
                lit = l[lit]
            else:
                ans[D[lit][1]] = Xi
                l[lit] = rit
                lit += 1
    for i in range(Q):
        print ans[i]

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

N,K,Q=map(int, input().split())
score=[K]*N
for i in range(Q):
  A = int(input())
  score[A-1]+=1
  score = [x-1 for x in score]
  
for i in range(N):
  if score[i] > 0:
    print('Yes')
    
  else:
    print('No')

### FIXED CODE ###

N,K,Q=map(int, input().split())
score=[K-Q]*N
for i in range(Q):
  A = int(input())
  score[A-1]+=1
  
for i in range(N):
  if score[i] > 0:
    print('Yes')
    
  else:
    print('No')
### BUGGY CODE ###

import numpy as np

def main():
  n=int(input())
  s=np.array([ord(i) for i in input()])
  dp=np.zeros((n,n),dtype=int)
  for i in range(n-1):
    for j in range(i+1,n):
      if s[i]==s[j]:
        dp[i,j]=min(j-i, dp[i-1,j-1]+1)
  print(np.amax(dp))
        

if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  n=int(input())
  s=input()
  dp=[[0]*(n+1) for i in range(n+1)]
  for i in range(n-1,-1,-1):
    for j in range(n-1,i,-1):
      if s[i]==s[j]:
        dp[i][j]=dp[i+1][j+1]+1
  #for i in dp:
  #  print(i)
  
  ans=0
  for i in range(n-1):
    for j in range(i+1,n):
      ans=max(ans,min(j-i,dp[i][j]))
  print(ans)      
        

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

import numpy as np
N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

kernel = [1] * K
est = (p + 1) / 2

est_k = np.convolve(est, kernel)
print(np.max(est_k))

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

p.insert(0, 0)
for i in range(1, N+1):
    p[i] = (p[i] + 1) / 2 + p[i-1]

s = [0] * (N+1)
for i in range(N-K+1):
    s[i] = p[i+K] - p[i]

print(max(s))