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

import bisect

N = int(input())

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

A.sort()
C.sort()

ans = 0
for b in B:
    na = len(A[:bisect.bisect_left(A, b)])
    nc = len(C[bisect.bisect_right(C, b):])
    ans += na * nc

print(ans)

### FIXED CODE ###

import bisect

N = int(input())

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

A.sort()
C.sort()
LC = len(C)
ans = 0
for b in B:
    na = bisect.bisect_left(A, b)
    nc = LC - bisect.bisect_right(C, b)
    ans += na * nc

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

def DFS(list,s,t):
    if s==t:
        return True
    if not t in s:
        return False

    for i in list:
        if(DFS(list,s,t+i)): return True
    return False

list=["dream","dreamer","erase","eraser"]
s=input()
t=""
if DFS(list,s,t):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

import sys
def DFS(list,s,t):
    if s==t:
        print("YES")
        sys.exit()
    if not t in s:
        return

    for i in list:
        DFS(list,s,t+i)

list=["maerd","remaerd","esare","resare"]
s=input()
s=s[::-1]
t=""
c_index=0
while True:
    moto=c_index
    for i in list:
        index=0
        temp=c_index
        while index<len(i) and temp<len(s) and i[index]==s[temp]:
            index+=1
            temp+=1
        if index==len(i):
            c_index=temp
            break
    if c_index==len(s):
        print("YES")
        sys.exit()
    if c_index==moto:
        print("NO")
        sys.exit()
### BUGGY CODE ###

a,b,k=map(int,input().split());
for i in range(a,b+1):
 if i<a+k or b-k<i:
  print(i)

### FIXED CODE ###

a, b, k = [int(m) for m in input().split(" ")]

for i in range(a, min(a+k, b+1)):
    print(i)
for i in range(max(b+1-k, a+k), b+1):
    print(i)
### BUGGY CODE ###

from collections import Counter
n = int(input())
s = Counter([input() for i in range(n)])
print(*sorted([k for k, v in s.items() if v == max(s.values())]), sep='\n')

### FIXED CODE ###

n = int(input())
dics = {}
for i in range(n):
    try:
        s = input()
        dics[s] += 1
    except KeyError:
        dics[s] = 1
max_v = max(dics.values())

max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
    print(i)
### BUGGY CODE ###

k,s=map(int,input().split())
ans=0
for i in range(k+1):
  for j in range(k+1):
    for x in range(k+1):
      if i+j+x==s:
        ans+=1

print(ans)

### FIXED CODE ###

k,s=map(int,input().split())
cnt=0
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-(i+j)<=k:
      cnt+=1

print(cnt)
### BUGGY CODE ###

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

out = 0

for i in range(n):
    for j in range(i):
        if(i-j == inList[i] + inList[j]):
            out += 1
print(out)

### FIXED CODE ###

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

ml = [0] * n
pl = [0] * n

out = 0

for i in range(0, n):
    if(i+a[i]<n):
        pl[i+a[i]] += 1
    if(i-a[i]>=0):
        ml[i-a[i]] += 1

for i in range(0, n):
    out += pl[i] * ml[i]

print(out)
### BUGGY CODE ###

n = int(input())

def main():
    ans = [0]*(n+1)
    for x in range(1, n+1):
        for y in range(1, n+1):
            for z in range(1, n+1):
                fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if fn > n:
                    break
                else:
                    ans[fn] += 1

    for i in range(1, n+1):
        print(ans[i])

if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())

