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

sums = 0
#bを固定しloopを取る
for i in range(n):
    middle = b[i]
    ca = 0
    cc = 0
    for j in range(n):
        if a[j] < middle:
            ca = ca + 1
    for j in range(n):
        if c[j] < middle:
            cc = cc + 1
    sums = sums + ca * cc
    
print(sums)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())



        
        
summer = 0
for j in bdic.keys():
    ai = 0
    ci = 0
    for i in range(j):
        if i in adic.keys():
            ai = ai + adic[i]
    for k in range(j,cma + 1):
        if k in cdic.keys():
            ci = ci + cdic[k]
    summer = summer + bdic[j] * ai * ci       
print(summer)

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})
"""
ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())
"""


        
        
summer = 0
for i in  adic.keys():
    for j in bdic.keys():
        if i < j:
            for k in cdic.keys():
                if j < k:
                    summer = summer + adic[i] * bdic[j] * cdic[k]
                else:
                    break
        else:
            break
print(summer)

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

li = [0] * n
j = 0

for i in range(n):
    while j < n and a[j] < b[i]:
        j += 1
    li[i] = j

lis = [0] * n

m = 0
j = 0

for i in range(n):
    while j < n and b[j] < c[i]:
        m += li[j]
        j += 1
        lis[i] = m
print(sum(lis))

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

lis = [0] * n
j = 0
for i in range(n):
    while j < n and a[j] < b[i]:
        j += 1
    lis[i] = j

li = [0] * n
m = 0
j = 0
for i in range(n):
    while j < n and b[j] < c[i]:
        m += lis[i]
        j += 1
    li[i] = m
print(sum(li))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
c = c[::-1]
answer,x,y = 0,0,0
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(y+1):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
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()))
count = 0
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
print(A,B,C)

for a in A:
    for b in B:
        if a>= b:
            break
        for c in C:
            if a<b<c:
                count += 1
            else:
                break

print(count)

Submission status: Wrong Answer

Solution code:

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

    count = 0
    b = 0
    c = 0
    for a in A:
        for j in range(b, len(B)):
            if B[j] <= a:
                b = j-1
            if B[j] > a:
                for k in range(c, len(C)):
                    if C[k] <= B[j]:
                        c = k-1
                    if C[k] > B[j]:
                        count += 1

    print (count)




if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    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()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(B, b))

print(counter)

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()
counter = 0
for b in B:
    counter += bisect.bisect_right(A, b)*(N-bisect.bisect_left(B, b))

print(int(counter))

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()
answer = 0
for i in range(n):
	x = bisect.bisect(a,b[i])
	y = bisect.bisect(c,b[i])
	if b[i] != a[x-1]:
		answer += x*(n-y)
	else:
		answer += (x-1)*(n-y)
print(answer)

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()
print(a)
print(b)
print(c)
answer = 0
for i in range(n):
	x = bisect.bisect(a,b[i])
	y = bisect.bisect(c,b[i])
	if b[i] != a[x-1]:
		answer += x*(n-y)
	else:
		answer += (x-1)*(n-y)
print(answer)

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()
answer = 0
for i in range(n):
	x = bisect.bisect(a,b[i])
	y = bisect.bisect(c,b[i])
	if b[i] != a[x-1] and b[i] != c[y-1]:
		answer += x*(n-y)
	elif b[i] == a[x-1] and b[i] == c[y-1]:
		answer += (x+1)*(n-y+1)
	elif b[i] == a[x-1]:
		answer += x*(n-y)
	else:
		answer += x*(n-y+1)

print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
Alist.sort()
Clist.sort()
retnum = 0 
for i in Blist:
    Anum = bisect.bisect_left(Alist,i)
    Cnum =  N - bisect.bisect_right(Clist,i)
    print(Anum)
    print(Cnum)
    retnum +=(Anum * Cnum)
print(retnum)

Submission status: Wrong Answer

Solution code:

