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


bi = bisect.bisect_right

result = 0
for i in range(n):
    a_bi_in_b = bi(b, a[i])
    for j in range(a_bi_in_b, n):
        b_bi_in_c = bi(c, b[j])
        result += n - b_bi_in_c
        
        
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc077_c():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0

    # 二分探索で Ai < Bj < Ck となる個数を数える
    from bisect import bisect_left
    for i in range(N):
        # 真に大きいが条件なので Ai + 1 が入るポイントを探す
        jst = bisect_left(B, A[i] + 1)
        if jst == N: continue
        for j in range(jst, N):
            kst = bisect_left(C, B[j] + 1)
            ans += N - kst
    print(ans)

abc077_c()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc077_c():
    N = int(readline())
    A = np.fromiter(readline().split(), dtype=np.int32)
    B = np.fromiter(readline().split(), dtype=np.int32)
    C = np.fromiter(readline().split(), dtype=np.int32)
    A.sort()
    B.sort()
    C.sort()
    ans = 0

    # 二分探索で Ai < Bj < Ck となる個数を数える
    for i in range(N):
        # 真に大きいが条件なので Ai + 1 が入るポイントを探す
        jst = np.searchsorted(B, A[i] + 1)
        if jst == N: continue
        for j in range(jst, N):
            kst = np.searchsorted(C, B[j] + 1)
            ans += N - kst
    print(ans)

abc077_c()

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()

  ans = 0

  for i in range(N):
    a = bi.bisect_left(A,B[i])
    c = len(C[bi.bisect_right(C,B[i]):])
    ans += a*c
  print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import math
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()
  n = int(math.log(N,2))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = len(C[right:])
    ans += a*c
  print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import math
def main():
  from builtins import input, int, map
  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()
  n = int(math.log2(N))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = len(C[right:])
    ans += a*c
  print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  from builtins import input, int, map
  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 range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      while right - left > 1:
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      while right - left > 1:
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = len(C[right:])
    ans += a*c
  print(ans)
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()

ans = 0

for i in range(N):
  if A[0] >= B[i]:
    continue
  if A[N-1] < B[i]:
    a = N
  else:
    left = 0
    right = N-1
    while right - left > 1:
      mid = (left + right) // 2
      if  B[i]> A[mid]:
        left = mid
      else:
        right = mid
    a = left + 1
  if C[N-1] <= B[i]:
    continue
  if C[0] > B[i]:
    c = N
  else:      
    left = 0
    right = N-1
    while right - left > 1:
      mid = (left + right) // 2
      if B[i]>= C[mid]:
        left = mid
      else:
        right = mid
    c = len(C[right:])
  ans += a*c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import itertools
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 s in range(bisect.bisect_right(b, a[i]),n):
    #count += n-bisect.bisect_right(c, b[s])
for i in itertools.product(a, b, c):
  if i[0] < i[1] < i[2]:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
count = 0
for i in range(n):
  for s in range(bisect.bisect_right(b, a[i]),n):
    count += n-bisect.bisect_right(c, b[s])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
bs = 0
for ai in range(n):
    bs = bs + bisect.bisect_right(b[bs:], a[ai])
    cs = 0
    for bi in range(bs, n):
        cs = cs + bisect.bisect_right(c[cs:], b[bi])
        ans = ans + (n-cs)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect

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

D = tuple(N - bisect(C, b) for b in B)
print(sum(sum(D[bisect(B, a):]) for a in A))

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


def binary_search(k, x):
    index = bisect.bisect_right(k, x)
    if index == len(k):
        return False
    else:
        # index + 1個している
        return index + 1


ans = 0
for up in a:
    indexed_b = binary_search(b, up)
    b_cnt = n - (indexed_b - 1)
    if b_cnt > len(b):
        break
    for middle in b[indexed_b-1:]:
        indexed_c = binary_search(c, middle)
        c_cnt = n - (indexed_c - 1)
        ans += c_cnt

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()
ct = 0
for i in C:
    b_max = bisect.bisect_left(B, i)
    for j in B[: b_max]:
        ct += bisect.bisect_left(A, j)
print(ct)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n=int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans=0
bfla=0
cfla=0
for i in range(n):
    x=a[i]
    bfla=0
    cfla=0
    for j in range(bfla,n):
        if b[j] > x :
            y=b[j]
            bfla=j
        else:
            continue
        for k in range(cfla,n):
            if c[k]>y:
                z=c[k]
                ans+=n-k
                cfla=k
                break
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()

cnt = 0
for i in a:
	x = bisect.bisect_right(b,i)
	for j in b[x:]:
		y = bisect.bisect_right(c,j)
		cnt += n-y
	b = b[x:]
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()

