Problem:


Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right


n = int(input())
lst_A = sorted(map(int, input().split()))
lst_B = sorted(map(int, input().split()))
lst_C = sorted(map(int, input().split()))


ans = 0
for b in lst_B:
    na = bisect_left(lst_A, b)
    nc = n - bisect_right(lst_C, b)
    ans += na * nc


print(ans)

Submission status: Accepted

Solution code:
import bisect


n = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    na = bisect.bisect_left(lst_A, b)
    nc = n - bisect.bisect_right(lst_C, b)
    ans += na * nc


print(ans)

Submission status: Accepted

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


def main():
    from bisect 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 bi in b:
        a_count = bisect(a, bi - 1)
        c_count = n - bisect(c, bi)
        ans += a_count * c_count

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

n = int(input())

parts = [list(map(int,input().split())) for i in range(3)]

parts[0] = sorted(parts[0])
parts[2] = sorted(parts[2])

c = 0

for i in parts[1]:
    low = 0
    high = 0
    
    low = bisect.bisect_left(parts[0],i)
    high = n-bisect.bisect_right(parts[2],i)
    
    c += (low*high)

print(c)

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()
print(sum(bisect_left(A, i) * (N - bisect_right(C, i)) for i in B))

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()
s = 0
for i in range(N):
    ii = bisect.bisect_left(A, B[i])
    jj = bisect.bisect_right(C, B[i])
    s += ii * (N - jj)

print(s)

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:
from sys import stdin
input = stdin.readline
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()

## 各B[i]に対してそれより上(下)に積むことができる数を計算
n_upper_lst = []
n_lower_lst = []
ans = 0
for i in range(N):
  n_upper = bisect.bisect_left(A, B[i])
  n_upper_lst.append(n_upper)
  n_lower = N - bisect.bisect_right(C, B[i])
  n_lower_lst.append(n_lower)
  ans += n_upper * n_lower

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N=II()
  l1=LI()
  l2=LI()
  l3=LI()

  l=[]
  for x in l1:
    l.append([x,3])

  for x in l2:
    l.append([x,2])

  for x in l3:
    l.append([x,1])

  l=sorted(l,key=lambda x:[x[0],x[1]])

  a=0
  b=c=N
  cnt=0
  for x in l:
    y=x[1]
    if y==3:
      a+=1
    elif y==1:
      c-=1
    else:
      cnt+=a*c
      b-=1

  return cnt

# main()
print(main())

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
ai = 0
ci = 0
for bi in b:
    while ai < N and a[ai] < bi:
        ai += 1
    while ci < N and c[ci] <= bi:
        ci += 1
    ans += ai * (N -ci)
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:
    i = bisect.bisect_left(A, b)
    j = N - bisect.bisect_right(C, b)
    ans += i * j
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()

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

print(s)

Submission status: Accepted

Solution code:
import bisect
num = int(input())
up = sorted(list(map(int,input().split())))
mid = sorted(list(map(int,input().split())))
dw = sorted(list(map(int,input().split())))
SUM = 0

for i in mid:
  head = bisect.bisect_left(up,i)
  foot = len(dw) - bisect.bisect_right(dw,i)
  SUM += head * foot

print(SUM)

Submission status: Accepted

Solution code:
n=int(input())
inf=[10**10]
a=sorted([int(j) for j in input().split()+inf])
b=sorted([int(j) for j in input().split()])
c=sorted([int(j) for j in input().split()+inf])
ans,pa,pc=0,0,0
for j in range(n):
    while a[pa]<b[j]:
        pa+=1
    while c[pc]<=b[j]:
        pc+=1
    ans+=pa*(n-pc)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[10**10]+[int(j) for j in input().split()]
b=[int(j) for j in input().split()]
c=[10**10]+[int(j) for j in input().split()]

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

ans=0
pa=0
pc=0
for j in range(n):
    while a[pa]<b[j]:
        pa+=1
    while c[pc]<=b[j]:
        pc+=1
    ans+=pa*(n-pc)
    
print(ans)

Submission status: Accepted

