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

#!/usr/bin/env python3
input()
d = input().split()
input()
t = input().split()
a = sum(d.count(i) < t.count(i) for i in set(t))
print("YNEOS"[a > 0::2])


### FIXED CODE ###

#!/usr/bin/env python3
from collections import Counter
input()
d = Counter(input().split())
input()
t = Counter(input().split())
for k, v in t.items():
    if k not in d or d[k] < v:
        print("NO")
        exit()
print("YES")
### BUGGY CODE ###

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

P = 0
for i in range(n-k+1):
  sp = p[i:i+k].sum()
  if P < sp:
    P = sp
    mp = p[i:i+k]

ans = 0
for i in mp:
  j = i//2
  if i%2 == 0:
    ans += ((i+1)*j)/i
  else:
    ans += ((i+1)*j + j + 1)/i

print(ans)


### FIXED CODE ###

from itertools import accumulate
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))

P = list(accumulate([(i+1)/2 for i in p]))
P = [0] + P
ans = max([P[i+k]-P[i] for i in range(n-k+1)])
print(ans)
### BUGGY CODE ###

n = int(input())
S = input()

ans = 0
for i in range(1000):
    a = '{0:03d}'.format(i)
    f1, f2 = False, False
    for s in S:
        if not f1 and s == a[0]:
            f1 = True
            continue
        if f1 and not f2 and s == a[1]:
            f2 = True
            continue
        if f1 and f2 and s == a[2]:
            ans += 1
            break

print(ans)


### FIXED CODE ###

n = int(input())
S = input()

ans = 0
for i in range(1000):
    a = '{0:03d}'.format(i)
    if a[0] in S:
        idx1 = S.index(a[0])
        S1 = S[idx1+1:]
        if a[1] in S1:
            idx2 = S1.index(a[1])
            S2 = S1[idx2+1:]
            if a[2] in S2:
                ans += 1

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

n=int(input())
if n==1:
    print(1)
else:
    l=[int(i) for i in input().split()]
    l.sort()
    d=dict()
    for i in l:
        d[i]=True
    res=0
    for i in range(n):
        if d[l[i]]:
            if i==n-1 or (i<n-1 and l[i]!=l[i+1]):
                res+=1
            for j in range(i+1,n):
                if not l[j]%l[i]:
                    d[l[j]]=False
    print(res)



### FIXED CODE ###

n=int(input())
if n==1:
    print(1)
else:
    oklist=[True for i in range(1000001)]
    l=[int(i) for i in input().split()]
    l.sort()
    res=0
    for i in range(n):
        if oklist[l[i]]:
            if i==n-1 or (i<n-1 and l[i]!=l[i+1]):
                res+=1
            for j in range(1,1000001):
                if l[i]*j<=1000000:
                    oklist[l[i]*j]=False
                else:
                  break
    print(res)
### BUGGY CODE ###

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =[0]*(N-1)
L.insert(0,1)
T.insert(0,int(P[0]))
for i in range(len(P)):
  P[i] = int(P[i])
for i in  range(1,len(P)):
  if P[i]<=P[i-1]:
    if min(T)>P[i]:
      L[i] = 1
    T.append(P[i])
print(L.count(1))

### FIXED CODE ###

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =0
T.insert(0,int(P[0]))
P[0] = int(P[0])
for i in  range(1,len(P)):
  P[i] = int(P[i])
  if T[-1]>=P[i]:
    L =+ 1
    if T[-1]>P[i]:
      T.append(P[i])
print(len(T))
### BUGGY CODE ###


a,b,k = map(int,input().split())

while k > 0:
    if a > 0:
        a -= 1
        k -= 1
    else:
        b -= 1
        k -= 1
print(a,b)


### FIXED CODE ###


a,b,k = map(int,input().split())

if a + b <= k:
    print(0,0)
elif a >= k:
    print(a-k,b)
elif a < k:
    print(0,b-(k-a))


"""
while k > 0:
    if a > 0:
        a -= 1
        k -= 1
    else:
        b -= 1
        k -= 1
print(a,b)
"""
### BUGGY CODE ###

N, Q = input().split(' ')
N = int(N)
Q = int(Q)
S = input()
for i in range(Q):
    l_i, r_i = input().split(' ')
    l_i = int(l_i)
    r_i = int(r_i)
    print(S[l_i-1:r_i].count('AC'))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l_i, r_i = map(int, input().split())
    print(t[r_i-1] - t[l_i-1])
### BUGGY CODE ###

N = int(input())
S = input()
exc = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            exc += 1

ans = S.count("R") * S.count("G") * S.count("B") - exc
print(ans)


