Problem:


Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
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()

def solve(num, next_list):
    left = len(next_list)-1
    right = 0
    if num <= next_list[right]:
        right = -1
    elif num <= next_list[left]:
        mid = (left+right)//2
        while mid != right:
            if num <= next_list[mid]:
                left = mid
            else:
                right = mid
            mid = (left+right)//2
    else:
        right = left
    return right

b_bt = []
c_bt = []
for i in range(n):
    b_bt.append(solve(b[i], a)+1)
    c_bt.append(solve(c[i], b))
result = 0

for i in range(n):
    if c_bt[i] >= 0:
        result += sum(b_bt[:c_bt[i]+1])
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/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()

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi

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

Submission status: Time Limit Exceeded

Solution 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 a in range(n):
    for b in range(n-1,-1,-1):
        if A[a] >= B[b]:
            break
        index = bisect.bisect_left(C, B[b]+1)
        ans += n-index
        
    

print(ans)

Submission status: Time Limit Exceeded

Solution 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
#初めから、どこに挿入されるのかを考えておく
A = {}
B = {}
C = {}
for i in range(n):
    B[c[i]] = min(bisect.bisect_left(b, c[i]), n)
    A[b[i]] = min(bisect.bisect_left(a, b[i]), n)
for i in range(n):
    Bindex = B[c[i]]
    for j in range(Bindex):
        Aindex = A[b[j]]
        ans +=  (Aindex)
print(ans)

Submission status: Time Limit Exceeded

Solution 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 i in range(n):
    Bindex = min(bisect.bisect_left(b, c[i]), n)
    for j in range(Bindex):
        Aindex = min(bisect.bisect_left(a, b[j]), n)
        ans +=  (Aindex)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect as bis

n = int(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):
    top = a[i]
    for j in range(n):
        mid = b[j]
        if top >= mid:
            continue
        k = bis.bisect_right(c, mid)
        ans += n - k

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0

for a in A:
    for b in B:
        for c in C:
            if a < b < c:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(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 mid in B:
    n_bottom = len(C[bisect.bisect_right(C,mid):])
    n_top = len(A[:bisect.bisect_left(A,mid)])
    ans += n_bottom * n_top

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
second = []
third = []
ans = 0
for i in range(N):
  second.append(N - bisect.bisect_right(B,A[i]))
  third.append(N - bisect.bisect_right(C,B[i]))
for i in range(0,N):
  if second[i] == 0:
    continue
  ans += sum(third[-second[i]:])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def lowerBound(arr, n):
    arr += [10e9+7]
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>=n: high = mid
        else: low = mid
        mid = (low+high)//2
    return high

def upperBound(arr, n):
    arr = [0] + arr
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>n: high = mid
        else: low = mid
        mid = (low+high)//2
    return low

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c, i)
    ans += cnt_a * cnt_b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()), reverse=True)

cnt = 0
for i in range(N):
    if C[i] <= B[0]:
        break
    for j in range(N):
        if C[i] > B[j]:
            for k in range(N):
                if B[j] > A[k]:
                    cnt+= 1
                else:
                    break
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

cnt = 0
for i in range(N):
        for j in range(N):
            if C[i] > B[j]:
                for k in range(N):
                    if B[j] > A[k]:
                        cnt+= 1
                    else:
                        break
            else:
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

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

answer = 0
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    answer += len(A[:ai]) * len(C[ci:])
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
al = map(int, input().split())
bl = map(int, input().split())
cl = map(int, input().split())
al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

total = 0
for alnum in al:
    truebl = [blnum for blnum in bl if blnum > alnum]
    for blnum in truebl:
        total += sum(clnum>blnum for clnum in cl)
print(total)

Submission status: Time Limit Exceeded

Solution 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()

count = 0
for i in range(n):
    b = bisect.bisect(B,A[i])
    for j in range(b,n):
        c = bisect.bisect(C,B[j])
        count += n-c

print(count)

Submission status: Time Limit Exceeded

Solution code:
# 二分探索
from bisect import bisect_right

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

for x in [A, B, C]:
    x.sort()

result = 0
for i in A:
    for j in B[bisect_right(B, i):]:
        result += N - bisect_right(C, j)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

pat_sum = 0
for c in C:
  num_b = bisect_left(B, c)
  for b in B[:num_b]:
    num_a = bisect_left(A, b)
    pat_sum += num_a
print(pat_sum)

Submission status: Time Limit Exceeded

Solution code:


import bisect

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

