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: Accepted

Solution code:
#import generator


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

"""
with open('generator.txt', 'r') as f:
    read = f.read().split('\n')
    N = int(read[0])
    A = list(map(int, read[1].split()))
    B = list(map(int, read[2].split()))
    C = list(map(int, read[3].split()))
"""
A.sort()
C.sort()


def binary_search(lst, value, high):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            # lstの中にある場合
            if high:
                # 真に大きい
                return binary_search(lst, value + 0.5, high)
            else:
                # 真に小さい
                return binary_search(lst, value - 0.5, high)
    if high:
        return l
    else:
        return r


def main():
    ans = 0
    # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる
    for middle in B:
        lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する
        higher = N - binary_search(C, middle, True)
        ans += lower * higher
    print(ans)

    
# 愚直解
def main2():
    ans = 0
    for a in A:
        for b in B:
            for c in C:
                if a < b < c:
                    ans += 1
    print(ans)
    

if __name__ == "__main__":
    main()
    #main2()

Submission status: Accepted

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 b:
  p = bisect.bisect_left(a, i)
  q = bisect.bisect_right(c, i)
  ans += (p*(n-q))
  
print(ans)

Submission status: Accepted

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

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

def bin_serch(array,num):
    head = 0
    tail = len(array)
    while head < tail:
        center = (head + tail) // 2
        if num < array[center]:
            tail = center
        else:
            head = center + 1
    return head

BC = [0 for _ in range(len(B))]
for i in range(len(B)):
    BC[i] = len(C) - bin_serch(C,B[i])
    
s = 0
for i in range(len(BC)-1, -1, -1):
    s += BC[i]
    BC[i] = s

ans = 0
for a in A:
    b = bin_serch(B,a)
    if b < len(B):
        ans += BC[b]
    
print(ans)

Submission status: Accepted

Solution code:
from bisect import *

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 b in B:
    index_A = bisect_left(A, b)
    index_C = bisect_right(C, b)
    ans += index_A * (n - index_C)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
import math
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
A=A+[math.inf]
B=B+[math.inf]
C=C+[math.inf]
d=[0 for i in range(N)]
ac=0
for i in range(N):
  while C[ac]<=B[i]:
    ac+=1
  if ac==N:
    break
  d[i]=N-ac
ab=0
ans=0
for i in range(1,N):
  d[i]+=d[i-1]
def f(x):
  if x!=0:
    return d[N-1]-d[x-1]
  else:
    return d[N-1]
for i in range(N):
  while B[ab]<=A[i]:
    ab+=1
    if ab==N:
      break
  ans+=f(ab)
print(ans)

Submission status: Accepted

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

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

combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected

ic = 0
lc = len(C)
for ib in range(len(B)):
	b = B[ib]
	while ic < lc:
		c = C[ic]
		if b >= c:
			ic += 1
		else:
			combiBC[ib] = lc - ic
			break

sumCombiBC = []
for i in range(len(combiBC)):
	if i == 0:
		sumCombiBC.append(combiBC[-1])
	else:
		sumCombiBC.insert(0, combiBC[-i-1] + sumCombiBC[0])

cnt = 0
ib = 0
for ia in range(len(A)):
	a = A[ia]
	while ib < len(B):
		b = B[ib]
		if a >= b:
			ib += 1
		else:
			cnt += sumCombiBC[ib]
			break

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=list(map(int, input().split()))
alist.sort()
blist.sort()
clist.sort()
import bisect
ans=0
for b in blist:
  num1=n-bisect.bisect(clist,b)
  num2=bisect.bisect_left(alist,b)
  ans+=num1*num2
print(ans)

Submission status: Accepted

Solution code:
from bisect import *
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

cnt = []

for b in B:
    cnt.append(bisect_left(A, b) * (N - bisect_right(C, b)))
print(sum(cnt))

Submission status: Accepted

Solution code:
from bisect import bisect, bisect_left


def bin_search(n):

    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):
        upper_b = bisect_left(a, b[i])
        under_b = n - bisect(c, b[i])
        ans += upper_b * under_b
    return ans


if __name__ == '__main__':
    n = int(input())
    print(bin_search(n))

Submission status: Accepted

Solution code:
from bisect import *

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 = []

for b in B:
    cnt.append(bisect_left(A,b) * (N - bisect_right(C,b)))
print(sum(cnt))

Submission status: Accepted

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())))
ans = 0
for i in b:
    an = bisect.bisect_left(a, i)
    cn = n - bisect.bisect_right(c, i)
    ans += an * cn

print(ans)

Submission status: Accepted

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

ans=0
for b in B:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += a_index * (N-c_index)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect

