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:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
a=sorted(a)
c=sorted(c)
ans=0

def srca(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return cent
    elif end==frt+1 and x[end]!=y:
      return frt+1
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return end+1
def srcc(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return n-cent-1
    elif end==frt+1 and x[end]!=y:
      return n-end
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return n-frt
for i in b:
  ans+=srca(a, i)*srcc(c, i)
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)
c=sorted(c)
ans=0

def srca(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return cent
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return end+1
def srcc(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return n-cent-1
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return n-frt
for i in b:
  ans+=srca(a, i)*srcc(c, i)
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(reverse=False)
A.append(float('inf'))
C.sort(reverse=False)
C.append(float('inf'))

# A > B > Cである組み合わせの数を求める
count = 0
    
for ib in range(N):
    
    top_a = N
    bottom_a = 0
    count_a = 0
    while top_a >= bottom_a:
        middle_a = (top_a + bottom_a) // 2

        if A[middle_a] == B[ib]:
            count_a = middle_a
            break
        if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
            count_a = middle_a + 1
            break
        if middle_a == 0:
            count_a = middle_a
            break
        if A[middle_a] > B[ib]:
            top_a = middle_a
        if A[middle_a] < B[ib]:
            bottom_a = middle_a + 1


    top_c = N
    bottom_c = 0
    count_c = 0
    while top_c >= bottom_c:
        middle_c = (top_c + bottom_c) // 2

        if C[middle_c] == B[ib]:
            count_c = middle_c + 1
            break
        if C[middle_c] < B[ib] and B[ib] < C[middle_c + 1]:
            count_c = middle_c + 1
            break
        if middle_c == 0:
            count_c = middle_c
            break
        if C[middle_c] > B[ib]:
            top_c = middle_c
        if C[middle_c] < B[ib]:
            bottom_c = middle_c + 1

    count += (count_a) * (N - count_c)

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.sort(reverse=False)
A.append(float('inf'))
C.sort(reverse=False)
C.append(float('inf'))

# A > B > Cである組み合わせの数を求める
count = 0
    
for ib in range(N):
    
    top_a = N
    bottom_a = 0
    count_a = 0
    while top_a >= bottom_a:
        middle_a = (top_a + bottom_a) // 2

        if A[middle_a] == B[ib]:
            count_a = middle_a
            break
        if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
            count_a = middle_a + 1
            break
        if middle_a == 0:
            count_a = middle_a
            break
        if A[middle_a] > B[ib]:
            top_a = middle_a
        if A[middle_a] < B[ib]:
            bottom_a = middle_a + 1


    top_c = N
    bottom_c = 0
    count_c = 0
    while top_c >= bottom_c:
        middle_c = (top_c + bottom_c) // 2

        if C[middle_c] == B[ib]:
            count_c = middle_c + 1
            break
        if C[middle_c] < B[ib] and B[ib] < C[middle_c + 1]:
            count_c = middle_c + 1
            break
        if middle_c == 0:
            count_c = middle_c
            break
        if C[middle_c] > B[ib]:
            top_c = middle_c
        if C[middle_c] < B[ib]:
            bottom_c = middle_c + 1


    count += (count_a) * (N - count_c)

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, reverse=False)
A.insert(0, 0)
A.append(float('inf'))
B = sorted(B, reverse=False)

# A > B > Cである組み合わせの数を求める

print('A', A)
print('B', B)
print('C', C)

count = 0
for ic in range(N):
    bottom_a = 0
    for ib in range(N):
        if B[ib] >= C[ic]:
            break
        
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] == B[ib]:
                count_a = middle_a - 1
                break
            if A[middle_a] < B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a
        bottom_a = count_a

print(count)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = set(map(int, input().split()))
    B = set(map(int, input().split()))
    C = set(map(int, input().split()))
    A = list(A)
    B = list(B)
    C = list(C)
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for b in B:
        idx_a = bisect_left(A, b)
        idx_c = bisect_right(C, b)
        ans += idx_a * (N - idx_c)
    print(ans) 

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, reverse=False)
A.insert(0, 0)
A.append(float('inf'))
B = sorted(B, reverse=False)
# A > B > Cである組み合わせの数を求める

count = 0
for ic in range(N):
    for ib in range(N):
        if B[ib] >= C[ic]:
            break
        
        bottom_a = 0
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] <= B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a

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, reverse=False)
A.insert(0, 0)
A.append(float('inf'))
B = sorted(B, reverse=False)
B.insert(0, 0)
B.append(float('inf'))
# A > B > Cである組み合わせの数を求める

