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: Runtime Error

Solution code:


# index が条件をみたかどうか
def isLess(index, key, a):
    if a[index] >= key:
        return True
    else: return False

def isUpper(index, key, a):
    if a[index] > key:
        return True
    else: return False

# 汎用的な二分探索のテンプレ
def binary_search(key, a, upper=True):
    left : int = -1 # index = 0 が条件を満たすこともあるので初期値は−１
    right : int = len(a) # index = len(a) -1 が条件満たさないこともある

    # どんな二分探索でもここの書き方を変えずにできる
    while right - left > 1 :
        mid = left + ((right - left + 1) // 2)
        if upper:
            if isUpper(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
        else:
            if isLess(mid, key, a): # isOKの名前でこの関数内の条件判定変えれば色々できそう
                right = mid
            else:
                left = mid
    return right

def main():
    n = int(input())
    a_l = sorted(list(map(int, input().split())))
    b_l = sorted(list(map(int, input().split())))
    c_l = sorted(list(map(int, input().split())))
    cnt = 0
    for b in b_l:
        a_under_b_idx : int = binary_search(b, a_l, upper=False)
        c_upper_b_idx : int = binary_search(b, c_l)
        cnt += len(a_l[:a_under_b_idx])*len(c_l[c_upper_b_idx:])
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)

Submission status: Runtime Error

Solution code:
# AtCoder Beginner Contest 077 C - Snuke Festival　

import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)


def search(i, S):  # i : search する数値  S: search対象の数列
    if S[0] > i:
        return len(S)
    if S[-1] < i:
        return 0

    left = 0
    right = len(S) - 1

    while right - left != 1:
        print(f'right:{right}, left:{left}')
        mid = int((left + right) / 2)
        if S[mid] < i:
            left = mid
        else:
            right = mid

    return len(S) - (left + 1)


ans = 0
for a in A:
    b_num = search(a, B)
    if b_num == 0:
        continue
    for b in B[-b_num:]:
        # print(f'a: {a}, b: {b}')
        c_num = search(b, C)
        # print(f'c_num: {c_num}')
        ans += c_num

print(ans)

Submission status: Runtime Error

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

import bisect
a.sort()
b.sort()
c.sort()
ans = 0

comb = []
for i in range(len(b)):
    key = bisect.bisect_left(c,b[i]+1)
    comb.append(len(c) -key)
comb.append(0)
combsum = []
for i in range(comb):
    x = sum(comb[i:])
    combsum.append(x)
for A in a:
    key_b = bisect.bisect_left(b,A+1)
    ans += combsum[key_b]
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
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())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
print(cnt)

Submission status: Runtime Error

Solution code:
def solve(n, a, b, c):

    b_count = [0]*len(b)
    for i, x in enumerate(b):
        b_count[i] = len(c) - find_ge(c, x)

    ans = 0
    for i in a:
        x = find_ge(b, i)
        ans += sum(b_count[x:])
        
    return ans

if __name__ == "__main__":
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    b = sorted([int(i) for i in input().split()])
    c = sorted([int(i) for i in input().split()])
    print(solve(n, a, b, c))

Submission status: Runtime Error

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

Submission status: Runtime Error

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, x)
    b = bisect.bisect_right(C, x)
    ans += (a + 1)*b 

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
def main():
  from builtins import input, int, map
  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()
  n = int(math.log2(N))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = N - right
    ans += a*c
  print(ans)
main()

Submission status: Runtime Error

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


bi = bisect.bisect_right

result = 0
for i in range(n):
    a_bi_in_b = bi(b, a[i])
    b_bi_in_c = bi(c, b[a_bi_in_b])
    result += (n - a_bi_in_b) * (n - b_bi_in_c)
        
        
