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: Runtime Error

Solution code:
def binery_search(left,right,keynum,list):
    mid = 0
    while True:
            #print(left,right,mid,cnt)
            mid = int( (left+right)/2 )
            if keynum == list[mid]:
                while True:
                    if list[mid] == list[mid+1]:
                        mid +=1
                        if mid == len(list)-1:
                            break
                    else:
                        mid += 1
                        break
                return mid
            elif keynum < list[mid]:
                right = mid
            elif keynum > list[mid]:
                left = mid + 1

            if left == right:
                return left

def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort()
    B.sort()
    C.sort()
    B_num = []
    for i in range(N):
        B_num.append(N-binery_search(0,N,B[i],C))
        print(B_num,binery_search(0,N,B[i],C))
    #累積和を計算
    B_ruiseki = [0]*N
    B_ruiseki[N-1] = B_num[i]
    for i in range(N-2,-1,-1):
        B_ruiseki[i] = B_ruiseki[i+1] + B_num[i]

    ans = 0
    for i in range(N):
        #print(binery_search(0,N,A[i],B))
        tmp = binery_search(0,N,A[i],B)
        if tmp >= N:
            continue
        else:
            ans += B_ruiseki[binery_search(0,N,A[i],B)]

    return ans

print(main())

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))
    C = list(map(int, sysread().split()))
    A.sort()
    B.sort()
    C.sort()
    ansBa = []
    ansBc = []
    for i in range(N):
        b = B[i]
        idx = bisect.bisect_left(A, b)
        ansBa.append(idx)

        idx2 = bisect.bisect_left(C, b)
        ansBc.append(N-idx2)
        if b == C[idx2]:
            ansBc[-1] -= 1
    #print(ansBc, ansBa)
    ans = 0
    for aa, cc in zip(ansBa, ansBc):
        ans += aa * cc


    print(ans)

if __name__ == "__main__":
    run()

Submission status: Runtime Error

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

d = deque([])
for i in range(N):
  n = bisect.bisect_right(C, B[N-1-i])
  if len(d) == 0:
    d.appendleft(N-n)
  else:
    d.appendleft(N-n+d[0])
  
ans = 0
for i in range(N):
  n = bisect.bisect_right(B, A[i])
  ans += d[n]
print(ans)

Submission status: Runtime Error

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	if n == 3:
		return 1/0
	al = lin()
	bl = lin()
	cl = lin()
	al.sort()
	bl.sort()
	cl.sort()
	cl_num=bl[:]
	cl_pos=0
	for i, vb in enumerate(bl):
		while cl_pos <n and cl[cl_pos] <= vb:
			cl_pos += 1
		cl_num[i] = n-cl_pos
		
	cl_nokori=[0]*n
	cl_nokori[-1] = cl_num[-1]
	for i, v in enumerate(cl_num[::-1]):
		if i == 0:
			continue
		cl_nokori[n-i-1] = cl_nokori[n-i]+v
	
	ret = 0
	bl_pos=0
	for va in al:
		while bl_pos < n and va >= bl[bl_pos]:
			bl_pos += 1
		if bl_pos == n:
			break
		ret += cl_nokori[bl_pos]
	print(ret)
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

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

tmp_b = 0
tmp_c = 0
max_b = B[-1]
max_c = C[-1]
ans = 0
for i in range(N):
    flg = False
    tmp = A[i]
    if tmp >= max_b:
        break
    while True:
        if B[tmp_b] > tmp:
            tmp = B[tmp_b]
            break
        else:
            tmp_b += 1
    while True:
        if C[tmp_c] > tmp:
            break
        else:
            tmp_c += 1
    k = tmp_c
    for j in range(tmp_b, N):
        if B[j] >= max_c or flg:
            break
        else:
            while True:
                if B[j] < C[k]:
                    ans += N-k
                    break
                else:
                    k += 1
                    if k == N:
                        flg = True
                        break

print(ans)

Submission status: Runtime Error

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)

# for this we will use binary search.
import bisect as bis

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

Submission status: Runtime Error

Solution code:

import bisect


I = lambda: list(map(int, input().split()))
N = I()
A = I()
B = I()
C = I()
A.sort()
B.sort()
C.sort()

