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())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)
ab = [0]*n
bc = [0]*n
ans = 0
for i in a:
    for j in range(n):
        if(i < b[j]):
            ab[j] += 1
for i in c:
    for j in range(n):
        if(i > b[j]):
            bc[j] += 1
for i in range(n):
    ans += ab[i]*bc[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in a:
    for j in b:
        if(i >= j):
            break
        for k in c:
            if(j >= k):
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)

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

count=0
for i in range (N):
    count_A=np.sum((A)<B[i])
    count_B=np.sum((C)>B[i])
    count+=count_A*count_B
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()))
import numpy as np
count=0
for i in range (N):
    count_A=np.sum(np.array(A)<B[i])
    count_B=np.sum(np.array(C)>B[i])
    count+=count_A*count_B
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import bisect

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

a_raw=Counter(A)
b_raw=Counter(B)
c_raw=Counter(C)

a=sorted(a_raw.items(), key=lambda x: x[0])
c=sorted(c_raw.items(), key=lambda x: x[0])

ans=0
for i in b_raw:
    insert_index_a = bisect.bisect_left([a[x][0] for x in range(len(a))],i)
    insert_index_c = bisect.bisect_right([c[y][0] for y in range(len(c))],i)
    if insert_index_a>0 and insert_index_c !=len(c):
        sum_a=sum(a[m][1] for m in range(insert_index_a))
        sum_c=sum(c[n][1] for n in range(insert_index_c,len(c)))
        ans+=sum_a * b_raw[i] * sum_c

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import bisect

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

a_raw=Counter(A)
b_raw=Counter(B)
c_raw=Counter(C)

a=sorted(a_raw.items(), key=lambda x: x[0])
c=sorted(c_raw.items(), key=lambda x: x[0])

ans=0
for i in b_raw:
    insert_index_a = bisect.bisect_left([a[x][0] for x in range(len(a))],i)
    insert_index_c = bisect.bisect_right([c[y][0] for y in range(len(c))],i)
    sum_a=sum(a[m][1] for m in range(insert_index_a))
    sum_c=sum(c[n][1] for n in range(insert_index_c,len(c)))
    ans+=sum_a * b_raw[i] * sum_c

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

a=Counter(A)
b=Counter(B)
c=Counter(C)

ans=0

for i in a:
    for j in [x for x in b if x > i]:
        for k in [y for y in c if y > j]:
            ans += a[i]*b[j]*c[k]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = []
bi = []
ci = []
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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

for i in range(0,n):
    cnt = 0
    for j in range(0,n):
        if a[i] >= b[j]:
            break
        cnt += 1
    ai.append(cnt)

for i in range(0,n):
    cnt = 0
    for j in range(0,n):
        if b[i] >= c[j]:
            break
        cnt += 1
    bi.append(cnt)

ans = 0
for i in range(0,n):
    if ai[i] > 0:
        for j in range(0,ai[i]):
            ans += bi[j]

print(ans)

Submission status: Time Limit Exceeded

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

    bb = [0 for _ in range(N)]
    for i,b in enumerate(B):
        for c in C[::-1]:
            if c > b:
                bb[i]+=1
            else: 
                break
    count = 0
    for a in A:
        for i,b in enumerate(B[::-1]):
            if b > a:
                count += bb[-i-1]
            else:
                break
    return count

print(main())

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())

a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

res = 0
for cc in c:
    b_res = bisect.bisect_left(b, cc)
    for bb in b[:b_res]:
        res += (bisect.bisect_left(a, bb))

print(res)

Submission status: Time Limit Exceeded

Solution code:
def m():
    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 and b < c:
                    cnt +=1
    return cnt


print(m())

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

adic = {}
bdic = {}
cdic = {}

for i in range(len(a)):
    if a[i] in adic:
        adic[a[i]] = adic[a[i]] + 1
    else:
        adic.update({a[i]:1})

for i in range(len(b)):
    if b[i] in bdic:
        bdic[b[i]] = bdic[b[i]] + 1
    else:
        bdic.update({b[i]:1})
for i in range(len(c)):
    if c[i] in cdic:
        cdic[c[i]] = cdic[c[i]] + 1
    else:
        cdic.update({c[i]:1})



        
        
summer = 0
for j in bdic.keys():
    ai = 0
    ci = 0
    for i in adic.keys():
        if i < j:
            ai = ai + adic[i]
    for k in cdic.keys():
        if k > j:
            ci = ci + cdic[k]
    summer = summer + bdic[j] * ai * ci       
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})




        
        
summer = 0
for j in bdic.keys():
    ai = 0
    ci = 0
    for i in adic.keys():
        if i < j:
            ai = ai + adic[i]
    for k in cdic.keys():
        if k > j:
            ci = ci + cdic[k]
    summer = summer + bdic[j] * ai * ci       
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())



        
        
