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

BtoA=[]
for b in B:
    BtoA.append(bisect(A,b))

#累積和
sum_BtoA=[BtoA[0]]
for i in range(n-1):
    sum_BtoA.append(sum_BtoA[i]+BtoA[i+1])


#CtoB=[]
#for callable in range(n):
#    CtoB.append(bisect(B,C[i]))
#
##累積和
#sum_CtoB=[CtoB[0]]
#for i in range(n-1):
#    sum_CtoB.append(sum_CtoB[i]+CtoB[i+1])

ans=0
for c in C:
    index=bisect(B,c)
    if index>0:
        ans+=sum_BtoA[index-1]

print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(int(T) for T in input().split())
B = sorted(int(T) for T in input().split())
C = sorted(int(T) for T in input().split())
Count = 0
for TB in B:
    SmallA = bisect.bisect_left(A,TB)
    BigC   = N-bisect.bisect_right(C,TB)
    Count += SmallA*BigC
print(Count)

Submission status: Accepted

Solution code:
import bisect 
from itertools import accumulate

N = int(input())
a = sorted([int(i) for i in input().split()])  #;print(a)
b = sorted([int(i) for i in input().split()])  #;print(b)
c = sorted([int(i) for i in input().split()])  #;print(c)

bc = [0] * N 
for i in range(N):
    bc[i]= N - bisect.bisect_right(c, b[i])
bcA = [0] + list(accumulate(bc))               #; print(bc); print(bcA)

cnt = 0
for i in range(N):
    x = bisect.bisect_right(b, a[i])            
    cnt += bcA[-1] - bcA[x]                    #; print(a[i], x, bcA[-1] - bcA[x]) 

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

ans = 0

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

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

# にぶたんで数えていく
cnt = 0

B_cnt = [0]*N

for i in range(N):
    ok = bisect.bisect_right(C, B[i])
    B_cnt[i] = N-ok

B_cum = [0]*N
B_cum[-1] = B_cnt[-1]

for i in range(N-1, 0, -1):
    B_cum[i-1] = B_cum[i]+B_cnt[i-1]

B_cum.append(0)

