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 sys
import bisect
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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 for _ in range(n)]
for i in range(len(b)):
    if b[i] >= c[n-1]:
        break
    p = bisect(c,b[i])
    bc[i] = (n-p)

for i in range(len(b)-1,0,-1):
    bc[i-1] += bc[i]
ans = 0
for i in range(len(a)):
    if a[i] >= b[n-1]:
        break
    p = bisect(b,a[i])
    ans += bc[p]

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ans = 0
    for b in B:
        sum_v = 1
        l = -1
        r = N
        while r - l > 1:
            m = (l + r) // 2
            if b > A[m]:
                l = m
            else:
                r = m
        sum_v *= l + 1

        l = -1
        r = N
        while r - l > 1:
            m = (l + r) // 2
            if b < C[m]:
                r = m
            else:
                l = m
        sum_v *= N - r
        ans += sum_v
    print(ans)

if __name__ == '__main__':
    main()

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

# Bの値を決める
# Bより小さいAを二分探索、Bより大きいAを二分探索、その積を各Bごとに求めて足していく

import bisect
ans=0
for i in range(len(B)):
  apos=bisect.bisect_left(A,B[i])
  cpos=bisect.bisect_right(C,B[i])
  ans+=(apos)*(N-cpos)
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:
    ans += bisect.bisect_left(A,b) * (n - bisect.bisect_right(C,b))

print(ans)

Submission status: Accepted

Solution code:
import bisect, itertools

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

c_num = [0]*n
for i in range(n):
    c_num[i] = n - bisect.bisect_right(C, B[i])
c_accum = [0] + list(itertools.accumulate(c_num))

ans = 0
for i in range(n):
    b_index = bisect.bisect_right(B, A[i])
    ans += (c_accum[-1] - c_accum[b_index])
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

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

cnt_A = np.searchsorted(A,B)
cnt_C = N - np.searchsorted(C,B,side='right')
ans = (cnt_A*cnt_C).sum()

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])
cnt = 0

for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k) 

print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

ret = 0
for mid in b:
    ret += bisect_left(a, mid) * (n - bisect_left(c, mid + 1))
print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left,bisect_right

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    answer = 0
    A.sort()
    C.sort()
    for i in range(N):
        answer += bisect_left(A,B[i])*(N-bisect_right(C,B[i]))
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#01:55
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
ans = 0
for x in b:
  atmp = bisect.bisect_left(a,x)
  ctmp = bisect.bisect_right(c,x)
  ans += atmp * (n - ctmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
AS = list(map(int,input().split()))
AS.sort()
BS = list(map(int,input().split()))
CS = list(map(int,input().split()))
CS.sort()
import bisect
  
ans = 0
for b in range(n):
  ans += bisect.bisect_left(AS,BS[b])*(n-bisect.bisect_right(CS,BS[b]))

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# bisectで行けるけどめぐる式の練習

# Bを固定すると、A,Cを二分探索すれば条件を満たす個数が計算できる

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    # Cに関しては真に大きい個数を知りたいことに注意
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# bisectで行けるけどめぐる式の練習

# Bを固定すると、A,Cを二分探索すれば条件を満たす個数が計算できる

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

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

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    # Cに関しては真に大きい個数を知りたいことに注意
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a = sorted(a)
c = sorted(c)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)

Submission status: Accepted

Solution code:
import bisect

def snukefestival(n , a , b , c):

    ans = 0
    a.sort()
    b.sort()
    c.sort()

    for i in b:
        ab = bisect.bisect_left(a , i)
        cb = bisect.bisect_right(c , i)
        ans += ab * (len(b) - cb)

    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int , input().split()))
    print(snukefestival(n , a , b , c))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right


def main():
    N = int(input())
    parts = [sorted(list(map(int, input().split()))) for _ in range(3)]
    answer = 0
    for b in parts[1]:
        a = bisect_left(parts[0], b)
        c = bisect_right(parts[2], b)
        answer += a * (N - c)
    print(answer)


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()))
b.sort()
c.sort()
y = 0
bc = [0]
for i in range(1, n+1):
    bc.append(bc[-1] + n - bisect.bisect_right(c, b[-i]))
bc.reverse()
for i in a:
    y += bc[bisect.bisect_right(b, i)]
print(y)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()

