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

s = input()
if len(s) <= 4 and int(s) != 2019 and int(s) < 4038:
    print(0)
elif len(s) <= 4 and int(s) == 2019:
    print(1)
else:
    count = 0
    for i in range(len(s)-3):
        for j in range(4,len(s)+1):
            x = s[i:j]
            if x != "" and int(x) % 2019 == 0:
                count += 1
    print(count)

### FIXED CODE ###

s = input()
mod = 2019
mod_lst = [0]*mod
mod_lst[0] =1
x = 0
t = 1
for i in reversed(s):
    x += int(i) * t
    y = x % mod
    t *= 10
    t %= mod
    mod_lst[y] += 1


count = 0
for j in mod_lst:
    a = j*(j-1)//2
    count += a
print(count)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
L = []
for i in range(N-1):
    if H[i] >= H[i+1]:
        L.append(1)
    else:
        L.append(0)
L = [0] + L + [0]
if 1 in L:
    a = 1
    nn = 0
    for i in range(a,N):
        n = 0
        for j in range(i+1,N+1):
            if L[j] == 1:
                n += 1
            else:
                a = j
                nn = max(nn,n)
                break
    print(nn)
else:
    print(0)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
c = 0
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        c += 1
    else:
        c = 0
    ans = max(ans,c)
print(ans)
### BUGGY CODE ###

s=input()
n=len(s)
while True:
    t=s.replace('01','').replace('10','')
    if t==s:
        break
    else:
        s=t
print(n-len(t))

### FIXED CODE ###

from collections import Counter
s=input()
if len(set(s))==1:
    print(0)
else:
    c=Counter(s).most_common()
    print(c[1][1]*2)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
A = list([0] * N)   # A yen
B = list([0] * N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

bought = 0
price = 0
while(M > bought):
#    print("bought = {}, price = {}".format(bought, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    if(M - bought >= B[minidx]):
#        print("buy = {}, price = {}".format(B[minidx], A[minidx]))
        price = price + A[minidx] * B[minidx]
        bought = bought + B[minidx]
    elif(M - bought < B[minidx]):
#        print("buy = {}, price = {}".format(M - bought, A[minidx]))
        price = price + A[minidx] * (M - bought)
        bought = M
    del A[minidx]
    del B[minidx]

print(price)


### FIXED CODE ###

YEN = 0
NUM = 1

N, M = list(map(int, input().split()))
shop = list([])
for i in range(N):
    a, b = list(map(int, input().split()))
    shop.append([a, b])
shop.sort()

require = M
price = 0
minidx = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)
### BUGGY CODE ###

a=input()
N,K=int(a.split()[0]),int(a.split()[1])
b=input().split()
list=list(map(int, b))

if (K>=len(list)):
  print(0)
else:
  for i in range(K):
    list.remove(max(list))
  print(sum(list))

### FIXED CODE ###

a=input()
N,K=int(a.split()[0]),int(a.split()[1])
b=input().split()
list=list(map(int, b))

if (K>=len(list)):
  print(0)
else:
  print(sum(sorted(list, reverse=True)[K:]))
### BUGGY CODE ###

from collections import deque

import numpy as np
import sys
#input = sys.stdin.readline

sys.setrecursionlimit(5000)

def get_adj_tiles(v):
    i, j = v
    res = [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]
    return res

def bfs(point):
    visited = []
    que = deque()
    que.append((point, 1))
    
    while len(que) > 0:
        v, depth = que.popleft()
        visited.append(v)
        adjs = get_adj_tiles(v)
        for a in adjs:
            if field[a[0]][a[1]] == '.' and a not in visited:
                if a == (H, W):
                    return depth + 1
                else:
                    que.append((a, depth+1))
        if len(que) == 0:
            return 0

H, W = list(map(int, input().split()))
field = [['#'] * (W + 2) for _ in range(H + 2)]
for i in range(H):
    values = list(input())
    field[i+1][1:-1] = values
    
number_of_whites = 0
for i in range(H+2):
    for j in range(W+2):
        if field[i][j] == '.':
            number_of_whites += 1
shortest_path = bfs((1, 1))
if shortest_path > 0:
    print(number_of_whites - shortest_path)
