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
import numpy as np
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))

memo = [0] * n
for i in range(n):
     memo[i] = n - bisect.bisect_right(c,b[i])
memo.reverse()
memo1 = np.cumsum(memo)

ans = 0
for i in range(n):
     if a[i] > b[n-1]:
          continue
     else:
          ans += memo1[n-1-bisect.bisect_right(b,a[i])]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))

memo = [0] * n
for i in range(n):
     memo[i] = n - bisect.bisect_right(c,b[i])
memo.reverse()
memo1 = np.cumsum(memo)
ans = 0
for i in range(n):
     ans += memo1[n-1-bisect.bisect_right(b,a[i])]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def count_over_target(lst, target, size):
    ng = -1
    ok = size
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if lst[mid] >= target:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = list(map(int, input().split()))
    c = sorted(list(map(int, input().split())))
    ans = 0
    for i in b:
        under = count_over_target(a, i, n)
        over = n - count_over_target(c, i, n)
        ans += under * over
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def count_over_target(lst, target, size):
    ng = -1
    ok = size
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if lst[mid] > target:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = list(map(int, input().split()))
    c = sorted(list(map(int, input().split())))
    ans = 0
    for i in b:
        under = count_over_target(a, i, n)
        over = n - count_over_target(c, i, n)
        ans += under * over
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = list(map(int, input().split(" ")))
bottoms = sorted(list(map(int, input().split(" "))))
# print(tops)
# print(mids)
# print(bottoms)


# def left_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] >= num:
#         return left_binary_search(check_list, num, left, mid - 1)
#     else:
#         return left_binary_search(check_list, num, mid + 1, right)


# def right_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] > num:
#         return right_binary_search(check_list, num, left, mid - 1)
#     else:
#         return right_binary_search(check_list, num, mid + 1, right)


total_count = 0
for mid in mids:
    # bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1)
    bottom_start_index = bisect.bisect_left(bottoms, mid)
    # top_end_index = left_binary_search(tops, mid, 0, N - 1)
    top_end_index = bisect.bisect_left(tops, mid)
    total_count += ((N - bottom_start_index) * top_end_index)
print(total_count)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
#A = [LIST() for i in range(3)]
A = LIST()
B = LIST()
C = LIST()
ans = 0
for b in B:
    a = bisect(A, b)
    c = bisect_left(C, b)
    right = N - c
    ans += a * right
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,b,c=sorted(a),sorted(b),sorted(c)

k=0
while 2**k<n:
    k+=1

