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:
# coding: utf-8
# Your code here!
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 = 0
    right = len(ar)-1
    center = (left + right) // 2
    
    if flag == 0:
        if key < ar[left]:
            return 0
        elif ar[right] < key:
            return len(ar)
    elif flag == 1:
        if key < ar[left]:
            return len(ar)
        elif ar[right] < key:
            return 0
    
    while left <= right:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif left == right:
            if flag == 0:
                if ar[center] < key:
                    return center+1
                else:
                    return center
            if flag == 1:
                if ar[center] < key:
                    return len(ar)-1-center
                else:
                    return len(ar)-center
        elif ar[center] < key:
            left = center + 1
            center = (left + right) // 2
        else:
            right = center - 1
            center = (left + right) // 2
    return 0

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)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
C = []
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):
  for j in range(N):
  	if A[i] < B[j]:
          for o in range(N):
            if B[j] < C[o]:
              count += 1

          
print(N,A,B,C,count)

Submission status: Wrong Answer

Solution code:
import sys

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

BtoC = []
cc = 0
for i in range(N):
	b_tmp = B[i]
	cond = False
	for c in range(cc, N):
		if C[c] > b_tmp:
			cc = c
			break
		if c == N:
			cc = N

	BtoC.append(N-cc)

S_BtoC = [BtoC[-1]]

for i in reversed(range(N-1)):
	S_BtoC.append(S_BtoC[-1] + BtoC[i])

S_BtoC.reverse()

ans = 0
cb = 0
for i in range(N):
	for b in range(cb, N):
		if A[i] < B[b]:
			cb = b
			break
		if b == N-1:
			print(ans)
			sys.exit()
	ans += S_BtoC[cb]

print(ans)

Submission status: Wrong Answer

Solution code:
def nibu_A(list,item):
    high=len(list)
    low=-1
    while abs(high-low) > 1:
        mid=(high+low)//2

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


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 range(n):
    data=B[i]
    ans+=(nibu_A(A,data)*nibu_c(C,data))
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
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(' '))))
    c_len=len(c)
    ans = 0
    for i in b:
        ans_a=bisect.bisect_right(a,i)
        ans_c=c_len-bisect.bisect_left(c,i)
        ans += ans_a*ans_c
    print(ans)

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()))
A.sort()
B.sort()
C.sort()
sum = 0
for i in range(0,N-1):
  a = A[i]
  b = B[i+1]
  c_min = b-a+1
  c_max = a+b-1
  l = bisect.bisect_left(C,c_min,lo = i+1)
  if l!= N:
    r = bisect.bisect_right(C,c_max,lo = i+1)
    if r:
      r = r-1
      if r >= l:
        sum += r-l+1
print(sum)

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()
sum = 0
for i in range(0,N):
  a = A[i]
  for j in range(1,N):
    b = B[j]
    c_min = b-a+1
    c_max = a+b-1
    l = bisect.bisect_left(C,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(C,c_max,lo = j+1)
      if r:
        r = r-1
        if r >= l:
          sum += r-l+1
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    A = string_to_int(inputs[1])
    B = string_to_int(inputs[2])
    C = string_to_int(inputs[3])
    A.sort()
    B.sort()
    C.sort()

    patterns = 0
    for c in C:
        bi = bisect.bisect_right(B, c-1)
        ai = bisect.bisect_right(A, B[bi-1])
        patterns += bi * ai
    return patterns


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(4))
    print(ret)

Submission status: Wrong Answer

Solution code:
import bisect as bis

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

ans = 0
for i in range(n):
    top = a[i]
    j_s = bis.bisect_right(b, top)
    for j in range(j_s, n):
        mid = b[j_s]
        k = bis.bisect_right(c, mid)
        ans += (n - k)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
z=[]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
    z.append([a[i],0])
    z.append([b[i],1])
    z.append([c[i],2])
z.sort()
p=[0]*(n*3+1)
q=[0]*(n*3+1)
bi=[]
for i in range(n*3):
    if z[i][1]==1:
        bi.append(i)
    if z[i][1]==0:
        p[i]+=1
    p[i+1]=p[i]
    if z[n*3-1-i][1]==2:
        q[3*n-i]+=1
    q[3*n-i-1]=q[3*n-i]
