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

def main():
    from bisect import bisect
    def _add(data,k,x):
        while k<=N:
            data[k]+=x
            k+=k&-k
    def add(l,r,x):
        _add(data0,l,-x*(l-1))
        _add(data0,r,x*(r-1))
        _add(data1,l,x)
        _add(data1,r,-x)
    def _get(data,k):
        s=0
        while k:
            s+=data[k]
            k-=k&-k
        return s
    def query(l,r):
        return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1)
    N,d,a,*t=map(int,open(0).read().split())
    data0=[0]*(N+1)
    data1=[0]*(N+1)
    z=sorted(zip(*[iter(t)]*2))
    y=[x for x,_ in z]
    c=0
    for i,(x,h)in enumerate(z,1):
        h-=query(i,i+1)
        t=0--max(0,h)//a
        j=bisect(y,x+d+d)
        add(1,j+1,t*a)
        c+=t
    print(c)
main()

### FIXED CODE ###

from bisect import*
def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

def _get(data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)
N,d,a,*t=map(int,open(0).read().split())
N+=1
z=sorted(zip(*[iter(t)]*2))
data0=[0]*(N+1)
data1=[0]*(N+1)
y=[x for x,_ in z]
c=0
for i,(x,h)in enumerate(z,1):
    h-=query(i,i+1)
    t=0--max(0,h)//a
    j=bisect(y,x+d+d)
    add(1,j+1,t*a)
    c+=t
print(c)
### BUGGY CODE ###

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if(L[i] < (L[j] + L[k]) and L[j] < (L[k] + L[i]) and L[k] < (L[i] + L[j])):
                ans += 1

print(ans)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        k = bisect.bisect_left(L, L[i]+L[j])
        ans += max(0, k-j-1)
print(ans)
### BUGGY CODE ###

from collections import Counter