else:
    print(-1)

### FIXED CODE ###

H, W = list(map(int, input().split()))
M = [[-1]*(W+2)]
ans = 0
for _ in range(H):
    s = input()
    ans += s.count('.')
    M.append([-1]+[0 if c=='.' else -1 for c in s]+[-1])
M += [[-1]*(W+2)]

queue = [(1,1)]
M[1][1] = 1
dr = [(+1,0),(-1,0),(0,+1),(0,-1)]
turn = 1
while len(queue)>0:
    turn += 1
    queue_new = []
    for qx, qy in queue:
        for dx, dy in dr:
            x, y = qx+dx, qy+dy
            if M[y][x]==0:
                M[y][x] = turn
                queue_new.append((x,y))
    queue = queue_new

print(ans-M[H][W] if M[H][W]>0 else -1)
### BUGGY CODE ###

list = []
n = int(input())
for i in range(n):
    list.append(int(input()))

for j in range(n):
    a = list.pop(j)
    print(max(list))
    list.insert(j,a)

### FIXED CODE ###

import copy
list = []
n = int(input())
for i in range(n):
    list.append(int(input()))
list2 = copy.deepcopy(list)
maxsize = max(list)
list2.sort(reverse=True)
max_second = list2[1]
maxsecond = list2[1]
for j in range(n):
    a = list[j]
    if a == maxsize:
        print(maxsecond)
    else:
        print(maxsize)
### BUGGY CODE ###

import math
import itertools
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

a = int(input())
list_a = [i for i in range(1, a + 1)]
res = 0
kumi = list(itertools.product(list_a, repeat=3))
for i in kumi:
    ans = gcd_list(i)
    res += ans

print(res)

### FIXED CODE ###

import math
import itertools
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

a = int(input())
list_a = [i for i in range(1, a + 1)]
res = 0
# kumi = list(itertools.product(list_a, repeat=3))
kumi = list(itertools.combinations_with_replacement(list_a, 3))
for i in kumi:
    ans = gcd_list(i)
    if i[0] == i[1] and i[0] == i[2]:
        res += ans
    elif i[0] != i[1] and i[0] != i[2] and i[2] != i[1]:
        res += ans*6
    elif i[0] == i[1] or i[0] == i[2] or i[1] == i[2]:
        res += ans*3

print(res)
### BUGGY CODE ###

sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx,sy,0)]
for i in range(n):
    data.append(tuple(map(int,input().split())))
data.append((gx,gy,0))
for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=((data[i][0]-data[j][0])**2+(data[i][1]-data[j][1])**2)**0.5-data[i][2]-data[j][2]
        if tmp<0:
            tmp=0
        g[i].append((tmp,j))
        g[j].append((tmp,i))

from heapq import heappush, heappop, heapify
dist=[2828427127 for i in range(len(g))]
dist[0]=0
que=[]
heappush(que,(0,0))
while que:
    c,v=heappop(que)
    if dist[v]<c:
        continue
    for i in range(len(g[v])):
        tmp=g[v][i][0]+c
        if tmp<dist[g[v][i][1]]:
            dist[g[v][i][1]]=tmp
            heappush(que,(tmp,g[v][i][1]))
print(dist[n+1])


### FIXED CODE ###

from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx+sy*1j,0)]
for i in range(n):
    a,b,c=map(int,input().split())
    data.append((a+b*1j,c))
data.append((gx+gy*1j,0))

for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=abs(data[i][0]-data[j][0])-data[i][1]-data[j][1]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(n+2)]
visited=[False for i in range(n+2)]
dist[0]=0
que=[]
heappush(que,(0,0))

while que:
    c,v=heappop(que)
    if visited[v]:
        continue
    visited[v]=True
    for x in g[v]:
        if visited[x[1]]:
            continue
        tmp=x[0]+c if not x[0]<0 else c
        if tmp<dist[x[1]]:
            dist[x[1]]=tmp
            heappush(que,(tmp,x[1]))
print(dist[n+1])
### BUGGY CODE ###

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

ok = 0
ng = N // 2 + 1

