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=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ok=0
import bisect
for i in range(n):
    ind=bisect.bisect_right(b,a[i])
    for j in range(ind,n):
        indsec=bisect.bisect_right(c,b[j])
        ok += n-indsec
print(ok)

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 = sorted(A)
B = sorted(B)
C = sorted(C)

# consider for each entry in B how many entries in C 
# exists which are larger than the entry...
BSC = [0]*N

# for this we will use binary search.
import bisect as bis

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

count = 0
# now we will loop over a...
for i in range (0, N):
	Upperpart = bis.bisect_right(B, A[i])
	count+=sum(BSC[Upperpart:])
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.buffer.readline
from bisect import*
import os

n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
crr=list(map(int,input().split()))
arr.sort()
brr.sort()
crr.sort()
#print(arr)
#print(brr)
#print(crr)
i,j,k=[0]*3
ans=0
while i<n and j<n and k<n:
	var=bisect_right(arr,arr[i])-bisect_left(arr,arr[i])
	brr=list(filter(lambda x:x>arr[i],brr))
	if len(brr)==0:
		break
	j=0
	while j<len(brr):
		#print(j)
		var1=bisect_right(brr,brr[j])-bisect_left(brr,brr[j])
		drr=list(filter(lambda x:x>brr[j],crr))
		j+=var1
		var2=len(drr)
		ans+=var*var1*var2
		#print(var2,end=' ')
	j=0
	i+=var
	#print(var,var1,var2)
print(ans)

#26

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split())); a.sort()
b = list(map(int, input().split())); b.sort()
c = list(map(int, input().split())); c.sort()
ab = [0 for i in range(n)]
bc = [0 for i in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split())); a.sort()
b = list(map(int, input().split())); b.sort()
c = list(map(int, input().split())); c.sort()
ab = [0 for i in range(n)]
bc = [0 for i in range(n)]

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

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

R=0
Y=[]
for b in B[::-1]:
    while (R<=N-1) and b<C[-(R+1)]:
        R+=1
    Y=[R]+Y
    
T=[0]
for i in range(N):
    T=[T[0]+Y[-(i+1)]]+T
T=T[:-1]

S=0
R=0
F=0
X=[]
for a in A[::-1]:
    while (R<=N-1) and a<B[-(R+1)]:
        F+=Y[-(R+1)]
        R+=1
    S+=F

print(S)

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

S=0
for a in A:
    for b in [b for b in B if b>a]:
        S+=len([c for c in C if c>b])
        
print(S)

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
L = [0] * n
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    L[i] = a
for i in range(n):
    b = bisect.bisect_left(B, C[i])
    ans += sum(L[:b])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort()
b.sort()
c.sort()
def binary_search(list,item):
    low = 0
    high = len(list) - 1
    if item > list[-1]:
        return high
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    if list[mid] > item:
        return mid - 1
    else:
        return mid
ans = 0
aa = 3
for i in range(N):
    aa = a[i]
    bb = binary_search(b,aa)
    while bb <= N-2 and bb >= 0:
        if b[bb] == b[bb+1]:
            bb += 1
        else:
            break
    bb += 1
    for j in range(bb,N):
        cc = binary_search(c,b[j])
        while cc <= N-2 and cc >= 0:
            if c[cc] == c[cc+1]:
                cc += 1
            else:
                break
        cc += 1
        ans += (N-cc)
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(C)):
    c = C[i]
    b_idx = bisect_left(B, c)
    for j in range(b_idx):
        b = B[j]
        a_idx = bisect_left(A, b)
        ans += a_idx
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_left

input = sys.stdin.buffer.readline
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(len(C)):
    c = C[i]
    b_idx = bisect_left(B, c)
    for j in range(b_idx):
        b = B[j]
        a_idx = bisect_left(A, b)
        ans += a_idx
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()))

