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

# -*- coding: utf-8 -*-
import numpy as np

def get_gcd(a, b, c):
    min_ab = min(a, b)
    max_ab = max(a, b)
    amari = max_ab % min_ab
    if amari == 0:
        gcd1 = min_ab
    else:
        x = min_ab
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd1 = y
                break
            x = y
            y = amari
    min_2 = min(c, gcd1)
    max_2 = max(c, gcd1)
    amari = max_2 % min_2
    if amari == 0:
        gcd2 = min_2
    else:
        x = min_2
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd2 = y
                break
            x = y
            y = amari

    return gcd2


k = int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        if b == a:
            continue
        for c in range(1, k+1):
            if c == a or c == b:
                continue
            ans += get_gcd(a, b, c)

for a in range(1, k+1):
    b = a
    for c in range(1, k+1):
        if c == a:
            continue
        ans += get_gcd(a, b, c) * 3

for a in range(1, k+1):
    b = a
    c = a
    ans += get_gcd(a, b, c)

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

def get_gcd(a, b, c):
    min_ab = min(a, b)
    max_ab = max(a, b)
    amari = max_ab % min_ab
    if amari == 0:
        gcd1 = min_ab
    else:
        x = min_ab
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd1 = y
                break
            x = y
            y = amari
    min_2 = min(c, gcd1)
    max_2 = max(c, gcd1)
    amari = max_2 % min_2
    if amari == 0:
        gcd2 = min_2
    else:
        x = min_2
        y = amari
        while y != 0:
            amari = x % y
            if amari == 0:
                gcd2 = y
                break
            x = y
            y = amari

    return gcd2


k = int(input())
ans = 0

for a in range(1, k+1):
    for b in range(a+1, k+1):
        if b == a:
            continue
        for c in range(b+1, k+1):
            if c == a or c == b:
                continue
            ans += get_gcd(a, b, c) * 6

for a in range(1, k+1):
    b = a
    for c in range(1, k+1):
        if c == a:
            continue
        ans += get_gcd(a, b, c) * 3

for a in range(1, k+1):
    b = a
    c = a
    ans += get_gcd(a, b, c)

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

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

def popcount(n):
    if n == 0:
        return 0
    return 1 + popcount(n % bin(n).count("1"))

def main():
    N = int(input())
    X = input().strip()


    x = int(X, 2)
    for i in range(N):
        if X[i] == '0':
            print(popcount(x + (2 ** (N - i - 1))))
        else:
            print(popcount(x - (2 ** (N - i - 1))))



    

if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def binbin(binn):
    return bin(binn).count("1")


def popcount(n):
    if n == 0:
        return 0
    return 1 + popcount(n % binbin(n))


def main():
    N = int(input())
    X = input().strip()

    x1 = 0
    xc = binbin(int(X, 2))
    if xc == 1:
        x2 = -1
    else:
        x2 = 0
    for i in range(N):
        if X[-1 - i] == '1':
            x1 += pow(2, i, xc + 1)
            if x2 != -1:
                x2 += pow(2, i, xc - 1)
    for i in range(N):
        if X[i] == '0':
            print(1 + popcount((x1 + pow(2, N - i - 1, xc + 1)) % (xc + 1)))
        else:
            if x2 == -1:
                print(0)
            else:
                print(1 + popcount((x2 - pow(2, N - i - 1, xc - 1) + xc - 1) % (xc - 1)))


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

import itertools

n, k = map(int, input().split())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = float("INF")
for a, b in itertools.combinations(xy, 2):
    for c, d in itertools.combinations(xy, 2):
        x1, x2 = a[0], b[0]
        y1, y2 = c[1], d[1]
        count = 0
        for x, y in xy:
            if min(x1, x2) <= x <= max(x1, x2) and min(y1, y2) <= y <= max(y1, y2):
                count += 1
        if count >= k:
            ans = min(ans, abs(x1 - x2) * abs(y1 - y2))
print(ans)

### FIXED CODE ###

import itertools

