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

from fractions import gcd
K = int(input())
ans = 0

for i in range(1, K + 1):
    ans += gcd(gcd(i, i), i)
    for j in range(1, K + 1):
        if i != j:
            ans += gcd(gcd(i, i), j)*3

for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        for l in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), l)*6

print(ans)


### FIXED CODE ###

from math import gcd
K = int(input())
ans = 0

for i in range(1, K + 1):
    ans += gcd(gcd(i, i), i)
    temp = gcd(i, i)
    for j in range(1, K + 1):
        if i != j:
            ans += gcd(temp, j)*3

for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        for l in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), l)*6

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

def f(n,m):
     a = list(map(int,input().split()))
     min_a = min(a)
     a = [(1,i) for i in a]
     for i in range(m):
          b_c = tuple(map(int,input().split()))
          if b_c[1]>min_a:
               a.append(tuple(b_c))
     a.sort(reverse=True,key=lambda x:x[1])
     ans = 0
     while True:
          if n>a[0][0]:
               ans += a[0][0]*a[0][1]
               n -= a[0][0]
               a.pop(0)
          else:
               ans += a[0][1]*n
               break
     print(ans)

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

### FIXED CODE ###

def f(n,m):
     a = list(map(int,input().split()))
     min_a = min(a)
     a = [(1,i) for i in a]
     b_c = [tuple(map(int,input().split())) for i in range(m)]
     a += b_c
     a.sort(key=lambda x:x[1])
     ans = 0
     while True:
          if n>a[-1][0]:
               ans += a[-1][0]*a[-1][1]
               n -= a[-1][0]
               a.pop()
          else:
               ans += a[-1][1]*n
               break
     print(ans)

n,m = map(int,input().split())
f(n,m)
### BUGGY CODE ###

import itertools

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

def count_step(n):
    num=n//2
    count=0
    for i in range(num+1):
        step=[]
        for _ in range(n-2*i):
            step.append(1)
        for _ in range(i):
            step.append(2)
        count+=len(list(itertools.combinations(step,i)))
    return count

if M!=0:
    a2=[a[0]-1]
    
    for i in range(M-1):
        p=a[i+1]-a[i]-2
        
        a2.append(p)
    
    a2.append(N-a[M-1]-1)

p=1
for i in range(M-1):
    if a[i]+1==a[i+1]:
        p=0
        break

if p==0:
    pattern=0
else:
    pattern=1
    if M==0:
        pattern=count_step(N)
    else:
        for i in range(len(a2)):
            pattern*=count_step(a2[i])

print(pattern%1000000007)

### FIXED CODE ###

N,M=map(int,input().split())
a=[0]
for _ in range(M):
    a.append(int(input()))

b=[]
num=0
if len(a)>1:
    b.append(a[1]-a[0]-1)
    for i in range(1,M):
            b.append(a[i+1]-a[i]-2)
    b.append(N-a[M]-1)
else:
    b.append(N)

num=max(b)


mod=1000000007

def fib(n,num):
    fib=[0 for i in range(num+10)]
    fib[0]=1
    fib[1]=1
    for i in range(2,num+1):
        fib[i]=fib[i-1]+fib[i-2]
    return fib[n]

if -1 in b:
    print(0)
else:
    p=1
    for j in range(M+1):
        p*=fib(b[j],num)
    print(p%mod)
### BUGGY CODE ###

N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 != 0:
            continue
        elif a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
            break

    if cnt == 0:
        flag = False
    else:
        ans += 1

print(ans)


### FIXED CODE ###

N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    ans += len(bin(a[i])) - bin(a[i]).rfind('1') - 1
print(ans)
### BUGGY CODE ###

n, k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
between = [h[i+1]-h[i] for i in range(n-1)]
answer = 10**9
for i in range(n-k+1):
  answer = min(answer, sum(between[i: i+k-1]))
  
print(answer)

### FIXED CODE ###

n, k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
between = [h[i+1]-h[i] for i in range(n-1)]
answer = 10**9
for i in range(1,n-1):
  between[i] += between[i-1]
between.insert(0,0)

for i in range(n-k+1):
  answer = min(answer, between[i+k-1]-between[i])
  
print(answer)
### BUGGY CODE ###

import math

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            wa += math.gcd(math.gcd(a,b),c)


print(wa)


### FIXED CODE ###

import math
from functools import reduce
import sys
sys.setrecursionlimit(2000000)

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            li = [a,b,c]
            wa += reduce(math.gcd,li)*6

for a in range(1,k+1):
    for b in range(a+1,k+1):
        wa += math.gcd(a,b)*6

for a in range(1,k+1):
    wa += a
    

print(wa)
### BUGGY CODE ###

l,r = map(int,input().split())

a = []
#r = min(r,l+2019)
for i in range(l,r):
    for j in range(i+1,r+1):
        a.append(i*j%2019)

