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:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr


    
def main():
    n = int(stdin.readline().rstrip())
    a_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a = sorted(a_kari)
    b_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    b = sorted(b_kari)
    c_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    c = sorted(c_kari)
    board_ab = [0] * n
    board_bc = [0] * n
    ans = 0
    
    for i in range(n):
        ab = bisect.bisect_left(a, b[i])
        bc = n - bisect.bisect_right(c, b[i])
        ans += ab * bc
        print(ab,bc)
    print(ans)
    
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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += round(Ind_A*num_C)
    #print('B[i] =' +str(B[i]),end='')
    #print(' Ind_A =' +str(Ind_A),end='')
    #print(' Ind_C =' +str(Ind_C),end = '')
    #print(' num_C =' +str(num_C),end = '')    
    #print(' 総数 ' + str(Ind_A*num_C))
print(counter)

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()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)

abl=[]
i=0
for j in range(n):
    i=n-1
    while al[i]>=bl[j]:
        print(al[i],bl[j],i,j)
        i-=1
        if i==-1:
            break
    if i==-1:
        abl.append(0)
    else:
        abl.append(i+1)
bcl=[]
j=0
for j in range(n):
    k=0
    while cl[k]<=bl[j]:
        print(bl[j],cl[k],j,k)
        k+=1
        if k==n:
            break
    if k==n:
        bcl.append(0)
    else:
        bcl.append(n-k)
ans=0
for i in range(n):
    ans+=abl[i]*bcl[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()))
al=sorted(a)
bl=sorted(b)
cl=sorted(c)
 
j=0
k=0
ans=0
saved_j=0
saved_k=0
cnt=0
 
for i in range(n):
    j=saved_j
    while al[i]>=bl[j]:
        if j==n-1:
            break
        j+=1
        saved_j=j
    cnt=0
    while (saved_j+cnt)!=n:
        k=saved_k
        while bl[saved_j+cnt]>=cl[k]:
            if k==n-1:
                break
            k+=1
        if cnt==0:
            saved_k=k
        ans+=n-k
        cnt+=1
        k=saved_k
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
 
    B_ = []
    B_accum = []
    ans = 0
 
    for b in B:
        num = binary_search(A, b) + 1
        B_.append((b, num))
 
    tmp_sum = 0
    for b_ in B_:
        tmp_sum += b_[1]
        B_accum.append(tmp_sum)
 
    for c in C:
        b_idx = binary_search_tuple(B_, c)
        if b_idx >= 0:
            ans += B_accum[b_idx]
    print(ans)
 
 
def binary_search(A, x):
    ok = -1
    ng = len(A)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
 
 
def binary_search_tuple(A, x):
    ok = -1
    ng = len(A)
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid][0] <= x:
            ok = mid
        else:
            ng = mid
    return ok
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

j=0
k=0
ans=0
saved_j=0
saved_k=0
cnt=0

for i in range(n):
    print("i",i)
    j=saved_j
    while al[i]>=bl[j]:
        if j==n-1:
            break
        j+=1
        saved_j=j
    cnt=0
    while (saved_j+cnt)!=n:
        k=saved_k
        while bl[saved_j+cnt]>=cl[k]:
            if k==n-1:
                break
            k+=1
        if cnt==0:
            saved_k=k
        ans+=n-k
        cnt+=1
        k=saved_k
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()))

al=a.sort()
bl=b.sort()
cl=c.sort()

j=0
k=0
ans=0
for i in range(n):
    while a[i]>=b[j]:
        if j==n-1:
            break
        j+=1
    while b[j]>=c[k]:
        if k==n-1:
            break
        k+=1
    ans+=(n-j)*(n-k)
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())))

ans = 0
for i in b:
  x = bisect.bisect_right(a,i)
  y = bisect.bisect_left(c, i)
  #print(x, y)
  ans = ans+x*(n-y)

print(ans)

Submission status: Wrong Answer

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