def main():
    ans = [0]*(n+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if fn > n:
                    break
                else:
                    ans[fn] += 1

    for i in range(1, n+1):
        print(ans[i])

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

n = int(input())
a = [int(each) for each in input().split()]

result = 0
for i in range(len(a)):
    for j in range(i):
        result += a[i] * a[j] % 1000000007

print(result % 1000000007)

### FIXED CODE ###

n = int(input())
a = [int(each) for each in input().split()]

result = 0
s = sum(a)
for i in range(len(a)):
    s = (s-a[i])
    result += s % 1000000007 * a[i]
print(result % 1000000007)
### BUGGY CODE ###

import functools
N, W = map(int, input().split())
v, w = [0] * N, [0] * N
for i in range(N):
    v[i], w[i] = map(int, input().split())


@functools.lru_cache(maxsize=1 << 20)
def rec(i, weight):
    if i == N:
        return 0
    elif weight + w[i] <= W:
        return max(rec(i+1, weight), rec(i+1, weight + w[i]) + v[i])
    else:
        return rec(i+1, weight)
print(rec(0, 0))

### FIXED CODE ###

N, maxW = map(int, input().split())
V, W = [], []
for i in range(N):
    v, w = map(int, input().split())
    V.append(v); W.append(w)
dp = [[0]*(maxW+1) for _ in range(2)]
for i in range(N):
    for j in range(maxW+1):
        if j < W[i]:
            dp[(i+1)&1][j] = dp[i&1][j]
        else:
            dp[(i+1)&1][j] = max(dp[i&1][j], dp[i&1][j-W[i]] + V[i])
print(dp[N&1][maxW])
### BUGGY CODE ###

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in [0]*m]
for i in range(2,n):
    if [1,i] in l and [i,n] in l:print('POSSIBLE');break
else:print('IMPOSSIBLE')

### FIXED CODE ###

import sys
input = sys.stdin.readline

n,m=map(int,input().split())
a=[]
b=[]
for _ in [0]*m:
    l=list(map(int,input().split()))
    if l[0]==1:a.append(l[1])
    if l[1]==n:b.append(l[0])
print('POSSIBLE' if set(a)&set(b) else 'IMPOSSIBLE')
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

B = A[:]

while len(A) > 1:
    n = (1+len(A))//2
    A = [y//gcd(x,y)*x for x,y in zip(A[:n], A[-n:])]

lcm = A[0]

answer = sum(lcm//x for x in B)
answer %= MOD
print(answer)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(read().split(),np.int64)

MOD = 10 ** 9 + 7

U = 10 ** 6 + 10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3,U,2):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p+p] = 0

M = 10 ** 3
small_primes = np.where(is_prime[:M])[0].tolist()

B = A.copy()
lcm = 1
for p in small_primes:
    e = 0
    while np.any(A % p == 0):
        e += 1
        A[A % p ==0] //= p
    lcm *= p**e
    lcm %= MOD

for x in set(A.tolist()):
    lcm *= x
    lcm %= MOD

answer = sum(pow(x, MOD-2, MOD) for x in B.tolist()) % MOD
answer *= lcm
answer %= MOD
print(answer)
### BUGGY CODE ###

n, m = map(int, raw_input().split())
edges = [[] for _ in range(n)]

nums = []
for i in range(m):
  nums.append(map(int, raw_input().split()))
nums.sort(key=lambda x: x[2])
start_u = nums[0][0] - 1
max_i = nums[0][2] - 1

for item in nums:
  u, v, s = item
  u, v = u-1, v-1
  edges[u].append([v, s])
  edges[v].append([u, s])
i = 1
total = 0

while i <= max_i:
  values = [0] * n
  values[start_u] = i
  q = [[start_u] + t for t in edges[start_u]]
  visited = [False] * n
  visited[start_u] = True
  legal = True
  while q and legal:
    from_to, to_next, vs = q.pop()
    visited[to_next] = True
    if values[to_next] == 0:
      values[to_next] = vs - values[from_to]
      if values[to_next] <= 0:
        legal = False
      else:
        for item in edges[to_next]:
          if visited[item[0]] == False:
            q.append([to_next, item[0], item[1]])
    elif values[to_next] == vs - values[from_to]:
      for item in edges[to_next]:
          if visited[item[0]] == False:
            q.append([to_next, item[0], item[1]])
    else:
      legal = False
  i += 1
  if legal:
    total += 1
  else:
    if total > 0:
      break
print(total)



### FIXED CODE ###

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

setrecursionlimit(10**6)
n, m = map(int, raw_input().split())
edges = [[] for _ in range(n)]

for i in range(m):
  u, v, s = map(int, raw_input().split())
  u, v = u-1, v-1
  edges[u].append((s, v))
  edges[v].append((s, u))

def quit(x):
  print(x)
  exit()

cond = [[None] * n for _ in range(2)]
cond[0][0] = 0