print(min(a))
        


### FIXED CODE ###

l,r = map(int,input().split())

a = []
r = min(r,l+2019)
for i in range(l,r):
    for j in range(i+1,r+1):
        a.append(i*j%2019)

print(min(a))
### BUGGY CODE ###

import numpy as np
import math

# input

N = int(input())
s = [str(input()) for _ in range(N)]

# sort
for i in range(0,N):
    s[i] = sorted(s[i])
    
count = 0 
for i in range(N):
    for j in range(i+1,N):
        if (s[i] == s[j]):
            count += 1

print(count)


### FIXED CODE ###

import numpy as np

def Speed_Anag_Count(String):
    count = {}
    for i in String:
        i = sorted(i)
        i = str(''.join(i))
        if count.get(i) is None:
            count[i] = 0
        count[i] += 1
    
    return count

N = int(input())

S = [str(input()) for _ in range(N)]

count = Speed_Anag_Count(S)

ans=0
for i in count.values():
    ans += (i*(i-1)/2)
    
print(int(ans))
### BUGGY CODE ###

import heapq
n,k = map(int,input().split())
c = []
heapq.heapify(c)
for i in range(n):
    a,b = map(int,input().split())
    c+=([a]*b)
l = heapq.nsmallest(k,c)
print(l[-1])


### FIXED CODE ###

import heapq
n,k = map(int,input().split())
d = {}
z = []
for i in range(n):
    a,b = map(int,input().split())
    z.append([a,b])
    d[a] = 0
for i in range(len(z)):
    d[z[i][0]]+=z[i][1]
c = sorted(d.keys())
l=0
for i in range(len(c)):
    if(k<=0):
        print(c[i-1])
        l+=1
        break
    k-=d[c[i]]
if(l!=1):
    print(c[-1])
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
S=''
for i in range(1,n+1):
  S+=str(A.index(i)+1)+' '
print(S)

### FIXED CODE ###

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

K,N = map(int,input().split())
li = list(map(int,input().split()))
#反時計回りか時計回りの合計距離を、個数出して比較
for i in range(N):#i番目の家を出発地にした時の最小距離を順に求めていく
  iti_t=i#初期位置
  iti_h=i#初期位置
  lon_t=0
  lon_h=0
  for j in range(N-1):#初期位置から進めていく
    if iti_t !=(N-1):
      lon_t+=li[iti_t+1]-li[iti_t]
      iti_t+=1
    else:#位置がN-1のとき
      lon_t+=li[0]+K-li[N-1]
      iti_t=0
    if iti_h !=0:
      lon_h+=li[iti_h]-li[iti_h-1]
      iti_h-=1
    else:#位置が0のとき
      lon_h+=li[0]+K-li[N-1]
      iti_h=N-1
  if i==0:
    res=min([lon_h,lon_t])
  else:
    res=min(res,min([lon_h,lon_t]))
print(res)

### FIXED CODE ###

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

result = A[0] - A[N - 1] + K
for i in range(N - 1):
    result = max(result, A[i + 1] - A[i])
print(K - result)
### BUGGY CODE ###

#https://www.slideshare.net/chokudai/union-find-49066733
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * self.n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y: return False
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x
        
  def issame(self, x, y):
    return self.find(x) == self.find(y)
  
  def get_node_members(self):
    return [[j for j in range(self.n) if self.issame(i, j)] for i in range(self.n)]
  
  def size(self, x):
    return -self.parents[self.find(x)]
  
N = list(map(int, input().split()))
uf = UnionFind(N[0])
results = [[] for i in range(N[0])]
for i in range(N[1]):
  x, y = list(map(int, input().split()))
  x, y = x - 1, y - 1
  results[x].append(y)
  results[y].append(x)
  uf.union(x, y)
#print(uf.parents)

for i in range(N[2]):
  x, y = list(map(int, input().split()))
  x, y = x - 1, y - 1
  results[x].append(y)
  results[y].append(x)
  
node_members = uf.get_node_members()
#print(node_members, results)

print(" ".join([str(len(set(node_members[i]) - set(results[i]) - set([i]))) for i in range(N[0])]))

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

#https://www.slideshare.net/chokudai/union-find-49066733
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * self.n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y: return False
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x
        
  def issame(self, x, y):
    return self.find(x) == self.find(y)
  
  def get_node_members(self):
    return [[j for j in range(self.n) if self.issame(i, j)] for i in range(self.n)]
  
  def size(self, x):
    return -self.parents[self.find(x)]

N = list(map(int, input().split()))
parents = [-1] * N[0]
def find(x):
  if parents[x] < 0:
    return x
  else:
    parents[x] = find(parents[x])
    return parents[x]