idx = 0
cnt = [0]*n
for i in range(n):
    while b[i] >= c[idx] and idx + 1 < n: idx += 1
    if b[i] >= c[idx]: break
    cnt[i] = n-idx

for i in range(n-1)[::-1]: cnt[i] += cnt[i+1]

idx = 0
ans = 0
for i in range(n):
    while a[i] >= b[idx] and idx + 1 < n: idx += 1
    if a[i] >= b[idx]: break
    ans += cnt[idx]

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)
B = np.array(input().split(), dtype=int)
C = np.array(input().split(), dtype=int)
A.sort()
B.sort()
C.sort()

CB = np.searchsorted(B, C, side="left")
BA = np.searchsorted(A, B, side="left")
tmp = [0]+BA.cumsum().tolist()
tmp = np.array(tmp)

ans = tmp[CB].sum()
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
Br=[0]*N
for i in range(N):
    t=bisect.bisect_left(A,B[i])
    if(i==0):
        Br[i]=t
    else:
        Br[i]=Br[i-1]+t
for i in range(N):
    t=bisect.bisect_left(B,C[i])
    if(t==0):
        continue
    ans+=Br[t-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(list(map(int, input().split())))
C = sorted(map(int, input().split()))
import bisect
ans = 0
 
for i in B:
    iA = bisect.bisect_left(A, i)
    iB = bisect.bisect_right(C, i)
    ans += (iA)*(N-iB)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)

cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,B,side='right')

ans = (cnt_A * (N-cnt_C)).sum()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)

ans = 0
for i in range(N):
	b = B[i]
	a_ind = np.searchsorted(A,b,side='left')
	c_ind = np.searchsorted(C,b,side='right')
	ans += a_ind * (N-c_ind)

print(ans)

Submission status: Accepted

Solution code:
import bisect
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
for _b in b:
    ans += bisect.bisect_left(a, _b)*(n - bisect.bisect_right(c, _b))

print(ans)

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 = sorted(a)
c = sorted(c)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        # alの中でkey以上のアイテムのうち最小のインデックスを返す
        # upper_boundにする時にはa>key
        return a>=key

    ng = -1
    ok = len(al)

    while abs(ok-ng)>1:
        mid = (ok+ng)//2

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

al.sort()
bl.sort()
cl.sort()

res = 0
for b in bl:
    na = lower_bound(al, b)
    nc = n - lower_bound(cl, b+1)
    res += na*nc
print(res)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()


def bin_chisaimono(b):
    if a[0][0] >= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == n - 1 and a[0][pc] < b:
            return n
        elif a[0][pc] < b <= a[0][pc + 1]:
            return pc + 1
        elif a[0][pc] >= b:
            pr = pc - 1
        else:
            pl = pc + 1


def bin_okimono(b):
    if a[2][n - 1] <= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == 0 and a[2][pc] > b:
            return n
        elif a[2][pc - 1] <= b < a[2][pc]:
            return n - pc
        elif a[2][pc] <= b:
            pl = pc + 1
        else:
            pr = pc - 1


cnt = 0
for i in range(n):
    cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i])
print(cnt)

Submission status: Accepted

Solution code:

import sys

input = sys.stdin.readline
# coding: utf-8
# Your code here!
n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()

def bin_chisaimono(b):
    if a[0][0] >= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == n - 1 and a[0][pc] < b:
            return n
        elif a[0][pc] < b <= a[0][pc + 1]:
            return pc + 1
        elif a[0][pc] >= b:
            pr = pc -1
        else:
            pl = pc + 1


def bin_okimono(b):
    if a[2][n - 1] <= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == 0 and a[2][pc] > b:
            return n
        elif a[2][pc - 1] <= b < a[2][pc]:
            return n - pc
        elif a[2][pc] <= b:
            pl = pc + 1
        else:
            pr = pc - 1


cnt = 0
for i in range(n):
    cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i])
print(cnt)

Submission status: Accepted

Solution code:
def sup(A, j):
	if A[0] >= j:
		return 0
	l = 0
	r = len(A) - 1
	while True:
		i = (l+r) // 2
		if i == len(A) - 1 and A[i] < j:
			return len(A)
		elif A[i]<j and A[i+1]>=j:
			return i+1
		else:
			if A[i] >= j:
				r = i-1
			else: # A[i+1] < j
				l = i+1		