count = 0
for ic in range(N):
    bottom_b = 0
    top_b = N
    count_b = 0
    while top_b >= bottom_b:
        middle_b = (top_b + bottom_b) // 2

        if B[middle_b] <= C[ic] and C[ic] < B[middle_b + 1]:
            count_b = middle_b
            break
        if B[middle_b] > C[ic]:
            top_b = middle_b
        if B[middle_b] < C[ic]:
            bottom_b = middle_b + 1


    for ib in range(1, count_b + 1):
        bottom_a = 0
        top_a = N
        count_a = 0
        while top_a >= bottom_a:
            middle_a = (top_a + bottom_a) // 2

            if A[middle_a] <= B[ib] and B[ib] < A[middle_a + 1]:
                count_a = middle_a
                break
            if A[middle_a] > B[ib]:
                top_a = middle_a
            if A[middle_a] < B[ib]:
                bottom_a = middle_a + 1

        count += count_a

print(count)

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)

    result = 0
    A_init = A[0]
    #初期化
    index = True
    for i, num in enumerate(B):
        if num > A_init:
            index = i
            break
    if index:
        print(0)
        sys.exit()
    past = index
    for i in A:
        index = past
        past = index
        for j in range(index, B_len):
            if B[j] > i:
                result += C_len - bisect(C,B[j])
            else:
                past += 1
    print(result)

if __name__ == "__main__":
    main()

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

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

# にぶたんで数えていく
cnt = 0

B_cnt = [0]*N

for i in range(N):
    ng = bisect.bisect_left(C, B[i])
    B_cnt[i] = N-ng

B_cum = [0]*N
B_cum[-1] = B_cnt[-1]

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

B_cum.append(0)

for i in range(N):
    cnt += B_cum[bisect.bisect_right(B, A[i])]

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()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search1(list,item):
    low = 0
    high = len(list) - 1

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

def binary_search2(list,item):
    low = 0
    high = len(list) - 1

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

ans=0

for i in range(n):
    #print(binary_search1(a,b[i]),binary_search2(c,b[i]),i)
    ans+=binary_search2(c,b[i])*binary_search1(a,b[i])

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()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search(list,item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            if high == low:
                return high
            high = mid
        else:
            if high == low:
                    return high+1
            low = mid+1
def binary_search2(list,item):
    low = 0
    high = len(list) - 1

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

ans=0

for i in range(n):
    #print(binary_search(a,b[i]),binary_search2(c,b[i]),i)
    ans+=(n-binary_search2(c,b[i]))*binary_search(a,b[i])

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()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search(list,item):
    low = 0
    high = len(list) - 1

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

def binary_search2(list,item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        #print(guess)
        if guess == item:
            if mid!=n-1:
                return d[mid+1]
            else:
                return 0
        if guess > item:
            if high == low:
                return d[high]
            high = mid
        else:
            if high == low:
                if high!=n-1:
                    return d[high+1]
                else:
                    return 0
            low = mid+1

for i in range(n):
    #print(binary_search(c,b[i]))
    d.append(n-binary_search(c,b[i]))
#print(d)
d.reverse()
import numpy
d=numpy.cumsum(d)
d=list(d)
d.reverse()
#print(d)
ans=0

for i in range(n):
    ans+=binary_search2(b,a[i])

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)

ans=0
max1=n-1
max2=n-1

for x in range(n)[::-1]:
  maxC=c[x]
  min1=0
  while max1-min1>1:
    zantei=(max1+min1)//2
    if b[zantei]>=maxC:
      max1=zantei
    else:
      min1=zantei
  if b[max1]<maxC:
    ch=max1
  elif b[min1]>=maxC:
    continue
  else:
    
    ch=min1
  
  for y in range(ch+1)[::-1]:
    maxB=b[y]
    min2=0
    while max2-min2>1:
      zantei1=(max2+min2)//2
      if a[zantei1]>=maxB:
        max2=zantei1
      else:
        min2=zantei1
    if a[max2]<maxB:
      ch1=max2
    else:
      ch1=min2
      
    ans+=ch1+1
    
print(ans)

Submission status: Wrong Answer

Solution code:

import sys

read=sys.stdin.read
readline=sys.stdin.readline

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.sort()
    b.sort()
    c=[-x for x in c]
    c.sort()

    def bise(x,lst):
        left=0
        right=len(lst)
        while right-left>1:
            mid=(right+left)//2
            if lst[mid]>=x:
                right=mid
            else:
                left=mid
        return left
    print(sum((bise(x,a)+1)*(bise(-x,c)+1) for x in b))

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:

import sys
from heapq import heapify,heappop,heappush
from collections import defaultdict
read=sys.stdin.read
readline=sys.stdin.readline

def main():
    n=int(readline())
    a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
    a.append(float('inf'))
    a.sort()
    b.sort()
    c.sort()

    bc=defaultdict(int)
    mi=0
    mj=0
    for mid in b:
        for i in range(mi,n):
            if c[i]>mid:
                mi=i
                break
        for j in range(mj,n+1):
            if a[j]>=mid:
                bc[mid]+=j*(n-i)
                mj=j
                break

    print(sum(bc[x] for x in iter(bc.keys())))

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heapify,heappop,heappush
from collections import defaultdict
read=sys.stdin.read
readline=sys.stdin.readline

n=int(readline())
a,b,c=(list(map(int,lst.split())) for lst in read().splitlines())
a.append(max(b)+1)
a.sort()
b.sort()
c.sort()

bc=defaultdict(int)
mi=0
mj=0
for mid in b:
  for i in range(mi,n):
    if c[i]>mid:
      mi=i
      break
  for j in range(mj,n+1):
    if a[j]>=mid:
      bc[mid]+=j*(n-i)
      mj=j
      break

print(sum(bc[x] for x in iter(bc.keys())))

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

comb = 0
mid_start = 0

while mid_start < N:
    mid_value = B[mid_start]
    mid_end = bisect.bisect_right(B,mid_value)
    mid_num = mid_end - mid_start
    top_end = bisect.bisect_left(A,mid_value)
    top_num = top_end
    bottom_start = bisect.bisect_right(C,mid_value)
    bottom_num = N - bottom_start
    if top_num == 0 or bottom_num == 0: break
    comb += top_num * mid_num * bottom_num
    mid_start = mid_end

print(comb)

Submission status: Wrong Answer

Solution code:
def find_small_than(x,A):
    
    first=0
    last=len(A)-1
    mid = (last+first)//2
    while 1:
        if A[mid]<=x:
            first=mid
            mid = (last+first)//2
        else:
            last=mid
            mid = (last+first)//2
        
        # print(first,mid,last)
        
        if first==mid :
            break
    
    
    if x<A[0]:
        mid=-1
        
    if A[-1]<x:
        mid = len(A)-1
    
    # print(x,A,mid)
    # print(mid)
            
    return mid
        
        
    
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

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


# print(find_small_than(5,A))
count = 0
for a in A:
    b_start = find_small_than(a,B)+1
    
    for b in range(b_start,len(B)):
        
        c_start = find_small_than(B[b],C)+1
        
        count += len(C)-c_start
            
print(count)

Submission status: Wrong Answer

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

lenc=len(C)

from bisect import *

cnt=0
for b in set(B):
    in_a = bisect_left(A, b)
    in_c = bisect_right(C, b)
    cnt+= in_a*(lenc-in_c)

print(cnt)

Submission status: Wrong Answer

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

from bisect import *

cnt=0
for a in A:
    in_b = bisect_right(B, a)
    for b in set(B[in_b:]):
        in_c = bisect_right(C, b)
        for c in set(C[in_c:]):
            print(a,b,c)
            cnt+=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()))