def union(x, y):
  x = find(x)
  y = find(y)

  if x == y: return False
  if parents[x] > parents[y]:
    x, y = y, x
  parents[x] += parents[y]
  parents[y] = x
        
def issame(x, y):
  return find(x) == find(y)
  
def size(x):
  return -parents[find(x)]
  

results = [0 for i in range(N[0])]
for i in range(N[1]):
  x, y = list(map(int, input().split()))
  x, y = x - 1, y - 1
  results[x] += 1
  results[y] += 1
  union(x, y)
#print(uf.parents)

for i in range(N[2]):
  x, y = list(map(int, input().split()))
  x, y = x - 1, y - 1
  if issame(x, y):
  	results[x] += 1
  	results[y] += 1
  
#print(node_members, results)

print(" ".join([str(size(i) - results[i] - 1) for i in range(N[0])]))
### BUGGY CODE ###

n, m = map(int, input().split())
if 2*n >= m:
    print(int(m/2))
else:
    while True:
        if 2*n < m:
            n = n + 1
            m = m - 2
        else:
            print(int(m/2))
            break


### FIXED CODE ###

n, m = map(int, input().split())
if 2*n >= m:
    print(int(m/2))
else:
    print((2*n + m)//4)
### BUGGY CODE ###

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


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
count_AC = [0]
tmp = 0
for i in range(1, len(S)):
    if S[i - 1] + S[i] == 'AC':
        tmp += 1
    count_AC.append(tmp)
for i in range(Q):
    l, r = map(int, input().split())
    print(count_AC[r-1] - count_AC[l-1])
### BUGGY CODE ###

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

LR = {}
for i in range(M):
  L, R = map(int, input().split())
  if L in LR:
    LR[L].append(R)
  else:
    LR[L] = [R]

for r in LR.values():
  r.sort()

for i in range(Q):
  p, q = map(int, input().split())
  s = 0
  for i in range(p,q+1):
    if i not in LR: continue
    for j in LR[i]:
      if q < j: break
      s += 1
  print(s)

### FIXED CODE ###

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

LR = [[0]*(N+2-i) for i in range(N+2)]
for i in range(M):
  L, R = map(int, input().split())
  LR[L][R-L+1] += 1

  
for i in range(2,N+2):
  for j in range(1,N-i+2):
    LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
    
for i in range(Q):
  p, q = map(int, input().split())
  print(LR[p][q-p+1]-LR[q+1][0])
### BUGGY CODE ###

H, W =  map(int, input().split())

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.append(gc)

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in reversed(gc):
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        gn.reverse()
        Gn.append(gn)

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(ans)

### FIXED CODE ###

H, W =  map(int, input().split())

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i in range(w):
        if i == 0:
            Gc[:, i] = Gs[:, i]
        else:
            Gc[:, i] = (Gc[:, i-1] + 1) * Gs[:, i]

    return Gc

Gs1 = np.asarray(S) == "."
Gn1 = count_light(Gs1, H, W)

Gs2 = np.rot90(Gs1, k=1)
Gn2 = count_light(Gs2, W, H)

Gs3 = np.rot90(Gs2, k=1)
Gn3 = count_light(Gs3, H, W)

Gs4 = np.rot90(Gs3, k=1)
Gn4 = count_light(Gs4, W, H)

Gn2 = np.rot90(Gn2, k=-1)
Gn3 = np.rot90(Gn3, k=-2)
Gn4 = np.rot90(Gn4, k=-3)

Gsum = Gn1+Gn2+Gn3+Gn4
ans = int(np.max(Gsum)-3)
print(ans)
### BUGGY CODE ###

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
LR = np.zeros((N+1, N+1))

for _ in range(M):
    l, r = map(int, input().split())
    np.add.at(LR, (l,r), 1)

np.cumsum(LR, axis = 0, out = LR)
np.cumsum(LR, axis = 1, out = LR)
    
for _ in range(Q):
    p, q = map(int, input().split())
    print(int(LR[q,q] - LR[p-1,q] - LR[q,p-1] + LR[p-1,p-1]))

### FIXED CODE ###

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
LR = np.zeros((N+1, N+1))

for _ in range(M):
    l, r = map(int, input().split())
    LR[l,r] += 1

np.cumsum(LR, axis = 0, out = LR)
np.cumsum(LR, axis = 1, out = LR)
    
for _ in range(Q):
    p, q = map(int, input().split())
    print(int(LR[q,q] - LR[p-1,q] - LR[q,p-1] + LR[p-1,p-1]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
x,y,z,k = map(int, input().split())
 
# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
 
a.sort()
b.sort()
c.sort()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = [[-1,-1,-1,-1] for i in range(3*k)]
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1,-1]
    for j in t:
        if ma <= j[0] :
            temp = j
            ma = j[0]
#    print(temp)
    print(temp[0])
    t[t.index(temp)][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in t:
            if temp[1]-1 == j[1] and temp[2]==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]-1==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]==j[2] and temp[3]-1==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1


### FIXED CODE ###

# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
x,y,z,k = map(int, input().split())
 
# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
b.sort()
c.sort()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))
### BUGGY CODE ###