def main():
    input = sys.stdin.buffer.readline
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    B = list(map(int, input().split()))
    B.sort()
    C = list(map(int, input().split()))
    C.sort()
    ans = 0
    for i in B:
        a = bisect.bisect_left(A, i)
        c = bisect.bisect_right(C, i)
        ans += a*(N-c)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def isOK(index, key, in_ls):
    if key<in_ls[index]: return True
    else: return False

def bs(in_ls, key):
    ng = -1
    ok = len(in_ls)
    while 1<abs(ok - ng):
        mid = (ng + ok)//2
        if isOK(mid, key, in_ls): ok = mid
        else: ng = mid
    return ok

def main():
    n = int(input())
    a_list = list(map(int, input().split(" ")))
    b_list = list(map(int, input().split(" ")))
    c_list = list(map(int, input().split(" ")))
    #a < b < c

    a_sorted = list(sorted(a_list))
    b_sorted = list(sorted(b_list))
    c_sorted = list(sorted(c_list))

    bc_dict = {}
    score = 0
    score_list = [0 for i in range(n)]
    for i, b in enumerate(b_sorted[::-1]):
        ok = bs(c_sorted, b)
        score+=n - ok
        score_list[n-i-1]+=score

    total = 0
    for a in a_sorted:
        ok = bs(b_sorted, a)
        if ok==n:
            continue
        total+=score_list[ok]

    print(total)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

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 b in B:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)

Submission status: Accepted

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

    B_accum = []
    B_accum_inv = [0] * N

    for b in B:
        c_idx = binary_search(C, b)
        B_accum.append(N-c_idx-1)

    tmp_sum = 0
    for i in range(len(B_accum)):
        tmp_sum += B_accum[N-i-1]
        B_accum_inv[N-i-1] = tmp_sum

    sum_ans = 0
    for a in A:
        b_idx = binary_search(B, a)
        if b_idx+1 < N:
            sum_ans += B_accum_inv[b_idx+1]

    print(sum_ans)


def binary_search(A, x):
    ok = -1
    ng = len(A)
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if A[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for B in b:
    i = bisect.bisect_left(a, B)
    j = bisect.bisect_right(c, B)
    ans += i * (n - j)

print(ans)

Submission status: Accepted

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 = i = j = 0

import bisect

for b in B:
    i = bisect.bisect_left(A,b)
    j = N - bisect.bisect_right(C,b)
    ans += i * j
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
N = int(input())
A, B, C = [sorted(map(int, input().split())) for _ in range(3)]
print(sum(bisect_left(A,b)*(N-bisect_right(C,b)) for b in B))

Submission status: Accepted

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 b:
    i = bisect_left(a, j)
    k = bisect_right(c, j)
    ans += i*(n-k)
    #print(j, a, i)
    #print(j, c, k)
print(ans)

Submission status: Accepted

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):
    a_cand = bisect.bisect_right(A,B[i]-1)
    c_cand = N-bisect.bisect_right(C,B[i])
    count += a_cand*c_cand
print(count)

Submission status: Accepted

Solution code:
def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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]*N
for i in range(N):
    cnt[i] = cnt[i-1] + bisect.bisect_left(A,B[i])
ans = 0
for i in range(N):
    target = bisect.bisect_left(B,C[i])
    if target > 0:
        ans += cnt[target-1]
print(ans)

Submission status: Accepted

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

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

ans = 0
a = [0]+a
c = c+[10**10]
ai, ci = 0, 0
for i in range(n):
    while ai < n and a[ai+1] < b[i]:
        ai += 1
    while ci < n and c[ci] <= b[i]:
        ci += 1
    ans += ai*(n-ci)
print(ans)

Submission status: Accepted

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 i in range(len(b)):
    index_a=bisect.bisect_left(a,b[i])
    index_c=bisect.bisect_right(c,b[i])
    ans+=(index_a*(len(c)-index_c))
print(ans)

Submission status: Accepted

Solution code:
import copy
import math
import time
import statistics
import math
import itertools
import bisect

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

    a_list.sort()
    b_list.sort()
    c_list.sort()

    a_count = []
    b_count = []
    b_count2 = []

    idx = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a, idx)
        a_count.append(idx)

    idx = 0
    for b in b_list:
        idx = bisect.bisect_right(c_list, b, idx)
        b_count.append(idx)

    ruikei = 0
    for i in range(n-1, -1, -1):
        ruikei += n - b_count[i]
        b_count2.append(ruikei)

    b_count2.sort(reverse=True)

    ans = 0
    for a in a_count:
        if a == n:
            continue
        ans += b_count2[a]

    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()

Submission status: Accepted

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)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

Submission status: Accepted

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)