def binary_search_left(target_list, key):
    left = 0
    right = len(target_list)
    while left < right:
        mid = (left + right) // 2
        if target_list[mid] == key:
            return mid
        elif key < target_list[mid]:
            right = mid
        else:
            left = mid + 1
    return left


def binary_search_right(target_list, key):
    left = 0
    right = len(target_list)
    while left < right:
        mid = (left + right) // 2
        if target_list[mid] == key:
            return mid + 1
        elif key < target_list[mid]:
            right = mid
        else:
            left = mid + 1
    return left


a.sort()
c.sort()
sum_count = 0
for i in b:
    sum_count += binary_search_left(a, i) * (N - binary_search_right(c, i))
print(sum_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()))


def binary_search(target_list, key):
    left = 0
    right = len(target_list)
    while left < right:
        mid = (left + right) // 2
        if target_list[mid] == key:
            return mid
        elif key < target_list[mid]:
            right = mid
        else:
            left = mid + 1
    return left


a.sort()
c.sort()
sum_count = 0
for i in b:
    sum_count += binary_search(a, i) * (N - binary_search(c, i))
print(sum_count)

Submission status: Wrong Answer

Solution code:
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))
c.sort()
b_limit = 0
count =0

for i in a:
    if b_limit == 1:
        break
    for j in  reversed(b):
        if j <= i:
            b_limit +=1
            break
        for k in reversed(c):
            if k <= j:
                break
            count +=1

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

check_li = [0]*(n+10)

for i in range(len(b_li)):
    s = bisect.bisect_right(c_li, b_li[i])
    check_li[i] = len(c_li[s:])

# tmp = 0
# for i in range(1, n+11):
#     check_li[-i] = check_li[-i] + tmp
#     tmp = check_li[-i]

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    ans += check_li[s]

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()
print(A)
print(B)
print(C)

