CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
slist = list(map(int, input().split()))
ans = 0
for C in range(1,N-1,1):
    flg = [False for i in range(N)]
    score = 0
    for k in range((N-1)//C):
        if (k-1)*C == N-1-k*C: #一つ前に選んだところ
            break
        if 2*k*C == N-1: #今から選ぶ二つが同じところ
            break
        score += slist[k*C]+slist[N-1-k*C]
        ans = max(ans, score)
print(ans)

# Optimized solution
N = int(eval(input()))
slist = list(map(int, input().split()))
ans = 0
for C in range(1,N-1,1):
    score = 0
    for k in range((N-1)//C):
        if (k-1)*C == N-1-k*C: #一つ前に選んだところ
            break
        if 2*k*C == N-1: #今から選ぶ二つが同じところ
            break
        score += slist[k*C]+slist[N-1-k*C]
        ans = max(ans, score)
print(ans)
# Original solution
n = int(eval(input()))
s = list(map(int, input().split()))

ans = s[n-1]

for c in range(1, n-1):
    dp = s[n-1]
    for k in range(n-1):
        if (k+1) * c >= n-1:
            break
        else:
            dp += s[n - 1 - k * c] + s[k * c]
            if dp > ans:
                if k <= 1:
                    ans = dp
                else:
                    a = n - 1 - k * c
                    b = a - c
                    if a > 2 * b:
                        ans = dp
                    elif a < 2 * b:
                        d = [0] * n
                        t = 0
                        while 1:
                            t += a
                            if t == n-1:
                                ans = dp
                                break
                            elif t > n-1:
                                break
                            d[t] = 1
                            t -= b
                            if d[t] == 1:
                                break
                            else:
                                d[t] = 1

print(ans)


# Optimized solution
n = int(eval(input()))
s = list(map(int, input().split()))

ans = 0

for d in range(1, n):
    temp = 0
    L = 0
    R = n-1
    if (n-1) % d == 0:
        while L < R:
            temp += s[L] + s[R]
            ans = max(ans, temp)
            L += d
            R -= d
    else:
        while L + d < n-1:
            temp += s[L] + s[R]
            ans = max(ans, temp)
            L += d
            R -= d

print(ans)
# Original solution
N, = list(map(int, input().split()))
xs = list(map(int, input().split()))
r = 0
for a in range(1, N-1):
    for b in range(1, N-2):
        if a <= b:
            continue
        if (N-1-a)%(a-b):
            continue
        n = (N-1-a)//(a-b)
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                continue
        s = a
        t = xs[a]
        vs = set([a])
        for i in range(n):
            #t = max(0, t)
            s -= b
            t += xs[s]
            vs.add(s)
            s += a
            vs.add(s)
            t += xs[s]
        #print("k:%d, A:%d, B:%d"%(a-b,a,b))
        #print(vs, t)
        r = max(r, t)

print(r)


# Optimized solution
N, = list(map(int, input().split()))
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    b = a - k
    n = (N-1-a)//k
    if a <= k:
        a += k
    if a <= k:
        a += k

    for _ in range((N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a <= b or a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    ps = [(s1,t)]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        ps.append((s2,xs[s2]))
        ps.append((s1,xs[s1]))
        s2 -= a-b
    #print(ps, t)
    r = max(r, t)

print(r)
# Original solution
N, = list(map(int, input().split()))
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    b = a - k
    n = (N-1-a)//k
    if a <= k:
        a += k
    if a <= k:
        a += k

    for _ in range((N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a <= b or a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    ps = [(s1,t)]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        ps.append((s2,xs[s2]))
        ps.append((s1,xs[s1]))
        s2 -= a-b
    #print(ps, t)
    r = max(r, t)

print(r)


# Optimized solution
N, = list(map(int, input().split()))
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    for _ in range(1+(N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b or a <= k:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        s2 -= a-b
    r = max(r, t)
print(r)
# Original solution
import bisect

n = int(eval(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()


bi = bisect.bisect_right

result = 0
for i in range(n):
    a_bi_in_b = bi(b, a[i])
    for j in range(a_bi_in_b, n):
        b_bi_in_c = bi(c, b[j])
        result += n - b_bi_in_c
        
        
print(result)

# Optimized solution
import bisect

n = int(eval(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()


result = 0
for i in range(n):
    b_bisect_in_a = bisect.bisect_left(a, b[i])
    b_bisect_in_c = bisect.bisect_right(c, b[i])
    result += b_bisect_in_a * (n - b_bisect_in_c)
        
        
print(result)
# Original solution
import bisect

def main():
    N = int(eval(input()))

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

    # print(A,B,C)

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

    def f(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            x = f(bi)
            cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

# Optimized solution
import bisect

def main():
    N = int(eval(input()))

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

    # print(A,B,C)

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

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
inf=10**9+1

n=int(eval(input()))
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])

nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur


nums_c=[0 for _ in range(n)]
cur=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        cur+=1
    nums_c[idx]=sum(nums_b[:cur])
print((sum(nums_c)))

# Optimized solution
inf=10**9+1

n=int(eval(input()))
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])

nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur


cur=0
res=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        res+=nums_b[cur]*(n-idx)
        cur+=1
print(res)
# Original solution
import bisect
n = int(eval(input()))
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort()
list_B.sort()
list_C.sort()
ans = 0
list_U = []
list_D = []

for i in range(n):
    b = list_B[i]
    index = bisect.bisect_left(list_A, b)
    list_U.append(index)

for i in range(n):
    c = list_C[i]
    index = bisect.bisect_left(list_B, c)
    list_D.append(index)

for i in range(n):
    j = list_D[i]
    for k in range(j):
        ans += list_U[k]

print(ans)

# Optimized solution
import bisect
n = int(eval(input()))
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort()
list_B.sort()
list_C.sort()
ans = 0

for i in range(n):
    b = list_B[i]
    left = bisect.bisect_left(list_A, b)
    right = n - bisect.bisect_right(list_C, b)
    ans += left * right

print(ans)
# Original solution
# coding: utf-8
# Your code here!
N=int(eval(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()
A.reverse()
B.reverse()
C.reverse()

ue=0
naka=0
sita=0
count=0
for i in range(N):
    ue=A[i]
    for j in range(N):
        naka=B[j]
        if ue>=naka:
            break
        for k in range(N):
            
            sita=C[k]
            if A[i]<B[j] and B[j]<C[k]:
                count+=1
            if naka>=sita:
                break
            
print(count)

# Optimized solution
N=int(eval(input()))
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))
S.sort()
T.sort()
U.sort()
#print(S)
#print(T)
#print(U)


count=0
def is_ok(index,key):
    if key>S[index]:
        return True
    else:
        return False


def meguru_bisect(key):
    ng=N
    ok=-1
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,key):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(index,key):
    if key<U[index]:
        return True
    else:
        return False


def meguru_bisect2(key):
    ng=-1
    ok=N
    
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid,key):
            ok = mid
        else:
            ng = mid
    return ok
ans=0
for i in range(N):
    ans+=(N-meguru_bisect2(T[i]))*(meguru_bisect(T[i])+1)
print(ans)
# Original solution
def main():
    import bisect

    N = int(eval(input()))
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    index_mid = 0
    index_low = 0

    for i in range(N):
        len_up = upper[i]
        index_mid = index_mid + bisect.bisect_right(middle[index_mid:], len_up)

        if (index_mid >= N):
            break

        index_low = index_low + bisect.bisect_right(lower[index_low:], middle[index_mid])

        tmp_mid = index_mid
        tmp_low = index_low        

        while (tmp_mid < N):
            len_mid = middle[tmp_mid]
            tmp_low = tmp_low + bisect.bisect_right(lower[tmp_low:], len_mid)

            if (tmp_low < N):
                cnt += N - tmp_low
                tmp_mid += 1

            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()



# Optimized solution
def main():
    import bisect

    N = int(eval(input()))
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


if __name__ == '__main__':
    main()
# Original solution
import bisect

n = int(eval(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()
ct = 0
for i in C:
    b_max = bisect.bisect_left(B, i)
    for j in B[: b_max]:
        ct += bisect.bisect_left(A, j)
print(ct)

# Optimized solution
import bisect

n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ct = 0
for j in B:
    a_max = bisect.bisect_left(A, j)
    c_min = bisect.bisect_right(C, j)
    ct += a_max * (n - c_min)
print(ct)
# Original solution
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, = I()
A = sorted(I())
B = sorted(I())
C = sorted(I())

ans = 0
for i in range(n):
    left = bl(A, B[i])
    right = n - br(C, B[i])
    ans += left * right
print(ans)



# Optimized solution
inp=lambda:list(map(int,input().split()))
import bisect as bi
n=int(eval(input()))
a=inp()
b=inp()
c=inp()
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    x=bi.bisect_left(a,b[i])
    y=n-bi.bisect_right(c,b[i])
    ans+=x*y
print(ans)
# Original solution
n = int(eval(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()
count=0
for i in a:
  for j in b:
    for k in c:
      if i<j<k:
        count=count+1
print(count)
        

# Optimized solution
import bisect

n = int(eval(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()
A = 0
for x in b:
  i = bisect.bisect_left(a, x)
  j = bisect.bisect_right(c, x)
  if i > 0 and j != len(c):
    A += i * (n - j)
print(A)
# Original solution
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    answer = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        B_index = bisect.bisect_left(B,A[i]+1)
        for j in range(B_index,N):
            C_index = bisect.bisect_left(C,B[j]+1)
            answer += N-C_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    answer = 0
    for i in range(N):
        A_index = bisect.bisect_left(A,B[i])
        C_index = bisect.bisect_left(C,B[i]+1) 
        answer += (N-C_index)*A_index
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()
# Original solution
n=int(eval(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()
def isOK(A,mid,target):
    #条件を満たす領域とそうでない領域の境目！
    return target<A[mid]   #条件を満たす中で最小
    #return A[mid]<=target  #条件を満たす中で最大
def aa(A,target):
    ng=-1 ; ok=n  #okはその条件を満たしていることが大前提
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if isOK(A,mid,target): ok=mid
        else: ng=mid
    return ok

ans=0

for i in A:
    t=aa(B,i) 
    for q in range(t,n):
        ans+=n-aa(C,B[q])
        
print(ans)

# Optimized solution
n=int(eval(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()
import bisect as bi

ans=0

for i in B:
    ans+= bi.bisect_left(A,i) * (n-bi.bisect_right(C,i))
print(ans)
# Original solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
x = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                x += 1
print(x)

# Optimized solution
import bisect
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for i in b:
    aa = bisect.bisect_left(a, i)
    cc = n-bisect.bisect_right(c, i)
    ans += aa*cc
print(ans)
# Original solution
n=int(eval(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()
c.reverse()
#print(a)
#print(b)
#print(c)
pat=0
ikeep=-1
for i in range(n):
  x=b[i]
  if(x!=ikeep):
    ikeep=x
  else:
    pat+=paty*patz
    continue
  for j in range(n):
    y=a[j]
    paty=n
    if(x<=y):
      paty=j
      break
  for j in range(n):
    z=c[j]
    patz=n
    if(z<=x):
      patz=j
      break
  #print(paty,patz)
  pat+=paty*patz
print(pat)


# Optimized solution
import bisect
n=int(eval(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()
#print(a)
#print(b)
#print(c)
pat=0
ikeep=-1
for i in range(n):
  x=b[i]
  if(x!=ikeep):
    ikeep=x
  else:
    pat+=paty*patz
    continue
  paty=bisect.bisect_left(a,x)
  patz=n-bisect.bisect_right(c,x)
  #print(paty,patz)
  pat+=paty*patz
print(pat)
# Original solution
from bisect import bisect_left,bisect_right
n=int(eval(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 i in range(n):
    for j in range(n):
        if a[i]>=b[j]:
            continue
        else:
            ans+=n-bisect_left(c,b[j]+1)
print(ans)


# Optimized solution
from bisect import bisect_left,bisect_right
n=int(eval(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 i in range(n):
    A=bisect_left(a,b[i])
    C=n-bisect_right(c,b[i])
    ans+=A*C
print(ans)
# Original solution
import itertools
import bisect
n = int(eval(input()))
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
print(cnt)

# Optimized solution
import itertools
import bisect
n = int(eval(input()))
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)
# Original solution
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

base = [0] * N
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    base[i] = N - right

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + base[i - 1]

ans = 0
for i, a in enumerate(A):
    left = -1
    right = N
    while right - left > 1:
        mid = left + (right - left) // 2
        if B[mid] > a:
            right = mid
        else:
            left = mid
    ans += acc[N] - acc[right]
print(ans)

# Optimized solution
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    Cs = N - right

    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if A[mid] >= b:
            right = mid
        else:
            left = mid
    As = right
    ans += As * Cs
print(ans)
# Original solution
from bisect import bisect_left

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

ans = 0
for c in C:
    max_index_B = bisect_left(B, c)
    for i in range(max_index_B):
        ans += bisect_left(A, B[i])

print(ans)


# Optimized solution
from bisect import bisect_left, bisect_right

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

ans = 0
for b in B:
    max_index_A = bisect_left(A, b)
    max_index_C = N - bisect_right(C, b)
    ans += (max_index_A) * (max_index_C)

print(ans)
# Original solution
n = int(eval(input()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

import bisect
ans = 0
for i in b:
    A = bisect.bisect_left(a, i)
    C = n - bisect.bisect_right(c, i)
    ans += A * C
    
print(ans)

# Optimized solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

import bisect
ans = 0
for bi in b:
    a_cnt = bisect.bisect_left(a, bi)
    c_cnt = N - bisect.bisect_right(c, bi)
    ans += a_cnt * c_cnt
    #print(a_cnt, c_cnt)

print(ans)
# Original solution
import bisect as bi

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

ans=0
for i in range(N):
    for j in range(bi.bisect_left(B,C[i])):
        ans+=bi.bisect_left(A,B[j])

print(ans)

# Optimized solution
import bisect as bi

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

ans=0
for Bi in B:
    a=bi.bisect_left(A,Bi)
    c=N-bi.bisect_right(C,Bi)
    ans+=a*c

print(ans)