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

from collections import deque
import sys

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))

visited = deque()
i = 0
cnt = 0
while True:
    if cnt == k:
        print(i+1)
        sys.exit()
    if i in visited:
        break
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = list(visited)[si:]
n_loop = len(loop)
left_k = k - cnt
print(loop[left_k % n_loop] + 1)

### FIXED CODE ###

import sys

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))

is_visited = [0] * n
visited = list()
i = 0
cnt = 0
while True:
    if cnt == k:
        print(i+1)
        sys.exit()
    if is_visited[i]:
        break
    is_visited[i] = 1
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = visited[si:]
n_loop = len(loop)
left_k = k - cnt
print(loop[left_k % n_loop] + 1)
### BUGGY CODE ###

s = input()
n = len(s)
mod = 998244353

R = [0] * n
B = [0] * n
for i in range(n):
    if s[i] == '0':
        R[i] = 2
    elif s[i] == '1':
        R[i] = 1
        B[i] = 1
    else:
        B[i] = 2

for i in range(n-1):
    R[i+1] += R[i]
    B[i+1] += B[i]


dp = [[0] * (2*n+10) for _ in range(2*n+10)]

if R[0] > 0:
    dp[0][1] = 1
if B[0] > 0:
    dp[0][0] = 1

for i in range(n-1):
    for r in range(2*n+1):
        if R[i+1] >= r+1:
            dp[i+1][r+1] += dp[i][r]
            dp[i+1][r+1] %= mod
        if i+2-r < 0:
            break
        if B[i+1] >= i+2-r:
            dp[i+1][r] += dp[i][r]
            dp[i+1][r] %= mod

for i in range(n-1, 2*n-1):
    for r in range(2*n+1):
        if R[n-1] >= r+1:
            dp[i + 1][r + 1] += dp[i][r]
            dp[i + 1][r + 1] %= mod
        if i+2-r < 0:
            break
        if B[n-1] >= i+2-r:
            dp[i+1][r] += dp[i][r]
            dp[i+1][r] %= mod

ans = 0
for r in range(2*n+1):
    ans += dp[2*n-1][r]
    ans %= mod

print(ans)

### FIXED CODE ###

s = input()
n = len(s)
mod = 998244353

R = [0] * n
B = [0] * n
for i in range(n):
    if s[i] == '0':
        R[i] = 2
    elif s[i] == '1':
        R[i] = 1
        B[i] = 1
    else:
        B[i] = 2

for i in range(n-1):
    R[i+1] += R[i]
    B[i+1] += B[i]


dp = [[0] * (2*n+10) for _ in range(2*n+10)]

if R[0] > 0:
    dp[0][1] = 1
if B[0] > 0:
    dp[0][0] = 1

for i in range(n-1):
    for r in range(2*n+1):
        if R[i+1] >= r+1:
            dp[i+1][r+1] += dp[i][r]
            dp[i+1][r+1] %= mod
        if i+2-r < 0:
            break
        if B[i+1] >= i+2-r:
            dp[i+1][r] += dp[i][r]
            dp[i+1][r] %= mod

for i in range(n-1, 2*n-1):
    for r in range(2*n+1):
        if R[n-1] >= r+1:
            dp[i + 1][r + 1] += dp[i][r]
            dp[i + 1][r + 1] %= mod
        if i+2-r < 0:
            break
        if B[n-1] >= i+2-r:
            dp[i+1][r] += dp[i][r]
            dp[i+1][r] %= mod

ans = 0
for r in range(2*n+1):
    ans += dp[2*n-1][r]
    ans %= mod

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

from itertools import combinations
N = int(input())

numbers = map(int, input().split())

res = 0
for pair in combinations(numbers, 2):
    res += pair[0] ^ pair[1]

p = 10 ** 9 + 7
print(res % p)


### FIXED CODE ###

N = int(input())

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

num = [[0, 0] for _ in range(60)]

for Ai in A:
    for digit in range(60):
        if (Ai >> digit) & 1:
            num[digit][1] += 1
        else:
            num[digit][0] += 1

res = 0
for i, p in enumerate(num):
    res += (1 << i) * p[0] * p[1]

m = 10 ** 9 + 7
print(res % m)
### BUGGY CODE ###

N=int(input())
i=1
while(True):
    if i**2>=N:
        break
    i+=1
