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 bisect

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

ans = 0

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

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

print(ans)

Submission status: Wrong Answer

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_search(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_search(Alist, B)
    c_point = binary_search(Clist, B)
#    print(B,a_point, c_point, Clist.count(B))

    ans = ans + a_point * (N - c_point - Clist.count(B))

print(ans)
#for C in Clist:

Submission status: Wrong Answer

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_search(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_search(Alist, B)
    c_point = binary_search(Clist, B)
    print(B,a_point, c_point, Clist.count(B))

    ans = ans + a_point * (N - c_point - Clist.count(B))

print(ans)
#for C in Clist:

Submission status: Wrong Answer

Solution code:
from sys import stdin
from bisect import bisect_right


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


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

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

    nums = [0] * (N + 1)

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

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()], reverse=True)
a_num = len(lst_a)
b_num = len(lst_b)
c_num = len(lst_c)
dic = {}
ret = 0

for b in lst_b:
    t = 0
    for c in lst_c:
        if b >= c:
            break
        t += 1
    dic[b] = t


for a in lst_a:
    for b in lst_b:
        if a >= b:
            break
        ret += dic[b]
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()], reverse=True)
a_num = len(lst_a)
b_num = len(lst_b)
c_num = len(lst_c)
dic = {}
ret = 0

for a in lst_a:
    for b in lst_b:
        if a >= b:
            break
        t = dic.get(b)
        if t is None:
            t = 0
            for c in lst_c:
                if c > b:
                    t += 1
                else:
                    break
        ret += t
        dic[b] = t
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()], reverse=True)
a_num = len(lst_a)
b_num = len(lst_b)
c_num = len(lst_c)

ret = 0
for a in lst_a:
    for b in lst_b:
        if a >= b:
            break
        for c in lst_c:
            if c > b:
                ret += 1
            else:
                break
print(ret)

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

Submission status: 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()))
a.sort()
c.sort()
ans = 0
print(a)
print(b)
print(c)
for i in range(n):
    ans += bisect.bisect_left(a,b[i])*n-(bisect.bisect_right(c,b[i]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect
 
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
lenc=len(c)

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

jsum=0
for j in b:
    ai=bisect(a,j-1)
    ci=lenc-bisect_left(c,j+1)
    print(j,ai,ci)
    jsum+=ai*ci

print(jsum)

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()))
a.sort
b.sort
c.sort
ans = 0

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

for i in range(len(c)):
    b_M = bisect.bisect_left(b, c[i])
    for j in range(b_M):
        a_M = bisect.bisect_left(a, b[j])
        ans += a_M
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import math
import collections

readline = sys.stdin.readline

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))
    log2lenB = 18

    A.sort()
    C.sort()

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

    sumAlist = [0] * (len(countAlist[0])+1)
    sumClist = [0] * (len(countClist[0])+1)

    for i in range(len(countAlist[0])):
        sumAlist[i+1] = sumAlist[i] + countAlist[1][i]

    for i in range(len(countClist[0])):
        j = len(countClist[0]) - i - 1
        sumClist[i+1] = sumClist[i] + countClist[1][j]

    #print(sumAlist)
    #print(sumClist)

    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 <= min(A):
                lower = -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 = (lower >= 0) * sumAlist[countAlist[0].index(A[lower])+1]
        #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 >= max(C):
                upper = -1
                break
            if target < min(C):
                upper = 0
                break
            if target == C[middle]:
                upper = middle + 1
                break
            elif target < C[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    sumAlist = [0] * (len(countAlist[0])+1)
    sumClist = [0] * (len(countClist[0])+1)

    for i in range(len(countAlist[0])):
        sumAlist[i+1] = sumAlist[i] + countAlist[1][i]

    for i in range(len(countClist[0])):
        j = len(countClist[0]) - i - 1
        sumClist[i+1] = sumClist[i] + countClist[1][j]

    #print(sumAlist)
    #print(sumClist)

    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 <= min(A):
                lower = -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 = (lower >= 0) * sumAlist[countAlist[0].index(A[lower])+1]
        #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 >= max(C):
                upper = -1
                break
            if target < min(C):
                upper = 0
                break
            if target == C[middle]:
                upper = middle + 1
                break
            elif target < C[middle]:
                upper = middle
            else:
                lower = middle
            middle = (upper + lower) // 2

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


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = bisect.bisect_left(aa,b)
    nc = n - bisect.bisect_right(cc,b)
    print(na, nc)
    cnt += na*nc
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Bs.sort()
pyout=0
for i in range(N):
    num1=bisect.bisect_left(As,Bs[i])
    num2=N-bisect.bisect_left(Cs,Bs[i])
    pyout+=num2*num1
print(pyout)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)]
ans=0
for v in b:
  if v<=a[0] or v>=c[-1]:break
  ans+=bl(a,v)*(n-br(c,v))
