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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    B = getIntList()
    d.dmp((B), 'B')
    C = getIntList()
    d.dmp((C), 'C')
    aParts = sorted(A)
    bParts = sorted(B)
    cParts = sorted(C)
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    combAB = zeros(N)  # Aのi番めのパーツが組み合わせられる数
    combBC = zeros(N)
    j = 0
    for i in range(N):
        while j < N and bParts[j] <= aParts[i]:
            j += 1
            #d.dmp((i,j),'in while')
        combAB[i] = N-j
        #d.dmp((i,j),'in for')
    d.dmp((combAB), 'combAB')
    j = 0
    for i in range(N):
        while j < N and cParts[j] <= bParts[i]:
            j += 1
        combBC[i] = N-j
    d.dmp((combBC), 'combBC')
    sm = zeros(N)
    sm[-1] = combBC[-1]
    for i in range(1, N):
        sm[-1-i] = combBC[-1-i]+sm[-i]
    d.dmp((sm), 'sm')
    count = 0
    for i in range(N):
#        count += sum(combBC[N-combAB[i]:])
        count += sm[N-combAB[i]]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    B = getIntList()
    d.dmp((B), 'B')
    C = getIntList()
    d.dmp((C), 'C')
    aParts = sorted(A)
    bParts = sorted(B)
    cParts = sorted(C)
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    combAB = zeros(N)  # Aのi番めのパーツが組み合わせられる数
    combBC = zeros(N)
    j = 0
    for i in range(N):
        while j < N and bParts[j] <= aParts[i]:
            j += 1
            #d.dmp((i,j),'in while')
        combAB[i] = N-j
        #d.dmp((i,j),'in for')
    d.dmp((combAB), 'combAB')
    j = 0
    for i in range(N):
        while j < N and cParts[j] <= bParts[i]:
            j += 1
        combBC[i] = N-j
    d.dmp((combBC), 'combBC')
    sm = zeros(N)
    for i in range(N):
        sm[i] = sum(combBC[i:])
    d.dmp((sm), 'sm')
    count = 0
    for i in range(N):
#        count += sum(combBC[N-combAB[i]:])
        count += sm[N-combAB[i]]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
As = sorted(list(map(int,input().split())))
Bs = sorted(list(map(int,input().split())))
Cs = sorted(list(map(int,input().split())))
ans = 0
for a in As:
    bindex = bisect.bisect_right(Bs, a)
    for b in Bs[bindex:]:
        ans += len(Cs)-bisect.bisect_right(Cs, b)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from bisect import bisect
from itertools import accumulate

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

    Bn = [0] * N
    for i in range(N):
        b = B[i]
        m = bisect(C, b)
        Bn[i] = (N - m)

    Bn = list(accumulate(Bn[::-1]))[::-1]

    ans = 0
    for i in range(N):
        a = A[i]
        m = bisect(B, a)
        ans += Bn[m]

    print(ans)


if __name__ == '__main__':
    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()
c.sort()
ans = 0
for i in b:
  ans += bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)

Submission status: Runtime Error

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()
c.sort()
     
     
from bisect import bisect_left,bisect_right
ans = 0
for i in b:
    count_a = bisect_right(a,i)
    count_c = n - bisect_right(c,i)
    ans += count_a * count_c
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [0] + list(map(int, input().split())) #index alliginment
b = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
bp, cp = 1, 1
cana, canb = [0], [0] # a[i]に対して条件を満たすbの要素数と
                      # b[i]に対して条件を満たすcの要素数を保管
sumb = [0] # canbの末尾からn個の累積和
ans = 0
for i in range(1,n+1): # aの1~nまで
    while b[bp] <= a[i] and bp != n+1:
        bp += 1
    appending = n+1-bp if bp != n+1 else 0
    cana.append(appending)
for i in range(1,n+1):
    while c[cp] <= b[i] and cp != n+1:
        cp += 1
    appending = n+1-cp if cp != n+1 else 0
    canb.append(appending)
for i in range(1,n+1):
    sumb.append(sumb[-1]+canb[-i])
for i in range(1,n+1):
    ans += sumb[cana[i]]
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0

