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:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ma=0
cntb=[0]*n
for i in range(n):
    if i>0:
        cntb[i]=cntb[i-1]
    while ma<n:
        if a[ma]<b[i]:
            cntb[i]+=1
            ma+=1
        else:
            break
mb=0
cntc=[0]*n
for i in range(n):
    if i>0:
        cntc[i]=cntc[i-1]
    while mb<n:
        if b[mb]<c[i]:
            cntc[i]+=cntb[mb]
            mb+=1
        else:
            break
print(sum(cntc))

Submission status: Accepted

Solution code:
import bisect

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]+list(map(int,input().split()))
A.sort()
B = [0]+list(map(int,input().split()))
B.sort()
C = [0]+list(map(int,input().split()))
C.sort()

bko = [0 for i in range(N+1)]
cnt = 1
for i in range(1,N+1):
  b = B[i]
  for j in range(cnt,N+1):
    if A[j] >= b:
      bko[i] = j-1
      cnt = j
      break
    if j == N:
      bko[i] = N
      cnt = N

#bkoを累積和にする
for i in range(N):     
  bko[i+1] += bko[i]

cko = [0 for i in range(N+1)]
cnt = 1
for i in range(1,N+1):
  c = C[i]
  for j in range(cnt,N+1):
    if B[j] >= c:
      cko[i] = bko[j-1]
      cnt = j
      break
    if j == N:
      cko[i] = bko[N]
      cnt = N
###
print(sum(cko))

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    cntB = [0 for _ in range(N)]
    for i, b in enumerate(B):
        cntB[i] = N - bisect.bisect_right(C, b)

    cumsumB = [0 for _ in range(N)]
    cumsumB[-1] = cntB[-1]
    for i in range(N - 2, -1, -1):
        cumsumB[i] = cumsumB[i + 1] + cntB[i]

    res = 0
    for i, a in enumerate(A):
        idx = bisect.bisect_right(B, a)
        if idx < N:
            res += cumsumB[idx]

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

aarr=sorted(limii())
barr=sorted(limii())
carr=sorted(limii())

ans=0

for i in range(n):
    temp1=bisect_left(aarr,barr[i])
    temp2=n-bisect_right(carr,barr[i])
    #print(temp1,temp2)
    if temp1>0 and temp2>0:
        ans+=temp1*temp2
print(ans)

Submission status: Accepted

Solution code:
def main():
    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
    ai = 0  # [0,ai)
    ci = 0  # [ci,N)
    for mid in b:
        while ai < N and a[ai] < mid:
            ai += 1

        while ci < N and c[ci] <= mid:
            ci += 1

        ans += ai * (N - ci)

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()

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 j in range(n):
	idx_i = bisect_left(A, B[j])
	idx_k = bisect_right(C, B[j])
	cnt += idx_i * (n - idx_k)

print(cnt)

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

al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

import bisect
bl_ac = []
for b in bl:
    idx = bisect.bisect_right(cl, b)
    bl_ac.append(n-idx)
import itertools
bl_ac = [0] + list(itertools.accumulate(bl_ac[::-1]))
bl_ac = bl_ac
ans = 0
for a in al:
    idx = bisect.bisect_right(bl, a)
    ans += bl_ac[n-idx]

print(ans)

Submission status: Accepted

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

n = inp()
a = inpl()
b = inpl()
c = inpl()
a.sort()
b.sort()
c.sort()
lb = [0] * n
res = 0
for i in range(n):
    tmp = bisect.bisect_right(b,a[i])
    if tmp == n: continue
    lb[tmp] += 1
llb = list(itertools.accumulate(lb))
# print(lb,llb)
rr = [0] * n
for i in range(n):
    tmp = bisect.bisect_right(c,b[i])
    if tmp == n: continue
    rr[tmp] += llb[i]
print(sum(list(itertools.accumulate(rr))))

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 = n ** 3
up = [0] * n
mid = [0] * n
bottom = [0] * n

p = 0
for i in range(n):
    while p < n and A[i] >= B[p]:
        p += 1
    mid[i] = p