while(True):
    if N%i==0:
        S=i+N//i-2
        print(S)
        break
    i+=1

### FIXED CODE ###

import math
N=int(input())
n=int(math.sqrt(N))
S=0
for i in range(1,n+1):
    if N%i==0:
        s=i+N//i-2
        if S==0:
            S=s
        elif S>=s:
            S=s
print(S)
### BUGGY CODE ###

s=input()
l=len(s)
mod=10**9+7
dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(l):
    if s[i]=='?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13]+=dp[i][k]%mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
print(dp[-1][5]%mod)


### FIXED CODE ###

MOD = 10**9 + 7
S = input()
 
cur = [0] * 13
cur[0] = 1
r = 1
base = 0
for i in range(len(S)):
    s = S[-(i+1)]
    if s == '?':
        prev = cur
        cur = [sum(prev)] * 13
        for m in range(13):
            for d in range(10,13):
                cur[(m + r*d) % 13] -= prev[m]
        for m in range(13):
            cur[m] %= MOD
    else:
        base = (base + r*int(s)) % 13
 
    r = (10 * r) % 13
 
print(cur[(5-base) % 13])
### BUGGY CODE ###

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

	n,x,y = map(int,input().split())

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1

	#res = shortest_path(route, unweighted=False,directed=False)
	res = dijkstra(route, directed=False)


	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()

### FIXED CODE ###

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

	n,x,y = map(int,input().split())

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1
	route = tuple(route)
	#res = shortest_path(route, unweighted=False,directed=False)
	res = tuple(dijkstra(route, directed=False))

	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

a,b,m=map(int, input().split())
fridge=list(map(int, input().split()))
microwave=list(map(int, input().split()))
s=[list(map(int,list(input().split()))) for i in range(m)]
discount = [[0 for i in range(b)] for j in range(a)]


def mapDiscountByXY(m,discount,s):
  for i in range(m):
    if discount[s[i][0]-1][s[i][1]-1] < s[i][2]:
      discount[s[i][0]-1][s[i][1]-1] = s[i][2]
  return discount


def findMin(a,b,fridge,microwave,discount):
  lowest = 100000
  
  for i in range(a):
    for j in range(b):
      if lowest > fridge[i]+microwave[j]-discount[i][j]:
        lowest = fridge[i]+microwave[j]-discount[i][j]
  return lowest


discount = mapDiscountByXY(m,discount,s)
print(findMin(a,b,fridge,microwave,discount))

### FIXED CODE ###

_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)
### BUGGY CODE ###

N=int(input())
a=[int(input())-1 for _ in range(N)]
x=a[0]
ans=1
while x!=0:
    if x==1:
        print(ans)
        break
    ans+=1
    x=a[x]
else:
    print(-1)


### FIXED CODE ###

N=int(input())
a=[int(input())-1 for _ in range(N)]
x=0
ans=0
while True:
    ans+=1
    x=a[x]
    if x==1:
        print(ans)
        break
    if ans>N:
        print(-1)
        break;
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

for b,c in BC:
    A =sorted(A+ [c] * b)[-N:]

print(sum(A))


### FIXED CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC, key=lambda x:x[1], reverse=True)
D = [0] * N
idx = 0
for b,c in BC:
    for i in range(b):
        D[idx] = c
        idx += 1
        if idx >= N:
            break
    if idx >= N:
        break
# print(D)


# print(D)
# print(sorted(A))
# print(len(D), len(A))
for i in range(N):
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break
print(sum(A))
### BUGGY CODE ###

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

### FIXED CODE ###

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

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)
### BUGGY CODE ###

mod = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), "b").zfill(60), input().split()))

ans = 0
for i in range(60):
    cnt = 0
    for j in a:
        if j[- i - 1] == "1":
            cnt += 1
    ans = (ans + (cnt * (n - cnt)) * (2 ** i)) % mod
print(ans)

### FIXED CODE ###

mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(len(str(bin(max(a)))) - 2)]
a = [bin(i)[2:] for i in a]

for i in a:
    for j, k in enumerate(i[::-1]):
        if k == "1":
            l[j] += 1
ans = 0
for i, j in enumerate(l):
    ans = (ans + (j * (n - j)) * (2 ** i)) % mod
print(ans)
### BUGGY CODE ###