N = int(raw_input())
As = raw_input().split(" ")
Bs = raw_input().split(" ")
Cs = raw_input().split(" ")

As = [(int(i), 2) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 0) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    #print i
    if i[1] == 0:
        ac += 1
    elif i[1] == 1:
        bc += ac
        #print bc
    elif i[1] == 2:
        cc += bc
        #print cc
print cc

Submission status: Wrong Answer

Solution code:

N = int(raw_input())
As = raw_input().split(" ")
Bs = raw_input().split(" ")
Cs = raw_input().split(" ")

As = [(int(i), 0) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 2) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0])

ac = 0
bc = 0
cc = 0

for i in l:
    print i
    if i[1] == 0:
        ac += 1
    elif i[1] == 1:
        bc += ac
        print bc
    elif i[1] == 2:
        cc += bc
        print cc
print cc

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

n = raw_input()
n = int(n)

a = raw_input()
a = a.split()
a = map(int,a)
b = raw_input()
b = b.split()
b = map(int,b)
c = raw_input()
c = c.split()
c = map(int,c)

an = np.array(a,int)
bn = np.array(b,int)
cn = np.array(c,int)

check_b = np.zeros([n],int)
for i in range(n):
    check_b[i] = len(np.where(an<bn[i])[0])
print check_b
check_c = np.zeros([n],int)
for j in range(n):
    check_c[j] = np.sum(check_b[np.where(bn<cn[j])[0]])
print check_c
ans = np.sum(check_c)

print ans

Submission status: Wrong Answer

Solution code:
import bisect

#動的計画法だった
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

ans = 0
for i in mid:
    ans += bisect.bisect_left(ue, i) * (len(bot) - bisect.bisect_right(bot, i))
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

#動的計画法だった
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

# ueのi番目に対してmidが何個あるのか
# midのj番目に対してbotが何個あるのかを計算すればいい
# 定数*N^2となるはず

uemid = [N]*N
mid_pos = 0
for i in range(len(ue)):
    mid_pos = bisect.bisect_right(mid, ue[i])
    uemid[i] = mid_pos


midbot = [N]*N
bot_pos = 0
for i in range(len(mid)):
    bot_pos = bisect.bisect_right(bot, mid[i])
    midbot[i] = bot_pos

"""
print(ue)
print(mid)
print(bot)
print(uemid)
print(midbot)
"""

ans = 0
for i in uemid:
    if i == len(mid):
        break
    for j in range(i, len(mid)):
        ans += len(bot) - midbot[j]

print(ans)

Submission status: Wrong Answer

Solution code:
#動的計画法だった
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

# ueのi番目に対してmidが何個あるのか
# midのj番目に対してbotが何個あるのかを計算すればいい
# 定数*N^2となるはず

uemid = [N]*N
mid_pos = 0
for i in range(len(ue)):
    while(mid[mid_pos] <= ue[i]):
        mid_pos += 1
        if mid_pos == len(mid):
            break
    if mid_pos == len(mid):
        break
    uemid[i] = mid_pos


midbot = [N]*N
bot_pos = 0
for i in range(len(mid)):
    while(bot[bot_pos] <= mid[i]):
        bot_pos += 1
        if bot_pos == len(bot):
            break
    if bot_pos == len(bot):
        break
    midbot[i] = bot_pos

"""
print(ue)
print(mid)
print(bot)
print(uemid)
print(midbot)
"""

ans = 0
for i in uemid:
    if i == N:
        break
    for j in range(i, len(mid)):
        ans += len(bot) - midbot[j]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()


ans = 0
for i in ue:
    for j in mid:
        if j <= i:
            continue
        else:
            for k in range(len(bot)):
                if bot[k] <= j:
                    continue
                else:
                    ans += len(bot) - k

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

