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: Wrong Answer

Solution code:
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()



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

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#　二分探索
# def is_ok(arg):
#     # 条件を満たすかどうか？問題ごとに定義
#     pass


# def meguru_bisect(ng, ok):
#     '''
#     初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
#     まずis_okを定義すべし
#     ng ok は  とり得る最小の値-1 とり得る最大の値+1
#     最大最小が逆の場合はよしなにひっくり返す
#     '''
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if is_ok(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

#ここから書き始める
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()

def is_ok(index, key, x):
    if x[index] >= key:
        return True
    return False

def meguru_bisect(ng, ok, key, x):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid, key, x):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
# print("a =", a)
# print("b =", b)
# print("c =", c)

for i in b:
    total1 = 0
    total2 = 0
    if i <= a[0] or c[-1] <= i:
        continue
    if i > a[-1]:
        total1 = n
    else:
        total1 = meguru_bisect(-1, n, i, a)
    if i < c[0]:
        total2 = n
    else:
        total2 = n - meguru_bisect(-1, n, i, c)
        if i == c[meguru_bisect(-1, n, i, c)]:
            total2 -= 1
    ans += total1 * total2
    # print(total1, total2)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#　二分探索
# def is_ok(arg):
#     # 条件を満たすかどうか？問題ごとに定義
#     pass


# def meguru_bisect(ng, ok):
#     '''
#     初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
#     まずis_okを定義すべし
#     ng ok は  とり得る最小の値-1 とり得る最大の値+1
#     最大最小が逆の場合はよしなにひっくり返す
#     '''
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if is_ok(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

#ここから書き始める
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()

def is_ok(index, key, x):
    if x[index] >= key:
        return True
    return False

def meguru_bisect(ng, ok, key, x):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid, key, x):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0
# print("a =", a)
# print("b =", b)
# print("c =", c)

for i in b:
    total1 = 0
    total2 = 0
    if i > a[0]:
        total1 = meguru_bisect(-1, n, i, a)
    if i < c[-1]:
        total2 = n - meguru_bisect(-1, n, i, c)
        if i == c[meguru_bisect(-1, n, i, c)]:
            total2 -= 1
    ans += total1 * total2
    # print(total1, total2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [(int(i), 0) for i in input().split()]
b = [(int(i), 1) for i in input().split()]
c = [(int(i), 2) for i in input().split()]

d = {}
for i, j in sorted(a + b + c):
    if i in d:
        d[i].append(j)
    else:
        d[i] = [j]


x = 0
y = 0
z = 0

for i in d:
    xx = x
    yy = y

    for j in d[i]:
        if j == 0:
            x = x + 1
        elif j == 1:
            y += xx
        else:
            z += yy

print(z)

Submission status: Wrong Answer

Solution code:
def binary_search_a(c1, c2):
    global i
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if a[m] < i:
            c1 = m
        else:
            c2 = m
        return binary_search_a(c1, c2)

def binary_search_c(c1, c2):
    global i
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if c[m] > i:
            c1 = m
        else:
            c2 = m
        return binary_search_c(c1, c2)

n = int(input())
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = (sorted(list(map(int, input().split()))))
c.reverse()
ans = 0
for i in b:
    ans += binary_search_a(0, n) * binary_search_c(0, n)
print(ans)

Submission status: Wrong Answer

Solution code:
#二分探索
from bisect import bisect_left
from bisect import bisect_right
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
ans = 0
for i in range(N):
    ab = bisect_left(A,B[i])
    bc = N-bisect_right(C,B[i])
    print(ab, end='  ')
    print(bc)
    ans += ab*bc
print(ans)

Submission status: Wrong Answer

Solution code:
#二分探索
from bisect import bisect_left
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
Bis_B = []
for i in range(N):
    Bis_B.append(bisect_left(A,B[i]))
Sum_B = []
print(Bis_B)
for i in range(N):
    Sum_B.append(sum(Bis_B[:i+1]))
print(Sum_B)

ans = 0
for i in range(N):
    M = bisect_left(B, C[i])
    if M == 0: #この文で余分な動作を少し減らせる
        continue
    ans += Sum_B[M-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for j in B:
    OK = -1
    NG = N
    while abs(OK-NG) > 1:
        mid = (OK + NG) // 2
        if A[mid] < j:
            OK = mid
        else:
            NG = mid
    A_ko = mid
        
    NG = -1
    OK = N
    while abs(NG-OK) > 1:
        mid = (NG + OK) // 2
        if C[mid] > j:
            NG = mid
        else:
            OK = mid
    C_ko = N - mid 
    ans += A_ko*C_ko
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for j in B:
    OK = -1
    NG = N
    while abs(OK-NG) > 1:
        mid = (OK + NG) // 2
        print(mid)
        if A[mid] < j:
            OK = mid
        else:
            NG = mid
    A_ko = mid
        
    NG = -1
    OK = N
    while abs(NG-OK) > 1:
        mid = (NG + OK) // 2
        if C[mid] > j:
            NG = mid
        else:
            OK = mid
    C_ko = N - mid 
    ans += A_ko*C_ko
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for j in B:
    OK = -1
    NG = N
    while abs(OK-NG) > 1:
        mid = (OK + NG) // 2
        print(mid)
        if A[mid] < j:
            OK = mid
        else:
            NG = mid
    A_ko = mid
        
    NG = -1
    OK = N
    while abs(NG-OK) > 1:
        mid = (NG + OK) // 2
        if C[mid] > j:
            NG = mid
        else:
            OK = mid
C_ko = mid 
ans += A_ko*C_ko
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

if __name__ == "__main__":
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    BB = []
    CC = []

    print(A)
    print(B)
    print(C)
    print('-------')

    cnt = 0

    for i in range(N):
        b = B[i]
        a_index = bisect.bisect_left(A, b)
        if i == 0:
            BB.append(a_index)
        else:
            BB.append(BB[i-1] + a_index)

    for i in range(N):
        c = C[i]
        b_index = bisect.bisect_left(B, c)
        if b_index == 0:
            CC.append(0)
            continue
        if i == 0:
            CC.append(BB[b_index - 1])
        else:
            CC.append(CC[i-1] + BB[b_index - 1])

    # print(BB)
    # print(CC)

    print(CC[-1])

Submission status: Wrong Answer

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])
    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 
