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

sum = 0
for j in range(n):
  atemp = bisect.bisect_left(a, b[j])
  ctemp = n - bisect.bisect_right(c, b[j])
  sum += atemp * ctemp

print(sum)

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() ) )
# print(d,n,m)
# print(A_list)
# print(B_list)
# print(C_list)

A_sort = sorted(A_list)
C_sort = sorted(C_list)

# print("A:", A_sort)
# print("C:", C_sort)

def is_ok_lower(list_data, index: int, key: int):
    if (list_data[index] >= key):
        return True
    else:
        return False

def is_ok_upper(list_data, index: int, key: int):
    if (list_data[index] > key):
        return True
    else:
        return False


def binary_search(list_data, key: int, is_ok_func):
    ng = -1  #「index = 0」が条件を満たすこともあるので、初期値は -1
    ok = len(list_data) # 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    # どんな二分探索でもここの書き方を変えずにできる！
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2

        if (is_ok_func(list_data, mid, key)):
            ok = mid
        else:
            ng = mid

    # left は条件を満たさない最大の値、ok は条件を満たす最小の値になっている
    return ok

sum_conbi = 0
for B in B_list:
    a_key = binary_search(A_sort, B, is_ok_lower)
    c_key = binary_search(C_sort, B, is_ok_upper)

    # print(a_key, N-c_key)
    # print(B,">", A_sort[:a_key])
    # print(B,"<", C_sort[c_key:])

    sum_conbi += (a_key) * (N-c_key)

print(sum_conbi)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    # 最大値 + 1を設定
    INF = N + 1
    A.sort()
    B.sort()
    C.sort()
    
    # True - ok - ng - False
    def is_ok(mid: int, b: int):
        # 判定する条件
        if mid < 0:
            return True
        elif mid >= N:
            return False
        return A[mid] < b
    
    # False - ng - ok - True
    def is_ok2(mid: int, b: int):
        # 判定する条件
        if mid < 0:
            return False
        elif mid >= N:
            return True
        return C[mid] > b

    def binSearch(ok: int, ng: int, b: int):
        #print(ok, ng)
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid, b):
                ok = mid
            else:
                ng = mid
            #print(ok, ng)
        return ok

    def binSearch2(ok: int, ng: int, b: int):
        #print(ok, ng)
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok2(mid, b):
                ok = mid
            else:
                ng = mid
            #print(ok, ng)
        return ok
    
    sum = 0
    for b in B:
        a = binSearch(-1, INF, b) - 0 + 1
        c = N - 1 - binSearch2(INF, -1, b) + 1
        sum += a * c
        #print(b, "->", a, c)
    print(sum)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import math
from queue import Queue
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()

sum = 0
for i in range(n):

    atemp = bisect.bisect_left(a,b[i])
    ctemp = n - bisect.bisect_right(c,b[i])
    sum += atemp * ctemp

print(sum)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
tops = sorted(tuple(map(int, input().split(' '))))
middles = sorted(tuple(map(int, input().split(' '))))
bottoms = sorted(tuple(map(int, input().split(' '))))

s = 0

for middle in middles:
    n_tops = bisect.bisect_left(tops, middle)
    n_bottoms = len(bottoms) - bisect.bisect_right(bottoms, middle)
    s += n_tops * n_bottoms

print(s)

Submission status: Accepted

Solution code:
def search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        e = search(a, B)
        if e < N:
            ans += E[e]
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    E = [0]*N
    for i in range(1, N+1):
        E[-i] = (N-search(B[N-i], C)) + E[-i+1]
    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())))
cnt = 0
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    cnt += a * (n-c)
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect
from itertools import accumulate
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    b.sort()
    c.sort()
    ainb = [bisect(b, ea) for ea in a]
    bc = [n - bisect(c, eb) for eb in b]
    bcaccum = tuple(accumulate(bc))
    tr = 0
    for eainb in ainb:
        if eainb != 0:
            tr += bcaccum[eainb - 1]
    r = bcaccum[-1] * n - tr

    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

ans = 0
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()


#A<B<Cの組み合わせの数が答え
for i in range(N):
    #Bを1つ決めた時、AがB未満の場合の総数
    B_miman = bisect.bisect_left(A,B[i])
    #Bを1つ決めた時、CがB以上の場合の総数
    B_ijou = N - bisect.bisect_right(C, B[i])

    ans+= B_miman*B_ijou

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = sorted(LIST())
B = sorted(LIST())
C = sorted(LIST())

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

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.append(10 ** 10)
B.append(10 ** 10)
C.append(10 ** 10)

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

i, j, k = 0, 0, 0
count = 0
total = 0
result = 0

while i < N:
    while C[i] > B[j] and j < N:
        while B[j] > A[k] and k < N:
            count += 1
            k += 1
        total += count
        j += 1
    result += total
    i += 1