def is_ok(G, index, key):
  if G[index] >= key:
    return True
  else:
    return False

def meg_bisect(G, key):
  ng = -1
  ok = len(G)
  #ok = length
  while abs(ok-ng) > 1:
    mid = (ok + ng) // 2
    if is_ok(G, mid, key):
      ok = mid
    else:
      ng = mid
  return ok

ans = 0

for i in range(N):
  b_index = meg_bisect(B, A[i]) #b配列のindex
  for i in range(b_index, N):
    c_index = meg_bisect(C, B[i])
    ans += N-c_index

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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

    A.sort()
    C.sort()
    C.append(INF)
    ans = 0


    for b in B:
        a = bisect_left(A, b)
        c = bisect_left(C, b)
        if C[c]==b:
            c += 1
        ans += a*(N-c)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def binary_search(a, L, N):
    s = 0
    f = N-1
    h = N//2
    while s < f:
        if a < L[h]:
            f = h-1
        else:
            s = h+1
        h = (s+f)//2
    if L[h] < a:
        return h+1
    else:
        return h

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
sum_b = [0]*N
for i in range(N):
    b[i] = binary_search(B[i], A, N)
    sum_b[i] = sum_b[i-1]+b[i]

c = [0]*N
sum_c = [0]*N
for i in range(N):
    x = binary_search(C[i], B, N)
    if x > 0:
        c[i] = sum_b[x-1]
    sum_c[i] = sum_c[i-1]+c[i]

print(sum_c[-1])

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in b:
    ans += (n - bisect_right(c, j))*bisect_right(a, j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in a:
    for j in range(bisect(b, i), n):
        ans += n - bisect(c, 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()))

def is_ok(mid, array, n):  return array[mid] > n

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

ans = 0
BtoC = []
for i in range(N):
    ret = binary_search(-1, N, C, B[i])
    if ret != N:
        BtoC.append(N - ret)
    else:
        BtoC.append(0)
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[i])]
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()))

def is_ok(mid, array, n):  return array[mid] > n

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

ans = 0
BtoC = [N - binary_search(-1, N, C, B[i]) for i in range(N)]
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[i])]
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())))

bcomb=[0 for i in range(n)]
sm=0

for i,y in enumerate(b):
    if a[0]>y :
        bcomb[i]=0
        continue
    if a[n-1]<y :
        bcomb[i]=n
        continue
    mn=0
    mx=n-1
    while mx-mn>=2:
        mid=(mn+mx)//2
        if a[mid]<y:
            mn=mid
        else : mx=mid
    bcomb[i]=mn+1

bcomb=[sum(bcomb[:i]) for i in range(1,n+1)]

for j,z in enumerate(c):
    if b[0]>z : continue
    if b[n-1]<z :
        sm+=bcomb[n-1]
        continue
    mn=0
    mx=n-1
    while mx-mn>=2:
        mid=(mn+mx)//2
        if b[mid]<z :
            mn=mid
        else : mx=mid
    sm+=bcomb[mn]

print(sm)

Submission status: Wrong Answer

Solution code:
def binary(list_a,item):
  low=0
  high=len(list_a)-1
  while (high-low)>1:
    mid=int((low+high)/2)
    tmp=list_a[mid]
    if tmp>item:
      high=mid
    elif tmp<item:
      low=mid
    elif tmp==item:
      eq=[i for i, x in enumerate(list_a) if x == tmp]
      high=eq[-1]
      low=eq[0]
      if high==len(list_a):
        high-=1
      if low==0:
        low+=1
      return low-1,high+1
  return low,high

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0
  for b in B:
    a_low,a_high=binary(A,b)
    c_low,c_high=binary(C,b)
    
    if b>A[N-1]:
      a_low=N-1
    elif b<=A[0]:
      a_low=0
      
    if b<C[0]:
      c_high=0
    elif b>=C[N-1]:
      c_high=N
    
    ans+=(a_low+1)*(N-c_high)
  print(ans)
  
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def binary_search(list_a,item):
  low=0
  high=len(list_a)-1
  flag=True
  while low<=high:
    mid=int((low+high)/2)
    guss=list_a[mid]
    if guss>item:
      high=mid-1
    elif guss<item:
      low=mid+1
    elif guss==item:
      return mid
  return mid

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0    
  for b in B:
    p=binary_search(A,b)
    if A[p]>=b:
      tmp_p=p
    elif A[p]<b:
      tmp_p=p+1
    q=binary_search(C,b)
    if C[q]>b:
      tmp_q=N-q
    elif C[q]<=b:
      tmp_q=N-q-1
    ans+=tmp_p*tmp_q
  print(ans)
  
if __name__=="__main__":
  main()