ans=0
for i in bi:
    if i>0 and z[i-1][0]==z[i][0] and z[i-1][1]==0:
        p[i]-=1
    if i<n*3-1 and z[i+1][0]==z[i][0] and z[i+1][1]==2:
        q[i]-=1
    ans+=p[i]*q[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
ary = [sorted(map(int,input().split())) for _ in range(3)]
print(ary)
ans = 0
for i in range(n):
    a = bisect.bisect_left(ary[0],ary[1][i])
    b = n - bisect.bisect_right(ary[2],ary[1][i])
    ans += a*b
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

def binary (l,num):
    high=len(l)-1
    low=0
    
    while True:
        print(high,low)
        mid=int((high+low))//2
        if l[mid]<num:
            if l[mid+1]>=num:
                return mid
            else:
                print("a")
                low=mid
        elif l[mid]>=num:
            if l[mid-1]<num:
                return (mid-1)
            else:
                print("b")
                high=mid
                
print(binary([1,3,4,5,6],3))
#一時保存

Submission status: Wrong Answer

Solution code:
def f(a,c,index):
    b = -(-len(a)//2)
    if len(a) == 1:
        if c < a[0]:return index-1
        elif c > a[0]:return index+1
        else:return index
    if len(a) == 2:
        if c < a[0]:
            return index+b-1
        elif c > a[1]:
            return index+b+1
        else:return index+b
    if c > a[b]:
        return f(a[b:],c,index+b)
    elif c < a[b]:
        return f(a[:b],c,index)
    else:return index+b+1
n = int(input())
ary = [sorted(map(int,input().split())) for _ in range(3)]
check = [[0]*n for _ in range(3)]
for i in range(2):
    for j in range(n):
        check[i][j] = f(ary[i+1],ary[i][j],0)
ans = 0
for i in check[0]:
    for j in range(i,n):
        ans += n-check[1][j]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

A.sort()
B.sort()
C.sort()
c_len = len(C)

cnt = 0
for b in B:
    a_cnt = bisect.bisect_left(A,b)
    c_cnt = c_len - bisect.bisect_left(C,b)
    cnt +=  a_cnt * c_cnt

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

cnt = 0

for a in A:
    for b in B:
        if a>=b:
            break
        for c in reversed(C):
            if b>=c:
                break
            cnt += 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()))

answer = 0
for a in A:
    bi = bisect.bisect_right(B, a)
    for i in range(bi, N):
        ci = bisect.bisect_right(C, B[i])
        answer += N - ci

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    cnt = 0
    for x in a:
        i = bisect_left(b, x)
        for y in b[i:]:
            j = bisect_left(c, y)
            cnt += len(c[j:])

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = np.searchsorted(A, B, side='left')

B = sorted(np.array(B) * (-1))
C = sorted(np.array(C) * (-1))

c = np.searchsorted(C, B, side='left')

print((a * c).sum())

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()
cnt = 0
for b in B:
  pos_a = bisect.bisect_right(A, b)
  pos_c = bisect.bisect_right(C, b)
  cnt += pos_a * (N-pos_c)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
B = input()
C = input()
A = sorted(list(map(int, A.strip("¥n").split(" "))))
B = sorted(list(map(int, B.strip("¥n").split(" "))))
C = sorted(list(map(int, C.strip("¥n").split(" "))))
l_a = len(A)
l_b = len(B)
l_c = len(C)
p_a = 1
p_b = 0
p_c = 0
ss = 0
for b in B:
  for i in range(p_a, l_a):
    p_a = i
    if A[i] >= b:break
  for i in range(p_c, l_c):
    p_c = i
    if C[i] > b:break
    if p_c == l_c - 1:p_c = l_c
  s = (p_a) * (l_c - p_c)
  ss += s
print (ss)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
B = input()
C = input()
A = sorted(list(map(int, A.strip("¥n").split(" "))))
B = sorted(list(map(int, B.strip("¥n").split(" "))))
C = sorted(list(map(int, C.strip("¥n").split(" "))))
l_a = len(A)
l_b = len(B)
l_c = len(C)
p_a = 0
p_b = 0
p_c = 0
ss = 0
for b in B:
  for i in range(p_a, l_a):
    if A[i] >= b:break
    p_a = i
  for i in range(p_c, l_c):
    p_c = i
    if C[i] > b:break
  s = (p_a + 1) * (l_c - p_c)
  ss += s
print (ss)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0
comb_n_list = []

# 自分より大きい個数
start_c_index = 0
start_a_index = 0

for i in range(N):  # 10 ** 5
    b = b_list[i]
    if i != 0 and b == b_list[i-1]:
        comb_n_list.append(comb_n_list[i-1])
        comb_n += comb_n_list[i-1]
    else:
        for j, c in enumerate(c_list[start_c_index:]):
            if c > b:
                # 最初に見つかった対象パーツのインデックス
                start_c_index = start_c_index + j
                break
        c_n = N - start_c_index
        goal_last_flag = True
        for j, a in enumerate(a_list[start_a_index:]):
            if a >= b:
                # 最初に見つかった不一致パーツのインデックス
                start_a_index = start_a_index + j
                goal_last_flag = False
                break

        if goal_last_flag:
            a_n = N
        else:
            a_n = start_a_index
        comb_n += a_n * c_n
        comb_n_list.append(a_n * c_n)
        # print(a_n, c_n)