INF = 10**16

visited = [False] * n

def walk(x):
  if visited[x]:
    return
  visited[x] = True
  for s, y in edges[x]:
    for sig in range(2):
      if cond[sig][x] is not None:
        p = cond[sig][x]
        if cond[1-sig][y] is None or cond[1-sig][y] == s - p:
          cond[1-sig][y] = s - p
        else:
          quit(0)
    walk(y)

walk(0)

for i in range(n):
  if cond[0][i] is not None and cond[1][i] is not None:
    x = (cond[1][i] - cond[0][i]) // 2
    for j in range(n):
      if cond[0][j] is not None and cond[0][j] + x <= 0:
        quit(0)
      if cond[1][j] is not None and cond[1][j] - x <= 0:
        quit(0)
      if cond[0][j] is not None and cond[1][j] is not None and x + cond[0][j] != cond[1][j] - x:
        quit(0)
    quit(1)

pmin = min(p for p in cond[0] if p is not None)
nmin = min(p for p in cond[1] if p is not None)

print(max(0, nmin + pmin - 1))
### BUGGY CODE ###

n = int(input())
dic = dict()

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

# print(dic)
# dic2 = sorted(dic.items(), key=lambda x:x[1])
# print(max(dic.values()))
# print(max(dic, key=dic.get))
#
# print(dic.items())

ans = []
for kv in dic.items():
    if kv[1] == max(dic.values()):
        ans.append(kv[0])

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

### FIXED CODE ###

n = int(input())
dic = dict()

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

ans = []
val = max(dic.values())
for kv in dic.items():
    if kv[1] == val:
        ans.append(kv[0])

ans = sorted(ans)
for a in ans:
    print(a)
### BUGGY CODE ###

n,q = map(int, input().split())
s = "#" + input() + "#"
l = [tuple(input().split()) for _ in range(q)]
d = {"L":-1, "R":1}
def move(x):
  for i in l:
    if i[0] == s[x]:
      x += d[i[1]]
    if x in [0,n+1]:
      break
  return x
def isr(x):
  if move(x) == n+1:
    return True
  else:
    return False
def isl(x):
  if move(x) == 0:
    return True
  else:
    return False
hi1,hi2 = n+1,n+1
lo1,lo2 = 0,0
while hi1-lo1>1:
  mid1 = (hi1+lo1)//2
  if isr(mid1):
    hi1 = mid1
  else:
    lo1 = mid1
while hi2-lo2>1:
  mid2 = (hi2+lo2)//2
  if isl(mid2):
    lo2 = mid2
  else:
    hi2 = mid2
print(max(hi1-lo2-1,0))

### FIXED CODE ###

n,q = map(int, input().split())
s = "#" + input() + "#"
l = [tuple(input().split()) for _ in range(q)]
def move(x,g):
  for i in l:
    if i[0] == s[x]:
      x += (i[1]=="R") or -1
  return x==g
hi1 = n+1
lo1,lo2 = 0,0
while hi1-lo1>1:
  mid1 = (hi1+lo1)//2
  if move(mid1,n+1):
    hi1 = mid1
  else:
    lo1 = mid1
hi2 = hi1
while hi2-lo2>1:
  mid2 = (hi2+lo2)//2
  if move(mid2,0):
    lo2 = mid2
  else:
    hi2 = mid2
print(hi1-lo2-1)
### BUGGY CODE ###

# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数を２つのグループに分ける

import itertools

def main():
  a, b = map(int, input().split())
  c = gojo(a,b)
  
  fac = [1]
  fac = facto(c, fac)
  # print(fac)
  print(len(fac))  
  
def facto(n, fac):
  if n == 1:
    return [1]
  if n == 2:
    return[1, 2]
  if n % 2 == 0:
    fac = [1, 2]
  else:
    fac = [1]
  
  max_n = n + 1 #int(n ** 0.5 + 2)
  
  is_prime = [True for x in range(max_n)]
  for cursor in range(3, max_n, 2):
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
      
  return fac
  
def gojo(a,b):
  if b > a:
    a, b = b, a
  c = a % b
  if c == 0:
    return(b)
  else:
    return gojo(b, c)

if __name__ == "__main__":
  main()


