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())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
S = 0
k = 0
l = 0
for i in range(N):
  for p in range(N):
    if K[i] > J[p]:
      k += 1
  for q in range(N):
    if K[i] < L[q]:
      l += 1
  S += k*l
  k = 0
  l = 0
print(S)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
J = list(map(int,input().split()))
K = list(map(int,input().split()))
L = list(map(int,input().split()))
J.sort()
K.sort()
L.sort()
S = 0
k = 0
l = 0
for i in range(N):
  for p in range(N):
    if K[i] > J[p]:
      k += 1
    else:
      break
  for q in range(N):
    if K[i] < L[N-q-1]:
      l += 1
    else:
      break
  S += k*l
  k = 0
  l = 0
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()))
A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    ans += len(list(filter(lambda x: x < b, A))) * \
        len(list(filter(lambda x: x > b, C)))

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 b in B:
    ans += len(list(filter(lambda x: x < b, A))) * \
        len(list(filter(lambda x: x > b, C)))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = 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()

BC_type_num = []
for b in B:
    upper_bound = bisect.bisect_right(C, b)
    BC_type_num.append(N - upper_bound)

ABC_type_num = []
for a in A:
    upper_bound = bisect.bisect_right(B, a)
    ABC_type_num.append(sum(BC_type_num[upper_bound:]))

print sum(ABC_type_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
a = sorted(a)
b = sorted(b)
c = sorted(c,reverse=True)
ic = []
kc = []
count = 0
for j in range(n):
    tmp = 0
    for i in range(n):
        if b[j]<=a[i]:
            break
        else:
            tmp += 1
    ic.append(tmp)
for j in range(n):
    tmp = 0
    for k in range(n):
        if b[j]>=c[k]:
            break
        else:
            tmp += 1
    kc.append(tmp)
for j in range(n):
    count += ic[j]*kc[j]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
a = sorted(a)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)
count = 0
for i in range(n):
    for j in range(n):
        if a[i]>=b[j]:
            break
        for k in range(n):
            if b[j]<c[k]:
                count += 1
            else:
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
a = sorted(a)
b = sorted(b,reverse=True)
c = sorted(c,reverse=True)
count = 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]):
                count += 1
            else:
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
a = sorted(a)
b = sorted(b)
c = sorted(c)
count = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if not (a[i]<b[j] and b[j]<c[k]):
                continue
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
z = int(input())
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
cr = list(map(int,input().split(" ")))
count = 0
for a in ar:
    for b in br:
        for c in cr:
            if a < b and b < c:
                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(' ')))

sorted_a = sorted(a)
sorted_b = sorted(b)
sorted_c_r = sorted(c)[::-1]
ans = 0
for each_b in sorted_b:
    count_a = 0
    for each_a in sorted_a:
        if each_b > each_a:
            count_a += 1
        else:
            break
    count_c = 0
    for each_c in sorted_c_r:
        if each_c > each_b:
            count_c += 1
        else:
            break
    ans += count_a * count_c
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()
ans=0
for j in range(N):
    for i in range(N):
        if A[i]>=B[j]:
            a=i
            break
    else:
        a=N
    for k in range(N):
        if C[k]>B[j]:
            c=N-k
            break
    else:
        c=0
    ans+=a*c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input().strip())
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)
ans=0
for i in range(len(a)):
    for j in range(len(b)):
        if a[i]>b[j]:
            break
        for k in range(len(c)):
#            print(a[i],b[j],c[k])
            if a[i]>=b[j] or b[j]>=c[k]:
                break
            else:
#                if ans==0:
                ans+=1
#                print(a[i],b[j],c[k])
#                    at=a[i]
#                    bt=b[j]
#                    ct=c[k]
#                    print(at,bt,ct)
#                elif at!=a[i] or bt!=b[j] or ct!=c[k]:
#                    ans+=1
#                    at=a[i]
#                    bt=b[j]
#                    ct=c[k]
#                    print(at,bt,ct)
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()]


BB = [0] * N
for i in range(N):
    for c in C:
        if B[i] < c:
            BB[i] += 1

AA = [0] * N
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            AA[i] += BB[j]

print(sum(AA))

Submission status: Time Limit Exceeded

Solution code:
def binarySearch(list_a, key):
    left = 0
    right = len(list_a)
    while left < right:
        mid = (left + right) // 2
        if key < list_a[mid]:
            right = mid
        else:
            left = mid+1
    else:
        return left