print(result)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-B)
print(ans)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    long long int N,ans,mid;
    cin >> N;

    vector<long long int> A(N,0),B(N,0),C(N,0);
    for (int i=0;i<N;i++) cin >> A[i];
    for (int i=0;i<N;i++) cin >> B[i];
    for (int i=0;i<N;i++) cin >> C[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    for(int i=0 ; i<N ; i++){
        mid = B[i];
        auto low = lower_bound(A.begin(), A.end(), mid)- A.begin();
        auto upp = C.end() - upper_bound(C.begin(),C.end(),mid);
        ans += low*upp;
    }
    cout << ans << endl;
    return 0;

}

Submission status: Runtime Error

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

def binary_search1(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return 0
    
    if num_list[-1] < target:
        return(len(num_list))
    
    for i in range(10000000):

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target >= left[-1] and right[0] > target:
            ans_counter += len(left)
            return ans_counter

        elif target < left[-1]:
            num_list = left
    
        elif right[0] <= target:
            ans_counter += len(left)
            num_list = right

def binary_search2(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return 0
    
    if num_list[-1] < target:
        return(len(num_list))
    
    for i in range(10000000):

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target > left[-1] and right[0] >= target:
            ans_counter += len(left)
            return ans_counter

        elif target <= left[-1]:
            num_list = left
    
        elif right[0] < target:
            ans_counter += len(left)
            num_list = right

ans = 0
#for C in Clist:
#    b_point = 0
#    b_point =  binary_search(Blist, C)

#    if b_point >= 0:
#        for B in Blist[:b_point]:
#            a_point =  binary_search(Alist, B)
#            print(B,C,a_point) 
#            ans += (a_point)

for B in Blist:
    a_point = binary_search2(Alist, B)
    c_point = binary_search1(Clist, B)
#    print(B,a_point, c_point, Clist.count(B))

    ans = ans + a_point * (N - c_point)

print(ans)
#for C in Clist:

Submission status: Runtime Error

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

def binary_search1(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return -1
    
    if num_list[-1] < target:
        return(len(num_list))
    
    while True:

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target >= left[-1] and right[0] > target:
            ans_counter += len(left)
            return ans_counter

        elif target < left[-1]:
            num_list = left
    
        elif right[0] <= target:
            ans_counter += len(left)
            num_list = right

def binary_search2(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return -1
    
    if num_list[-1] < target:
        return(len(num_list))
    
    while True:

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target > left[-1] and right[0] >= target:
            ans_counter += len(left)
            return ans_counter

        elif target <= left[-1]:
            num_list = left
    
        elif right[0] < target:
            ans_counter += len(left)
            num_list = right

ans = 0
#for C in Clist:
#    b_point = 0
#    b_point =  binary_search(Blist, C)

#    if b_point >= 0:
#        for B in Blist[:b_point]:
#            a_point =  binary_search(Alist, B)
#            print(B,C,a_point) 
#            ans += (a_point)

for B in Blist:
    a_point = binary_search2(Alist, B)
    c_point = binary_search1(Clist, B)
#    print(B,a_point, c_point, Clist.count(B))

    ans = ans + a_point * (N - c_point)

print(ans)
#for C in Clist:

Submission status: Runtime Error

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 n in range(N):
        a = A[n]
        bc = bisect.bisect_left(B, a)
        if len(B) == bc: continue
        if a == B[bc]: bc += 1
        for b in B[bc:]:
            cc = bisect.bisect_left(C, b)
            if b == C[cc]: cc += 1
            ret += len(C) - cc

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = list(map(int, input()))
b = list(map(int, input()))
c = list(map(int, input()))
a.sort()
ans = 0
for i in b:
  d = bisect.bisect_left(a, i)
  e = bisect.bisect_right(c, i)
  if d > 0 and e < len(c):
    ans += d*(n-e)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import collections

readline = sys.stdin.readline

def myindex(t, x, default=-1):
    if x in t:
        return t.index(x)
    else:
        return default


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

    lenB = len(B)
    log2lenB = int(math.log2(lenB))

    A.sort()
    C.sort()

    countAlist = list(zip(*list(collections.Counter(A).items())))
    countClist = list(zip(*list(collections.Counter(C).items())))

    #print(countClist)

    sumAlist = [0] * (max(A)+1)
    sumClist = [0] * (max(C)+1)

    for i in range(max(A)+1):
        index = myindex(countAlist[0], i)
        sumAlist[i] = sumAlist[i-1] + (index >= 0) * countAlist[1][index]

    for i in range(max(C)+1):
        j = max(C) - i + 1
        index = myindex(countClist[0], j)
        sumClist[i] = sumClist[i-1] + (index >= 0) * countClist[1][index]

    ans = 0

    for i in range(lenB):
        target = B[i]
        upper = lenB - 1
        lower = 0
        middle = (upper + lower) // 2

        for _ in range(log2lenB+1):
            if target > max(A):
                lower = len(A) - 1
                break
            if target == A[middle]:
                lower = middle - 1
                break
            elif target < A[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2 + 1
        
        ansA = sumAlist[A[lower]]
        #print('A:{} B:{} C:{}'.format(A, B, C))
        #print('A:{} B:{}, ansA:{}'.format(A[lower], target, ansA))

        upper = lenB - 1
        lower = 0
        middle = (upper + lower) // 2

        for _ in range(log2lenB+1):
            if target == C[middle]:
                upper = middle + 1
                break
            elif target < C[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2

        ansC = sumClist[-C[upper]]
        #print('B:{} C:{}, ansC:{}'.format(target, C[upper], ansC))
        ans += ansA * ansC


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
import collections

readline = sys.stdin.readline

def myindex(t, x, default=-1):
    if x in t:
        return t.index(x)
    else:
        return default


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

    lenB = len(B)
    log2lenB = int(math.log2(lenB))

    A.sort()
    C.sort()

    countAlist = list(zip(*list(collections.Counter(A).items())))
    countClist = list(zip(*list(collections.Counter(C).items())))

    #print(countClist)

    sumAlist = [0] * (max(A)+1)
    sumClist = [0] * (max(C)+1)

    for i in range(max(A)+1):
        index = myindex(countAlist[0], i)
        sumAlist[i] = sumAlist[i-1] + (index >= 0) * countAlist[1][index]

    for i in range(max(C)+1):
        j = max(C) - i + 1
        index = myindex(countClist[0], j)
        sumClist[i] = sumClist[i-1] + (index >= 0) * countClist[1][index]

    ans = 0

    for i in range(lenB):
        target = B[i]
        upper = lenB - 1
        lower = 0
        middle = (upper + lower) // 2

        for _ in range(log2lenB+1):
            if target > max(A):
                lower = len(A) - 1
                break
            if target == A[middle]:
                lower = middle - 1
                break
            elif target < A[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2 + 1
        
        ansA = sumAlist[A[lower]]
        print('A:{} B:{} C:{}'.format(A, B, C))
        print('A:{} B:{}, ansA:{}'.format(A[lower], target, ansA))

        upper = lenB - 1
        lower = 0
        middle = (upper + lower) // 2

        for _ in range(log2lenB+1):
            if target == C[middle]:
                upper = middle + 1
                break
            elif target < C[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2

        ansC = sumClist[-C[upper]]
        print('B:{} C:{}, ansC:{}'.format(target, C[upper], ansC))
        ans += ansA * ansC


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import bisect

def snuke_festival(N,arr):
    n_pair = 0
    for item in arr[1]:
        up_pair = bisect.bisect(arr[0],item)
        dowm_pair = bisect.bisect_right(arr[2],item)
        n_pair += up_pair*down_pair
    return n_pair


if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))
    arr_sorted = []
    for j in range(3):
        arr_sorted.append(arr[j].sort())
    print(snuke_festival(N,arr))

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]

for b in ABC[1]:
  ans += bisect.bisect_left(ABC[0],b)*(N-bisect.bisect_right(ABC[2],b))
print(ans)

Submission status: Runtime Error

Solution code:
vn=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort() ; B.sort() ; C.sort()
import bisect as bi

ans=0

for i in B:
    ans+= bi.bisect_left(A,i) * (n-bi.bisect_right(C,i))
print(ans)

Submission status: Runtime Error

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

alters_count = 0
for a in A:
    count += 1
    bidx = bisect.bisect_left(B, a)
    if bidx == N:
        continue
    for b in B[bidx:]:
        count += 1
        cidx = bisect.bisect_left(C, b)
        if cidx == N:
            continue
        alters_count += N - cidx

print(alters_count)

Submission status: Runtime Error

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

print(A)
print(B)
print(C)

ans = 0
for i in range(n):
  canB = bisect.bisect_right(B, A[i])
  if canB == n:
    continue
  else:
    for j in range(canB, n):
      canC = bisect.bisect_right(C, B[j])
      ans += (n - canC)
      print(A[i], B[j], C[canC], (n - canC))
print(ans)

Submission status: Runtime Error

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)


def is_ok(array, index, value):
    if array[index] >= value:
        return True
    return False


def bs_general(array, value, is_ok):
    left = -1
    right = len(array)
    while abs(right - left) > 1:
        mid = (left + right) // 2
        if is_ok(array, mid, value):
            right = mid
        else:
            left = mid
    return right


res = 0
for b in B:
    index_a = bs_general(A, b, is_ok)
    index_c = bs_general(C, b, is_ok)
    if C[index_c] == b:
        res += index_a * (N - index_c - 1)
    else:
        res += index_a * (N - index_c)

print(res)

Submission status: Runtime Error

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 range(N):
    upi = bisect.bisect_left(A, B[i])
    dwi = bisect.bisect_left(C, B[i])
    if C[dwi] == B[i]:
        dwi = bisect.bisect_left(C, B[i] + 1)
    ans += upi*(N - dwi)

print(ans)

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()
INDEX_KETA = 10**12

def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is None:
        return

    if isinstance(ans, tuple):
        split_print_space(ans)


def solve():

    N = iip()
    A = iip()
    B = iip()
    C = iip()

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

    def ruisekiwa(l):
        ret = []
        cur = 0
        for i in l:
            cur += i
            ret.append(cur)
        return ret



    nb = [bisect_left(A, i) for i in B]
    snb = ruisekiwa(nb)

    #print(A)
    #print(B)
    #print(C)

    #print("")
    #print(nb)
    #print(snb)

    id = [bisect_right(B, i-1) -1 for i in C]
    id = [i for i in id if i != -1]
    nc = [snb[min(i, len(B)-1)] for i in id]

    #print(nc)
    #print(id)

    print(sum(nc))




#####################################################ライブラリ集ここから



def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=False):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    if isinstance(l, list):
        l = l[0] # 間違って要素１個のタプルを渡されても受け取る
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def index_sorted(sorted_list, target):
    idx = bisect_left(sorted_list, target)
    if idx != len(sorted_list) and sorted_list[idx] == target:
        return idx
    else:
        return False


def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                #for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
# import numpy as np

import bisect

def main():
	N=II()
	A=LI()
	B=LI()
	C=LI()
	A.sort()
	B.sort()
	C.sort()
	BB=[0]*N
	ans=0
	for i,b in enumerate(B):
		BB[i]=N-bisect.bisect_right(C,b)

	for i in range(N-2,-1,-1):
		BB[i]+=BB[i+1]
		BB.append(0)
	for a in A:
		ans+=BB[bisect.bisect_right(B,a)]
	print(ans)



if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
from bisect import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
A = sorted(list(map(int,input().split())))
A = sorted(list(map(int,input().split())))
count = 0
for i in range(N):
    minb = bisect(B, A[i])
    if minb == N:
        break
    for j in range(minb, N):
        if B[j] == A[i]:
            continue
        minc = bisect(C, B[j])
        if minc == N:
            break
        count += N - minc
print(count)

Submission status: Runtime Error

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
        
    left_f = -1
    right_t = N+1
    while abs(left-right) > 1:
        mid = (left + right) // 2
        if C[mid] > j:
            left_f = mid
        else:
            right_t = mid
C_ko = mid 
ans += A_ko*C_ko
print(ans)