Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N \leq 10^5

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

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

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

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

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

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

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

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

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b = sorted(b)
c = sorted(c)
import bisect
count = 0
for i in range(n):
  x = bisect.bisect_left(b, a[i]+1)
  for j in range(x,n):
    y = bisect.bisect_left(c, b[j]+1)
    count += n-y
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):
    for k in range(n):
      if a[i]<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()))
cnt=0
count=0

a.sort()
b.sort()
c.sort()

for i in range(n):
    for j in range(n):
        for k in range(n):
            if c[i]>b[j]>a[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()
bans = []
last = 0
for bi in range(n):
  bnow = b[bi]
  for ci in range(last,n):
    if c[ci] > bnow:
      bans.append([bnow,n-ci])
      last = ci
      break
  else:
    bans.append([bnow,0])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
last = 0
for ai in range(n):
  anow = a[ai]
  for bi in range(last,n):
    if bans[bi][0] > anow:
      ans += bans[bi][2]
      last = bi
      break
#print(bans)
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()

cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if A[i] < B[j] < C[k]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Bn = [0] * N
prea = 0
for b in range(N):
    for a in range(prea, N):
        if A[a] < B[b]:
            prea = a
            break
    else:
        break
    Bn[b] = N-a

ans = 0
preb = 0
for c in range(N):
    for b in range(preb, N):
        if B[b] < C[c]:
            preb = b
            break
    else:
        break
    ans += sum(Bn[b:])

print(ans)

Submission status: Time Limit Exceeded

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

Bn = [0] * N
prea = 0
for b in range(N):
    for a in range(prea, N):
        if A[a] < B[b]:
            prea = a
            break
    else:
        a = N
    Bn[b] = N-a

ans = 0
preb = 0
for c in range(N):
    for b in range(preb, N):
        if B[b] < C[c]:
            preb = b
            break
    else:
        b = N
    ans += sum(Bn[b:])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

lenC = len(C)
cnt = 0

for a in A:
    for b in B:
        if a >= b: continue

        ii = bisect.bisect_right(C, b)
        cnt += lenC - ii

print(cnt)

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

for i in range(n):
  for j in range(n):
    b1 = b[j]
    c1 = c[i]
    if c1 <= b1:
      break
    for k in range(n):
      a1 = a[k]
      if b1 <= a1:
        break
      else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub

total = 0
for c in C:
    b_ub = bin_search(B, c)
    for b in B[:b_ub]:
        a_ub = bin_search(A, b)
        total += len(A[:a_ub])

print(total)

Submission status: Time Limit Exceeded

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

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

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub
total = 0
for c in C:
    b_ub = bin_search(B, c)
    for _b in B[:b_ub]:
        a_ub = bin_search(A, _b)
        total += len(A[:a_ub])


print(total)

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())))
B=[0]*n
j=0
for i in range(n):
    while b[i]>=c[j] and j<n-1:j+=1
    B[i]=n-j
ans=0
j=0
for i in range(n):
    while a[i]>=b[j] and j<n-1:j+=1
    if a[i]<b[j]:ans+=sum(B[j:])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if a==0 or i<k :break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    ans+=a*(N-c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
P=[list(map(int,input().split())) for i in range(3)]
ans=0
for i in P[0]:
    for j in P[1]:
        for k in P[2]:
            if i<j<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()))
A.sort()
B.sort()
C.sort()

b_ptn = [0] * (N)
for idx, b in enumerate(B):
  cnt = 0
  for a in A:
    if a < b:
      cnt += 1
    else:
      break
  b_ptn[idx] = cnt
ans = 0
for c in C:
  for idx, b in enumerate(B):
    if b >= c:
      break
    if idx == N-1:
      ans += b_ptn[idx]
      break
    ans += b_ptn[idx]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in B:
    x, y = 0, 0
    for j in A:
        if j < i:
            x += 1
        else:
            break
    for j in reversed(C):
        if i < j:
            y += 1
        else:
            break
    ans += x * y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in C:
    for j in B:
        if i <= j:
            break
        for k in A:
            if j <= k:
                break
            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 A:
    for j in B:
        for k in C:
            if i < j < k:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