n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
list_a.sort()
list_b.sort()
list_c.sort()
count = 0
for c in list_c:
    for b in list_b[:binarySearch(list_b, c-0.5)]:
        count += binarySearch(list_a, b-0.5)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
count = 0
for c in list_c:
    for b in [b for b in list_b if b < c]:
        count += len([a for a in list_a if a < b])
print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(a,b,c):
	table = []
	for b_ in b:
		counter = 0
		for a_ in a:
			if  a_ < b_:
				counter += 1
		table.append(counter)
	
	#print(table)
	ans = 0
	for i in range(len(b)):
		for c_ in c:
			if  b[i] < c_:
				ans += table[i]
	return ans
	
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()]

print(solve(a,b,c))

Submission status: Time Limit Exceeded

Solution code:
def solve(a,b,c):
        table = []
        for b_ in b:
                counter = 0
                for a_ in a:
                        if  a_ < b_:
                                counter += 1
                table.append(counter)

        #print(table)
        ans = 0
        for i in range(len(b)):
                for c_ in c:
                        if  b[i] < c_:
                                ans += table[i]
        return ans

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

print(solve(a,b,c))

Submission status: Time Limit Exceeded

Solution code:
def solve(a,b,c):
	table = []
	for b_ in b:
		counter = 0
		for a_ in a:
			if  a_ < b_:
				counter += 1
		table.append(counter)
	
	#print(table)
	ans = 0
	for i in range(len(b)):
		for c_ in c:
			if  b[i] < c_:
				ans += table[i]
	return ans
	
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()]

print(solve(a,b,c))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
As = list(map(int, input().split()))
Bs = sorted(list(map(int, input().split())))
Cs = sorted(list(map(int, input().split())))

cnt = [0]*n
for idx, b in enumerate(Bs):
    cnt[idx] = len(Cs) - bisect.bisect_right(Cs, b)

print(sum([sum(cnt[bisect.bisect_right(Bs, a):]) for a in As]))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
As = list(map(int, input().split()))
Bs = sorted(list(map(int, input().split())))
Cs = sorted(list(map(int, input().split())))

cnt = 0
for a in As:
    cntB = bisect.bisect_right(Bs, a)
    for b in Bs[cntB:]:
        cnt += len(Cs) - bisect.bisect_right(Cs, b)
print(cnt)

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

cnt = 0
for a in As:
    cntB = bisect.bisect_right(Bs, a)
    for b in Bs[cntB:]:
        cnt += len(Cs) - bisect.bisect_right(Cs, b)
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 a in A:
	for b in B:
		for c in C:
			if a < b < c:
				ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
#print(A)
#print(C)
for b in B:
    lenA = bisect.bisect_left(A,b) #競合時は無事無視される
    lenC = N - bisect.bisect_left(C,b) if b not in C else N - C.index(b) - 1
    ans += lenA*lenC
    #print(lenA,lenC)
    
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 b in B:
    a = len(list(filter(lambda x:x<b,A)))
    c = len(list(filter(lambda x:x>b,C)))
    ans += 1*a*c
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
raw_input = input()
length = len(raw_input)
input_number = int(raw_input)
count = 0

top_lane = input().split()
mid_lane = input().split()
bot_lane = input().split()

for i in range(input_number):
    top_lane[i] = int(top_lane[i])
    mid_lane[i] = int(mid_lane[i])
    bot_lane[i] = int(bot_lane[i])

top_lane.sort()
mid_lane.sort()
bot_lane.sort()

for i in range(input_number):
    top = top_lane[i]
    for j in range(input_number):
        mid = mid_lane[len(mid_lane) - j - 1]
        if top < mid:
            for k in range(input_number):
                bot = bot_lane[len(bot_lane) - k - 1]
                if mid < bot:
                    count += 1
                else:
                    break
        else:
            break

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 binary_search(x,i):
	low = 0
	high = len(x)-1
	t = (low + high) // 2 	
	while (low<=high):
		if (i==x[t]):
			break
		elif (i > x[t]):
			low = t + 1
		elif (i < x[t]):
			high = t - 1
		t = (low + high) // 2
	return t

ans=0
for i in range(n):
  b_l=binary_search(b,a[i])
  for j in range(b_l+1,n):
    c_l=binary_search(c,b[j])
    ans+=n-c_l-1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
raw_input = input()
length = len(raw_input)
input_number = int(raw_input)
count = 0

top_lane = input().split()
mid_lane = input().split()
bot_lane = input().split()

for i in range(input_number):
    top_lane[i] = int(top_lane[i])
    mid_lane[i] = int(mid_lane[i])
    bot_lane[i] = int(bot_lane[i])

