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()
B.sort()
C.sort()
total=0
for j in range(N):
    b=B[j]
    p_a=bisect.bisect_left(A,b)
    p_b=bisect.bisect_right(C,b)
    total+=p_a*(N-p_b)
print(total)

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

from bisect import bisect_left, bisect_right
ans = 0
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    ans += ai * (N-ci)
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 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 j in range(n):
    i = bisect.bisect_left(a, b[j])
    k = n - bisect.bisect_right(c, b[j])
    ans += i * k
print(ans)

Submission status: Accepted

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

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

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] >= b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    i.append(a_mid + 1)
    
for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
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()

bc = [0]*n
bc[n-1]=n-bisect.bisect_right(c, b[n-1])

for i in range(0,n-1):
  bc[n-2-i]=bc[n-1-i] + n-bisect.bisect_right(c, b[n-2-i])

ans = 0
for i in range(n):
  temp = bisect.bisect_right(b, a[i])
  if temp != n:  
    ans += bc[temp]
  
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(arg, target, abc):
    if abc[arg] >= target:
        return True
    else:
        return False

def is_ok2(arg, target, abc):
    if abc[arg] > target:
        return True
    else:
        return False


def bict(left, right, target, abc, jug):

    while(right - left > 1):
        mid = (right + left)//2

        if jug(mid, target, abc):
            right = mid
        else:
            left = mid

    return right

cnt = 0
for b in B:
    a_min_index = bict(-1, N, b, A, is_ok)
    c_min_index = bict(-1, N, b, C, is_ok2)
    temp = (a_min_index - 1 + 1) * (N - c_min_index)
    cnt += temp

print(cnt)

Submission status: Accepted

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

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

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

    ans = 0

    for i in range(n):
        k = B[i]
        a = bisect.bisect_left(A,k)
        c = n-bisect.bisect_right(C,k)
        ans += a*c
        
    return ans


if __name__ == "__main__":
    print(slove())

Submission status: Accepted

Solution code:
#ABC077C
def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    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()
    B.sort()
    C.sort()
    #print(A)
    #print(B)
    #print(C)
    ans = 0
    for b in B:
        a = bisect.bisect_left(A, b)
        b = N-bisect.bisect_right(C, b)
        ans +=a*b
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return [ok, ng]

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:
    x = bisect(a, lambda x:x < i, -1, n)[0]
    y = bisect(c, lambda x:x > i, n, -1)[0]
    ans += (x+1)*(n-y)

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = list(map(int, input().split()))
    C = sorted(list(map(int, input().split())))
    ans = 0
    for b in B:
        ans += bisect_left(A, b) * (n - bisect_right(C, b))
    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()


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

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
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()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)

Submission status: Accepted

Solution code:
import bisect
from itertools import accumulate
n, *ABC = map(int, open(0).read().split())
A, B, C = ABC[:n], ABC[n:2*n], ABC[2*n:3*n]
A.sort()
B.sort()
C.sort()
D = [bisect.bisect_left(A, b) for b in B]
E = [bisect.bisect_left(B, c) for c in C]
F = list(accumulate(D))
s = 0
for e in E:
    if e != 0:
        s += F[e-1]
print(s)

Submission status: Accepted

Solution code:
import bisect
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt += bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)

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

# 上に載せられるピースの組み合わせ数 * 下におけるピースの組み合わせ数
ans = 0

for i in range(N):
    upper = bisect_left(A, B[i])
    lower = N - bisect_right(C, B[i])
    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=sorted(a)
for i in range(n):
    c[i]=-c[i]
c=sorted(c)

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

alist.sort()
blist.sort()
clist.sort()

ans = 0

for i in blist:
    a = bisect.bisect_left(alist,i)
    b = len(clist) - bisect.bisect_right(clist,i)
    ans += a*b
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

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

    ret = 0
    for b in B:
        ia = bisect_left(A,b)
        ic = bisect_right(C,b)
        ret += ia*(N-ic)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import bisect

m=0
d=[0 for i in range(n)]
for i in range(n):
    y=bisect.bisect_right(c,b[n-1-i])
    m+=n-y
    d[n-1-i]=m

