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

import sys
import numpy as np

read = sys.stdin.buffer.read

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

hw = []
w = np.zeros(3*10**5,dtype=np.int64)
h = np.zeros(3*10**5,dtype=np.int64)
 
for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.append([h_i-1, w_j-1])
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 0
for i in np.where(h==h.max())[0]:
    for j in np.where(w==w.max())[0]:
        mxh_v = h[i]
        mxw_v = w[j]

        if [i,j] in hw:
            a = max(a, mxh_v + mxw_v - 1)
        else:
            a = max(a, mxh_v + mxw_v)

print(a)

### FIXED CODE ###

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

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
### BUGGY CODE ###

N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
ans = 0
S = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    S[s] += 1
    ans += S[s]
print(ans)
### BUGGY CODE ###

import math

def gcd(a,b):
    if a ==b:
        return a
    elif a !=b:
        return math.gcd(a,b)
    
    
        
cnt=0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        c = gcd(i,m)
        for u in range(1,K+1):
            cnt+= gcd(c,u)
print(cnt)

### FIXED CODE ###

import math
K = int(input())

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)
### BUGGY CODE ###

import math
import re

n = int(raw_input())
a = raw_input().split()
#s = list(raw_input())

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            #divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                #divisors.append(n//i)
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1

    # divisors.sort()
    return divisors

if n == 2:
    print max(a[0],a[1])
else:
    for i in a:
        make_divisors(i)
    answer = 0
    for i in chk:
        if int(chk[i]) >= n - 1:
            answer = i
    print answer

### FIXED CODE ###

n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k not in chk2:
        chk2[k] = 1
    else:
        if chk2[k] == 1:
            chk2[k] += 1
        elif chk2[k] > 1:
            continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = 0
for i in chk:
    if int(chk[i]) >= chk[1] - 1 and i > answer:
        answer = i
print answer
### BUGGY CODE ###

N = int(input())

A = list(map(int, input().split()))
a = [0] * N

for i in range(N-1):
  print(A.count(i+1))

print(0)


### FIXED CODE ###

N = int(input())

A = list(map(int, input().split()))
a = [0] * N

for i in range(N-1):
  k = A[i]
  a[k-1] += 1

for l in range(N):
  print(a[l])
### BUGGY CODE ###