p = 0
q = 0
for i in range(n):
    while p < n and B[i] >= C[p]:
        p += 1
    while q < n and B[i] > A[q]:
        q += 1
    bottom[i] = p
    up[i] = q

for m in mid:
    ans -= m * n

for u, b in zip(up, bottom):
    ans -= u * b

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
for j in range(n):
    bind = j
    top = n
    bot = -1
    while top-bot > 1:
        mid = (top+bot)//2
        if b[bind] > a[mid]:bot = mid
        else:top = mid
    
    aind = bot
    l = -1
    r = n
   
    while r-l> 1:
   
        cen = (l+r)//2
        if b[bind] < c[cen]:r = cen
        else:l = cen
    cind = r
    ans +=(aind+1)*(n-cind)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=n-bisect.bisect_right(und,i)
    num+=a*c
print(num)

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]
    ab=bisect.bisect_left(A,b)
    bc=N-bisect.bisect_right(C,b)
    ans+=ab*bc
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())))
#真ん中を固定
ba=0
bc=N
ans=0
for i in range(N):
    b=B[i]
    if ba!=N:
        while A[ba]<b:
            ba+=1
            if ba==N:
                break
    if bc!=0:
        while C[N-bc]<=b:
            bc-=1
            if bc==0:
                break
    ans+=ba*(bc)
    #print(ba,bc)
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
b = [int(i) for i in input().split()]
b = sorted(b)
c = [int(i) for i in input().split()]
c = sorted(c)
ans = 0
for i in range(n):
    B = b[i]
    a_nums = bisect.bisect_left(a,B)
    c_nums = n - bisect.bisect_right(c,B)
    ans += a_nums * c_nums
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
from itertools import accumulate

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

# a < b < c

# Bcnt[i]: B[i]が置ける下部パーツの数
Bcnt = [0] * N
for i,b in enumerate(B):
    r = bisect_right(C, b)
    Bcnt[i] = N - r
 
Bcnt = [0] + list(accumulate(Bcnt))
 
Acnt = [0] * N
for i,a in enumerate(A):
    r = bisect_right(B, a)
    Acnt[i] = Bcnt[N] - Bcnt[r]

print(sum(Acnt))

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
  
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Snuke Festival

import bisect

# input
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# initialization
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
ans = 0

# b search
for i in range(N):
    b = B_list[i]
    a_nums = bisect.bisect_left(A_list, b)
    c_nums = N - bisect.bisect_right(C_list, b)
    ans += a_nums * c_nums

# output
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
for j in range(n):
    bind = j
    top = n
    bot = -1
    while top-bot > 1:
        mid = (top+bot)//2
        if b[bind] > a[mid]:bot = mid
        else:top = mid
    
    aind = bot
    l = -1
    r = n
   
    while r-l> 1:
   
        cen = (l+r)//2
        if b[bind] < c[cen]:r = cen
        else:l = cen
    cind = r
    ans +=(aind+1)*(n-cind)
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()
ai = []
bi = []
for i in range(n):
    ai.append(n - bisect.bisect_right(b, a[i]))
    bi.append(n - bisect.bisect_right(c, b[i]))
ans = 0
c = [0]+list(accumulate(bi[::-1]))
for j in ai:
    ans += c[j]
print(ans)

Submission status: Accepted

Solution code:
def main():
    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()
    Bdic = [0]*N
    from bisect import bisect
    from itertools import accumulate
    for i, b in enumerate(B):
        idx = bisect(C, b)
        Bdic[i] = N - idx
    Bacc = list(accumulate([b for b in Bdic + [0]][::-1]))[::-1]
    ans = 0
    for i, a in enumerate(A):
        idx = bisect(B, a)
        ans += (Bacc[idx])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    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())))
    b_comb_accum = [0] * (N+1)
    for i in range(N-1, -1, -1):
        c_min_ind = bisect_right(C, B[i])
        b_comb_accum[i] = b_comb_accum[i+1] + N - c_min_ind
    ans = 0
    for a in A:
        b_min_ind = bisect_right(B, a)
        ans += b_comb_accum[b_min_ind]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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())))
