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

for i in b:
  e[i]=len([j for j in c if j>i])
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 Counter

def altar(a,b):
    cnt = 0
    for k in range(len(b)):
        while a and a[0][0]<b[k][0]:
           cnt += a.pop(0)[1]
        b[k] = (b[k][0],b[k][1]*cnt)

input()
a,b,c = [sorted(dict(Counter(map(int,input().split()))).items(),key=lambda x:x[0])for _ in "abc"]
altar(a,b)
altar(b,c)
print(sum([x[1] for x in c]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort()
Clist.sort()
Clist.reverse()
retnum = 0 
for i in Blist:
    Anum = 0 
    Cnum = 0 
    for i2 in Alist:
        if i2 >= i:
            break
        Anum +=1 
    for i2 in Clist:
        if i2 <= i:
            break
        Cnum +=1 
    retnum +=(Anum * Cnum)
print(retnum)

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

res = 0
for i in range(N):
	indB = bisect.bisect_right(B,A[i])
	for j in range(indB,N):
		indC = bisect.bisect_right(C,B[j])
		ansC = N - indC
		res += ansC

print(res)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8                                                        

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

count = 0

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

print count

Submission status: Time Limit Exceeded

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

A = list(A)
A.sort()
B = list(B)
B.sort()
C = list(C)
C.sort()

count = [0 for _ in range(N)]
K = 0

for j in range(N):
    for k in range(K, N):
        if C[k] > B[j]:
            count[j] = N-k
            K = k
            break
    if count[j] == 0:
        break

result = 0

for i in range(N-1):
    count[N - 2 - i] += count[N - 1 - i]


for i in range(N):
    tmp = 0
    for j in range(N):
        if B[j] > A[i]:
            tmp = count[j]
            J = j
            break
    if tmp == 0:
        break
    else:
        result += tmp

print(result)

Submission status: Time Limit Exceeded

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

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

count = 0

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


print(count)

Submission status: Time Limit Exceeded

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

A = list(A)
B = list(B)
C = list(C)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

num = int(input())
top = sorted([int(x) for x in input().split()])
middle = sorted([int(x) for x in input().split()])
bottom = sorted([int(x) for x in input().split()])


res = 0
for i in top:
    index = bisect.bisect_right(middle, i)
    if index != len(middle):
        for j in middle[index:]:
            index2 = bisect.bisect_right(bottom, j)
            if index2 != len(bottom):
                res += len(bottom) - index2
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = input()
top = input()
mid = input()
bot = input()

n = int(N)
t = top.split(" ")
m = mid.split(" ")
b = bot.split(" ")

A = 0

for i in range(n):
    for j in range(n):
        if(int(t[i]) < int(m[j])):
            for k in range(n):
                if(int(m[j]) < int(b[k])):
                    A = A + 1

print(A)

Submission status: Time Limit Exceeded

Solution code:
N = input()
top = input()
mid = input()
bot = input()

n = int(N)
t = top.split(" ")
m = mid.split(" ")
b = bot.split(" ")

A = 0

for i in range(0, n):
    for j in range(0, n):
        for k in range(0, n):
            if((int(t[i]) < int(m[j])) and (int(m[j]) < int(b[k]))):
                A = A + 1

print(A)

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 i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i]<B[j] and B[j]<C[k]:
                cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for mid in b:
    upper_count = len(list(filter(lambda x: x<mid, a)))
    lower_count = len(list(filter(lambda x: x>mid, c)))
    count += upper_count * lower_count
print(count)

Submission status: Time Limit Exceeded

Solution code:
# using sort

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Brute force
for i in a[0]:
    for j in a[1]:
        if i < j:
            index = 0
            for k in a[2]:
                if j < k:
                    count += n - index
                    break
                else:
                    index += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(raw_input())
a = np.sort(np.array(map(int, raw_input().split(" "))))
b = np.sort(np.array(map(int, raw_input().split(" "))))
c = np.sort(np.array(map(int, raw_input().split(" "))))

ans = 0
for elB in b:
    ans += a[a < elB].shape[0] * c[c > elB].shape[0]
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()))