count=0
#a[i]の個数
for i in range(n):
    a_count = bisect.bisect_left(a, b[i])
    c_count = bisect.bisect_right(c, b[i])
    count+=a_count*(len(c)-c_count)

print(count)

Submission status: Accepted

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)

from bisect import bisect_right

d=[]
for i in range(n):
    index = bisect_right(c,b[i])    

    d.append(n-index)

import numpy as np
s=sum(d)
cum=np.cumsum(d)

ans=0
for j in range(n):
    dex = bisect_right(b,a[j])
    if dex==0:
        ans+=s
    elif dex==n:
        continue
    else:
        ans+=s-cum[dex-1]

print(ans)

Submission status: Accepted

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()))
out=0
a.sort()
b.sort()
c.sort()
for i in b:
    na = bisect.bisect_left(a,i)
    nc = bisect.bisect(c,i)
    out += na * (len(c)-nc)
print(out)

Submission status: Accepted

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 b in B:
    a_count = bisect.bisect_left(A, b)
    c_count = N - bisect.bisect_right(C, b)
    ans += a_count * c_count
print(ans)

Submission status: Accepted

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

pat = 0

for i in B:
    numA = bisect.bisect_left(A,i)
    numC = bisect.bisect(C,i)
    pat += numA * (len(C)-numC)

print(pat)

Submission status: Accepted

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg): #　B　より小さい最大の　A
    return A_list[arg] < B_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg): #　B　より大きい最小の　A
    return C_list[arg] > B_list[i]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Bを固定
    #Bより小さいAを探す
    A_key = bisect(len(A_list), 0)
    if A_list[A_key] < B_list[i]:
        #Bより大きいCを探す
        C_key = bisect2(-1, len(C_list)-1)
        if B_list[i] < C_list[C_key]:
            #print(A_key, i, C_key, A_list[A_key], B_list[i], C_list[C_key])
            cnt += (n-C_key)*(A_key+1)

print(cnt)

Submission status: Accepted

Solution code:
import bisect

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

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c
else:
    print(ans)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
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()
b_res=[0]*n
c_res=[0]*n
j=0
cnt=0
for i in range(n):
    res=b[i]
    cnt=bisect.bisect_left(a,res)
    b_res[i]=cnt
    res=c[i]
    cnt=bisect.bisect_left(b,res)
    c_res[i]=cnt
cntb=[0]*n
cntb[0]=b_res[0]
for i in range(1,n):
    cntb[i]=cntb[i-1]+b_res[i]
ans=0
for i in range(n):
    cnt=c_res[i]
    if cnt==0:
        continue
    else:
        ans+=cntb[cnt-1]
print(ans)

Submission status: Accepted

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

import bisect as bi
ans=0
for i in range(n):
    q=B[i]
    oka= bi.bisect_left(A,q)
    okb= n- bi.bisect_right(C,q)
    ans+=oka*okb
print(ans)

Submission status: Accepted

Solution code:
import bisect
from collections import defaultdict
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
bb = []
for b in B:
  idx = bisect.bisect_right(C, b)
  bb += [[b, len(C)-idx]]

for i in range(len(bb)-1, 0, -1):
  bb[i-1][1] += bb[i][1]

for a in A:
  idx = bisect.bisect_right(B, a)
  if idx > len(B)-1:
    continue
  ans += bb[idx][1]
print(ans)

Submission status: Accepted

Solution code:
from bisect import*
(n,), a, b, c = [sorted(map(int, o.split())) for o in open(0)]
print(sum(bisect_left(a, i) * (n - bisect(c, i)) for i in b))

Submission status: Accepted

Solution code:
# ABC_077_C_Sunuke_Festival.py

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

# B[j]を固定してA[i]<=B[j]<=C[k]を満たす(i,j)の個数を求める
# ソートして二分探索すれば間に合う
A.sort()
# B.sort()
C.sort()
# print(A)
# print(B)
# print(C)


def bisectsearch_left(L, a):
    i = bisect_left(L, a)
    return(i)


def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)


ans = 0
for j in range(N):
    b = B[j]
    cti = bisectsearch_left(A, b)
    ctk = N-bisectsearch_right(C, b)
    # print(cti, ctk)
    ans += cti*ctk
print(ans)

Submission status: Accepted

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)
c=sorted(c)
ans=0
import bisect
for i in b:
  t=bisect.bisect_left(a, i)
  q=bisect.bisect_right(c, i)
  ans+=t*(n-q)
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()


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()
    C.sort()
    ans = 0
    for b in B:
        idx_a = bisect_left(A, b)
        idx_c = bisect_right(C, b)
        ans += idx_a * (N - idx_c)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#関数リスト
