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

for elem in a:
    id1=bisect_left(b,elem)
    if id==n:
        continue
    else:
        for i in range(id1,n):
            id2=bisect_left(c,b[i])
            ans+=n-id2
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
list_A=sorted(list(input().split( )))
list_B=sorted(list(input().split( )))
list_C=sorted(list(input().split( )))

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

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())

list_A=sorted(list(input().split(' ')))
list_B=sorted(list(input().split(' ')))
list_C=sorted(list(input().split(' ')))
ans=0
for i in list_B:
	a=bisect.bisect_left(list_A, i)
	b=bisect.bisect_right(list_C, i)
	ans += a*(n-b)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())

list_A=sorted(list(input().split(' ')))
list_B=sorted(list(input().split(' ')))
list_C=sorted(list(input().split(' ')))
ans=0
for i in range(len(list_B)):
	a=bisect.bisect_left(list_A, list_B[i])
	b=bisect.bisect_right(list_C, list_B[i])

	ans += a*(n-b)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
X = sorted(list(map(int,input().split())))
Y = sorted(list(map(int,input().split())))
Z = sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(X,b) * (n-bisect.bisect_right(Z,b))) for b in Y)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = sorted(list(map(int,input().split())))
Y = sorted(list(map(int,input().split())))
Z = sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(X,b) * (n-bisect.bisect_right(Z,b))) for b in Y)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = sorted(list(map(int,input().split())), reverse=True)
Y = sorted(list(map(int,input().split())), reverse=True)
Z = sorted(list(map(int,input().split())), reverse=True)
print(sum((n-bisect.bisect_right(X,b)) * (bisect.bisect_left(Z,b))) for b in Y)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
X = sorted(list(map(int,input().split())), reverse=True)
Y = sorted(list(map(int,input().split())), reverse=True)
Z = sorted(list(map(int,input().split())), reverse=True)
print(sum(bisect.bisect_right(X,b) * (n-bisect.bisect_left(Z,b))) for b in Y)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
X = sorted(list(map(int,input().split())), reverse=True)
Y = sorted(list(map(int,input().split())), reverse=True)
Z = sorted(list(map(int,input().split())), reverse=True)
print(sum(bisect.bisect_right(x,y[b]) * (n-bisect.bisect_left(z,y[b]))) for y in Y)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
x = sorted(list(map(int,input().split())), reverse=True)
y = sorted(list(map(int,input().split())), reverse=True)
z = sorted(list(map(int,input().split())), reverse=True)
count = 0
X =[0]*n
for b in range(n):
  k = bisect.bisect_right(x,y[b])
  X[b] =(n-k)
for a in range(n):
  j = bisect.bisect_right(y,z[a])
  count+=sum(X[j:])
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
x = sorted(list(map(int,input().split())), reverse=True)
y = sorted(list(map(int,input().split())), reverse=True)
z = sorted(list(map(int,input().split())), reverse=True)
count = 0
for a in range(n):
  j = bisect.bisect_right(y,z[a])
  for b in range(j,n-1):
    k = bisect.bisect_right(x,y[b])
    count+=(n-k)
print(count)

Submission status: Wrong Answer

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 b:
    left = 0
    right = len(a) 
    while right - left > 1:
        mid = (right + left) //2 
        if a[mid] <  i:
            left = mid 
        else :
            right = mid 
    left2 = -1
    right2 = len(c)
    while right2 - left2 > 1:
        mid2 = (right2 + left2) //2
        if c[mid2] > i:
            right2 = mid2
        else :
            left2 = mid2
    cnt += (left+1)*(n-right2)

print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

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

ans = 0

for i in range(n):
    b = B[i]
    pos_a = bisect_right(A, b)
    pos_c = bisect_left(C, b)
    ans += pos_a * (n - pos_c)
    # print(b, pos_a, pos_c)
print(ans)

Submission status: Wrong Answer

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

a.sort()

c.sort()
ans = 0
#基準は中段
for i in range(n):
    kijun = b[i]
    lefta = 0
    righta = n-1
    if kijun > a[-1] :
        jodan = n
    else :
        while lefta <= righta :
            mida = (lefta + righta) // 2
            if a[lefta] <= kijun <= a[mida] :
                if mida == lefta + 1 :
                    if kijun == a[lefta] :
                        while kijun == a[lefta] and lefta > 0 :
                            lefta -= 1
                    jodan = lefta + 1
                    break
                else :
                    righta = mida
            elif a[mida] < kijun <= a[righta] :
                if mida == righta - 1 :
                    if kijun == a[righta] :
                        while kijun == a[righta] and righta > 0 :
                            righta -= 1
                    jodan = mida + 1
                    break
                else :
                    lefta = mida
    leftc = 0
    rightc = n-1
    if kijun < c[0] :
        gedan = n
    else :
        while leftc <= rightc :
            midc = (leftc + rightc) // 2
            if c[leftc] <= kijun < c[midc] :
                if midc == leftc + 1 :
                    gedan = n - midc
                    break
                else :
                    rightc = midc
            elif c[midc] <= kijun <= c[rightc] :
                if midc == rightc - 1 :
                    if kijun == c[rightc] :
                        while kijun == c[rightc] and rightc < n-1 :
                            rightc += 1
                    gedan = n - rightc
                    break
                else :
                    leftc = midc
    ans += jodan * gedan
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))