for i in range(input_number):
    top = top_lane[i]
    for j in range(input_number):
        mid = mid_lane[j]
        for k in range(input_number):
            bot = bot_lane[k]
            if top < mid < bot:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
As = list(map(int, input().split(' ')))
Bs = list(map(int, input().split(' ')))
Cs = list(map(int, input().split(' ')))

Bs.sort(reverse=True)
Cs.sort(reverse=True)

cnt = 0

for a in As:
    for b in Bs:
        if b <= a:
            break
        
        for c in Cs:
            if c <= b:
                break
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
As = list(map(int, input().split(' ')))
Bs = list(map(int, input().split(' ')))
Cs = list(map(int, input().split(' ')))

As.sort()
Bs.sort(reverse=True)
Cs.sort(reverse=True)

cnt = 0

for a in As:
    for b in Bs:
        if b <= a:
            break
        
        for c in Cs:
            if c <= b:
                break
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

As.sort()
Bs.sort()
Cs.sort()

cnt = 0

for a in As:
    b_idx = bisect.bisect_left(Bs, a)

    while b_idx < N and Bs[b_idx] == a:
        b_idx += 1

    if b_idx >= N:
        continue

    for bi in range(b_idx, N):
        c_idx = bisect.bisect_left(Cs, Bs[bi])

        while c_idx < N and Cs[c_idx] == Bs[bi]:
            c_idx += 1

        cnt += max(0, N - c_idx)

print(cnt)

Submission status: Time Limit Exceeded

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

N = int(input())

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

As.sort()
Bs.sort()
Cs.sort()

ans = 0
for a in As:
    for b in Bs:
        if a >= b:
            continue
        for c in Cs:
            if b >= c:
                continue
            #print(a,b,c)
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
s = sorted(list(map(int,input().split())))
m = sorted(list(map(int,input().split())))
l = sorted(list(map(int,input().split())))
count = 0
for sitem in s:
  for mitem in m[bisect.bisect_right(m,sitem):]:
    count += len(l)-bisect.bisect_right(l,mitem)

print (count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list(map(int,input().split()))
m = list(map(int,input().split()))
l = list(map(int,input().split()))
count = 0
for sitem in s:
  for mitem in m:
    for litem in l:
      if sitem < mitem and mitem < litem:
        count += 1
print (count)

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

anum = [0]*N
cnum = [0]*N
for i in range(N):
	j = 0
	k = 0
	while Bs[i] > As[j]:
		anum[i] += 1
		j += 1
		if j >= N:
			break
	while Bs[i] < Cs[N-k-1]:
		cnum[i] += 1
		k += 1
		if k >= N:
			break

ans = 0
for a, c in zip(anum, cnum):
	ans += a * c
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();b.reverse();c.sort();c.reverse()

s = 0

for i in range(0, n):
    for j in range(0, n):
        for k in range(0, n):
            if (a[i] < b[j] and b[j] < c[k]):
                s+=1
            else:
                break
        if (a[i] > b[j]):
            break

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(' ')))
a.sort();b.sort();c.sort();c.reverse()

s = 0

for i in range(0, n):
    for j in range(0, n):
        for k in range(0, n):
            if (a[i] < b[j] and b[j] < c[k]):
                s+=1
            else:
                break

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 i in range(0, n):
    for j in range(0, n):
        for k in range(0, n):
            if (a[i] < b[j] and b[j] < c[k]):
                s+=1

print(s)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect_left
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = [N for _ in range(N)]
BC = [N for _ in range(N)]
result = 0

j = 0
for i, a in enumerate(A):
    while a >= B[j]:
        AB[j] = i
        j += 1
        if j == N:
            break
    if j == N:
        break

sAB = []
for i in range(N):
    sAB.append(sum(AB[:i+1]))

j = 0
for i, b in enumerate(B):
    while b >= C[j]:
        BC[j] = i
        j += 1
        if j == N:
            break
    if j == N:
        break

for bc in BC:
    if bc:
        result += sAB[bc-1]
print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect_left
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = []
result = 0

for i in range(N):
    AB.append(bisect_left(A, B[i]))

sAB = []
for i in range(N):
    sAB.append(sum(AB[:i+1]))

for i in range(N):
    j = bisect_left(B, C[i])
    if j:
        result += sAB[j-1]
print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = input()
Alis = sorted(map(int, raw_input().split()))
Blis = sorted(map(int, raw_input().split()))
Clis = sorted(map(int, raw_input().split()))