print(ans)

Submission status: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
                break
        for k in range(step_3,N):
            if arr[1][j] < arr[2][k]:
                step_3 = k
                n_pair += N-k
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
        for k in range(step_3,N):
            if arr[1][j] < arr[2][k]:
                step_3 = k
                n_pair += N-k
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
                for k in range(step_3,N):
                    if arr[1][j] < arr[2][k]:
                        step_3 = k
                        n_pair += N-k
                        break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
                for k in range(step_3,N):
                    step_3 = k
                    if arr[1][j] < arr[2][k]:
                        n_pair += N-k
                        break
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
                for k in range(step_3,N):
                    step_3 = k
                    if arr[1][j] < arr[2][k]:
                        n_pair += (N-j)*(N-k)
                        break
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    step_1 = 0
    step_2 = 0
    step_3 = 0
    for i in range(N):
        for j in range(step_2,N):
            if arr[0][i] < arr[1][j]:
                step_2 = j
                for k in range(step_3,N):
                    step_3 = k
                    if arr[1][j] < arr[2][k]:
                        n_pair += (N-j+1)*(N-k+1)
                        break
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    for i in range(N):
        for j in range(N):
            if arr[0][i] < arr[1][j]:
                for k in range(N):
                    if arr[1][j] < arr[2][k]:
                        n_pair += (N-j+1)*(N-k+1)
                        break
                break
    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: Wrong Answer

Solution code:
def snuke_festival(N,arr):
    n_pair = 0
    for i in range(N):
        for j in range(N):
            if arr[0][i] < arr[1][j]:
                for k in range(N):
                    if arr[1][j] < arr[2][k]:
                        n_pair += (N-j+1)*(N-k+1)
                        break
    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: Wrong Answer

Solution code:
import copy
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
l1n=[-1 for _ in range(N)]
l2n=[-1 for _ in range(N)]
idab=0
idbc=0
buf1=[]
flag1=0
buf2=[]
flag2=0
i=0
#print(A)
#print(B)
#print(C)
exc=0
mulsum=[0]*N
while i<N:
    if (idab!=N)and(A[i]>=B[idab]):
        flag1=1
        idab=idab+1
    elif flag1==1:
        l1n[i]=idab-1
        i=i+1
    else:
        i=i+1
    #print(l1n)
    #input()
#print(l1n)
i=0
while i<N:
    if (idbc!=N)and(B[i]>=C[idbc]):
        flag2=1
        idbc=idbc+1
    elif flag1==1:
        l2n[i]=idbc-1
        i=i+1
    else:
        i=i+1
    #print(l2n)
    #input()
#print(l1n,l2n)
#print(sum(l1n)+N,sum(l2n)+N)
mulsum[0]=l2n[0]+1
for i in range(N-1):
    mulsum[i+1]=mulsum[i]+(l2n[i+1]+1)
#print(mulsum)
for i in range(N):
    if l1n[i]!=-1:
        exc=exc+mulsum[l1n[i]]
        #print(exc)
print(pow(N,3)-(sum(l1n)+N)*N-(sum(l2n)+N)*N+exc)

Submission status: Wrong Answer

Solution code:
def isOK(array, index, key):
    if array[index] >= key:
        return True
    else:
        return False