#        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: Wrong Answer

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(down_bin(i,a),up_bin(i,c))
print(ans)

Submission status: Wrong Answer

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=0
    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-1
    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: Wrong Answer

Solution code:
def bs(l, n):
    left = 0
    right = len(l) - 1
    a = -1
    while True:
        if right < left:
            break

        m = (left + right) // 2
        if l[m] == n:
            return len(l) - m - 1
        if l[m] < n:
            left = m + 1
        else:
            a = len(l) - m
            right = m - 1

    return max(a, 0)


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

ab = []
for ai in a:
    ab.append(bs(b, ai))

bc = []
for bi in b:
    bc.append(bs(c, bi))

bcs = [0]
for i in range(n):
    bcs.append(bcs[i] + bc[~i])

print(sum(bcs[abi] for abi in ab if abi))

Submission status: Wrong Answer

Solution code:
inp=lambda:list(map(int,input().split()))
import bisect as bi
n=int(input())
a=inp()
b=inp()
c=inp()
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: Wrong Answer

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_right(a_list,b)
  sita = len(c_list) - bisect.bisect_left(c_list,b)
  counter += ue * sita
print(counter)

Submission status: Wrong Answer

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: Wrong Answer

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

def bi_len(list,max_item):
    low = 0
    high = len(list)-1
    while low <= high:
        mid = (low+high)//2
        if(mid == len(list)-1):
            if (list[mid]<= max_item):
                return len(list[:mid])+1,list[mid]
        elif((list[mid+1]>= max_item) and list[mid]< max_item):
                return len(list[:mid])+1,list[mid]
        elif (list[mid] < max_item):
            low = mid + 1
        elif (list[mid] > max_item):
            high = mid - 1
    return False,False
total = 0
for i,c in enumerate(C):
    B_len,max_b = bi_len(B,c)
    #print(c,B_len,max_b)
    if (B_len is not False):
        A_len,max_a = bi_len(A,max_b)
        if(A_len is not False):
            total += 1*A_len*B_len
print(total)

Submission status: Wrong Answer

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
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: Wrong Answer

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

Submission status: Wrong Answer

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(a,b[i])*(n-bisect.bisect(c,b[i]))
print(ans)

Submission status: Wrong Answer

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):
  pass
print('tle test')

Submission status: Wrong Answer

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

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(list(set(A)))
B = sorted(list(set(B)))
C = sorted(list(set(C)))
# 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: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

def binary_search_lower_bound(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return left
    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
    # left == right + 1, so arr[right] < value < arr[left]
    return left

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

Submission status: Wrong Answer

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

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)
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

def binary_search_lower_bound(arr, value):
    left = 0
    right = len(arr) - 1
    if value <= arr[left]:
        return left
    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
    # left == right + 1, so arr[right] < value < arr[left]
    return left

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

Submission status: Wrong Answer

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

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)
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

# def binary_search_lower_bound(arr, value):
#     left = 0
#     right = len(arr) - 1
#     if value <= arr[left]:
#         return left
#     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
#     # left == right + 1, so arr[right] < value < arr[left]
#     return left

def binary_search_more_than(arr, value):
    left = 0
    right = len(arr) - 1
    if value < arr[left]:
        return left
    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 left

count = 0
alters = []
for top in A:
    # print(f"\ntop: {top}")
    index_B = binary_search_more_than(B, top)
    B_bin = B[index_B:]
    # print(f"B_bin: {B_bin}")
    for mid in B_bin:
        # print(f"mid: {mid}")
        index_C = binary_search_more_than(C, mid)
        C_bin = C[index_C:]
        # print(f"C_bin: {C_bin}")
        count += len(C_bin)

print(count)

Submission status: Wrong Answer

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

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: Wrong Answer

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()
#b.sort(reverse=True)
#c.sort()
ans = 0
A = []
bs = []
for i in range(n):
  A.append(sum(x>a[i] for x in b))
for i in range(n):
  bs.append(sum(x>b[i] for x in c))
bs.sort(reverse=True)
ans = 0
for i in range(n):
	if A[i] > 1:
		ans += sum(bs[:A[i]-1])
print(ans)

Submission status: Wrong Answer

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()
from bisect import bisect_left
ans=0
for b in b:
    aa=bisect_left(a,b)
    cc=bisect_left(c,b)
    ans+=aa*(n-cc)
print(ans)