m=0
for i in a:
    x=bisect.bisect_right(b,i)
    try :
        m+=d[x]
    except IndexError:
        pass
    
print(m)

Submission status: Accepted

Solution code:
import sys
import bisect
import numpy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A = sorted(A)
B = sorted(B)

ans = 0
ind_list = []
for b in B:
  index = bisect.bisect_left(A,b)
  ind_list.append(index)
  
res = numpy.cumsum(ind_list)
for c in C:
  index = bisect.bisect_left(B,c)
  if index == 0:
    continue
  ans += res[index-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 i in b:
    x=bisect.bisect_left(a,i)
    y=n-bisect.bisect_right(c,i)
    ans+=x*y
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
    he=-1
    ta=n
    while ta-he>1:
        mid=(he+ta)//2
        if i>a[mid]:
            he=mid
        else:
            ta=mid
    x=he+1

    he_=-1
    ta_=n
    while ta_-he_>1:
        mid_=(he_+ta_)//2
        if i>=c[mid_]:
            he_=mid_
        else:
            ta_=mid_
    y=n-ta_
    ans+=x*y
print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()

Submission status: Accepted

Solution code:
#ABC077-C
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):
    b=B[i]
    left=0
    right=N-1
    if A[-1]<b:
        a_comb=N
    elif A[0]>=b:
        a_comb=0
    elif A[0]<b and A[1]>=b:
        a_comb=1
    else:
        a_comb=0
        while left<=right:
            mid=(left+right)//2
            if A[mid]<b and A[mid+1]>=b:
                a_comb=mid+1
                break
            elif A[mid]<b and A[mid+1]<b:
                left=mid+1
            elif A[mid]>=b:
                right=mid-1

    left=0
    right=N-1
    if C[0]>b:
        c_comb=N
    elif C[-1]<=b:
        c_comb=0
    elif C[-1]>b and C[-2]<=b:
        c_comb=1
    else:
        c_comb=0
        while left<=right:
            mid=(left+right)//2
            if C[mid]>b and C[mid-1]<=b:
                c_comb=N-mid
                break
            elif C[mid]>b and C[mid-1]>b:
                right=mid-1
            elif C[mid]<=b:
                left=mid+1
    ans+=a_comb*c_comb
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()
memo = [0]*(n+1)
for i in range(n):
    memo[bisect.bisect_left(b,c[i])] += 1
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
memo = memo[1:]+[0]
ans = 0

for i in range(n):
    ans += memo[bisect.bisect_right(b,a[i])]
print(ans)

Submission status: Accepted

Solution code:
import bisect

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for j in range(N):
         i = bisect.bisect_right(A, B[j] - 1)
         k = bisect.bisect_left(C, B[j] + 1)
         ret += i * (N - k) if 0 <= i and 0 <= k < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)

Submission status: Accepted

Solution code:
def binarySearchLeft(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == 0 or target != nums[mid - 1]:
                return mid
            else:
                high = mid - 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return low

def binarySearchRight(nums, target):
    low = 0
    high = len(nums) - 1
    while low <= high:
        mid = low + high >> 1
        if target == nums[mid]:
            if mid == len(nums) - 1 or target != nums[mid + 1]:
                return mid
            else:
                low = mid + 1
        elif target < nums[mid]:
            high = mid - 1
        else:
            low = mid + 1
    return high

def solve(N, A, B, C):
     A.sort()
     B.sort()
     C.sort()
     ret = 0
     for j in range(N):
         i = binarySearchRight(A, B[j] - 1)
         k = binarySearchLeft(C, B[j] + 1)
         ret += (i + 1) * (N - k) if 0 <= i < N and 0 <= k < N else 0
     print(ret)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    solve(N, A, B, C)

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

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

Submission status: Accepted

Solution code:
import bisect

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

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

ans = 0

for middle in b:
    # 挿入できる箇所の左側のインデックスを返す
    tmp1 = bisect.bisect_left(a, middle)
    # 挿入できる箇所の右側のインデックスを返す
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

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

Submission status: Accepted

Solution code:
import bisect
import numpy as np

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

small = []
big = []

for x in b:
    small.append(bisect.bisect_left(a, x))
    big.append(n-bisect.bisect(c, x))

small = np.array(small)
big = np.array(big)

print(np.sum(small*big))

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

BC = []
for b in B:
    BC.append(n - bisect.bisect_right(C, b))

cumsum = [BC[-1]]
for bc in BC[-2::-1]:
    cumsum.append(cumsum[-1] + bc)
cumsum = cumsum[::-1]

ans = 0
for a in A:
    idx = bisect.bisect_right(B, a)
    if idx < n: ans += cumsum[idx]
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):
  temp1=bisect.bisect_left(a,b[i])
  temp2=bisect.bisect(c,b[i])
  ans=ans+temp1*(n-temp2)
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:
    x = bisect.bisect_left(A, i)
    y = bisect.bisect_right(C, i)
    y = N - y
    ans += x*y
