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

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

print(ans)

Submission status: Accepted

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

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

for j in range(n):
    al=bisect.bisect_left(a,b[j])
    cl=n-bisect.bisect_right(c,b[j])
    ans+=al*cl
print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=list(int(i) for i in input().split())
b=list(int(i) for i in input().split())
c=list(int(i) for i in input().split())
A=sorted(a)
B=sorted(b)
C=sorted(c)
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:
from bisect import bisect_left as bil
from bisect import bisect_right as bir
from itertools import accumulate


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

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

t = [0]*(N+1)

for i, b in enumerate(B):
    j = bil(A, b)
    t[i+1] = j


t = list(accumulate(t))


ans = 0
for c in C:
    i = bil(B, c)
    ans += t[i]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = list(map(int,readline().rstrip().split()))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = sorted(list(map(int,readline().rstrip().split())))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = 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.bisect_left(A, b)
  j = bisect.bisect_right(C, b)
  ans += i*(n-j)
  
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
A = LI()
B = LI()
C = LI()

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:
from bisect import bisect_left,bisect_right
import sys
input = sys.stdin.readline


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

sa = sorted(a)
sb = sorted(b)
sc = sorted(c)

ans = 0
for i in range(n):
    ab = bisect_left(sa,sb[i])
    bc = n - bisect_right(sc,sb[i])

    if ab == 0:
        continue
    ans += ab * bc

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left


def main():
    N = int(input())

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

    ans = 0
    for b in B:
        idx_a = bisect_left(A, b)
        cnt_a = idx_a

        idx_c = bisect_right(C, b)
        cnt_c = N - idx_c

        ans += cnt_a * cnt_c

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    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
from sys import stdin

def get_result(data):
    N = data[0][0]
    A = sorted(data[1])
    B = sorted(data[2])
    C = sorted(data[3])
    ans = 0
    for mid_val in B:
      num_a = bisect.bisect_left(A, mid_val)
      num_c = N - bisect.bisect_right(C, mid_val)
      ans += num_a * num_c
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Accepted

Solution code:
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    ans += ok_a*(N-ok_c)
print(ans)

Submission status: Accepted

Solution code:
import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_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 i in range(n):
    p = bisect.bisect_left(a,b[i])
    q = bisect.bisect_right(c,b[i])
    ans += p * (n-q)

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()
anssum = 0
for i in B:
    moreB = N-bisect.bisect_right(C,i)
    lessB = bisect.bisect_left(A,i)
    anssum += moreB*lessB
print(anssum)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
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
ans = 0
for i in range(N):
    b = B[i]
    inda = bisect_left(A,b)
    indc = bisect_left(C,b+1)
    ans += (N-indc)*inda
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

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

an.sort()
cn.sort()

a_pair = []
for i in bn:
    if i <= an[0]:
        a_pair.append(0)
        continue
    if i > an[-1]:
        a_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if an[mid] < i:
            front = mid + 1
        else:
            back = mid
    a_pair.append(front)

c_pair = []
for i in bn:
    if i >= cn[-1]:
        c_pair.append(0)
        continue
    if i < cn[0]:
        c_pair.append(n)
        continue
    front = 0
    back = n-1
    while front != back:
        mid = (front+back)//2
        if cn[mid] > i:
            back = mid
        else:
            front = mid + 1
    c_pair.append(n-back)

a_pair = np.array(a_pair)
c_pair = np.array(c_pair)
print(np.sum(a_pair*c_pair))

Submission status: Accepted

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

from bisect import bisect_left, bisect

print(sum([bisect_left(a, bi)*(n-bisect(c, bi)) for bi in b]))

Submission status: Accepted

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

def solve():
    import bisect

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))
    As.sort(), Bs.sort(), Cs.sort()
    lenA, lenB, lenC = len(As), len(Bs), len(Cs)

    Bs_cases = [0 for _ in range(lenB)]  # Bs[bi]を選んだときの、Csの選び方の場合の数
    for bi in range(lenB-1, -1, -1):
        cidx = bisect.bisect_right(Cs, Bs[bi])
        if cidx == lenC:
            Bs_cases[bi] = 0
        else:
            Bs_cases[bi] = lenC-cidx

    Bs_cases_ruiseki = [0 for _ in range(lenB)]  # Bs[bi]を選んだときの、Csの選び方の場合の数の累積和
    Bs_cases_ruiseki[lenB-1] = Bs_cases[lenB-1]
    for bi in range(lenB-2, -1, -1):
        Bs_cases_ruiseki[bi] = Bs_cases_ruiseki[bi+1] + Bs_cases[bi]

    ans = 0
    for a in As:
        bidx = bisect.bisect_right(Bs, a)
        if bidx == lenB:
            continue
        ans += Bs_cases_ruiseki[bidx]

    print(ans)


if __name__ == "__main__":
    solve()

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 = sorted(A)
B = sorted(B)
C = sorted(C)

from bisect import bisect_left,bisect

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

print(ans)

Submission status: Accepted

Solution code:
import 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
ans_a=0
ans_c=0

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

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

ans = 0

for B in Blist:
    Aindex = bisect.bisect_left(Alist, B)
    Cindex = bisect.bisect_right(Clist, B)

#    print(B, Aindex, N-Cindex)
    ans += Aindex * (N - Cindex)

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

Submission status: Accepted

Solution code:
import bisect
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

    B2 = [bisect_left(A, b) for b in B]
    B3 = [B2[0]]
    pre = B3[0]
    for b in B2[1:]:
        pre += b
        B3.append(pre)
    C2 = [bisect_left(B, c) for c in C]
    B3.append(0)
    ans = sum([B3[c-1] for c in C2])
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right