import bisect

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

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

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

    cnt = 0
    for b in B:
        a_index = bisect.bisect_left(A, b)
        c_index = bisect.bisect_right(C, b)
        cnt += a_index * (N - c_index)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for c in C:
	for b in B:
		if c > b:
			for a in A:
				if b > a:
					ans += 1
		
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N
    b = B[j]
    #print(b)
    while(high>low):
        mid = (high + low)//2
        if b > A[mid]:
            low = mid +1
        else:
            high = mid
    acount = mid
    while (high2>low2):
        mid2 = (high2 + low2)//2
        if b < C[mid2]:
            high2 = mid2
        else:
            low2 = mid2 + 1
    ccount=N-mid2
    sum += acount*ccount
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N - 1
    mid =mid2 = (N - 1) // 2
    b = B[j]
    #print(b)

    if A[0] > b:
        acount = 0
    else:
        while high > low:
            if A[mid] < b:
                if low == mid:
                    if A[mid+1] < b:
                            low += 1
                    elif A[mid+1] >= b:
                            high += - 1
                else:
                    low = mid
            if A[mid] >= b:
                high = mid-1
            mid = (high + low) // 2
        acount = mid + 1


    while high2 > low2:
        #print(mid2)
        if C[mid2] > b:
            high2 = mid2
        if C[mid2] <= b:
            if low2 == mid2:
                if C[mid2+1] > b:
                    low2 += 1
                elif C[mid2+1] <=b:
                    high2 -= 1
            else:
                low2 = mid2 + 1
        mid2 = (high2 + low2)//2
    ccount = N-mid2
    if C[N-1] < b:
        ccount = 0
    sum += acount*ccount
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N - 1
    mid =mid2 = (N - 1) // 2
    b = B[j]
    #print(b)

    if A[0] > b:
        acount = 0
    else:
        while high > low:
            if A[mid] < b:
                if low == mid:
                    if A[mid+1] < b:
                            low += 1
                    elif A[mid+1] >= b:
                            high += - 1
                else:
                    low = mid
            if A[mid] >= b:
                high = mid-1
            mid = (high + low) // 2
        acount = mid + 1


    while high2 > low2:
        #print(mid2)
        if C[mid2] > b:
            high2 = mid2
        if C[mid2] <= b:
            if low2 == mid2:
                if C[low2+1] > b:
                    low2 += 1
                elif C[low2+1] <=b:
                    high2 -= 1
            else:
                low2 = mid2 + 1
        mid2 = (high2 + low2)//2
    ccount = N-mid2
    sum += acount*ccount
print(sum)

Submission status: Wrong Answer

Solution code:
"""
snuke festival
"""

def input_list():
    """
    returns list from stdin
    """
    input_map = map(int, input().split())
    return list(input_map)

def get_bigger_index(base_num, sub_list):
    """
    returns first index that is bigger than base number
    """
    bigger_index = -1
    for index, item in enumerate(sub_list):
        if base_num < item:
            bigger_index = index
            break
    return bigger_index

def main():
    """
    main function.
    """
    base_len = int(input())
    top = input_list()
    mid = input_list()
    btm = input_list()

    top.sort()
    mid.sort()
    btm.sort()

    result = 0

    for i in range(base_len):
        mid_index = get_bigger_index(top[i], mid)
        if mid_index < 0:
            break
        else:
            btm_index = get_bigger_index(mid[mid_index], btm)
            if btm_index >= 0:
                result += (base_len - mid_index) * (base_len + btm_index)

    print(result)

main()

Submission status: Wrong Answer

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

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

def binary_search_lower(array,target):
    # arrayの中のtarget 未満の最大インデックスを返す
    low = 0
    high = len(array)-1
    
    while (low != high):
        t = int((low + high) / 2)
        if (target==array[t]):
            break
        elif (target > array[t]):
            low = t + 1
        elif (target < array[t]):
            high = t - 1
    
    t = int((low + high) / 2)
    if(target == array[t]):
        return t - 1
    elif(target < array[t]):
        return t - 1
    elif(target > array[t]):
        return t
      