k = []
for _ in range(3):
    a = [int(i) for i in input().split()]
    a.sort()
    k.append(a)
count = 0
for i in k[0]:
    b = bisect.bisect_right(k[1],i)
    for j in k[1][b:n]:
        c = bisect.bisect_right(k[2],j)
        count += n-c 
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
k = []
for _ in range(3):
    a = [int(i) for i in input().split()]
    a.sort()
    k.append(a)
#print(k)
count = 0
for i in k[0]:
    b = bisect.bisect_right(k[1],i)
    for j in k[1][b:n]:
        #print(j)
        c = bisect.bisect_right(k[2],j)
        #print(c)
        count += n-c 
print(count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
n = int(input())
l_a = list(map(int,input().split()))
l_b = sorted(list(map(int,input().split())))
l_c = sorted(list(map(int,input().split())))
lenc=len(l_c)
ans=0
for i in l_a:
    for j in l_b[bisect(l_b,i):]:
        ans += lenc-bisect(l_c,j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

ans = 0
AA = list(tuple(A))
CC = list(tuple(C))

for i in range(N):
  AA = list(tuple(A))
  CC = list(tuple(C))
  b = B[i]
  
  AA.append(b)
  AA.sort()
  idx_b_AA = AA.index(b)
  
  CC.append(b)
  CC.sort(reverse=True)
  idx_b_CC = CC.index(b)
  
  ans += idx_b_AA * idx_b_CC

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(sorted([int(a) for a in input().split()], reverse=True))
B = tuple(sorted([int(b) for b in input().split()], reverse=True))
C = tuple(sorted([int(c) for c in input().split()], reverse=True))
ans = 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]:
        break
      else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()], reverse=True)
B = sorted([int(b) for b in input().split()], reverse=True)
C = sorted([int(c) for c in input().split()], reverse=True)
ans = 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]:
        break
      else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()], reverse=True)
B = sorted([int(b) for b in input().split()], reverse=True)
C = sorted([int(c) for c in input().split()], reverse=True)
ans = 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]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
ans = 0

for i in range(N):
  for j in range(N):
    if A[i] >= B[j]:
      continue
    for k in range(N):
      if A[i] < B[j] < C[k]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
ans = 0

for i in range(N):
  for j in range(N):
    for k in range(N):
      if A[i] < B[j] < C[k]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

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

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

cnt = 0
for j in b:
    a_cnt = np.sum(a < j)
    c_cnt = np.sum(j < c)
    cnt += a_cnt * c_cnt

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC77 C

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in a:
    s = 0
    x = bisect.bisect_right(b,i)
    for j in b[x:]:
        y = bisect.bisect_right(c,j)
        ans += n-y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in [0]*3]
from itertools import accumulate
a.sort()
b.sort()
c.sort()
a+=[10**20]
b+=[10**20]

p,q=0,0
cnt=0
ans=[0]*n
for i in range(n):
	for j in range(p,n+1):
		if b[i]>a[j]:
			pass
		else:
			break
	ans[i]=j
	p=j
ans=[0]+list(accumulate(ans))

for i in range(n):
	for j in range(q,n+1):
		if c[i]>b[j]:
			pass
		else:
			break
	cnt+=ans[j]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
top = sorted(list(map(int, input().split())))
mid = sorted(list(map(int, input().split())))
bot = sorted(list(map(int, input().split())))

midc = [0]*n
for i in range(n):
    cnt = 0
    for j in range(n):
        if mid[i]>top[j]: cnt += 1
    midc[i] = cnt

botc = [0]*n
for i in range(n):
    cnt = 0
    for j in range(n):
        if bot[i]>mid[j]: cnt += 1
    botc[i] = cnt

ans = 0
for i in range(n):
    ans += sum(midc[:botc[i]])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.sort(np.array(list(map(int, input().split()))))
b = np.sort(np.array(list(map(int, input().split()))))
c = np.sort(np.array(list(map(int, input().split()))))
x = 0
for i in b:
  x += len(a[a<i])*len(c[c>i])
print(x)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

