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

n = int(input())
a_list = list(map(int, input().split()))
ans = 1

for i in range(n):
    ans *= a_list[i]

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


### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
ans = 1

if 0 in a_list:
    print(0)
    exit()

for i in range(n):
    ans *= a_list[i]
    if len(str(ans)) > 19 or ans > 10 ** 18:
        print(-1)
        exit()

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

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()

ans = 0
# a = [INT() for i in range(n)]
a = []
for i in range(n):
    a.append(INT())
l = []
# print(a)

for i in range(n):
    l = []
    for j in range(n):
        if i != j:
            l.append(a[j])
    print(max(l))
        # print(l)
        # print(max(l))

    # print(a[0:i], a[i:n])
    # print(ans)
# 


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()

ans = 0
# a = [INT() for i in range(n)]
a = []
for i in range(n):
    a.append(INT())
l = []
# print(a)

b = sorted(a, reverse=True)
# print(a)
m1 = b[0]
m2 = b[1]
for i in range(n):
    if a[i] != m1:
        print(m1)
    else:
        print(m2)
     




# # for i in range(n):
#     l = []
#     for j in range(n):
#         if i != j:
#             l.append(a[j])
#     print(max(l))
#         # print(l)
#         # print(max(l))

#     # print(a[0:i], a[i:n])
#     # print(ans)
#
### BUGGY CODE ###

import math
A, B, N = map(int, input().split())

d = 0
ans = 0

mid = N//2
if (math.floor((A*mid)/B) - A*math.floor(mid/B)) < (math.floor((A*(mid+1))/B) - A*math.floor((mid+1)/B)):
    for i in range(mid, N+1):
        d = math.floor((A * i) / B) - A * math.floor(i / B)
        if ans <= d:
            ans = d
        else:
            print(ans)
            exit()
else:
    for i in range(0, mid+1):
        d = math.floor((A * i) / B) - A * math.floor(i / B)
        if ans <= d:
            ans = d
        else:
            print(ans)
            exit()

print(ans)

### FIXED CODE ###

import math

A, B, N = map(int, input().split())
print(math.floor((A * min(B-1, N)) / B) - A * math.floor(min(B-1, N) / B))
### BUGGY CODE ###

S = input()

res = 0
for i in range(len(S) - 3):
    for j in range(i + 3, len(S)):
        if int(S[i:j + 1]) % 2019 == 0:
            res += 1

print(res)


### FIXED CODE ###

S = input()[::-1]

res = 0
tmp = [0] * 2019
tmp[0] = 1
sum_of_digits = 0
d = 1

for c in S:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    tmp[sum_of_digits] += 1

for t in tmp:
    res += (t * (t - 1)) // 2

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

n, k, q = list(map(int, input().split()))
p = [k] * n
for _ in range(q):
    a = int(input())
    for j in range(n):
        if j != a - 1:
            p[j] -= 1
for c in p:
    print('Yes' if c > 0 else 'No')

### FIXED CODE ###

n, k, q = list(map(int, input().split()))
pp = [0] * n
for _ in range(q):
    a = int(input())
    pp[a - 1] += 1
for i in range(n):
    print('Yes' if k - (q - pp[i]) > 0 else 'No')
### BUGGY CODE ###

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

R = {}
for s, t in st:
  s -= 1
  t -= 1
  if s in R:
    R[s].append(t)
  else:
    R[s] = [t]

ans = N
for i in range(N - 1):
  DP = [0] * N
  for j in range(N - 2, -1, -1):
    A = []
    su = 0
    for x in R[j]:
      A.append(DP[x] + 1)
      su += A[-1]
    DP[j] = su / len(A)
    if i == j and len(A) != 1:
      DP[j] = (su - max(A)) / (len(A) - 1)

  ans = min(ans, DP[0])
 
print(ans)

### FIXED CODE ###

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

R = {}
for s, t in st:
  s -= 1
  t -= 1
  if s in R:
    R[s].append(t)
  else:
    R[s] = [t]

DP = [0] * N
ans = N
D = [0] * N
for i in range(N - 2, -1, -1):
  ma = 0
  su = 0
  le = len(R[i])
  for j in R[i]:
    su += DP[j]
    ma = max(ma, DP[j])

  DP[i] = su / le + 1 
  if le == 1:
    D[i] = 0
  else:
    D[i] = DP[i] - (((su - ma) / (le - 1)) + 1)

P = [0] * N 
P[0] = 1
ma = 0
man = -1
for i in range(N - 1):
  t = P[i] / len(R[i])
  for j in R[i]:
    P[j] += t 
  t = P[i] * D[i]
  R[i].sort()
  if ma < t:
    ma = t
    man = i
 