ans = 0
for b in B:
    a_ind = bisect.bisect(A, b)

    if A[a_ind-1] == b:
        a_ind -=1
    c_ind = bisect.bisect(C, b)
    
    ans += a_ind*(n-c_ind)
    
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 b in B:
    a_ind = bisect.bisect(A, b)

    if A[a_ind-1] == b:
        a_ind -=1
    c_ind = bisect.bisect(C, b)
    
    ans += a_ind*(n-c_ind)
    
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 a in A:
    b_ind = bisect.bisect(B, a)
    for b in B[b_ind:]:
        c_ind = bisect.bisect(C, b)
        ans += (n-c_ind)
    
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 b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    print("a:{0},c:{1}".format(a, c))
    ans += a*(len(C)-c)

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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += round(Ind_A*num_C)
    print('B[i] =' +str(B[i]),end='')
    print(' Ind_A =' +str(Ind_A),end='')
    print(' Ind_C =' +str(Ind_C),end = '')
    print(' num_C =' +str(num_C),end = '')    
    print(' 総数 ' + str(Ind_A*num_C))
print(counter)

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())))
counter = 0
for i in range(len(B)):
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += Ind_A*num_C
print(counter)

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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += Ind_A*num_C
    #print('B[i] =' +str(B[i]),end='')
    #print(' Ind_A =' +str(Ind_A),end='')
    #print(' Ind_C =' +str(Ind_C),end = '')
    #print(' num_C =' +str(num_C),end = '')    
    #print(' 総数 ' + str(Ind_A*num_C))
print(counter)

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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += Ind_A*num_C
    #print('Ind_A =' +str(Ind_A),end='')
    #print(' Ind_C =' +str(Ind_C),end = '')
    #print(' 総数 ' + str(Ind_A*num_C))
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()

ans = 0
C = len(c)

# Bを中心に考える
for i in b:
    ans += (bisect.bisect(a,i-1))*(C-bisect.bisect(c,i+1))

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()))
print(sum(bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)) for b in B))

Submission status: Wrong Answer

Solution code:
# 20
# ABC077 C Snuke Festival

import bisect
import itertools

n = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]

a_list.sort()
b_list.sort()
c_list.sort()

bc_list = []
for i in range(n):
    _b = b_list[i]
    _idx = bisect.bisect_right(c_list, _b)
    bc_list.append(n-_idx)

ab_list = []
for i in range(n):
    _a = a_list[i]
    _idx = bisect.bisect_right(b_list, _a)
    ab_list.append(n-_idx)

bc_list.sort(reverse=True)
cumsum = list(itertools.accumulate(bc_list))

ans = 0
for i in range(n):
    if ab_list[i] == 0:
        continue
    ans += cumsum[ab_list[i]-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.sort()
b.sort()
c.sort()

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] > b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    if a[a_mid] == b[j]:
        i.append(a_mid)
    else:
        i.append(a_mid + 1)

for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
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
dict_a = dict()
dict_b = dict()
for i in range(n):
    if a[i] in dict_a.keys():
        b_mid = dict_a[a[i]]
    else:
        left = n - 1
        right = 0
        b_mid = n // 2
        while left >= right:
            if b[b_mid] > a[i]:
                left = b_mid - 1
            else:
                right = b_mid + 1
            b_mid = (left + right) // 2
        b_mid += 1
        dict_a[a[i]] = b_mid

    for j in range(b_mid, n):
        if b[j] in dict_b.keys():
            c_mid = dict_b[b[j]]
        else:
            left = n - 1
            right = 0
            c_mid = n // 2
            while left >= right:
                if c[c_mid] > b[j]:
                    left = c_mid - 1
                else:
                    right = c_mid + 1
                c_mid = (left + right) // 2
            ans += n - c_mid - 1
            dict_b[b[j]] = c_mid
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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()]
sorted(a)
sorted(b)
sorted(c)