import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    lst_p = list(map(float, input().split()))

    # dp[j] := 表が j 枚となる確率
    # dp[j] = dp[j-1]*p[i] + dp[j]*(1-p[i])
    dp = [0.0] * (N+1)
    # 初期条件
    dp[0]= 1.0

    for i in range(N):
        # 更新前のdpを更新に使う。
        dp_before_update = list(dp)
        for j in range(N+1):
            dp[j] = (dp_before_update[j-1] * lst_p[i]) + (dp_before_update[j] * (1 - lst_p[i]))
    
    ans = sum(dp[(N//2+1):])

    print(ans)

main()

### FIXED CODE ###

import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    lst_p = list(map(float, input().split()))

    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # 次のコインが表: dp[i+1][j+1] += dp[i][j]∗p[i]
    # 次のコインが裏: dp[i+1][j] += dp[i][j]∗(1.0−p[i])
    dp = [[0] * (N+1) for i in range(N+1)]

    # 初期条件
    dp[0][0] = 1.0

    for i in range(N):
        for j in range(N):
            dp[i+1][j+1] += dp[i][j] * lst_p[i]
            dp[i+1][j] += dp[i][j] * (1.0 - lst_p[i])
    
    ans = 0
    for i in range((N+1)//2, N+1):
        ans += dp[N][i]

    print(ans)

main()
### BUGGY CODE ###

def main():
  import sys
  input = sys.stdin.readline

  N,M = map(int,input().split())
  A = tuple([int(input()) for _ in range(M)])
  
  dp = [0]*(N+1)
  dp[0] = 1
  if 1 in A:
    dp[1] = 0
  else:
    dp[1] = 1

  for i in range(2,N+1):
    if i not in A:
      dp[i] = (dp[i-1] + dp[i-2])%1000000007
    else:
      continue
  print(dp[N])

if __name__ == "__main__":
  main()

### FIXED CODE ###

mod = 10**9+7
n,m = map(int,input().split())
a = set()
for i in range(m):
  a.add(int(input()))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1) :
    dp[i] = (dp[i-1] + dp[i-2]) % mod
    if i in a :
        dp[i] = 0
print(dp[n])
### BUGGY CODE ###

import math
import sys
sys.setrecursionlimit(int(10**9))

mod = 10**9 + 7

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def fact(n):
    if n == 1: 
        return 1
    else:
        return (fact(n-1)*n)%mod

def comb(n, k):
    ans = 1
    for i in range(k):
        ans *= (n-i)
        ans //= i+1
    return ans % mod

n, a, b = map(int, input().split())
now = 1
for i in range(a):
    now = (now*(n-i)*power(i+1,mod-2))%mod
cnka = now
for i in range(a,b):
    now = (now*(n-i)*power(i+1,mod-2))%mod
cnkb = now

ans = power(2, n)%mod - cnka - cnkb - 1
print(ans % mod)

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(int(10**9))

mod = 10**9 + 7

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def fact(n):
    if n == 1: 
        return 1
    else:
        return (fact(n-1)*n)%mod

def comb(n, k):
    ans = 1
    for i in range(k):
        ans *= (n-i)
        ans //= i+1
    return ans % mod

n, a, b = map(int, input().split())
now = 1
for i in range(a):
    now = (now*(n-i))%mod
cnka = (now * power(math.factorial(a),mod-2) )% mod
for i in range(a,b):
    now = (now*(n-i))%mod
cnkb = (now * power(math.factorial(b),mod-2) )% mod

ans = power(2, n)%mod - cnka - cnkb - 1
print(ans % mod)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np

K, S = map(int, input().split())
sets = []
for x in range(K+1):
    for y in range(S-K-x, S-x+1):
        if y >= 0 and y <= K:
            z = S - (x + y)
            sets.append((x, y, z))

print(len(sets))

### FIXED CODE ###

K, S = map(int, input().split())
number = 0
for x in range(K+1):
  for y in range(K+1):
    z = S - (x + y)
    if 0 <= z <= K:
      number += 1
print(number)
### BUGGY CODE ###

import math

n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            #divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                #divisors.append(n//i)
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1

    # divisors.sort()
    return divisors

if n == 2:
    print max(a[0],a[1])
else:
    for i in range(2):
        make_divisors(a[i])
    cnt = 1
    for i in reversed(range(2,len(a))):
        k = a[i]
        del_list = []
        for j in chk:
            if k % j == 0:
                chk[j] += 1
            if chk[j] < cnt:
                del_list.append(j)
        for j in del_list:
            del chk[j]
        cnt += 1

    answer = 0
    for i in chk:
        if int(chk[i]) >= n - 1 and i > answer:
            answer = i
    print answer

### FIXED CODE ###

n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k not in chk2:
        chk2[k] = 1
    else:
        if chk2[k] == 1:
            chk2[k] += 1
        elif chk2[k] > 1:
            continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = 0
for i in chk:
    if int(chk[i]) >= chk[1] - 1 and i > answer:
        answer = i
print answer
### BUGGY CODE ###

x=int(input())
s={0}
n=1
stop=0
while(1):
    N=n**5
    for i in s:
        if N-i==x:
            if i>0:
                sig=int(i//abs(i))
            else:
                sig=1
            print(n,sig*int(pow(abs(i),1/5)))
            stop=1
        elif N-i==-x:
            if i>0:
                sig=int(i//abs(i))
            else:
                sig=1
            print(n,sig*int(pow(abs(i),1/5)))
            stop=1
    if stop==1:
        break
    s|={N,-N}

### FIXED CODE ###

x=int(input())
s={0}
n=1
stop=0
while(1):
    N=n**5
    for i in s:
        if N-i==x:
            if i>0:
                sig=1
            elif i<0:
                sig=-1
            else:
                sig=0
            print(n,int(sig*pow(abs(i),1/5)))
            stop=1
        elif i-N==x:
            if i>0:
                sig=1
            elif i<0:
                sig=-1
            else:
                sig=0
            print(int(sig*pow(abs(i),1/5)),n)
            stop=1
    if stop==1:
        break
    s|={N,-N}
    n+=1
### BUGGY CODE ###

n = int(input())
cnt = 1
mod = 10**9+7
for i in range(1,n+1):
    cnt *= i
print(cnt % mod)

### FIXED CODE ###

import math
n=int(input())
mod = 10**9 + 7
ans = math.factorial(n)
print(ans % mod)
### BUGGY CODE ###

input()
ans = 1
for a in map(int, input().split()):
  ans *= a
  
print(ans if ans <= 10**18 else -1)

### FIXED CODE ###

N = input()
A_i = list(map(int, input().split()))

def manipulate(A_i):
    if 0 in A_i:
        return 0
    
    ans = 1
    
    for a in A_i:
        ans *= a
        if ans > 10 ** 18:
            return -1
    
    return ans

print(manipulate(A_i))
### BUGGY CODE ###

N,M = map(int, input().split(' '))
mass = [[True for i in range(M)] for j in range(N)]
for n in range(N):
    for m in range(M):
        if n > 0:
            if m > 0:
                mass[n-1][m-1] = not mass[n-1][m-1]
            mass[n-1][m] = not mass[n-1][m]
            if m < M-1:
                mass[n-1][m+1] = not mass[n-1][m+1]
        if n < N-1:
            if m > 0:
                mass[n+1][m-1] = not mass[n+1][m-1]
            mass[n+1][m] = not mass[n+1][m]
            if m < M-1:
                mass[n+1][m+1] = not mass[n+1][m+1]
        if m > 0:
            mass[n][m-1] = not mass[n][m-1]
        mass[n][m] = not mass[n][m]
        if m < M-1:
            mass[n][m+1] = not mass[n][m+1]
num = 0
for n in range(N):
    for m in range(M):
        if not mass[n][m]:
            num += 1
print(num)

### FIXED CODE ###


import sys

N,M = map(int, input().split(' '))
num = 0
if N == 1:
    if M < 2:
        print(1)
        sys.exit()
    print(str(M-2))
    sys.exit()
elif N == 2:
    print(0)
    sys.exit()
else:
    if M < 2:
        num = N-2
    else:
        num = (M-2)*(N-2) 
    print(num)
### BUGGY CODE ###

import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = list(input())

    ok = 0
    ng = N // 2
    ans = 0
    for i in range(N - 1):
        for j in range(i + ans + 1, N):
            if  N - j + 1 < ans:
                break
            for k in range(0, min(j - i, N - j)):
                if S[i + k] != S[j + k]:
                    ans = max(ans, k)
                    break
            else:
                ans = max(ans, k + 1)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = list(input())



    ans =0
    for k in range(1,N):
        i=0
        count =0
        while i<N-k:
            if S[i]==S[i+k]:
                count+=1
                ans =max(ans,min(count,k))
            else:
                count=0

            i+=1

    print(ans)









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

a,b=map(int,input().split())
t=min(a,b)
s=max(a,b)
c=1
i=2
while t > 1:
  frag=0
  while t%i ==0:
    t=t/i
    if frag==0 and s%i ==0:
      c=c+1
    frag=1
  i=i+1
print(c)

### FIXED CODE ###

a,b=map(int,input().split())
t=min(a,b)
t1=t
s=max(a,b)
c=1
i=2
while t > 1 and i <=int(t1**(0.5)+1):
  frag=0
  while t%i ==0:
    t=t/i
    if frag==0 and s%i ==0:
      c=c+1
    frag=1
  if i==2:
    i=3
  else:
    i= i+2
if s%t==0 and t > int(t1**(0.5)+1):
  c=c+1
print(c)
### BUGGY CODE ###

N = int(input())
S = input()
Q = int(input())
K = [int(_) for _ in input().split()]

D = [0] * (N+1)
M = [0] * (N+1)
C = []
DM = [0] * (N+1)
DMC = [0] * (N+1)

for i in range(N):
    if S[i] == 'D':
        D[i] += 1
    elif S[i] == 'M':
        M[i] += 1
        DM[i] += D[i-1]
    elif S[i] == 'C':
        C += [i]
    D[i+1] = D[i]
    M[i+1] = M[i]
    DM[i+1] = DM[i]

for k in K:
    ans = 0
    for c in C:
        if c > 1:
            ans += DM[c-1]
            if c-k+1 > 0:
                ans -= D[c-k]*(M[c-1]-M[c-k])+DM[c-k]
    print(ans)


### FIXED CODE ###

N = int(input())
S = input()
Q = int(input())
K = [int(_) for _ in input().split()]

D = [0] * (N+10)
M = [0] * (N+10)
C = []
DM = [0] * (N+10)
DMC = [0] * (N+10)

for i in range(N):
    if S[i] == 'D':
        D[i] += 1
    elif S[i] == 'M':
        M[i] += 1
        DM[i] += D[i-1]
    elif S[i] == 'C':
        C += [i]
    D[i+1] = D[i]
    M[i+1] = M[i]
    DM[i+1] = DM[i]

for k in K:
    ans = 0
    for c in C:
        ans += DM[c-1]
        if c-k+1 > 0:
            ans -= D[c-k]*(M[c-1]-M[c-k])+DM[c-k]
    print(ans)
### BUGGY CODE ###

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

ad=[1]*n
an=n

for i in range(n-1):
    if ad[i]==1:
        for j in range(i+1,n):
            wk1,wk0=divmod(a[j],a[i])
            if wk0==0:
                if wk1==1:
                    ad[i]=0
                ad[j]=0

print(sum(ad))

### FIXED CODE ###

import numpy as np

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

amax=max(a)+1
ah=[0]*amax

for i in a:
    for j in range(i,amax,i):
        ah[j]+=1

an=0
for i in a:
    if ah[i]==1:
        an+=1
print(an)
### BUGGY CODE ###

MOD = 10**9+7
s = input()
sl = list(s)
n=len(s)
dsl={i:sl[i] for i in range(n)}

dp={i:0 for i in range(13)}
dp[0]=1

for i in range(n):
    next_dp={i:0 for i in range(13)}
    for k in range(10):
        if dsl[i] != "?" and dsl[i] != str(k):
            continue
        for j in range(13):
            next_dp[(j*10+k)%13] += dp[j]%MOD
    dp = next_dp

print(dp[5]%MOD)

### FIXED CODE ###

MOD = 10**9+7
s = input()
ind = list(range(len(s)))
sl = list(s)
#print(sl)
dsl = dict(zip(ind, sl))
#print(dsl)

ind2 = list(range(13))
dp={}
#dp.setdefault(0, dict(zip(ind2,[0]*13)))
for i in range(len(s)+1):
    #dp.append(dict(zip(ind2,[0]*13)))
    dp.setdefault(i, dict(zip(ind2,[0]*13)))


#print(dp)
dp[0][0]=1

for i in range(len(s)):
    for k in range(10):
        if dsl[i] != "?" and dsl[i] != str(k):
            continue
        for j in range(13):
            dp[i+1][(j*10+k)%13] += dp[i][j]%MOD
    #for k in range(13):
    #    dp[i+1][k] %= MOD

#print(dp)
print(dp[len(s)][5]%MOD)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
x = sum(a)
difference = []
for i in range(n-1):
	x = x - a[i]
	difference.append(abs(sum(a)-2*x))
print(min(difference))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
x = sum(a)
t = sum(a)
difference = []
for i in range(n-1):
	x = x - a[i]
	difference.append(abs(t-2*x))
print(min(difference))
### BUGGY CODE ###

from collections import defaultdict

N, K, L = map(int, input().split())


class UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.par = list(range(n))
        self.rank = [1] * n

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        elif self.rank[x]  < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            self.rank[x] += 1

    def group(self):
        d = defaultdict(set)
        for i in range(self.n):
            d[self.root(i)].add(i)
        return d

load_uf = UnionFind(N)
rail_uf = UnionFind(N)

for k in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    load_uf.unite(p, q)

for l in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    rail_uf.unite(r, s)
ld = load_uf.group()
rd = rail_uf.group()

ans = []
d = defaultdict(int)
for i in range(N):
    lp = load_uf.par[i]
    rp = rail_uf.par[i]
    d[lp, rp] += 1
# print(d)

for i in range(N):
    lp = load_uf.par[i]
    rp = rail_uf.par[i]
    if i == N-1:
        print(d[lp, rp])
    else:
        print(d[lp, rp], end=' ')

#     print(rd[rp])
#     print(ld[lp])
#     ans.append(len(ld[lp] & rd[rp]))
# print(str(ans).replace(',', '')[1:-1])


### FIXED CODE ###

from collections import defaultdict

N, K, L = map(int, input().split())


class UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.par = list(range(n))
        self.rank = [1] * n

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        elif self.rank[x]  < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            self.rank[x] += 1

load_uf = UnionFind(N)
rail_uf = UnionFind(N)

for k in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    load_uf.unite(p, q)

for l in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    rail_uf.unite(r, s)

ans = []
d = defaultdict(int)
for i in range(N):
    lp = load_uf.root(i)
    rp = rail_uf.root(i)
    d[lp, rp] += 1

for i in range(N):
    lp = load_uf.par[i]
    rp = rail_uf.par[i]
    if i == N-1:
        print(d[lp, rp])
    else:
        print(d[lp, rp], end=' ')

#     print(rd[rp])
#     print(ld[lp])
#     ans.append(len(ld[lp] & rd[rp]))
# print(str(ans).replace(',', '')[1:-1])
### BUGGY CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

x_sorted = [0] * n
for i in range(q):
    p = px[i][0]
    x = px[i][1]
    x_sorted[p - 1] += x

# print(x_sorted)

start = 0
# コストテーブルの作成
from heapq import heappop, heappush
inf = float('inf')
cost = dict() # コストテーブル
for i, j in ab:
    c = x_sorted[i - 1]
    cost[i - 1] = cost.get(i - 1, []) + [(j - 1, c)]
# print(cost)

d = [inf for i in range(n)] # 最短距離
d[start] = 0

qq = [] # min-heap, (距離, 頂点)
heappush(qq, (d[start], start))
while qq:
    du, u = heappop(qq) # 最短距離とその頂点
    if d[u] < du:
        continue
    for v, weight in cost.get(u, []):
        alt = du + weight
        if d[v] > alt:
            d[v] = alt
            heappush(qq, (alt, v))

ans = ''
for i in range(n):
    ans += str(d[i] + x_sorted[i]) + ' '

print(ans[:-1])


### FIXED CODE ###

from sys import stdin
from collections import defaultdict

if __name__ == '__main__':
    n, q = map(int, stdin.readline().rstrip().split())
    ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n - 1)]
    px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]

    g = defaultdict(list)
    for a, b in ab:
        a -= 1
        b -= 1
        g[a].append(b)
        g[b].append(a)

    adder = defaultdict(int)
    for p, x in px:
        p -= 1
        adder[p] += x

    ans = [float('inf')] * n
    ans[0] = adder[0]
    qu = [0]

    while qu:
        cur = qu.pop()

        for target in g[cur]:
            if ans[target] == float('inf'):
                ans[target] = ans[cur] + adder[target]
                qu.append(target)

    for _ans in ans:
        print(_ans)
### 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()))
b.sort()
c.sort()
ai = []
bi = []
for i in range(n):
    ai.append(n - bisect.bisect_right(b, a[i]))
    bi.append(n - bisect.bisect_right(c, b[i]))
ans = 0
for j in ai:
    ans += sum(bi[n-j:])
print(ans)

### FIXED CODE ###

from itertools import accumulate
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()
ai = []
bi = []
for i in range(n):
    ai.append(n - bisect.bisect_right(b, a[i]))
    bi.append(n - bisect.bisect_right(c, b[i]))
ans = 0
c = [0]+list(accumulate(bi[::-1]))
for j in ai:
    ans += c[j]
print(ans)