ans = comb_n
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
print(a)
for i in range(N):
    flag = 0
    for j in range(memo, N):
        print(a[0][i], a[1][j])
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            dataa.append(0)
        break
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            datab.append(0)
        break
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[0][i] < a[1][j]:
            memo = i
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        dataa.append(0)
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = i
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        datab.append(0)
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[0][i] < a[1][j]:
            memo = i
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        dataa.append(0)
memo = 0
for i in range(N):
    flag = 0
    for j in range(0, N):
        if a[1][i] < a[2][j]:
            memo = i
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        datab.append(0)
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
C.sort()
ans = sum([bisect_left(A, b) * bisect_right(C, b) for b in B])
print(ans)

Submission status: Wrong Answer

Solution code:

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

A.sort()
C.sort()

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search(A, b)
    c_ub, c_lb = bin_search(C, b)
    # print(A[:a_ub], C[c_ub:])
    total += a_ub * (N - c_ub)

print(total)

Submission status: Wrong Answer

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

A.sort()
C.sort()

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search(A, b)
    c_ub, c_lb = bin_search(C, b)
    # print(A[:a_ub], C[c_ub:])
    total += len(A[:a_ub]) * len(C[c_ub:])

print(total)

Submission status: Wrong Answer

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

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

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search(A, b)
    c_ub, c_lb = bin_search(C, b)
    # print(A[:a_ub], C[c_ub:])
    # print("a: lb, ub", a_lb, a_ub)
    # print("c: lb, ub", c_lb, c_ub)
    total += len(A[:a_ub]) * len(C[c_ub:])
    # total += a_lb * (N - c_ub)

print(total)

Submission status: Wrong Answer

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

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

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    c_ub, c_lb = bin_search(C, b)
    a_ub, a_lb = bin_search(A, b)
    # print("a: lb, ub", a_lb, a_ub)
    # print("c: lb, ub", c_lb, c_ub)
    total += (len(B) - c_ub) * a_ub

print(total)

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())))
B=[0]*n
j=0
for i in range(n):
    while b[i]>=c[j] and j<n-1:j+=1
    B[i]=n-j
ans=0
s=sum(B)
j=0
for i in range(n):
    while a[i]>=b[j] and j<n-1:s-=B[j];j+=1
    if a[i]<b[j]:ans+=s
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    tmplist = []
    for i,val in enumerate(B):
        target1 = bisect_left(C, val+1)
        tmp = N - target1
        tmplist.append(tmp)
            
    for i in range(N-2, -1, -1):
        tmplist[i] = tmplist[i] + tmplist[i+1]
        
    print(tmplist)
    
    ans = 0
    for i,val in enumerate(A):
        target1 = bisect_left(B, val+1)
        if target1 == N:
            continue
        ans += tmplist[target1]
        
    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.sort()
B.sort()
C.sort()

b_ptn = [0] * (N)
last = 0
for idx, b in enumerate(B):
  cnt = 0
  for j in range(last, N):
    if A[j] < b:
      cnt += 1
    else:
      last = j
      break
  if idx == 0:
  	b_ptn[idx] = cnt
  else:
    b_ptn[idx] = b_ptn[idx-1] + cnt
ans = 0
last = 0
for c in C:
  for idx in range(last, N):
    if B[idx] >= c:
      last = idx
      break
  if c > B[-1]:
    ans += sum(b_ptn)
  else:
  	ans += sum(b_ptn[:last])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    tmplist = []
    for i,val in enumerate(B):
        target1 = bisect_left(C, val+1)
        tmp = N - target1
        tmplist.append(tmp)
            
    for i in range(N-2, -1, -1):
        tmplist[i] = tmplist[i] + tmplist[i+1]
        
    print(tmplist)
    
    ans = 0
    for i,val in enumerate(A):
        target1 = bisect_left(B, val+1)
        if target1 == N:
            continue
        ans += tmplist[target1]
        
    print(ans)
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    tmplist = []
    for i,val in enumerate(B):
        target1 = bisect_left(C, val)
        tmp = N - target1
        tmplist.append(tmp)
            
    for i in range(N-2, -1, -1):
        tmplist[i] = tmplist[i] + tmplist[i+1]
        
    #print(tmplist)
    
    ans = 0
    for i,val in enumerate(A):
        target1 = bisect_left(B, val)
        if target1 == N:
            continue
        ans += tmplist[target1]
        
    print(ans)
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    B = inputList()
    C = inputList()
    
    A.sort()
    B.sort()
    C.sort()
    
    ans = 0
    for i,val in enumerate(A):
        tmp = 0
        target1 = bisect_left(B, val)
        for j in range(target1, N):
            target2 = bisect_left(C, B[j])
            #print(target2)
            tmp = N - target2
            ans += tmp
        
    print(ans)
            	
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()))
A.sort()
C.sort()
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_left(C,b))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in [0]*3]

