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:
# encoding: utf-8
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())))

### TLE test in NlogN ###

# # num of Ai each Bi can lift
# capacity_B = [0] * N
# idx_A = 0
# idx_B = 0
# for i in range(2 * N):
#     if idx_B == N: break
#     elif idx_A == N:
#         for i in range(idx_B, N): capacity_B[i] = N
#     elif A[idx_A] >= B[idx_B]:
#         capacity_B[idx_B] = idx_A
#         idx_B += 1
#     else:
#         idx_A += 1
        
# # print("#", capacity_B)

# # num of Bi each Ci can lift
# capacity_C = [0] * N
# idx_B = 0
# idx_C = 0
# for i in range(2 * N):
#     if idx_C == N: break
#     elif idx_B == N:
#         for i in range(idx_C, N): capacity_C[i] = N
#     elif B[idx_B] >= C[idx_C]:
#         capacity_C[idx_C] = idx_B
#         idx_C += 1
#     else:
#         idx_B += 1

# # print("#", capacity_C)

# # num of (Ai, Bi) each Ci can lift
# stacked = [0] * N
# idx_AB = 0
# idx_BC = 0
# sum_tmp = 0
# for i in range(2 * N):
#     if idx_BC == N: break
#     elif idx_AB == N:
#         for i in range(idx_BC, N): stacked[i] = sum_tmp
#     elif idx_AB >= capacity_C[idx_BC]:
#         stacked[idx_BC] = sum_tmp
#         idx_BC += 1
#     else:
#         sum_tmp += capacity_B[idx_AB]
#         idx_AB += 1

# # print("#", stacked)

# # the answer is sum of All
# print(sum(stacked))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
N = int(input())
ABC = [list(map(int, input().split())) for i in range(3)]

memo = [[None] * N for i in range(3)] # row 0 is dummy ?

def stack(height, base, base_idx):
    if height == 3: return 1
    elif memo[height][base_idx] != None: return memo[height][base_idx]
    ret = 0
    for i, width in enumerate(ABC[2 - height]):
        if width < base: ret += stack(height + 1, width, i)
    if memo[height][base_idx] == None: memo[height][base_idx] = ret
    return ret

print(stack(0, 10 ** 5, 0))

Submission status: Wrong Answer

Solution code:

import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aA = sorted([int(_) for _ in input().split()])
    aB = sorted([int(_) for _ in input().split()])
    aC = sorted([int(_) for _ in input().split()])

    #想定解法どおりやろうとすると場合分けが増えてミスも増えて大変だ。

    idxA = 0
    idxC = 0
    iAns = 0
    iA = aA[0]
    for idxB_s in range(iN):
        if iA >= aB[idxB_s]:
            continue
        else:
            break
    for idxB in range(idxB_s,iN):
        iB = aB[idxB]
        while aA[idxA] < iB:
            idxA += 1
            if idxA == iN:
                idxA -= 1
                break
        if 0 < idxA  and aA[idxA] >= iB:
            idxA -= 1

        if aC[-1] <= iB:
            break
        elif aC[0] > iB:
            iAns += (idxA + 1) * iN
            continue
        else:
            while aC[idxC] <= iB:
                idxC += 1
                if idxC == iN :
                    idxC -= 1
                    break
            if idxC < iN and aC[idxC] > iB:
                idxC -= 1
            elif idxC == iN-1:
                break
        iAns += (idxA + 1 )* (iN - idxC -1 )
    print(iAns)
解()

Submission status: Wrong Answer

Solution code:
import bisect

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

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

ans=bisect.bisect_left(A,B[0])*(N-bisect.bisect_right(C,B[0]))

for i in range(1,N):
  if B[i]!=B[i-1]:
    ans+=(bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i])))

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *

n = int(input())
a,b,c = [sorted(map(int,input().split())) for i in range(3)]

print(sum([bisect_left(a,i)*bisect_right(c,i) for i in b]))

Submission status: Wrong Answer

Solution code:
def Bsearch(X, i, Y):
    if X[i] <= Y[0]:
        return False
    else:
        min, max = 0, len(X)
        while max - min > 1:
            mid = (min + max) // 2
            if X[i] > Y[mid]:
                min = mid
            else:
                max = mid
        return min

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

Btotal = [0 for i in range(N)]
Ctotal = [0 for i in range(N)]
Btotal[0] = (0 if Bsearch(B, 0, A) == False else Bsearch(B, 0, A) + 1)
for i in range(1, N):
    Btotal[i] = Btotal[i-1] + (0 if Bsearch(B, i, A) == False else Bsearch(B, i, A) + 1)
Ctotal[0] = (0 if Bsearch(C, 0, B) == False else Btotal[Bsearch(C, 0, B)])
for i in range(1, N):
    Ctotal[i] = Ctotal[i-1] + (0 if Bsearch(C, i, B) == False else Btotal[Bsearch(C, i, B)])