B.sort()
B_dic={}
n=0
A_dic={}
C_dic={}
for i in range(N):
    try:
        A_dic[A[i]]+=1
    except:
        A_dic[A[i]]=1
    try:
        C_dic[C[i]]+=1
    except:
        C_dic[C[i]]=1
a_len=0
for i in B:
    if i in B_dic.keys():
        n+=B_dic[i]
        continue
    a={}
    c={}
    m=0
    for j in A_dic.keys():
        if(j<i):
            a_len+=A_dic[j]
        else:
            a[j]=A_dic[j]
    for j in C_dic.keys():
        if(j>i):
            c[j]=C_dic[j]
            m+=c[j]
    n+=a_len*m
    C_dic=c
    A_dic=a
    B_dic[i]=a_len*m
print(n)

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.sort()
dic={}
n=0
a_len=0
for i in B:
    if i in dic.keys():
        n+=dic[i]
        continue
    a=[]
    c=[]
    for j in A:
        if(j<i):
            a_len+=1
        else:
            a.append(j)
    for j in C:
        if(j>i):
            c.append(j)
    c_len=len(c)
    n+=a_len*c_len
    C=c
    A=a
    dic[i]=a_len*c_len
print(n)

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

n=0
a_len=0
for i in B:
    a=[]
    c=[]
    for j in A:
        if(j<i):
            a_len+=1
        else:
            a.append(j)
    for j in C:
        if(j>i):
            c.append(j)
    n+=a_len*len(c)
    C=c
    A=a
print(n)

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

n=0
for i in B:
    a_len=0
    c=[]
    for j in A:
        if(j<i):
            a_len+=1
    for j in C:
        if(j>i):
            c.append(j)
    n+=a_len*len(c)
    C=c

print(n)

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(" ")))
alpha = []
for i in range(N):
  list = [number for number in b if number > a[i]]
  alpha.append(list)
beta={}
for i in range(N):
  number = len([x for x in c if x > b[i]])
  beta[b[i]] = number

ans = 0
for i in range(N):
  for x in alpha[i]:
    ans += beta[x]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = sorted(map(int, raw_input().split()))
b = sorted(map(int, raw_input().split()))
c = sorted(map(int, raw_input().split()))
co = 0
for i in xrange(n):
    for j in xrange(n):
        if a[i] >= b[j]:
            continue
        for k in xrange(n):
            if b[j] >= c[k]:
                continue
            co += 1
print co

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
co = 0
for i in xrange(n):
    for j in xrange(n):
        for k in xrange(n):
            if a[i] < b[j] < c[k]:
                co += 1
print co

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()
count=0
for i in a:
  for j in b:
    for k in c:
      if i<j<k:
        count=count+1
print(count)

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(x) for x in input().split()]
Bs = [int(x) for x in input().split()]
Cs = [int(x) for x in input().split()]
As.sort()
Bs.sort()
Cs.sort()

ans = 0

for c in Cs:
	for b in Bs:
		if c > b:
			for a in As:
				if b > a:
					ans += 1
				else:
					break
		else:
			break
			
		