cnt = 0
for i in a:
	x = bisect.bisect_right(b,i)
	for j in b[x:]:
		y = bisect.bisect_right(c,j)
		cnt += n-y
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()
Kosuu = 0
for b in B:
    UP = A
    UPnum = 0
    while len(UP) > 1:
        num = len(UP)//2
        if UP[num-1] < b:
            UPnum += num
            UP = UP[num:]
        else:
            UP = UP[:num-1]
    if UP != []:
        X = UP[0]
        if X < b:
            UPnum += 1
    UNDER = C
    UNDERnum = 0
    while len(UNDER) > 1:
        Num = len(UNDER)//2
        if UNDER[Num] > b:
            UNDERnum += (len(UNDER)-Num)
            UNDER = UNDER[:Num] 
        else:
            UNDER = UNDER[Num+1:]
    if UNDER != []:
        Y = UNDER[0]
        if Y > b:
            UNDERnum += 1
    Kosuu += UPnum*UNDERnum
print(Kosuu)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
    C2 = C[:]
    ok = bisect.bisect(C2,b)
    if ok!=N:
        bisect.insort(C2,b)
        for _ in range(N-ok):
            BC.append(C2[ok:])
for a in A:
    for bc in BC:
        if bisect.bisect(bc,a)==0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
    C2 = C[:]
    ok = bisect.bisect(C2,b)
    if ok!=N:
        bisect.insort(C2,b)
        for _ in range(N-ok):
            BC.append(C2[ok:])
for a in A:
    for bc in BC:
        if bisect.bisect(bc,a)==0:
            ans += 1
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)
anssum = 0
for i in A:
    for l in B[bisect.bisect_right(B,i):]:
        anssum += lenC - bisect.bisect_right(C,l)
print(anssum)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
from bisect import bisect_left
ans = 0
for i in range(N):
    a = A[i]
    indb = bisect_left(B,a+1)
    if indb == N:
        continue
    for j in range(indb,N):
        b = B[j]
        indc = bisect_left(C,b+1)
        ans += N-indc
print(ans)

Submission status: Time Limit Exceeded

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

def solve():
    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()
    lenA, lenB, lenC = len(As), len(Bs), len(Cs)

    ans = 0
    for ai, a in enumerate(As):
        bidx = bisect.bisect_right(Bs, a)
        if bidx == lenB: continue
        for bi in range(bidx, lenB):
            cidx = bisect.bisect_right(Cs, Bs[bi])
            if cidx == lenC: continue
            ans += lenC-cidx

    print(ans)


if __name__ == "__main__":
    solve()

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

ans = 0
for i in a:
  bi = bisect.bisect_right(b,i)
  for j in b[bi:]:
    ci = bisect.bisect_right(c,j)
    ans += (n-ci)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

def binary_search(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return -1
    
    if num_list[-1] < target:
        return(len(num_list))
    
    while True:

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target > left[-1] and right[0] >= target:
            ans_counter += len(left)
            return ans_counter

        elif target <= left[-1]:
            num_list = left
    
        elif right[0] < target:
            ans_counter += len(left)
            num_list = right
ans = 0
for C in Clist:
    b_point = 0
    b_point =  binary_search(Blist, C)

    if b_point >= 0:
        for B in Blist[:b_point]:
            a_point =  binary_search(Alist, B)
#            print(B,C,a_point) 
            ans += (a_point)

print(ans)
#for C in Clist:

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 i in A:
    for j in B:
        for k in C:
            if (i<j)&(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()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
for i in range(n):
    for j in range(n):
        if b[i]>a[j]:
            t+=1
    u[i]=t
    t=0
for i in range(n):
    for j in range(n):
        if b[i]<c[j]:
            t+=1
    d[i]=t
    t=0
for i in range(n):
    ans+=u[i]*d[i]
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()
ans = 0
for ai in a:
    idx_b = bisect.bisect_right(b, ai)
    if idx_b == n:
        break
    for bi in b[idx_b:]:
        ans += n - bisect.bisect_right(c, bi)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left
n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
    i += 1
    j = li_b[(-1)*i]
    k = bisect_right(li_c, j)
    relation_bc.append(len(li_c)-k)
ans = 0
for i in li_a:
    p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
    p = n - p
    if p >= 1:
        s = 0
        for j in range(p):
            s += relation_bc[j]
        ans += s
    else:
        continue
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()
cc = {}
for i in b:
    cc[i] = n-bisect.bisect_right(c, i)
sum = 0
for i in a:
    for j in [s for s in b if s > i]:
        sum += cc[j]
print(sum)

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

ans = 0

for a in A:
    for i in range(bisect.bisect_right(B, a), len(B)):
        cPtn = len(C) - bisect.bisect_right(C, B[i])
        ans += cPtn

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect 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())))

ans = 0
for i in A:
    min_B = bisect(B, i)
    # print("min_B", min_B)
    for j in range(min_B, len(B)):
        min_C = bisect(C, B[j])
        # print("min_C", min_C)
        ans += len(C) - min_C
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# abc077_c.py
'''
多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。
'''
def is_okC(idx,key,target):
########## wirte criteria here ##########
    if target[idx] > key:
        return True
    return False