summ = 0
for ai in A:
    r = bisect.bisect_right(B, ai)
    for bi in B[r:]:
        rr = bisect.bisect_right(C, bi)
        summ += (N - r) * (N - rr)

print(summ)

Submission status: Runtime Error

Solution code:
def main(n,a,b,c):
  import bisect
  ans=0
  todo=[[ai] for ai in a]
  while len(todo)>0:
    d=todo.pop()
    if len(d)==1:
      l=bisect.bisect_right(b,d[-1])
      for li in b[l:]:
        e=d.copy()
        e.append(li)
        todo.append(e)
    elif len(d)==2:
      l=bisect.bisect_right(c,d[-1])
      for li in c[l:]:
        e=d.copy()
        e.append(li)
        todo.append(e)
    elif len(d)==3:
      ans+=1
  print(ans)
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())))
  main(n,a,b,c)

Submission status: Runtime Error

Solution code:
def main(n,a,b,c):
  import bisect
  ans=0
  todo=[[ai] for ai in a]
  while len(todo)>0:
    d=todo.pop()
    if len(d)==1:
      l=bisect.bisect_right(b,d[-1])
      for li in b[l:]:
        e=d.copy()
        e.append(li)
        todo.append(e)
    if len(d)==2:
      l=bisect.bisect_right(c,d[-1])
      for li in c[l:]:
        e=d.copy()
        e.append(li)
        todo.append(e)
    if len(d)==3:
      ans+=1
  print(ans)
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())))
  main(n,a,b,c)

Submission status: Runtime Error

Solution code:
def main(n,a,b,c):
  import bisect
  ab=[] #ab[i]:上部にi個目を選んだ時、中部に選べるもののうち最小のインデックス。選べないならnになる
  ab.append(bisect.bisect_right(b,a[0]))
  bc=[]
  bc.append(bisect.bisect_right(c,b[0]))
  for i in range(1,n):
    if a[i]<b[ab[i-1]]:
      ab.append(ab[i-1])
    else:
      ab.append(bisect.bisect_right(b[ab[i-1]:],a[i])+ab[i-1])
    if b[i]<c[bc[i-1]]:
      bc.append(bc[i-1])
    else:
      bc.append(bisect.bisect_right(c[bc[i-1]:],b[i])+bc[i-1])
  ans=0
  for i in range(n):
    for j in range(ab[i],n):
      ans+=n-bc[j]
  print(ans)
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())))
  main(n,a,b,c)

Submission status: Runtime Error

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())))
ab={} #ab[i]:上部にi個目を選んだ時、中部に選べるもののうち最小のインデックス。選べないならnになる
l=bisect.bisect_right(b,a[0])
ab[0]=l
for i in range(1,n):
  if a[i]<b[ab[i-1]]:
    ab[i]=ab[i-1]
  else:
    j=ab[i-1]+1
    while n>j and a[i]>=b[j]:
      j+=1
    ab[i]=j
bc={} 
l=bisect.bisect_right(c,b[0])
bc[0]=l
for i in range(1,n):
  if b[i]<c[bc[i-1]]:
    bc[i]=bc[i-1]
  else:
    j=bc[i-1]+1
    while n>j and b[i]>=c[j]:
      j+=1
    bc[i]=j
ans=0
for i in range(n):
  for j in range(ab[i],n):
    ans+=n-bc[j]
print(ans)

Submission status: Runtime Error

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())))
ab={} #ab[i]:上部にi個目を選んだ時、中部に選べるもののうち最小のインデックス。選べないならnになる
l=bisect.bisect_right(b,a[0])
ab[0]=l
for i in range(1,n):
  if a[i]<b[ab[i-1]]:
    ab[i]=ab[i-1]
  else:
    j=ab[i-1]+1
    while n>j and a[i]>=b[j]:
      j+=1
    ab[i]=j
bc={} 
l=bisect.bisect_right(c,b[0])
bc[0]=l
for i in range(1,n):
  if b[i]<c[bc[i-1]]:
    bc[i]=bc[i-1]
  else:
    j=bc[i-1]+1
    while n>j and b[i]>=c[j]:
      j+=1
    bc[i]=j