### FIXED CODE ###

N = int(input())
S = [s for s in 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 + (j - i)
        if N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            ans -= 1

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

A = list(input())
n = len(A)

count = 0
for _ in range(n):
    for i in reversed(range(1, n)):
        if  A[i-1] == 'B' and A[i] == 'W':
            A[i] = 'B'
            A[i-1] = 'W'
            count += 1

print(count)


### FIXED CODE ###

A = list(input())

count = 0
ans = 0
for a in A:
    if a == 'B':
        count += 1
    else:
        ans += count

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

from math import sqrt
A, B = map(int, input().split())

n = max(A,B)
ans = 1
for p in range(2,n+1):
    if A%p==0 and B%p==0:
        ans += 1
        while A%p==0 and B%p==0:
            A = A//p
            B = B//p
    if A==1 or B==1:
        break
print(ans)

### FIXED CODE ###

from math import sqrt
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
    
A, B = map(int, input().split())

g = gcd(A, B)
n = int(sqrt(g))+1
ans = 1
for p in range(2,n+1):
    if g%p==0:
        ans += 1
        while g%p==0:
            g = g//p
if g!=1:
    ans += 1

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

from collections import Counter 
import math

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

N = int(input())
A = list(map(int,input().split()))
P = list(set(A))
P.sort()
li = Counter(A).most_common()
S = sum(comb(li[i][1],2) for i in range(len(li)) if li[i][1]>=2)
for i in A:
    ans = S
    IDX = P.index(i)
    if li[IDX][1]>2:
        ans -= comb(li[IDX][1],2)-comb(li[IDX][1]-1,2)
    elif li[IDX][1]==2:
        ans -= 1
    print(ans)

### FIXED CODE ###

from collections import Counter
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
A = list(map(int,input().split()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)
### BUGGY CODE ###

import itertools

N = int(input())

ans = [0 for _ in range(1,N+1)]

for v in itertools.combinations_with_replacement(range(1,(N//6)+1), 3):
    x,y,z = v
    count = 0
    if x == y == z:
        fn = 6 * x * x
        count = 1
    else:
        fn = x*x + y*y + z*z + x*y + y*z + z*x
        count = 3
    if N >= fn:
        ans[fn-1] += count

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

### FIXED CODE ###

N = int(input())
ans = [0 for _ in range(1,10101)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x + y*y + z*z + x*y + y*z + z*x
            if n < N+1:
                ans[n-1] += 1

print(*ans[:N],sep='\n')
### BUGGY CODE ###

import sys
from collections import Counter
read = sys.stdin.buffer.read
n, *lst = map(int, read().split())

def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]


al = lst[:n]
bl = lst[n:]
a = convert(al)
b = convert(bl)
if Counter(a)!=Counter(b):
  quit()
alal, aa = al + al, a + a
for k in range(n):
    tmp = aa[k:n + k]
    for i, j in zip(tmp, b):
        if i != j:
            break
    else:
        x = alal[k] ^ bl[0]
        print(k, x)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())

A = list(map(int, readline().split()))
B = list(map(int, readline().split()))


def convert(A):
    return [x ^ y for x, y in zip(A, A[1:])] + [A[-1] ^ A[0]]


C = convert(A)
D = convert(B)


def Z_algorithm(S):
    # 共通接頭辞の長さを返す
    N = len(S)
    arr = [0] * N
    arr[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        arr[i] = j
        if not j:
            i += 1
            continue
        k = 1

        while i + k < N and k + arr[k] < j:
            k += 1
        i += k
        j -= k

    return arr


Z = Z_algorithm(D + [-1] + C + C)[N + 1:N + N + 1]

K = [i for i, x in enumerate(Z) if x == N]
X = [A[k] ^ B[0] for k in K]

print('\n'.join('{} {}'.format(k, x) for k, x in zip(K, X)))
### BUGGY CODE ###

import math

q = int(input())

s = [i for i in range(2,100001) if i%2!=0 and i%3!=0 and i%5!=0]
sosu = [2,3,5]
while math.sqrt(100000) <= s[0]:
    sosu.append(s[0])
    for s_num in range(s[0],s[-1]+1,s[0]):
        if s_num in s:
            s.remove(s_num)
sosu = sosu + s
            
for i in range(q):
    l,r = map(int,input().split())
    ans = 0
    for j in range(l,r+1,2):
        if j in sosu and (j+1)//2 in sosu:
            ans += 1
    print(ans)
        


### FIXED CODE ###

import math

q = int(input())

def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(math.sqrt(a)+1)):
        if a%i == 0:
            return False
    else:
        return True

s = [0 for i in range(0,100001)]
for i in range(3,100001,2):
    if is_prime(i) and is_prime((i+1)//2):
        s[i] = 1

s2 = [0 for i in range(0,100001)]
tmp = 0
for i in range(100001):
    tmp += s[i]
    s2[i] = tmp

for i in range(q):
    l,r = map(int,input().split())
    ans = s2[r] - s2[l-1]
    print(ans)
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
import numpy as np

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

queue = deque()

vert = np.array([[0 for j in range(w)] for i in range(h)])
hori = np.array([[0 for j in range(w)] for i in range(h)])

h_start = 0
h_val = 0
v_start = 0
v_val = 0

for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            h_val += 1
            if j == w-1:
                hori[i,h_start:w] += h_val
                h_val = 0
                h_start = 0
        else:
            hori[i,h_start:j] += h_val
            h_val = 0
            h_start = (j+1)%(w)

for j in range(w):
    for i in range(h):
        if maze[i][j] == '.':
            v_val += 1
            if i == h-1:
                vert[v_start:h,j] += v_val
                v_val = 0
                v_start = 0
        else:
            vert[v_start:i,j] += v_val
            v_val = 0
            v_start = (i+1)%(h)


sum_ = hori + vert - 1

print(np.max(sum_))


### FIXED CODE ###


from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

queue = deque()

left = [[0 for j in range(w)] for i in range(h)]
right = [[0 for j in range(w)] for i in range(h)]
up = [[0 for j in range(w)] for i in range(h)]
down = [[0 for j in range(w)] for i in range(h)]

cnt = 0

for i in range(h):
    cnt = 0
    for j in range(w):
        if maze[i][j] == '#': cnt = 0
        else:
            cnt += 1
            left[i][j] = cnt

    cnt = 0
    for j in reversed(range(w)):
        if maze[i][j] == '#': cnt = 0
        else:
            cnt += 1
            right[i][j] = cnt


for j in range(w):
    cnt = 0
    for i in range(h):
        if maze[i][j] == '#': cnt = 0
        else:
            cnt += 1
            up[i][j] = cnt

    cnt = 0
    for i in reversed(range(h)):
        if maze[i][j] == '#': cnt = 0
        else:
            cnt += 1
            down[i][j] = cnt

ans = 0
for i in range(h):
    for j in range(w):
        tmp = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        ans = max(tmp, ans)

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

from collections import deque


# 幅優先と深さ優先でトポロジカルソート
def set_indeg(u):
    # t = uとなる数を求める。
    ans = 0
    for line in G:
        if line[u] == 1:
            ans += 1
    return ans


def topologicalSortBfs(n):
    for i in range(n):
        color[i] = WHITE
        indeg[i] = set_indeg(i)

    for i in range(0, n):
        if indeg[i] == 0 and color[i] == WHITE:
            bfs(i)


def bfs(s):
    Q.appendleft(s)
    color[s] = GRAY
    while Q:
        u = Q.popleft()

        out.append(u)

        for v in range(n):
            if G[u][v] != 1:
                continue
            indeg[v] -= 1
            if indeg[v] == 0 and color[v] == WHITE:
                color[v] = GRAY
                Q.append(v)


def topologicalSortDfs(n):
    for i in range(n):
        color[i] = WHITE
        indeg[i] = set_indeg(i)

    for s in range(0, n):
        if color[s] == WHITE:
            dfs(s)


def dfs(u):
    color[u] = GRAY
    for v in range(n):
        if color[v] == WHITE and G[u][v] == 1:
            dfs(v)
    out.appendleft(u)


n, e = map(int, input().split())
G = [[0] * n for _ in range(n)]
for i in range(e):
    s, t = map(int, input().split())
    G[s][t] = 1
color = [None] * n
out = deque([])
indeg = [None] * n
WHITE = 0
GRAY = 1
Q = deque([])

topologicalSortDfs(n)
print(*out)
# 031452
# dfsがおかしい



### FIXED CODE ###

from collections import deque


# 幅優先と深さ優先でトポロジカルソート


def topologicalSortBfs(n):
    for i in range(n):
        color[i] = WHITE

    for i in range(0, n):
        if indeg[i] == 0 and color[i] == WHITE:
            bfs(i)


def bfs(s):
    Q.appendleft(s)
    color[s] = GRAY
    while Q:
        u = Q.popleft()

        out.append(u)

        for v in G[u]:
            indeg[v] -= 1
            if indeg[v] == 0 and color[v] == WHITE:
                color[v] = GRAY
                Q.append(v)


def topologicalSortDfs(n):
    for i in range(n):
        color[i] = WHITE

    for s in range(0, n):
        if color[s] == WHITE:
            dfs(s)


def dfs(u):
    color[u] = GRAY
    for v in G[u]:
        if color[v] == WHITE:
            dfs(v)
    out.appendleft(u)


n, e = map(int, input().split())
G = {}
for i in range(n):
    G[i] = []
indeg = [0] * n
for i in range(e):
    s, t = map(int, input().split())
    indeg[t] += 1
    G[s].append(t)
color = [None] * n
out = deque([])
WHITE = 0
GRAY = 1
Q = deque([])

topologicalSortDfs(n)
print(*out)
# 031452
# dfsがおかしい
### BUGGY CODE ###

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = int('7'*len(str(K)))

while True:
    if x % K == 0:
        print(len(str(x)))
        exit()
    x = x * 10 + 7


### FIXED CODE ###

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()
### BUGGY CODE ###

N, M, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(Q)]
List = sorted(X)  
ans = 0
for i in range(2**Q):
  sum = 0
  A = [0 for _ in range(N)]
  for j in range(Q):
    if ((i >> j) & 1) and A[List[j][0]-1] != 0 and A[List[j][1]-1] != 0: #値入ってる
      if A[List[j][1]-1] - A[List[j][0]-1] == List[j][2]:
        sum += List[j][3]
      else:
        break
    elif ((i >> j) & 1) and A[List[j][0]-1] != 0 and A[List[j][1]-1] == 0: #aだけ値入ってる
      A[List[j][1]-1] = A[List[j][0]-1] + List[j][2] #値決める
      if A[List[j][1]-1] > M:
        break
      else:
        sum += List[j][3]
    elif ((i >> j) & 1) and A[List[j][0]-1] == 0 and A[List[j][1]-1] == 0: #値入ってない
      A[List[j][0]-1] = 1
      A[List[j][1]-1] = 1 + List[j][2] #値決める
      sum += List[j][3]
  else:
    if ans < sum:
      ans = sum
print(ans)

### FIXED CODE ###

N, M, Q =  map(int, input().split())
List = [list(map(int, input().split())) for _ in range(Q)]
A = [1 for _ in range(N)]
ans = 0

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

def new_A(A):
  for i in range(N):
    if A[N-i-1] < M:
      A[N-i-1] += 1
      break
    elif A[N-i-1] == M and A[N-i-2] < M:
      A[N-i-2] += 1
      for x in range(N-i-1, N):
        A[x] = A[N-i-2]
      break
  return A

for j in range(cmb(N+M-1, N)):
  sum = 0
  for k in range(Q):
    if A[List[k][1]-1] - A[List[k][0]-1] == List[k][2]:
      sum += List[k][3]
  if ans < sum:
    ans = sum
  A = new_A(A)
print(ans)
### BUGGY CODE ###

from sys import setrecursionlimit


def f(i, links, dp):
    if dp[i] != -1:
        return dp[i]
    if len(links[i]) == 0:
        dp[i] = 0
    else:
        dp[i] = max(f(j, links, dp) for j in links[i]) + 1
    return dp[i]


setrecursionlimit(10 ** 6)

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

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

dp = [-1] * N
print(max(f(i, links, dp) for i in range(N)))


### FIXED CODE ###

from sys import setrecursionlimit


def f(i, links, dp):
  if dp[i] != -1:
    return dp[i]
  if len(links[i]) == 0:
    dp[i] = 0
  else:
    dp[i] = max(f(j, links, dp) for j in links[i]) + 1
  return dp[i]


setrecursionlimit(1000000)

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

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

dp = [-1] * N
print(max(f(i, links, dp) for i in range(N)))
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

cnt = [[10 ** 10] * w for _ in range(h)]
visited = [[0] * w for _ in range(h)]
queue = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            cnt[i][j] = 0
            queue.append([i, j])
            visited[i][j] = 1

def bfs(q, v, c):
    while q:
        y, x = q.popleft()
        for i, j in ([0, 1], [1, 0], [-1, 0], [0, -1]):
            ny = y + i
            nx = x + j
            if 0 <= nx < w and 0 <= ny < h and v[ny][nx] == 0:
                c[ny][nx] = c[y][x] + 1
                v[ny][nx] = 1
                q.append([ny, nx])

bfs(queue, visited, cnt)

ans = 0
for i in range(h):
    ans = max(ans, max(cnt[i]))
print(ans)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

cnt = [[10 ** 10] * w for _ in range(h)]
visited = [[0] * w for _ in range(h)]
queue = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            cnt[i][j] = 0
            queue.append([i, j])
            visited[i][j] = 1

def bfs(q, v, c):
    while q:
        y, x = q.popleft()
        for i, j in ([0, 1], [1, 0], [-1, 0], [0, -1]):
            ny = y + i
            nx = x + j
            if 0 <= nx < w and 0 <= ny < h and v[ny][nx] == 0:
                c[ny][nx] = c[y][x] + 1
                v[ny][nx] = 1
                q.append([ny, nx])

bfs(queue, visited, cnt)

ans = 0
for i in range(h):
    ans = max(ans, max(cnt[i]))
print(ans)
### BUGGY CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [[0 for i in range(S+1)] for j in range(N+1)]
L[0][0] = 1
for j, a in enumerate(A):
  for i in range(S+1):
    if i < a:
      L[j+1][i] = (2 * L[j][i]) % mod
    else:
      L[j+1][i] = (2 * L[j][i] + L[j][i-a]) % mod
print(L[N][S])

### FIXED CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [[0 for i in range(S+1)] for j in range(N+1)]
L[0][0] = 1
for j, a in enumerate(A):
  for i in range(S+1):
    if i < a:
      L[j+1][i] = (2 * L[j][i]) % mod
    else:
      L[j+1][i] = (2 * L[j][i] + L[j][i-a]) % mod
print(L[N][S])
### BUGGY CODE ###

s = input()
k = int(input())

alphabet = "abcdefghijklmnopqrstuvwxyz"
candidates = []

for i in range(len(alphabet)):
  key = alphabet[i]
  count = s.count(key)
  if count > 0:
    index = 0
    for j in range(count):
      index = s.find(key, index)
      for i in range(index, len(s) + 1):
        if not s[index:i] in candidates and len(s[index:i]) > 0:
          candidates += [s[index:i]]
      index += 1
  if len(candidates) >= k:
    break

candidates.sort()
print(candidates[k - 1])

### FIXED CODE ###

s = input()
k = int(input())

#alphabet = "abcdefghijklmnopqrstuvwxyz"
candidates = []

for i in range(len(s)):
  for j in range(i + 1, len(s) + 1):
    if not s[i:j] in candidates:
      candidates += [s[i:j]]
    if len(s[i:j]) >= k:
      break

candidates.sort()
print(candidates[k - 1])
### BUGGY CODE ###

N = int(input())
from collections import Counter
A = []
for i in range(N):
  A.append(int(input()))

sorted_A = sorted(A, reverse=True)  
for a in A:
  tmp_A = list(sorted_A)
  tmp_A.remove(a)
  print(tmp_A[0])

### FIXED CODE ###

N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)
### BUGGY CODE ###

import collections
import copy

n = int(input())
al = [int(x) for x in input().split()]
ccc = collections.Counter
cs_orig = dict(ccc(al))
copy_copy = copy.copy

aset = set(al)
patterns_d = {}

for i in range(1, n+1):
    cs = copy_copy(cs_orig)
    patterns = 0
    if i in aset:
        cs[i] -= 1

        cscs = dict(ccc(cs.values()))
        for k, v in cscs.items():
            if k > 1:
                patterns += (int(k * (k-1) / 2)) * v

        patterns_d[i] = patterns

for a in al:
    print(patterns_d[a])


### FIXED CODE ###

import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]
### BUGGY CODE ###

s = input()
t = input()

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

res = ""
i = len(s)
j = len(t)
while i>0 and j>0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = s[i-1] + res
        i -= 1
        j -= 1
print(res)

### FIXED CODE ###

s = input()
t = input()

x = len(s)
y = len(t)
dp = [[0]*(y+1) for _ in range(x+1)]

for i in range(x):
    for j in range(y):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

res = ""
while x>0 and y>0:
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        res = s[x-1] + res
        x -= 1
        y -= 1
print(res)
### BUGGY CODE ###

if __name__ == '__main__':
    s = list(input())
    s.reverse()
    n = len(s)
    now = 0
    mods = [0] * 2019
    for i in range(n):
        now += (10 ** i) * int(s[i])
        mods[now % 2019] += 1
    ans = mods[0]
    for i in mods:
        ans += (i * (i - 1)) // 2
    print(ans)


### FIXED CODE ###

if __name__ == '__main__':

    s = list(input())
    s.reverse()
    n = len(s)
    now = 0
    mods = [0] * 2019
    mods[0] += 1
    ten = 1
    for i in range(n):
        now += ten * int(s[i])
        now %= 2019
        ten *= 10
        ten %= 2019
        mods[now] += 1
    ans = 0
    for i in mods:
        ans += (i * (i - 1)) // 2
    print(ans)