la=[]
for i in range(n):
    p=[0,n-1]
    for j in range(k):
        if p[1]-p[0]==1 and n>2:
            break
        else:
            if a[i]<b[0]:
                p[1]=0
                break
            elif b[n-1]<=a[i]:
                p[1]=n
                break
            elif a[i]<b[(p[0]+p[1])//2]:
                p[1]=(p[0]+p[1])//2
            else:
                p[0]=(p[0]+p[1])//2
    la.append(n-p[1])

lb=[]
for i in range(n):
    p=[0,n-1]
    for j in range(k):
        if p[1]-p[0]==1 and n>2:
            break
        else:
            if b[i]<c[0]:
                p[1]=0
                break
            elif c[n-1]<=b[i]:
                p[1]=n
                break
            elif b[i]<c[(p[0]+p[1])//2]:
                p[1]=(p[0]+p[1])//2
            else:
                p[0]=(p[0]+p[1])//2
    lb.append(n-p[1])

m=0
for i in range(n):
    m+=sum(lb[n-la[i]:n])
print(m)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
print(A,B,C,sep="\n")
ans = 0
b_memo = [0]
for b in B:
    a = bisect.bisect_left(A, b)
    b_memo.append(b_memo[-1]+a)
for c in C:
    b = bisect.bisect_left(B, c)
    if (b == 0):
        continue
    ans += b_memo[b]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
def solve():
    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()
    ans = 0

    for b in B:
        a_idx = bisect.bisect_left(A, b)
        c_idx = bisect.bisect_right(C, b)
        ans += a_idx * (N - c_idx)

    print(ans)

if __name__ == '__main__':
    solve()

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

for x in range(N):
    ab = bisect_right(A, B[x])
    bc = N - bisect_left(C, B[x])
    if B[x] in A:
        ab -= 1
    if B[x] in C:
        bc -= 1
    sumSunuke += ab * bc
print(sumSunuke)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(raw_input())

A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

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

num_A_on_B = 0
num_C_under_B = 0

ans = 0
for y in B:
    x = 0
    z = 0
    while x < N and A[x] <= y:
        x = x + 1
    while z < N and A[z] >= y:
        z = z + 1
    ans = ans + x*(N-z)
    
print ans

Submission status: Wrong Answer

Solution code:
import numpy as np

def is_okay(A, index, key):
    if(A[index] > key):
        return True
    else:
        return False


def bis(A, key):
    left = -1
    right = len(A)

    while(right - left > 1):
        mid = left + (right - left)/2
        if is_okay(A, mid, key):
            right = mid
        else:
            left = mid

    if right < len(A):
        return right
    else:
        return len(A) - 1


N = int(raw_input())

A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

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

ans = 0
num = len(C)
Bmax = B[-1]
Cmax = C[-1]

for i in range(len(A)):
    Ai = A[i]
    if Bmax < Ai:
        break
    Bj = bis(B, Ai)
 
    for j in range(Bj, len(B)):
        if Cmax < B[j]:
            break
        Ck = bis(C, B[j])
        add = num - Ck
        ans = ans + add
 
print ans

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
k = [list(map(int,input().split())) for _ in range(3)]
cnt = [[0] * n for _ in range(2)] 
# cnt[0][i]がb[i]より小さいa[j]の個数、cnt[1][i]がb[i]より大きいc[j]の個数
a = sorted(k[0])
b = sorted(k[1])
c = sorted(k[2])
for i in range(n):#b[i] に対して二分探索
    l = -1
    r = n #極端にとる
    while r-l > 1:#r-l =1で終了
        # 条件はb[i] > a[j]でb[i] >= a[j+1]
        k = (l+r)//2
        if b[i] > a[k]: l = k
        else: r = k
    cnt[0][i] = l+1
    l = -1
    r = n #極端にとる
    while r-l > 1:#r-l =1で終了
        # 条件はb[i] < b[j]でb[i] <= a[j+1]
        k = (l+r)//2
        if b[i] < c[k]: r = k
        else: l = k
    cnt[1][i] = n-r
print(cnt)#a,cのみす
""" ACするが、O(n**2)
i = 0
j = 0
while i < n:
    if b[i] < c[j]: 
        cnt[1][i] = n-j
        i +=1
    else: j+=1
    if j >= n:
        j = n-1
        cnt[1][i] = 0
        i += 1
i = 0
j = 0
while i < n:
    if b[i] > a[j]:
        j+= 1
    else:
        cnt[0][i] = j
        i += 1
    if j >= n:
        j = n-1
        cnt[0][i] = n
        i += 1"""
ans = 0
for i in range(n):
    ans += cnt[0][i]*cnt[1][i]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
#print(a,b,c)
cnt = 0
for i in range(n):
    d = bisect.bisect_left(a,b[i])
    e = bisect.bisect_left(c,b[i])
    cnt += d*(n-e)
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

n = int(input())
aa = sorted(list(map(int,input().split())))
bb = sorted(list(map(int,input().split())))
cc = sorted(list(map(int,input().split())))

ans = 0
for bi in bb:  
  ans += bisect_left(aa,bi) * (n- bisect_left(cc,bi))
  
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 = sorted(a)
b = sorted(b)
c = sorted(c)

def bs(li, num):
    """return boundary index"""
    l = 0
    r = len(li) - 1
    if li[l] >= num:
        return -1
    elif li[r] < num:
        return r
    while r-l > 1:
        mid = (l+r) // 2
        if li[mid] < num:
            l = mid
        else:
            r = mid
    return l

def bs_1(li, num):
    """return boundary index"""
    l = 0
    r = len(li) - 1
    if li[l] > num:
        return r
    elif li[r] <= num:
        return -1
    while r-l > 1:
        mid = (l+r) // 2
        if li[mid] <= num:
            l = mid
        else:
            r = mid
    return r


ans = 0
for i in range(len(b)):

    c_i = bs_1(c, b[i])
    a_i = bs(a, b[i])
    ans += (n-c_i) * (a_i+1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])
cnt = 0

for i in range(N):
    j = bisect.bisect_right(A,B[i])
    k = bisect.bisect_left(C,B[i])
    cnt += j*(N-k) 

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
AS = list(map(int,input().split()))
AS.sort()
BS = list(map(int,input().split()))
BS.sort()
CS = list(map(int,input().split()))
CS.sort()
import bisect
AB  = [0 for _ in range(n)]
BC  = [0 for _ in range(n)]
a = 0
for b in range(n):
  AB[b] = bisect.bisect_left(AS,BS[b])
  
for b in range(n):
  BC[b] = n-bisect.bisect_left(CS,BS[b])

ans = 0
for i in range(n):
  ans += AB[b] * BC[b]
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# bisectで行けるけどめぐる式の練習

# Bを固定すると、A,Cを二分探索すれば条件を満たす個数が計算できる

from bisect import bisect_left, bisect_right
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

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

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

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    # Cに関しては真に大きい個数を知りたいことに注意
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
# coding: utf-8
# Your code here!

n=int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()
"""
print(a[0])
print(a[1])
print(a[2])
"""
def bin_lower(b):
    if a[0][0]>=b:
        return 0
    pl=0
    pr=n-1
    
    while True:
        pc=(pl+pr)//2
        if a[0][pc]>=b and a[0][pc-1]<b:
            return pc
        else:#a[0][pc]<b
            pl=pc+1
            if pl>n-1:
                return n
        """
        else:
            pr=pc-1
            if pr<0:
                return 0
        """
                
def bin_upper(b):    
    if a[2][n-1]<=b:
        return 0
    pl=0
    pr=n-1
    
    while True:
        pc=(pl+pr)//2
        if a[2][pc]<=b and a[2][pc+1]>b:
            return n-1-pc
        else:#if a[2][pc]>b
            pr=pc-1
            if pr<0:
                return n
        """
        else:
            pl=pc+1
            if pl>n-1:
                return 0
        """
"""
print(bin_upper(a[1][0]))
print(bin_lower(a[1][0]))
print(bin_upper(a[1][1]))
print(bin_lower(a[1][1]))
print(bin_upper(a[1][2]))
print(bin_lower(a[1][2]))
"""

cnt=0
for i in range(n):
    cnt+=bin_lower(a[1][i])*bin_upper(a[1][i])
print(cnt)

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 b in B:
  a = bisect.bisect_left(A, b)
  c = bisect.bisect_left(C, b)

  ans += a * (len(C) - c)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list = sorted(a_list, reverse=True)
b_list = list(map(int, input().split()))
b_list = sorted(b_list, reverse=True)
c_list = list(map(int, input().split()))
c_list = sorted(c_list, reverse=True)
counter = 0
for _a in a_list:
    for _b in b_list :
        for _c in c_list:
            if _a > _b > _c:
                counter = counter + 1
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from bisect import bisect_right, bisect_left
n=int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()



cnt=0
for i in range(n):
    index_1 = bisect_right(a[0],a[1][i])
    index_2 = n-bisect_left(a[2],a[1][i])
    cnt+=index_1*index_2
print(cnt)

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(reverse=True)

#2分探索を用いる
ans = 0
for i in B:
    a = bisect.bisect_left(A,i)
    b = bisect.bisect_left(C,i)
    ans += a*b
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
aList = sorted(list(map(int,input().split())))
bList = list(map(int,input().split()))
cList = sorted(list(map(int,input().split())))

count = 0
for i in bList:
  idxA = bisect.bisect_left(aList,i)
  idxC = bisect.bisect_left(cList,i)
#  print("idxA",idxA)
#  print("idxC",idxC)

  count += (idxA)*(n-(idxC))

print(count)

Submission status: Wrong Answer

Solution code:
# わからなかった

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from bisect import bisect_left

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
for i in range(N):
    x1 = bisect_left(A, B[i])
    x2 = bisect_right(C, B[i])
    print(x1, x2, N)
    answer += x1 * (N - x2)

print(answer)

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()
import bisect
ans = 0
for i in range(N):
    b = B[i]
    x = bisect.bisect_left(A,b)
    y = bisect.bisect_right(C,b)
    if y == 0:
        break
    ans += x*y
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
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)