print(result)

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 mybisectl(mylist, mytarget):
  if mytarget <= mylist[0]:
    return 0
  mylen = len(mylist)
  if mylist[mylen-1] < mytarget:
    return mylen
  L, R = 0, len(mylist)
  while R-L > 0:
    mid = (R+L) //2
    mymid = mylist[mid]
    mymidl = mylist[mid-1]
    if (mymidl < mytarget) and (mytarget <= mymid):
      return mid
    else:
      if mytarget <= mymidl:
        R = mid
      else:
        L = mid

B_kinds = [0] + [mybisectl(A, B[i]) for i in range(N)]
for i in range(N):
  B_kinds[i+1] += B_kinds[i]

ans = 0
for i in range(N):
  ans += B_kinds[mybisectl(B, C[i])]

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

for x in b:
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc

print(ans)

Submission status: Accepted

Solution code:
"""
前処理で下記のようなメモを作っておく必要がある。
candidate[j] -> 昇順ソートされたBの中でインデックスj以降のパーツを使えるときに、考えられるB,Cの組み合わせの数。
candidateリストを作成するためにまずは、下記のmemoを用意して、その総和としてcandidateを作成する。
memo[j] -> Bの中のインデックスjのパーツを使った場合に使用可能なCの数。
"""

def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

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

    memo = [0]*(N)
    for j in range(N):
        b = B[j]
        cIdx = bisect(C,b)
        memo[j] = N-cIdx
    candidate = [0]*(N)
    candidate[-1] = memo[-1]
    for j in range(N-2,-1,-1):
        candidate[j] += candidate[j+1]+memo[j]

    ans = 0
    for a in A:
        bIdx = bisect(B,a)
        if bIdx < N:
            ans += candidate[bIdx]

    print(ans)
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.sort()
B.sort()
C.sort()
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  left2 = -1
  right2 = N
  while right2-left2>1:
    mid2 = left2 + (right2-left2)//2
    if C[mid2]>B[i]:
      right2 = mid2
    else:
      left2 = mid2
  total+=right*(N-right2)
print(total)

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 = [0]*N
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  AB[i]=right
for i in range(1,N):
  AB[i]+=AB[i-1]
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if B[mid]>=C[i]:
      right = mid
    else:
      left = mid
  if right!=0:
    total+=AB[right-1]
print(total)

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

total = 0

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

print(total)

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

b_cn = [0] * n

for i, val in enumerate(b):
    index = bisect.bisect_right(c, val)
    b_cn[i] = n - index

b_rui = [0] * (n + 1)

for i in range(n):
    b_rui[i+1] = b_rui[i] + b_cn[i]

ret = 0

for item in a:
    index = bisect.bisect_right(b, item)
    ret += b_rui[-1] - b_rui[index]

print(ret)

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

Submission status: Accepted

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

N = int(readline())
A = list(map(int,input().split()))
#A = []  
#[bisect.insort_right(A, x) for x in tmp]
B = list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

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

listb = []
for i , b in enumerate(B[::-1]):
    if i == 0:
        listb.append(N - bisect.bisect_right(C,b))
    else:
        listb.append(N - bisect.bisect_right(C,b) + listb[i-1])

ans = 0
for a in A :
    indexb = bisect.bisect_right(B,a)
    if indexb == N :
        break
    ans += listb[N-1 - indexb]

print(ans)

Submission status: Accepted

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

N = int(readline())
A = list(map(int,input().split()))
#A = []  
#[bisect.insort_right(A, x) for x in tmp]
B= list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

A.sort()
C.sort()

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

print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

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

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-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())))
ans = 0
for j in range(N):
    ans += bisect.bisect_left(A, B[j]) * (N - bisect.bisect_right(C, B[j]))
print(ans)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 077 C - Snuke Festival　

import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)


def search(i, S):  # i : search する数値  S: search対象の数列　　大きいものの個数を返す
    if S[0] > i:
        return len(S)
    if S[-1] <= i:
        return 0

    left = 0
    right = len(S) - 1

    while right - left != 1:
        # print(f'right:{right}, left:{left}')
        mid = int((left + right) / 2)
        if S[mid] <= i:
            left = mid
        else:
            right = mid

    return len(S) - (left + 1)


def search1(i, S):  # i : search する数値  S: search対象の数列  小さいものの個数を返す
    if S[0] >= i:
        return 0
    if S[-1] < i:
        return len(S)

    left = 0  # 満たす
    right = len(S) - 1  # 満たさない

    while right - left != 1:
        mid = int((left + right) / 2)
        if S[mid] < i:
            left = mid
        else:
            right = mid

    return left + 1


ans = 0
for b in B:
    ans_a = search1(b, A)
    ans_c = search(b, C)

    ans += ans_a * ans_c

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

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)

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

import bisect
ans = 0