def main():
    n = ni()
    a = sorted(na()) + [float('inf')]
    b = sorted(na())
    c = sorted(na()) + [float('inf')]
    ans = 0
    small = 0
    big = 0
    for mid in b:
        while a[small] < mid:
            small += 1
        while c[big] <= mid:
            big += 1
        ans += small * (n-big)
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=0
for 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:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
a2 =[]
b2 =[]
c2 =[]

for i in range(n):
    a2.append([2,a[i]])
for i in range(n):
    b2.append([1,b[i]])
for i in range(n):
    c2.append([0,c[i]])
a2b2=a2+b2
b2c2=b2+c2

a2b2.sort(key = lambda x:(x[1],x[0]))
b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True)

j=0
c=0
for i in range(2*n):
    if a2b2[i][0]==2:
        c+=1
    if a2b2[i][0]==1:
        u[j]=c
        j+=1
j=0
c=0
for i in range(2*n):
    if b2c2[i][0]==0:
        c+=1
    if b2c2[i][0]==1:
        d[j]=c
        j+=1
d.reverse()
for i in range(n):
    ans+=u[i]*d[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())
    B = sorted(il())
    C = sorted(il())

    ret = 0
    for b in B:
        al = bisect.bisect_right(A, b-1)
        cl = len(C) - bisect.bisect_left(C, b+1)
        ret += al*cl
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_left 
from bisect import bisect_right
def main():
    n = int(readline()) 
    a = [int(i) for i in readline().split()]
    b = [int(i) for i in readline().split()]
    c = [int(i) for i in readline().split()]
    a.sort()
    c.sort()
    ans = 0
    for v in b:
        i = bisect_left(a, v)
        j = bisect_right(c, v)
        ans += i*(n-j)
    print(ans)
if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
ts = list(map(int, input().split()))
ms = list(map(int, input().split()))
bs = list(map(int, input().split()))

ts = sorted(ts)
ms = sorted(ms)
bs = sorted(bs)

m_count = np.zeros(N, dtype=int)
i = 0
for j, m in enumerate(ms):
    while i < N and m >= bs[i]:
        i += 1
    m_count[j] = N-i
m_cumcount = np.cumsum(m_count[::-1])[::-1]
#import IPython;IPython.embed()

i = 0
ans = 0
for j, t in enumerate(ts):
    while i < N and t >= ms[i]:
        i += 1
    #print(m_cumcount[j])
    if i == N:
        break
    ans += m_cumcount[i] 
    #np.append(m_count, N-i)
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()))
a.sort()
b.sort()
c.sort()
ans = 0
b_ = []
for bi in reversed(b):
    b_.append(n - bisect.bisect_right(c, bi))
b_ = list(accumulate(b_))[::-1]
for ai in a:
    idx_b = bisect.bisect_right(b, ai)
    if idx_b == n:
        break
    ans += b_[idx_b]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right, bisect_left
from itertools import accumulate
n = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
    i += 1
    j = li_b[(-1)*i]
    k = bisect_right(li_c, j)
    relation_bc.append(len(li_c)-k)
ans = 0
li = list(accumulate(relation_bc))
for i in li_a:
    p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
    p = n - p
    if p >= 1:
        ans += li[p-1]
    else:
        continue
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()

answer=0
ai,ci=0,0
for bi in range(N):
  while(ai<N and alist[ai]<blist[bi]):
    ai+=1
  while(ci<N and blist[bi]>=clist[ci]):
    ci+=1
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)

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

answer=0
for bi in range(N):
  ai=bisect.bisect_left(alist,blist[bi])  
  ci=bisect.bisect(clist,blist[bi])  
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)

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

print(sum)

Submission status: Accepted

Solution code:
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

    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:
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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
    i, j = 0, 0
    for b in B:
        i = bisect_left(A, b, lo=i)
        j = bisect_right(C, b, lo=j)
        ans += i * (N - j)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from bisect import bisect_left


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    pos = 0
    for i, b in enumerate(B):
        pos = bisect_left(C, b + 1, pos)
        nums[i] = N - pos

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

    ans = 0
    pos = 0
    for a in A:
        pos = bisect_left(B, a + 1, pos)
        ans += nums[pos]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

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

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    for i, b in enumerate(B):
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

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

    ans = 0
    for a in A:
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()])
ans = 0
for b in lst_b:
    i = bisect.bisect_left(lst_a, b)
    j = bisect.bisect_right(lst_c, b)
    ans += i * (N - j)

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()])
ans = 0
for b in lst_b:
    i = bisect.bisect_left(lst_a, b)
    j = bisect.bisect_right(lst_c, b)
    if i > 0 and j != len(lst_c):
        ans += i * (N - j)

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right

n = int(input().strip())
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 elem in b:
    idx_c = bisect_right(c, elem)
    rep = (n - idx_c)
    idx_a = bisect_left(a, elem)
    ans += rep * idx_a
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=bisect.bisect_right(C,b)
    ans+=a*(N-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())))
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
print(ans)

Submission status: Accepted

Solution code:
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 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 = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

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

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 i in B:
    max_A = bisect(A, i-1)
    min_C = bisect_left(C, i+1)
    # print("m_A", max_A, "m_C", min_C)
    ans += (max_A)* (len(C) - min_C)
print(ans)

Submission status: Accepted

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left,  bisect_right #(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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
lenC = len(C)
for b in B:
    uecnt = bisect_left(A, b)
    shitacnt = lenC - bisect_right(C, b)
    val = uecnt*shitacnt
    cnt += val

print(cnt)