print(ans)

Submission status: Accepted

Solution code:
import bisect
N=int(input())
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
sita.sort(),naka.sort(),ue.sort()
count2=[0]*N
count1=[0]*N
for i in range(N):
    m = naka[i]
    k=naka[i]
    small=bisect.bisect_left(ue,k)
    count1[i]=small
    big = bisect.bisect_right(sita, m)
    count2[i]=N-big
ans=0
for i in range(N):
    ans+=count1[i]*count2[i]
print(ans)

Submission status: Accepted

Solution code:
# ABC077C

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

# bC=[0 for i in range(N)]
# for i in range(N):
#     bC[i]=N-bisect.bisect(C,B[i])
    
# bCS=[0]*(N+1)
# for i in range(N):
#     bCS[i+1] = bCS[i]+bC[i]
    
# ans=0
# for i in range(N):
#     x=bisect.bisect(B,A[i])
#     ans+=bCS[N]-bCS[x]
        
# print(ans)

# 以下賢い

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:
# ABC077C

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

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
bCS=[0]*(N+1)
for i in range(N):
    bCS[i+1] = bCS[i]+bC[i]
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    ans+=bCS[N]-bCS[x]
        
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())

list.sort(A), list.sort(B), list.sort(C)

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

import bisect
#a=[0,2,3,4,67,8]
#a.sort()
#bisect.bisect_left(a, 4) #被ったら左側のindexを返す
#bisect.bisect_right(a, 4)#被ったら右側のindexを返す
ans=0
for bb in b:
    #print(">>>",bb)
    #print(a,bisect.bisect_left(a, bb))
    #print(c,n-bisect.bisect_right(c, bb))
    ans+=bisect.bisect_left(a, bb)*(n-bisect.bisect_right(c, bb))

print(ans)

Submission status: Accepted

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

res = 0

from bisect import bisect_left, bisect_right

for b in B:
    idx_a = bisect_left(A, b)
    idx_c = bisect_right(C, b)
    res += idx_a * (n - idx_c)

print(res)

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

ans = 0
for i in range(N):
  cand_num_a = bisect_left(A, B[i])
  cand_num_c = N - bisect_right(C, B[i])
  ans += cand_num_a * cand_num_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()))
ans = 0
tmp = 0
a.sort()
b.sort()
c.sort()
for i in range(n):
    tmp = bisect.bisect_left(a,b[i])
    tmp2 = n - bisect.bisect_left(c,b[i]+1)
    ans += tmp*tmp2
print(ans)

Submission status: Accepted

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

lal = sorted(al)
lbl = sorted(bl)
lcl = sorted(cl)


from bisect import bisect_left, bisect_right
 

res = 0

for i in range(n):
    bx = lbl[i]
    ax = bisect_left(lal,bx)
    cx = n - bisect_right(lcl,bx)
    
    res += ax*cx

print(res)

Submission status: Accepted