a2b = []
c2b = []
for b in B:
    i = N - bisect.bisect_right(C, b)

    #例えば，C＝「13344」のとき，b=3とする，n=5なので，2になってほしい
    #bisect.bisect_right(C, b)＝3になるので，c＿bisect＝N-bisect.bisect_right(B, c)

    #例えば，C＝「133344」のとき，b=3とする，n=6なので，2になってほしい
    #bisect.bisect_right(C, b)＝4になるので，c＿bisect＝N-bisect.bisect_right(B, c)=2
    
    j = bisect.bisect_left(A, b)
    #例えば，A＝「13344」のとき，b=3とする，n=5なので，1になってほしい
    #bisect.bisect_left(A, b)＝1になるので，c＿bisect＝bisect.bisect_left(A, b)
    
    
    #例えば，A＝「113344」のとき，b=3とする，n=6なので，2になってほしい
    #bisect.bisect_left(A, b)＝2になるので，c＿bisect＝bisect.bisect_left(A, b)
    ans += i*j
    #print(i,j,i*j)
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=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def meguru_a(bi):
    ng=n+1 ; ok=0
    while (abs(ok - ng) > 1): 
        mid = (ok + ng) // 2
        if a[mid] < bi :
            ok = mid
        else:
            ng = mid
    return ok

def meguru_c(bi):
    ng=-1 ; ok=n
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if bi < c[mid+1]:
            ok = mid
        else:
            ng = mid
    return ok

altar=0

for bi in b:
    s=meguru_a(bi)*(n - meguru_c(bi))
    altar+=s
print(altar)

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

Submission status: Accepted

Solution code:
import bisect

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

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:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

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

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-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=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def bin_search_a(a,b):
    low=0
    high=len(a)-1
    while low<=high:
        mid=(low+high)//2
        if a[mid] < b <= a[mid+1]:
            return mid
        if a[mid] >= b:
            high=mid-1
        else:
            low=mid+1
    
def bin_search_c(c,b):
    low=0
    high=len(c)-1
    while low<=high:
        mid=(low+high)//2
        if c[mid] <= b < c[mid+1]:
            return mid
        if c[mid] > b:
            high=mid-1
        else:
            low=mid+1

altar=0

for bi in b:
    s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
    altar+=s
print(altar)

Submission status: Accepted

Solution code:
def binary_search_1(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if data[mid] < value:
      l = mid + 1
    else:
      r = mid
  return l  

def binary_search_2(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if value < data[mid]:
      r = mid 
    else:
      l = mid + 1
  return l  
  
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 +=(binary_search_1(a,i)*(len(c)-binary_search_2(c,i)))

print(cnt)

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

count = 0
for j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect(C, B[j])
    count += (i * (n - k))

print(count)

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

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

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:
    ac=bisect.bisect_right(al,b-1)
    cc=n-bisect.bisect_left(cl,b+1)
    ans+=ac*cc
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()

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

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

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():
    import bisect
    n = int(input())
    a_lis = list(map(int, input().split()))
    b_lis = list(map(int, input().split()))
    c_lis = list(map(int, input().split()))
    a_lis.sort()
    b_lis.sort()
    c_lis.sort()
    cnt = 0

    for b in b_lis:
        a = bisect.bisect_left(a_lis, b)
        c = n - bisect.bisect_right(c_lis, b)
        cnt += a * c

    print(cnt)
        


    


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

import bisect
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(len(b)):
    ab = bisect.bisect_right(a,b[i]-1) # b[i]より真に小さいaの要素数
    bc = len(c) - bisect.bisect_left(c,b[i]+1) # b[i]より真に大きいcの要素数
    ans += ab*bc
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.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        ans += bisect.bisect_left(A, B[i]) * (N - bisect.bisect_right(C, B[i]))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
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 range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)

Submission status: Accepted

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

def resolve():
    import bisect
    n=int(input())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lc=list(map(int,input().split()))
    la.sort()
    lb.sort()
    lc.sort()
    ans=0
    for i in lb:
        ans1=bisect.bisect_left(la,i)
        ans2=len(lc)+-bisect.bisect_right(lc,i)
        ans+=ans1*ans2
    print(ans)
resolve()

Submission status: Accepted

Solution code:
#ABC077C
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()))
    if n==1:
        if a<b and b<c:
            print(1)
        else:
            print(0)
    else:
        a.sort()
        b.sort()
        c.sort()
        aList=[0]*n
        bList=[0]*n
        bListSum=[0]*n
        for i in range(n):
            aList[i]=bisect.bisect_right(b,a[i])
            bList[i]=n-bisect.bisect_right(c,b[i])
        bListSum[n-1]=bList[n-1]
        for i in range(n-2,-1,-1):
            bListSum[i]=bListSum[i+1]+bList[i]
        ans=0
        for i in range(n):
            if aList[i]<n:
                ans+=bListSum[aList[i]]
        print(ans)
if __name__=="__main__":
    main()

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

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

print(cnt)

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 = len(C) - bisect.bisect_right(C, b)
    ans += a * c

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()
total = 0
for num in b:
    a_pos = bisect_left(a, num)
    c_pos = bisect_right(c, num)
    total += a_pos * (len(c) - c_pos)
print(total)

Submission status: Accepted

Solution code:
# ABC 077
import bisect

N = int(input())
A = sorted([int(j) for j in input().split()])
B = sorted([int(j) for j in input().split()])
C = sorted([int(j) for j in input().split()])
ans = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = N - bisect.bisect_right(C,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()
ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    ans += i*(n-j)
print(ans)