from bisect import bisect_left


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

    res = 0
    for a in A:
        t = bisect_left(B, a + 1)
        for b in B[t:]:
            s = bisect_left(C, b + 1)
            res += N - s

    print(res)


if __name__ == '__main__':
    main()

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

memo_b_c = dict()

answer = 0
for a in list_a:
    for b in filter(lambda x: x > a, list_b):

        if b not in memo_b_c:
            memo_b_c[b] = len(list(filter(lambda y: y > b, list_c)))

        answer += memo_b_c[b]

print(answer)

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

s_list_a = sorted(list_a)
s_list_b = sorted(list_b)
s_list_c = sorted(list_c)

memo_a_b = dict()
memo_b_c = dict()


answer = 0
for a in s_list_a:
    for b in filter(lambda x: x > a, s_list_b):

        if b not in memo_b_c:
            memo_b_c[b] = list()
            for c in filter(lambda y: y > b, list_c):
                memo_b_c[b].append(c)
                answer += 1
        else:
            answer += len(memo_b_c[b])

print(answer)

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

memo_a_b = dict()
memo_b_c = dict()


answer = 0
for a in sorted(list_a):
    for b in sorted(filter(lambda x: x > a, list_b)):

        if b not in memo_b_c:
            memo_b_c[b] = list()
            for c in sorted(filter(lambda y: y > b, list_c)):
                memo_b_c[b].append(c)
                answer += 1
        else:
            answer += len(memo_b_c[b])

print(answer)

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

answer = 0
for a in sorted(list_a):
    for b in sorted(filter(lambda x: x > a, list_b)):
        for c in sorted(filter(lambda y: y > b, list_c)):
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
ans=0
for i in l_a:
    for j in [b for b in l_b if b>i]:
        ans += len([c for c in l_c if c>j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def binary_search_A(N,A,b):
    upper = N - 1
    lower = 0
    
    while upper - lower > 1:
        middle = upper + lower // 2
        if A[middle] > b:
            upper = middle
        else:
            lower = middle
            
    if b >= A[upper]:
      return upper+1
    elif b >= A[lower]:
      return lower+1
    else:
      return lower

def binary_search_C(N,C,b):
    upper = N - 1
    lower = 0
    
    
    while upper - lower > 1:
        middle = upper + lower // 2
        if C[middle] > b:
            upper = middle
        else:
            lower = middle
            
            
    if b < C[lower]:
      return N-lower
    elif b < C[upper]:
      return N - (lower+1)
    else:
      return N - (upper+1)
    


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

ans = 0

for i in range(N):
    j = binary_search_A(N, A, B[i])
    #print(j)
    k = binary_search_C(N, C, B[i])
    #print(k)
    ans += j * k
    
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=sorted(a)
b=sorted(b)
c=sorted(c)
answer=0
for val1 in range(N):
  a2=[i for i in a if i<b[val1]]
  c2=[i for i in c if i>b[val1]]
  answer+=len(a2)*len(c2)

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=sorted(a)
b=sorted(b)
c=sorted(c)
l=[]
for val1 in range(N):
  b2=[i for i in b if i>a[val1]]
  for val2 in range(len(b2)):
    c2=[i for i in c if i>b2[val2]]
    l.append(len(c2))

print(sum(l))

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=sorted(a)
b=sorted(b)
c=sorted(c)
l=[]
for val1 in range(N):
  b2=[i for i in b if i>a[val1]]
  for val2 in range(len(b2)):
    c2=[i for i in c if i>b2[val2]]
    l.append(len(c2))

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input());
a = input().split(" ");
b = input().split(" ");
c = input().split(" ");
num_b = [0]*n;
for i in range(n) :
	for j in range(n) :
		if int(b[i]) < int(c[j]) :
			num_b[i] += 1;
ans = 0;
for i in range(n) :
	for j in range(n) :
		if int(a[i]) < int(b[j]) :
			ans += num_b[j]
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 c in C:

    for b in B:

        if b >= c:
            break

        for a in A:

            if a >= b:
                break

            else:

                ans += 1

print (ans)

Submission status: Time Limit Exceeded

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


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()

    AtoB = [0] * N
    BtoC = [0] * N

    j = 0
    for i in range(N):
        while j < N and A[i] >= B[j]:
            j += 1
        AtoB[i] = j 

    j = 0
    for i in range(N):
        while j < N and B[i] >= C[j]:
            j += 1
        BtoC[i] = j 

    res = 0
    for i in range(N):
        for j in range(AtoB[i],N):
            for k in range(BtoC[j],N):
                res += 1

    print(res)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
n=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])
a=[]
b=[]
for i in range(n):
    for j in range(n):
        if A[i]<B[j]:
            a.append(n-j)
            break
    else:
        a.append(0)