ret = 0
for i in range(N):
    # 中段を決めた時、その値より小さくなる上段を探す
    new_A = bisect_left(A, B[i])
    # 中段を決めた時、その値より大きくなる下段を探す
    new_C = bisect_right(C, B[i])
    # 組み合わせ
    ret += new_A * (N - new_C)

print(ret)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
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)


ret = 0
for i in C:
    if i <= B[0]:
        break
    small_b = [b for b in B if b < i]
    for j in small_b:
        if j <= small_b[0]:
            break
        small_a = [a for a in A if a < j]
        ret += len(small_a)

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()))
count = 0
for i in range(N):
    b = B[i]
    cind = bisect.bisect_left(C,b)
    aind = bisect.bisect_right(A,b)
    count+=(N-cind)*aind
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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()
num=[[0]*n for _ in range(3)]
from bisect import bisect_left as bl

for i in range(n):
    t=bl(b,a[i])
    if t==n:
        continue
    num[0][t]+=1
#print(num)
for i in range(1,n):
    num[0][i]+=num[0][i-1]
#print(num[0])
for i in range(n):
    t=bl(c,b[i])
    if t==n:
        continue
    num[1][t]+=num[0][i]

#print(num)
for i in range(1,n):
    num[1][i]+=num[1][i-1]