ans=0
for i in range(n):
  for j in range(ab[i],n):
    ans+=n-bc[j]

Submission status: Runtime Error

Solution code:
import sys
import bisect
input = sys.stdin.readline
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=len(c)-bisect.bisect_right(und,i)
    num+=a*c
print(num)

Submission status: Runtime Error

Solution code:
import sys
import bisect
input = sys.stdin.readline()
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=len(c)-bisect.bisect_right(und,i)
    num+=a*c
print(num)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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 ai in range(N):
    bi = bisect_left(B, A[ai])
    ci = bisect_left(C, B[bi])
    ans += (N-bi)*(N-ci)

print(ans)

Submission status: Runtime Error

Solution code:
from bisect import*
r=lambda:sorted(map(int,input().split()))
N=r()[0]
A,B,C,w,s=r(),r(),r(),[0]*N,0
for i in range(N-1,-1,-1):s=w[i]=s+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

Submission status: Runtime Error

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()
ans = 0
for i in range(n):
    B_HIGH = n-1
    B_LOW = 0
    B_NOW = 0
    while(1 < (B_HIGH - B_LOW)):
        B_NOW = (B_HIGH + B_LOW)//2
        if c[i] < b[B_NOW]:
            B_HIGH = B_NOW
        else:
            B_LOW = B_NOW

    if b[B_NOW] == b[B_NOW - 1]:
        while(1):
            if B_NOW == 0 or b[B_NOW] != b[B_NOW - 1]:
                break
            else:
                B_NOW -= 1

    for j in range(B_NOW,n):
        A_HIGH = n-1
        A_LOW = 0
        A_NOW = 0

        while(1 < (A_HIGH - A_LOW)):
            A_NOW = (A_HIGH + A_LOW)//2
            if b[j] < a[A_NOW]:
                A_HIGH = A_NOW
            else:
                A_LOW = A_NOW

        if a[A_NOW] == a[A_NOW +1]:
            while(1):
                if A_NOW == n-1 or a[A_NOW] != a[A_NOW + 1]:
                    break
                else:
                    A_NOW += 1
        ans += A_NOW + 1

print(ans)

Submission status: Runtime Error

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
"""
print(a)
print(b)
print(c)
"""
for i in range(n):
    B_HIGH = n-1
    B_LOW = 0
    B_NOW = 0
    while(1 < (B_HIGH - B_LOW)):
        B_NOW = (B_HIGH + B_LOW)//2
        """print(B_NOW,end = " ")"""
        if c[i] < b[B_NOW]:
            B_HIGH = B_NOW
        else:
            B_LOW = B_NOW

    if b[B_NOW] == b[B_NOW - 1]:
        while(1):
            if B_NOW == 0 or b[B_NOW] != b[B_NOW - 1]:
                break
            else:
                B_NOW -= 1

    """print(c[i],b[B_NOW])"""
    for j in range(B_NOW,n):
        A_HIGH = n-1
        A_LOW = 0
        A_NOW = 0

        while(1 < (A_HIGH - A_LOW)):
            A_NOW = (A_HIGH + A_LOW)//2
            if b[j] < a[A_NOW]:
                A_HIGH = A_NOW
            else:
                A_LOW = A_NOW

        if a[A_NOW] == a[A_NOW +1]:
            while(1):
                if A_NOW == n-1 or a[A_NOW] != a[A_NOW + 1]:
                    break
                else:
                    A_NOW += 1

        ans += A_NOW + 1

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: cp932 -*-

import sys
import os
import re
import datetime
import bisect

def Test(value):
    a = [1,3,5]
    #x = 4

    insert_index = bisect.bisect_left(a, value)
    
    print("insert_index = ", insert_index)
    
if False:   
    while(True): 
        Test(int(input('? ')));
    sys.exit()
 
N = int(input())

partsNumA = sorted(map(int, input().split()))
partsNumB = sorted(map(int, input().split()))
partsNumC = sorted(map(int, input().split()))