for i in range(n):
    for j in range(n):
        if B[i]<C[j]:
            b.append(n-j)
            break
    else:
        b.append(0)
b.sort()
b=list(accumulate(b))
ans=0
for i in range(n):
    if a[i]!=0:
        ans+=b[a[i]-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])
a=[]
b=[]
for i in range(n):
    for j in range(n):
        if A[i]<B[j]:
            a.append(n-j)
            break
    else:
        a.append(0)
for i in range(n):
    for j in range(n):
        if B[i]<C[j]:
            b.append(n-j)
            break
    else:
        b.append(0)
#print(a)
#print(b)
ans=0
for i in range(n):
    if a[i]!=0:
        for j in range(n-a[i],n):
            ans+=b[j]
#            print(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])
a=[]
b=[]
for i in range(n):
    count=0
    for j in range(n):
        if A[i]<B[j]:
            count+=1
    a.append(count)
for i in range(n):
    count=0
    for j in range(n):
        if B[i]<C[j]:
            count+=1
    b.append(count)
ans=0
for i in range(n):
    if a[i]!=0:
        for j in range(n-a[i],n):
            ans+=b[j]
#            print(ans)
print(ans)
#print(a)
#print(b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
B.sort()
C.sort()
def isOK(lis,index,key):
    if lis[index] > key:
        return True
    else:
        return False

def binary_search(lis,key):
    ng = -1
    ok = len(lis)

    while(abs(ok-ng)>1):
        mid = int((ok+ng)/2)
        if isOK(lis,mid,key):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
lis = []
for i in range(N):
    b_index = binary_search(B,A[i])
    lis.extend(B[b_index:len(B)])
for b in lis:
    c_index = binary_search(C,b)
    ans += len(C) - c_index
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def bs(a, v):
    ok = len(a)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] > v:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N = readi()
    A = sorted(readi(N))
    B = sorted(readi(N))
    C = sorted(readi(N))
    ab = [bs(B, a) for a in A]
    bc = [bs(C, b) for b in B]
    bcount = [N - bc[i] for i in range(N)]
    bcum = arr(N + 1)
    for i in range(N - 1, -1, -1):
        bcum[i] = bcum[i + 1] + bcount[i]
    ans = 0
    for i in range(N):
        ans += bcum[ab[i]]
    print(ans)


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())),dtype=np.int32)
b = np.array(list(map(int,input().split())),dtype=np.int32)
c = np.array(list(map(int,input().split())),dtype=np.int32)

a = np.array([sum(np.where(a-i<0,1,0)) for i in b])

b = b-c.reshape(len(c),1)
b = np.where(b<0)[1]

print(np.sum(a[b]))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import numpy as np
n = int(input())
abc = [sorted(list(map(int, input().split()))) for i in range(3)]

unko = np.zeros(n)
for c in abc[2]:
  unko[:bisect.bisect_left(abc[1], c)] += 1
s = 0
for i,b in enumerate(abc[1]):
  s += bisect.bisect_left(abc[0], b)*unko[i]
  
print(int(s))

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

cnt = 0
for j in range(N):
  target = B[j]
  insert_indexA = bisect.bisect_left(A, target)
  insert_indexC = bisect.bisect_right(C, target)
  cnt = cnt + len(A[:insert_indexA]) * len(C[insert_indexC:])

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

cnt = 0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if A[i] < B[j] < C[k]:
        cnt = cnt + 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(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

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

ans = 0
for n in abnums[1:]:
    ans += bcnums[n]
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(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

ans = 0
for n in abnums[1:]:
    ans += sum(bcnums[1:n+1])
print(ans)