import sys
import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in B:
        tempA = bisect.bisect_left(A,i) 
        tempC = C_len - bisect.bisect_right(C,i)
        result += tempA*tempC
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]
a=sorted(A)
b=sorted(B)
c=sorted(C)
ans=0
import bisect
from bisect import bisect_right
from bisect import bisect_left
for j in range(n):
  p=bisect.bisect_left(a,b[j])
  q=n-bisect.bisect_right(c,b[j])
  ans+=p*q
print(ans)

Submission status: Accepted

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()))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))

Submission status: Accepted

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()
ab=[]
bc=[]
for i in range(n):
    ab.append([a[i],n])
    bc.append([b[i],n])
    ab.append([b[i],i])
    bc.append([c[i],i])
numa=1
numb=1
numc=1
la=[1]*n
lb=[1]*n
lc=[1]*n
for i in range(1,n):
    if a[i-1]!=a[i]:
        la[i]=i+1
        numa=i+1
    else:
        la[i]=numa
    if b[i-1]!=b[i]:
        lb[i]=i+1
        numb=i+1
    else:
        lb[i]=numb
    if c[i-1]!=c[i]:
        lc[i]=i+1
        numc=i+1
    else:
        lc[i]=numc
ab.sort(key=lambda x: x[0])
numab=1
lab=[1]*(n+1)
for i in range(1,n*2):
    if ab[i-1][0]!=ab[i][0]:
        lab[ab[i][1]]=i+1
        numab=i+1
    else:
        lab[ab[i][1]]=numab
ansb=[0]*n
numb=0
for i in range(n):
    numb+=lab[i]-lb[i]
    ansb[i]=numb
bc.sort(key=lambda x: x[0])
numbc=1
lbc=[1]*(n+1)
for i in range(1,n*2):
    if bc[i-1][0]!=bc[i][0]:
        lbc[bc[i][1]]=i+1
        numbc=i+1
    else:
        lbc[bc[i][1]]=numbc
ansc=[0]*n
for i in range(n):
    ansc[i]=lbc[i]-lc[i]
ans=0
for i in range(n):
    if ansc[i]!=0:
        ans+=ansb[ansc[i]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
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()
  C.sort()
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect_left(A, b)
    mc = lc-bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
def main():
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect_left(A, b)
    mc = lc-bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

def main():
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
  import bisect
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
  import bisect
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lb,lc=len(B),len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
n=int(input())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
lc=len(C)
ans=0
for b in B:
  ma = bisect.bisect_left(A, b)
  mc = lc-bisect.bisect_right(C, b)
  ans += ma*mc
print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
lb,lc=len(B),len(C)
ans=0
for b in range(lb):
  ma = bisect.bisect_left(A, B[b])
  mc = lc-bisect.bisect_right(C, B[b])
  ans += ma*mc
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split())
bis = map(int, raw_input().split())
cis = map(int, raw_input().split())


count = 0
ais.sort()
bis.sort()
cis.sort()

i,j = 0,0
for b in bis:
	while(i < len(ais) and ais[i] < b):
		i += 1
	while(j < len(cis) and cis[j] <= b):
		j += 1
	count += i * (n - j)
print count

Submission status: Accepted

Solution code:
#create date: 2020-08-06 09:16

import sys
stdin = sys.stdin
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = na()
    c = na()
    a.sort()
    b.sort()
    c.sort()
    cnt = 0
    #print(a, b, c)
    for bi in b:
        i = bisect_left(a, bi)
        j = bisect_right(c, bi)
        cnt += i * (n-j)
        #print(bi, i, n-j)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
c_ls = list(map(int, input().split()))
for ls in [a_ls,b_ls,c_ls]:
    ls.sort()

def is_not_less_than(ls, ind, key):
    if ls[ind] >= key:
        return True
    else:
        return False

def return_min_ind_whose_value_not_less_than(ls,key):
    r = len(ls)
    l = -1
    while True:
        next_ind = (r+l) // 2
        if is_not_less_than(ls, next_ind, key):
            r = next_ind
        else:
            l = next_ind
        if r - l == 1:
            return r

def is_more_than(ls, ind, key):
    if ls[ind] > key:
        return True
    else:
        return False

def return_min_ind_whose_value_more_than(ls,key):
    r = len(ls)
    l = -1
    while True:
        next_ind = (r+l) // 2
        if is_more_than(ls, next_ind, key):
            r = next_ind
        else:
            l = next_ind
        if r - l == 1:
            return r

ans = 0
for i in range(n):
    b_c = n - return_min_ind_whose_value_more_than(c_ls, b_ls[i])
    a_b = return_min_ind_whose_value_not_less_than(a_ls, b_ls[i])
    ans += b_c*a_b
print(ans)