# Bに対してAの個数のBによるループ
partsNumSumBa = []
sumA = 0
#for i in range(N):
for curPartsB in partsNumB:
    indexA = bisect.bisect_left(partsNumA, curPartsB)
    numA = indexA
    sumA += numA
    partsNumSumBa.append(sumA)

if False:
    print("Sorted A" , partsNumA)
    print("Sorted B" , partsNumB)
    print("Sorted C" , partsNumC)

    print("B loop" , partsNumSumBa)

# Cに対してBの個数のCによるループ
sumBAll = 0
for curPartsC in partsNumC:
    indexB = bisect.bisect_left(partsNumB, curPartsC)
    if indexB == 0:
        continue
    numB = partsNumSumBa[indexB - 1]
    sumBAll += numB
        
print(sumBAll)

Submission status: Runtime Error

Solution code:
# -*- coding: cp932 -*-

import sys
import os
import re
import datetime
import bisect

def Test(value):
    a = [1,3,5]
    #x = 4

    insert_index = bisect.bisect_left(a, value)
    
    print("insert_index = ", insert_index)

####### main #######
    
if False:   
    while(True): 
        Test(int(input('? ')));
    sys.exit()
 
N = int(input())

partsNumA = sorted(map(int, input().split()))
partsNumB = sorted(map(int, input().split()))
partsNumC = sorted(map(int, input().split()))

# Bに対してAの個数のBによるループ
partsNumSumBa = []
sumA = 0
for curPartsB in partsNumB:
    indexA = bisect.bisect_left(partsNumA, curPartsB)
    numA = indexA
    sumA += numA
    partsNumSumBa.append(sumA)

# Cに対してBの個数のCによるループ
sumBAll = 0
for curPartsC in partsNumC:
    indexB = bisect.bisect_left(partsNumB, curPartsC)
    if indexB == 0:
        continue
    numB = partsNumSumBa[indexB - 1]
    sumBAll += numB
        
print(sumBAll)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right

if __name__ == "__main__":
    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

    # まずあるbを選んだ時のcの組み合わせの数のリストを作る。
    clist = [0] * n
    clist[n-1] = n - bisect_right(c, b[n-1])
    for i in range(n-2, -1, -1):
        clist[i] = n - bisect_right(c, b[i]) + clist[i+1]

    for aa in a:
        b_pos = bisect_right(b, aa)
        ans += clist[b_pos]

    print(ans)

Submission status: Runtime Error

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())))
ad = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if A[i] < B[j]:
        ad[i] = j
        i += 1
    else:
        j += 1
bd = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if B[i] < C[j]:
        bd[i] = j
        i += 1
    else:
        j += 1
csum = [0] * N
for i in range(N):
    if bd[i] >= 0:
        csum[i] = N-bd[i]
bsum = [0]* N
cnt = 0
for i in range(N):
    cnt += csum[N-1-i]
    bsum[N-1-i] = cnt
ans = 0
for i in range(N):
    if ad[i] >= 0:
        ans += bsum[ad[i]]
print(ans)

Submission status: Runtime Error

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

# BとCのセットだけ見てありえるパターンを出す
# B_Csは注目要素より右側の和
B_Cs = [0] * N

prev = N - bisect.bisect_left(Cs, Bs[-1])
B_Cs[-1] = prev
for i, b in enumerate(reversed(Bs)):
    if i == 0 :
        continue
    rev_i = N - i -1
    index = bisect.bisect_left(Cs, b+1)
    
    prev = (N - index) + prev
    B_Cs[rev_i] = prev

cnt = 0
for i, a in enumerate(As):
    index = bisect.bisect_left(Bs, a+1)
    cnt += B_Cs[index]
print(cnt)

Submission status: Runtime Error

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

# BとCのセットだけ見てありえるパターンを出す
B_Cs = [0] * N
for i, b in enumerate(Bs):
    index = bisect.bisect_left(Cs, b+1)
    B_Cs[i] = (N - index)

cumsum_BC =[sum(B_Cs[i:]) for i in range(N)]

cnt = 0
for i, a in enumerate(As):
    index = bisect.bisect_left(Bs, a+1)
    cnt += cumsum_BC[index]
print(cnt)

Submission status: Runtime Error