s = 0
for i in Alis:
	x = bisect.bisect_left(Blis,i+1)	# we can use x to n-1 in B
	if x == n: break

	for j in range(x,n):
		b = Blis[j]
		y = bisect.bisect_left(Clis,b+1)	# we can use y to n-1 in C
		if y == n: break

		s += n - y

print s

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = input()
Alis = sorted(map(int, raw_input().split()))
Blis = sorted(map(int, raw_input().split()))
Clis = sorted(map(int, raw_input().split()))

s = 0
for i in Alis:
	x = bisect.bisect_left(Blis,i+1)	# we can use x to n-1 in B

	for j in range(x,n):
		b = Blis[j]
		y = bisect.bisect_left(Clis,b+1)	# we can use y to n-1 in C

		s += n - y

print s

Submission status: Time Limit Exceeded

Solution code:
#C_Snuke Festival
import bisect

def SnukeFestival(N, A, B, C):
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)
    count = 0
    for a in A:
        start = bisect.bisect_right(B, a)
        for j in range(start, N):
            b = B[j]
            count += (N-bisect.bisect_right(C, b))
    print(count)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    SnukeFestival(N, A, B, C)

Submission status: Time Limit Exceeded

Solution code:
#C_Snuke Festival
import itertools

def SnukeFestival(N, A, B, C):
    combination = [(a,b,c) for (a,b,c) in itertools.product(A,B,C) if a < b and b < c]
    print(len(combination))

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    SnukeFestival(N, A, B, C)

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

ans = 0

bl = [0] * len(b)

p = 0
for i,x in enumerate(b):
    for j in range(p,n):
        if x >= c[j]:
            pass
        else:
            bl[i] = n - j
            p = j
            break

p = 0
for x in a:
    for i in range(p,n):
        if x >= b[i]:
            pass
        else:
            ans += sum(bl[i:])
            p = i
            break

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

ans = 0

for x in reversed(a):
    for y in reversed(b):
        if x < y:
            for z in reversed(c):
                if y < z:
                    ans += 1
                else:
                    break
        else:
            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(reverse=True)
cnt = 0
cntA = []
pntA = 0
cntC = []
pntC = 0
for i in B:
    for j in range(pntA, N):
        if A[j] >= i:
            pntA = j
            cntA.append(j)
            break
    else:
        cntA.append(N)
B.sort(reverse=True)
for i in B:
    for j in range(pntC, N):
        if C[j] <= i:
            pntC = j
            cntC.append(j)
            break
    else:
        cntC.append(N)
for i in range(N):
    cnt += cntA[i] * cntC[- i - 1]
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.sort()
B.sort()
C.sort(reverse=True)
cnt = 0
cntA = []
pntA = 0
cntC = []
pntC = 0
for i in range(N):
    isA = False
    isC = False
    for j in range(min(pntA, pntC), N):
        if isA and isC:
            break
        if A[j] >= B[i] and not(isA):
            pntA = j
            cntA.append(j)
            isA = True
        if C[j] <= B[- i - 1] and not(isC):
            pntC = j
            cntC.append(j)
            isC = True
    if not(isA):
        cntA.append(N)
    if not(isC):
        cntC.append(N)
for i in range(N):
    cnt += cntA[i] * cntC[- i - 1]
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.sort()
B.sort()
C.sort(reverse=True)
cnt = 0
cntA = []
pntA = 0
cntC = []
pntC = 0
for i in range(N):
    for j in range(pntA, N):
        if A[j] >= B[i]:
            pntA = j
            cntA.append(j)
            break
    else:
        cntA.append(N)
B.sort(reverse=True)
for i in range(N):
    for j in range(pntC, N):
        if C[j] <= B[i]:
            pntC = j
            cntC.append(j)
            break
    else:
        cntC.append(N)
for i in range(N):
    cnt += cntA[i] * cntC[- i - 1]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a_list = input().split()
a_list = [int(a) for a in a_list]

b_list = input().split()
b_list = [int(b) for b in b_list]

c_list = input().split()
c_list = [int(c) for c in c_list]

a_ar = np.sort(np.array(a_list))
b_ar = np.sort(np.array(b_list))
c_ar = np.sort(np.array(c_list))

goukei = 0
for b in b_ar:
    goukei += len(a_ar[a_ar<b]) * len(c_ar[c_ar>b])
    
print(goukei)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(raw_input())
A = Counter(map(int, raw_input().split()))
B = Counter(map(int, raw_input().split()))
C = Counter(map(int, raw_input().split()))

