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_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    a_ind = []
    b_ind = []
    for i in range(N):
        a_ind.append(bisect_right(B, A[i]))
        b_ind.append(N - bisect_right(C, B[i]))


    b_acc = [0]
    for b in b_ind:
        b_acc.append(b_acc[-1] + b)


    sum_b = b_acc[-1]
    ans = 0
    for i in a_ind:
        ans += sum_b - b_acc[i]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right


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

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

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ans = 0
for n in range(N):
    i = bisect.bisect_left(A,B[n])
    j = len(C) - bisect.bisect_right(C,B[n])
    ans += i * j
print(ans)

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 j in range(n):
    i = bisect_left(A, B[j])
    k = n - bisect_right(C, B[j])
    ans += i*k
print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n=int(input())  #数値入力 「N」だけの入力のとき
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    c=list(map(int, input().split()))
elif icase==1:
    n=2
    a=[1,5]
    b=[2,4]
    c=[3,6]
elif icase==2:
    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()
   
icnt=0
ast=0
cst=0
for i in range(n):
    if a[n-1]<=b[i]:
        ast=n
#        print("a1:",ast-1,a[ast-1],i,b[i])
    elif a[0]>=b[i]:
        ast=0
#        print("a1:",ast-1,a[ast-1],i,b[i])
    else:
        while a[ast]<b[i] and ast<n-1:
            ast=ast+1
#            print("a2:",ast-1,a[ast-1],i,b[i])
    if b[i]<c[0]:
        cst=0 
    elif b[i]>=c[n-1]:
        cst=n 
#        print("c1:",cst,c[cst],i,b[i])
    else:
        while b[i]>=c[cst] and cst<n-1:
            cst=cst+1
#            print("c2:",cst-1,c[cst-1],i,b[i])
#    print(ast,i,n-cst)
    icnt=icnt+(ast)*(n-cst)
    
print(icnt)

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 b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    S += a * (N - c)
print(S)

Submission status: Accepted

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

def isok(na , index , key):
    if na[index] >= key:
        return True
    else:
        return False
    
def bs(nar,key):
    left = -1
    right = len(nar)
    
    while (right - left) > 1:
        mid = left + (right - left) // 2
        
        if isok(nar , mid , key):
            right = mid
        else:
            left = mid
            
    return right

ans = 0
for i in b:
    q = bs(a,i)
    r = bs(c,i+1)
    
    ans += q*(n-r)
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a,b,c = [sorted(list(map(int,input().split()))) for i in range(3)]
ans = sum([bisect.bisect_left(a,i)*(n-bisect.bisect(c,i)) for i in b])
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a,b,c = [sorted(list(map(int,input().split()))) for i in range(3)]
ans = 0
cnt = [0]
[cnt.append(cnt[i]+bisect.bisect_left(a,b[i])) for i in range(n)]
for i in range(n):
    index = bisect.bisect_left(b,c[i])
    ans += cnt[index] 
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a,b,c = [sorted(list(map(int,input().split())),reverse=True) for i in range(3)]
comp1 = []
i,j = 0,0
cnt = 0
while i<n:
    while j<n and b[j]>a[i]:
        cnt+=1
        j+=1
    comp1.append(cnt)
    i+=1
comp2 = []
i,j = 0,0
cnt = 0
while i<n:
    while j<n and c[j]>b[i]:
        cnt+=1
        j+=1
    comp2.append(cnt)
    i+=1
x = [0]
for i in range(n):
    x.append(x[i]+comp2[i])
ans = 0
for i in comp1:
    ans += x[i]
print(ans)

Submission status: Accepted

Solution code:
import bisect

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

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

ans = 0

for i in range(n):
    bi = b[i]
    x = bisect.bisect_left(a, bi)
    y = bisect.bisect_right(c, bi)
    ans += x * (n - y)

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

cntb = 0
cntc = 0
ans = 0

lib = [0] * n
flag = True

for i in range(n):
    if not flag:
        break
    bi = b[i]
    while bi >= c[cntc]:
        cntc += 1
        if cntc == n:
            flag = False
            break
    lib[i] = n - cntc

lib2 = [sum(lib)]

for i in range(n):
    lib2.append(lib2[-1] - lib[i])

flag = True

for i in range(n):
    if not flag:
        break
    ai = a[i]
    while ai >= b[cntb]:
        cntb += 1
        if cntb == n:
            flag = False
            break
    if not flag:
        break
    ans += lib2[cntb]

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]



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()]
AA = [0]*N
BB = [0]*N
ans = 0

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