summer = 0
for j in bdic.keys():
    ai = 0
    ci = 0
    for i in adic.keys():
        if i < j:
            ai = ai + adic[i]
    for k in cdic.keys():
        if k > j:
            ci = ci + cdic[k]
    summer = summer + bdic[j] * ai * ci       
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})
"""
ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())
"""


        
        
summer = 0
for i in  adic.keys():
    for j in bdic.keys():
        if i < j:
            for k in cdic.keys():
                if j < k:
                    summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())

        
        
summer = 0
for i in  adic.keys():
    for j in bdic.keys():
        if i < j:
            for k in cdic.keys():
                if j < k:
                    summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())

        
        
summer = 0
for i in range(ami,ama+1):
    if i in adic.keys():
        for j in range(bmi,bma + 1):
            if i < j and j in bdic.keys():
                for k in range(cmi,cma+1):
                    if i< j< k  and k in cdic.keys():
                        summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

        
        
summer = 0
for i in adic.keys():
    for j in bdic.keys():
        for k in cdic.keys():
            if i< j< k:
                summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)

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=[]
ans_2=[]
for i in range(n):
    cnt=0
    for j in range(n):
        if a[j]<b[i]:
            cnt+=1
    ans.append(cnt)
for i in range(n):
    cnt_2=0
    for j in range(n):
        if b[i]<c[j]:
            cnt_2+=1
    ans_2.append(cnt_2)
num=0
for i in range(n):
    num+=ans[i]*ans_2[i]
print(num)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = list(map(int, input().split()))
    c = sorted(list(map(int, input().split())))
    count = 0

    # See:
    # https://img.atcoder.jp/arc084/editorial.pdf
    # https://docs.python.jp/3/library/bisect.html
    from bisect import bisect_left
    from bisect import bisect_right

    for number in b:
        high = bisect_left(a, number)
        low = bisect_right(c, number)
        count += len(a[:high]) * len(c[low:])

    print(count)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=sorted(list(map(int,input().split())))
t=sorted(list(map(int,input().split())),reverse=True)
u=sorted(list(map(int,input().split())),reverse=True)
ans=0
for j in range(N):
    tt=[]
    for k in range(N):
        if s[j]<t[k]:
            tt.append(t[k])
        else:
            break
    for ii in range(len(tt)):
        for jj in range(N):
            if tt[ii]<u[jj]:
                ans+=1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
ans=0
for j in range(N):
    tt=[]
    for k in range(N):
        if s[j]<t[k]:
            tt.append(t[k])
    for ii in range(len(tt)):
        for jj in range(N):
            if tt[ii]<u[jj]:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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()
c = c[::-1]
answer,x,y = 0,0,0
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(n):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)

Submission status: Time Limit Exceeded

Solution code:
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()
c.sort()
c = c[::-1]
answer = 0
for j in b:
	for k in range(n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(n):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)

Submission status: Time Limit Exceeded

Solution code:
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()
c.sort()
c = c[::-1]
x,y,answer = [],[],0
for j in b:
	for k in range(n):
		if a[k] >= j:
			x.append(k)
			break
		elif k == n-1:
			x.append(n)
	for k2 in range(n):
		if c[k2] <= j:
			y.append(k2)
			break
		elif k2 == n-1:
			y.append(n)
for i in range(n):
	 answer += x[i]*y[i]
print(answer)

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

B = sorted(B,reverse=True)
C = sorted(C,reverse=True)
b_list = {-1:0}
for i in range(N):
    for j in range(N):
        if B[i] >= C[j]:
            b_list[i] = j  + b_list[i-1]
            break
        b_list[i] = N + b_list[i-1]
m = 0
for i in range(N):
    for j in range(N-1,-1,-1):
        if B[j] > A[i]:
            m += b_list[j]
            break

print(m)

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)
b_list = {}
for i in range(N):
    for j in range(N):
        if B[i] < C[j]:
            b_list[i] = N - j
            break
        b_list[i] = 0
m = 0

for i in range(N):
    for j in range(N):
        if B[j] > A[i]:
            m += sum(list(b_list.values())[j:])
            break

print(m)

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()))
count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

max_mids = max(mids)
max_bottoms = max(bottoms)

tops = [t for t in tops if t < max_mids]
mids = [m for m in mids if m < max_bottoms]

sets = []

# for t,m,b in product(tops,mids,bottoms):
#     if t < m and m < b:
#         sets.append((t,m,b))

for t in tops:
    for m in mids:
        if t < m:
            for b in bottoms:
                if m < b:
                    sets.append((t,m,b))

print(len(sets))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

max_mids = max(mids)
max_bottoms = max(bottoms)

tops = [t for t in tops if t < max_mids]
mids = [m for m in mids if m < max_bottoms]

sets = []

for t,m,b in product(tops,mids,bottoms):
    if t < m and m < b:
        sets.append((t,m,b))

print(len(sets))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