a.sort(reverse=True)
b.sort()
c.sort()

p,q=0,0
cnt=0
for i in range(n):
	pp=p
	for j in range(pp,n):
		if a[pp]>=b[i]:
			pp+=1
		else:
			break
	qq=q
	for j in range(qq,n):
		if c[qq]<=b[i]:
			qq+=1
		else:
			break
	cnt+=(n-pp)*(n-qq)
	p=pp
	q=qq
print(cnt)

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

G = sorted(A)
H = sorted(B)

P = [bisect_left(G, n) for n in B]
Q = [bisect_left(H, n) for n in C]

print(sum([p * q for p, q in zip(P, Q)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
la=sorted(list(map(int,input().split())))
lb=sorted(list(map(int,input().split())))
lc=sorted(list(map(int,input().split())))
def lower(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=(left+right)//2
    if n>l[mid]:
      left=mid
    elif n<=l[mid]:
      right=mid
  return left+1
def upper(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=(left+right)//2
    if n>=l[mid]:
      left=mid
    elif n<l[mid]:
      right=mid
  return len(l)-right
c=0
for i in lb:
  c+=lower(i,la)*upper(i,lb)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
def lower(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=(left+right)//2
    if n>l[mid]:
      left=mid
    elif n<=l[mid]:
      right=mid
  return left+1
def upper(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=(left+right)//2
    if n>=l[mid]:
      left=mid
    elif n<l[mid]:
      right=mid
  return len(l)-right
c=0
for i in lb:
  c+=lower(i,la)*upper(i,lb)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
def lower(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=left+right
    mid=mid//2
    if n>l[mid]:
      left=mid
    elif n<=l[mid]:
      right=mid
  return left+1
def upper(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=left+right
    mid=mid//2
    if n>=l[mid]:
      left=mid
    elif n<l[mid]:
      right=mid
  return len(l)-right
c=0
for i in lb:
  c+=lower(i,la)*upper(i,lb)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
def lower(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=left+right
    mid=mid//2
    if n>l[mid]:
      left=mid
    elif n<=l[mid]:
      right=mid
  return left+1
def upper(n,l):
  left=-1
  right=len(l)
  while right>left+1:
    mid=left+right
    mid=mid//2
    if n>l[mid]:
      left=mid
    elif n<=l[mid]:
      right=mid
  return len(l)-right
c=0
for i in lb:
  c+=lower(i,la)*upper(i,lb)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
la=sorted(list(map(int,input().split())))
lb=sorted(list(map(int,input().split())))
lc=sorted(list(map(int,input().split())))
def nib1(x,l):
  right=len(l)-1
  left=0
  mid=(right+left)//2
  while left<=right:
    mid=(right+left)//2
    if x<l[mid]:
      right=mid-1
    elif x>l[mid]:
      left=mid+1
    else:
      return [mid,1]
  mid=(right+left)//2
  return [mid,0]
c=0 
for i in range(n):
  a=nib1(lb[i],la)
  if a[1]==1:
    c+=(a[0])*(n-1-nib1(lb[i],lc)[0])
  else:
    c+=(a[0]+1)*(n-1-nib1(lb[i],lc)[0])
print(c)

Submission status: Wrong Answer

Solution code:
def lower(A, b):
    i = -1
    j = len(A)
    while j - i > 1:
        m = (i + j) // 2
        if A[m] < b:
            i = m
        else:
            j = m
    return i + 1


def upper(C, b):
    i = -1
    j = len(C)
    #print('upper', C, b)
    while j - i > 1:
        m = (i + j) // 2
        #print(i, m, j, C[m] > b)
        if C[m] > b:
            i = m
        else:
            j = m
    return i + 1


def answer(N, A, B, C):
    A.sort()
    B.sort()
    C.sort()
    #print(A, B, C)
    count = 0
    for b in B:
        #print(b, lower(A, b), upper(C, b))
        count += lower(A, b) * upper(C, b)
    return count


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
print(answer(N, A, B, C))

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()
A.append(0)

B.sort()
C.sort()
C.reverse()
C.append(10**9+1)

ans = 0

ci = 0
bi = 0
ai = 0


while True:

    if bi == N:
        break

    while True:

        if ai == N or A[ai] >= B[bi]:
            ai -= 1
            break

        else:
            ai += 1

    while True:

        if ci == N or C[ci] <= B[bi] :
            ci -= 1
            break

        else:
            ci += 1

    ans += (ai+1) * (ci+1)

    bi += 1

print (ans)