As.sort(reverse = True)
Bs.sort(reverse = True)
Cs.sort(reverse = True)

ls = [0]
sum = 0
for i in range(N):
    l = 0
    r = N-1
    while(r-l>1):
        mid = (l+r)//2
        if Cs[mid] <= Bs[i]:
            r = mid
        else:
            l = mid
    if Cs[0] < Bs[i]:
        r = 0
    if Cs[N-1] > Bs[i]:
        r = N
    sum += r
    ls.append(sum)

ans = 0
for i in range(N):
    l = 0
    r = N-1
    while(r-l>1):
        mid = (l+r)//2
        if Bs[mid] <= As[i]:
            r = mid
        else:
            l = mid
    if Bs[0] < As[i]:
        r = 0
    if Bs[N-1] > As[i]:
        r = N
    ans += ls[r]

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
B_ = [0]*N
ans = 0
start = 0
for i, b in enumerate(B):
    j = bisect_right(A, b, start)
    B_[i] = j
    start = j
B_ = cumsum(B_)
start = 0
for c in C:
    i = bisect_right(B, c, start)
    start = i
    if i != 0:
        ans += B_[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
B_ = [0]*N
ans = 0
for i, b in enumerate(B):
    j = bisect_right(A, b)
    B_[i] = j
for c in C:
    i = bisect_right(B, c)
    for b in range(len(B[:i])):
        ans += B_[b]
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for c in C:
    i = bisect_right(B, c)
    for b in B[:i]:
        j = bisect_right(A, b)
        ans += j
print(ans)

Submission status: Wrong Answer

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

a.sort()

c.sort()
ans = 0
#基準は中断
for i in range(n):
    kijun = b[i]
    lefta = 0
    righta = n-1
    if kijun > a[-1] :
        jodan = n
    else :
        while lefta <= righta :
            mida = (lefta + righta) // 2
            if a[lefta] <= kijun <= a[mida] :
                if mida == lefta + 1 :
                    if kijun == a[lefta] :
                        while kijun == a[lefta] and lefta > 0 :
                            lefta -= 1
                    jodan = lefta + 1
                    break
                else :
                    righta = mida
            elif a[mida] < kijun <= a[righta] :
                if mida == righta - 1 :
                    if kijun == a[righta] :
                        while kijun == a[righta] and righta > 0 :
                            righta -= 1
                    jodan = mida + 1
                    break
                else :
                    lefta = mida
    leftc = 0
    rightc = n-1
    if kijun < c[0] :
        gedan = n
    else :
        while leftc <= rightc :
            midc = (leftc + rightc) // 2
            if c[leftc] <= kijun < c[midc] :
                if midc == leftc + 1 :
                    gedan = n - midc
                    break
                else :
                    rightc = midc
            elif c[midc] <= kijun <= c[rightc] :
                if midc == rightc - 1 :
                    if kijun == c[rightc] :
                        while kijun == c[rightc] and rightc < n-1 :
                            rightc += 1
                    gedan = n - rightc
                    break
                else :
                    leftc = midc
    ans += jodan * gedan
print(ans)

Submission status: Wrong Answer

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


def binary_search(x, d):
    l = 0
    r = n - 1
    if d[l] >= x:
        r = 0
    elif x > d[r]:
        l = n - 1
    else:
        while l + 1 != r:
            m = (l + r) // 2
            if d[m] < x:
                l = m
            else:
                r = m
    if d[r] == x:
        r += 1
    if d[l] == x:
        l -= 1
    return l, r


res = 0
for i in range(n):
    x = b[i]
    al, ar = binary_search(x, a)
    cl, cr = binary_search(x, c)
    res += (al + 1) * (n - cr)

print(res)

Submission status: Wrong Answer

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


def binary_search(x, d):
    l = 0
    r = n - 1
    if d[l] >= x:
        r = 0
    elif x > d[r]:
        l = n - 1
    else:
        while l + 1 != r:
            m = (l + r) // 2
            if d[m] < x:
                l = m
            else:
                r = m
    if d[r] == x:
        r += 1
    return l, r


res = 0
for i in range(n):
    x = b[i]
    al, ar = binary_search(x, a)
    cl, cr = binary_search(x, c)
    res += (al + 1) * (n - cr)

print(res)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

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

cnt = 0
for b in B:
    cnt += bisect_left(A, b) * bisect_right(C, b)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    A = NLI()
    B = NLI()
    C = NLI()
    
    A = sorted(A)
    C = sorted(C)
    
    ans = 0
    
    for b in B:
        

        A_ng = 0       #ng:とり得る最小の値-1
        A_ok = len(A)  #ok:とり得る最大の値+1

        while (abs(A_ok - A_ng) > 1):
            A_mid = (A_ok + A_ng) // 2

            if A[A_mid] >= b:#計算の結果、midが条件を満たすならokにmidを代入。そうでなければngにmidを代入。
                A_ok = A_mid
            else:
                A_ng = A_mid
                
        C_ng = 0       #ng:とり得る最小の値-1
        C_ok = len(C)  #ok:とり得る最大の値+1

        while (abs(C_ok - C_ng) > 1):
            C_mid = (C_ok + C_ng) // 2

            if C[C_mid] > b:#計算の結果、midが条件を満たすならokにmidを代入。そうでなければngにmidを代入。
                C_ok = C_mid
            else:
                C_ng = C_mid
                
                
        len_C = len(C)
        
        ans += A_ok * (len_C-C_ok)
        
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
for a in A:
    B_a = [b > a for b in B]
    for b in B_a:
        C_b = [c > b for c in C]
        ans += len(C_b)
print(ans)

Submission status: Wrong Answer

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

A.sort()
C.sort()


def binary_search(lst, value, high):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            # lstの中にある場合
            if high:
                # 真に大きい
                return mid + 1
            else:
                # 真に小さい
                return mid - 1
    if high:
        return l
    else:
        return r


def main():
    ans = 0
    # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる
    for middle in B:
        lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する
        higher = N - binary_search(C, middle, True)
        ans += lower * higher
    
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A_count = [0] * len(A)
B_count = [0] * len(B)
for i in range(len(B)):
    B_count[i] = len(C) - bisect(C, B[i])
for i in range(len(A)):
    A_count[i] = sum(B_count[bisect(B, A[i]):])
print(sum(A_count))

Submission status: Wrong Answer

Solution code:
def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

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 b in B:
    ans += (bs_right(A, b) * (n - bs_left(C, b)))
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import math
import time
import statistics
import math
import itertools
import bisect

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

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

    ans = 0
    idx = 0
    idx2 = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a, idx)
        for i in range(idx, n):
            idx2 = bisect.bisect_right(c_list, b_list[i], idx2)
            ans += n - idx2

    print(ans)
    #print(time.time() - start)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    while l < r - 1:
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