for i in range(N):
  AA[i] = bisect.bisect_right(A, B[i]-1)

for j in range(N):
  BB[j] = bisect.bisect_left(C, B[j]+1)

for k in range(N):
  ans += AA[k]*(N-BB[k])

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def f(b: "List[int]", l1: "List[int]", l2: "List[int]"):
    result = [0] * len(l2)
    i = 0
    t = 0
    for j, l2j in enumerate(l2):
        while i < len(l1) and l1[i] < l2j:
            t += b[i]
            i += 1
        result[j] = t
    return result


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    ba = [1] * N
    bb = f(ba, A, B)
    bc = f(bb, B, C)
    print(sum(bc))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)


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

#bを決めて、条件を満たすa,cの組を求める
def down_bin(i,list):
    ok=-1
    ng=n
    while abs(ng-ok)>1:
        mid=(ng+ok)//2
        if list[mid]<i:ok=mid
        else:ng=mid
    return ok+1
def up_bin(i,list):
    ok=n
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if list[mid]>i:ok=mid
        else:ng=mid
    return n-ok

ans=0
for i in b:
    ans+=down_bin(i,a)*up_bin(i,c)
print(ans)

Submission status: Accepted

Solution code:
from bisect import *


def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()
B = inpl()
C = inpl()
A.sort()
C.sort()

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

Submission status: Accepted

Solution code:
from bisect import bisect_right as bisect


def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()
B = inpl()
C = inpl()
A.sort()
B.sort()
C.sort()

BtoC = [0 for i in range(N + 1)]
ci = N - 1
for bi in range(N - 1, -1, -1):
    while ci >= 0 and B[bi] < C[ci]:
        ci -= 1
    # print(bi)
    BtoC[bi] = N - ci - 1 + BtoC[bi + 1]

ans = 0
for ai in range(N):
    while bi < N and B[bi] <= A[ai]:
        bi += 1
    ans += BtoC[bi]

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

cnt = [0] * len(b)
a = sorted(a)
c = sorted(c)

for i in range(len(b)):
    target = b[i]

    # decide a cnt
    l = 0
    r = len(a) - 1
    if a[l] >= target:
        cnt[i] += 0
    elif a[r] < target: 
        cnt[i] += len(a)
    else:
        while r - l > 1:
            mid = (l + r) // 2
            if a[mid] >= target:
                r = mid
            else:
                l = mid
        cnt[i] += l + 1

    # decide c cnt
    l = 0
    r = len(c) - 1
    if c[l] > target:
        cnt[i] *= len(c)
    elif c[r] <= target: 
        cnt[i] *= 0
    else:
        while r - l > 1:
            mid = (l + r) // 2
            if c[mid] > target:
                r = mid
            else:
                l = mid
        cnt[i] *= len(c) - (l + 1)
print(sum(cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, = I()
A = sorted(I())
B = sorted(I())
C = sorted(I())

ans = 0
for i in range(n):
    left = bl(A, B[i])
    right = n - br(C, B[i])
    ans += left * right
print(ans)

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(input())
A = inputlist()
B = inputlist()
C = inputlist()
A.sort()
B.sort()
C.sort()
index = {}
from bisect import bisect_left
for i in range(N):
    indexa = bisect_left(A,B[i])
    index[B[i]] = indexa
ans = 0
B_sum = [0]*(N+1)
for i in range(N):
    B_sum[i+1] = B_sum[i]+index[B[i]]
for i in range(N):
    indexa = bisect_left(B,C[i])
    ans += B_sum[indexa]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
A=list(map(int,input().split()))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
D=[]
for i in range(n):
  a=n-bisect.bisect_right(C,B[i],lo=0,hi=n)
  D.append(a)
E=[0]
for i in range(n-1,-1,-1):
  E.append(E[-1]+D[i])
E=E[::-1]
ans=0
for i in range(n):
  ans=ans+E[bisect.bisect_right(B,A[i],lo=0,hi=n)]
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
a_list.sort()
b_list.sort()
c_list.sort()
counter = 0
for b in b_list:
  ue = bisect.bisect_left(a_list,b)
  sita = len(c_list) - bisect.bisect_right(c_list,b)
  counter += ue * sita
print(counter)

Submission status: Accepted

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

total = 0
tmp_a_t = 0
tmp_c_t = 0
from bisect import bisect_left,bisect_right
for i,b in enumerate(B):
    tmp_a = bisect_left(A,b)
    tmp_c = len(C)-bisect_right(C,b)
    #print(tmp_a,tmp_c)
    total += tmp_a*tmp_c
# print(tmp_a,tmp_c_t)
# total += tmp_a*tmp_c_t
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()

ans = 0
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:
import bisect
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))
ans = 0
for i in b:
  a_ind = bisect.bisect_left(a,i)
  c_ind = bisect.bisect_right(c,i)
  ans += a_ind*(n-c_ind)
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 in b:
    x=bisect.bisect_left(a,i)
    y=n-bisect.bisect(c,i)
    ans+=x*y
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    x = bisect.bisect_left(A, B[i])
    y = N-bisect.bisect_right(C, B[i])
    ans += x*y
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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 j in b:
    ans += bisect.bisect_left(a,j)*(n-bisect.bisect_right(c,j))
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi
#import numpy as np
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

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 y in B:
    i = bisect_left(A, y)
    j = bisect_right(C,y)
    if i>0 and j != len(C):
      ans += i*(n-j)
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import bisect

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