for i in range(n):
    Ac[i] = bisect.bisect_left(Ap, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(Cp, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp


count = 0
for i in range(n):
    count += Ac[i]*Cc[i]

print(count)

Submission status: Runtime Error

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

def quicksort(array):
    if len(array) < 2:
        return array        
    else:
        pivot = array[0]    
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]

        return quicksort(less) + [pivot] + quicksort(greater)

A = quicksort(A)
C = quicksort(C)

listAB = []
listBC = []
sum = 0
case = 0

for b in B:
    for a in A:
        if b > a:
            listAB.append([])
        elif b < a:
            break
    for c in C[::-1]:
        if b < c:
            listBC.append([])
        elif b > c:
            break
    case = len(listAB)*len(listBC)
    listAB = []
    listBC = []
    sum = sum + case

print(sum)

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

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1 + 1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2 + 1
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N - mid2)

print(total)

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
#A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
#C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
#A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
#C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = -1
    high = N
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
ma = min(a)
b = sorted([x for x in map(int, input().split()) if x > ma])
mb = min(b)
c = sorted([x for x in map(int, input().split()) if x > mb])
m = len(c)
ans = 0
for x in b:
    #挿入できる箇所を返す
    p = bisect.bisect_left(a, x)
    q = m - bisect.bisect_right(c, x)
    ans += p*q
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
#a = [list(map(int, input().split())) + [i] for i in range(n)]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(n):
    a.append([])
    b.append([])
    c.append([])
for i in range(n):
    a[i].append(A[i])
    a[i].append(2)
    b[i].append(B[i])
    b[i].append(1)
    c[i].append(C[i])
    c[i].append(0)
d = a + b + c
d.sort(key=lambda x:(x[0], x[1]))
lenli = []
allli = []
count = 0
for i in range(len(d)):
    if d[i][1] == 2:#a
        if lenli == []:
            lenli.append(1)
        else:
            lenli[-1] += 1
    elif d[i][1] == 1:#b
        if allli == []:
            allli.append(lenli[-1])
        else:
            allli[-1] += lenli[-1]
        allli.append(allli[-1])
        lenli.append(lenli[-1])
    elif d[i][1] == 0:#c
        if i != 0 and d[i - 1][1] == 1 and allli != []:
            count += allli[-2]
        elif allli == []:
            count += 0
        else:
            count += allli[-2]

print(count)

Submission status: Runtime Error

Solution code:

import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    #解法どおり書くとどれくらいでできるのか計測

    idxA = 0
    idxC = iN-1
    iAns = 0
    for idxB in range(iN):

        iB = aB[idxB]
        while idxA < iN and aA[idxA] < iB:
            idxA += 1
        idxA -= 1
        while 0 <= idxC  and aC[idxC] > iB:
            idxC -= 1
        idxC += 1
        if aA[idxA] >= iB or aC[idxC] <= iB:
            break
        else:
            iAns += (idxA + 1 )* (iN - idxC  )
    print(iAns)
解()

Submission status: Runtime Error

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

cnt = 0

for i in range(len(a)):
    A = a[i]
    j = 0
    while j < len(b):
        if A < b[j]:
            cnt += 1
            j += 1
            k = 0
            while k < len(c):
                if b[j] > c[k]:
                    cnt += 1
                    k += 1
        else:
            break
print(cnt)

Submission status: Runtime Error

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

cnt = 0

for i in range(len(a)):
    A = a[i]
    j = 0
    while j < len(b):
        if A < b[j]:
            cnt += 1
            j += 1
        else:
            break
		while k < len(c):
           if b > c:
               cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

N = int(input())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

An.sort()
Bn.sort()
Cn.sort()

# print(An)
# print(Bn)
# print(Cn)

# B
C_cnt = []
C_sum = 0
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            C_cnt.append(N - j)
            C_sum += N - j
            break
        else:
            j += 1

B_cnt = []
temp_sum = 0
for cnt in C_cnt:
    B_cnt.append(C_sum - temp_sum)
    temp_sum += cnt

A_cnt = 0
j = 0
for i in range(N):
    while j < N:
        if An[i] < Bn[j]:
            A_cnt += B_cnt[j]
            break
        else:
            j += 1

# print(C_cnt)
# print(B_cnt)
print(A_cnt)

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()
#A < B < C
def sarch(i, left, right, x, y):
    mid = (right + left) // 2
    if right - left < 3:
        return left, right
    elif x[i] <= y[mid]:
        sarch(i, left, mid, x, y)
    elif y[mid] <= x[i]:
        sarch(i, mid, right, x, y)
cnt_a = [0 for i in range(N)]
cnt_b = [0 for i in range(N)]


