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:
def binery_search(left,right,keynum,list):
    mid = 0
    while True:
            #print(left,right,mid,cnt)
            mid = int( (left+right)/2 )
            if keynum == list[mid]:
                return mid+1
                break
            elif keynum < list[mid]:
                right = mid
            elif keynum > list[mid]:
                left = mid + 1

            if left == right:
                return left

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()
    B_num = []
    for i in range(N):
        B_num.append(N-binery_search(0,N,B[i],C))
    #累積和を計算
    B_ruiseki = [0]*N
    B_ruiseki[N-1] = B_num[i]
    for i in range(N-2,-1,-1):
        B_ruiseki[i] = B_ruiseki[i+1] + B_num[i]

    ans = 0
    for i in range(N):
        #print(binery_search(0,N,A[i],B))
        tmp = binery_search(0,N,A[i],B)
        if tmp >= N:
            continue
        else:
            ans += B_ruiseki[binery_search(0,N,A[i],B)]

    return ans

print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))
    C = list(map(int, sysread().split()))
    A.sort()
    B.sort()
    C.sort()
    ansBa = []
    ansBc = []
    for i in range(N):
        b = B[i]
        idx = bisect.bisect_left(A, b)
        ansBa.append(idx)

        idx2 = bisect.bisect_left(C, b)
        ansBc.append(N-idx2)
        if idx2 < N and b == C[idx2]:
            ansBc[-1] -= 1
    #print(ansBc, ansBa)
    ans = 0
    for aa, cc in zip(ansBa, ansBc):
        ans += aa * cc


    print(ans)

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
import bisect
import sys
n = int(input())
up = sorted(list(set(map(int, input().split()))))
mid = sorted(list(set(map(int, input().split()))))
low = sorted(list(set(map(int, input().split()))))
ans = 0
for i in range(len(mid)):
    pre = bisect.bisect_left(up, mid[i])
    over = len(low) - bisect.bisect(low, mid[i])
    ans += pre * over

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
n = int(input())
up = sorted(list(set(map(int, input().split()))))
mid = sorted(list(set(map(int, input().split()))))
low = sorted(list(set(map(int, input().split()))))
ans = 0
for i in range(len(up)):
    # if len(mid) > 1:
    #     a = bisect.bisect(mid, up[i])
    # else:
    #     a = 0 if up[i] < mid[i] else 1
    a = bisect.bisect(mid, up[i])
    for j in range(len(mid) - a):
        # if len(low) > 1:
        #     b = bisect.bisect(low, mid[j], 0, len(low) - 1)
        #     ans += (len(low) - b)
        # else:
        #     ans += 1 if mid[i] < low[i] else 0
        b = bisect.bisect(low, mid[j], 0, len(low) - 1)
        ans += (len(low) - b)


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)

# for this we will use binary search.
import bisect as bis

BSC = [0]*N

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])
    
for i in range (1, N):
	BSC[i] += BSC[i-1]

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)

Submission status: Wrong Answer

Solution code:
import bisect

N= int(input())
a = map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

