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

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

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 range(N):
  a=bisect.bisect_left(A,B[i])
  b=N-bisect.bisect_right(C,B[i])
  if b==0:
    break
  ans+=a*b
print(ans)

Submission status: Accepted

Solution code:
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()
C.sort()
ans = 0

for i in range(N):
  def meguru_bisect_A(ng, ok):
    def is_ok(idx):
      return A[idx] < B[i]

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

  def meguru_bisect_C(ng, ok):
    def is_ok(idx):
      return B[i] < C[idx]

    while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
        ok = mid
      else:
        ng = mid
    return ok
  
  ans += (meguru_bisect_A(N, -1)+1) * (N - meguru_bisect_C(-1, N))

print(ans)

Submission status: Accepted

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
B=list(map(int,input().split()))
B=sorted(B)
C=list(map(int,input().split()))
C=sorted(C)
count=0
for num in (B):
    a=bisect.bisect_left(A,num)
    b=bisect.bisect_right(C,num)
    count+=a*(N-b)

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

Submission status: Accepted

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    return N, A, B, C


def get_lb(l: list, key: int) -> int:
    """
    l[index] > keyとなる最小のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] > keyとなる最小のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess > key:
            high = mid
        else:
            low = mid
    return high


def get_ub(l: list, key: int) -> int:
    """
    l[index] < keyとなる最大のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] < keyとなる最大のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess < key:
            low = mid
        else:
            high = mid
    return low


def main(N: int, A: list, B: list, C: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): パーツの数
        A (list): 上部のパーツのサイズ
        B (list): 中部のパーツのサイズ
        C (list): 下部のパーツのサイズ
    """
    # 事前にリストをソートしておく
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    # 求解処理
    ans = 0
    for i in range(N):
        B_i = B[i]
        ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, A, B, C = get_input()

    # メイン処理
    main(N, A, B, C)

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

Submission status: Accepted

Solution code:
def binary_search_low(ls, v):
    """
    ・基準(v)より小さい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok+1
    