while ng - ok > 1:
    m = (ok + ng) // 2
    if any([S[i : i + m] in S[i + m :] for i in range(N - 2 * m + 1)]):
        ok = m
    else:
        ng = m

print(ok)

### FIXED CODE ###

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

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            tmp = 1
            if i > 0:
                tmp += dp[i - 1][j - 1]
            if j - i < tmp:
                continue
            dp[i][j] = tmp
        ans = max(ans, dp[i][j])
print(ans)
### BUGGY CODE ###

texts = list(str(input()))
Q = int(input())


reverse = False

for _ in range(Q):
    input_text = list(input().split())
    if len(input_text) == 1:
        texts = texts[::-1]
    else:
        if input_text[1] == '1':
            texts.insert(0, input_text[2])
        else:
            texts.append(input_text[2])

print(''.join(texts))


### FIXED CODE ###

from collections import deque
texts = deque(str(input()))
Q = int(input())


reverse = False
start_text = deque('')
end_text = deque('')
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text.append(str(input_text[2]))
            else:
                start_text.appendleft(str(input_text[2]))
        else:  # 末尾に
            if reverse:
                start_text.appendleft(input_text[2])
            else:
                end_text.append(input_text[2])

# print(start_text, texts, end_text)
# print(''.join(texts))

texts.appendleft(''.join(start_text))
texts.append(''.join(end_text))
# print(''.join(texts))

# print(texts)
if reverse:
    texts = deque("".join(texts))
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(''.join(texts))
### BUGGY CODE ###

# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
Slen = len(S)

ans = 0
if len(S)<=3:
    print(0)
    exit()
for num_s in range(4,Slen+1):
    for i in range(Slen - num_s + 1):
        num = int(S[i:i+num_s])
        if num%2019 == 0:
            ans += 1

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()[::-1]

MOD = 2019
tmp = [0]*MOD
tmp[0] += 1
tens = 1
num = 0
for s in S:
    num += int(s) * tens
    num = num % MOD
    tmp[num] += 1
    tens *= 10
    tens %= MOD

ans = 0
for i in tmp:
    ans += i*(i-1)//2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
### BUGGY CODE ###

N = int(input())
a = list(map(int,(input().split())))
ans = 1
for i in range(N):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int,(input().split())))
ans = 1
if 0 in a:
    print(0)
else:
    for i in range(N):
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)
### BUGGY CODE ###

from functools import reduce
S = list(map(int,input().rstrip()))
result=0
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        n = reduce( lambda a,b:10*a+b, S[i:j])
        if n %2019==0:
            result+=1
print(result)

### FIXED CODE ###

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        #print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
    aa = map(int, raw_input().split())
    for j in range(n):
        a[i + 1][j + 1] = a[i][j + 1] + a[i + 1][j] - a[i][j] + aa[j]
m = -10000 * 100 * 100
for i in range(n):
    for j in range(n):
        for k in range(i + 1, n + 1):
            for l in range(j + 1, n + 1):
                r = a[k][l] - a[k][j] - a[i][l] + a[i][j]
                m = max(m, r)
print m

### FIXED CODE ###

n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
m = -10000 * 100 * 100

for i in range(n):
    b = map(int, raw_input().split())
    for j in range(n):
        aa = 0
        for k in range(j, n):
            aa += b[k]
            a[j][k] = max(a[j][k], 0) + aa
            m = max(m, a[j][k])
print m
### BUGGY CODE ###

from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)
G[X - 1].append(Y - 1)
G[Y - 1].append(X - 1)

L = [0] * N
for i in range(N - 1):
    dist = [N] * N
    dist[i] = 0
    Q = deque()
    Q.append(i)
    while len(Q) > 0:
        q = Q.popleft()
        for j in G[q]:
            if dist[j] != N:
                continue
            dist[j] = min(dist[q] + 1, dist[j])
            Q.append(j)
    for k in range(i, N):
        if dist[k] != N and dist[k] != 0:
            L[dist[k]] += 1
for i in range(1, N):
    print(L[i])

### FIXED CODE ###

from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)
G[X - 1].append(Y - 1)
G[Y - 1].append(X - 1)