a = sorted(a)
b = sorted(b)
c = sorted(c,reverse=True)

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    ans+=x*(n-y)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    ans+=x*(n-y)
    print(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    b = bisect.bisect_left(B, C[i])
    a = bisect.bisect_left(A, B[min(b, n-1)])
    ans += a * b
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
b.sort()
c.sort()
from bisect import bisect_left
count = 0
for ci in range(n):
  b_right = bisect_left(b, c[ci]) - 1
  if b_right < 0:
    continue
  for bi in range(b_right+1):
    a_right = bisect_left(a, b[bi]) - 1
    an = a_right + 1
    if a_right < 0:
      break
    count += an
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

ans=0

for i in range(n):
    num1 = bisect.bisect(a,b[i])
    num2 = n - bisect.bisect_left(c,b[i])
    ans += num1*num2

print(ans)

Submission status: Wrong Answer

Solution code:
def search(array, n, flag):
    left, right = 0, len(array) - 1
    temp = left if flag else right
    while left <= right:
        i = (left + right) // 2
        if array[i] == n:
            if flag:
                while True:
                    if i+1 < len(array) and array[i] == array[i+1]:
                        i += 1
                    else:
                        break
            if not flag:
                while True:
                    if i > 0 and array[i] == array[i-1]:
                        i -= 1
                    else:
                        break
            return i
        if array[i] < n:
            left = i + 1
            if flag and array[temp] != array[i]:
                temp = i
        else:
            right = i - 1
            if not flag and array[temp] != array[i]:
                temp = i
    return temp
N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
result = 0
for b in B:
    #print(search(A, b-1, True) + 1, N - search(C, b+1, False))
    result += (search(A, b-1, True) + 1) * (N - search(C, b+1, False))
print(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()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
count = 0
import bisect
for i in range(n):
    A = bisect.bisect(a,b[i]-1)
    B = bisect.bisect(c,b[i]+1)
    count += A*(n-B)
print(count)

Submission status: Wrong Answer

Solution code:
def main(n,a,b,c):
  import bisect
  ans=0
  todo=[[ai] for ai in a]
  while len(todo)>0:
    d=todo.pop()
    if len(d)==1:
      l=bisect.bisect_right(b,d[-1])
      d.append(0)
      for li in b[l:]:
        d[-1]=li
        todo.append(d)
    elif len(d)==2:
      l=bisect.bisect_right(c,d[-1])
      d.append(0)
      for li in b[l:]:
        d[-1]=li
        todo.append(d)
    elif len(d)==3:
      ans+=1
  print(ans)
if __name__=='__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())))
  main(n,a,b,c)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

readline = sys.stdin.readline
bileft = bisect.bisect_left
biright = bisect.bisect_right

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort(); C.sort()
    minA = min(A); maxA = max(A)
    minC = min(C); maxC = max(C)
    ans = 0
    for b in B:
        L = minA; R = maxA + 1
        mid = (L + R) // 2
        if b >= R:
            L = R
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2
        #print('L:{}, b:{}, R:{}'.format(L, b, R))
        a = bileft(A, L)
        #print(a, A)

        L = minC; R = maxC + 1
        mid = (L + R) // 2
        if b <= L-1:
            R = L-1
        else:
            while L + 1 < R:
                if mid <= b:
                    L = mid
                else:
                    R = mid
                mid = (L + R) // 2   
        #print('L:{}, b:{}, R:{}'.format(L, b, R))
        c = len(C) - biright(C, R)
        #print(c, C)
        #print('------')

        ans += a*c

    print(ans)

if __name__ == "__main__":
    main()

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

count = 0

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

for i in range(N):
  bis_a = len(A[:bisect_left(A, B[i])])
  bis_c = len(C[bisect_left(C, B[i]):])
  count += (bis_a*bis_c)

print(count)

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

count = 0

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

for i in range(N):
  bis_b = bisect_left(B, A[i])
  for j in range(bis_b, N):
    bis_c = bisect_left(C, B[j])
    count += len(C[bis_c:])

print(count)

Submission status: Wrong Answer

Solution code:
import bisect
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=num-bisect.bisect_right(und,i)
    num+=a*c
print(num)

Submission status: Wrong Answer

Solution code:
import bisect
num=0
n=int(input())
top=sorted(list(map(int,input().split())))
mid=sorted(list(map(int,input().split())))
und=sorted(list(map(int,input().split())))
for i in mid:
    a=bisect.bisect_left(top,i)
    c=num-bisect.bisect_right(und,i)
    num+=a*c
print(num)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
print(A)
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left
from itertools import accumulate

n = int(readline())
a = sorted(list(map(int, readline().split())))
b = sorted(list(map(int, readline().split())))
c = sorted(list(map(int, readline().split())))
check = [0] * n
ans = 0
for i in range(n):
    index = bisect_left(c, b[i])
    if index != n:
        if c[index] == b[i]:
            index += 1
    check[i] = n - index
cumsum = [0] + list(accumulate(check[::-1]))
for aa in a:
    index = bisect_left(b, aa)
    if index != n:
        if b[index] == aa:
            index += 1
    ans += cumsum[n - index]
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()
ans = 0
for i in range(n):
    for j in range(bisect.bisect_left(b,a[i]),n):
        ans += n-bisect.bisect_right(c,b[j])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
"""
print(a)
print(b)
print(c)
"""
for i in range(n):
    B_HIGH = n-1
    B_LOW = 0
    B_NOW = 0
    while(1 < (B_HIGH - B_LOW)):
        B_NOW = (B_HIGH + B_LOW)//2
        """print(B_NOW,end = " ")"""
        if c[i] < b[B_NOW]:
            B_HIGH = B_NOW
        else:
            B_LOW = B_NOW

    if b[B_NOW] == b[B_NOW - 1]:
        while(1):
            if B_NOW == 0 or b[B_NOW] != b[B_NOW - 1]:
                break
            else:
                B_NOW -= 1
    elif b[B_NOW] == b[B_NOW +1]:
        while(1):
            if B_NOW == n-1 or b[B_NOW] != b[B_NOW + 1]:
                break
            else:
                B_NOW += 1

    """print(c[i],b[B_NOW])"""
    for j in range(B_NOW,n):
        A_HIGH = n-1
        A_LOW = 0
        A_NOW = 0

        while(1 < (A_HIGH - A_LOW)):
            A_NOW = (A_HIGH + A_LOW)//2
            if b[j] < a[A_NOW]:
                A_HIGH = A_NOW
            else:
                A_LOW = A_NOW

        if a[A_NOW] == a[A_NOW - 1]:
            while(1):
                if A_NOW == 0 or a[A_NOW] != a[A_NOW - 1]:
                    break
                else:
                    A_NOW -= 1
        elif a[A_NOW] == a[A_NOW +1]:
            while(1):
                if A_NOW == n-1 or a[A_NOW] != a[A_NOW + 1]:
                    break
                else:
                    A_NOW += 1

        ans += A_NOW + 1

print(ans-1)

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()
ans = 0
print(a)
print(b)
print(c)
for i in range(n):
    B_HIGH = n-1
    B_LOW = 0
    B_NOW = 0
    while(1 < (B_HIGH - B_LOW)):
        B_NOW = (B_HIGH + B_LOW)//2
        print(B_NOW,end = " ")
        if c[i] < b[B_NOW]:
            B_HIGH = B_NOW
        else:
            B_LOW = B_NOW

    if b[B_NOW] == b[B_NOW - 1]:
        while(1):
            if B_NOW == 0 or b[B_NOW] != b[B_NOW - 1]:
                break
            else:
                B_NOW -= 1
    elif b[B_NOW] == b[B_NOW +1]:
        while(1):
            if B_NOW == n-1 or b[B_NOW] != b[B_NOW + 1]:
                break
            else:
                B_NOW += 1

    print(c[i],b[B_NOW])
    for j in range(B_NOW,n):
        A_HIGH = n-1
        A_LOW = 0
        A_NOW = 0

        while(1 < (A_HIGH - A_LOW)):
            A_NOW = (A_HIGH + A_LOW)//2
            if b[j] < a[A_NOW]:
                A_HIGH = A_NOW
            else:
                A_LOW = A_NOW

        if a[A_NOW] == a[A_NOW - 1]:
            while(1):
                if A_NOW == 0 or a[A_NOW] != a[A_NOW - 1]:
                    break
                else:
                    A_NOW -= 1
        elif a[A_NOW] == a[A_NOW +1]:
            while(1):
                if A_NOW == n-1 or a[A_NOW] != a[A_NOW + 1]:
                    break
                else:
                    A_NOW += 1

        ans += A_NOW + 1

print(ans-1)

Submission status: Wrong Answer

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

def bin_a(list,bi):
    ok=0
    ng=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi>list[mid]:
            ok=mid
        else:
            ng=mid
    return ok+1
def bin_c(list,bi):
    ok=n-1
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi<list[mid]:
            ok=mid
        else:
            ng=mid
    return n-ok

cnt=0
for i in range(n):
    cnt+=bin_a(a,b[i])*bin_c(c,b[i])
    #print(bin_a(a,b[i]),bin_c(c,b[i]))
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

A.sort()
B.sort()
C.sort()
ans=0

for b in B: #O(N)
    s = bisect.bisect_left(A,b) #O(logN)
    t = bisect.bisect_right(C,b) #O(logN)
    print(s,N-t,s*(N-t))
    ans += s*(N-t)
   
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ali = [0] * (N+1)
bli = [N - bisect.bisect_left(C,B[i]) for i in range(N)]
for i in range(N):
    ali[i+1] = ali[i] + bli[i]
print(sum([ali[N]-ali[bisect.bisect_left(B,A[i])] for i in range(N)]))

Submission status: Wrong Answer

Solution code:
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        d = bisect.bisect_left(a, i)
        e = len(c) - bisect.bisect_right(c, i)
        print(d,e)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def function1(array, number, first, last):
    if first+1 == last:
        return last
    index = (first+last)//2
    if number <= array[index]:
        return function1(array, number, first, index)
    else:
        return function1(array, number, index, last)


def function2(array, number, first, last):
    if first+1 == last:
        return last
    index = (first+last)//2
    if array[index] <= number:
        return function2(array, number, index, last)
    else:
        return function2(array, number, first, index)


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()
ans = 0
for i in range(0, N):
    a = function1(A, B[i], 0, N)
    b = N-function2(C, B[i], 0, N)
    ans += (a*b)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    abottom = 0
    atop = n
    while atop - abottom >1:
        amid = (atop + abottom )//2
        if b[i] > a[amid]:abottom = amid
        else:atop = amid
    cbottom = -1
    ctop = n
    while ctop - cbottom >1:
        cmid = (ctop+cbottom )//2
        if b[i] < c[cmid]:ctop = cmid
        else:cbottom = cmid
    ans += (abottom+1)*(n-ctop)
   
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
readline = sys.stdin.readline

K = int(readline())

inf = 10**9+7
dist = [inf]*(K+1)
dist[K] = 0
Q = deque([K])
used = [False]*(K+1)
while Q:
    vn = Q.pop()
    if used[vn]:
        continue
    used[vn] = True
    vf = (vn*10)%K
    if vn%K and not used[vf]:
        dist[vf] = min(dist[vf], dist[vn])
        Q.append(vf)
    vf = (vn+1)%K
    if not used[(vn+1)%K]:
        dist[vf] = min(dist[vf], 1+dist[vn])
        Q.appendleft(vf)
print(dist[0])

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()
ans=0
for i in range(n):
  x=a[i]
  y=bisect.bisect_right(b,x)
  if y<n:
    z=bisect.bisect_right(c,b[y])
    ans+=n-z
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for i in range(n):
    ans1 = 0
    ans2 = 0
    ok = -1
    ng = n
    for _ in range(100):
        mid = (ok + ng) // 2

        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans1 += max(ok,0) + 1
            break
            
    ok = -1
    ng = n
    for _ in range(100):
        mid = (ok + ng) // 2

        if a[mid] < b[i]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += max(ok,0) + 1
            break
    ans += ans1 * ans2

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)

ans1 = 0
ans2 = 0

for k in range(n):
    if a[k] < b[0]:
        ans1 +=1
    else:
        break

for i in range(n):
    ok = -1
    ng = n
    for j in range(100):
        mid = (ok + ng) // 2

        if b[i] < c[mid]:
            ok = mid
        else:
            ng = mid
        if abs(ng - ok) == 1:
            ans2 += max(ok,0) + 1
            break
print(ans1 * ans2)

Submission status: Wrong Answer

Solution code:
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()
    ans=0
    if a[0]>=b[n-1] or b[0]>=c[n-1]:
        print(0)
        return
    for i in range(n):
        ok=0
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if b[i]>=a[mid]:
                ok=mid
            elif b[i]<a[mid]:
                ng=mid
        nx=ok
        ok=n-1
        ng=-1
        while ok-ng>1:
            mid=(ok+ng)//2
            if b[i]<=c[mid]:
                ok=mid
            elif b[i]>c[mid]:
                ng=mid
        nz=ok
        ans+=(nx+1)*(n-nz)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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()
    ans=0
    if a[0]>=b[n-1] or b[0]>=c[n-1]:
        print(0)
        return
    for i in range(n):
        ok=0
        ng=n
        while ng-ok>1:
            mid=(ok+ng)//2
            if b[i]>a[mid]:
                ok=mid
            elif b[i]<=a[mid]:
                ng=mid
        nx=ok
        ok=n-1
        ng=-1
        while ok-ng>1:
            mid=(ok+ng)//2
            if b[i]<c[mid]:
                ok=mid
            elif b[i]>=c[mid]:
                ng=mid
        nz=ok
        ans+=(nx+1)*(n-nz)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
b_bisect = [bisect.bisect_left(a,one) for one in b]
c_bisect = [bisect.bisect_left(b,one) for one in c]

ans = 0
for one in c_bisect:
    if one == 0:
        continue
    else:
        ans += one * b_bisect[one-1]
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_tmp = [one+0.2 for one in a]
b_tmp = [one+ i/10**6 for i,one in enumerate(b)]
ab = sorted(a_tmp+b_tmp)
ab_len = 2*N
ab_dict = dict()
for one in enumerate(ab):
    ab_dict[one[1]] = one[0]
b_ans = [ab_dict[one] - i for i,one in enumerate(b_tmp)]

b_tmp = [one+0.2 for one in b]
c_tmp = [one+ i/10**6 for i,one in enumerate(c)]
bc = sorted(b_tmp+c_tmp)
bc_len = 2*N
bc_dict = dict()
for one in enumerate(bc):
    bc_dict[one[1]] = one[0]
c_ans = [bc_dict[one] - i for i,one in enumerate(c_tmp)]

ans = 0
for i,one in enumerate(c_ans):
    if one == 0:
        continue
    ans += sum(b_ans[:one])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
#print(A)
#print(B)
#print(C)

BC = {}
i = 0
j = 0
count = 0
while (i < N and j < N):
  if B[i] < C[j]:
    count += 1
    j += 1
  else:
    BC[B[i]] = count
    i += 1
for j in range(i,N):
  BC[B[j]] = count
#print(BC)

BCS = [0 for _ in range(N+1)]
for i in range(N):
  BCS[i+1] = BCS[i] + BC[B[i]]
#print(BCS)
  
ans = 0
i = 0
j = 0
count = 0
while (i < N and j < N):
  #print(i,j,ans)
  if A[i] < B[j]:
    ans += BC[B[j]]
    j += 1
  else:
    ans += BCS[j]
    i += 1
if i < N-1:
  ans += BCS[N] * (N-1-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()))