print(a)
print(b)
print(c)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(100):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

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 = sorted(a)
b = sorted(b)
c = sorted(c)

print(a)
print(b)
print(c)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for i in range(100):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#xがちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<=arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    if a_count==0 or c_count==0:
        count+=0
    else:
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)

Submission status: Wrong Answer

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())))
count=0
for a in A:
    for b in B:
        if b>=a:
            count += len([i for i in C if i>=b])
print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    if a_count==0 or c_count==0:
        count+=0
    else:
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    if a_count==0 or c_count==0:
        count=0
    else:
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    if a_count==-1 or c_count==-1:
        count=0
    else:
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    #if min(a)>=b[i] or max(c)<=b[i]:
        #count=0
    #else:
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ物は一個下げる
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r+1

#二分探索(x以下の最大値)
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    count+=a_count*(len(c)-c_count+1)
    #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
    #print(a_count,len(c),c_count,len(c)-c_count+1)
    #print(count)

print(count)

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=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ物は一個下げる
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r+1

#二分探索(x以下の最大値)
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    count+=a_count*(len(c)-c_count+1)
    print(upper_bound(a,b[i]),lower_bound(c,b[i]))
    print(a_count,len(c),c_count,len(c)-c_count+1)
    print(count)

print(count)

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
count = 0

for i in b:
    a_ = bisect.bisect_left(a,i)
    c_ = bisect.bisect_right(c,i)

    count += (a_ * (n - c_))

print(count)

Submission status: Wrong Answer

Solution code:
# ABC_077_C_Sunuke_Festival.py

from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# B[j]を固定してA[i]<=B[j]<=C[k]を満たす(i,j)の個数を求める
# ソートして二分探索すれば間に合う
A.sort()
# B.sort()
C.sort()
# print(A)
# print(B)
# print(C)


def bisectsearch_left(L, a):
    i = bisect_left(L, a)
    return(i)


def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)


ans = 0
for j in range(N):
    b = B[j]
    cti = bisectsearch_left(A, b)
    ctk = N-bisectsearch_right(C, b)
    print(cti, ctk)
    ans += cti*ctk
print(ans)