Solution code:
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    as = sorted(a)
    cs = sorted(C)
    ans = 0
    for i in b:
        d = bisect.bisect_left(as, i)
        e = n - bisect.bisect_right(cs, i)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int con;
    con = 0;
    vector<vector<int>> parts(3, vector<int>(N));

    for(int i = 0;i < 3; i++){
        for(int j = 0;j < N; j++){
            cin >> parts[i][j];
        }
    }

    for (int i = 0;i < N; i ++){
        for (int j = 0;j < N; j++){
            if (parts[2][i] > parts[1][j]){
                for (int k = 0;k < N; k++){
                    if (parts[1][j] > parts[0][k]){
                        con += 1;

                    } 
                }
            }
        }
    }
    cout << con << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
parts = [[] for i in range(3)]
bigger = [[0] * N for i in range(2)]

m = 0

for i in range(3):
  t = list(map(int,input().split()))
  t = [i for i in t if i >= m]
  parts[i] = t
  m = min(t)

under =parts[2]
middle = parts[1]
upper = parts[0]

con = 0

for i in range(len(under)):
  p = under[i]
  for j in range(len(middle)):
    q = middle[j]
    if p > q:
      for k in range(len(upper)):
        r = upper[k]
        if q > r:
          con += 1
          
print(con)

Submission status: Runtime Error

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 range(n):
  x=b[i]
  y=bisect.bisect_left(a,x)
  z=bisect.bisect_right(c,x)
    ans+=(n-z)*y
print(ans)

Submission status: Runtime Error

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 range(n):
  x=a[i]
  y=bisect.bisect_right(x)
  if y<n:
    z=bisect.bisect_right(b[y])
    ans+=n-z
print(ans)

Submission status: Runtime Error

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 range(n):
  x=a[i]
  y=bisect.bisect_right(x)
  z=bisect.bisect_right(b[y])
  ans+=n-z
print(ans)

Submission status: Runtime Error

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

bc=[0]*N
ii=0
for i in range(N):
  while c[ii]<=b[i] and ii<N:
    ii+=1
    if ii==N:
      break
  bc[i]=N-ii
#print(bc)
for i in range(N-2,-1,-1):
  bc[i]+=bc[i+1]
#print(bc)

ab=[0]*N
ii=0
for i in range(N):
  while b[ii]<=a[i] and ii <N:
    ii+=1
    if ii==N:
      break
  ab[i]=bc[ii] if ii<N else 0
print(sum(ab))

Submission status: Runtime Error

Solution code:
import bisect
from itertools import accumulate
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))
aa = [0] * n
bb = [0] * n
for i in range(n):
  bb[i] = n - bisect.bisect_right(c,b[i])
bb.reverse()
bbb = tuple(accumulate(bb))
for i in range(n):
  aa[i] = bbb[-(bisect.bisect_right(b,a[i])+1)]
print(sum(aa))

Submission status: Runtime Error

Solution code:
import bisect
from itertools import accumulate
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))
aa = [0] * n
bb = [0] * n
for i in range(n):
  bb[i] = n - bisect.bisect_right(c,b[i])
bb.reverse()
bbb = tuple(accumulate(bb))
for i in range(n):
  aa[i] = bbb[-(bisect.bisect_right(b,a[i])+1)]
print(sum(aa))
print(bb,bbb,aa)

Submission status: Runtime Error

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()]
d = 0
a.sort()
b.sort()
c.sort()
ls = b

for i in range(n):
  ls = [bs for bs in ls if bs > a[i]]
  for j in range(len(ls)):
    d += len([cs for cs in c if cs > ls[i]])
print(d)

Submission status: Runtime Error

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

def bs(left,right,aim,line):
    center = (right + left) // 2

    if aim == line[center]:
        return center
    elif left == right:
        return center
    elif aim > line[center]:
        left = center + 1
    else:
        right = center - 1
    return bs(left,right,aim,line)

ans = 0

for i in b:
    if max(a[-1],i) == i:
        tmp1 = len(a)
    else:
        tmp1 = bs(0,len(a),i,a) + 1
    if min(c[0],i) == i:
        tmp2 = len(c)
    else:
        tmp2 = len(c) - (bs(0,len(c),i,c) + 1)
    ans += tmp1 * tmp2