Solution code:
import bisect

    
def main():
    answer=0
    n = int(input())
    
    A = input().split( )
    B = input().split( )
    C = input().split( )
    
    A = [int(a) for a in A]
    B = [int(b) for b in B]
    C = [int(c) for c in C]
    
    A.sort()
    B.sort()
    C.sort()
    #Bの要素数分ループ
    for b in B:
        #Bの要素でAを2分探索し、Bより小さい個数を求める
        num_A=bisect.bisect_left(A,b)
        #Bの要素でCを2分探索し、Bより大きい個数を求める
        num_C=len(C)-bisect.bisect_right(C,b)
        #掛け算
        num=num_A*num_C
        #合計をたしていく
        answer+=num
    print(answer)


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

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 = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

import bisect
ans = 0
for i, b in enumerate(B):
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a * (N-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
A.sort()
C.sort()
B.sort()

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

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())
A, B, C = (sorted([int(i) for i in input().split()]) for _ in range(3))

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

p,q=0,0
xB=[None]*N

for i in range(N):
	while p < N and A[p] < B[i]:
		p += 1
	xB[i] = p

p,q=0,0
xC=[None]*N

for i in range(N):
	while p < N and B[p] < C[i]:
		q += xB[p]
		p += 1
	xC[i] = q

print(sum(xC))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int,input().split())) + [10**10]
B = sorted(map(int,input().split())) + [10**10+1]
C = sorted(map(int,input().split())) + [10**10+2]

j = 0
nB = [0]*(N+1)
for i in range(N):
    while B[i] >= C[j]:
        j += 1
    nB[i] = N-j

S = [0]*(N+1)
for i in range(N-1,-1,-1):
    S[i] = S[i+1] + nB[i]
ans = 0
j = 0
for i in range(N):
    while A[i] >= B[j]:
        j += 1
    ans += S[j]
print(ans)

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    blist = list(map(int, input().split()))
    clist = list(map(int, input().split()))

    return n, alist, blist, clist


def submit():
    n, alist, blist, clist = read_input()

    alist.sort(reverse=True)
    blist.sort(reverse=True)
    clist.sort(reverse=True)

    b_a_n = [0] * n
    i = j = 0

    while j < n:
        while i < n and alist[i] >= blist[j]:
            i += 1
        b_a_n[j] = n - i
        j += 1

    b_a_sum = b_a_n.copy()
    for i in range(2, n + 1):
        b_a_sum[n - i] = b_a_sum[n - i + 1] + b_a_n[n - i]

    count = 0
    i = j = 0
    while i < n:
        while blist[j] >= clist[i]:
            j += 1
            if j == n:
                print(count)
                return
        count += b_a_sum[j]
        i += 1

    print(count)

if __name__ == '__main__':
    submit()

Submission status: Accepted

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


N = int(input())
A = list(map(int ,input().split()))
B = list(map(int ,input().split()))
C = list(map(int ,input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for j in B:
    a_index = bisect.bisect_left(A, j)
    c_index = bisect.bisect_right(C, j)
    cnt += a_index*(N-c_index)
print(cnt)

Submission status: Accepted

Solution code:
def c_snuke_festival(N, A, B, C):
    from bisect import bisect_left, bisect_right
    a, b, c = sorted(A), sorted(B), sorted(C)
    # bの各要素に対して、それより小さなaの要素数とそれより大きなcの要素数の積の総和が解
    return sum(bisect_left(a, _b) * (N - bisect_right(c, _b)) for _b in b)

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()]
print(c_snuke_festival(N, A, B, C))

Submission status: Accepted

Solution code:
import numpy as np
import bisect

n=int(input())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])

count=0
index_b=0
index_c=0
count_b=[0]*(n+1)
for i in range(n):
        count_b[i+1]=bisect.bisect_left(a,b[i])+count_b[i]
for i in range(n):
        count+=count_b[bisect.bisect_left(b,c[i])]
print(count)

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

o = []
p = []

i = 0
k = 0
for j in range(N):
    while i < N and A[i] < B[j]:
        i = i + 1
    o.append(i)

    while k < N and B[j] >= C[k]:
        k = k + 1
    p.append(N-k)