F = [0 for _ in range(N+1)]
for i in range(N-1,-1,-1):
    b = B[i]
    indC = bisect_right(C,b)
    if i<N-1:
        indC1 = bisect_right(C,B[i+1])
    else:
        indC1 = N
    F[i] = F[i+1]+indC1-indC
G = [0 for _ in range(N+1)]
for i in range(N-1,-1,-1):
    G[i] = G[i+1]+F[i]
cnt = 0
for i in range(N):
    a = A[i]
    indB = bisect_right(B,a)
    cnt += G[indB]
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
# n = 6
# A = [3, 14, 159, 2, 6, 53]
# B = [58, 9, 79, 323, 84, 6]
# C = [2643, 383, 2, 79, 50, 288]
A.sort()
B.sort()
C.sort()
# X[i]=B[i]<C[j]なるjの個数
X = []
j = 0
for i in range(n):
    while j < n and B[i] >= C[j]:
        j += 1
    X.append(n-j)
# S[i]=sum(X[:i])
S = [0]
for i in range(n):
    S.append(S[-1]+X[i])
# A[i]<B[j]なるjに対してS[n]-S[j]をたす
j = 0
ans = 0
for i in range(n):
    while j < n and A[i] >= B[j]:
        j += 1
    ans += S[n]-S[j]
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


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())))
    ans = 0
    for b in B:
        i = bisect_left(A, b)
        j = n - bisect_right(C, b)
        if i == 0 or j == 0:
            continue
        ans += i * j
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
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()

# print(A)
# print(B)
# print(C)
ans = 0
for b in B:
    a = bisect_left(A, b)
    c = N - bisect_right(C, b)
    ans += a * c
    # print(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()
b.sort()
c.sort()
from bisect import bisect_left,bisect_right
ans=0
for i in range(n):
  ida=bisect_left(a,b[i])
  idc=bisect_right(c,b[i])
  ans+=ida*(n-idc)
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()
import bisect
ans = 0
for i in range(n):
    abis = bisect.bisect_left(a, b[i])
    cbis = bisect.bisect_right(c, b[i])
    ans += abis*(n-cbis)
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):
    num = b[i]
    x = bisect.bisect_left(a, num)
    y = bisect.bisect_right(c, num)
    ans += x * (n - y)

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left
from itertools import accumulate

n = int(readline())
a = sorted(list(map(int, readline().split())))
b = sorted(list(map(int, readline().split())))
c = sorted(list(map(int, readline().split())))
check = [0] * n
ans = 0
for i in range(n):
    index = bisect_left(c, b[i])
    if index != n:
        if c[index] == b[i]:
            index = bisect_left(c, b[i] + 1)
    check[i] = n - index
cumsum = [0] + list(accumulate(check[::-1]))
for aa in a:
    index = bisect_left(b, aa)
    if index != n:
        if b[index] == aa:
            index = bisect_left(b, aa + 1)
    ans += cumsum[n - index]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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

ans = 0

for bi in range(N):
    ai_max = bisect_left(A, B[bi])
    ci_min = bisect_right(C, B[bi])
    ans += (ai_max) * (N - ci_min)

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    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):
        btest = b[i]
        aind = bisect.bisect_left(a,btest)
        cind = bisect.bisect_right(c, btest)
        ans += aind * (len(c)-cind)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


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


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


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/arc084/tasks/arc084_a
# 真ん中固定すれば良い
# そうすれば自分より小さい(大きい)範囲は二分探索で求まる。

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

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

ans = 0
for b in B:
    i = bisect_left(A, b)  # [0,i)のi個がbより小さい
    k = bisect_right(C, b)
    ans += i * (N - 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()

C.sort()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b)

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

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

Submission status: Accepted

Solution code:
import bisect

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

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

Submission status: Accepted

Solution code:
from bisect import bisect
from collections import deque

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