L = [0] * N
for i in range(N - 1):
    dist = [N] * N
    dist[i] = 0
    Q = deque()
    Q.append(i)
    while len(Q) > 0:
        q = Q.popleft()
        for j in G[q]:
            if dist[j] != N:
                continue
            dist[j] = min(dist[q] + 1, dist[j])
            Q.append(j)
    for k in range(i, N):
        if dist[k] != N and dist[k] != 0:
            L[dist[k]] += 1
for i in range(1, N):
    print(L[i])
### BUGGY CODE ###

def main():
    S = input()
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S += tmp[2]
                else:
                    S = tmp[2] + S
            else:
                if revFlag:
                    S = tmp[2] + S
                else:
                    S += tmp[2]
    if revFlag:
        print(S[::-1])
    else:
        print(S)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():
    S = deque(input())
    Q = int(input())
    revFlag = False
    for i in range(Q):
        tmp = list(input().split())
        if tmp[0] == "1":
            if revFlag:
                revFlag = False
            else:
                revFlag = True
        else:
            if tmp[1] == "1":
                if revFlag:
                    S.append(tmp[2])
                else:
                    S.appendleft(tmp[2])
            else:
                if revFlag:
                    S.appendleft(tmp[2])
                else:
                    S.append(tmp[2])
    if revFlag:
        S = list(S)
        S.reverse()
        print("".join(S))
    else:
        S = list(S)
        print("".join(S))


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

N = int(input())
A = list(input().split())
while A!=[]:
    a = A.pop()
    if a in A:
        print('NO')
        exit()
print('YES')

### FIXED CODE ###

N = int(input())
A = list(input().split())
A.sort()
for i in range(N-1):
    if A[i]==A[i+1]:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

# E
import fractions
N = int(input()) 
A = list(map(int, input().split()))

value = A[0]
for i in range(1, N):
    value = value * A[i] // fractions.gcd(value, A[i])