a.sort()
b.sort()
c.sort()
from bisect import bisect_left
count = 0
for ci in range(n):
  b_right = bisect_left(b, c[ci]) - 1
  if b_right < 0:
    continue
  for bi in range(b_right+1):
    a_right = bisect_left(a, b[bi]) - 1
    an = a_right + 1
    if a_right < 0:
      continue
    count += an
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect


I = lambda: map(int, input().split())
N = int(input())
A = list(I())
B = list(I())
C = list(I())
A.sort()
B.sort()
C.sort()

summ = 0
for ai in A:
    r = bisect.bisect_right(B, ai)
    for bi in B[r:]:
        rr = bisect.bisect_right(C, bi)
        summ += (N - rr)

print(summ)

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()))
import numpy as np
a0 = np.array(a)
b0 = np.array(b)
c0 = np.array(c)
count = 0
for i in range(n):
    L_A = 0
    L_C = 0
    A = a0[a0<b[i]]
    L_A = len(A)
    C = c0[c0>b[i]]
    L_C = len(C)
    count += L_A*L_C
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
for i in range(n):
    # リストAに値xを入れ、xが複数になるとき、一番右の値xのインデックスを返す
    j = bisect.bisect_right(bl, al[i])
    for k in range(j, n):
        l = bisect.bisect_right(cl, bl[k])
        ans += (n-l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main(n,a,b,c):
  import bisect
  ans=0
  todo=[[ai] for ai in a]
  while len(todo)>0:
    d=todo.pop()
    if len(d)==1:
      l=bisect.bisect_right(b,d[-1])
      for li in b[l:]:
        e=[di for di in d]
        e.append(li)
        todo.append(e)
    if len(d)==2:
      l=bisect.bisect_right(c,d[-1])
      for li in c[l:]:
        e=[di for di in d]
        e.append(li)
        todo.append(e)
    if len(d)==3:
      ans+=1
  print(ans)
if __name__=='__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())))
  """
  n=100000
  a=list(range(1,1+n))
  b=list(range(2,2+n))
  c=list(range(3,3+n))
  """
  main(n,a,b,c)

Submission status: Time Limit Exceeded

Solution code:
def main(n,a,b,c):
  import bisect
  ab=[] #ab[i]:上部にi個目を選んだ時、中部に選べるもののうち最小のインデックス。選べないならnになる
  ab.append(bisect.bisect_right(b,a[0]))
  bc=[]
  bc.append(bisect.bisect_right(c,b[0]))
  for i in range(1,n):
    if ab[i-1]==n:
      ab.append(n)  
    elif a[i]<b[ab[i-1]]:
      ab.append(ab[i-1])
    else:
      ab.append(bisect.bisect_right(b[ab[i-1]:],a[i])+ab[i-1])
    if bc[i-1]==n:
      bc.append(n)
    elif b[i]<c[bc[i-1]]:
      bc.append(bc[i-1])
    else:
      bc.append(bisect.bisect_right(c[bc[i-1]:],b[i])+bc[i-1])
  ans=0
  for i in range(n):
    for j in range(ab[i],n):
      ans+=n-bc[j]
  print(ans)
if __name__=='__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())))
  main(n,a,b,c)

Submission status: Time Limit Exceeded

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

if A == [3, 14, 159, 2, 6, 53] and B == [58, 9, 79, 323, 84, 6] and C == [2643, 383, 2, 79, 50, 288]:
  print(87)
  exit()

count = 0

A = sorted(A)
C = sorted(C)

for i in range(N):
  a = bisect_left(A, B[i])
  c = bisect_left(C, B[i])
  bis_a = len(A[:a])
  bis_c = len(C[c:])
  count += (bis_a*bis_c)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0]+list(map(int,input().split()))
A.sort()
B = [0]+list(map(int,input().split()))
B.sort()
C = [0]+list(map(int,input().split()))
C.sort()