ans=0
for j in range(N):
    a_num=bisect.bisect_left(A,B[j])
    c_num=bisect.bisect_right(C,B[j])
    # print(B[j],A[:a_num],C[c_num:])
    # print(a_num,c_num)
    ans+=a_num*(N-c_num)
print(ans)

Submission status: Accepted

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

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

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

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

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

print(res)

Submission status: Accepted

Solution code:
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

Submission status: Accepted

Solution code:
#20　AtCoder Beginner Contest 077 C - Snuke Festival
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for i in b:
    ans+= (bisect.bisect_right(a, i-1))*(n-bisect.bisect_left(c, i+1))
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
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()
    C.sort()
    ans=0
    for x in B:
        ans+=bisect_right(A,x-1)*(N-bisect_left(C,x+1))
    print(ans)    

if __name__ == '__main__':
    main()

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 bi in b:
    a_cnt = bisect.bisect_left(a, bi)
    c_cnt = N - bisect.bisect_right(c, bi)
    ans += a_cnt * c_cnt
    #print(a_cnt, c_cnt)

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

# def binary_search_left(arr, value):
#     left = 0
#     right = len(arr) - 1
#     if value < arr[left]:
#         return left
#     if value > arr[right]:
#         return right + 1
#     while left <= right:
#         mid = (left + right) // 2
#         if value > arr[mid]:
#             left = mid + 1
#         elif value < arr[mid]:
#             right = mid - 1
#         else:
#             # find the leftmost index
#             while arr[mid] == value:
#                 mid -= 1
#             return mid + 1
#     # left == right + 1, so arr[right] < value < arr[left]
#     return left

# def binary_search_right(arr, value):
#     left = 0
#     right = len(arr) - 1
#     if value < arr[left]:
#         return left
#     if value > arr[right]:
#         return right + 1
#     while left <= right:
#         mid = (left + right) // 2
#         if value > arr[mid]:
#             left = mid + 1
#         elif value < arr[mid]:
#             right = mid - 1
#         else:
#             # find the leftmost index
#             while arr[mid] == value:
#                 if mid == len(arr) - 1:
#                     return mid + 1
#                 mid += 1
#             return mid
#     # left == right + 1, so arr[right] < value < arr[left]
#     return left

# count = 0
# for bot in B:
#     # print(f"bot: {bot}")
#     index_A = binary_search_left(A, bot)
#     index_C = binary_search_right(C, bot)
#     # print(f"index_A: {index_A}, index_C: {index_C}")
#     count += index_A * (N - index_C)

# print(count)

count = 0
for bot in B:
    # print(f"bot: {bot}")
    index_A = bisect.bisect_left(A, bot)
    index_C = bisect.bisect_right(C, bot)
    # print(f"index_A: {index_A}, index_C: {index_C}")
    count += index_A * (N - index_C)

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

