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

def main():
    from bisect import bisect_left
    from array import array
    I=10**9+1
    n,*t=open(0)
    n,q=map(int,n.split())
    d=[-I]+list(map(int,t[n:]))+[I]
    N0=2**(q+1).bit_length()
    data=array('I',[I]*2*N0)
    for x,t,s in sorted(list(map(int,t.split()))[::-1]for t in t[:n])[::-1]:
        l=bisect_left(d,s-x)
        r=bisect_left(d,t-x)
        L,R=l+N0,r+N0
        while L<R:
            if R&1:
                R-=1
                data[R-1]=x
            if L&1:
                data[L-1]=x
                L+=1
            L>>=1
            R>>=1
    for k in range(q):
        k+=N0
        s=I
        while k+1:
            if data[k]<s:s=data[k]
            k=~-k//2
        print(-(s==I)or s)
if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    from bisect import bisect_left
    def update(l,r,v):
        L,R=l+N0,r+N0
        while L<R:
            if R&1:
                R-=1
                data[R-1]=v
            if L&1:
                data[L-1]=v
                L+=1
            L>>=1
            R>>=1
    def query(k):
        k+=N0-1
        s=10**18
        while k+1:
            if data[k]<s:s=data[k]
            k=~-k//2
        return s
    n,*t=open(0)
    n,q=map(int,n.split())
    d=[-10**18]+list(map(int,t[n:]))+[10**18]
    N0=2**(q+1).bit_length()
    data=[10**18]*2*N0
    for x,t,s in sorted(list(map(int,t.split()))[::-1]for t in t[:n])[::-1]:
        l=bisect_left(d,s-x)
        r=bisect_left(d,t-x)
        update(l,r,x)
    for i in range(q):
        a=query(i+1)
        print(-(a==10**18)or a)
if __name__=='__main__':
    main()
### BUGGY CODE ###

from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    s=readline().strip()
    n=len(s)

    dp=np.zeros((n,13),dtype=np.int64)
    tmp1=np.array(range(10),dtype=np.int64)%13
    keta=10
    for i in range(n-1,-1,-1):
        if i==n-1:
            if s[i]=="?":
                dp[i,0:10]=1
            else:
                dp[i][int(s[i])]=1
        else:
            if s[i]=="?":
                tmp2=(keta*tmp1)%13
            else:
                tmp2=(keta*int(s[i]))%13
            for j in range(13):
                dp[i][(tmp2+j)%13]+=dp[i+1][j]
            dp[i]%=mod
            keta*=10
            keta%=13

    print(dp[0][5])

if __name__=="__main__":
    main()

### FIXED CODE ###

#import numpy as np
def main():
    S=input()
    #dp=np.zeros((len(S)+1,13),dtype=int)
    dp=[[0]*13 for _ in range(len(S)+1)]
    dp[0][0]=1
    mod=10**9+7
    """
    for i in range(1,len(S)+1):
        for a in range(13):
            if S[i-1]=="?":
                if a*10%13<(a*10+10)%13:
                    dp[i][a*10%13:(a*10+10)%13]+=dp[i-1][a]
                    dp[i][a*10%13:(a*10+10)%13]%=mod
                else:
                    dp[i][a*10%13:]+=dp[i-1][a]
                    dp[i][a*10%13:]%=mod
                    dp[i][:(a*10+10)%13]+=dp[i-1][a]
                    dp[i][:(a*10+10)%13]%=mod
            else:
                dp[i][(a*10+int(S[i-1]))%13]+=dp[i-1][a]
                dp[i][(a*10+int(S[i-1]))%13]%=mod
    print(dp[len(S)][5])
"""
    for i in range(1,len(S)+1):
        for a in range(13):
            if S[i-1]=="?":
                for n in range(10):
                    dp[i][(a*10+n)%13]+=dp[i-1][a]
                    dp[i][(a*10+n)%13]%=mod
            else:
                dp[i][(a*10+int(S[i-1]))%13]+=dp[i-1][a]
                dp[i][(a*10+int(S[i-1]))%13]%=mod
    print(dp[len(S)][5])
if __name__=="__main__":
    main()
### BUGGY CODE ###

n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
dp=[0]*(n+1)
for i in range(n,-1,-1):
  if i not in a:
    if i==n or i==n-1:
      dp[i]=1
    else:
      dp[i]=(dp[i+1]+dp[i+2])%1000000007