sum = 0
for x in range(N):
    sum = sum + o[x] * p[x]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)

ans = 0
before_b = 0
before_c = 0
mem = 0

for a in range(N):
    ans += mem
    for b in range(before_b, N):
        if A[a] < B[b]:
            for c in range(before_c, N):
                if B[b] >= C[c]:
                    before_c = c
                    c -= 1
                    break
                before_c = N

            ans += c + 1
            mem += c + 1
        else:
            before_b = b
            break
        before_b = b + 1


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_right as b_r,bisect_left as b_l

N = int(input())
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])

sum = 0
for b in B:
    sum += b_l(A,b) * (N - b_r(C,b))
print(sum)

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(sum(bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)) for b in B))

Submission status: Accepted

Solution code:
n = int(input())
import bisect


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 num_b in b:
  cnt_a = bisect.bisect_left(a,num_b)
  cnt_c = len(b) - bisect.bisect_right(c,num_b)
  ans += cnt_a * cnt_c
  
print(ans)

Submission status: Accepted

Solution code:
n,a=int(input()),[sorted(list(map(int,input().split())))for i in range(3)]
b=[[],[]]
x=0
for i in range(n):
  while a[2][i]>a[1][x]:
    b[1].append(n-i)
    x+=1
    if x==n:break
  if x==n:break
for i in range(n-len(b[1])):b[1].append(0)
for i in range(1,n):b[1][n-i-1]+=b[1][n-i]
x=0
for i in range(n):
  while a[1][i]>a[0][x]:
    b[0].append(b[1][i])
    x+=1
    if x==n:break
  if x==n:break