if ma == -1:
  print(DP[0])
else:
  print(DP[0] - ma)
### BUGGY CODE ###

import bisect
n,m = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
right = l[-1]*2+1
left = 0
ans = 0
while right - left >1:
    mid = (right+left)//2
    
    x = 0
    for i in range(n):
        a = l[i]
        index = bisect.bisect_left(l,mid-a)
        x += n-index
   
    if x >= m:
        left = mid
    elif m >= x:
        right = mid
ans = []
for i in range(n):
    a = l[i]
    for j in range(n):
        if a + l[j] >= left:
            ans.append(a+l[j])
ans.sort(reverse=True)

print(sum(ans[0:m]))



### FIXED CODE ###

def main():
    import bisect
    import numpy as np
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    l.sort()
    l1 = np.array(l)
    def bise(x):
        y = np.searchsorted(l1,x-l1)
        return n*n-y.sum()

    left = -1
    right = l[-1]*2+1

    while right > left+1:
        mid = (right+left)//2
        
        if bise(mid) >= k:
            left = mid
        else:
            right = mid
    ans = 0
    count = 0
    acc = [0]
    for i in l:
        acc.append(acc[-1]+i)
    for i in l:
        index = bisect.bisect_left(l,right-i)
        ans += i*(n-index) + acc[n]-acc[index]
        count += n-index

    print(ans-(count-k)*left)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():
    # 町の数N, 町iの転送先はindexがAi-1の町
    N,K = map(int, input().split())
    A = list(map(int, input().split()))

    # K回移動した時の町番号を出力
    # もし一度出てきた番号が出てきたら記憶している道順リストを使う
    # 最初は道を覚えさせる作業が必要
    now = 0
    history = [0]
    i = 0
    while i<K:
        # まず進む
        now = A[now]-1
        # 道順登録
        if now not in history:
            history.append(now)
            i+=1
        # 以前出てきてる町ならそこから末尾までを自動で進めてiのカウントも進める
        else:
            start = history.index(now)
            r = start + (K-1-i)%(len(history)-start)
            now = history[r]
            break

    print(now+1)

main()


### FIXED CODE ###

def main():
    # 町の数N, 町iの転送先はindexがAi-1の町
    N,K = map(int, input().split())
    A = list(map(int, input().split()))

    # K回移動した時の町番号を出力
    # もし一度出てきた番号が出てきたら記憶している道順リストを使う
    # 最初は道を覚えさせる作業が必要
    now = 0
    history = [0]
    isVisited = [False for i in range(N)]
    i = 0
    while i<K:
        # まず進む
        now = A[now]-1
        # 道順登録
        #if now not in history:
        if isVisited[now] == False:
            history.append(now)
            isVisited[now] = True
            i+=1
        # 以前出てきてる町ならそこから末尾までを自動で進めてiのカウントも進める
        else:
            start = history.index(now)
            r = start + (K-1-i)%(len(history)-start)
            now = history[r]
            break

    print(now+1)

main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
no_zero_dic = {}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

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


S = str(input())

count = 0
for i in range(len(S)+1):
    for j in range(i+4, len(S)+1):
        s_p = int(S[i:j])
        amari = s_p % 2019
        if amari == 0:
            count = count +1

print(count)


### FIXED CODE ###

s=list(input())[::-1] # 10進数で位を上げていくために反転させる
n=len(s)
amari_lis=[0]*2019 # 
amari_lis[0]=1 # 2019で割り切れる場合、組合せ総数は (n+1)C2 となるため（その他はnC2でOK）

num=0
kurai=1
for keta in s:
    num+=int(keta)*kurai
    num%=2019
    amari_lis[num]+=1
    kurai*=10
    kurai%=2019 # amari_lisが 0~2019 のため、位の数も 2019 で割った余りで考える

ans=0
for i in amari_lis:
    ans+=i*(i-1)/2 # nC2の計算, 余りが同じものを引けば 0⇒2019で割れると言える（組合せ数を逐次追加することで総数算出）

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

N = int(input())
temp = list(map(int, input().split()))
for i in range(N):
  print(temp.index(i+1)+1, end=" ")

### FIXED CODE ###

N = int(input())
temp = list(map(int, input().split()))
b = {}
for i in range(N):
  b[temp[i]] = i+1
c = sorted(b.items(), key=lambda x:x[0])
for i in range(N):
  print(c[i][1], end=" ")
### BUGGY CODE ###

n,q=map(int,input().split())
box=[list(map(int,input().split())) for i in range(n-1)]
point=[list(map(int,input().split())) for i in range(q)]
tree={i+1:[] for i in range(n)}
answer=[0]*n
for x,y in box:
    tree[x] +=[y]