print(dp[0])

### FIXED CODE ###

n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
dp=[0]*(n+1)
if m==0:
  for i in range(n,-1,-1):
    if i==n or i==n-1:
      dp[i]=1
    else:
      dp[i]=dp[i+1]+dp[i+2]
  print(dp[0]%1000000007)
else:
  j=-1
  for i in range(n,-1,-1):
    if i==a[j]:
      if m>j*(-1):
        j-=1
    else:
      if i==n or i==n-1:
        dp[i]=1
      else:
        dp[i]=dp[i+1]+dp[i+2]
  print(dp[0]%1000000007)
### BUGGY CODE ###

R,G,B,N = map(int,input().split())

n = int(N / min(R,G,B))
ans_count = 0

for red in range(int(N/R)+1):
  for green in range(int(N/G)+1):
    for blue in range(int(N/B)+1):
      if red*R + green*G + blue*B == N:
        ans_count += 1

print(ans_count)
        

### FIXED CODE ###

R,G,B,N = map(int,input().split())

ans_count = 0

for red in range(int(N/R)+1):
  for green in range(int((N-red*R)/G)+1):
    if (N - red*R - green*G) % B ==0 :
      ans_count += 1

print(ans_count)
### BUGGY CODE ###

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

fromR = {i:[] for i in range(N+1)}
toR = {i:[] for i in range(N+1)}

ans = [-1 for i in range(N+1)]

for _ in range(N-1+M):
    a,b=map(int,input().split())
    fromR[a].append([b,a])
    toR[b].append(a)

r=1
while len(toR[r])>0:
    r=toR[r][0]

ans[r]=0

que = fromR[r]

while len(que)>0:
    tmp=[]
    for q in que:
        b,a=q
        ans[b]=a
        tmp+=fromR[b]
    que=tmp
for a in ans[1:]:
    print(a)


### FIXED CODE ###

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

fromR = {i:[] for i in range(N+1)}

cnt = [0 for i in range(N+1)]
ans = [-1 for i in range(N+1)]

for _ in range(N-1+M):
    a,b=map(int,input().split())
    fromR[a].append([b,a])
    cnt[b]+=1
r=-1
for i in range(1,N+1):
    if cnt[i]==0:
        r=i
        break

ans[r]=0

que = fromR[r]

while len(que)>0:
    tmp=[]
    for q in que:
        b,a=q
        cnt[b]-=1
        if cnt[b]==0:
            ans[b]=a
            tmp+=fromR[b]
    que=tmp
for a in ans[1:]:
    print(a)
### BUGGY CODE ###

n = int(input())
li = []
for i in range(n):
  li.append(int(input()))

for i in range (n):
  li_2 = li[0:i]+li[i+1:n+1]
  print(max(li_2))

### FIXED CODE ###

n = int(input())
li = []
for i in range(n):
  li.append(int(input()))
li_2 = sorted(li)
m_1 = li_2[-1]
m_2 = li_2[-2]
for i in range(n):
  if m_1 == li[i]:
    print(m_2)
  else:
    print(m_1)
### BUGGY CODE ###

def main():
    from functools import lru_cache
    S = input()
    T = input()
    if set(S) & set(T) != set(T):
        print(-1)
    else:
        lt = len(T)
        st = set(T)
        D = dict()
        for t in st:
            D[t] = list()
            for i, s in enumerate(S):
                if t == s:
                    D[t].append(i)
        pre = -1
        cnt = 0

        @lru_cache(maxsize=None)
        def judge(pre, t):
            X = D[t]
            for x in X:
                if pre < x:
                    return (x, False)
                    break
            else:
                return (X[0], True)

        for t in T:
            J = judge(pre, t)
            pre = J[0]
            if J[1]:
                cnt += 1

        print(cnt * len(S) + pre + 1)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    from functools import lru_cache
    import bisect
    S = input()
    T = input()
    if set(S) & set(T) != set(T):
        print(-1)
    else:
        lt = len(T)
        ls = len(S)
        st = set(T)
        D = dict()
        for t in st:
            D[t] = list()
            for i, s in enumerate(S):
                if t == s:
                    D[t].append(i)
        pre = -1
        cnt = 0

        @lru_cache(maxsize=None)
        def judge(pre, t):
            X = D[t]
            index = bisect.bisect(X, pre)
            if len(X) == index:
                return (X[0], True)
            else:
                return (X[index], False)

        for t in T:
            J = judge(pre, t)
            pre = J[0]
            if J[1]:
                cnt += 1

        print(cnt * len(S) + pre + 1)


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