if __name__ == '__main__':
    s = list(input())
    s.reverse()
    n = len(s)
    now = 0
    mods = [0] * n
    for i in range(n):
        now += (10 ** i) * int(s[i])
        mods[i] = now % 2019
    mods.sort()
    m = Counter(mods)
    ans = 0
    for k, v in m.items():
        if k == 0:
            ans += v
        ans += (v * (v - 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)
### BUGGY CODE ###

import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
INF=np.inf
#print(S)
def bfs(sx,sy,gx,gy):
  #dx, dy 四方向に対応したベクトルのリスト
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  #P: (x, y)のキュー
  P=[]
  #d: スタートから各点までの最小距離の配列
  d=np.ones((H, W))*INF
  #スタート地点をキューに入れ、その点の距離を0にする
  P.append([sx, sy])
  d[sx,sy]=0
    
  #キューがからになるまでループ
  while len(P)>0:
    #キューの先頭を取り出す
    p=P.pop(0)
    #取り出してきた状態がゴールなら探索をやめる
    if (p[0]==gx and p[1]==gy):
      break
        
    #移動四方向をループ
    for i in range(4):
      #移動した後の点をnx, nyとする
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
            
      #移動が可能かどうかの判定とすでに訪れたことがあるかどうかの判定（d[nx, ny]!=INFならおtpずれたことがある）
      if 0<=nx and nx<H and 0<=ny and ny<W and S[nx, ny]!="#" and d[nx, ny]==INF:
        #移動できるならキューに入れ、その点の距離をpからの距離＋１で確定する
        P.append([nx, ny])
        d[nx, ny]=d[p[0], p[1]]+1
  #print(d)
  if d[gx,gy]!=INF:
    result=d[gx, gy]
  else:
    result=0
  return result
ans=0
Tlen=H*W
for i in range(Tlen):
  for j in range(i,Tlen):
    sx,sy=i%H, int(i//H)
    gx,gy=j%H, int(j//H)
    
    if S[sx,sy]=="#" or S[gx,gy]=="#":
      continue
    res=bfs(sx,sy,gx,gy)
    ans=max(ans, res)
"""
for sx in range(H):
  for sy in range(W):
    for gx in range(H):
      for gy in range(W):
        if S[sx,sy]=="#" or S[gx,gy]=="#":
          continue
        res=bfs(sx,sy,gx,gy)
        ans=max(ans, res)
"""
print(int(ans))

### FIXED CODE ###

import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
INF=-1
#print(S)
def bfs(sx,sy):
  #dx, dy 四方向に対応したベクトルのリスト
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  #P: (x, y)のキュー
  P=[]
  #d: スタートから各点までの最小距離の配列
  d=np.ones((H, W))*INF
  #スタート地点をキューに入れ、その点の距離を0にする
  P.append([sx, sy])
  d[sx,sy]=0
    
  #キューがからになるまでループ
  while len(P)>0:
    #キューの先頭を取り出す
    p=P.pop(0)
    #取り出してきた状態がゴールなら探索をやめる
    """
    if (p[0]==gx and p[1]==gy):
      break
    """
        
    #移動四方向をループ
    for i in range(4):
      #移動した後の点をnx, nyとする
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
            
      #移動が可能かどうかの判定とすでに訪れたことがあるかどうかの判定（d[nx, ny]!=INFならおtpずれたことがある）
      if 0<=nx and nx<H and 0<=ny and ny<W and S[nx, ny]!="#" and d[nx, ny]==INF:
        #移動できるならキューに入れ、その点の距離をpからの距離＋１で確定する
        P.append([nx, ny])
        d[nx, ny]=d[p[0], p[1]]+1
  """
  #print(d)
  if d[gx,gy]!=INF:
    result=d[gx, gy]
  else:
    result=0
  """
  result=d.max()
  return result
ans=0
Tlen=H*W
for sx in range(H):
  for sy in range(W):
    if S[sx,sy]=="#":
      continue
    res=bfs(sx,sy)
    ans=max(ans, res)
"""
for i in range(Tlen):
  for j in range(i,Tlen):
    sx,sy=i%H, int(i//H)
    gx,gy=j%H, int(j//H)
    
    if S[sx,sy]=="#" or S[gx,gy]=="#":
      continue
    res=bfs(sx,sy,gx,gy)
    ans=max(ans, res)
"""
"""
for sx in range(H):
  for sy in range(W):
    for gx in range(H):
      for gy in range(W):
        if S[sx,sy]=="#" or S[gx,gy]=="#":
          continue
        res=bfs(sx,sy,gx,gy)
        ans=max(ans, res)
"""
print(int(ans))
### BUGGY CODE ###

import itertools
import sys
input = sys.stdin.readline

H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = []
for m in range(M):
  h, w = map(int, input().split())
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.append(str(h-1)+"_"+str(w-1))

hmax_ind = list(map(lambda x: True if x == max(Hsum) else False, Hsum))
hmax_ind = list(itertools.compress(range(len(Hsum)), hmax_ind))
wmax_ind = list(map(lambda x: True if x == max(Wsum) else False, Wsum))
wmax_ind = list(itertools.compress(range(len(Wsum)), wmax_ind))
 
res = []
for n1, n2 in itertools.product(hmax_ind, wmax_ind):
  res.append(str(n1)+"_"+str(n2))

if len(set(res).intersection(set(hw))) == len(res):
  print(max(Hsum) + max(Wsum)-1)
else:
  print(max(Hsum) + max(Wsum))

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = set()
for m in range(M):
  h, w = map(lambda x: int(x) - 1, input().split())
  Hsum[h] += 1
  Wsum[w] += 1
  hw.add((h, w))

mh = max(Hsum)
mw = max(Wsum)
hidx = [i for i, _ in enumerate(Hsum) if _ == mh]
widx = [i for i, _ in enumerate(Wsum) if _ == mw]
 
if len(hidx) * len(widx) > M:
  print(mh + mw)
else:
  fi_flg = False
  for h in hidx:
    for w in widx:
      if (h, w) not in hw:
        print(mh + mw)
        fi_flg = True
        break
    if fi_flg:
      break
  if fi_flg is False:
    print(mh + mw - 1)
### BUGGY CODE ###

import heapq
import itertools

def solve():
    N, M, _ = list(map(int, input().split()))
    R = list(map(int, input().split()))
    R = map(lambda x: x-1, R)
    G = [[] for i in range(N)]

    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A].append((C, B))
        G[B].append((C, A))


    def dijkstra(d):
        que = []

        tar = -1
        for i in range(len(d)):
            if d[i] == -1:
                break
            if d[i] == 0:
                tar = i
            heapq.heappush(que, (d[i], i))

        while len(que) != 0:
            dist, node = heapq.heappop(que)
            for (cost, to) in G[node]:
                if d[to] > d[node] + cost:
                    d[to] = d[node] + cost
                    heapq.heappush(que, (dist + cost, to))

        return d


    ds = [[1e16 for i in range(N)] for j in range(N)]

    for i in range(N):
        ds[i][i] = 0

    for i in range(N):
        ds[i] = dijkstra(ds[i])
        for j in range(N):
            ds[j][i] = ds[i][j]

    res = 1e16
    for r in list(itertools.permutations(R)):
        d = 0
        for i in range(len(r)-1):
            d += ds[r[i]][r[i+1]]
        res = min(res, d)

    return res

print(solve())

### FIXED CODE ###

import heapq
import itertools

def solve():
    N, M, _ = list(map(int, input().split()))
    R = list(map(int, input().split()))
    R = map(lambda x: x-1, R)
    G = [[] for i in range(N)]

    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A].append((C, B))
        G[B].append((C, A))


    def dijkstra(d):
        que = []

        tar = -1
        for i in range(len(d)):
            if d[i] == -1:
                break
            if d[i] == 0:
                tar = i
            heapq.heappush(que, (d[i], i))

        while len(que) != 0:
            dist, node = heapq.heappop(que)
            for (cost, to) in G[node]:
                if d[to] > d[node] + cost:
                    d[to] = d[node] + cost
                    heapq.heappush(que, (dist + cost, to))

        return d


    ds = [[1e16 for i in range(N)] for j in range(N)]

    for i in range(N):
        ds[i][i] = 0

    for i in range(N):
        ds[i] = dijkstra(ds[i])
        for j in range(N):
            ds[j][i] = ds[i][j]

    res = 1e16
    for r in list(itertools.permutations(R)):
        d = 0
        for i in range(len(r)-1):
            d += ds[r[i]][r[i+1]]
        res = min(res, d)

    return res

print(solve())
### BUGGY CODE ###

A, B, C, K = map(int, input().split())

if A == B == C:
    print(0)
    exit()

for i in range(K):
    nA = B + C
    nB = A + C
    nC = A + B
    A, B, C = nA, nB, nC
    if abs(A - B) >= int(1e18):
        print("Unfair")
        break
else:
    print(A - B)

### FIXED CODE ###

A, B, C, K = map(int, input().split())

if K % 2 == 0:
    if abs(A - B) >= int(1e18):
        print("Unfair")
    else:
        print(A - B)
else:
    if abs(A - B) >= int(1e18):
        print("Unfair")
    else:
        print(B - A)
### BUGGY CODE ###

import random
N, K = map(int, input().split())
*V, = map(int, input().split())
random.shuffle(V)
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | ((A[i] << V[i]) & MASK))
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i]))