total = 0
for i in b:
    a_number = bisect.bisect_left(a, i)
    c_number = n - bisect.bisect_right(c, i)
    total = total +  a_number * c_number
print(total)

Submission status: Wrong Answer

Solution code:
import bisect

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()]
sorted(a)
sorted(b)
sorted(c)

total = 0
for i in b:
    a_number = bisect.bisect_left(a, i)
    c_number = len(c) - bisect.bisect_right(c, i)
    total += a_number * c_number
print(total)

Submission status: Wrong Answer

Solution code:
import bisect
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()]
total = 0
for i in b:
    a_number = bisect.bisect_left(a, i)
    c_number = len(c) - bisect.bisect_right(c, i)
    total += a_number * c_number
print(total)   
    
    
a_number = bisect.bisect_left(a,2)
c_number = len(c) - bisect.bisect_right(c,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.sort()
B.sort()
C.sort()

def getPoint(X, size):
  l = 0
  r = len(X)-1
  while 0 < r-l:
    center = (l+r)//2
#    print(l, r, center, size)
    if size < X[center]:
      r = center
    else:
      l = center
    if r-l == 1 and X[l] <= size and size < X[r]:
      return r
    if r-l == 1 and X[r] <= size:
      return r+1
  return r

count = 0
for a in A:
  for i in range(getPoint(B, a), len(B)):
#    print(getPoint(C, B[i]))
    count += len(C) - getPoint(C, B[i])
print(count)

Submission status: Wrong Answer

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

def getPoint(X, size):
  l = 0
  r = len(X)-1
  while 1 < r-l:
    center = (l+r)//2
    if size < X[center]:
      r = center
    else:
      l = center
  return r-1

count = 0
for a in A:
  for i in range(getPoint(B, a), len(B)):
    if a < B[i]:
      for j in range(getPoint(C, B[i]), len(C)):
        if B[i] < C[j]:
          count += 1
print(count)

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=0
for i in b:
    he=0
    ta=n
    while ta-he>1:
        mid=(he+ta)//2
        if i>a[mid]:
            he=mid
        else:
            ta=mid
    x=he+1

    he_=-1
    ta_=n
    while ta_-he_>1:
        mid_=(he_+ta_)//2
        if i>=c[mid_]:
            he_=mid_
        else:
            ta_=mid_
    y=n-ta_
    ans+=x*y
    print(i,x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
print("a")

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
temp=n
for i in range(n):
  j=0
  k=0
  while j<n:
    if a[i]<=b[j]:
      while k<n:
        if b[j]<=c[k]:
          ans=ans+n-k
          j=j+1
          break
        else:
          k=k+1
    else:
      j=j+1
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())))

# bC=[0 for i in range(N)]
# for i in range(N):
#     bC[i]=N-bisect.bisect(C,B[i])
    
# bCS=[0]*(N+1)
# for i in range(N):
#     bCS[i+1] = bCS[i]+bC[i]
    
# ans=0
# for i in range(N):
#     x=bisect.bisect(B,A[i])
#     ans+=bCS[N]-bCS[x]
        
# print(ans)

# 以下賢い

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):
    ans+=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))

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

# bC=[0 for i in range(N)]
# for i in range(N):
#     bC[i]=N-bisect.bisect(C,B[i])
    
# bCS=[0]*(N+1)
# for i in range(N):
#     bCS[i+1] = bCS[i]+bC[i]
    
# ans=0
# for i in range(N):
#     x=bisect.bisect(B,A[i])
#     ans+=bCS[N]-bCS[x]
        
# print(ans)

#以下賢い

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):
    ans+=bisect.bisect_left(A,B[i])+N-bisect.bisect_right(C,B[i])

Submission status: Wrong Answer

Solution code:
import bisect
import itertools

N = int(input())
up = sorted(list(map(int, input().split())))
middle = sorted(list(map(int, input().split())))
bottom = sorted(list(map(int, input().split())))
up_arr = []
middle_arr =[]