def binary_serch(array, key):
    ng = -1
    ok = len(array)

    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2

        if isOK(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok
n = int(input())
array1 = list(map(int,input().split()))
array2 = list(map(int,input().split()))
array3 = list(map(int,input().split()))

array1 = sorted(array1)
array2 = sorted(array2)
array3 = sorted(array3)

# a = binary_serch(array2, 5)
count=0
for array1_index in range(n):
    start_array2_index = binary_serch(array2, array1[array1_index])
    #print(array1[array1_index])
    for cor_array2_index in range(start_array2_index, n):
        #print(array2[cor_array2_index])
        start_array3_index = binary_serch(array3, array2[cor_array2_index])
        # for k in range(start_array3_index,n):
        #     print(array3)
        count+=abs(start_array3_index - n)
print(count)

Submission status: Wrong Answer

Solution code:
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            b_list[i] = c_len-ind_c-1
        else:
            b_list[i] = c_len-ind_c

# 累積和
a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            count += SumArea(ind_b+1, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
print(a)
print(b)
print(c)
def bin_search(x, n, flag):
    if flag == True:
        return bisect_left(x, n)
    else:
        return bisect_right(x, n)



for i in range(n):
    ans += bin_search(a, b[i], True) * (n - bin_search(c, b[i], False))

print(ans)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_right
from bisect import bisect_left
def main():
    n=int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

    A.sort()
    C.sort()
    sum=0
    for i in range(n):
        cnt=1
        cnt*= bisect_right(A,B[i])
        cnt*= n-bisect_left(A,B[i])
        sum+=cnt 

    print(sum)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from bisect import bisect_left
def main():
    n=int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

    A.sort()
    C.sort()
    sum=0
    for i in range(n):
        cnt=1
        cnt*= bisect_left(A,B[i])
        cnt*= n-bisect_right(A,B[i])
        sum+=cnt 

    print(sum)

if __name__ == '__main__':
    main()

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()
def isOK(A,mid,target):
    #条件を満たす領域とそうでない領域の境目！
    return target<A[mid]   #条件を満たす中で最小
    #return A[mid]<=target  #条件を満たす中で最大
def aa(A,target):
    ng=-1 ; ok=n-1  #okはその条件を満たしていることが大前提
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if isOK(A,mid,target): ok=mid
        else: ng=mid
    return ok

def qq(A,target):
    ng=n ; ok=0  #okはその条件を満たしていることが大前提
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if target>A[mid]: ok=mid
        else: ng=mid
    return ok

ans=0

for i in B:
    ans+= (1+qq(A,i))* (n-aa(C,i))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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()]

ans = 0
a = tuple(a); b = tuple(b); c = tuple(c)
a = sorted(a)
b = sorted(b,reverse=True)
c = sorted(c)

import bisect
chk_b = [0]*n
for i,bi in enumerate(b):
  y = bisect.bisect_right(c, bi)
  chk_b[i] = max(0,n-y) + chk_b[i-1]
  
chk_b = tuple(chk_b)
b = sorted(b)
for i in a:
  x = bisect.bisect_right(b, i)
  ans += chk_b[n-1-x]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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()]

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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:
    bidx = bisect_left(B, a)
    if bidx == N:
        continue
    for b in B[bidx:]:
        cidx = bisect_left(C, b)
        if cidx == N:
            continue
        alters_count += N - cidx

print(alters_count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
n = int(input())
alis = sorted(list(map(int, input().split())))
blis = list(map(int, input().split()))
clis = sorted(list(map(int, input().split())))
ans = 0
for b in blis:
    up = bisect_right(alis, b)
    down = n - bisect_left(clis, b)
    ans += up*down
print(ans)

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)


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 0 <= index_c <= len(C) - 1 and C[index_c] == b:
        res += index_a * (N - index_c - 1)
    else:
        res += index_a * (N - index_c)

print(res)

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

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

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

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 tmp in b:
    top = bisect.bisect_left(a, tmp)
    bottom = bisect.bisect_right(c, tmp)
    ans += top * (n-bottom)

print(ans)