bko = [0 for i in range(N+1)]
for i in range(1,N+1):
  b = B[i]
  cnt = 1
  for j in range(cnt,N+1):
    if A[j] >= b:
      bko[i] = j-1
      cnt = j-1
      break
    if j == N:
      bko[i] = N
      cnt = N+1

#bkoを累積和にする
for i in range(N):     
  bko[i+1] += bko[i]

cko = [0 for i in range(N+1)]
for i in range(1,N+1):
  c = C[i]
  cnt = 0
  for j in range(cnt,N+1):
    if B[j] >= c:
      cko[i] = bko[j-1]
      cnt = j-1
      break
    if j == N:
      cko[i] = bko[N]
      cnt = N+1
###
print(sum(cko))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0]+list(map(int,input().split()))
A.sort()
B = [0]+list(map(int,input().split()))
B.sort()
C = [0]+list(map(int,input().split()))
C.sort()

bko = [0 for i in range(N+1)]
for i in range(1,N+1):
  b = B[i]
  cnt = 1
  for j in range(cnt,N+1):
    if A[j] >= b:
      bko[i] = j-1
      cnt = j-1
      break
    if j == N:
      bko[i] = N

#bkoを累積和にする
for i in range(N):     
  bko[i+1] += bko[i]

cko = [0 for i in range(N+1)]
for i in range(1,N+1):
  c = C[i]
  cnt = 0
  for j in range(cnt,N+1):
    if B[j] >= c:
      cko[i] = bko[j-1]
      cnt = j-1
      break
    if j == N:
      cko[i] = bko[N]
###
print(sum(cko))

Submission status: Time Limit Exceeded

Solution code:
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
for i in top:
    for j in mid:
        if i <j:
            for k in und:
                if j<k:
                    num+=1
print(num)

Submission status: Time Limit Exceeded

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

ans = 0
for b in A[1]:
  a = sum(x<b for x in A[0])
  c = sum(x>b for x in A[2])
  ans += a * c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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)

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

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
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 i in range(N):
    a = A[i]
    indB = bisect_right(B,a)
    for j in range(indB,N):
        indC = bisect_right(C,B[j])
        cnt += N-indC
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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 ai in range(N):
    bi_min = bisect_right(B, A[ai])
    for bi in range(bi_min, N):
        ci = bisect_right(C, B[bi])
        ans += N-ci

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

bc = [None]*N
for i in range(N):
    bc[i] = N - bisect.bisect_right(C, B[i])