ans = N
for i in range(N):
    if K <= V[i]:
        ans -= 1
        continue
    a = A[i]; b = B[i+1]
    VM = 2**(V[i]+1)-2
    while a and b:
        if a & 1 and b & VM:
            ans -= 1
            break
        l = max((a & -a).bit_length()-1, 1)
        a >>= l; b >>= l
print(ans)


### FIXED CODE ###

import random
N, K = map(int, input().split())
*V, = map(int, input().split())
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | ((A[i] << V[i]) & MASK))
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i]))

ans = N
for i in range(N):
    if K <= V[i]:
        ans -= 1
        continue
    a = A[i]; b = B[i+1]
    VM = 2**(V[i]+1)-2
    l = 1
    while a and b and l:
        if a & 1 and b & VM:
            ans -= 1
            break
        l = max((a & -a).bit_length()-1, (b & -b).bit_length()-V[i]-1)
        a >>= l; b >>= l
print(ans)
### BUGGY CODE ###

def solve():
    R,G,B,N=map(int,input().split())
    ans=0
    for i in range(N+1):
        for j in range(N+1):
            tmp=N-(R*i+G*j)
            if tmp%B==0 and tmp>=0:
                ans+=1
    print(ans)

solve()

### FIXED CODE ###

def solve():
    R,G,B,N=map(int,input().split())
    ans=0
    for i in range(N+1):
        for j in range(N+1):
            tmp=N-(R*i+G*j)
            if tmp>=0 and tmp%B==0:
                ans+=1
    print(ans)

solve()
### BUGGY CODE ###

import sys

H, W = map(int, sys.stdin.readline().strip().split())
grid = []
for _ in range(H):
    grid.append(sys.stdin.readline().strip())

# (x, y)のx, y方向のscore [a, b]
scores = [[[0, 0] for _ in range(W)] for _ in range(H)]
for y in range(H):
    start = 0
    count = 0
    for x in range(W):
        if grid[y][x] == "#" or x == W-1:
            if x == W-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, x+1):
                scores[y][i][0] = count
            count = 0
            start = x + 1
        else:
            count += 1