print(ans)

Submission status: Runtime Error

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()
i,j=0,0
m1=[]
for k in a:
  if b[i]>k:
    j+=1
  else:
    m1.append(j)
for t in range(len(m1),len(b)):
  m1.append(j)
i,j=0,0
m2=[]
for k in range(n):
  if c[i]>k:
    j+=m1[b[k]]
  else:
    m2.append(j)
for t in range(len(m2),len(c)):
  m2.append(j)
print(sum(m2))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=list(set(a))
b=list(set(b))
c=list(set(c))
a.sort()
b.sort()
c.sort()
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,len(b)):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,len(c)):
  d2[c[t]]=j
print(sum(d2.values()))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=list(set(a))
b=list(set(b))
c=list(set(c))
a.sort()
b.sort()
c.sort()
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,n):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,n):
  d2[c[t]]=j
print(sum(d2.values()))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
    j=0
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
    j=0
print(sum(d2.values()))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
All = [] #全ての数字格納リスト
B_A = [] #Biより小さいAjの個数格納リスト
B_C = [] #Biより大きいCkの個数格納リスト

for i in range(N):
  All.append([A[i],0])
  All.append([B[i],1])
  All.append([C[i],2])
All.sort()

count1,count2 = 0,0
for i in range(3*N):
  if(All[i][1] == 1):     
    if(i == 0):
      B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(N-count2-1)
      else: B_C.append(N-count2)
    elif(i == N-1):
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      B_C.append(N-count2)
    else:
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(N-count2-1)
      else: B_C.append(N-count2)
    
  if(All[i][1] == 0): count1 += 1
  if(All[i][1] == 2): count2 += 1

ans = 0
for i in range(N):
 ans += B_A[i]*B_C[i]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
All = [] #全ての数字格納リスト
B_A = [] #Biより小さいAjの個数格納リスト
B_C = [] #Biより大きいCkの個数格納リスト

for i in range(N):
  All.append([A[i],0])
  All.append([B[i],1])
  All.append([C[i],2])
All.sort()

count1,count2 = 0,0
for i in range(3*N):
  if(All[i][1] == 1):     
    if((i != 0)and(i != N-1)):
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(N-count2-1)
      else: B_C.append(N-count2)
    else:
      B_A.append(count1),B_C.append(N-count2)
    
  if(All[i][1] == 0): count1 += 1
  if(All[i][1] == 2): count2 += 1

ans = 0
for i in range(N):
 ans += B_A[i]*B_C[i]
print(ans)

Submission status: Runtime Error

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):
    a=bisect.bisect_left(a, B[j])
    c=bisect.bisect_right(a, B[j])
    ans+=a*c
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, bisect_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=0
for j in range(N):
    a=bisect_left(a, B[j])
    c=bisect_right(a, B[j])
    ans+=a*c
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, bisect_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=0
for j in range(N):
    a=bisect_left(a, B[i])
    c=bisect_right(a, B[i])
    ans+=a*c
print(ans)

Submission status: Runtime Error

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)

BB = [0] * N

cidx = 0
for i in range(N):
    while cidx < N and C[cidx] <= B[i]:
        cidx += 1
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while B[bidx] <= A[i]:
        bidx += 1
        if bidx == N:
            break
    if bidx != N:
        sum += BBB[bidx]

print(sum)

Submission status: Runtime Error

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)

BB = [0] * N

cidx = 0
for i in range(N):
    while C[cidx] <= B[i]:
        cidx += 1
        if cidx == N:
            break
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while B[bidx] <= A[i]:
        bidx += 1
        if bidx == N:
            break
    if bidx != N:
        sum += BBB[bidx]

print(sum)
pass

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[100000], B[100000], C[100000];
    cin >> N;
    REP(i, N) cin >> A[i]; sort(A, A + N);
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i]; sort(C, C + N);

    ll ans = 0;
    REP(i, N) {
        ll a = lower_bound(A, A + N, B[i]) - A;
        ll c = C - upper_bound(C, C + N, B[i]) + N;
        ans += a * c;
    }
    cout << ans << endl;
    return 0;
}