def main():
    S=input()
    Q=int(input())
    Left=[]
    Right=[]

    reverse_flag=0
    for i in range(Q):
        query=input().split()
        if query[0]=="1":
            if reverse_flag==1:
                reverse_flag=0
            else:
                reverse_flag=1
        else:
            if query[1]=="1":
                if reverse_flag==0:
                    Left.append(query[2])
                else:
                    Right.append(query[2])
            else:
                if reverse_flag==0:
                    Right.append(query[2])
                else:
                    Left.append(query[2])

    res=""
    if reverse_flag==0:
        while len(Left)>0:
            res+=Left.pop()
        res+=S
        for r in Right:
            res+=r
    else:
        while len(Right)>0:
            res+=Right.pop()
        
        for i in range(len(S)-1,-1,-1):
            res+=S[i]
        
        for l in Left:
            res+=l
    print(res)

if __name__=="__main__":
    main()

### FIXED CODE ###

def main():
    S=input()
    Q=int(input())
    Left=[]
    Right=[]

    reverse_flag=0
    for i in range(Q):
        query=input().split()
        if query[0]=="1":
            if reverse_flag==1:
                reverse_flag=0
            else:
                reverse_flag=1
        else:
            if query[1]=="1":
                if reverse_flag==0:
                    Left.append(query[2])
                else:
                    Right.append(query[2])
            else:
                if reverse_flag==0:
                    Right.append(query[2])
                else:
                    Left.append(query[2])

    res=""
    if reverse_flag==0:
        Left.reverse()
        res+="".join(Left)
        res+=S
        res+="".join(Right)

    else:
        Right.reverse()
        res+="".join(Right)
        S=list(S)
        S.reverse()
        res+="".join(S)
        res+="".join(Left)
    print(res)

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

def lcs(S,T):
    m = len(S)
    n = len(T)
    dp = [[0]*(n+1) for x in range(m+1)]
    
#計算量はO(MN)、DP表の作成
    for i in range(m):
        for j in range(n):
            if S[i] == T[j]:#同じやったときは+1延ばし斜めに移動
                dp[i+1][j+1] = dp[i][j] + 1
            else:#違うかったら、最長は上と左の大きいほうをもってくる
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
# if I want to know the length of the Lcs, return dp[m][n]
#文字列の復元（複数の場合は、そのうちの一つ）
    ans = ''
    while m!=0 and n!=0:#どっちも0になるまで、後ろから復元
        if dp[m][n] == dp[m-1][n]:#dp表を上に動かす
            m-=1
        elif dp[m][n] == dp[m][n-1]:#dp表を左に動かす
            n-=1
        else:#斜めの移動(S[i]==T[j])のときだけ、LCS伸びているので延ばす
            m-=1
            n-=1
            ans=S[m]+ans#これはT[n]でもいい
    return ans
#----------------------------------------------------------------
S = input()
T = input()
print(lcs(S,T))

### FIXED CODE ###

def lcs(S,T):
    m = len(S)
    n = len(T)
    dp = [[0]*(n+1) for x in range(m+1)]
    
#計算量はO(MN)、DP表の作成
    for i in range(m):
        for j in range(n):
            if S[i] == T[j]:#同じやったときは+1延ばし斜めに移動
                dp[i+1][j+1] = dp[i][j] + 1
            else:#違うかったら、最長は上と左の大きいほうをもってくる
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
# if I want to know the length of the Lcs, return dp[m][n]
#文字列の復元（複数の場合は、そのうちの一つ）
    ans = ''
    while m!=0 and n!=0:#どっちも0になるまで、後ろから復元
        if dp[m][n] == dp[m-1][n]:#dp表を上に動かす
            m-=1
        elif dp[m][n] == dp[m][n-1]:#dp表を左に動かす
            n-=1
        else:#斜めの移動(S[i]==T[j])のときだけ、LCS伸びているので延ばす
            m-=1
            n-=1
            ans=S[m]+ans#これはT[n]でもいい
    return ans
#----------------------------------------------------------------
S = input()
T = input()
print(lcs(S,T))
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
ans = 1
A = []
for i in range (0,N):
  x = min(P[0:i+1])
  A.append(x)

for i in range (1,N):
  if (A[i-1] > A[i]):
    ans = ans + 1
  elif (P[i] <= A[i-1]):
    ans = ans + 1