from __future__ import print_function
range = xrange
input = raw_input





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




def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=map(int,input().split())
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=map(int,input().split())
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)


   
    cd=0
    p=sum(x)
    while p!=0:
        for i in range(len(x)):
            if x[i]>0:
                x[i]-=1
                p-=1
        cd+=1
    print(cd)
        
        
    
for _ in range(1):
    solve()



### FIXED CODE ###

import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

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


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=mp()
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=mp()
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)
           
    pr(max(x))
        
        
    
for _ in range(1):
    solve()
### BUGGY CODE ###

S = str(input())

_sum = 0

for i in range(1, len(S)):
  if S[i] == "W":
    _sum += S.count("B", 0,i)
    
print(_sum)

### FIXED CODE ###

S = str(input())

_sum = 0
ans = 0

for s in S:
  
  if s == "B":
    _sum += 1
    
  elif s == "W":
    ans += _sum
    
print(ans)
### BUGGY CODE ###

a, b, c, n = map(int, input().split())
count = 0
for y in range(n//b+1):
    for z in range(n//c+1):
        x = (n - b*y - c*z) / a
        if int(x) == x and x >= 0:
            count += 1
print(count)

### FIXED CODE ###

*j, n = map(int, input().split())
j.sort()
a, b, c = j
count = 0
for y in range(n//b+1):
    for z in range((n-y*b)//c+1):
        if (n - b*y - c*z) % a == 0:
            count += 1
print(count)
### BUGGY CODE ###

from collections import deque
dictionary = deque()
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.append(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')

### FIXED CODE ###

from collections import deque
dictionary = set()
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.add(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')
### BUGGY CODE ###

def BIT_query(BIT,idx):
  res_sum=0
  if idx==0:
    return 0
  while idx>0:
    res_sum+=BIT[idx]
    idx-=idx&(-idx)
  return res_sum

def BIT_update(BIT,idx,x,n):
  while idx<=n:
    BIT[idx]+=x
    idx+=idx&(-idx)
  return

def main():
  N,Q=map( int, input().split())
  C=list( map( int, input().split()))
  LRI=[]
  for i in range(Q):
    l,r=map( int, input().split())
    LRI.append((r,l,i))
  LRI=sorted(LRI)
  lastAppend=[-1]*(N+1)
  BIT=[0]*(N+1)
  ANS=[0]*Q
  now=1
  for r,l,i in LRI:
    while now <= r:
      c=C[now-1]
      if lastAppend[c]== -1:
        BIT_update(BIT,now,1,N)
      else:
        BIT_update(BIT,now,1,N)
        BIT_update(BIT,lastAppend[c],-1,N)
      lastAppend[c]=now                
      now+=1
    ANS[i] = BIT_query(BIT,r) - BIT_query(BIT,l-1)
  for ans in ANS:
    print(ans)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def BIT_query(BIT,idx):
  res_sum=0
  if idx==0:
    return 0
  while idx>0:
    res_sum+=BIT[idx]
    idx-=idx&(-idx)
  return res_sum

def BIT_update(BIT,idx,x,n):
  while idx<=n:
    BIT[idx]+=x
    idx+=idx&(-idx)
  return

def main():
  N,Q=map( int, input().split())
  C=list( map( int, input().split()))
  LRI=[]
  for i in range(Q):
    l,r=map( int, input().split())
    LRI.append((r,l,i))
  LRI.sort(key=lambda x:x[0])
  lastAppend=[-1]*(N+1)
  BIT=[0]*(N+1)
  ANS=[0]*Q
  now=1
  for r,l,i in LRI:
    while now <= r:
      c=C[now-1]
      if lastAppend[c]== -1:
        BIT_update(BIT,now,1,N)
      else:
        BIT_update(BIT,now,1,N)
        BIT_update(BIT,lastAppend[c],-1,N)
      lastAppend[c]=now                
      now+=1
    ANS[i] = BIT_query(BIT,r) - BIT_query(BIT,l-1)
  for ans in ANS:
    print(ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,w = map(int,input().split())
wt = [0]*n
v = [0]*n
dp = [[0 for _ in range(w)]for _ in range(n)]
for i in range(n):
    wt[i],v[i] = map(int,input().split())
for i in range(w):
    if(wt[0]>i+1):dp[0][i] = 0
    else:dp[0][i] = v[0]
for i in range(1,n):
    for j in range(w):
        if(wt[i]>j+1):
            dp[i][j] = dp[i-1][j]
        else:
            remain = (j+1) - wt[i]
            res = 0
            if(remain > 0):
                res = v[i] + dp[i-1][remain-1]
            else:
                res = v[i]
            dp[i][j] = max(dp[i-1][j],res)

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



### FIXED CODE ###

n,w = map(int,input().split())
wt = [0]*n
v = [0]*n
dp = [[0 for _ in range(w)]for _ in range(n)]
for i in range(n):
    wt[i],v[i] = map(int,input().split())
for i in range(w):
    if(wt[0]>i+1):dp[0][i] = 0
    else:dp[0][i] = v[0]
for i in range(1,n):
    for j in range(w):
        if(wt[i]>j+1):
            dp[i][j] = dp[i-1][j]
        else:
            remain = (j+1) - wt[i]
            res = 0
            if(remain > 0):
                res = v[i] + dp[i-1][remain-1]
            else:
                res = v[i]
            dp[i][j] = max(dp[i-1][j],res)

print(dp[n-1][w-1])
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)
ABC = []
for i in range(min(K,len(AB))):
    for j in range(Z):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
C = [i for i in map(int,input().split())]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(X):
    for j in range(Y):
        if (i+1) * (j+1) > K:
            break
        for k in range(Z):
            if (i+1) * (j+1) * (k+1) > K:
                break
            ABC.append(A[i] +  B[j] + C[k])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
B = [int(x) for x in input().split()]
B.sort(reverse=True)
C = [int(x) for x in input().split()]
C.sort(reverse=True)


bi_comb = []
for i in A[:K]:
    for j in B[:K]:
        bi_comb.append(i+j)
bi_comb.sort(reverse=True)
tri_comb = []
for k in bi_comb[:K]:
    for l in C[:K]:
        tri_comb.append(k + l)
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)
B = sorted([int(x) for x in input().split()], reverse=True)
C = sorted([int(x) for x in input().split()], reverse=True)

bi_comb = []
for i in range(min(X, K)):
    for j in range(min(Y, K)):
        if (i+1)*(j+1) > K:
            break
        bi_comb.append(A[i] + B[j])
bi_comb.sort(reverse=True)

tri_comb = []
for k in range(min(len(bi_comb), K)):
    for l in range(min(Z, K)):
        if (k+1)*(l+1) > K:
            break
        tri_comb.append(bi_comb[k] + C[l])
tri_comb.sort(reverse=True)

print(*tri_comb[:K], sep="\n")
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    dp[i] = min(dp[j] + abs(h[j] - h[i]) for j in range(max(i - k, 0), i))
print(dp[n-1])

### FIXED CODE ###

def main():
    n, k = [int(e) for e in input().split()]
    h = [int(e) for e in input().split()]
    dp = [0] * n
    for i in range(1, n):
        dp[i] = min(dp[j] + abs(h[j] - h[i]) for j in range(max(i - k, 0), i))
    print(dp[n-1])
main()
### BUGGY CODE ###

import sys
import collections
input = sys.stdin.readline
N = int(input())
S = list(input().strip())
assert 1 <= N <= 4000
assert N == len(S)
c = collections.Counter(S)
total = 0
for j in range(1, N-1):
    for i in range(j):
        k = 2*j-i
        if k < len(S):
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                total += 1
print(c["R"]*c["G"]*c["B"]-total)


### FIXED CODE ###

n = int(input())
s = input()
r,g,b =0,0,0
ls = len(s)
for i in range(ls):
    if s[i]=='R':
        r+=1
    elif s[i]=='G':
        g+=1
    elif s[i]=='B':
        b+=1
cnt =0
for j in range(1,ls-1):
    for i in range(j):
        k = 2*j-i
        if k<ls:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                cnt+=1
print(r*g*b-cnt)
### BUGGY CODE ###

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

if 0 in a:
  ans = 0
else:
  ans = 1
  for item in a:
    ans *= item
  if ans > 1000000000000000000:
    ans = -1
print(ans)


### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  if 0 in A:
    print(0)
    return
  
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
  
main()
### BUGGY CODE ###

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


for q in range(Q):
    b, c = map(int, input().split())
    for n in range(N):
        if b == A[n]:
            A[n] = c
    print(sum(A))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
Q = int(input())
ans = []
s = sum(A)
for _ in range(Q):
    b, c = map(int, input().split())
    n = cnt[b]
    if b in cnt:
        cnt[c] += cnt[b]
        del cnt[b]
    s += (c-b)*n
    print(s)
### BUGGY CODE ###

H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

stack=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            stack.append([i,j])


dh=[1,0,-1,0]
dw=[0,1,0,-1]

cnt=0
while stack:
    nstack=[]
    for h,w in stack:
        for k in range(4):
            th=h+dh[k]
            tw=w+dw[k]
            if not board[th][tw]:
                board[th][tw]=True
                nstack.append([th,tw])
    stack=nstack
    cnt+=1

print(cnt-1)




### FIXED CODE ###

H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)
### BUGGY CODE ###

n = int(input())
a = tuple(int(input()) for i in range(n))
x = a.count(max(a))
if 2 <= x:
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if a[i] != max(a):
            print(max(a))
        else:
            print(max(a[:i] + a[i+1:]))

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = tuple(a)
a.sort()
for i in b:
    if i == a[n-1]:
        print(a[n-2])
    else:
        print(a[n-1])
### BUGGY CODE ###

N,K = map(int,input().split())
H = [int(x) for x in input().split()]
ld = sorted(H,reverse=True)
for _ in range(K):
    ld[0:1] = []
print(sum(ld))


### FIXED CODE ###

N,K = map(int,input().split())
H = [int(x) for x in input().split()]
ld = sorted(H,reverse=True)

ld[0:K] = []
print(sum(ld))
### BUGGY CODE ###

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

N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
  a = int(input())
  X[a-1].append(i+1)
  
# dfsをして、Depthを計算しつつ、depth大きい順に取り出せるようにheapqを使う
h = []

seen = [False] * N
def dfs(a,depth):
  seen[a] = True
  heapq.heappush(h, (-depth, a))
  for nxt in X[a]:
    #if seen[nxt]:
      #continue
    dfs(nxt, depth+1)

dfs(0,0)
#rint(len(h))
DP = [0] * N
while h:
  depth, a = heapq.heappop(h)
  cand = []
  for child in X[a]:
    cand.append(DP[child])
  if not cand:
    DP[a] = 1
    continue
  cand.sort(reverse=True)
  for i in range(len(cand)):
    DP[a] = max(DP[a], cand[i]+i+1)
    
print(DP[0]-1)

### FIXED CODE ###

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

N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
  a = int(input())
  X[a-1].append(i+1)
  
# dfsをして、Depthを計算しつつ、depth大きい順に取り出せるようにheapqを使う
h = []

seen = [False] * N
def dfs(a,depth):
  seen[a] = True
  heapq.heappush(h, (-depth, a))
  for nxt in X[a]:
    #if seen[nxt]:
      #continue
    dfs(nxt, depth+1)

dfs(0,0)
#rint(len(h))
DP = [0] * N
while h:
  depth, a = heapq.heappop(h)
  cand = []
  for child in X[a]:
    cand.append(DP[child])
  if not cand:
    DP[a] = 1
    continue
  cand.sort(reverse=True)
  for i in range(len(cand)):
    DP[a] = max(DP[a], cand[i]+i+1)
    
print(DP[0]-1)
### BUGGY CODE ###

n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n-1:
    while v!=w:
      if v>w:v,w=w,v
      w=(w+n-2)//n
  print(v)

### FIXED CODE ###

n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))
### BUGGY CODE ###

def solve(N, As, Bs, Cs):
    # print(As, Bs, Cs)
    ans = 0
    As.sort()
    Bs.sort()
    Cs.sort()
    
    memo = {}
    for b in Bs:
        bans = 0
        for i, c in enumerate(Cs):
            if b < c:
                bans += N - i
                break
        memo[b] = bans

    for a in As:
        for b in Bs:
            if b > a and b in memo:
                ans += memo[b]

    return ans

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    Bs = list(map(int, input().split(" ")))
    Cs = list(map(int, input().split(" ")))
    print(solve(N, As, Bs, Cs))


### 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()
B.sort()
C.sort()

ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    ans += i * (N - j)
print(ans)