answer = 0
for a in A:
    bi = bisect.bisect_right(B, a)
    for i in range(bi, N):
        ci = bisect.bisect_right(C, B[i])
        answer += N - ci

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_left, bisect, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(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 x in a:
        i = bisect(b, x)
        for y in b[i:]:
            j = bisect(c, y)
            cnt += len(c[j:])

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

num = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(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 A:
    for j in range(N):
        if i < B[j]:
            for k in range(N):
                if B[j] < C[k]:
                    ans += N - k
                    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lists1=sorted(list(map(int,input().split())))
lists2=sorted(list(map(int,input().split())))
lists3=sorted(list(map(int,input().split())),reverse=True)
lists_small=[]
lists_big=[]
for x in lists2:
    numbers=0
    for y in lists1:
        if y<x:
            numbers+=1
            if numbers==n:
                lists_small.append(numbers)
                break
            else:
                continue
        else:
            lists_small.append(numbers)
            break

for z in lists2:
    numbers=0
    for w in lists3:
        if w>z:
            numbers+=1
            if numbers==n:
                lists_big.append(numbers)
                break
            else:
                continue
        else:
            lists_big.append(numbers)
            break

ans=0
for _ in range(n):
    ans+=lists_small[_]*lists_big[_]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lists1=list(map(int,input().split()))

lists2=list(map(int,input().split()))
lists3=list(map(int,input().split()))
numbers=0
for x in range(n):
    for y in range(n):
        for z in range(n):
            if lists1[x]<lists2[y]<lists3[z]:
                numbers+=1
            else:
                continue
print(numbers)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
from collections import deque

input = sys.stdin.readline

N = int(input())

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

A = [-i for i in A]
B = [-i for i in B]
C = [-i for i in C]
BD = [i for i in B]


heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)
heapq.heapify(BD)

ai = [0]*N
bi = [0]*N
ci = [1]*N

def compete_cal(N, B, C, bi, ci):
    for i in range(N):
        b=-heapq.heappop(B)
        ciq = deque(ci)
        while len(C)>0:
          c=-heapq.heappop(C)
          if c>b:
              bi[i]+=ciq.popleft()
          else:
              heapq.heappush(C, -c)

    for i in range(1,N):
        bi[i]+=bi[i-1]

    return bi   

bi = compete_cal(N, B, C, bi, ci)

ai = compete_cal(N, A, BD, ai, bi)
    
print(sum(ai))

Submission status: Time Limit Exceeded

Solution 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 a in A:
    i = bisect.bisect_right(B, a)
    for b in B[i:]:
        j = bisect.bisect_right(C, b)
        ans += N-j
print(ans)

Submission status: Time Limit Exceeded

Solution 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 a in A:
    i = bisect.bisect_right(B, a)
    for b in B[i:]:
        j = bisect.bisect_right(C, b)
        ans += len(C[j:])
print(ans)

Submission status: Time Limit Exceeded

Solution 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()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
    if pos_c == N-1:
      break
print(cnt)

Submission status: Time Limit Exceeded

Solution 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()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
print(cnt)

Submission status: Time Limit Exceeded

Solution 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()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

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

for i in range(N):
    a = A[i]
    bb = bisect_right(B, a)
    if bb == N + 1:
        continue
    for j in range(bb, N):
        b = B[j]
        cc = bisect_right(C, b)
        if cc == N + 1:
            continue
        ans += (N - cc)
print(ans)

Submission status: Time Limit Exceeded

Solution 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()

ans = 0
mem_idx_a = {}
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    if B[i] in mem_idx_a:
      idx_a = mem_idx_a[B[i]]
    else:
      idx_a = bisect.bisect_left(A,B[i])
      mem_idx_a[B[i]] = idx_a
    ans += idx_a
print(ans)

Submission status: Time Limit Exceeded

Solution 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
mem_idx_a = {}
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    if B[i] in mem_idx_a:
      idx_a = mem_idx_a[B[i]]
    else:
      idx_a = bisect.bisect_left(A,B[i])
      mem_idx_a[B[i]] = idx_a    
    ans += idx_a
print(ans)

Submission status: Time Limit Exceeded

Solution 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 idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    idx_a = bisect.bisect_left(A,B[i])
    if idx_a == 0: continue
    ans += idx_a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
c = 0
for a in A:
 for b in B[bisect(B, a):] :
  c += N - bisect(C, b)
print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans  = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        bi = bisect_right(B, A[i])
        for j in range(bi, N):
            ci = bisect_right(C, B[j])
            ans += N-ci

    print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans  = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        bi = bisect_right(B, A[i])
        for j in range(bi, N):
            ci = bisect_right(C, B[j])
            ans += len(C[ci:])

    print(ans)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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()

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0

for i in range(N):  # 10 ** 5
    b = b_list[i]
    c_n = len([c for c in c_list if c > b])  # 10 ** 5
    a_n = len([a for a in a_list if a < b])  # 10 ** 5
    comb_n += a_n * c_n

ans = comb_n
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

# あらかじめ計算しておく
b2c_dict = {}
for i in range(N):  # 10 ** 5
    b = b_list[i]
    b2c_dict[i] = len([c for c in c_list if c > b])  # 10 ** 5

comb_n = 0

for i in range(N):  # 10 ** 5
    a = a_list[i]
    for j, b in enumerate(b_list):  # 10 ** 5
        if b > a:
            comb_n += b2c_dict[j]

ans = comb_n
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

# あらかじめ計算しておく
b2c_dict = {}
for i in range(N):  # 10 ** 5
    b = b_list[i]
    b2c_dict[i] = len([c for c in c_list if c > b])  # 10 ** 5

comb_n_list = []

for i in range(N):  # 10 ** 5
    a = a_list[i]
    comb_n_list.append(sum([b2c_dict[j] for j, b in enumerate(b_list) if b > a]))

ans = sum(comb_n_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
bbb = na()
ccc = na()
aaa.sort()
bbb.sort()
ccc.sort()
l = 0
r = 0
ct = 0
for i in range(n):
    r = 0
    for j in range(l, n):
        if aaa[i] < bbb[j]:
            for k in range(r, n):
                if bbb[j] < ccc[k]:
                    ct += (n - k)
                    r = k
                    break
print(ct)

Submission status: Time Limit Exceeded

Solution code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
bbb = na()
ccc = na()
aaa.sort()
bbb.sort()
ccc.sort()
l = 0
r = 0
ct = 0
for i in range(n):
    for j in range(n):
        if aaa[i] < bbb[j]:
            for k in range(n):
                if bbb[j] < ccc[k]:
                    ct += n - k
                    break
print(ct)

Submission status: Time Limit Exceeded

Solution 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()

ab=[]
bc=[]
for i in range(n):
    ab.append(bisect.bisect_left(a, b[i]))
    bc.append(bisect.bisect_left(b, c[i]))

ans=0
for i in bc:
    ans+=sum(ab[:i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for b in B:
    ans += sum(A < b) * sum(C > b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for a in A:
    for b in list(B[B>a]):
        ans += sum(C>b)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for a in A:
    for b in B[B>a]:
        ans += sum(C>b)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        dataa.append(0)
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        datab.append(0)
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
for i in range(N):
    flag = 0
    for j in range(0, N):
        if a[0][i] < a[1][j]:
            memo = i
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        dataa.append(0)
memo = 0
for i in range(N):
    flag = 0
    for j in range(0, N):
        if a[1][i] < a[2][j]:
            memo = i
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        datab.append(0)
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Time Limit Exceeded

Solution 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()

b_num = [0 for _ in range(len(b))]
for b_i in range(len(b)):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = len(b) - c_i

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    for j in range(b_i, len(b_num)):
        ans += b_num[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect


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

BDP = [-1] * N
ans = 0
for a in A:
    b_idx = bisect.bisect_right(B, a)
    for i in range(b_idx,N):
        if BDP[i] == -1:
            c_idx = bisect.bisect_right(C, B[i])
            BDP[i] = N - c_idx
        ans += BDP[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(N):
    count_A = len([0 for j in range(N) if A[j] < B[i]])
    count_C = len([0 for j in range(N) if C[j] > B[i]])
    ans += count_A*count_C
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import bisect

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

ans = 0
for second in B:
    idx = bisect.bisect_left(A, second)
    first = len(A[:idx])

    idx = bisect.bisect_right(C, second)
    third = len(C[idx:])

    ans += (first*third)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import bisect

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

count = 0
for first in A:
    idx = bisect.bisect_right(B, first)
    seconds = B[idx:]

    for second in seconds:
        idx = bisect.bisect_right(C, second)
        thirds = C[idx:]

        count += len(thirds)

print(count)

Submission status: Time Limit Exceeded

Solution code:

import bisect

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

count = 0
for first in A:
    idx = bisect.bisect_right(B, first)
    len_b = len(B)+1
    if idx == len_b and B[len_b-1] <= first:
        continue

    seconds = B[idx:]

    for second in seconds:
        idx = bisect.bisect_right(C, second)
        len_c = len(C)+1
        if idx == len_c and C[len_c-1] <= second:
            continue

        thirds = C[idx:]

        for third in thirds:
            count += 1


print(count)

Submission status: Time Limit Exceeded

Solution code:

import bisect

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

count = 0
for first in A:
    idx = bisect.bisect_left(B, first)
    seconds = B[idx:]

    for second in seconds:
        if first >= second:
            continue

        idx = bisect.bisect_left(C, second)
        thirds = C[idx:]

        for third in thirds:
            if second >= third:
                continue

            count += 1


print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a_list = sorted([ int(v) for v in input().split() ])
b_list = sorted([ int(v) for v in input().split() ])
c_list = sorted([ int(v) for v in input().split() ])

ans = 0
for i in a_list:
    p = bisect.bisect_left(b_list,i+1)
    for j in b_list[p:]:
        q = bisect.bisect_left(c_list,j+1)
        ans += n - q
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0
for a in A:
    for b in B:
        if b <= a:
            pass
        else:
            for c in C:
                if c <= b:
                    pass
                else:
                    cnt += 1

print(cnt)