print(Ctotal[N-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
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()

bcnt = [0]*n
for i, bi in enumerate(b):
    j = bisect.bisect_left(a, bi)
    if i == 0:
        bcnt[i] = j
    else:
        bcnt[i] = bcnt[i-1] + j
cnt = 0
for i, ci in enumerate(c):
    j = bisect.bisect_left(b, ci)
    if j == 0:
        continue
    else:
        cnt += bcnt[j-1]
    print(ci, j, bcnt[j-1], cnt)
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

a_max = 0
c_min = 0
ans = 0

for j in range(N):
    b = B[j]

    a_max = bisect.bisect_left(A,b,a_max,N)
    c_min = bisect.bisect_right(C,b,c_min,N)

    print(a_max,c_min)

    ans += len(A[:a_max]) * len(C[c_min:])

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect_left
    from bisect import bisect_right

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

    for i, bi in enumerate(b):
        less = bisect_left(a, bi)
        greater = n - bisect_right(c, bi)

        if a[less - 1] == bi:
            less -= 1

        if a[greater - 1] == bi:
            greater -= 1

        ans += less * greater

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from bisect 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())))
    ans = 0

    for i, bi in enumerate(b):
        less = bisect(a, bi)
        greater = n - bisect(c, bi)

        if a[less - 1] == bi:
            less -= 1

        if a[greater - 1] == bi:
            greater -= 1

        ans += less * greater

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from bisect 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())))
    ans = 0

    for i, bi in enumerate(b):
        less = bisect(a, bi)
        greater = n - bisect(c, bi)

        if a[less - 1] == bi:
            less -= 1

        ans += less * greater

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

ans = 0
for i in range(n):
    anum = bisect.bisect_right(a, b[i])
    cnum = n - bisect.bisect_left(c, b[i])
    ans += anum * cnum

print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
INF = 10 ** 18
A = sorted(map(int, raw_input().split())) + [INF]
B = sorted(map(int, raw_input().split())) + [INF]
C = sorted(map(int, raw_input().split())) + [INF]

DP = [i for i in range(N + 1)]
DP2 = [0 for i in range(N + 1)]

pos = 0
for i in range(N):
  while A[pos] < B[i]:
    pos += 1
  DP2[i + 1] = DP2[i] + DP[pos]
DP = DP2

pos = 0
for i in range(N):
  while B[pos] < C[i]:
    pos += 1
  DP2[i + 1] = DP2[i] + DP[pos]
DP = DP2

print DP[N]

Submission status: Wrong Answer

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

DP = [i for i in range(N + 1)]
DP2 = [0 for i in range(N + 1)]

pos = 0
for i in range(N):
  while pos < N and A[pos] < B[i]:
    pos += 1
  DP2[i + 1] = DP2[i] + DP[pos]
DP = DP2

pos = 0
for i in range(N):
  while pos < N and B[pos] < C[i]:
    pos += 1
  DP2[i + 1] = DP2[i] + DP[pos]
DP = DP2

print DP[N]

Submission status: Wrong Answer

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

for i in B:
    iA = bisect.bisect_right(A, i)
    iB = bisect.bisect_right(C, i)
    ans += (iA)*(N-iB)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
B = np.array([int(i) for i in input().split()])
C = np.array([int(i) for i in input().split()])

ans = 0

for b in B:
	ans += len(A<b) + len(C>b)

print(ans)

Submission status: Wrong Answer

Solution code:
#ABC077C 解説を見て自作
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())))
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    C_under_B[i]=N-bisect.bisect_left(C,B[i])
#あるBの上にいくつAが乗るか数える
A_on_B=[0]*N     #i番目のBの上に乗るAの数
for i in range(N):
    A_on_B[i]=bisect.bisect_right(A,B[i])
#あるBの上下におけるものを数えて出力
ans=0
for i in range(N):
    ans+=C_under_B[i]*A_on_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()))

def binary_search(list,target,b):
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:
            return center+1 if b else center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1

    if list[center]<target:
        center+=1
    return center

A.sort()
C.sort()
ans=0
for b in B:
    ans+=binary_search(A,b,0)*(len(C)-binary_search(C,b,1))
print(ans)

Submission status: Wrong Answer

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0
    if lst[-1] == act:
        return n-1

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def calc2(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0
    if lst[-1] == act:
        return n


    low = 0
    high = n-1
    #切り上げのため+1してる
    mid = (low + high+1)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid+1
        elif lst[mid] < act:
            low = mid
            mid = (low + high+1)//2
            if tmp == mid:
                return mid
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high+1)//2
            if tmp == mid:
                return mid
            else:
                tmp = mid