def binary_search_high(ls, v):
    """
    ・基準(v)より大きい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ng = -1
    ok = n

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


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_count = binary_search_low(A,b)
    b_count = binary_search_high(C, b)
    ans += a_count*b_count

print(ans)

Submission status: Accepted

Solution code:
def binary_search_low(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok  #, ng
    
def binary_search_high(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return ok


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_count = binary_search_low(A,b) + 1
    b_count = n - binary_search_high(C, b)
    #print(a_count,b_count)

    ans += a_count*b_count


print(ans)

Submission status: Accepted

Solution code:
def main():
    _ = 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_accum = []
    ans = 0

    for b in B:
        num = binary_search(A, b) + 1
        B_.append((b, num))

    tmp_sum = 0
    for b_ in B_:
        tmp_sum += b_[1]
        B_accum.append(tmp_sum)

    for c in C:
        b_idx = binary_search_tuple(B_, c)
        if b_idx >= 0:
            ans += B_accum[b_idx]
    print(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


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


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
for b in B:
    index_a = bisect.bisect_left(A, b)
    index_c = bisect.bisect_right(C, b)
    cnt += index_a * (n - index_c)

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

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_ind = bisect.bisect_left(A, b)
    c_ind = bisect.bisect_right(C, b)
    ans += a_ind*(n-c_ind)
    
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:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    #print("a:{0},c:{1}".format(a, c))
    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(reverse=True)
C.sort()
countA = [0]*(N+1)
countC = [0]*(N+1)

ans = 0
for b in range(N):
    countA = bisect.bisect_left(A, B[b])
    countC = N - bisect.bisect_right(C, B[b])
    ans += countA*countC
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:
    n_lower_B = bisect.bisect_left(A, b)
    n_higher_B = N - bisect.bisect_right(C, b)
    ans += n_lower_B * n_higher_B

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

ans = 0
C = len(c)

# Bを中心に考える
for i in b:
    ans += (bisect.bisect_right(a,i-1))*(C-bisect.bisect_left(c,i+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()))
a.sort()
b.sort()
c.sort()

ans = 0
C = len(c)

# Bを中心に考える
for i in b:
    ans += (bisect.bisect_right(a,i-1))*(C-bisect.bisect_left(c,i+1))

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect_right
n=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
    ans+=bisect_left(a,i)*(n-bisect_right(c,i))
print(ans)

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
C = [*map(int, input().split())]
A.sort()
C.sort()
ans = 0
for b in B:
    ia = bisect_left(A, b)
    ic = bisect_right(C, b)
    ans += ia * (n-ic)
print(ans)

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
C = [*map(int, input().split())]
A.sort()
C.sort()
# B.sort()
ans = 0
for b in B:
    ia = bisect_left(A, b)
    ic = bisect_right(C, b)
    # print('b:{:3d} ia:{:2d} ic:{:2d} ia*ic={:4d}'.format(b,ia,ic,ia*ic))
    # print('b:{:3d} ia:{:2d} ic:{:2d} ia*(n-ic)={:4d}'.format(b,ia,ic,ia*(n-ic)))
    ans += ia * (n-ic)
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:
  a = bisect.bisect_left(A,b)
  c = bisect.bisect_right(C,b)
  ans += a * (len(C)-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()
C.sort()
ans = 0

for b in B:
    if b <= A[0] or b >= C[N-1]:
        continue
    # Aに対して
    l, r = -1, N
    while abs(l - r) > 1:
        mid = (l + r) // 2
        if A[mid] < b:
            l = mid
        else:
            r = mid
    # Bに対して
    l2, r2 = -1, N
    while abs(l2 - r2) > 1:
        mid = (l2 + r2) // 2
        if C[mid] > b:
            r2 = mid
        else:
            l2 = mid
    ans += (l+1) * (N - r2)
print(ans)

Submission status: Accepted

Solution code:
import bisect
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 y in b:
    x = bisect.bisect_left(a, y)#挿入点はどの同じ値よりも左
    z = bisect.bisect_right(c, y) #挿入点はどの同じ値より右
    ans += x * (len(c) - z)#b<a * b > cの組み合わせ
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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 b in B:
    a = bisect.bisect_left(A, b)
    b = bisect.bisect_right(C, b)
    ans += a * (N - b)
    # print(a, b)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
    #B[i]より小さいAのインデックスを求める
    ok = -1#B[i]より小さい
    ng = N#B[i]より大きい
    while ng-ok>1:#
        mid = (ok + ng)//2
        if A[mid]<B[i]:
            ok = mid
        else:
            ng = mid
    
    #B[i]より大きいCのインデックスを求める
    ok2 = N
    ng2 = -1
    while ok2-ng2>1:
        mid2 = (ok2+ng2)//2
        if C[mid2] > B[i]:
            ok2 = mid2
        else:
            ng2 = mid2
    
    ans += (ok+1)*(N-ok2)

print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
aa = list(sorted(map(int, input().split())))
bb = list(sorted(map(int, input().split())))
cc = list(sorted(map(int, input().split())))

ans = 0
for b in bb:
    ax = bisect.bisect_left(aa, b)
    ci = bisect.bisect(cc, b)
    cx = len(cc) - ci
    ans += ax * cx
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.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    ans += a*(N-c)
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())))
cnt=0
for i in b:
  cnt+=bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]


#

n = iinput()
a = sorted(iarr())
b = sorted(iarr())
c = sorted(iarr())

cnt = 0
for bb in b:
    avar = bs.bisect_left(a,bb) #bbより小さいものたち
    cvar = n - bs.bisect_right(c,bb) #bb含めて除外
    cnt += avar * cvar
print(cnt)

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):
    ans += bisect_left(A, B[i]) * (n - bisect_right(C, B[i]))

print(ans)

Submission status: Accepted

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

# print(A)
# print(B)
# print(C)

A_B = []

for i in range(n):
    A_B.append(bisect_left(A, B[i]))

ruisekiwa = [A_B[0]]
for i in range(1, n):
    ruisekiwa.append(ruisekiwa[-1] + A_B[i])

# print(A_B)
# print(ruisekiwa)

ans = 0

for i in range(n):
    idx = bisect_left(B, C[i])
    if idx:
        ans += ruisekiwa[idx-1]

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    Cs = N - right

    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if A[mid] >= b:
            right = mid
        else:
            left = mid
    As = right
    ans += As * Cs
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

base = [0] * N
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    base[i] = N - right

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + base[i - 1]

ans = 0
for i, a in enumerate(A):
    left = -1
    right = N
    while right - left > 1:
        mid = left + (right - left) // 2
        if B[mid] > a:
            right = mid
        else:
            left = mid
    ans += acc[N] - acc[right]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
n = int(input())
al = sorted(list(map(int,input().split())))
bl = sorted(list(map(int,input().split())))
cl = sorted(list(map(int,input().split())))

ans = 0
for b in bl:
    # b未満の要素の個数
    a_cnt = bisect_left(al,b)
    # bより大きい要素の個数
    c_cnt = n - bisect_right(cl,b)
    ans += a_cnt*c_cnt

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
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()

ans = 0
for b in bl:
    # b未満の要素の個数
    a_cnt = bisect_left(al,b)
    # bより大きい要素の個数
    c_cnt = n - bisect_right(cl,b)
    ans += a_cnt*c_cnt

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()
lb = [0] * (len(B)+1)
lsum = [0] * (len(B)+1)
temp = 0
for i in range(len(B)):
    lb[i]= bisect.bisect_left(A,B[i])
    
for i in range(len(B)):
    lsum[i] = lb[i] +lsum[i-1]


ans = 0    
for i in range(len(C)):
    temp = bisect.bisect_left(B,C[i])
    ans +=lsum[temp-1]


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

Submission status: Accepted

Solution code:
import bisect
import itertools

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
bc = []
ans = 0
count = 0


for i in b:
  indc = bisect.bisect_right(c,i)
  bc.append((n - indc))
  count += 1

BC = [0] + list(itertools.accumulate(bc))

for i in a:
  indb = bisect.bisect_right(b,i)
  ans += BC[-1] - BC[indb]
   
print(ans)

Submission status: Accepted

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

ans = 0
for b in bl:
    a_num = bisect.bisect_left(al,b)
    c_num = n - bisect.bisect_right(cl,b)
    ans += a_num*c_num

print(ans)

Submission status: Accepted

Solution code:
import bisect


def 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)
    c = sorted(c)

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

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

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()
c.sort()
cnt = 0
for i in b:
    a_i = bisect.bisect_left(a,i)
    c_i = bisect.bisect_right(c,i)
    cnt += a_i * (n - c_i)
print(cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

num_fixed_b = [-1] * N
c_idx = 0
for b_idx, b in enumerate(B):
  while c_idx < N and C[c_idx] <= b:
    c_idx += 1
  num_fixed_b[b_idx] = N - c_idx

num_fixed_b = list(accumulate(num_fixed_b[::-1]))[::-1]
b_idx = 0
ans = 0
for a_idx, a in enumerate(A):
  while b_idx < N and B[b_idx] <= a:
    b_idx += 1
  if b_idx == N:
    print(ans)
    quit()
  ans += num_fixed_b[b_idx]

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
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:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    ans += a * (N-c)
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())))
sm=0
for j in B:
  sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j))
print(sm)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A, B, C = sorted(il()), sorted(il()), sorted(il())

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


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

ans = 0
for j in b:
    #aについてにぶたん
    left = -1
    right = n 
    while(right - left > 1):
        center = (right + left)//2
        if a[center]  < j:
            left = center
        else:
            right = center
    #cについてにぶたん
    l = -1
    r = n 
    while(r - l > 1):
        ce = (r+l)//2
        if c[ce] <= j:
            l = ce
        else:
            r = ce
    ans += right * (n - r)

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

#print(A)
#print(B)
#print(C)

ans = 0
for b in B:
    a = bisect.bisect_right(A, b-1)
    c = N - bisect.bisect_right(C, b)
    #print("smaller",a,"bigger",c)
    ans += a*c

print(ans)

Submission status: Accepted

Solution code:
import bisect
import itertools

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

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

ans = 0
dp = [0] * N
for i in range(N):
    up = A[i]
    middleIndex = bisect.bisect(B, up)
    if middleIndex < N:
        if i == 0:
            for j in range(middleIndex, N):
                middle = B[j]
                lowIndex = bisect.bisect(C, middle)
                if lowIndex < N:
                    cnt = N - lowIndex
                    dp[j] = cnt
                    ans += cnt
                else:
                    dp[j] = 0
            dp = list(itertools.accumulate(dp[::-1]))
        else:
            ans += dp[-middleIndex-1]

print(ans)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
# 20
# ABC077 C Snuke Festival

import bisect
import itertools

n = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]

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

bc_list = []
for i in range(n):
    _b = b_list[i]
    _idx = bisect.bisect_right(c_list, _b)
    bc_list.append(n-_idx)

ab_list = []
for i in range(n):
    _a = a_list[i]
    _idx = bisect.bisect_right(b_list, _a)
    ab_list.append(n-_idx)

bc_list.sort()
cumsum = list(itertools.accumulate(bc_list))

ans = 0
for i in range(n):
    if ab_list[i] == 0:
        continue
    ans += cumsum[ab_list[i]-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()

low = 0
high = len(A) -1

def check(mid, parts,key):
    if parts[mid] > key:
        return True
    return False
cnt = 0

# for a in A:
#
#     B_low = -1
#     B_high = len(B) - 1
#     b_cnt = 0
#     if a >= B[B_high]:
#         break
#     while B_high -B_low > 1:
#         mid = (B_high + B_low)//2
#
#         if check(mid, B, a):
#             B_high = mid
#             # b_cnt = _cnt
#
#         else:
#             B_low = mid
#     for b in B[B_high::]:
#         C_high = len(C) - 1
#         C_low = -1
#         c_cnt = 0
#         if b >= C[C_high]:
#             break
#         while C_high -C_low > 1:
#             mid = (C_high + C_low) //2
#             if check(mid,C ,b):
#                 C_high = mid
#             else:
#                 C_low= mid
#         # print(b, C_high, a)
#         # print(len(C[C_high::]))
#         cnt+=len(C[C_high::])

    # b_cnt = len(B) - B_high if B[B_high] > a  else 0
    # C_high = len(C) -1
    # C_low = -1
    # c_cnt = 0
    # if b_cnt >0:

    #     while C_high -C_low >1 :
    #         mid = (C_high + C_low )//2
    #         # _cnt = check(mid,C,B_high)
    #         if check(mid,C,B[B_high]):
    #             C_high  =mid
    #             # c_cnt = _cnt
    #         else:
    #             C_low = mid
    #     c_cnt = len(C) - C_high if C[C_high] > B[B_high] else 0
    # print(a,b_cnt,c_cnt)
    #
    # cnt += b_cnt * c_cnt



for b in B:
    A_low = -1
    A_high = len(A)
    while A_high - A_low > 1:
        mid = (A_high + A_low) //2
        if A[mid] < b:
            A_low = mid
        else:
            A_high = mid

    a_cnt =  A_low + 1
    C_low = -1
    C_high = len(C)
    while C_high - C_low > 1:
        mid = (C_high + C_low) //2
        if C[mid] > b:
            C_high = mid
        else:
            C_low = mid
    c_cnt = len(C) - C_high

    cnt += a_cnt * c_cnt
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import bisect
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a,b[i])
    y = n - bisect.bisect_right(c,b[i])
    ans += (x*y)

print(ans)