for i in range(N):
    sg = sarch(i, 0, N - 1, B, C)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if B[i] < C[j]:
            ans = 1
            break
    if ans == -1:
        j = N
    cnt_b[i] = N - j
ans_2 = 0    
for i in range(N):
    sg = sarch(i, 0, N - 1, A, B)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if A[i] < B[j]:
            ans = 1
            break
    if ans == 1:
        for k in range(j, N):
            ans_2 += cnt_b[k]
    cnt_a[i] = N - j
print(ans_2)

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()
#A < B < C
def sarch(i, left, right, x, y):
    mid = (right + left) // 2
    if right - left < 10:
        return left, right
    elif x[i] <= y[mid]:
        sarch(i, left, mid, x, y)
    elif y[mid] <= x[i]:
        sarch(i, mid, right, x, y)
cnt_a = [0 for i in range(N)]
cnt_b = [0 for i in range(N)]


for i in range(N):
    sg = sarch(i, 0, N - 1, B, C)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if B[i] < C[j]:
            ans = 1
            break
    if ans == -1:
        j = N
    cnt_b[i] = N - j
ans_2 = 0    
for i in range(N):
    sg = sarch(i, 0, N - 1, A, B)
    s = sg[0]
    g = sg[1]
    ans = -1
    for j in range(s, g + 1):
        if A[i] < B[j]:
            ans = 1
            break
    if ans == 1:
        for k in range(j, N):
            ans_2 += cnt_b[k]
    cnt_a[i] = N - j
print(ans_2)

Submission status: Runtime Error

Solution code:
#ABC077C
N=int(input())
#大きい順に# 並べる
A=sorted(list(map(int,input().split())), reverse=True)
B=sorted(list(map(int,input().split())), reverse=True)
C=sorted(list(map(int,input().split())), reverse=True)
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if j > 0:
        if B[i] == B[i-1]:
            C_under_B[i]=C_under_B[i-1]
            continue
    for j in range(N):
        if C[j]>B[i]:
            C_under_B[i]+=1
        else:       #C[j+1]>C[j]>B[i]なので検討を中止する
            break
#あるAの下にいくつBが入るか数える
B_under_A=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if j > 0:
        if A[i] == A[i-1]:
            B_under_A[i]=B_under_A[i-1]
            continue
    for j in range(N):
        if B[j]>A[i]:
            B_under_A[i]+=1
        else:       #B[j+1]>B[j]>A[i]なので検討を中止する
            break
#あるAのもとに入るBのもとに入るCを数える
C_under_B_under_A=[0]*N
for i in range(N):
    C_under_B_under_A[i]=sum([C_under_B[j] for j in range(B_under_A[i])])
#出力
print(sum(C_under_B_under_A))

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

res = 0
for b in B:
    bisect_index_A = bisect.bisect_left(A, b)
    bisect_index_C = bisect.bisect_right(C, b)
    res += insert_index_A * (N - insert_index_C)
    
print(res)

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

res = 0
for b in B:
    insert_index_A = bisect.bisect_left(A, b)
    insert_index_C = bisect.bisect_right(C, b)
    res += insert_index_A * (N - insert_index_C)
    
print(res)

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

def binary_search(list,target,b):
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:
            if b:
                while list[center]==target:
                    center+=1
            return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1

    if list[center]<target:
        center+=1
    return center

A.sort()
C.sort()
ans=0
for b in B:
    ans+=binary_search(A,b,0)*(len(C)-binary_search(C,b,1))
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 = A.sort()
B = B.sort()
C = C.sort()
Sum = 0
for i in range(N):
    Start_B = bisect.bisect_left(B,A[i]+1)
    for j in range(Start_B, N):
        Start_C = bisect.bisect_left(C,B[j]+1)
        Sum += N - Start_C
print(Sum)

Submission status: Runtime Error

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()]res = 0
cnt_a = 0
cnt_c = 0
for b in B:
    for ca in range(cnt_a, N):
        if A[ca] >= b:
            cnt_a = ca
            break
        if ca == N-1:
            if A[ca] < b:
                ca = N
                cnt_a = N
                break

    for cc in range(cnt_c, N):
        if C[cc] > b:
            cnt_c = cc
            break
        if cc == N-1:
            if b > C[cc]:
                cc = N
                cnt_c = N
                break
    res += (N - cc) * ca
print(res)