s = 0

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

ia = 0
ic = -1

for b in B:
  while True:
    if ia == N-1 or A[ia+1]>=b: 
      break
    ia += 1
  while True:
    if ic == N-1 or C[ic+1]>b:
      break
    ic += 1
  s += (ia+1)*(N-ic-1)
    
print(s)

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

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

ia = 0
ic = 0

for b in B:
  while True:
    if ia == N-1 or A[ia+1]>=b: 
      break
    ia += 1
  while True:
    if ic == N-1 or C[ic+1]>b:
      break
    ic += 1
  s += (ia+1)*(N-ic-1)
    
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

Astring = (input())

A = Astring.split()

Bstring = (input())

B = Bstring.split()

Cstring = (input())

C = Cstring.split()

ncomb = 0


for k in range(len(C)):
    for j in range(len(B)):
        if C[k]>B[j]:
            for i in range(len(A)):
                if B[j]>A[i]:
                    ncomb+=1
                    

print(ncomb)

Submission status: Wrong Answer

Solution code:
N = int(input("How many parts does Ringo have for each category? (under 10 000) "))

Astring = (input("Set up the sizes of the top parts A, separated by a space, under 10⁹ : "))

A = Astring.split()

Bstring = (input("Set up the sizes of the middle parts B, separated by a space, under 10⁹ : "))