Solution code:
import bisect
def main():
  N = int(input())
  A = sorted(list(map(int, input().split())))
  B = sorted(list(map(int, input().split())))
  C = sorted(list(map(int, input().split())))
  b_c = [0]*N
  for i, b in enumerate(reversed(B)):
    b_c[-1-i]  = b_c[-i] +N-bisect.bisect_right(C, b)
  ans = 0
  for i in A:
    posi = bisect.bisect_right(B, i)
    if posi < N:
      ans += b_c[posi]
  print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        top = bisect_left(A, B[i])
        bottom = bisect_right(C, B[i])
        if top>0 and bottom != N:
            ans += top*(N-bottom)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
Lists = []
ans = 0
for _ in range(3):
    s = [int(e) for e in input().split()]
    s.sort()
    Lists.append(s)
def bin(i,j):
    global t,s
    right = N-1;left = 0
    while(right >= left):
        mid = int(left + (right-left)/2)
        if(j==0):
            if(i>Lists[j][mid]):
                left = mid + 1
            else:
                right = mid -1
        else:
            if(i>=Lists[j][mid]):
                left = mid + 1
            else:
                right = mid - 1
    if(j == 0):
        t = left
    else:
        s = N - left
for i in Lists[1]:
    bin(i,0)
    bin(i,2)
    ans += t*s
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    #N = [list(map(int, input().split())) for i in range(3)]

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

    import bisect
    cnt = 0
    for bi in B:
        a_ok = bisect.bisect_left(A, bi)
        c_ok = bisect.bisect_right(C, bi)
        cnt += a_ok * (n - c_ok)
    print(cnt)

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())),reverse=True)
ul=[0]*n
ll=[0]*n
u=0
l=0
ans=0
for i in range(n):
  if u!=n:
    while a[u]<b[i]:
      u+=1
      if u==n:
        break
  ul[i]=u
b=b[::-1]
for i in range(n):
  if l!=n:
    while c[l]>b[i]:
      l+=1
      if l==n:
        break
  ll[i]=l
ll=ll[::-1]
for i in range(n):
  ans+=ul[i]*ll[i]
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()
# print(al)
bl.sort()
# print(bl)
cl.sort()
# print(cl)

cnt = 0
for i in range(N):
    cnt_ab = bisect.bisect_left(al, bl[i])  # bl[b] = 6 idx= 3
    cnt_bc = len(cl) - bisect.bisect(cl, bl[i])  # bl[b] = 6 idx2= 1
    # print(cnt_ab,cnt_bc)
    cnt += cnt_ab * cnt_bc

print(cnt)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N = getN()
top = getList()
middle = getList()
bottom = getList()

top.sort()
middle.sort()
bottom.sort()

# i未満
on_mid = [0]
for i in range(N):
    index_mid = bisect_left(top, middle[i])
    on_mid.append(on_mid[i] + index_mid)

ans = 0
for j in range(N):
    index_bot = bisect_left(middle, bottom[j])
    # on_midの最初の0を取り除いてないのでインデックスが一つずれる
    ans += on_mid[index_bot]
print(ans)

Submission status: Accepted

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

from bisect import bisect_left, bisect

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.buffer.readline

from bisect import bisect_left
from bisect import 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())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    res += num_a * num_c
    pre_b = b
print(res)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.buffer.readline

import numpy as np

N = int(input())

A = np.array(input().split(), dtype=np.int32) # 32ビットで9桁の数字を記述できる。今回は10^9までなので、これでOK。
B = np.array(input().split(), dtype=np.int32)
C = np.array(input().split(), dtype=np.int32)

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

num_a = np.searchsorted(A, B, side="left")
num_c = N - np.searchsorted(C, B, side="right")

res = np.dot(num_a, num_c)

print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import 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())))
num_a = 0
num_c = 0
res = 0
pre_b = -1


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_right(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    res += num_a * num_c
    pre_b = b
print(res)

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

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 = n - bisect.bisect_left(C,b+1)
    ans += a*c
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from collections import defaultdict

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0
pre_b = -1

dict_C = defaultdict(int)


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    if pre_num_c != N and C[pre_num_c] == b:
        num_c = N - bisect_left(C, b+1)
    res += num_a * num_c
    pre_b = b
print(res)