Submission status: Runtime Error

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (r-l)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x, l=0):
    return searchsub(arr, x, l, len(arr))

    
    
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)

s = 0

for i in range(n):
    t = search(b, a[i], t)
    left = 0
    for j in range(t, n):
        if (left < n):
            left =  search(c, b[j], left)
            s += n-left


print(s)

Submission status: Runtime Error

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (r-l)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x, l=0):
    return searchsub(arr, x, l, len(arr))

    
    
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)

s = 0

for i in range(n):
    t = search(b, a[i])
    left = 0
    for j in range(t, n):
        left =  search(c, b[j], left)
        s += n-left
        
        
print(s)

Submission status: Runtime Error

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (l+r)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x):
    return searchsub(arr, x, 0, len(arr))

    
    
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)

s = 0

for i in range(n):
    t = search(b, a[i])
    for j in range(t, n):
        s += n - search(c, b[j])
        
print(s)

Submission status: Runtime Error

Solution code:
def mergesortsub(a, b):
    i = 0
    j = 0
    merged = []
    while i<len(a) or j<len(b):
        if i == len(a):
            merged.append(b[j])
            j += 1
        elif j == len(b):
            merged.append(a[i])
            i += 1
        elif a[i]<b[j]:
            merged.append(a[i])
            i += 1
        else:
            merged.append(b[j])
            j += 1
    return merged

def mergesort(a):
    if len(a)==1:
        return a
    else:
        l = len(a)//2
        return mergesortsub(mergesort(a[0:l]), mergesort(a[l:len(a)]))


def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (l+r)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x):
    return searchsub(arr, x, 0, len(arr))

    
    
n = int(input())

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

a = mergesort(a)
b = mergesort(b)
c = mergesort(c)

s = 0

for i in range(n):
    t = search(b, a[i])
    for j in range(t, n):
        s += n - search(c, b[j])
        
print(s)

Submission status: Runtime Error

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())))
x = 0

B = b[:]

for i in a:
    while B[0] <= i:
        del B[0]
        if B == []:
            break
    C = c[:]
    if B == []:
        break
    for j in B:
        while C[0] <= j:
            del C[0]
        x += len(C)

print(x)

Submission status: Runtime Error

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())))
x = 0

B = b

for i in a:
    while B[0] <= i:
        del B[0]
    C = c[:]
    for j in B:
        while C[0] <= j:
            del C[0]
        x += len(C)

print(x)

Submission status: Runtime Error

Solution code:
# vim: set fileencoding=utf-8 :
import bisect


def main():
    n = int(raw_input())
    A = sorted(map(int, raw_input().split()))
    B = sorted(map(int, raw_input().split()))
    C = sorted(map(int, raw_input().split()))
    BC = [0] * n
    ans = 0

    for bj in range(n):
        idx = bisect.bisect_left(C, B[bj])
        if B[bj] == C[idx]:
            idx += 1

        BC[bj] = n - idx

    print(A)
    print(B)
    for ai in range(n):
        idx = bisect.bisect_left(B, A[ai])
        if A[ai] == B[idx]:
            idx += 1

        print(BC[idx:])
        ans += sum(BC[idx:])

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect, functools, sys
sys.setrecursionlimit(10**6)
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())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

b_cache = [0] * N
b_cached = [False] * N
def b_i(i):
    if i >= 1:
        if not b_cached[i - 1]: b_i(i - 1)
        t = b_cahce[i - 1] + a(B[i - 1])
        b_cache[i] = t
        b_cached[i] = True
        return t
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(len(B), bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())

Submission status: Runtime Error

Solution code:
import bisect, functools
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())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b_i(i):
    if i >= 1:
        return b_i(i - 1) + a(B[i - 1])
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(len(B), bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())

Submission status: Runtime Error

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

def main():
    n = int(input())
    a_list = list(set(list(map(int, input().split()))))
    b_list = list(set(list(map(int, input().split()))))
    c_list = list(set(list(map(int, input().split()))))

    a_list.sort()
    b_list.sort()
    c_list.sort()

    cnt = 0

    for i in range(n):
        for j in range(n):
            if a_list[i] < b_list[j]:
                for k in range(n):
                    if b_list[j] < c_list[k]:
                        cnt += n - k
                        break
    
    print(cnt)


if __name__ == '__main__':
    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 = sorted(a)
b = sorted(b)
c = sorted(c)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  ans += z[bind]
print(ans)