print(ans)
    

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
ans = 1
P0 = P[0]

for i in range (1,N):
  if P[i] <= P0:
    ans = ans + 1
    P0 = P[i]
print(ans)
### BUGGY CODE ###

x,y= map(int, input().split())
a = list(map(int, input().split()))
b=[]
for _ in range(y):
    b.append(list(map(int, input().split())))
b.sort(key = lambda x: x[1],reverse=True) 
for l in b:
    a.extend([l[1]]*l[0])
a.sort(reverse=True)
print(sum(a[:x]))


### FIXED CODE ###

x,y= map(int, input().split())
a = list(map(int, input().split()))
#print(a)
b=[]
for _ in range(y):
    b.append(list(map(int, input().split())))
b.sort(key = lambda x: x[1],reverse=True) 
for l in b:
    if(len(a)<=x*2):
        a.extend([l[1]]*l[0])
#print(len(a))        
#print(a)
a.sort(reverse=True)
print(sum(a[:x]))
### BUGGY CODE ###

def main():
    q=int(input())
    aa=0
    bb=0
    a=[]
    b=[]
    ac=[]
    bc=[]
    for _ in range(q):
        aa,bb=map(int,input().split())
        a.append(aa)
        b.append(bb)
        # ac.append(aa)
        # bc.append(bb)

    # sorted(a)
    # sorted(b)
    bm=max(b)
    ans=[0]*100001
    flg=[0]*100001
    flg[0]=1
    flg[1]=1
    ans[2]=1
    ii=int((bm+1)**0.5)
    for i in range(2,100001):

        if flg[i]==0:
            flg[i]=1
            ans[i]=1
            for j in range(i,int(100001**0.5),i):
                flg[j]=1
    for i in range(0,q):
        cnt=0
        for j in range(a[i],b[i]+1):
            if ans[j]==1 and ans[(j+1)//2]==1:
                cnt+=1
        print(cnt)
    # print(ans[:8])
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
    q=int(input())
    aa=0
    bb=0
    a=[]
    b=[]
    ac=[]
    bc=[]
    for _ in range(q):
        aa,bb=map(int,input().split())
        a.append(aa)
        b.append(bb)
        # ac.append(aa)
        # bc.append(bb)

    # sorted(a)
    # sorted(b)
    bm=max(b)
    ans=[0]*100001
    flg=[0]*100001
    flg[0]=1
    flg[1]=1
    ans[2]=1
    ii=int((bm+1)**0.5)
    for i in range(2,100001):

        if flg[i]==0:
            flg[i]=1
            ans[i]=1
            for j in range(i,100001,i):
                flg[j]=1
    ans2=[]
    cnt=0
    for i in range(0,100001):
        if ans[i]==1 and ans[(i+1)//2]==1:
            cnt+=1
        ans2.append(cnt)
    # print(ans[:11])
    # print(ans2[:11])
    for i in range(0,q):
        print(ans2[b[i]]-ans2[a[i]-1])
    # print(ans[:8])
if __name__=='__main__':
    main()
### BUGGY CODE ###

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

for i in range(1,N):
    print(A.index(i) + 1,end=' ')
print(A.index(N) + 1)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = [''] * N
for i in range(N):
    Q[A[i] - 1] = str(i + 1)
print(' '.join(Q))
### BUGGY CODE ###

#!/usr/bin/env python3
#SoundHound D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,s,t = LI()
cost1 = [[inf]*n for _ in range(n)]
cost2 = [[inf]*n for _ in range(n)]
for _ in range(m):
    u,v,a,b = LI()
    cost1[u-1][v-1] = a
    cost1[v-1][u-1] = a
    cost2[u-1][v-1] = b
    cost2[v-1][u-1] = b

def dijkstra(s,cost):
    d = [inf]*n
    used = [False]*n
    d[s] = 0

    while 1:
        v = -1
        for i in range(n):
            if not used[i] and v == -1:
                v = i
            elif not used[i] and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j],d[v] + cost[v][j])

    return d

c1 = dijkstra(s-1,cost1)
c2 = dijkstra(t-1,cost2)
c = [c1[i] + c2[i] for i in range(n)]
money = 10**15
for i in range(n):
    ans = money - min(c[i:])
    print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#SoundHound D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,s,t = LI()