def binary_search_upper(array,target):
    low = 0
    high = len(array) -1
    # t は中央番目の数
    
    while (low != high):
        t = int((low + high) / 2)
        if (target==array[t]):
            break
        elif (target > array[t]):
            low = t + 1
        elif (target < array[t]):
            high = t - 1
    
    t = int((low + high) / 2)
    if(target == array[t]):
        return t + 1
    elif(target < array[t]):      
        return t
    elif(target > array[t]):
        return t + 1
      
ans = 0
for j in range(N):
    i_ix = binary_search_lower(A,B[j])
    k_ix = binary_search_upper(C,B[j])
    i = i_ix + 1
    k = N-k_ix
    ans += i*k
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
def search(num,key):
    global n,a,b,c
    left = 0
    right = n-1
    factor = -1
    if num == 1:
        l = a
    else:
        l = c
    while left <= right:
        mid = (left+right)//2
        if key < l[mid]:
            right = mid-1
        elif l[mid] < key:
            left = mid+1
        else:
            if num == 1:
                factor = mid
            else:
                factor = mid+1
            break
    else:
        if factor == -1:
            factor = left
    return factor

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()
c.sort()
for tmp in range(n):
    ans += search(1, b[tmp])*(n-search(2, b[tmp]))
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)
cnt = 0
for a in A:
    for b in B:
        if a>=b: break
        for c in C:
            if b>=c: break
            cnt = cnt+1
print(str(cnt))

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A,B,C = sorted(Is()),sorted(Is()),sorted(Is())

Bs = [0]*N
b,j = 0,0
for i in range(N):
    while j < N:
        if B[i] >= C[j]:
            b += 1
        else:
            Bs[i] = N - b
            break
        if j == N-1:
            Bs[i] = N - b
            break
        j += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())

partA = list(map(int, input().split()))
partA.sort()
partB = list(map(int, input().split()))
partB.sort()
partC = list(map(int, input().split()))
partC.sort()
cnt = 0


for i in range(N):
    Ahier = 0
    Chier = 0
    for p in range(N):
        if partB[i] >= partA[p]:
            Ahier += 1
            #print(partA[p])
            #print(Ahier)

        if partB[i] <= partC[p]:
            Chier += 1
            #print(partC[p])
            #print(Chier)

    cnt += (Ahier * Chier)

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A,B,C = sorted(Is()),sorted(Is()),sorted(Is())

Bs = [0]*N
for i in range(N):
    b = 0
    for j in range(N):
        if B[i] < C[-j-1]:
            b = j+1 
        else:
            Bs[i] = b
            break
sum = 0
for i in range(N):
    for j in range(N):
        if A[i] < B[-j-1]:
            sum += Bs[-j-1]
        else:
            break
print(sum)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import math
import itertools
import heapq
import numpy as np
from collections import OrderedDict, deque, Counter
from bisect import bisect_left, bisect_right, insort_left, insort_right
sys.setrecursionlimit(10000)

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def solve():
    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)
    print(B)
    print(C)
    cnt = 0
    for ele in B:
        cnt += bisect_left(A, ele) * (len(C) - bisect_right(C, ele))

    print(cnt)


solve()

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline())
 
As= list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs= list(map(int, sys.stdin.readline().rstrip().split(" ")))
Cs= list(map(int, sys.stdin.readline().rstrip().split(" ")))
  
class Solve:
    def __init__(self):
        self.result = 0 
    def check(self, Alist, Blist, Clist):       
        if len(Alist) == 1:
            if len(Blist) == 1:
                self.result = self.result + len(Clist)               
            else:
                for B in Blist:
                    self.check(Alist, [B], list(filter(lambda x : x > B, Clist)))
        else:
            for A in Alist:
                self.check([A], list(filter(lambda x : x > A, Blist)), list(filter(lambda x : x > A, Clist)))
 