def main():
    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
    for i in range(n):
        aans = calc(n,b[i],a)
        cans = calc2(n,b[i],c)
        ans += aans * (n-cans)

    print(ans)


if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0
    if lst[-1] == act:
        return n-1

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def calc2(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0
    if lst[-1] == act:
        return n


    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid+1
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def main():
    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
    for i in range(n):
        aans = calc(n,b[i],a)
        cans = calc2(n,b[i],c)
        ans += aans * (n-cans)



    print(ans)


if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def calc2(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid+1
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def main():
    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
    for i in range(n):
        aans = calc(n,b[i],a)
        cans = calc2(n,b[i],c)
        ans += aans * (n-cans)

    print(ans)


if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def calc2(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid+1
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2


def main():
    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
    for i in range(n):
        aans = calc(n,b[i],a)
        cans = calc2(n,b[i],c)
        ans += aans * (n-cans)
        print(aans * (n-cans))

    """
    for i in range(n):
        tmp = calc(n,c[i],b)
        ans += sum(blist[:tmp])
    """

    print(ans)


if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2




def main():
    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)

    #blist = [0 for i in range(n)]
    ans = 0

    for i in range(n):
        aans = calc(n,b[i],a)
        cans = calc(n,b[i],c)
        ans += aans * (n-1-cans)

    """
    for i in range(n):
        tmp = calc(n,c[i],b)
        ans += sum(blist[:tmp])
    """


    print(ans)


if __name__ == "__main__":
        main()

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(x) for x in input().split()])
B = sorted([int(x) for x in input().split()])
C = sorted([int(x) for x in input().split()])
a = 0
c = 0
cnt = 0
for i in range(N):
  while a < N:
    if A[a] < B[i]:
      a += 1
    else:
      break
  while c < N:
    if C[c] < B[i]:
      c += 1
    else:
      break
  cnt += a * (N - c)
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()))
print(A)
A.sort()
B.sort()
C.sort()
print(A)
Sum = 0
for i in range(N):
    Start_B = bisect.bisect_left(B,A[i]+1)
    for j in range(Start_B, N):
        Start_C = bisect.bisect_left(C,B[j]+1)
        Sum += N - Start_C
print(Sum)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
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()]
# N = 6
# A = sorted([int(i) for i in '3 14 159 2 6 53'.split()])
# B = sorted([int(i) for i in '58 9 79 323 84 6'.split()])
# C = sorted([int(i) for i in '2643 383 2 79 50 288'.split()])
res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

N = 6
A = sorted([int(i) for i in '3 14 159 2 6 53'.split()])
B = sorted([int(i) for i in '58 9 79 323 84 6'.split()])
C = sorted([int(i) for i in '2643 383 2 79 50 288'.split()])
res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
res = 0
cnt_a = 0
cnt_c = 0
for b in B:
    for ca in range(cnt_a, N):
        if A[ca] >= b:
            cnt_a = ca
            break
        if ca == N-1:
            if A[ca] < b:
                ca = N
                cnt_a = N
                break

    for cc in range(cnt_c, N):
        if C[cc] > b:
            cnt_c = cc
            break
        if cc == N-1:
            if b > C[cc]:
                cc = N
                cnt_c = N
                break
    res += (N - cc) * ca
print(res)

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
import bisect


def main():
    n = int(raw_input())
    A = sorted(map(int, raw_input().split()))
    B = sorted(map(int, raw_input().split()))
    C = sorted(map(int, raw_input().split()))
    AB = [0] * n
    BC = [0] * n

    for ai in range(n):
        idx = bisect.bisect_left(B, A[ai])
        AB[ai] = n - idx

    for bj in range(n):
        idx = bisect.bisect_left(C, B[bj])
        BC[bj] = n - idx

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
def main():
    n = int(raw_input())
    A = sorted(map(int, raw_input().split()))
    B = sorted(map(int, raw_input().split()))
    C = sorted(map(int, raw_input().split()))
    AB = [0] * n
    BC = [0] * n

    comb = 0
    for ai in range(n):
        for bj in range(n):
            if A[bj] < B[bj]:
                AB[bj] = n - bj
                break

    for bj in range(n):
        for ck in range(n):
            # CからB[bj]よりも大きくなる瞬間のidxを探し、n-idxを足す。
            if B[bj] < C[ck]:
                BC[bj] = n - ck
                break

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = input().split()
B = input().split()
C = input().split()
count = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i] < B[j] < C[k]:
                count+=1
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()))
bina = 0
binc = 0
count = 0
for b_tree in b:
    while bina < N and a[bina] < b_tree:
        bina += 1
    while binc < N and c[binc] <= b_tree:
        binc += 1
    count += bina * (N-binc)

print(count)

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