n, k = map(int, input().split())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = float("INF")
for a, b in itertools.combinations(xy, 2):
    for c, d in itertools.combinations(xy, 2):
        x1, x2 = a[0], b[0]
        y1, y2 = c[1], d[1]
        count = 0
        for x, y in xy:
            if min(x1, x2) <= x <= max(x1, x2) and min(y1, y2) <= y <= max(y1, y2):
                count += 1
        if count >= k:
            ans = min(ans, abs(x1 - x2) * abs(y1 - y2))
print(ans)
### BUGGY CODE ###


S = input()

s = list(S)

s.reverse()

#print (s)

lis = [0] * 13
lis[0] = 1
keta = 1

for i in range(len(S)):

    nlis = [0] * 13

    if s[i] == "?":

        for j in range(10):

            for k in range(13):

                nlis[ (k + (j * keta)) % 13] += lis[k]

    else:

        now = int(s[i])

        for k in range(13):

            nlis[ (k + (now * keta)) % 13 ] += lis[k]

    #print (nlis)
    keta *= 10
    for j in range(13):
        lis[j] = nlis[j]

#print (lis)
print (lis[5] % (10**9 + 7))


### FIXED CODE ###


S = input()

s = list(S)

s.reverse()

#print (s)

lis = [0] * 13
lis[0] = 1
keta = 1

for i in range(len(S)):

    nlis = [0] * 13



    for j in range(10):

        for k in range(13):

            if s[i]== "?" or j == int(s[i]):
                nlis[ (k + (j * keta)) % 13] += lis[k]

    keta *= 10
    keta = keta % 13
    for j in range(13):
        lis[j] = nlis[j] % (10**9 + 7)

#print (lis)
print (lis[5] % (10**9 + 7))
### BUGGY CODE ###

N = int(input())
card = list(map(int,input().split(' ')))

dif_list = []
for i in range(1,N,1):
  sunuke = sum(card[:i])
  arai = sum(card[i:])
  dif = abs(sunuke-arai)
  dif_list.append(dif)
  
print(min(dif_list))

### FIXED CODE ###

N = int(input())
card = list(map(int,input().split(' ')))

sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))
### BUGGY CODE ###

N, K = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]

def dfs(x, fr) :
    flag = True
    M = 0
    for i in range(fr, 30) :
        y = x | (1 << i)
        if y <= K :
            M = max(M, dfs(y, i + 1))
            flag = False
            
    if flag :
        s = 0
        for A, B in AB :
            if A & ~x == 0 :
                s += B
        return s
    else :
        return M
        
print(dfs(0, 0))

### FIXED CODE ###

N, K = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]

ret = 0
for A, B in AB :
    if A & ~K == 0 :
        ret += B
        
for i in range(30) :
    if K & (1 << i) == 0 :
        continue
        
    k = K
    k ^= 1 << i
    k |= (1 << i) - 1
    s = 0
    for A, B in AB :
        if A & ~k == 0 :
            s += B
            
    ret = max(ret, s)
    
print(ret)
### BUGGY CODE ###

N=int(input())

ans=0
for i in range(1,N):
    ans+=i%(i+1)
print(ans)
    


### FIXED CODE ###

N=int(input())

ans=N*(N-1)//2
    
print(ans)
### BUGGY CODE ###

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

for i in range(A,B+1):
    if i <A+K:
        print(i)
    elif i > B-K:
        print(i)

### FIXED CODE ###

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

if K>(B-A)/2:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)
### BUGGY CODE ###

N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    for j in range(N):
        if i != j:
            A.append(B[j])
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []


### FIXED CODE ###

N = int(input())
B = list(map(int, input().split()))
A = [0] + B + [0]
s = 0
t = 0

for i in range(1,N+2):
    t += abs(s-A[i])
    s = A[i]

for i in range(1,N+1):
    print(t + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))
### BUGGY CODE ###

class MyList(list):
    def __init__(self):
        self.__init__ = list

        self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX}
    def cmd(self,command):
        if ' ' in command:
            ope, num = command.split()
            num = int(num)
            self.d[ope](num)
        else:
            self.d[command]()
            
    def delF(self):
        self.pop(0)

    def delL(self):
        self.pop(-1)

    def insX(self,num):
        self.insert(0,num)

    def delX(self,num):
        if num in self:
            self.remove(num)