solve = Solve()
solve.check(As, Bs, Cs)
print (solve.result)

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()))
ans = 0
a.sort()
b.sort()
c.sort()
for y in range(n):
    if a[n-1] <= b[y]:
        a_ans = n
    elif a[0] > b[y]:
        a_ans = 0
    else:
        left = 0
        right = n
        while True:
            mid = (left + right) // 2
            if a[mid] < b[y] and b[y] <= a[mid+1]:
                a_ans = mid + 1
                break
            elif a[mid] > b[y]:
                right = mid - 1
            else:
                left = mid + 1

    if b[y] <= c[0]:
        c_ans = n
    elif b[y] > c[n-1]:
        c_ans = 0
    else:
        left = 0
        right = n
        while True:
            mid = (left + right) // 2
            if c[mid] <= b[y] and b[y] < c[mid+1]:
                c_ans = n - mid - 1
                break
            elif c[mid] > b[y]:
                right = mid - 1
            else:
                left = mid + 1
    ans += a_ans * c_ans
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

a = 0
b = 0
c = 0
e = 0
table = [[0] * 3 for i in range(3 * N + 1)]
for i in range(1, 3 * N + 1):
    table[i][0] = table[i - 1][0]
    table[i][1] = table[i - 1][1]
    table[i][2] = table[i - 1][2]
    if a < N and link[i - 1] == A[a]:
        a += 1
        table[i][0] = a
    elif b < N and link[i - 1] == B[b]:
        b += 1
        if link[i - 1] == A[a - 1]:
            e += (a - 1) * (N - c)
            continue
        table[i][1] = table[i - 1][1] + table[i][0]
    else:
        c += 1
        if link[i - 1] == A[a - 1] or link[i - 1] == B[b - 1]:
            e += table[i - 2][1]
            continue
        table[i][2] = table[i - 1][2] + table[i][1]

print(table[3 * N][2] + e)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
link = A + B + C
A.sort()
B.sort()
C.sort()
link.sort()
print(link)

a = 0
b = 0
c = 0
e = 0
table = [[0] * 3 for i in range(3 * N + 1)]
for i in range(1, 3 * N + 1):
    table[i][0] = table[i - 1][0]
    table[i][1] = table[i - 1][1]
    table[i][2] = table[i - 1][2]
    if a < N and link[i - 1] == A[a]:
        a += 1
        table[i][0] = a
    elif b < N and link[i - 1] == B[b]:
        b += 1
        if link[i - 1] == A[a - 1]:
            e += (a - 1) * (N - c)
            continue
        table[i][1] = table[i - 1][1] + table[i][0]
    else:
        c += 1
        if link[i - 1] == A[a - 1] or link[i - 1] == B[b - 1]:
            e += table[i - 2][1]
            continue
        table[i][2] = table[i - 1][2] + table[i][1]
print(table[3 * N][2] + e)

Submission status: Wrong Answer

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

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

cnt = 0
len_c = len(C)
for a in A:
  for b in B:
    if a > b: continue
    for idx, c in enumerate(C):
      if b > c:
        continue
      else:
        cnt += len_c-idx
#        print(a,b,c,len_c-idx)
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))

b_index = list(map(lambda x: N-x if (x != -1) else 0, b_index))
bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    tmp = tmp - b_index[i]

res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += N * (N - a_i) - bb[a_i]
print(str(res))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))

bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    tmp = tmp - b_index[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += N * (N - a_i) - bb[a_i]
print(str(res))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cand1 = [0 for i in range(n)]
cand2 = [0 for i in range(n)]
tmp = n - 1
for j in range(n):
    for i in range(tmp, -1, -1):
        if a[i] < b[j]:
            tmp = i
            cand1[j] += i + 1
            break
tmp = 0
for j in range(n):
    for k in range(tmp, n):
        if b[j] < c[k]:
            tmp = k
            cand2[j] += n - k
            break
ans = sum(np.array(cand1) * np.array(cand2))
print (ans)