for x,y in point:
    answer[x-1] +=y
for x,y in tree.items():
    for i in y:
        answer[i-1]=answer[x-1]+answer[i-1]

print(*answer)

### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,q = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*n
for _ in range(q):
    p,x = [int(i) for i in readline().split()]
    add[p-1] += x

ans = [0]*n
#ans[0] = add[0]

def dfs(v,p,value): #p: parent of v
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

#print(add)

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

n = int(input())
s = input()
ans = n
for i in range(n):
    cnt = 0
    for j in range(i):
        if s[j] == "W":
            cnt += 1
    for k in range(i + 1, n):
        if s[k] == "E":
            cnt += 1
    
    ans = min(cnt, ans)

print(ans)

### FIXED CODE ###

n = int(input())
s = input()

w_e = [0] * n
e_w = [0] * n
ans = []

for i in range(n - 1):
    if s[i] == 'W':
        w_e[i + 1] = w_e[i] + 1
    else:
        w_e[i + 1] = w_e[i] + 0

for i in range(n - 2, -1, -1): 
    if s[i + 1] == 'E':
        e_w[i] = e_w[i + 1] + 1
    else:
        e_w[i] = e_w[i + 1] + 0

for i in range(n):
    ans.append(w_e[i] + e_w[i])

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

import sys

sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split(' '))

tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    tree[a].append(b)
    tree[b].append(a)
memo = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split(' '))
    memo[p] += x


def dfs(v, par):
    for i in tree[v]:
        if i == par:
            continue
        memo[i] += memo[v]
        dfs(i, v)
dfs(1,-1)

print(*memo[1:])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

memo = [0] * n

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

def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        memo[nv] += memo[v]
        dfs(nv, v)

dfs(0, -1)

print(*memo)
### BUGGY CODE ###

s = input()
n = len(s)
s_cu = [0] * n
counter = [0] * 2019

counter[0] += 1
for i in range(1, n):
    s_cu[i] = int(s[n-i:])
    counter[int(s[n-i-1:]) % 2019] += 1

ans = 0
for i in counter:
    ans += (i * (i - 1)) // 2

print(ans)

### FIXED CODE ###

s = input()
n = len(s)
s_cu = [0] * (n+1)
counter = [0] * 2019
counter[0] += 1
for i in range(n):
    s_cu[i+1] = (int(s[n-i-1]) * pow(10,i,2019) + s_cu[i]) % 2019
    counter[s_cu[i+1]] += 1

ans = 0
for i in counter:
    ans += (i * (i - 1)) // 2

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

import sys
n = int(input())
lis = list(map(int,input().split()))
count = 0
for i,l in enumerate(lis):
    if i == 0:
        count += 1
    else:
        rs_lis = sorted(lis[0:i])
        if rs_lis[0] >= l:
            count += 1
print(count)

### FIXED CODE ###

import sys
n = int(input())
lis = list(map(int,input().split()))
count = 0
mi = 0
for i,l in enumerate(lis):
    if i == 0:
        mi = l
        count += 1
    else:
        if l < mi:
            mi = l
        if mi >= l:
            count += 1
print(count)
### BUGGY CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
edges = ABC[:]