#print(num)
"""
for i in range(1,n):
    num[1][i]+=num[1][i-1]"""
#print(num[1])
print(sum(num[1]))

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())

*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    count = 0
    index = bisect.bisect_right(A,B[i])
    A_B[i] = index 

for i in range(N):
    count = 0
    index = bisect.bisect_left(C,B[i])
    B_C[i] = len(C)-index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())

*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A.sort()
B.sort()
C.sort()

A_B = [0]*N
B_C = [0]*N

for i in range(N):
    count = 0
    index = bisect.bisect_right(A,B[i])
    A_B[i] = index 

for i in range(N):
    count = 0
    index = bisect.bisect_right(A,B[i])
    B_C[i] = index

sum = 0
for i in range(N):
    sum = sum + B_C[i]*A_B[i]

print(sum)

Submission status: Wrong Answer

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

count=0
for j in range(N):
  count_A=0
  l=0
  r=N
  while r-l>1:
    p=(r+l)//2
    if A[p]<B[j]:
      l=p
    else:
      r=p
  count_A=l+1
  
  count_C=0
  l=0
  r=N
  while r-l>1:
    p=(r+l)//2
    if C[p]>B[j]:
      r=p
    else:
      l=p
  count_C=N-l-1
  
  count +=count_A*count_C
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()))

count = 0
a1 = sorted(a)
b1 = sorted(b)
c1 = sorted(c)
for i in c1:
    prior_c = bisect.bisect_right(b1,i)
    prior_c_list = b1[:prior_c]
    for j in prior_c_list:
        count += bisect.bisect_right(a1,j)

print(count)

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def binary_search(A, n):
    left = 0
    right = len(A)

    if A[0] > n:
        return -1

    else:
        while left <= right:
            if right - left == 1:
                break

            mid = (left + right) // 2
            if A[mid] < n:
                left = mid
            elif n < A[mid]:
                right = mid
            else:
                left = mid
                break

        if A[left] == n:
            return left - 1
        else:
            return left


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

    A, B, C = np.sort(A), np.sort(B), np.sort(C)

    aa = np.zeros([N], dtype=np.int32)
    for i, b in enumerate(B):
        aa[i] = binary_search(A, b) + 1

    bb = np.cumsum(aa)

    cnt = 0
    for i, c in enumerate(C):
        m = binary_search(B, c)
        if m != -1:
            cnt += bb[m]

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def binary_search(A, n):
    left = 0
    right = len(A)

    if A[0] > n:
        return -1
    else:
        while left <= right:
            mid = (left + right) // 2
            if A[mid] < n:
                left = mid
            elif n < A[mid]:
                right = mid
            else:
                left = mid
                break

            if right - left == 1:
                break

        if A[left] == n:
            return left - 1
        else:
            return left


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

    A, B, C = np.sort(A), np.sort(B), np.sort(C)

    aa = np.zeros([N], dtype=np.int32)
    for i, b in enumerate(B):
        aa[i] = binary_search(A, b) + 1
    bb = np.cumsum(aa)

    cnt = 0
    for i, c in enumerate(C):
        m = binary_search(B, c)
        if m != -1:
            cnt += bb[m]
        else:
            continue

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
a_list.sort()
b_list.sort()
c_list.sort()
counter = 0
for i in c_list:
  insert_index_b = bisect.bisect_right(b_list,i)
  insert_index_a = bisect.bisect_right(a_list,insert_index_b)
  counter += insert_index_a * insert_index_b