for x in range(W):
    start = 0
    count = 0
    for y in range(H):
        if grid[y][x] == "#" or y == H-1:
            if y == H-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, y+1):
                scores[i][x][1] = count
            count = 0
            start = y + 1
        else:
            count += 1

# print(scores)
ans = 0
for y in range(H):
    for x in range(W):
        ans = max(ans, scores[y][x][0] + scores[y][x][1] -1)
print(ans)

### FIXED CODE ###

import sys

H, W = map(int, sys.stdin.readline().strip().split())
grid = []
for _ in range(H):
    grid.append(sys.stdin.readline().strip())

# (x, y)のx, y方向のscore [a, b]
scores_y = [[0 for _ in range(W)] for _ in range(H)]
scores_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    start = 0
    count = 0
    for x in range(W):
        if grid[y][x] == "#" or x == W-1:
            if x == W-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, x+1):
                scores_x[y][i] = count
            count = 0
            start = x + 1
        else:
            count += 1

for x in range(W):
    start = 0
    count = 0
    for y in range(H):
        if grid[y][x] == "#" or y == H-1:
            if y == H-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, y+1):
                scores_y[i][x] = count
            count = 0
            start = y + 1
        else:
            count += 1

# print(scores)
ans = 0
for y in range(H):
    for x in range(W):
        ans = max(ans, scores_x[y][x] + scores_y[y][x] - 1)
print(ans)
### BUGGY CODE ###

N = int(input())
line = [int(x) for x in input().split(' ')]
for i in range(1,N+1):
  print(line.count(i))

### FIXED CODE ###

N = int(input())
line = [int(x) for x in input().split(' ')]
L = [0]*N
for i in line:
  L[i-1] += 1
for i in L:
  print(i)
### BUGGY CODE ###

n = int(input())
def digit_sum(n):
    # 各桁の和を求める
    # 計算量: O(logN)
    ans = 0
    while n > 0:
        ans += n % 10
        n //= 10
    return ans
if digit_sum(n)%9 ==0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
if n%9 ==0:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes

era = eratos(max_r)


for l, r in zip(ls, rs):
    num = 0
    for i in range(l, r+1, 2):
        #print(i, isPrime(i), isPrime((i+1)/2), isPrime((i+1)/2))
        if ((i+1)/2)%2 == 0 and (i+1)/2 != 2:
            continue
        else:
            if era[i] == 1 and era[int((i+1)/2)] == 1:
                num += 1
    print(num)



### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes


def count_similar(era, n):
    count_similar = [0 for i in range(n+1)]
    for i in range(1,n+1):
        count_similar[i] = count_similar[i-1]
        if era[i] == 1 and era[int((i+1)/2)] == 1:
            count_similar[i] += 1
    return count_similar




era = eratos(max_r)
cnt = count_similar(era, max_r)

for l, r in zip(ls, rs):
    print(cnt[r] - cnt[l-1])
### BUGGY CODE ###

n = int(input())
n_list = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]
a_list = []

for i in range(n-1):
    for j in range(i+1,n):
        a_list.append((num_list[i] * num_list[j]) % mod)
ans_list = [n % mod for n in a_list]
ans = sum(a_list) % mod

print (ans)

### FIXED CODE ###

n = int(input())
n_list = [int(i) for i in input().split()]

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

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

input()
A=list(map(int,input().split()))
c=0
for b in set(A):
  a=A.count(b)
  c+=a-b if a>=b else a
print(c)

### FIXED CODE ###

from collections import Counter
input()
A=Counter(list(map(int,input().split()))).most_common()
c=0
for a,b in A:
  c+= b-a if b>=a else b
print(c)
### BUGGY CODE ###

A, B, K = map(int, input().split())
ab = [int(i) for i in range(A, B + 1)]
ba = ab[::-1]
ans = set()

for i in range(min(K, len(ab))):
    ans.add(ab[i])
    ans.add(ba[i])

ans = sorted(ans)
for i in ans:
    print(i)

### FIXED CODE ###

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

if b-a+1 <= 2*k:
    for num in range(a, b+1):
        print(num)
else:
    for num in range(a, a+k):
        print(num)
    for num in range(b-k+1,b+1):
        print(num)
### BUGGY CODE ###

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=list(X_Y_)
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)
### BUGGY CODE ###

S=input()
N=len(S)
K=int(input())

from collections import*
ans=set([])
for i in range(1,N+1):
    now=S[:i]
    ans.add(now)
    now=list(now)
    now=deque(now)
    for s in S[i:]:
        now.append(s)
        now.popleft()
        a=''.join(now)
        ans.add(a)