def warshall_floyd(d, n):
    import copy
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for i, d_sub in enumerate(copy.deepcopy(d)):
        for j, j_v in enumerate(d_sub):
            for k, k_v in enumerate(d_sub):
                d[i][j] = min(j_v,k_v + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import itertools
line = R_LIST
for l in itertools.permutations(line):
    #print(l)
    tmp_len = 0
    for a,b in zip(l[:-1], l[1:]):
        tmp_len += shortest[a][b]

    #print(tmp_len)
    ans = min(ans, tmp_len)
print(ans)

### FIXED CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

rest = set(R_LIST[:])

import copy  
def dfs(cost,pre,rest):
    if len(rest) == 0:
        return cost
    
    ret = INT_MAX
    for r in rest:
        if pre == None:
            next_cost = 0
        else:
            next_cost = cost + shortest[pre][r]
        next_rest = copy.copy(rest)
        next_rest.remove(r)
        
        tmp_ret = dfs(next_cost, r, next_rest)
        ret = min(ret, tmp_ret)
        
    return ret
        
    

print(dfs(0, None, rest))
### BUGGY CODE ###

x = int(input())
c = [1]
for i in range(1,x):
	for j in range(2,x):
		if i**j <= x:
			c.append(i**j)
print (max(c))

### FIXED CODE ###

x = int(input())
c = [1]
for i in range(1,x):
	for j in range(2,x):
		if i**j <= x:
			c.append(i**j)
		else:
			break
print (max(c))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

print(dp[n-1][W])        
        
        


### FIXED CODE ###

N,W = map(int,input().split())
INF = 10**9+7
NV = (10**3)*N
dp = [[INF for j in range(NV+1)] for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(NV+1):
        if j < v:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)
ans = 0
for j in range(NV+1):
    if dp[N][j] <= W:
        ans = j
print(ans)
### BUGGY CODE ###

import numpy as np


def read():
    N = int(input().strip())  # N <= 10**5
    edges = dict()
    for i in range(N-1):
        # u[i] < v[i] は保証されている
        u, v, w = list(map(int, input().strip().split()))
        if u - 1 in edges.keys():
            edges[u - 1].update({v - 1: w % 2})
        else:
            edges.update({u - 1: {v - 1: w % 2}})
        if v - 1 in edges.keys():
            edges[v - 1].update({u - 1: w % 2})
        else:
            edges.update({v - 1: {u - 1: w % 2}})
    return N, edges


def solve(N, edges):
    c = np.full((N, ), -1, dtype=np.int32)  # -1: unvisited, 0: white, 1: black
    stack = list()
    c[0] = 0
    stack.append(0)
    while len(stack) > 0:
        s = stack.pop()
        for t in edges[s].keys():
            if c[t] == -1:
                if edges[s][t]:
                    c[t] = 1 - c[s]
                else:
                    c[t] = c[s]
                stack.append(t)
    return c


if __name__ == '__main__':
    inputs = read()
    colors = solve(*inputs)
    for col in colors:
        print("%d" % col)


### FIXED CODE ###

import numpy as np


def read():
    N = int(input().strip())  # N <= 10**5
    to = [[] for _ in range(N)]
    cost = [[] for _ in range(N)]
    for i in range(N-1):
        # u[i] < v[i] は保証されている
        u, v, w = list(map(int, input().strip().split()))
        to[u-1].append(v-1)
        to[v-1].append(u-1)
        cost[u-1].append(w % 2)
        cost[v-1].append(w % 2)
    return N, to, cost


def solve(N, to, cost):
    c = [-1] * N  # -1: unvisited, 0: white, 1: black
    q = list()
    c[0] = 0
    q.append(0)
    while len(q) > 0:
        s = q.pop()
        for t, co in zip(to[s], cost[s]):
            if c[t] == -1:
                if co:
                    c[t] = 1 - c[s]
                else:
                    c[t] = c[s]
                q.append(t)
    return c


if __name__ == '__main__':
    inputs = read()
    colors = solve(*inputs)
    for col in colors:
        print("%d" % col)
### BUGGY CODE ###

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

ans = 0
l2 = []
for i in range(1, M+1):
    tmp = [j[1] for j in list if j[0] == i]
    l2.extend(tmp)
    l2.sort(reverse=True)
    if len(l2) != 0:
        ans += l2.pop(0)

print(ans)


### FIXED CODE ###

from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

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

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

A.sort()
B.sort()
C.sort()

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub
total = 0
for c in C:
    b_ub = bin_search(B, c)
    for _b in B[:b_ub]:
        a_ub = bin_search(A, _b)
        total += len(A[:a_ub])


print(total)


### FIXED CODE ###


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

A.sort()
C.sort()

def bin_search_withR(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

def bin_search_withL(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] > targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search_withR(A, b)
    c_ub, c_lb = bin_search_withL(C, b)
    total += a_ub * (N - c_ub)

print(total)
### BUGGY CODE ###

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

for i in range(K):
    if len(H)!=0:
        H.remove(max(H))
        #print(H)
    else:
        #print(0)
        break
print(sum(H))


### FIXED CODE ###

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

for i in range(K):
    if len(H)!=0:
        H.remove(max(H))
        #print(H)
    else:
        #print(0)
        break
print(sum(H))'''

N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)

print(sum(H[K:]))
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for _ in range(q):
  l,r=map(int,input().split())
  sl=s[l-1:r]
  print(sl.count('AC'))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]
for i in range(1,len(s)):
  a.append(a[i-1]+s[i-1:i+1].count('AC'))
for i in range(q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])
### BUGGY CODE ###

S = input()
Q = int(input())

cnt = 0
ss = " "
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            ss = query[2]+ss
        else:
            ss = ss+query[2]
if cnt%2 == 1:
    S = S[::-1]
    ss = ss[::-1]
print(ss.replace(" ", S))

### FIXED CODE ###

s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))
### BUGGY CODE ###

n = int(input())
s = input()

dp = [set(), set()]

dp[0].add("")
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1].add(j + s[i])

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

dp = [set(), set()]

dp[0].add("")
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1].add(j + s[i])

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)