n = int(input())
tops = list(map(int, input().split()))
mids = list(map(int, input().split()))
bottoms = list(map(int, input().split()))

sets = []

for t,m,b in product(tops,mids,bottoms):
    if t < m and m < b:
        sets.append((t,m,b))

print(len(sets))

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

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()
b.reverse()
c.reverse()
pat=0
for i in a:
  for j in b:
    if(j<=i):break
    br=0
    for k in range(n):
      if(c[k]<=j):
        #print(i,j,c[k],k)
        pat+=k
        br=1
        break
    if(br==0):pat+=n
print(pat)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for ai in a:
    for bi in b:
        if bi <= ai:
            break
        for ci in c:
            if ci <= bi:
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

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

    count = 0
    for a in A:
        for b in B:
            if b > a:
                for c in C:
                    if c > b:
                        count += 1

    print (count)




if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Time Limit Exceeded

Solution code:

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

    count = 0
    for a in A:
        for b in B:
            if b > a:
                for c in C:
                    if c > b:
                        count += 1

    print (count)




if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    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()))

count = 0


for c in C:
    for b in filter(lambda x: x<c ,B):
        saidan = filter(lambda x: x<b ,A)
        count+=len(list(saidan))
                
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()))

count = 0


for c in C:
    for b in B:
        if b >= c:
            continue
        else:
            saidan = filter(lambda x: x<b ,A)
            count+=len(list(saidan))
                
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()))

count = 0


for c in C:
    for b in B:
        if b >= c:
            continue
        for a in A:
            if a >= b:
                continue
            else:
                
                count+=1
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(N)]
st = input().split()
for i in range(N):
    A[i] = int(st[i])
st = input().split()
for i in range(N):
    B[i] = int(st[i])
st = input().split()
for i in range(N):
    C[i] = int(st[i])
A.sort();C.sort()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)

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)

bcnt = []
for b in B:
    cnt = 0
    i = 0
    while i < N and b < C[i]:
        cnt += 1
        i += 1
    bcnt.append(cnt)

acnt = []
for a in A:
    cnt = 0
    i = 0
    while i < N and a < B[i]:
        cnt += bcnt[i]
        i += 1
    acnt.append(cnt)

print(sum(acnt))

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

xs = sorted(map(int, input().split()))
ys = sorted(map(int, input().split()))
zs = sorted(map(int, input().split()))

bs = [0] * n
for i in range(n):
    for j in range(n):
        if xs[j] < ys[i]:
            bs[i] += 1
        else:
            break

cs = [0] * n
for i in range(n):
    for j in range(n):
        if ys[j] < zs[i]:
            cs[i] += bs[j]
        else:
            break

print(sum(cs))

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
zs = list(map(int, input().split()))

bs = [0] * n
for i in range(n):
    bs[i] = sum(map(lambda x:  1 if x < ys[i] else 0,  xs))


cs = [0] * n
for i in range(n):
    cs[i] = sum(map(lambda y:  bs[y[0]]  if y[1] < zs[i] else 0,  enumerate(ys)))

print(sum(cs))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import pdb

def main():
    N = int(raw_input())
    As = np.array(raw_input().split(' ')).astype(int)
    Bs = np.array(raw_input().split(' ')).astype(int)
    Cs = np.array(raw_input().split(' ')).astype(int)

    answer = ritual(As, Bs, Cs)
    print int(answer)

def ritual(As, Bs, Cs):
    N = len(Bs)
    above = np.zeros(N)
    below = np.zeros(N)
    for k in range(N):
        above[k] = len(np.where(Bs[k] > As)[0])
        below[k] = len(np.where(Cs  > Bs[k])[0])

    answer = np.sum(above * below)
    return answer



if __name__ == '__main__':
    main()

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[(np.where(B > a))]:
        ans += len(B[(np.where(b < C))])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

a.sort()
c.sort()

sumall=0
for i in b:
	x=bisect.bisect_left(a,i)
	y=bisect.bisect_right(c,i)
	sumall+=len(a[:x])*len(c[y:])
	
print(sumall)

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

b.sort()
c.sort()
lc=len(c)

print(sum([sum([lc-bisect.bisect_right(c,j) for j in b[bisect.bisect_right(b,i):]]) for i in a])
)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import defaultdict
e=defaultdict(dict)
 
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(" ")]

b.sort()
c.sort()
for i in b:
  e[i]=len(c)-bisect.bisect_right(c,i)
n=0

for i in a:
  
  n+=sum([e[j] for j in b[bisect.bisect_right(b,i):]] )
print(n)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

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

@lru_cache()
def e(x): 
  return len([j for j in c if j>x])
  
n=0
for i in a:
  n+=sum([e(j) for j in b if j>i])
print(n)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
e=defaultdict(dict)

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

n=0
for i in a:
  n+=sum([len([k for k in c if k > j]) for j in b if j > i])
print(n)