ans = 0
amin = 10000000000
bmin = 10000000000
memoa = {}
memob = {}
for a in A:
  tmpa = 0
  if a >= amin:
    pass # 0
  elif a in memoa:
    tmpa = memoa[a]
  else:
    for b in B:
      tmpb = 0
      if a < b:
        if b >= bmin:
          pass # 0
        elif b in memob:
          tmpb = memob[b]
        else:
          for c in C:
            if b < c:
              tmpb += C[c]
          tmpb *= B[b]
          memob[b] = tmpb
          if tmpb == 0:
            bmin = b
      tmpa += tmpb
    tmpa *= A[a]
    memoa[a] = tmpa
    if tmpa == 0:
      amin = a
  ans += tmpa

print ans

Submission status: Time Limit Exceeded

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

ans = 0
amin = 10000000000
bmin = 10000000000
memoa = {}
memob = {}
for a in A:
  tmpa = 0
  if a >= amin:
    pass # 0
  elif a in memoa:
    tmpa = memoa[a]
  else:
    for b in B:
      tmpb = 0
      if a < b:
        if b >= bmin:
          pass # 0
        elif b in memob:
          tmpb = memob[b]
        else:
          for c in C:
            if b < c:
              tmpb += 1
          memob[b] = tmpb
          if tmpb == 0:
            bmin = b
      tmpa += tmpb
    memoa[a] = tmpa
    if tmpa == 0:
      amin = a
  ans += tmpa

print ans

Submission status: Time Limit Exceeded

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

ans = 0
memo = {}
for i, a in enumerate(A):
  for j, b in enumerate(B):
    if a < b:
      if b in memo:
        ans += memo[b]
      else:
        tmp = 0
        for k, c in enumerate(C):
          if b < c:
            tmp += 1
        ans += tmp
        memo[b] = tmp

print ans

Submission status: Time Limit Exceeded

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

ans = 0
memo = {}
for i, a in enumerate(A):
  for j, b in enumerate(B):
    if a < b:
      if b in memo:
        ans += memo[b]
      else:
        for k, c in enumerate(C):
          if b < c:
            ans += N - k
            memo[b] = N - k
            break
        else:
          memo[b] = 0

print ans

Submission status: Time Limit Exceeded

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

ans = 0
for i, a in enumerate(A):
  for j, b in enumerate(B):
    if a < b:
      for k, c in enumerate(C):
        if b < c:
          ans += N - k
          break

print ans

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = np.array( list(map(float, input().split(" "))) )
b = np.array( list(map(float, input().split(" "))) )
c = np.array( list(map(float, input().split(" "))) )

mem_b = np.zeros(N, dtype=np.int16)

dict_c = {}
def count_c(v):
    key = v
    if v in dict_c:
        return dict_c[v]
    else:
        val = len(np.where( (v < c) == True )[0])
        dict_c.update({key:val})
        return val

num = 0
for i in range(N):
    mem_b[i] += count_c(b[i])

for i in range(N):
    num += ( (a[i] < b) * mem_b ).sum()
print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = np.array( list(map(float, input().split(" "))) )
b = np.array( list(map(float, input().split(" "))) )
c = np.array( list(map(float, input().split(" "))) )

# sort(a)
# sort(b)
# sort(c)

mem_b = np.zeros(N, dtype=np.int32)

dict_c = {}
def count_c(v):
    key = v
    if v in dict_c:
        return dict_c[v]
    else:
        val = len(np.where( (v < c) == True )[0])
        dict_c.update({key:val})
        return val

num = 0
for i in range(N):
    mem_b[i] += count_c(b[i])

for i in range(N):
    num += ( (a[i] < b) * mem_b ).sum()
print(num)

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(reverse=True)
cnt = 0
cntA = []
pntA = 0
cntC = []
pntC = 0
for i in range(N):
    for j in range(pntA, N):
        if A[j] >= B[i]:
            pntA = j
            cntA.append(j)
            break
    else:
        cntA.append(N)
    for j in range(pntC, N):
        if C[j] <= B[- i - 1]:
            pntC = j
            cntC.append(j)
            break
    else:
        cntC.append(N)
for i in range(N):
    cnt += cntA[i] * cntC[- i - 1]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(); b.sort(); c.sort()
ins_c = [0]*n
ins_b = [0]*n
for i in range(n) :
    ins_c[i] = bisect.bisect_right(c, b[i])
    ins_b[i] = bisect.bisect_right(b, a[i])
ans = 0
for i in range(n) :
    for j in range(ins_b[i], n) :
        ans += n - ins_c[j]

print(ans)