ans = 0
for i in A:
    ans += (value//i) % (10**9+7)

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

### FIXED CODE ###

# E
from fractions import gcd

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

value = 1
for a in A:
    value = value * a // gcd(value, a)

mod = 10**9+7

ans = 0
for i in A:
    ans += value // i

print(ans%mod)
### BUGGY CODE ###

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

def c(n,k):
    return n * (n-1) / k

pair_len = c(n,2)

minus_num = len([i for i in a_list if i < 0])
plus_num = len([i for i in a_list if i > 0])
zero_num = n - minus_num - plus_num

minus_len = minus_num * plus_num
plus_len = c(minus_num,2) + c(plus_num,2)
zero_len = int(pair_len - minus_len - plus_len)

if k <= minus_len:
    #-1つ,+1つ
    minus_list = a_list[:minus_num]
    plus_list = a_list[minus_num+zero_num:]
    all_num = sorted([i*j for i in minus_list for j in plus_list])
    print(all_num[k-1])
elif k <= minus_len + zero_len:
    print(0)
else:
    #-2つ or +2つ
    minus_list = a_list[:minus_num]
    plus_list = a_list[minus_num+zero_num:]
    all_num = sorted([minus_list[i]*minus_list[j] for i in range(len(minus_list)-1) for j in range(i+1,len(minus_list))] + [plus_list[i]*plus_list[j] for i in range(len(plus_list)-1) for j in range(i+1,len(plus_list))])
    print(all_num[k-minus_len-zero_len-1])

### FIXED CODE ###

import numpy as np

n,k = map(int,input().split())
a_list = np.array(list(map(int,input().split())))
a_list = np.sort(a_list)

zero = a_list[a_list == 0]
pos = a_list[a_list > 0]
neg = a_list[a_list < 0]

def count(x): #積がx以下になるペアの個数を返す(一旦重複は考えない)
    ans = 0
    if x >= 0:
        ans += n * len(zero)
    # a_list * pos < xだから，a_list < x/posになる個数をcountしている(pos側を固定)
    ans += np.searchsorted(a_list,x // pos, side='right').sum()
    # a_list < x // negとなる者を全ての組み合わせから抜く
    ans += (n - np.searchsorted(a_list, (-x - 1) // (-neg), side='right')).sum()
    # 同じもの2つは選べない
    ans -= np.count_nonzero(a_list * a_list <= x)
    return ans // 2

left = -10 ** 18
right = 10 ** 18
while left + 1 < right:
    x = (left + right) // 2
    if count(x) >= k:
        right = x
    else:
        left = x

print(right)
### BUGGY CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x % MOD


fact = [1] * 100100
for i in range(1, 100100):
    fact[i] = fact[i-1] * i % MOD


def comb(n, r):
    if n < r or r < 0:
        return 0
    else:
        return fact[n] * modinv(fact[n - r]) % MOD * modinv(fact[r]) % MOD


n = int(input())
a = list(map(int, input().split()))
x = sum(a) - n*(n+1)//2

l = 0
while a[l] != x:
    l += 1
r = 0
while a[n - r] != x:
    r += 1
c = n + 1 - l - r - 2

for k in range(1, n + 2):
    ans = comb(n+1, k) - comb(l + r, k - 1)
    if ans < 0:
        ans += MOD
    print(ans)


### FIXED CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x


fact = [1] * 100100
for i in range(1, 100100):
    fact[i] = fact[i-1] * i % MOD


def comb(n, r):
    if n < r or r < 0:
        return 0
    else:
        return fact[n] * modinv(fact[n - r]) * modinv(fact[r]) % MOD


n = int(input())
a = list(map(int, input().split()))
x = sum(a) - n*(n+1)//2

l = 0
while a[l] != x:
    l += 1
r = 0
while a[n - r] != x:
    r += 1
c = n + 1 - l - r - 2

for k in range(1, n + 2):
    ans = comb(n+1, k) - comb(l + r, k - 1)
    if ans < 0:
        ans += MOD
    print(ans)
### BUGGY CODE ###

s=input()
K=int(input())

S=[]
for n in range(1,len(s)+1):
    for i in range(len(s)-n+1):
        S.append(s[i:i+n])
S=list(set(S))
S.sort()

print(S[K-1])



### FIXED CODE ###

s=input()
K=int(input())

S=[]
for n in range(len(s)):
    for i in range(1,len(s)-n+1):
        if len(S)<5:
            S.append(s[n:i+n])
            S = list(set(S))
            S.sort()
        elif S[4]>s[n:i+n]:
            S.append(s[n:i+n])
            S = list(set(S))
            S.sort()
        else:
            break
S=list(set(S))
S.sort()

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

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    for k in range(1, N):
        ans = sum(sum(1 for j in range(i + 1, N)
                      if min(j - i, abs(i - X) + abs(j - Y) + 1) == k) for i in range(N))
        print(ans)


main()


### FIXED CODE ###

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    print(N)
    dist = [0] * (N + 1)

    for i in range(N):
        for j in range(i + 1, N):
            d = min(j - i, abs(i - X) + abs(j - Y) + 1)
            dist[d] += 1

    for k in range(2, N):
        print(dist[k])


main()
### BUGGY CODE ###

N, M = map(int, input().split())
dict = {}
for _ in range(M):
    L, R = map(int, input().split())
    for x in range(L, R+1):
        if x in dict:
            dict[x] += 1
        else:
            dict[x] = 1
print(sum([1 for k, v in dict.items() if v == M]))

### FIXED CODE ###

n, m = map(int, input().split())
L, R = 1, n
for i in range(m):
    l, r = map(int, input().split())
    L = max(L, l)
    R = min(R, r)
print(max(R-L+1, 0))
### BUGGY CODE ###

s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=[list(map(int,input().split())) for i in range(s[1])]
a=0
b=0
for i in range(s[1]):
  b=b+u[i][0]
  for j in range(u[i][0]):
    t.append(u[i][1])
t.sort()
for l in range(s[0]):
  a = a+t[s[0]+b-1-l]
print(a)

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=[list(map(int,input().split())) for _ in range(M)]
B.sort(key=lambda x:-x[1])
i,j=0,0
while i<=N-1:
  for l in range(B[j][0]):
    if A[i]>=B[j][1]:
      print(sum(A))
      exit()
    A[i]=B[j][1]
    i+=1
    if i==N:
      print(sum(A))
      exit()
  j+=1
  if j==M:
    print(sum(A))
    exit()
print(sum(A))