B = Bstring.split()

Cstring = (input("Set up the sizes of the bottom parts C, separated by a space, under 10⁹ : "))

C = Cstring.split()

ncomb = 0


for k in range(len(C)):
    for j in range(len(B)):
        if C[k]>B[j]:
            for i in range(len(A)):
                if B[j]>A[i]:
                    ncomb+=1
print("Ringo can build ",end="")
print(ncomb,end="")
print(" different altars.")

Submission status: Wrong Answer

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

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

a.sort()
b.sort()
c.sort()

print(a)
print(b)
print(c)

ans = 0
k = 0
for i in a:
    for j in b:
        if j <= i:
            continue
        for k in range(len(c)):
            if j < c[k]:
                ans += (n - k)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
ans = 0
for i in range(a):
    ans += bisect.bisect_left(b, c[i]) * (a - bisect.bisect_right(d, c[i]))

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
A=sorted(set(map(int,input().split())))
B=sorted(set(map(int,input().split())))
C=sorted(set(map(int,input().split())))
s=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    s+=a*c
print(s)

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

answer=0

def search_A(b,T):
    l=len(T)
    if T[0]>b:
        return 0
    elif T[-1]<b:
        return l
    else:
        upper=l-1
        lower=0
        while upper-lower!=1:
            middle = int((upper + lower) / 2)
            if T[middle]>b:
                upper=middle
            else:
                lower=middle
        if T[lower]==b:
            return lower
        else:
            return lower+1


def search_C(b,T):
    l=len(T)
    if T[0]>b:
        return l
    elif T[-1]<b:
        return 0
    else:
        upper=l-1
        lower=0
        while upper-lower!=1:
            middle = int((upper + lower) / 2)
            if T[middle]>b:
                upper=middle
            else:
                lower=middle
        if T[upper]==b:
            return l-upper-1
        else:
            return l-upper


for b in B:
    a=search_A(b,A)
    c=search_C(b,C)
    answer+=a*c

print(answer)

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()]
d = 0
a.sort()
b.sort()
c.sort()

Submission status: Wrong Answer

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