### FIXED CODE ###

# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素数＋１が答え

import itertools
from fractions import gcd
from math import ceil

def main():
  a, b = map(int, input().split())
  fac = facto(gcd(a,b))
  print(len(fac))  
  
def facto(n):
  fac = [1]
  if n == 1:
    return [1]
  elif n % 2 == 0:
    fac = [1, 2]
    while n % 2 == 0:
      n = n // 2
  
  max_n = ceil(n ** 0.5) + 1
  
  is_prime = [True for x in range(max_n)]
  for cursor in range(3, max_n, 2):
    if is_prime[cursor]:
      if n % cursor == 0:
        fac.append(cursor)
        while n % cursor == 0:
          n = n // cursor
        if n == 1:
          break
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    fac.append(n)
  return fac

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

def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=dict(Counter(x))
  cxmod=dict(Counter(xmod))
  keys=list(cxmod.keys())
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



### FIXED CODE ###

def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import heapq
import sys
sys.setrecursionlimit(10**9)

# 全頂点からのゴールへの到達可能性を確認
# 頂点1からDFSしてNまできたら、それまでのパス全てについて到達可能に更新
# その後、到達可能な部分のみを新たな辺にして、ベルマンフォード
# 辺の重みは（C - P）
# 負閉路を検出したなら-1
# そうでなければNまでの距離


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

Edge = [[] for _ in range(N)]
for a,b,c in ABC:
    Edge[b-1].append(a-1)


reachable = [False]*N
reachable[N-1] = True

def dfs(v):
    for nv in Edge[v]:
        if reachable[nv]:
            continue
        else:
            reachable[nv] = True
            dfs(nv)
    return 

def BellmanFord(s, N, Edge):
    INF = 10**20
    dist = [INF] * N
    dist[s] = 0
    for i in range(N):
        isUpdated = False
        for t in range(N):
            if dist[t] == INF:
                continue
            for v,c in Edge[t]:
                if dist[t]+c < dist[v]:
                    dist[v] = dist[t]+c
                    isUpdated = True
        if not isUpdated:
            break
        elif i==N-1:
            return -1
    return dist

                
dfs(N-1)
newEdge = [[] for _ in range(N)]
for a,b,c in ABC:
    if reachable[a-1]:
        newEdge[a-1].append([b-1, P-c])

dist = BellmanFord(0, N, newEdge)
if dist==-1:
    print(-1)
else:
    print(max(0, -dist[N-1]))






### FIXED CODE ###

# -*- coding: utf-8 -*-
import heapq
import sys
sys.setrecursionlimit(10**9)

# 全頂点からのゴールへの到達可能性を確認
# 頂点1からDFSしてNまできたら、それまでのパス全てについて到達可能に更新
# その後、到達可能な部分のみを新たな辺にして、ベルマンフォード
# 辺の重みは（C - P）
# 負閉路を検出したなら-1
# そうでなければNまでの距離


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

Edge = [[] for _ in range(N)]
for a,b,c in ABC:
    Edge[b-1].append(a-1)


reachable = [False]*N
reachable[N-1] = True

def dfs(v):
    for nv in Edge[v]:
        if reachable[nv]:
            continue
        else:
            reachable[nv] = True
            dfs(nv)
    return 

def BellmanFord(s, N, Edge):
    INF = 10**20
    dist = [INF] * N
    dist[s] = 0
    for i in range(N):
        isUpdated = False
        for t in range(N):
            if dist[t] == INF:
                continue
            for v,c in Edge[t]:
                if dist[t]+c < dist[v]:
                    dist[v] = dist[t]+c
                    isUpdated = True
        if not isUpdated:
            break
        elif i==N-1:
            return -1
    return dist

                
dfs(N-1)
newEdge = [[] for _ in range(N)]
for a,b,c in ABC:
    if reachable[a-1]:
        newEdge[a-1].append([b-1, P-c])

dist = BellmanFord(0, N, newEdge)
if dist==-1:
    print(-1)
else:
    print(max(0, -dist[N-1]))
### BUGGY CODE ###

import operator
from functools import reduce

N = int(input())
A = input().split()

length = len(A)

list = []

for num in range(length):
    list.append(int(A[num]))