def meguru_bisectC(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_okC(mid,key,target):
            right = mid
        else:
            left = mid
#    print("C : ",target[right:])
    return target[right:]


def is_okA(idx,key,target):
########## wirte criteria here ##########
    if target[idx] >= key:
        return True
    return False

def meguru_bisectA(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
#        print("mid : " , mid)
        if is_okA(mid,key,target):
            right = mid
        else:
            left = mid
#    print("A : ",target[:right])
    return target[:right]

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
a = 0
c = 0
ans = 0

for i in B:
    a = len(meguru_bisectA(i,A))
#    print("i : ",i)
    c = len(meguru_bisectC(i,C))
    ans += a*c
#    print()

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = np.searchsorted(aa,b, side='left')
    nc = n - np.searchsorted(cc,b, side='right')
    cnt += na*nc
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def is_ok(idx,key,target):
########## wirte criteria here ##########
    if target[idx] > key:
        return True
    return False

def meguru_bisect(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_ok(mid,key,target):
            right = mid
        else:
            left = mid
    return target[right:]

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 = []
cnt = 0
for i in A:
    ans += meguru_bisect(i,B)
for i in ans:
    cnt += len(meguru_bisect(i,C))

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import bisect
n = int(input())
aa = np.array(list(map(int, input().split())))
bb = list(map(int, input().split()))
cc = np.array(list(map(int, input().split())))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = bisect.bisect_left(aa,b)
    nc = n - bisect.bisect_right(cc,b)
    cnt += na*nc
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
aa = np.array(list(map(int, input().split())))
bb = list(map(int, input().split()))
cc = np.array(list(map(int, input().split())))
cnt = 0
for b in bb:
    na = (aa < b).sum()
    nc = (cc > b).sum()
    cnt += na*nc
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()
pyout=0
for i in range(N):
    num1=bisect.bisect_left(Bs,Cs[i])
    for j in range(num1):
        num2=bisect.bisect_left(As,Bs[j])
        pyout+=num2
print(pyout)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect

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

cnt = 0
for i in B:
    #print( A[:bisect_left(A,i)],C[bisect(C,i):])
    cnt += len(A[:bisect_left(A,i)]) *len(C[bisect(C,i):])
    
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 ai in a:
  for bi in b:
    for ci in c:
      if ai<bi and bi<ci:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()
ans = 0
for i in range(n):
    pos = 0
    for j in range(bisect.bisect_right(b,a[i]),n):
        while (pos < n and c[pos] <= b[j]):
            pos += 1
        ans += n-pos
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())))
import bisect
ans = 0
for i in a:
    comb = 1
    index = bisect.bisect_right(b,i)
    for j in b[index:]:
        ans += n-bisect.bisect_right(c,j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    for i in range(N):
        for j in range(N):
            if arr[0][i] < arr[1][j]:
                for k in range(N):
                    if arr[1][j] < arr[2][k]:
                        n_pair += 1
    return n_pair

if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))
    arr_sorted = []
    for j in range(3):
        arr_sorted.append(arr[j].sort())
    print(snuke_festival(N,arr))

Submission status: Time Limit Exceeded

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    for i in range(N):
        for j in range(N):
            if arr[0][i] < arr[1][j]:
                for k in range(N):
                    if arr[1][j] < arr[2][k]:
                        n_pair += 1
    return n_pair


if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))

    print(snuke_festival(N,arr))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline

n = int(input())
a = np.array(readline().split(),dtype=np.int64)
b = np.array(readline().split(),dtype=np.int64)
c = np.array(readline().split(),dtype=np.int64)

ans = 0
for i in range(n):
    ans += np.count_nonzero(a < b[i]) * np.count_nonzero(c > b[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline

n = int(input())
a = np.array(readline().split(),dtype=np.int64)
b = np.array(readline().split(),dtype=np.int64)
c = np.array(readline().split(),dtype=np.int64)

ans = 0
for i in b:
    ans += np.count_nonzero(a < i) * np.count_nonzero(c > i)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())
b = list(myinput())
c = list(myinput())

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

# print(a)
# print(b)
# print(c)

ls = [0]*n
for j in range(n):
    ind_a = bisect_left(a,b[j])
    ls[j] = ind_a
# print(ls)

count = 0
for k in range(n):
    ind_b = bisect_left(b,c[k])
    count += sum(ls[:ind_b])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())
b = list(myinput())
c = list(myinput())

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

# print(a)
# print(b)
# print(c)

count = 0
for i in range(n):
    ind_b = bisect_right(b,a[i])
    for j in range(ind_b,n):
        ind_c = bisect_right(c,b[j])
        count += n - ind_c
print(count)