if __name__ == '__main__' :
    l = MyList()
    n = input()
    
    for i in range(n):
        l.cmd(raw_input())

    for i in range(len(l)-1):
        print l[i],
    print l[-1]

### FIXED CODE ###

from collections import deque

class MyList(deque):
    def __init__(self):
        self.__init__ = deque
        self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX}
    def cmd(self,command):
        if ' ' in command:
            ope, num = command.split()
            num = int(num)
            self.d[ope](num)
        else:
            self.d[command]()
            
    def delF(self):
        self.popleft()

    def delL(self):
        self.pop()

    def insX(self,num):
        self.appendleft(num)

    def delX(self,num):
        if num in self:
            self.remove(num)

if __name__ == '__main__' :
    l = MyList()
    n = input()
    
    for i in range(n):
        l.cmd(raw_input())

    q = deque(l)
    for i in range(len(l)-1):
        print q.popleft(),
    print l[-1]
### BUGGY CODE ###

def f_takahashi_basics_in_education_and_learning(L, A, B, M, DIGIT_MAX=18):
    import numpy
    # 数列に対して、d桁の要素の個数を求める
    num_pow_d = [0] * (DIGIT_MAX + 1)
    for d in range(DIGIT_MAX + 1):
        if 10**d - 1 < A:
            continue
        # dに対してA + B*n <= 10**d - 1 となる最大のn(L以下しか取りえない)
        num_pow_d[d] = min(((10**d - 1 - A) // B) + 1, L)  # +1はnが0スタートのため

    ans = 0
    array = numpy.array([0, A, 1])
    for d in range(1, DIGIT_MAX + 1):
        c_d = num_pow_d[d] - num_pow_d[d - 1]
        matrix = numpy.array([[(10**d), 0, 0], [1, 1, 0], [0, B, 1]], dtype='object')
        m = numpy.eye(3, dtype='object') if c_d == 0 else numpy.linalg.matrix_power(matrix, c_d)
        array = array.dot(m)
        array %= M
    return array[0]

L, A, B, M = [int(i) for i in input().split()]
print(f_takahashi_basics_in_education_and_learning(L, A, B, M))

### FIXED CODE ###

def f_takahashi_basics_in_education_and_learning(L, A, B, M, DIGIT_MAX=18):
    """numpyの行列演算だと L, A, B が 10**18 程度のときうまく動作しない"""
    def identity_matrix(n):
        """n×n単位行列"""
        return [[int(i == j) for i in range(n)] for j in range(n)]

    def multiply(a, b):
        """行列a, bの積"""
        row = len(a)
        col = len(b[0])
        t = len(b)
        ret = [[0] * col for _ in range(row)]
        for i in range(row):
            for j in range(col):
                for k in range(t):
                    ret[i][j] += a[i][k] * b[k][j]
        for i in range(row):
            for j in range(col):
                ret[i][j] %= M
        return ret

    def power(a, k):
        """行列aのk乗"""
        n = len(a)
        ret = identity_matrix(n)
        while k:
            if k & 1:
                ret = multiply(ret, a)
            a = multiply(a, a)
            k >>= 1
        return ret
 
    # 数列に対して、d桁の要素の個数を求める
    num_pow_d = [0] * (DIGIT_MAX + 1)
    for d in range(DIGIT_MAX + 1):
        if 10**d - 1 < A:
            continue
        # dに対してA + B*n <= 10**d - 1 となる最大のn(L以下しか取りえない)
        num_pow_d[d] = min(((10**d - 1 - A) // B) + 1, L)  # +1はnが0スタートのため
    ans = 0
    array = [[0, A, 1]]
    for d in range(1, DIGIT_MAX + 1):
        c_d = num_pow_d[d] - num_pow_d[d - 1]
        matrix = [[10**d, 0, 0], [1, 1, 0], [0, B, 1]]
        array = multiply(array, power(matrix, c_d))
    return array[0][0]

L, A, B, M = [int(i) for i in input().split()]
print(f_takahashi_basics_in_education_and_learning(L, A, B, M))
### BUGGY CODE ###

#! /usr/bin/env python3

def f(a, b, c, d):
    n = 1
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(input())):
        c, d = map(int, input().split())
        a, b = f(a, b, c, d)
    print(a+b)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#! /usr/bin/env python3

def f(a, b, c, d):
    n = max(1,a//c, b//d)
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(input())):
        c, d = map(int, input().split())
        a, b = f(a, b, c, d)
    print(a+b)

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

#n=int(input())
n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
def f(l):
    res=1
    for li in l:
        res=res*li
    return res
sc=[]
alr=0
for i in range(k-1,n):
    
    if alr==0:
        score=f(al[i-k+1:i+1])
        alr=1
    else:
        first=al[i-k]
        last=al[i]
        score=(score//first)*last
    sc.append(score)
for i in range(n-k):
    if sc[i+1]>sc[i]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

#n=int(input())
n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
def f(l):
    res=1
    for li in l:
        res=res*li
    return res
sc=[]
alr=0
for i in range(k-1,n):
    if i==k-1:
        #score=f(al[i-k+1:i+1])
        first=al[i-k+1]
        alr=1
    else:
        #first=al[i-k]
        last=al[i]
        if last>first :
            print('Yes')
        else:
            print('No')
        first=al[i-k+1]
### BUGGY CODE ###

import heapq

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

C=[[-A[i]*F[i], A[i], F[i]] for i in range(N)]

heapq.heapify(C)

for _ in range(K):
  tmp=heapq.heappop(C)
  a=max(tmp[1]-1, 0)
  heapq.heappush(C, [-a*tmp[2], a, tmp[2]])
  
tmp=heapq.heappop(C)
print(-tmp[0])

### FIXED CODE ###

import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)
### BUGGY CODE ###

N=int(input())
la=list(range(2,10**2+1))
l=[]
for i in range(len(la)):
  l.append(la[i]**2)
for n in range(1,N+1):
  if n<6:
    print(0)
  else:
    c=0
    for x in range(len(l)):
      if l[x]*3>2*n:
        break
      else:
        for y in range(x,len(l)):
          if l[x]+2*l[y]>2*n:
            break
          else:
            for z in range(y,len(l)):
              if l[x]+l[y]+l[z]>2*n:
                break
              else:
                
                if l[x]+l[y]+l[z]==2*n:
                  
                  if (x+y+z)%2==0 and x+y+2>z:
                      if l[x]==l[y] and l[y]==l[z]:
                        c+=1
                      elif l[x]==l[y] or l[y]==l[z]:
                        c+=3
                      else:
                        c+=6
                   
    print(c)

### FIXED CODE ###

n=int(input())
dp=[0]*(10**5)
for x in range(1,10**2):
  for y in range(1,10**2):
    for z in range(1,10**2):
      dp[x**2+y**2+z**2+x*y+y*z+z*x]+=1
for i in range(n):
  print(dp[i+1])
### BUGGY CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N,W = map(int,(input().split()))
ww = []
vv = []

for i in range(N):
	w,v = map(int,(input().split()))
	ww.append(w)
	vv.append(v)

dp =  [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
	weight = ww[i-1]
	value = vv[i-1]
	for j in range(W+1):
		if j >= weight:
			dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight]+value)
		else:
			dp[i][j] = dp[i-1][j]

print(dp[N][W])

### FIXED CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N,W = map(int,(input().split()))
wv = [[] for i in range(4)]


w,v = map(int,(input().split()))
min_w = w
wv[0].append(v)

for i in range(N-1):
	w,v = map(int,(input().split()))
	wv[w-min_w].append(v)

wv[0].sort(reverse=True)
wv[1].sort(reverse=True)
wv[2].sort(reverse=True)
wv[3].sort(reverse=True)
L1 = len(wv[0])
L2 = len(wv[1])
L3 = len(wv[2])
L4 = len(wv[3])

SUM = 0
sum_wv1 = [0]
for i in range(L1):
	SUM += wv[0][i]
	sum_wv1.append(SUM)

SUM = 0
sum_wv2 = [0]
for i in range(L2):
	SUM += wv[1][i]
	sum_wv2.append(SUM)

SUM = 0
sum_wv3 = [0]
for i in range(L3):
	SUM += wv[2][i]
	sum_wv3.append(SUM)

SUM = 0
sum_wv4 = [0]
for i in range(L4):
	SUM += wv[3][i]
	sum_wv4.append(SUM)

ans = 0

for n1 in range(L1+1):
	for n2 in range(L2+1):
		for n3 in range(L3+1):
			for n4 in range(L4+1):
				weight = min_w*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4
				if weight <= W:
					ans = max(ans,sum_wv1[n1]+sum_wv2[n2]+sum_wv3[n3]+sum_wv4[n4])

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

import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


def main():
    n, limit = map(int, input().split())
    jobs = [list(map(int, input().split())) for _ in range(n)]

    for j in jobs:
        j.append(True)

    money = 0

    for d in range(1, limit+1):
        available_jobs = []

        for j in jobs:
            if j[0] <= d:
                available_jobs.append(j)
        
        if available_jobs:
            available_jobs.sort(key=lambda x: x[1], reverse=True)
            for aj in available_jobs:
                if aj[2]:
                    money += aj[1]
                    aj[2] = False
                    break

    print(money)


if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
from collections import deque, defaultdict
from heapq import heappop, heappush
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


def main():
    n, limit = map(int, input().split())
    
    jobs = defaultdict(deque)

    for _ in range(n):
        d, v = map(int, input().split())
        jobs[d].append(v)

    money = 0
    available_jobs = []

    for d in range(1, limit+1):
        if d in jobs:
            for j in jobs[d]:
                heappush(available_jobs, -j)

        if available_jobs:
            money += -heappop(available_jobs)

    print(money)


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

import sys
sys.setrecursionlimit(100000)

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

people = []
lang = [[] for _ in range(m)]

for i in range(n):
  kl = list(map(int, input().split()))
  k = kl[0]
  people.append(kl[1:])
  for l in kl[1:]:
    lang[l-1].append(i)

visited = [False for _ in range(n)]

def dfs(i):
  if visited[i]:
    return
  else:
    visited[i] = True
    for l in people[i]:
      for nexp in lang[l-1]:
        dfs(nexp)

dfs(0)

if all(visited):
  print('YES')
else:
  print('NO')


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def dfs(v):
    used[v] = True
    for _v in adjl[v]:
        if not used[_v]:
            dfs(_v)

n, m = map(int, input().split())
adjl = [[] for v in range(n + m)]
for i in range(n):
    kl = list(map(int, input().split()))
    k = kl[0]
    llist = kl[1:]
    for l in llist:
        adjl[i].append(l + n - 1)
        adjl[l + n - 1].append(i)

used = [False] * (n + m)
dfs(0)

if all(used[:n]):
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

H,W,D = map(int,input().split())
A = [[] for _ in range(H)]
posi = [[]] * (H * W)

for _ in range(H):
  a = list(map(int,input().split()))
  A[_] = a
  for i,j in enumerate(a):
    k = i + 1
    t = _ + 1
    posi[j - 1] = [t,k]


Q = int(input())

for i in range(Q):
  ans = 0
  l,r = map(int,input().split())
  power = 0
  for j in range(l - 1,r - D,D):
    ans += abs(posi[j + D][0] - posi[j][0]) + abs(posi[j + D][1] - posi[j][1])
  print(ans)

### FIXED CODE ###

H,W,D = map(int,input().split())
posi = [[]] * (H * W)

for _ in range(H):
  a = list(map(int,input().split()))
  for i,j in enumerate(a):
    posi[j - 1] = [_ + 1,i + 1]

Q = int(input())

acdist = [0] * (H * W)

for _ in range(0,H * W - D):
  acdist[_ + D] += acdist[_] + abs(posi[_ + D][0] - posi[_][0]) + abs(posi[_ + D][1] - posi[_][1])

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

import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ans = []
for i in range(n):
    a, b = readints()
    for j in range(b):
        ans.append(a)
aannss = sorted(ans)
print(aannss[k-1])


### FIXED CODE ###

import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += abab[i][1]
    if tmp >= k:
        print(abab[i][0])
        break