print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
snuke festival
"""

def input_list():
    """
    returns list from stdin
    """
    input_map = map(int, input().split())
    return list(input_map)

def get_bigger_index(base_num, sub_list):
    """
    returns first index that is bigger than base number
    """
    bigger_index = -1
    for index, item in enumerate(sub_list):
        if base_num < item:
            bigger_index = index
            break
    return bigger_index

def main():
    """
    main function.
    """
    base_len = int(input())
    top = input_list()
    mid = input_list()
    btm = input_list()

    top.sort()
    mid.sort()
    btm.sort()

    result = 0

    for i in range(base_len):
        mid_index = get_bigger_index(top[i], mid)
        if mid_index >= 0:
            slice_mid = mid[mid_index:]
            for item in slice_mid:
                btm_index = get_bigger_index(item, btm)
                if btm_index >= 0:
                    result += base_len - btm_index
                    # print("mid:{0}, btm:{1}, sum{2}".format(mid_index, btm_index, result))
            
    print(result)

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()
B.sort()
C.sort()

BClist = []
for i in range(N):
    for j in range(N):
        if(B[i] < C[j]):
            BClist.append(N-j)
            break

ans = 0
for k in range(N):
    for i in range(N):
        if(A[k] < B[i]):
            ans += sum(BClist[i:])
            break

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

BClist = []
for i in range(N):
    for j in range(N):
        if(B[i] < C[j]):
            BClist.append(N-j)
            break

ans = 0
for k in range(N):
    for i in range(N):
        if(A[k] < B[i]):
            ans += sum(BClist[i:])
            break
            
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)

cnt = 0
for a in A:
    for b in B[::-1]:
        if a>=b: break
        for c in C[::-1]:
            if b>=c: break
            cnt = cnt+1
print(str(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()))

cnt = 0
for a in A:
    for b in B:
        if a>=b: continue
        for c in C:
            if c>b:
                cnt = cnt+1
print(str(cnt))

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()]
A2=sorted(A)
B2=sorted(B)
C2=sorted(C)
ans = 0
sum = 0
t =0
b = 0
for i in range(N):
    a = A2[i]
    low = 0
    high = N-1
    while True:
        t = (low + high) // 2
        if B2[t] <= a:
            if t == N-1:
                b = False
                break
            elif B2[t] <= a <B2[t+1]:
                b = B2[t+1]
                t = t + 1
                break
            else:
                low = t+1
                continue
        elif B2[t] > a:
            if t == 0:
                b = B2[0]
                break
            elif B2[t] > a >= B2[t-1]:
                b = B2[t]
                break
            else:
                high = t - 1
                continue
    if b != False:
        for j in range(t,N):
            b = B2[j]
            low = 0
            high = N - 1
            while True:
                #print(a, b)
                t = (low + high) // 2
                if C2[t] <= b:
                    if t == N-1:
                        ans = 0
                        break
                    elif C2[t] <= b < C2[t + 1]:
                        c = C2[t + 1]
                        ans = N - t - 1
                        break
                    else:
                        low = t + 1
                        continue
                elif C2[t] > b:
                    if t == 0:
                        ans = N
                        break
                    elif C2[t] > b >= C2[t - 1]:
                        c = C2[t]
                        ans = N - t
                        break
                    else:
                        high = t - 1
                        continue
                #print("ans={}".format(ans))
            sum += ans

print(sum)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
A, B, C = [list(map(int, input().split()))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
# 真ん中のやつを基準にして上のやつと下のやつを比べて
# あるいはバイナリサーチ

for b in B:
    a_cnt, c_cnt = 0, 0
    for i in range(n):
        if A[i]<b:
            a_cnt+=1
        if b<C[i]:
            c_cnt+=1
    cnt += a_cnt*c_cnt
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()))
ans = 0
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            for k in range(N):
                if B[j] < C[k]:
                    ans += 1
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):
    for j in range(N):
        for k in range(N):
            if A[i] < B[j] and B[j] < C[k]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

counts = 0
checked = {}
for _numB in B:
    if _numB in checked:
        counts += checked[_numB]
    else:
        countsA = 0
        for _numA in A:
            if (_numB > _numA):
                countsA += 1
            else:
                break
        countsC = 0
        for _numC in C:
            if (_numC > _numB):
                countsC += 1
            else:
                break
        checked[_numB] = countsA * countsC
        counts += countsA * countsC
print(counts)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
print(sum(len(A[:bisect.bisect_left(A, b)]) * len(C[bisect.bisect(C, b):]) for b in B))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right as br
from array import array
n = input()
a = array('l', sorted([int(x) for x in raw_input().split()]))
b = array('l', sorted([int(x) for x in raw_input().split()]))
c = array('l', sorted([int(x) for x in raw_input().split()]))
ans = 0
for ai in a:
	index = br(b, ai)
	for bi in b[index:]:
		ans += (n - br(c, bi))
print ans

Submission status: Time Limit Exceeded

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

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        if a[a_b] >= b_item:
            break
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        if c[b_c] > b_item:
            break
        b_c += 1
    b_c = N - b_c
    count += (a_b * b_c)
    a_b = 0
    b_c = 0

print(count)

Submission status: Time Limit Exceeded

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

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        b_c += 1
    b_c = N - b_c
    count += (a_b * b_c)
    a_b = 0
    b_c = 0

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 i in range(N):
    for j in range(N):
        if a[i] >= b[j]:
            continue
        for k in range(N):
            if b[j] < c[k]:
                count += 1
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.sort()
B.sort()
C.sort()


def extract(M):
    Md = []
    Mc = []
    for m in M:
        try:
            Mc[Md.index(m)] += 1
        except ValueError:
            Md.append(m)
            Mc.append(1)
    return Md, Mc


Ad, Ac = extract(A)
Bd, Bc = extract(B)
Cd, Cc = extract(C)

result = 0
# for i, c in enumerate(Cd):
#     for j, b in enumerate(Bd):
#         if b < c:
#             for k, a in enumerate(Ad):
#                 if a < b:
#                     result += Cc[i] * Bc[j] * Ac[k]
#                 else:
#                     break
#         else:
#             break
for i, c in enumerate(Cd):
    for j, b in enumerate(Bd):
        if b < c:
            result += sum([Cc[i] * Bc[j] * Ac[k] for k, a in enumerate(Ad) if a < b])
        else:
            break

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
raw_input()
Ali = np.array( map(int,raw_input().split()))
Bli =np.array(map(int,raw_input().split()))
Cli =np.array(map(int,raw_input().split()))
Ali = np.sort(Ali)
Cli = np.sort(Cli)[::-1]
co=0
for B in Bli:
    ca = 0 
    for A in Ali:
        if A >= B:
            break
        else:
            ca+=1
    cb =0
    for C in Cli:
        if C <= B:
            break
        else:
            cb +=1 
    co += ca*cb
print(co)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
a = int(raw_input())
Ali = (np.array( map(int,raw_input().split())))
Bli =(np.array(map(int,raw_input().split())))
Cli =(np.array(map(int,raw_input().split())))
Ali = np.sort(Ali)
Bli = np.sort(Bli)
Cli = np.sort(Cli)[::-1]
co=0
for B in Bli:
    ca = 0 
    for A in Ali:
        if A >= B:
            break
        else:
            ca+=1
    cb =0
    for C in Cli:
        if C <= B:
            break
        else:
            cb +=1 
    co += ca*cb
print(co)

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

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

for j in B:
    for i in range(N):
        if A[i] >= j:
            break
        if A[N-1] < j:
            i = N
    for k in range(N):
        if j >= C[k]:
            break
        if j < C[N-1]:
            k = N
    m =  m + i * k

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

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

for j in range(N):
    for i in range(N):
        if A[i] >= B[j]:
            break
        if A[N-1] < B[j]:
            i = N
    for k in range(N):
        if B[j] >= C[k]:
            break
        if B[j] < C[N-1]:
            k = N
    m =  m + i * k

print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0

for n in range(N):
    A[n] = int(A[n])
    B[n] = int(B[n])
    C[n] = int(C[n])

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

for j in range(N):
    for i in range(N):
        if A[i] >= B[j]:
            break
        if A[N-1] < B[j]:
            i = N
    for k in range(N):
        if B[j] >= C[k]:
            break
        if B[j] < C[N-1]:
            k = N
    m =  m + i * k

print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cand1 = [0 for i in range(n)]
cand2 = [0 for i in range(n)]
tmp = n 
for j in reversed(range(n)):
    for i in reversed(range(0, tmp)):
        if a[i] < b[j]:
            tmp = i + 1
            cand1[j] += i + 1
            break
tmp = 0
for j in range(n):
    for k in range(tmp, n):
        if b[j] < c[k]:
            tmp = k
            cand2[j] += n - k
            break
ans = sum(np.array(cand1) * np.array(cand2))
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()

result=0

i=0
j=0
k=0

for a in A:
    k=0
#    print(a)
    while a>=B[j]:
        j+=1
        if j==N:
            break
    if j==N:
        break

    for b in B[j:]:
#        print(' '+str(b)+':'+str(j))
        while b>=C[k]:
            k+=1
            if k==N:
                break
        if k==N:
            break
        for c in C[k:]:
#            print('  '+str(c)+':'+str(k))
            result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = range(int(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
counter = 0
a.sort()
b.sort()
c.sort()
d = [0 for i in range(int(len(n)))]
for y in n:
    for z in n:
        if b[y] < c[z]:
            d[int(y)]= len(n) - int(z)
            break
for x in n:
    for y in n:
        if a[x] < b[y]:
            counter += d[y]
print(counter)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

N=int(input())
A=sorted(list( int(i) for i in input().split()))
B=sorted(list( int(i) for i in input().split()))
C=sorted(list( int(i) for i in input().split()))

'''
print(A)
print(B)
print(C)
'''

count=0

for i in range(0, len(A)):
	for j in reversed(range(0, len(B))):
		if(A[i]>=B[j]):
			# print("break:",A[i],B[j])
			break
		for k in reversed(range(0, len(C))):
			# print("count:",count,"A:",A[i],"B:",B[j],"C:",C[k])
			if(B[j]>=C[k]):
				# print("break2:",A[i],B[j],C[k])
				break
			count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
top = list(map(int, input().strip().split()))
middle = list(map(int, input().strip().split()))
bottom = list(map(int, input().strip().split()))

top_less = []
middle_less = []

for i in range(N):
    count1 = 0
    count2 = 0
    indices = []
    for j in range(N):
        if top[i] < middle[j]:
            indices.append(j)
        if middle[i] < bottom[j]:
            count2 += 1
    top_less.append(indices)
    middle_less.append(count2)

final_count = 0

for markers in top_less:
    for marker in markers:
        final_count += middle_less[marker]
print(final_count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""077-c"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(input())

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

    Bs_count = [len(list(filter(lambda c : b < c, Cs))) for b in Bs]
    As_count = [len(list(filter(lambda b : a < b, Bs))) for a in As]

    count = 0
    for c in As_count:
        if -1 * c == 0:
            break
        for c_ in Bs_count[-1 * c:]:
            count += c_

    print(count)


if __name__ == '__main__':
    sys.exit(main())

Submission status: Time Limit Exceeded

Solution code:
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

def get_Num():
    return int(raw_input())

def get_parts_list():
    line = raw_input()
    array = map(int, line.split())
    return array


Num = get_Num()
array_top = get_parts_list()
array_mid = get_parts_list()
array_btm = get_parts_list()

array_top.sort()
array_mid.sort()
array_btm.sort()
array_top.reverse()
array_mid.reverse()
array_btm.reverse()

p_dbg(str(Num))
p_dbg(array_top)
p_dbg(array_mid)
p_dbg(array_btm)

comb = 0

while len(array_btm) > 0:
    item_b = array_btm.pop(0)
#    for item_m in array_mid:
    tmp_mid = array_mid[:]
    while len(tmp_mid) > 0:
        item_m = tmp_mid.pop(0)
#        for item_t in array_top:
        tmp_top = array_top[:]
        while len(tmp_top) > 0:
            item_t = tmp_top.pop(0)
            p_dbg(str(item_b)+':'+str(item_m)+':'+str(item_t))
            if((item_b > item_m) and (item_m > item_t)):
                comb = comb + 1
    p_dbg('next btm')
    
print comb

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import numpy as np
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = [int(i) for i in A]
B = np.array([int(i) for i in B])
C = np.array([int(i) for i in C])

dp = np.array([])
s = 0
for b in B :
    ind = b < C
    c = C[ind]
    s = len(c)
    dp = np.append(dp , s)
 
s = 0
rst = []
for a in A : 
    ind = a<B
    b = dp[ind]
    rst.append(sum(b))
print(int(sum(rst)))

Submission status: Time Limit Exceeded

Solution code:
#!/user/bin/python
# coding: UTF-8

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

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

n = 0
x = 0
for i in range(N):
    j = x
    for j in range(N):
        if A[i] < B[j]:
            for k in range(N):
                if B[j] < C[k]:
                    n = n + (N - k)
                    break
        else:
            x = j
print n

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import numpy as np
 
import numpy as np
import copy as cp
 
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = [int(i) for i in A]
B = np.array(sorted([int(i) for i in B] , reverse = True))
C = np.array([int(i) for i in C])

dp = np.array([])
s = 0
for b in B :
    ind = b < C
    c = C[ind]
    if len(c) > 0 : 
        C = C[-(ind)]
    s = s + len(c)
    dp = np.append(dp , s)
 
s = 0
rst = []
for a in A : 
    ind = a<B
    b = dp[ind]
    rst.append(sum(b))
print(int(sum(rst)))