def inf(A, j): 
    if A[-1] <= j:
        return 0
    l = 0
    r = len(A) - 1
    while True:
        i = (l+r) // 2
        if i == 0 and A[i]>j:
            return len(A)
        elif A[i]>j and A[i-1]<=j:
            return len(A)-i
        else:
            if A[i] <= j:
                l = i+1
            else: # A[i-1] > j
                r = i-1		

N = int(input())
[A, B, C] = [sorted([int(i) for i in input().split()]) for j in range(3)]
ans = 0
for j in B:
	ans += sup(A, j) * inf(C, j)
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()
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

ba = [0]*N
for i in range(N):
	ba[i] = bisect_left(A, B[i])

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

ans = 0
for i in range(N):
	t = bisect_left(B,C[i])
	if t<=0:
		continue
	ans += ba[t-1]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = sorted(inpl())
b = sorted(inpl())
c = sorted(inpl())
x = [0] * n
for i in range(n):
    x[i] = bisect.bisect_left(a,b[i])
xx = [0] * (n+1)
xx[0] = 0
xx[1] = x[0]
for i in range(1,n):
    xx[i+1] = xx[i] + x[i] 
# print(x,xx)
res = 0
for i in range(n):
    tmp = bisect.bisect_left(b,c[i])
    res += xx[tmp]
print(res)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

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:
  a = bisect.bisect_left(A, b)
  c = bisect.bisect_right(C, b)

  ans += a * (len(C) - c)

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

ans = 0
# (i, j, k) -> Fix j

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
from bisect import bisect_right, bisect_left
n=int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()



cnt=0
for i in range(n):
    index_1 = bisect_left(a[0],a[1][i])
    index_2 = n-bisect_right(a[2],a[1][i])
    cnt+=index_1*index_2
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ba = [bisect_left(a, bi) for bi in b]
bc = [bisect_right(c, bi) for bi in b]
cnt = 0
for i in range(n):
    cnt += ba[i] * (n - bc[i])
print(cnt)

Submission status: Accepted

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

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:
    ans += bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
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()
ans = 0
for i in b:
    ans += bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
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(reverse=True)
C.sort()
#2分探索を用いる
ans = 0
for i in B:
    a = bisect.bisect_left(A,i)
    b = N - bisect.bisect_right(C,i)
    ans += a*b
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 i in B:
  a=bisect.bisect_left(A,i)
  b=N-bisect.bisect_right(C,i)
  ans+=a*b
print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
aList = sorted(list(map(int,input().split())))
bList = sorted(list(map(int,input().split())))
cList = sorted(list(map(int,input().split())))
#print("aList",aList)
#print("bList",bList)
#print("cList",cList)

count = 0
for i in bList:
  idxA = bisect.bisect_left(aList,i)
  idxC = bisect.bisect_right(cList,i)
#  print("idxA",idxA)
#  print("idxC",idxC)

  count += (idxA)*(n-idxC)
#  print("count",count)
print(count)

Submission status: Accepted

Solution code:
# ABC077c
from bisect import bisect_left
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

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:
    smallPos = bisect_left(a, i)
    BigPos = bisect_left(c, i+1)
    ans += smallPos*(n-BigPos)
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())))

nA = nC = 0
ans = 0
for i, b in enumerate(B):
    while nA<N and A[nA]< b: nA += 1
    while nC<N and C[nC]<=b: nC += 1
    ans += nA*(N-nC)

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

def binary_search(x, lst, l , r):
    while l < r:
        mid = (l + r) // 2
        mid_val = lst[mid]
        if x == mid_val:
            return mid - 1
        elif x < mid_val:
            r = mid - 1
        else:
            l = mid + 1
    else:
        return l

ans = 0
for i in range(N):
    max_ab = bisect.bisect_left(A, B[i])
    max_bc = N - bisect.bisect_right(C, B[i])
    ans += (max_ab * max_bc)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from bisect import bisect_left

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

Submission status: Accepted

Solution code:
import bisect

N = int(input(), 10)

heads = list(sorted(map(int,input().split())))
bodies = list(map(int,input().split()))
legs = list(sorted(map(int,input().split())))