BC_ruiseki = deque([0])
for i, b in enumerate(B):
  BC_ruiseki.append(BC_ruiseki[i] + N - bisect(C, b))

ans = 0
for a in A:
  idx = bisect(B, a)
  ans += BC_ruiseki[-1] - BC_ruiseki[idx]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import*
(N,),A,B,C=[sorted(map(int,input().split()))for _ in range(4)]
w,i=[0]*(N+1),N
while i:i-=1;w[i]=w[i+1]+N-bisect(C,B[i])
print(sum(w[bisect(B,a)]for a in A))

Submission status: Accepted

Solution code:
from bisect import*
r=lambda:sorted(map(int,input().split()))
N=r()[0]
A,B,C,w,i=r(),r(),r(),[0]*(N+1),N
while i:i-=1;w[i]=w[i+1]+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

Submission status: Accepted

Solution code:
from bisect import*
r=lambda:sorted(map(int,input().split()))
N=r()[0]
A,B,C,w,i=r(),r(),r(),[0]*(N+1),N
while i:w[i-1]=w[i]+N-bisect(C,B[i-1]);i-=1
print(sum(w[bisect(B,A[i])]for i in range(N)))

Submission status: Accepted

Solution code:
from bisect import*
N=int(input())
r=lambda:sorted(map(int, input().split()))
A,B,C,w=r(),r(),r(),[0]*(N+1)
for i in range(N-1,-1,-1):w[i]=w[i+1]+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

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

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

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

print(count)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A=sorted(A)
B=list(map(int,input().split()))
B=sorted(B)
C=list(map(int,input().split()))
C=sorted(C)
def ais_ok(i,b):
    if i<-1: #all ng ok=-1
        return True
    if n<=i: #all ok ng=n
        return False
    return A[i]<b #okになる条件
def cis_ok(i,b):
    if i<-1: #all ok ng=-1
        return False
    if n<=i: #all ng ok=n
        return True
    return b<C[i]
ans=0
for i in range(n):
    b=B[i]
    ok_a,ng_a=-1,n
    ok_c,ng_c=n,-1
    while (ng_a-ok_a)>1:
        mid=(ok_a+ng_a)//2
        if ais_ok(mid,b):
            ok_a=mid
        else:
            ng_a=mid
    while (ok_c-ng_c)>1:
        mid=(ok_c+ng_c)//2
        if cis_ok(mid,b):
            ok_c=mid
        else:
            ng_c=mid
    ans+=(ok_a+1)*(n-(ng_c+1))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    C = Scanner.map_int()
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        ok = -1
        ng = N
        while abs(ok - ng) > 1:
            m = (ok + ng) // 2
            if A[m] < B[i]:
                ok = m
            else:
                ng = m
        n = ok + 1
        ok = N
        ng = -1
        while abs(ok - ng) > 1:
            m = (ok + ng) // 2
            if C[m] > B[i]:
                ok = m
            else:
                ng = m
        m = N - ok
        ans += n * m
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
cnt = [0] * n
res = 0
for i,b in enumerate(B):
    c = bisect.bisect_left(C,b+1)
    cnt[i] = n-c

acc = [0]
for x in cnt:
    acc += [acc[-1] + x]
su = sum(cnt) 
for i,a in enumerate(A):
    c = bisect.bisect_left(B,a+1)
    res += su - acc[c]
print(res)

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

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

Submission status: Accepted

Solution code:
import bisect

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

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

print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left

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

A.sort()
C.sort()

ans = 0
for b in B:
    a = bisect_left(A, b)
    c = N - bisect_right(C, b)
    ans += a * c

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

def bin_a(list,bi):
    ok=-1
    ng=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi>list[mid]:
            ok=mid
        else:
            ng=mid
    return ok+1
def bin_c(list,bi):
    ok=n
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi<list[mid]:
            ok=mid
        else:
            ng=mid
    return n-ok

cnt=0
for i in range(n):
    cnt+=bin_a(a,b[i])*bin_c(c,b[i])
    #print(bin_a(a,b[i]),bin_c(c,b[i]))
print(cnt)