print(sum(b[0]))

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 range(N):
    count_A = bisect.bisect_left(A,B[i])
    count_C = bisect.bisect_right(C,B[i])
    ans += count_A * (N-count_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()

a2=[]
for i1 in range(N):
    a2.append(bisect.bisect_left(C,B[i1]+1))

a2c=[0]*(N+1)
for i1 in range(N-1,-1,-1):
    a2c[i1] = a2c[i1+1] + N - a2[i1]

ans=0
for i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    ans += a2c[a1]
print(ans)

Submission status: Accepted

Solution code:
import bisect
from itertools import accumulate

n = int(input())
a_s = sorted([int(item) for item in input().split()])
b_s = sorted([int(item) for item in input().split()])
c_s = sorted([int(item) for item in input().split()])

count = [0] * n
for i, b in enumerate(b_s):
    count[i] = bisect.bisect_left(a_s, b)
cumsum = list(accumulate(count))

ans = 0
for i, c in enumerate(c_s):
    index = (bisect.bisect_left(b_s, c)-1)
    if index >= 0:
        ans += cumsum[index]

print(ans)

Submission status: Accepted

Solution code:
import bisect#bisection search 
#二分探索のためのライブラリ
#ソート済みリストに対して二分探索法を行う関数を提供
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:
    a=bisect.bisect_left(A,b)
    c_=bisect.bisect_right(C,b)
    c=N-c_
    count+=a*c
print(count)

Submission status: Accepted

Solution code:
import bisect

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

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

ans = 0
for b in B:
    i_a = bisect.bisect_left(A, b)
    i_c = bisect.bisect_right(C, b)
    ans += i_a * (N - i_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()
C.sort()

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

print(ans)

Submission status: Accepted

Solution code:
from sys import exit
import bisect

N = int(input())
A = sorted([int(n) for n in input().split()])
B = sorted([int(n) for n in input().split()])
C = sorted([int(n) for n in input().split()])
Cl = len(C)
# print(A)
# print(B)
# print(C)
ans=0
for b in B:
    a = bisect.bisect_left(A,b)#未満を探す
    c = Cl - bisect.bisect_right(C,b)#以下を探して全体から引く
    # print(b,a,c)
    ans+=a*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()
c.sort()
count=0

for j in b:
   x=bisect.bisect_left(a,j)
   y=bisect.bisect_right(c,j)
   count+=x*(N-y)
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()
c.sort()

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

dpA = [0]*n
dpB = [0]*n

for i in range(n):
    dpB[i] = n-bisect.bisect_right(C,B[i])
for i in range(n-2,-1,-1):
    dpB[i] += dpB[i+1] 
for i in range(n):
    x = bisect.bisect_right(B,A[i])   
    if x == n:
        dpA[i] = 0
    else:
        dpA[i] = dpB[x]

print(sum(dpA))

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
c.sort()
sum=0
for i in range(n):
    ans_a=bisect.bisect_left(a,b[i])
    ans_c=n-bisect.bisect_left(c,b[i]+1)
    sum+=ans_a*ans_c
print(sum)

Submission status: Accepted

Solution code:
def solve(string):
    n, *abc = map(int, string.split())
    a, b, c = map(sorted, [abc[i*n:(i+1)*n] for i in range(3)])
    ai = ci = ans = 0
    for _b in b:
        while ai < n and a[ai] < _b:
            ai += 1
        while ci < n and c[ci] <= _b:
            ci += 1
        ans += ai * (n - ci)
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *abc = map(int, string.split())
    a, b, c = sorted(abc[:n]), sorted(abc[n:2 * n]), sorted(abc[2 * n:])
    ai = ci = ans = 0
    for _b in b:
        while ai < n and a[ai] < _b:
            ai += 1
        while ci < n and c[ci] <= _b:
            ci += 1
        ans += ai * (n - ci)
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *abc = map(int, string.split())
    a = sorted(abc[:n], reverse=True)
    b = sorted(abc[n:2 * n], reverse=True)
    c = sorted(abc[2 * n:], reverse=True)
    ab = [0] * n
    j = 0
    for i, _a in enumerate(a):
        while j <= n - 1 and _a < b[j]:
            j += 1
        ab[i] = j
    bc = [0] * (n + 1)
    j = 0
    for i, _b in enumerate(b, start=1):
        while j <= n - 1 and _b < c[j]:
            j += 1
        bc[i] = j

    for i in range(1, len(bc)):
        bc[i] += bc[i - 1]
    return str(sum([bc[_ab] for _ab in ab]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

A_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    a_count = bisect.bisect_left(A_sorted, b)
    
    #Cのうちbより大きいの数
    c_count = N - bisect.bisect_right(C_sorted, b)
    
    ans += a_count * c_count

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

A_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if A_sorted[mid] < b:
            left = mid
        else:
            right = mid
    a_count = right
    #Cのうちbより大きいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if C_sorted[mid] > b:
            right = mid
        else:
            left = mid
    c_count = N - right
    
    ans += a_count * c_count

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import time
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()

sum = 0

for i in range(N):
    a = bisect.bisect_left(A,B[i])

    c = N-bisect.bisect_right(C,B[i])
    # print(a,c)

    sum += a*c

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
An = sorted(list(map(int, input().split())))
Bn = sorted(list(map(int, input().split())))
Cn = sorted(list(map(int, input().split())))

import bisect
total = 0
for B in Bn:
    ai = bisect.bisect_left(An, B)  # この index より手前は自分より真に小さい
    ci = bisect.bisect_right(Cn, B) # この index より後ろは自分より真に大きい
    total += ai*(N-ci)
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()
Bpatan=[0]*N
Bpatan[0]=bisect.bisect_left(A,B[0])*(N-bisect.bisect_right(C,B[0]))
for i in range(1,N):
    Bpatan[i]=Bpatan[i-1]+bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
print(Bpatan[N-1])

Submission status: Accepted

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

i=0
j=0
k=0

NA=list(range(1,N+1))+[0]
NB=[0]*N+[0]
NC=[0]*N+[0]

while j<N:
  while A[i]<B[j]:
    i+=1
  NB[j]=NA[i-1]+NB[j-1]
  j+=1

j=0
while k<N:
  while B[j]<C[k]:
    j+=1
  NC[k]=NB[j-1]+NC[k-1]
  k+=1

#print(NA,NB,NC)
    
print(NC[-2])

Submission status: Accepted

Solution code:
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()
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N = read_int()[0]
A = sorted(read_int())
B = sorted(read_int())
C = sorted(read_int())

def solve():
    ans = 0
    # memo
    memo = [0 for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        lbc = bisect.bisect_right(C,B[i])
        memo[i] += N - lbc
        if i > 0:
            memo[i - 1] = memo[i]
    for i in range(N):
        lbb = bisect.bisect_right(B,A[i])
        ans += memo[lbb]
    return ans


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

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

Submission status: Accepted

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

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

Submission status: Accepted

Solution code:

import bisect

def solve(N,A,B,C):

    # A=['3', '14', '159', '2', '6', '53']
    # B=['58', '9', '79', '323', '84', '6']
    # C=['2643', '383', '2', '79', '50', '288']
    A,B,C=list(map(int, A)),list(map(int, B)),list(map(int, C))
    A=sorted(A)
    B=sorted(B)
    C=sorted(C)
    # print(A)
    # print(B)
    # print(C)
    D = [0]*N
    # E = [0]*N
    # for i in range(N):
    #     a = A[i]
    #     # print(N-bisect.bisect_right(B,a))
    #     D[i]= N-bisect.bisect_right(B,a)
    #     #bはaより大きい数字が何個あるか分かれば良い
    #     #cはbの
    # # print(D)

    for i in range(N):
        b = B[i]
        D[i]=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
        # print(b,'より小さいのは',bisect.bisect_left(A,b))
        # print(b,'より大きいのは',N-bisect.bisect_right(C,b))
    print(sum(D))
    # print(E)
    # answer = 0
    # for i in range(N):
    #     d=N-D[i]
    #     answer+=sum(E[d:])

    # print(answer)

    
 
 
def main():
    N = int(input())
    # A,B,C=0,0,0
    A=input().rstrip().split()
    B=input().rstrip().split()
    C=input().rstrip().split()
    solve(N,A,B,C)

 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

import itertools
import collections
import bisect

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

    ans = 0

    for b in B:
        i = bisect.bisect_left(A, b)
        j = bisect.bisect_right(C, b)

        ans += i * (N - j)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def biserch_min(l,key):
    left = 0; right = len(l)
    while left < right:
        mid = (left+right)//2
        if l[mid] < key:
            left = mid+1
        else:
            right = mid
    return left

def biserch_max(l,key):
    left = 0; right = len(l)
    while left < right:
        mid = (left+right)//2
        if key < l[mid]:
            right = mid
        else:
            left = mid+1
    return 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 b in B:
    top = biserch_min(A,b)
    bottom = N - biserch_max(C,b)
    ans += top*bottom
print(ans)

Submission status: Accepted

Solution code:
def biserch(l,key,flag=True):
    if flag is True:
        func = judge_1
    else:
        func = judge_2
    left = -1; right = len(l)
    while right - left > 1:
        middle = (left+right) // 2
        if func(l,key,middle) is True:
            right = middle
        else:
            left = middle
    return right

def judge_1(l,key,middle):
    if key <= l[middle]:
        return True
    else:
        return False

def judge_2(l,key,middle):
    if key < l[middle]:
        return True
    else:
        return False

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:
    top = biserch(A,b)
    bottom = N - biserch(C,b,flag=False)
    ans += top*bottom
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 i in range(n):
    in_a = bisect.bisect_left(a,b[i])
    in_c = bisect.bisect_right(c,b[i])
    ans += (in_a)*(n-in_c)


print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect,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 b in B:
    top = bisect_left(A,b)
    bottom = N - bisect(C,b)
    ans += top*bottom
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

An = sorted(map(int, input().split()), reverse=True)
Bn = sorted(map(int, input().split()), reverse=True)
Cn = sorted(map(int, input().split()), reverse=True)


def f(xn, yn, zn):
    tn = [0] * N
    num = 0
    j = 0

    for i in range(N):
        while j <= N - 1 and xn[i] < yn[j]:
            num += zn[j]
            j += 1
        tn[i] = num

    return tn


def main():
    Zn = [1] * N

    Zn = f(Bn, Cn, Zn)
    Zn = f(An, Bn, Zn)

    print(sum(Zn))
    return


main()