ans=sorted(list(ans))
print(ans[K-1])

### FIXED CODE ###

S=input()
N=len(S)
K=int(input())
A=[]
for i in range(1,K+1):
    j=0
    while j+i<=N:
        A.append(S[j:j+i])
        j+=1
A=list(set(A))
A.sort()
print(A[K-1])
### BUGGY CODE ###

from collections import Counter

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

dic = Counter(a)

ans = 0

for ai in a:
    cnt = 0
    f = 1
    for i in range(1, int(ai**0.5)+1):
        if ai % i == 0:
            d = i
            if d in dic:
                cnt += dic[d]
            if d == ai:
                cnt -= 1
            if cnt > 0:
                f = 0
                break
            if i != ai // i:
                d = ai // i
                if d in dic:
                    cnt += dic[d]
                if d == ai:
                    cnt -= 1
                if cnt > 0:
                    f = 0
                    break

    ans += f

print(ans)
    

            




### FIXED CODE ###

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

a.sort()
am = a[-1]

memo = [0] * (am+1)

for ai in a:
    memo[ai] = 1

p = -1

for ai in a:
    if ai == p:
        memo[ai] = 0
        continue
    for j in range(2, am // ai + 1):
        memo[ai * j] = 0
    p = ai

print(sum(memo))
### BUGGY CODE ###

def main():
    n, q = map(int, input().split())

    # 頂点のリスト、ポイント、走査済みか
    graph = [[[], 0, False] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        graph[a-1][0].append(b-1)
        graph[b-1][0].append(a-1)

    for i in range(q):
        p, x = map(int, input().split())
        graph[p-1][1] += x

    queue = [0]
    while queue:
        q = queue.pop()
        graph[q][2] = True
        for v in graph[q][0]:
            if graph[v][2]:
                continue
            graph[v][1] += graph[q][1]
            queue.append(v)

    for i in range(n):
        print(graph[i][1], end=' ')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, q = map(int, input().split())

    # 頂点のリスト、ポイント、走査済みか
    graph = [[[], 0, False] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        graph[a-1][0].append(b-1)
        graph[b-1][0].append(a-1)

    for i in range(q):
        p, x = map(int, input().split())
        graph[p-1][1] += x

    queue = [0]
    while queue:
        q = queue.pop()
        graph[q][2] = True
        for v in graph[q][0]:
            if graph[v][2]:
                continue
            graph[v][1] += graph[q][1]
            queue.append(v)

    for i in range(n):
        print(graph[i][1], end=' ')


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

n=int(input())
a=list(map(int,input().split()))
ans=1
d={}
for i in range(n):
    d[i]=a.count(i)
for i in range(1,n-1):
    cnt=d[i-1]+d[i]+d[i+1]
    ans=max(ans,cnt)
print(ans)

### FIXED CODE ###

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
ans=1
counter=Counter(a)
for i in range(1,n-1):
    ans=max(ans,counter[i-1]+counter[i]+counter[i+1])
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
As = [A-1 for A in map(int, input().split())]

maxD = K.bit_length() - 1

dp = [[0]*(N) for _ in range(maxD+1)]
for i in range(N):
    dp[0][i] = As[i]
for d in range(1, maxD+1):
    for i in range(N):
        dp[d][i] = dp[d-1][dp[d-1][i]]

iNow = 0  ###
for d in range(maxD+1):
    if K & (1<<d):
        iNow = dp[d][iNow]

print(iNow+1)


### FIXED CODE ###

N, K = map(int, input().split())
As = [A-1 for A in map(int, input().split())]

maxD = K.bit_length() - 1

dp = [[0]*(N) for _ in range(maxD+1)]
for i in range(N):
    dp[0][i] = As[i]
for d in range(1, maxD+1):
    for i in range(N):
        dp[d][i] = dp[d-1][dp[d-1][i]]

iNow = 0  ###
for d in range(maxD+1):
    if K & (1<<d):
        iNow = dp[d][iNow]

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

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

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,ns):
  global cnt
  if ns in s:
    cnt+=1
  if cnt==k:
    print(ns)
    exit()
  if keta==k:
    return

  for i in abc:
    dfs(keta+1,ns+i)

cnt=0
for i in abc:
  dfs(1,i)

### FIXED CODE ###

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

st=set()
s_len=len(s)

length=1
while length<=min(s_len,k):
  for i in range(s_len-length+1):
    sub_s=s[i:i+length]
    st.add(sub_s)
  length+=1

list=sorted(st)
print(list[k-1])