cnt = 0
for body in bodies:
    #  頭は、体より小さくなければならない
    head_cnt = bisect.bisect_left(heads, body)
    #  足は、体より大きくなければならない
    leg_cnt = N - bisect.bisect_right(legs, body)

    cnt += head_cnt * leg_cnt # 組み合わせの掛け算

print(cnt)

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

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

Submission status: Accepted

Solution code:
import bisect

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

ans = 0
for b in li_b:
    aa = bisect.bisect_left(li_a, b)
    cc = len(li_c) - bisect.bisect_right(li_c, b)
    ans += aa * cc

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
import bisect
sys.setrecursionlimit(10 ** 7)

# 二分探索

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

'''
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)
'''

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

cntB = [0] * (N+1)

# Cを超えないBの累積和
for i in range(N):
    b = bisect.bisect_right(C, B[i])
    cntB[i+1] = cntB[i] + N - b


ans = 0
for i in range(N):
    a = bisect.bisect_right(B, A[i])
    c = cntB[N] - cntB[a]
    ans += c

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]
C = [int(z) for z in input().split()]
centertoover = [0] * N  # それを中段に置くと上段の組み合わせはいくつある？
undertocenter = [0] * N  # それを下段に置くと中段の組み合わせはいくつある？
sort_A = sorted(A)
sort_B = sorted(B)
sum = 0
sum_B = [0]*N
for i in range(N):
    sum += bisect.bisect_left(sort_A, sort_B[i])
    sum_B[i] += sum
ans = 0

for j in range(N):
    index = bisect.bisect_left(sort_B, C[j])
    if index != 0:
        ans += sum_B[index-1]

print(ans)
# print(sum_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()
c.sort()
ans=0

for i in range(n):
    ai=bisect_left(a,b[i])
    ci=bisect_right(c,b[i])
    ans+=ai*(n-ci)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from bisect import bisect_left

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
for i in range(N):
    x1 = bisect_left(A, B[i])
    x2 = bisect_right(C, B[i])
    # print(x1, x2, N)
    answer += x1 * (N - x2)

print(answer)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from bisect import bisect_left
 
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)
# from collections import defaultdict
# d = defaultdict(list)

# from itertools import combinations
# comb = combinations(range(N), 2)

# 累積和
from itertools import accumulate
# _list = list(accumulate(a_list)


def C(x, ub):
    return x < ub


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    a_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    b_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    c_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    a_list = sorted(a_list, reverse=True)
    b_list = sorted(b_list, reverse=True)
    c_list = sorted(c_list, reverse=True)

    total_count = 0
    i_b_upper = -1
    i_a_upper = -1

    b_count_list = None
    for c in c_list:
        if b_list[-1] >= c or a_list[-1] >= c:
            break
        i_b_lower = N

        while (i_b_lower - i_b_upper > 1):
            i_b_middle = (i_b_lower + i_b_upper) // 2
            if C(b_list[i_b_middle], c):
                i_b_lower = i_b_middle
            else:
                i_b_upper = i_b_middle

        if b_count_list is None:
            b_count_list = [0 for _ in range(N)]
            for i in range(i_b_lower, N):
                b = b_list[i]
                if a_list[-1] >= b:
                    break
                i_a_lower = N

                while (i_a_lower - i_a_upper > 1):
                    i_a_middle = (i_a_lower + i_a_upper) // 2
                    if C(a_list[i_a_middle], b):
                        i_a_lower = i_a_middle
                    else:
                        i_a_upper = i_a_middle

                b_count_list[i] = N - i_a_lower

                total_count += (N - i_a_lower)

            b_count_list = reversed(b_count_list)
            b_count_list = list(reversed(list(accumulate(b_count_list))))
        else:
            total_count += b_count_list[i_b_lower]

    print(total_count)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 5
2 4
3 6"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
1 1 1
2 2 2
3 3 3"""
        output = """27"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
        output = """87"""
        self.assertIO(input, output)


if __name__ == "__main__":
    unittest.main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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()]
import bisect
A.sort()
B.sort()
C.sort()
ans = 0
for i in B:
    idx_1 = bisect.bisect_left(A, i)
    idx_2 = N - bisect.bisect(C, i)
    ans += idx_1 * idx_2
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, 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 b in B:
  ans += bisect_left(A, b) * (N - bisect_right(C, b))

print(ans)