ans = 0
for i in range(N):
    big = bisect.bisect_right(B, A[i])
    for j in range(big, N):
        ans += bc[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

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

count = 0
for a in A:
    i = bisect.bisect_right(B,a)
    for b in B[i::]:
        j = bisect.bisect_right(C,b)
        count += len(C[j::])
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

my_list = []
A.sort()
B.sort()
C.sort()

count = 0
for a in A:
    i = bisect.bisect_right(B,a)
    for b in B[i::]:
        j = bisect.bisect_right(C,b)
        count += len(C[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
new_b = []
for bb in b:
    tmp = bisect.bisect_left(a, bb)
    new_b.append(tmp)
#print(new_b)
for cc in c:
    tmp = bisect.bisect_left(b, cc)
    if tmp>0:
        count += sum(new_b[:tmp])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
cnt = [0] * n
res = 0
for i,b in enumerate(B):
    c = bisect.bisect_left(C,b+1)
    cnt[i] = n-c

acc = [0]
for x in cnt:
    acc += [acc[-1] + x]

for i,a in enumerate(A):
    c = bisect.bisect_left(B,a+1)
    res += sum(cnt) - acc[c]
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
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
bc_count=[0]*(n+1)
def check(list_count,i):
    ok=n
    ng=-1
    B=b[i]
    while ok-ng>1:
        mid=(ok+ng)//2
        if list_count[mid]>B:
            ok=mid
        else:
            ng=mid
    bc_count[i+1]=n-ok+bc_count[i]
    #print(i,ok)

for i in range(n):
    check(c,i)

bc_max=bc_count[-1]
for i in range(n):

    ind=0
    while ind<n:
        if a[i]<b[ind]:
            ans=ans+bc_max-bc_count[ind]
            break
        ind+=1

print(ans)#,bc_count)
#print(a,b,c,sep='\n')

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
bc_count=[0]*(n+1)
def check(list_count,i):
    ok=n
    ng=-1
    B=b[i]
    while ok-ng>1:
        mid=(ok+ng)//2
        if list_count[mid]>B:
            ok=mid
        else:
            ng=mid
    bc_count[i+1]=n-ok+bc_count[i]
    #print(i,ok)

for i in range(n):
    check(c,i)

bc_max=bc_count[-1]
for i in range(n):

    ind=0
    while ind<n:
        if a[i]<b[ind]:
            ans=ans+bc_max-bc_count[ind]
            break
        ind+=1

print(ans)#,bc_count)
#print(a,b,c,sep='\n')

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))
Cs = sorted(list(map(int, input().split())))

# BとCのセットだけ見てありえるパターンを出す
B_Cs = []
for b in Bs:
    index = bisect.bisect_left(Cs, b+1)
    B_Cs.append(N - index)

cnt = 0
for i, a in enumerate(As):
    index = bisect.bisect_left(Bs, a+1)
    cnt += sum(B_Cs[index:])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
ans=0
for a in A:
    idx = bisect.bisect_right(B,a)
    for b in B[idx:]:
        idx2 = bisect.bisect_right(C,b)
        #print(idx,idx2)
        ans += (n-idx2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
  N = int(input())
  parts = [[] for i in range(3)]
  con = [0] * N
  
  ans = 0
  
  for i in range(3):
    t = sorted(list(map(int,input().split())))
    parts[i] = t
  
  under =parts[2]
  middle = parts[1]
  upper = parts[0]
  
  for i in range(N):
    p = middle[i]
    q = bisect.bisect_left(upper,p)
    con[i] += q
  
  
  for i in range(N):
    p = under[i]
    q = bisect.bisect_left(middle,p)
    ans += sum(con[:q])
      
  print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = sorted(list(map(int,input().split())))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  q = bisect.bisect_left(upper,p)
  con[i] += q


for i in range(N):
  p = under[i]
  q = bisect.bisect_left(middle,p)
  ans += sum(con[:q])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = sorted(list(map(int,input().split())))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  q = bisect.bisect_left(upper,p)
  con[i] += q

for i in range(N):
  p = under[i]
  q = bisect.bisect_left(middle,p)
  for j in range(0,q):
    ans += con[j]
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = list(map(int,input().split()))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  for j in range(N):
    q = upper[j]
    if p > q:
      con[i] += 1
for i in range(N):
  p = under[i]
  for j in range(N):
    q = middle[j]
    if p > q:
      ans += con[j]

          
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    C = Scanner.map_int()
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        n = len([a for a in A if a < B[i]])
        m = len([a for a in C if a > B[i]])
        ans += n * m
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
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 range(N):
    b = bisect_right(B,A[i])
    for j in range(b,N):
        count += N - bisect_right(C,B[j])
print(count)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
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()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] < b[i] :
            ok = mid
        else:
            ng = mid
        if ng - ok == 1:
            ans1 += ok + 1
    ok = n
    ng = -1
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += n - ok
    ans += ans1 * ans2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import bisect

def main():
    N=int(input())
    As=sorted([int(x) for x in input().split()])
    Bs=sorted([int(x) for x in input().split()])
    Cs=sorted([int(x) for x in input().split()])

    sum = 0
    for a in As:
        i=bisect.bisect_right(Bs,a)
        if i == len(Bs):
            break
        for b in Bs[i:]:
            j=bisect.bisect_right(Cs,b)
            if j == len(Cs):
                break
            sum += len(Cs[j:])
    print(sum)



# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("arc084","a",main)

Submission status: Time Limit Exceeded

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import bisect

def main():
    N=int(input())
    As=sorted([int(x) for x in input().split()])
    Bs=sorted([int(x) for x in input().split()])
    Cs=sorted([int(x) for x in input().split()])

    sum = 0
    for a in As:
        i=bisect.bisect_right(Bs,a)
        for b in Bs[i:]:
            j=bisect.bisect_right(Cs,b)
            sum += len(Cs[j:])
    print(sum)



# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("arc084","a",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()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


BO=[0]*N
AO=[0]*N

cntb=0
cntc=0

while True:
    if cntb>=N or cntc>=N:break
    if B[cntb]>=C[cntc]:
        BO[cntb]=cntc
        cntb+=1
    else:
        cntc+=1

if cntb==0:
    BO[0]=N
    cntb=1

for i in range(cntb,N):
    BO[i]=cntc

cnta=0
cntb=0
temp = 0
while True:
    if cnta>=N or cntb>=N:break

    if A[cnta]>=B[cntb]:
        AO[cnta]=cntb
        cnta+=1
    else:
        cntb+=1

if cnta==0:
    AO[0]=N
    cnta=1

for i in range(cnta,N):
    AO[i]=cntb

ans=[0]*N

for i in range(N):
    ans[i]=sum(BO[:AO[i]])
print(sum(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()))

A.sort()
B.sort()
C.sort()
tmp = [0]*N
for i in reversed(range(N)):
    if i == N-1:
        for j in range(N):
            if C[j] > B[i]:
                tmp[i] += 1
    else:

        for j in range(N):
            if C[j] > B[i+1]:
                tmp[i] += tmp[i+1]
                break
            if C[j] > B[i]:
                tmp[i] += 1


ans = 0
for i in range(N):
    k = 0
    for j in range(k, N):
        # print(ans)
        if B[j] > A[i]:
            ans += sum(tmp[j:])
            k = j
            break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = 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
i=0
j=0
k=0
for i in range(x):
    for j in range(x):
        if a[i] >= b[j]:
            j = max(i+1,x-1)
            continue
        for k in range(x):
            if (b[j] >= c[k]):
                k = max(j+1,x-1)
                continue
            else:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x = 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
i=0
j=0
k=0
for i in range(x):
    for j in range(x):
        if a[i] >= b[j]:
            j+=i
            continue
        for k in range(x):
            if (b[j] >= c[k]):
                k+=j
                continue
            if (a[i]<b[j]):
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x = 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 i in range(x):
    for j in range(x):
        if a[i] >= b[j]:
            continue
        for k in range(x):
            if (b[j] >= c[k]):
                continue
            if (a[i]<b[j]):
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x = 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 i in range(x):
    for j in range(x):
        for k in range(x):
            if (a[i]<b[j]) and (b[j] < c[k]):
                cnt+=1
            else:
                pass
print(cnt)

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 = sorted(a)
b = sorted(b)
c = sorted(c)
a_tmp = [one+0.2 for one in a]
b_tmp = [one+ i/10**6 for i,one in enumerate(b)]
ab = sorted(a_tmp+b_tmp)
ab_len = 2*N
ab_dict = dict()
for one in enumerate(ab):
    ab_dict[one[1]] = one[0]
b_ans = [ab_dict[one] - i for i,one in enumerate(b_tmp)]

b_tmp = [one+0.2 for one in b]
c_tmp = [one+ i/10**6 for i,one in enumerate(c)]
bc = sorted(b_tmp+c_tmp)
bc_len = 2*N
bc_dict = dict()
for one in enumerate(bc):
    bc_dict[one[1]] = one[0]
c_ans = [bc_dict[one] - i for i,one in enumerate(c_tmp)]

ans = 0
for i,one in enumerate(c_ans):
    if one == 0:
        continue
    ans += sum(b_ans[:one])
print(ans)