for i in range(N):
    cnt += B_cum[bisect.bisect_right(B, A[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()
sm = 0
for i in b:
    target = i
    a_idx = bisect.bisect_left(a,target)
    c_idx = bisect.bisect_right(c,target)
    sm += a_idx * (n-c_idx)

print(sm)

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()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search1(list,item):
    low = 0
    high = len(list) - 1

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

def binary_search2(list,item):
    low = 0
    high = len(list) - 1

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

ans=0
#print(a,b,c)
for i in range(n):
    #print(binary_search1(a,b[i]),binary_search2(c,b[i]),i)
    ans+=binary_search2(c,b[i])*binary_search1(a,b[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 = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    ia = bisect.bisect_left(A, b)
    ic = len(C) - bisect.bisect(C, b)
    ans += ia * ic

print(ans)

Submission status: Accepted

Solution code:
#この問題のポイント一つ目　３つ動くときは真ん中を固定する
#真ん中を固定したら下の段からはそれより小さいもの、上の段はそれより大きいものを選べる
#上の段と下の段をsortするとある境界を境にokとngがはっきり分かれる
#二部探索
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()
from bisect import bisect_left
from bisect import bisect_right
ans=0
for i in range(n):
  #b[i]を固定する
  ans=ans+bisect_left(a,b[i])*(n-bisect_right(c,b[i]))

  
print(ans)

Submission status: Accepted

Solution code:
import bisect

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
  B = b_li[i]
  k = n - bisect.bisect_right(c_li,B)
  l = bisect.bisect_left(a_li,B)
  ans += k*l
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

def isAok(a, b):
    return True if a < b else False

def isCok(b, c):
    return True if c > b else False


for b in B:
    left = -1
    right = N
    while right-left > 1:
        mid = left + (right-left)//2
        if isAok(A[mid], b):
            left = mid
        else:
            right = mid
    acnt = left + 1

    left = -1
    right = N
    while right-left > 1:
        mid = left
        mid = left + (right-left)//2
        if isCok(b, C[mid]):
            right = mid
        else:
            left = mid
    ccnt = N-right
    ans += acnt * ccnt
print(ans)

Submission status: Accepted

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

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.sort()
    b.sort()
    c=[-x for x in c]
    c.sort()
    print(sum(bisect_left(a,x)*bisect_left(c,-x) for x in b))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:

import sys
from heapq import heapify,heappop,heappush
from collections import defaultdict
read=sys.stdin.read
readline=sys.stdin.readline

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.sort()
    b.sort()
    c=[-x for x in c]
    c.sort()

    def bise(x,lst):
        left=0
        right=len(lst)
        while right-left>0:
            mid=(right+left)//2
            if lst[mid]>=x:
                right=mid
            else:
                left=mid+1
        return left
    print(sum(bise(x,a)*bise(-x,c) for x in b))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import bisect as bs

n = int(input())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for b in b_l:
    ans += bs.bisect_left(a_l,b) * (n-bs.bisect_right(c_l,b))
print(ans)


'''
以下の方法だと、N*logN*logN
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
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())))

comb = 0
mid_start = 0

while mid_start < N:
    mid_value = B[mid_start]
    mid_end = bisect.bisect_right(B,mid_value)
    mid_num = mid_end - mid_start
    top_end = bisect.bisect_left(A,mid_value)
    top_num = top_end
    bottom_start = bisect.bisect_right(C,mid_value)
    bottom_num = N - bottom_start
    comb += top_num * mid_num * bottom_num
    mid_start = mid_end

print(comb)

Submission status: Accepted

Solution code:
n = int(input())
#k, x = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
import bisect
al.sort();bl.sort();cl.sort()
ans=0
for bi in bl:
    c1 = bisect.bisect_right(al, bi-1)
    c2 = n-bisect.bisect_left(cl, bi+1)
    ans += c1*c2
print(ans)

Submission status: Accepted

Solution code:
def bs_left(lists, item):
    low, high = 0, len(lists)
    
    while (high >low ) :
        mid = (low + high)//2
        if lists[mid]  < item:
            low = mid +1
            
        else:
            high = mid
            
    return low

def bs_right(lists, item):
    low, high = 0, len(lists)
    
    while (high >low ):
        mid = (low + high)//2
        if lists[mid] > item:
            high = mid 
            
        else:
            low = mid+1
            
    return len(lists) - low
  
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()]

count = 0
A.sort(), B.sort(), C.sort()
for b in B:
    count += (bs_left(A, b) * bs_right(C, b))
    
print(count)

Submission status: Accepted

Solution code:
from bisect import bisect_left

N = int(input())

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

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

B_count = [0]*N
A_count = [0]*N

for i in range(N):
    B_count[i]=bisect_left(C,B[i])

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

for i in range(N):
    A_count[i]= B_count[bisect_left(B,A[i])]

print(sum(A_count))

Submission status: Accepted

Solution code:
"""
入力
"""
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

"""
ライブラリ
"""

"""
処理
"""
a.sort()
b.sort()
c.sort()

total = 0
import bisect
for _b in b:
    n_a = bisect.bisect_left(a, _b)
    n_c = n - bisect.bisect_right(c, _b)
    total += n_a * n_c
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()
a_pt=0;b_pt=0;c_pt=0
ci=0;bi=0;ai=0
while ci < len(c):
  cc=c[ci]
  while bi <len(b):
    bb=b[bi]
    if bb>=cc:
      break
    while ai<len(a):
      aa=a[ai]
      if aa>=bb:
        break
      a_pt+=1
      ai+=1
    b_pt+=a_pt
    bi+=1
  c_pt+=b_pt
  ci+=1

print(c_pt)

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 b in B:
    
    c_num = len(C)-bisect.bisect_left(C,b+1)
    a_num = bisect.bisect_right(A,b-1)
    count+=c_num*a_num

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lenc=len(C)

from bisect import *

cnt=0
for b in B:
    in_a = bisect_left(A, b)
    in_c = bisect_right(C, b)
    cnt+= in_a*(lenc-in_c)

print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a

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()
# print(A)
# print(B)
# print(C)

total = 0
for b in B:
    c1 = bisect_right(A, b - 1)
    c2 = N - bisect_left(C, b + 1)
    # print(b, c1, c2, c1 * c2)
    total += c1 * c2

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

"""
前処理で中部に大きさb以下のパーツを使える場合の組み合わせの数を計算しておく。
"""

tmp1 = [0]
for b in B:
    a = bisect_left(A,b)
    tmp1.append(tmp1[-1]+a)

tmp2 = 0
for c in C:
    idx = bisect_left(B,c)
    tmp2 += tmp1[idx]
print(tmp2)

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):
    t = b[i]
    ci = bisect.bisect_right(c,t)
    ai = bisect.bisect_left(a,t)
    ans += ai*(n-ci)
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()

cnt = 0

for b_e in b:
    a_cases = bisect_left(a, b_e)
    c_cases = bisect_right(c, b_e)
    cnt += a_cases * (n - c_cases)
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

an.sort()
bn.sort()
cn.sort()

cnt = 0

for b in bn:
    a = bisect_left(an,b)
    c = bisect_right(cn,b)
    cnt += a * (n-c)
print(cnt)

Submission status: Accepted

Solution code:
import bisect

ans =0

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

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
mod = 10**9+7

if __name__ == "__main__":
    n = int(input())
    A = sorted(list(map(int,input().split())))
    B = sorted(list(map(int,input().split())))
    C = sorted(list(map(int,input().split())))
    ans = 0
    for b in B:
        a = bisect.bisect_left(A,b)
        c = n - bisect.bisect_left(C,b+1)
        ans += a*c
    print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

a_li.sort()
b_li.sort()
c_li.sort()

ans = 0

for i in b_li:
    s = bisect.bisect_right(c_li, i)
    s_num = n-s
    
    t = bisect.bisect_left(a_li, i)
    t_num = t
    
    ans += s_num * t_num

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import bisect
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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


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())))
#print(A)
#print(B)
#print(C)

ans = 0

for i in B:
  a_num = bisect.bisect_left(A,i)
  c_num = bisect.bisect(C,i)
  ans += a_num*(N-c_num)


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)
  C=bisect.bisect(c,i)
  ans+=A*(n-C)
print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  #startline-------------------------------------------
    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()
    ans = 0
    for i in range(n):
        a_left = bisect.bisect_left(a, b[i])
        c_right = bisect.bisect_right(c, b[i])
        ans += (a_left*(n-c_right))
    print(ans)
        
        
    
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
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()
cl.sort()
s=0
for b in bl:
    a=bisect_left(al,b)
    c=n-bisect_right(cl,b)
    s+=a*c
print(s)

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):
  ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[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 m in b:
    l_idx = bisect.bisect_left(a, m)
    u_idx = bisect.bisect_right(c, m)
    ans += l_idx * (n - u_idx)

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.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)

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

for i in B:
    num_A = bisect.bisect_left(A, i)
    num_B = bisect.bisect_right(C, i)
    ans += num_A * (N - num_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
for i in b:
  ans+=bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
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()

res = 0
for j in b:
  res += bisect_left(a, j) * (n - bisect_right(c, j))
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    l = -1
    r = N
    while (r-l) > 1:
        mid = (r+l)//2
        if A[mid] < b:
            l = mid
        else:
            r = mid
    top = l+1
    l = -1
    r = N
    while (r-l) > 1:
        mid = (r+l)//2
        if C[mid] <= b:
            l = mid
        else:
            r = mid
    bottom = N-r
    ans += top*bottom
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools
import math
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 bi in B:
    res += bisect.bisect_left(A, bi) * (N-bisect.bisect_right(C, bi))
print(res)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in b:
    ans += (n - bisect_right(c, j))*bisect_left(a, j)
print(ans)

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import heapq
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()))

    sA = sorted(A)
    sC = sorted(C)

    res = 0
    for b in B:
        a = bisect.bisect_left(sA, b)
        c = N - bisect.bisect_right(sC, b)
        res += a*c

    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(cnt)

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:
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 is_ok(mid, array, n):  return array[mid] > n
 
def binary_search(left, right, array, n):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid, array, n):  right = mid
        else:  left = mid
    return right
 
ans = 0
BtoC = [N - binary_search(-1, N, C, B[i]) for i in range(N)]
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[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.sort()
B.sort()
C.sort()

def is_ok(mid, array, n):  return array[mid] > n

def binary_search(left, right, array, n):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid, array, n):  right = mid
        else:  left = mid
    return right

ans = 0
BtoC = []
for i in range(N):
    ret = binary_search(-1, N, C, B[i])
    if ret != N:
        BtoC.append(N - ret)
    else:
        BtoC.append(0)
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[i])]
print(ans)

Submission status: Accepted

Solution code:
import bisect

N=int(input())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
L3=list(map(int,input().split()))

L1.sort()
L2.sort()
L3.sort()

ans=0
for l2 in L2:
    l1_idx=bisect.bisect_left(L1,l2)
    l3_idx=bisect.bisect_right(L3,l2)
    
    ans+=l1_idx*(N-l3_idx)
print(ans)

Submission status: Accepted

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

cnt = [0] * n
for i in range(n):
    cnt[i] = n - bisect_right(c, b[i])

cnt = [0] + list(accumulate(cnt[::-1]))
cnt.reverse()

ans = 0
for i in range(n):
    ans += cnt[bisect_right(b, a[i])]

print(ans)

Submission status: Accepted

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

cnt = [0] * n
for i in range(n):
    cnt[i] = n - bisect_left(c, b[i] + 1)

cnt = [0] + list(accumulate(cnt[::-1]))
cnt.reverse()

ans = 0
for i in range(n):
    ans += cnt[bisect_left(b, a[i] + 1)]

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
 
n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
 
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 i in range(N):
    b=B[i]
    a=bisect.bisect_left(A,b)
    c=bisect.bisect_right(C,b)
    ans+= a*(N-c)

print(ans)