graph1 = [[] for _ in range(n)]
graph2 = [[] for _ in range(n)]
for _ in range(m):
    u,v,a,b = LI()
    graph1[u-1].append((v-1,a))
    graph1[v-1].append((u-1,a))
    graph2[u-1].append((v-1,b))
    graph2[v-1].append((u-1,b))

def dijkstra(s,graph):
    d = [inf]*n
    d[s] = 0
    h = [(0,s)]
    while h:
        c,v = heappop(h)
        if d[v] < c:
            continue
        for t,cost in graph[v]:
            if d[v] + cost < d[t]:
                d[t] = d[v] + cost
                heappush(h,(d[t],t))
    return d

c1 = dijkstra(s-1,graph1)
c2 = dijkstra(t-1,graph2)
c = [c1[i] + c2[i] for i in range(n)]
money = 10**15
mi = c[-1]
for i in range(n-1)[::-1]:
    mi = min(mi,c[i])
    c[i] = mi
for i in range(n):
    print(money - c[i])
### BUGGY CODE ###

S=list(input())
Q=int(input())
which=0#0 normal #1 reverse
check=[list(map(str,input().split())) for i in range(Q)]
#print(check)
for i in range(Q):
    if check[i][0]=="1":
        which+=1
        which%=2
        continue
    if check[i][0]!="1":
        if which==0:
            if check[i][1]=="1":
                S.insert(0,check[i][2])
            if check[i][1]=="2":
                S.append(check[i][2])
        if which==1:
            if check[i][1]=="1":
                S.append(check[i][2])
            if check[i][1]=="2":
                S.insert(0,check[i][2])
if which==1:
    print("".join(S[len(S)-i-1] for i in range(len(S))))
if which==0:
    print("".join(S))


### FIXED CODE ###

S=str(input())
Q=int(input())
which=0
front=""
back=""
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front=a[2]+front
            if a[1]=="2":
                back+=a[2]
        if which==1:
            if a[1]=="1":
                back+=a[2]
            if a[1]=="2":
                front=a[2]+front

S=front+S+back
if which==1:
    print(S[::-1])
if which==0:
    print(S)
### BUGGY CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = collections.deque([inputs[1]])

for day in conditions.keys():
  conditions[day] = sorted(conditions[day], reverse=True)

ans = 0
candidates = []
for reversed_day in range(1, m + 1):
  for d in range(1, reversed_day+1):
    if d in conditions.keys():
      heapq.heappush(candidates, -conditions[d].pop(0))
      if len(conditions[d]) == 0:
        del conditions[d]
  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

print(ans)

### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
import sys

def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]

N, M = map(int, input().split())
A = []
B = []
neighbor = [[0 for x in range(N)] for y in range(N)]
for i in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    neighbor[a][b] = 1
    neighbor[b][a] = 1

neighbor = csr_matrix(neighbor)

ans = []
for i in range(1,N):
    d, p = shortest_path(neighbor, return_predecessors=True, indices=[0, i], method='D')
    next_sign = get_path(0,i,p)
    if next_sign:
        ans.append(next_sign[-2]+1)
    else:
        print("No")
        sys.exit(0)

print("Yes")
for i in range(N-1):
    print(ans[i])


### FIXED CODE ###

from collections import deque

N,M = map(int, input().split())
ways = [[] for _ in range(N+1)]

for i in range(M):
    a,b = map(lambda x: int(x), input().split())
    ways[a].append(b)
    ways[b].append(a)

dq = deque([1])
sign = [None] * (N+1)
sign[0] = 0
sign[1] = 0

while(dq):
    now = dq.popleft()
    for w in ways[now]:
        if not sign[w]:
            sign[w] = now
            dq.append(w)

if None in sign:
    print("No")
else:
    print("Yes")
    for i in range(2, N+1):
        print(sign[i])
### BUGGY CODE ###

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x + y)
    Y.append(x - y)
# print(X, Y)
ans = 0
for i in range(N):
    for j in range(i):
        if i == j:
            continue
        tmp = max(abs(X[i] - X[j]), abs(Y[i] - Y[j]))
        ans = max(ans, tmp)
print(ans)



### FIXED CODE ###

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x + y)
    Y.append(x - y)
# print(X, Y)

maxX = max(X)
maxY = max(Y)
minX = min(X)
minY = min(Y)

ans = max(maxX - minX, maxY - minY)
print(ans)