print(counter)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A_arr = list(map(int,input().split()))
A_arr.sort()
B_arr = list(map(int,input().split()))
B_arr.sort()
C_arr = list(map(int,input().split()))
ans = 0
for i in C_arr:
    B_index = bisect.bisect_left(B_arr,i)
    for k in range(B_index):
        tmp = bisect.bisect_left(A_arr,B_arr[k])
        if tmp != 0:
            ans += tmp
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
A.sort()
C.sort()
for i in B:
    x = bisect.bisect_left(A,i)
    y = N-bisect.bisect_right(C,i)
    ans += x*y
    print(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
A.sort()
B.sort()
for i in B:
    x = bisect.bisect_left(A,i)
    y = N-bisect.bisect_right(C,i)
    ans += x*y
    print(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in B:
    x = bisect.bisect_left(A,i)
    y = N-bisect.bisect_right(C,i)
    ans += x*y
    print(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
def binary_search(lst,item):
  low=0
  high=len(lst)-1
  while low<=high:
    mid=(low+high)//2
    guess=lst[mid]
    if guess==item:
      return mid
    if guess<item:
      low=mid+1
    else:
      high=mid-1
  if lst[mid]>item:
    return mid-1
  if lst[mid]<item:
    return mid
  
cnt=0
for i in range(n):
  cnt+=(binary_search(b,a[i])+1)*(binary_search(c,b[i])+1)
    
print(cnt)

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 binary_search(lst,item):
  low=0
  high=len(lst)-1
  while low<=high:
    mid=(low+high)//2
    guess=lst[mid]
    if guess==item:
      return mid
    if guess>item:
      low=mid-1
    else:
      high=mid+1
  if lst[mid]>item:
    return mid-1
  if lst[mid]<item:
    return mid
  
A=[]
B=[]
for i in range(n):
  A.append(binary_search(b,a[i]))
  B.append(binary_search(c,b[i]))
    
cnt=0
for i in range(n):
  cnt+=(A[i]+1)*(B[i]+1)

print(cnt)

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):
    low = bisect.bisect_left(a,b[i]-1)
    upp = bisect.bisect_left(c,b[i]+1)
    ans += low*(n-upp)
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())))

dp_b = [0] * n
j = 0
for i in range(n):
  while j < n:
    if B[i] >= C[j]:
      dp_b[i] = j
      break
    j += 1
  if j == n:
    dp_b[i] = n

for i in range(1, n):
  dp_b[i] = dp_b[i] + dp_b[i-1]

ans = 0
j = 0
for i in range(n):
  while j < n:
    if A[i] >= B[j]:
      if j == 0:
        break
      else:
        ans += B[j-1]
        break
    j += 1
    if j == n:
      ans += B[n-1]
  
print(ans)

Submission status: Wrong Answer

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

num = 0

for B in set(Blist):
    num += (bisect.bisect_right(Alist, B) * (N - bisect.bisect_left(Clist, B)))
print(num)

Submission status: Wrong Answer

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

num = 0
for B in Blist:
    num += (bisect.bisect_right(Alist, B) * (N - bisect.bisect_left(Clist, B)))
print(num)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
al = sorted(list(set(int(i) for i in input().split())))
bl = sorted(list(set(int(i) for i in input().split())))
cl = sorted(list(set(int(i) for i in input().split())))
ans = 0

def search(ar, key, flag):
    left = -1
    right = len(ar)
    center = (left + right) // 2
    
    while right - left > 1:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif ar[center] < key:
            left = center
            center = (left + right) // 2
        else:
            right = center
            center = (left + right) // 2
    
    if flag == 0:
        return right
    elif flag == 1:
        return len(ar) - right
        

for i in range(len(bl)):
    mid = bl[i]
    top_num = search(al, mid, 0)
    bottom_num = search(cl, mid, 1)
    ans += top_num * bottom_num
    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0

def search(ar, key, flag):
    left = -1
    right = len(ar)
    center = (left + right) // 2
    
    while right - left > 1:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif ar[center] < key:
            left = center
            center = (left + right) // 2
        else:
            right = center
            center = (left + right) // 2
    
    if flag == 0:
        return right
    elif flag == 1:
        return len(ar) - right
        

for i in range(n):
    mid = bl[i]
    top_num = search(al, mid, 0)
    bottom_num = search(cl, mid, 1)
    ans += top_num * bottom_num
    
print(ans)