import bisect

N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()])

min_A = A[0]

for _ in range(M) :
    B, C = map(int, input().split())
    if C > min_A :
        for _ in range(B) :
            bisect.insort_left(A, C)
        A = A[B:]
        min_A = A[0]

print(sum(A))


### FIXED CODE ###

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

BC.sort(key=lambda x: x[1], reverse=True)

i = 0
res = 0

for B, C in BC :
    if i + B <= N :
        res += C * B
        i += B
    else :
        res += C * (N - i)
        break

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

S = input()

for i in range(60000):
    S = S.replace("ST","")

print(len(S))


### FIXED CODE ###

X = input()
N = len(X)
S = 0
ans = 0
for i in range(N):
    if X[i] == 'S':
        S += 1
    elif S > 0:
        S -= 1
        ans += 2
        
print(N - ans)
### BUGGY CODE ###

import math
k=int(input())
ans=0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)
            

### FIXED CODE ###

import math
k=int(input())
ans=0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)
### BUGGY CODE ###

import copy
n = int(input())
a_list = [ int(input()) for _ in range(n)]
for i, a in enumerate(a_list):
  tmp_list = copy.copy(a_list)
  tmp_list.pop(i)
  max_val = max(tmp_list)
  print(max_val)
  

### FIXED CODE ###

import copy
n = int(input())
a_list = [ int(input()) for _ in range(n)]
max_val = max(a_list)
index = [a_list.index(max_val)]
tmp_list = copy.copy(a_list)
for i, a in enumerate(a_list):
  if 2 <= len(index):
    print(max_val)
  elif i in index:
    tmp_list.pop(i)
    print(max(tmp_list))
    tmp_list = copy.copy(a_list)
  else:
    print(max_val)
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
for i in range(1,N):
    if P[i]==min(P[0:i+1]):
        count+=1
print(count+1)


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
min=2*10**5
for i in range(N):
    if P[i]<=min:
        min=P[i]
        count+=1
print(count)
### BUGGY CODE ###

m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 5000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")

### FIXED CODE ###

n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")
### BUGGY CODE ###

a = list(map(int,input().split()))
ans=0
for k in range(a[1],a[0]+2):
    min=0
    max=0
    for i in range(k):
        min +=i
    for i in range(k):
        max +=a[0]-i
    if min<=max:
        ans = ans+ max-min+1

print(ans)

### FIXED CODE ###

a = list(map(int,input().split()))
ans=0
min=0
max=0
for i in range(a[1]):
    min +=i
    max +=a[0]-i
    minx=i-1
    maxx=a[0]-i-1
ans=max-min+1
for i in range(a[1]+1,a[0]+2):
    minx +=1
    min += minx
    maxx += -1
    max +=maxx
    ans=(ans+max-min+1)%(10**9+7)
print(ans)
### BUGGY CODE ###

from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    lis = list(map(int,input().split()))
    ans = Counter(lis)
    for j in range(n):
        su = 0
        for k, v in ans.items():
            if k == lis[j]:
                su += (v - 2) * (v - 1) // 2
            else:
                su += (v - 1) * v // 2
        print(su)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    lis = list(map(int,input().split()))
    d = Counter(lis)
    su = 0
    for e in d:
        su += (d[e] - 1) * d[e] // 2

    for e in lis:
        if d[e] <= 1:
            print(su)
        else:
            k = d[e]
            res = su - k*(k-1)//2 + (k-1)*(k-2)//2
            print(res)

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

N = int(input())
S =[]
times = {}
for i in range(N):
  word = input()
  if word in times:
    times[word] = times[word] + 1
  else:
    times[word] = 1
max_k_list = [kv[0] for kv in times.items() if kv[1] == max(times.values())]
new_str_list = sorted(max_k_list)
for i in new_str_list:
  print(i)



### FIXED CODE ###

N = int(input())
S =[]
times = {}
for i in range(N):
  word = input()
  if word in times:
    times[word] = times[word] + 1
  else:
    times[word] = 1
m = max(times.items(), key = lambda x:x[1])[1]
a = []
for t in times.items():
	if(t[1]==m):
		a.append(t[0])
 
a.sort()
for t in a:
	print(t)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=[]
    for i in range(n):
        a,b=map(int, input().split())
        for j in range(b):
            l.append(a)
    l.sort()
    print(l[k-1])
resolve()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    l.sort(key=lambda x:x[0])
    kosu=0
    for i in range(n):
        kosu+=l[i][1]
        if kosu>=k:
            print(l[i][0])
            break
resolve()