for list in middle:
    middle_arr.append(N-bisect.bisect_right(bottom,list))

for list in up:
    up_arr.append(N-bisect.bisect_right(middle,list))

rui_middle = []
count = 0
for i in middle_arr[::-1]:
    count += i
    rui_middle.append(count)

ans =0
for i in up_arr:
    ans += rui_middle[i-1]

print(ans)

Submission status: Wrong Answer

Solution code:

n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al,reverse = True)
lbl = sorted(bl,reverse = True)
lcl = sorted(cl,reverse = True)

res =0
for i in range(n):
    x = lcl[i]
    for j in range(n):
        y = lbl[j]
        if x >y:
            for k in range(n):
                z = lal[k]
                if y > z:
                    res += (n-k)
                    print(res,x,y,z)
                    break
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
# print(al)
bl.sort()
# print(bl)
cl.sort()
# print(cl)

cnt = 0
for b in range(N):
    idx = bisect.bisect_left(al, bl[b])  # bl[b] = 6 idx= 3
    cnt_ab = idx - 1


    idx2 = bisect.bisect(cl, bl[b])  # bl[b] = 6 idx2= 1
    cnt_bc = len(cl) - idx2

    # print(cnt_ab,cnt_bc)

    cnt += cnt_ab * cnt_bc

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
# print(al)
bl.sort()
# print(bl)
cl.sort()
# print(cl)

cnt = 0
for b in range(N):
    idx = bisect.bisect(al, bl[b])  # bl[b] = 6 idx= 3
    if al[idx - 1] == bl[b]:
        cnt_ab = idx - 1
    else:
        cnt_ab = idx

    idx2 = bisect.bisect(cl, bl[b])  # bl[b] = 6 idx2= 1
    cnt_bc = len(cl) - idx2

    # print(cnt_ab,cnt_bc)

    cnt += cnt_ab * cnt_bc

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

cnt = 0
for b in range(N):
    al_idx = bisect.bisect(al,bl[b])
    cnt_ab = al_idx

    cl_idx = bisect.bisect(cl,bl[b])
    cnt_bc = len(cl) - cl_idx

    cnt += cnt_ab*cnt_bc
    
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from collections import defaultdict

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0
pre_b = -1

dict_C = defaultdict(int)


for b in B:
    if b == pre_b:
        res += num_a * num_c
        continue
    num_a = bisect_left(A, b) # a < b となるAの要素数
    pre_num_c = bisect_left(C, b)
    num_c = N - pre_num_c # c > b となるAの要素数
    if pre_num_c != N and C[pre_num_c] == b:
        num_c -= N - bisect_left(C, b+1)
    res += num_a * num_c
    pre_b = b
print(res)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
num_a = 0
num_c = 0
res = 0

for b in B:
    num_a = bisect_left(A, b) # a < b となるAの要素数
    num_c = N - bisect_left(C, b) # c > b となるAの要素数
    if num_a != N and A[num_a] == b:
        num_a -= 1
    if num_c != N and A[num_c] == b:
        num_a -= 1
    res += num_a * num_c
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] + sorted([int(i) for i in input().split()]) + [10**9+1]
B = sorted([int(i) for i in input().split()])
C = [10**9+1] + sorted([int(i) for i in input().split()], reverse=True) + [0]

def A_count(n, ls):
    left = 0
    right = N + 1

    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] == n: return mid - 1

        if n < ls[mid]: right = mid
        if n > ls[mid]: left = mid

    return left

def C_count(n, ls):
    left = 0
    right = N + 1

    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] == n: return mid - 1

        if n > ls[mid]: right = mid
        if n < ls[mid]: left = mid

    return left