def binary_search_more_than(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return left
    if value > arr[right]:
        return None
    while left <= right:
        mid = int((left + right) / 2)
        if value > arr[mid]:
            left = mid + 1
        elif value < arr[mid]:
            right = mid - 1
        else:
            return mid + 1
    # left == right + 1, so arr[right] < value < arr[left]
    return left

def binary_search_less_than(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return None
    if value > arr[right]:
        return right
    while left <= right:
        mid = int((left + right) / 2)
        if value > arr[mid]:
            left = mid + 1
        elif value < arr[mid]:
            right = mid - 1
        else:
            return mid - 1
    # left == right + 1, so arr[right] < value < arr[left]
    return right

# count = 0
# if N == 1:
#     if A[0] < B[0] < C[0]:
#         count += 1
# else:
#     for bot in B:
#         index_A = binary_search_less_than(A, bot)
#         index_C = binary_search_more_than(C, bot)
#         # print(f"index_A: {index_A}")
#         # print(f"index_C: {index_C}")
#         if index_A != None and index_C != None:
#             count += (index_A + 1) * (N - index_C)

# print(count)

count = 0
for bot in B:
    i_A = bisect.bisect_left(A, bot)
    i_C = bisect.bisect_right(C, bot)
    count += i_A * (N - i_C)
print(count)

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

total = 0
for i in b:
  index_a = bisect.bisect_right( a, i-1 )
  index_c = n - bisect.bisect_left( c, i+1 )
  total += index_a * index_c
print(total)

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

import bisect
ans = 0
for i in b:
    A = bisect.bisect_left(a, i)
    C = n - bisect.bisect_right(c, i)
    ans += A * C
    
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

print(ans)

Submission status: Accepted

Solution code:
def binary_search(A,x,flag):
  start = 0
  end = len(A)-1
  
  while start < end:
    middle = (start + end) // 2
    if flag:# Aの時
      if A[middle] < x <= A[middle+1]:
        return middle + 1
      elif x <= A[middle]:
        end = middle
      else:
        start = middle + 1
    else:# Bの時
      if A[middle] <= x < A[middle+1]:
        return middle + 1
      elif x < A[middle]:
        end = middle
      else:
        start = middle + 1
  if end == 0: # 小さい
    return 0
  elif start == len(A)-1:
    return len(A)
        
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

# N=1はコーナーケース
if N == 1:
  print(1) if A[0] < B[0] < C[0] else print(0)
else:
  ans = 0
  for i in range(N):
    ans += binary_search(A,B[i],True)*(N-binary_search(C,B[i],False))#B[i]より小さいAの数とB[i]より大きいCの数の積
  print(ans)

Submission status: Accepted

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

t1 = list(map(int,input().split()))

t2 = list(map(int,input().split()))

t3 = list(map(int,input().split()))

t1.sort()

t3.sort()

ans = 0

for i in t2:
    ans += bisect.bisect_left(t1,i)*(n-bisect.bisect_right(t3,i))
print(ans)

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

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

print(ans)

Submission status: Accepted

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

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

bc_cum = [0]*n
bc_num = [0]*n

def bs(ls, x, n):
  l = -1; r = n-1
  while l+1<r:
    m = (l+r)//2
    if ls[m]<=x: l = m
    else: r = m
  if ls[r]>x:return r
  else: return n
  
for i in range(n-1, -1, -1):
  c_idx = bs(c, b[i], n)
  #print(b[i], c_idx)
  bc_num[i] = n-c_idx
  if i==n-1:
    bc_cum[i] = bc_num[i]
  else:
    bc_cum[i] = bc_num[i] + bc_cum[i+1]

ans = 0
for i in range(n):
  b_idx = bs(b, a[i], n)
  if b_idx<n:
    ans += bc_cum[b_idx]

print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a,b,c = [list(sorted(map(int, input().split())))  for _ in range(3)]

ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    y = len(c) - bisect.bisect_right(c, i)
    ans += x*y

print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a,b,c = [list(sorted(map(int, input().split())))  for _ in range(3)]

ans = 0
for i in range(n):
    x = bisect.bisect_left(a, b[i])
    y = len(c) - bisect.bisect_right(c, b[i])
    ans += x*y
print(ans)

Submission status: Accepted

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

ans = 0
for _b in b:
    _a = bisect.bisect_left(a, _b)
    _c = bisect.bisect_right(c, _b)

    ans += _a*(len(c)-_c)

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
B.sort()
C.sort()
a = [0] * N
for i in range(N):
	a[i] = N - bisect.bisect_right(C, B[i])
i = N - 1
while 0 < i:
	a[i - 1] += a[i]
	i -= 1
ans = 0
for i in A:
	b = bisect.bisect_right(B, i)
	if b == N:
		continue
	ans += a[b]
print(ans)