result = reduce(operator.mul, list, 1)

max = 10**18

if result <= max:
    print(result)
else:
    print("-1")

### FIXED CODE ###

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr) #配列を昇順ソートしておく(配列に0がある場合0が先頭に来るので、場合分けの必要がなくなる)
ans=1
for val in arr:
 ans*=val #Pythonは多倍長整数をサポートしているので単に積を求めれば十分
 if ans>10**18:
   print(-1)
   break
else:
 print(ans)
### BUGGY CODE ###

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

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while pow(g, n) <= p:
        if p % pow(g, n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)



### FIXED CODE ###

def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

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

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

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

def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    def lcm(a, b):
        return a * b // gcd(a, b)

    l = reduce(lcm, A)
    ans = [(l // a) % MOD for a in A]
    return sum(ans) % MOD

print(e_flatten())

### FIXED CODE ###

def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

    def lcm(a, b):
        return a * b // gcd(a, b)

    def inv(n, mod=MOD):
        return pow(n, mod - 2, mod)

    l = reduce(lcm, A) % MOD
    ans = [(l * inv(a)) % MOD for a in A]
    return sum(ans) % MOD

print(e_flatten())
### BUGGY CODE ###

x = input().split()
y = []
member = [int(x[1])] * int(x[0])
for i in range(int(x[2])):
  tmp = input()
  y.append(int(tmp))

for l in y:
  for i,point in enumerate(member):
    if (l-1) != i:
      member[i] = (point -1)
      
for z in member:
  if z > 0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

x = input().split()
member = [int(x[1])] * int(x[0])

for l in range(int(x[2])):
  y = input()
  member[int(y) - 1] += 1
      
for z in member:
  if (z - int(x[2])) > 0:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])
### BUGGY CODE ###

n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.extend([a] * b)
a_list.sort()
print(a_list[k-1])

### FIXED CODE ###

n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append([a, b])
a_list.sort(key=lambda x: x[0])
for i in range(n):
	k -= a_list[i][1]
	if k <= 0:
		print(a_list[i][0])
		break
### BUGGY CODE ###

N = int(input())
a_list = list(map(int, input().split()))
for i in range(1,N+1):
    print(a_list.count(i))

### FIXED CODE ###

N = int(input())
a_list = list(map(int, input().split()))
a_list = [ (i+2, s) for i, s in enumerate(a_list) ]
a_list = sorted(a_list, key=lambda x: x[1])
count = 0
boss = 1
for a in a_list:
    if a[1] == boss:
        count += 1
    else:
        diff = a[1] - boss
        for _ in range(diff):
            print(count)
            count = 0
        boss = a[1]
        count += 1

for _ in range(N - a_list[-1][1]+1):
    print(count)
    count = 0
### BUGGY CODE ###

a=input()
b=input().split(" ")
sum1=1

for i in range(int(a)):
	sum1=sum1*int(b[i])

if sum1>10**18:
	print("-1")
else:
	print(sum1)


### FIXED CODE ###

a=int(input())
b=input().split(" ")
sum1=1

if "0" in b:
	print("0")
else:
	for i in range(a):
		sum1=sum1*int(b[i])
		if sum1>10**18:
			sum1=-1
			break
	print(sum1)
### BUGGY CODE ###

import heapq
import numpy as np

N, M = [int(x) for x in input().split(" ")]

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * -1
# prev = np.ones(N, dtype=int) * -1
# q = [(d[0], 0)]
# heapq.heapify(q)

# while len(q) != 0:
#   c, u = heapq.heappop(q)
#   for nv in e[u]:
#     alt = d[u] + 1
#     if d[nv] > alt:
#       d[nv] = alt
#       prev[nv] = u
#       heapq.heappush(q, (alt, nv))

q = [0]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
      q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in d[1:]]))


### FIXED CODE ###

import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    if i == n - 1:
        ans = max(a[:i])
    elif i == 0:
        ans = max(a[1:])
    else:
        ans = max(max(a[:i]), max(a[i+1:]))
    print(ans)

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
sorted_a = []
for item in a:
    sorted_a.append(item)
sorted_a.sort(reverse=True)
for num in a:
    if num == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])