ans = 0
for i in range(N):
    n = B[i]
    ans += A_count(n, A) * C_count(n, C)

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(len(b)):
#     al = 0
#     ar = n-1
#     while True:
#         if a[-1] < b[i]:
#             an = n
#             break
#         am = (al+ar)//2
#         if a[am] < b[i]:
#             al = am
#         else:
#             ar = am
#         an = al + 1
#         if al+1 == ar:
#             break
#     cl = 0
#     cr = n-1
#     while True:
#         if c[0] > b[i]:
#             cn = n
#             break
#         cm = (cl+cr)//2
#         if c[cm] <= b[i]:
#             cl = cm
#         else:
#             cr = cm
#         cn = n - cr
#         if cl+1 == cr:
#             break
#     ans += an*cn
# 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(len(b)):
    al = 0
    ar = n-1
    while True:
        if a[-1] < b[i]:
            an = n
            break
        am = (al+ar)//2
        if a[am] < b[i]:
            al = am
        else:
            ar = am
        an = al + 1
        if al+1 == ar:
            break
    cl = 0
    cr = n-1
    while True:
        if c[0] > b[i]:
            cn = n
            break
        cm = (cl+cr)//2
        if c[cm] <= b[i]:
            cl = cm
        else:
            cr = cm
        cn = n - cr
        if cl+1 == cr:
            break
    ans += an*cn
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()))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
import sys
from bisect import bisect_left, bisect_right


def S(): return sys.stdin.readline().rstrip()


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()
B = LI()
C = LI()
A.sort()
B.sort()
C.sort()
ans = 0
for i in A:
    b_left = bisect_left(B, i)

    for q in range(b_left, len(B)):
        c_left = bisect_left(C, B[q])

        ans += len(C) - c_left

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a
import sys
from bisect import bisect_left, bisect_right


def S(): return sys.stdin.readline().rstrip()


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()
B = LI()
C = LI()
A.sort()
B.sort()
C.sort()
ans = 0
for i in A:
    b_left = bisect_left(B, i)
    print(b_left, 'b_left')
    for q in range(b_left, len(B)):
        c_left = bisect_left(C, B[q])
        print(c_left, 'c_left')
        ans += len(C) - c_left

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(lambda x:int(x) * -1, input().split())))

count = 0
for b in B:
    # Aの候補
    la = -1
    ra = n
    while (ra - la) > 1:
        mid = (la+ra)//2
        if A[mid] > b:
            ra = mid
        else:
            la = mid

    # Cの候補
    lc = -1
    rc = n
    while (rc - lc) > 1:
        mid = (lc+rc)//2
        if C[mid] > -b:
            rc = mid
        else:
            lc = mid
    count += (la+1)*(lc+1)

print(count)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline

def binary_search(xs,target,direc=False):
    low = 0
    high = len(xs)-1
    middle = 0
    #print(xs)
    while(low <= high):
        middle = (low + high) // 2
        can = xs[middle]
        if direc == True:
            if can == target:
                return middle+1
        else:
            pass

        if can >= target:
            high = middle - 1
        elif can < target:
            low = middle + 1

    middle = (low + high)//2
    return middle+1
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)
    mid_a = 0
    mid_c = 0

    for target in b_sorted:
        mid_a = binary_search(a_sorted,target,False)
        mid_c = binary_search(c_sorted,target,True)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Submission status: Wrong Answer

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

def binary_search(xs,target,maxlen,low,high,reverse=True):
    middle = 0
    while(low <= high):
        middle = (low + high) // 2
        can = xs[middle]
        if can == target:
            if reverse == False:
                return middle
            else:
                return middle + 1
        if can > target:
            high = middle - 1
        elif can < target:
            low = middle + 1

    middle = (low + high) // 2 +1
    return middle

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)
    high = maxlen - 1
    low = 0
    mid_a = low
    mid_b = high

    for target in b_sorted:
        mid_a = binary_search(a_sorted,target,maxlen,low,high,False)
        mid_b = binary_search(c_sorted,target,maxlen,low,high,True)
        count += mid_a * (maxlen - mid_b)
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))