total = 0
j = 0
for i in range(N):
    counta = 0
    countc = 0
    while (j < N and A[j] < B[i]):
        counta += 1
        j += 1
    j = 0
    while (j < N and C[j] > B[i]):
        countc += 1
        j += 1
    j = 0
    total += (counta * countc)

print(total)

Submission status: Wrong Answer

Solution code:
n =  int(input())
print(int(n ** 0.5)**2)

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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
stopping_b = 0
stopping_c = 0
count_R = 0
past_ans = 0
first_b_num = 0
count_3rd = -1

for i in range(N):
    if A[i] > B[i] or A[i] > C[i] or C[N - 1] < A[i] or C[N - 1] < B[i] or B[N - 1] < A[i]:
        continue
    if count_R > 0:
        if A[i] < B[first_b_num]:
            count += past_ans
            continue
    a = A[i]
    for j in range(stopping_b, N):
        b = B[j]
        for k in range(stopping_c, N):
            c = C[k]
            count_3rd += 1
            if a < b < c:
                count += N - k
                stopping_c = k
                if count_3rd == 0:
                    first_b_num = j
                break
    else:
        count_3rd = 0
        stopping_c = 0
        count_R += 1
        past_ans = count - past_ans
        stopping_b = first_b_num
        first_b_num = 0
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
stopping_b = 0
stopping_c = 0
count_R = 0
past_ans = 0
first_b_num = 0
count_3rd = 0

for i in range(N):
    if A[i] > B[i] or A[i] > C[i] or C[N - 1] < A[i] or C[N - 1] < B[i] or B[N - 1] < A[i]:
        continue
    if count_R > 0:
        if A[i] < B[first_b_num]:
            count += past_ans
            continue
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(stopping_c, N):
            c = C[k]
            if a < b < c:
                count += N - k
                stopping_c = k
                if count_3rd == 0:
                    first_b_num = j
                break
        else:
            count_3rd += 1
    else:
        stopping_c = 0
        count_R += 1
        past_ans = count - past_ans
        first_b_num = 0
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
while True:
    for i in range(N):
        if A[i] > B[i] or A[i] or C[i]:
            continue
        a = A[i]
        for j in range(N):
            b = B[j]
            for k in range(N):
                c = C[k]
                if a < b < c:
                    count += 1
    else:
        break

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 = 0
b = 0
c = 0
count = 0
cutting = 0
A.sort()
B.sort()
C.sort()

for i in range(N):
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(N):
            c = C[k]
            if a < b < c:
                count += (N - k) * (N - k)
                break
        else:
            break
else:
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
res = 0
for i in range(N):
    low = 0
    high = N - 1
    # t は中央番目の数
    t1 = (low + high) // 2 
    # 探索の下限のlowが上限のhighになるまで探索
    # lowがhighに達すると数は見つからなかったということ
    while (low <= high):
        if ( A[t1-1] <= B[i] < A[t1]):
            break
        elif (B[i] > A[t1]):
            low = t1 + 1
        elif (B[i] < A[t1]):
            high = t1- 1
        elif (t1 == N-1):
            break
        t1 = (low + high) // 2
    
    low = 0
    high = N - 1
    t2 = (low + high) // 2 

    while (low <= high):
        if ( C[t2-1] <= B[i] < C[t2] ):
            break
        elif (B[i] > C[t2]):
            low = t2 + 1
        elif (B[i] < C[t2]):
            high = t2 - 1
        elif (t2 == 0):
            break
        t2 = (low + high) // 2
    
    res += (t1+1) * (N - t2 - 1)
    print(res, t1, t2)

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

def bs1(a, x):
    l, r = 0, len(a)
    mid = (r + l) // 2
    while r - l > 0:
        if a[mid] == x:
            return mid
        if x > a[mid]:
            l = mid + 1
        else:
            r = mid
        mid = (r + l) // 2
    return mid

def bs2(a, x):
    l, r = 0, len(a)
    mid = (r + l) // 2
    while r - l > 0:
        if a[mid] == x:
            return mid + 1
        if x > a[mid]:
            l = mid + 1
        else:
            r = mid
        mid = (r + l) // 2
    return mid

for e in B:
    res += (bs1(A, e)) * (N - bs2(C, e))

print(res)

Submission status: Wrong Answer

Solution code:
import bisect
def inpl(): return list(map(int, input().split()))
N = int(input())
a, b, c = sorted(inpl()), sorted(inpl()), sorted(inpl())
print(a)
print(b)
print(c)
ans = 0
for j in b:
    ans += bisect.bisect_left(a, j)*(N-bisect.bisect_right(c, 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()

count=0
for i in range (N):
    count_A=bisect.bisect_left(A,B[i])
    count_B=len(C)-bisect.bisect_right(C,B[i])
    print(count_A)
    print(count_B)
    count+=count_A*count_B
print(count)

Submission status: Wrong Answer

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