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: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
al = sorted(set(int(i) for i in input().split()))
bl = sorted(set(int(i) for i in input().split()))
cl = sorted(set(int(i) for i in input().split()))
ans = 0

def search(ar, key, flag):
    left = -1
    right = len(ar)
    center = (left + right) // 2
    
    while right - left > 1:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif ar[center] < key:
            left = center
            center = (left + right) // 2
        else:
            right = center
            center = (left + right) // 2
    
    if flag == 0:
        return right
    elif flag == 1:
        return len(ar) - right
        

for i in range(n):
    mid = bl[i]
    top_num = search(al, mid, 0)
    bottom_num = search(cl, mid, 1)
    ans += top_num * bottom_num
    
print(ans)

Submission status: Runtime Error

Solution code:
import bisect
point=0
N=int(input())
A=list(map(int,input().split())).sort()
B=list(map(int,input().split())).sort()
C=list(map(int,input().split())).sort()
for i in range(N):
  m=bisect.bisect_left(A,B[i])
  n=bisect.bisect_left(C,B[i])
  point+=m*n
print(point)

Submission status: Runtime Error

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()
kinds=0
j1=0 #Bのインデックス
while B[j1]<A[0]:
  j1+=1
k1=0
while C[k1]<B[j1]:
  k1+=1
for i in range(N):
  for j in range(j1,N):
    if A[i]<B[j]:
      while k1<N and B[j]>C[k1]:
        k1+=1
      kinds+=(N-k1)
      k1=k1-1
print(kinds)

Submission status: Runtime Error

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()
kinds=0
j1=0 #Bのインデックス
while B[j1]<A[0]:
  j1+=1
k1=0
while C[k1]<B[j1]:
  k1+=1
for i in range(N):
  for j in range(j1,N):
    if A[i]<B[j]:
      while k1<N and B[j]>C[k1]:
        k1+=1
      kinds+=(N-k1)
      k1=k1-1

Submission status: Runtime Error

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()
kinds=0
j1=0 #Bのインデックス
while B[j1]<A[0]:
  j1+=1
k1=0
while C[k1]<B[j1]:
  k1+=1
for i in range(N):
  for j in range(j1,N):
    if A[i]<B[j]:
      for k in range(k1,N):
        if B[j]<C[k]:
          kinds+=1
print(kinds)

Submission status: Runtime Error

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()
kinds=0
j1=0 #Bのインデックス
while B[j]<A[0]:
  j1+=1
k1=0
while C[k]<B[j]:
  k1+=1
for i in range(N):
  for j in range(j1,N):
    if A[i]<B[j]:
      for k in range(k1,N):
        if B[j]<C[k]:
          kinds+=1
print(kinds)

Submission status: Runtime Error

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()
kinds=0
j1=0 #Bのインデックス
while B[j]<A[0]:
  j+=1
k1=0
while C[k]<B[j]:
  k+=1
for i in range(N):
  for j in range(j1,N):
    if A[i]<B[j]:
      for k in range(k1,N):
        if B[j]<C[k]:
          kinds+=1
print(kinds)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
sum = 0
for i in range(0,N):
  a = A[i]
  for j in range(1,N):
    b = B[j]
    c_min = b-a+1
    c_max = a+b-1
    l = bisect.bisect_left(C,c_min,lo = j+1)
    if l! = N:
      r = bisect.bisect_right(C,c_max,lo = j+1)
      if r:
        r = r-1
        if r >= l:
          sum += r-l+1
print(sum)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

bc = []
idx = 0
for i in range(n):
    while True:
        if b[i] >= c[-1]:
            break
        elif c[idx] <= b[i]:
            idx += 1
        else:
            bc.append(n-idx)
            break

bc2 = bc[::-1]
ab2 = []
absum = 0
for i in range(n):
    absum += bc2[i]
    ab2.append(absum)
ab = ab2[::-1]

res = 0
idx = 0
for i in range(n):
    while True:
        if a[i] >= b[-1]:
            break
        elif b[idx] <= a[i]:
            idx += 1
        else:
            res += ab[idx]
            break
print(res)

Submission status: Runtime Error

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())))
ans=0
for i in range(N):
  val=B[i]
  mid_a=A[N//2-1]
  mid_c=C[N//2-1]
  if mid_a<val:
    count1=0
    for i in range(N//2,N):
      if A[i]<val:
        count1+=1
      else:
        break
    val1=N//2+count1
  else:
    count2=0
    for i in range(N//2):
      if A[i]<val:
        count2+=1
      else:
        break
    val1=count2
  if mid_c>val:
    count3=0
    for i in range(N//2):
      if C[i]<val:
        count3+=1
      else:
        break
    val2=N-count3
  else:
    for i in range(N//2,N):
      if C[i]>val:
        val2=N-i
        break
      else:
        if i==N:
          val2=0
        else:
          pass
  ans+=val1*val2
print(ans)

Submission status: Runtime Error

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

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = sorted(list(map(int, input().split())))
    c = list(map(int, input().split()))

    sum_c = [0] * (max(max(c), b[-1]) + 2)
    for i in range(N):
        sum_c[c[i]] += 1
    
    for i in range(len(sum_c)-2, -1, -1):
        sum_c[i] += sum_c[i+1]
    
    count = [0] * N
    for i in range(N):
        count[i] = sum_c[b[i]+1]
    for i in range(N-2, -1, -1):
        count[i] += count[i+1]
    # print(count)
    ans = 0
    for i in range(N):
        a_ = a[i]
        b_i = bisect.bisect_left(b, a_+1)
        if b_i < N:
            # print("{}より大きくて最小のbは{}でcount[{}] := {}".format(a_, b[b_i], b_i, count[b_i]))
            ans += count[b_i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#3_1_1
import bisect
n = int(input())
a = list(map(int,input().split))
b = list(map(int,input().split))
c = list(map(int,input().split))

a.sort()
c.sort()
ans = 0
for i in range(n):
    ue = bisect.bisect_left(a,b[i])
    sita = bisect.bisect_right(c,b[i])
    ans += ue * sita
print(ans)

Submission status: Runtime Error

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

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

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

q=[0]*n
b=0

for k in range(n):
    b+=n-bisect.bisect_right(a[2],a[1][-k-1])
    q[-k-1]=b

ans=0
max1=max(a[1])

for l in a[0]:
    if l<=max1:
        ans+=q[bisect.bisect_right(a[1],l)]
print(ans)

Submission status: Runtime Error

Solution code:

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

A.sort()
C.sort()

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

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

total = 0
for b in B:
    a_ub, a_lb = bin_search_r(A, b)
    c_ub, c_lb = bin_search_l(C, b)
    total += a_ub * (N - c_ub)

print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(sorted(map(int, input().split())))
B = list(sorted(map(int, input().split()))
C = list(sorted(map(int, input().split())))
 
import bisect
upper_condition = [bisect.bisect_left(A, b) for b in B]
lower_condition = [N - bisect.bisect_right(C, b) for b in B]
 
print(sum(map(lambda x: x[0]*x[1], zip(upper_condition, lower_condition))))

Submission status: Runtime Error

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

import bisect
upper_condtion = [bisect.bisect_left(A, b) for b in B]
lower_condition = [N - bisect.bisect_right(C, b) for b in B]

print(sum(map(lambda x: x[0]*x[1], zip(upper_condition, lower_condition))))

Submission status: Runtime Error

Solution code:
N = int(input())
A = np.array(list(sorted(map(int, input().split()))), dtype=int)
B = np.array(list(sorted(map(int, input().split()))), dtype = int)
C = np.array(list(sorted(map(int, input().split()))), dtype = int)
 
upper_condition = np.array([1 + np.max(np.where(A < b)[0]) for b in B])
lower_condition = np.array([N - np.min(np.where(C > b)[0]) for b in B])
 
print(np.sum(upper_condition*lower_condition))

Submission status: Runtime Error

Solution code:
def lower_elements(A, b):
    lower_bound = -1
    upper_bound = len(A)
    while upper_bound - lower_bound > 1:  # ア
        middle = (lower_bound + upper_bound) // 2
        if A[middle] < b:  # イ
            lower_bound = middle
        else:
            upper_bound = middle
    return lower_bound + 1  # ウ upper_boundでも可


def upper_elements(C, b):
    lower_bound = -1
    upper_bound = len(C)
    while upper_bound - lower_bound > 1:  # ア
        middle = (lower_bound + upper_bound) // 2
        if C[middle] <= b:
            lower_bound = middle
        else:
            upper_bound = middle
    return len(C) - upper_bound


def answer(N: int, A: list, B: list, C: list):
    assert N == len(A) == len(B) == len(C)
    A.sort()
    B.sort()
    C.sort()
    count = 0
    for b in B:
        count += lower_elements(A, b) * upper_elements(C, b)
    return count


def snuke_festival():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    print(str(answer(N, A, B, C)) + '¥n')


if __name__ == '__main__':

Submission status: Runtime Error

Solution code:
def lower_elements(A, b):
    lower_bound = -1
    upper_bound = len(A)
    while upper_bound - lower_bound > 1:  # ア
        middle = (lower_bound + upper_bound) // 2
        if A[middle] < b:  # イ
            lower_bound = middle
        else:
            upper_bound = middle
    return lower_bound + 1  # ウ upper_boundでも可


def upper_elements(C, b):
    lower_bound = -1
    upper_bound = len(C)
    while upper_bound - lower_bound > 1:  # ア
        middle = (lower_bound + upper_bound) // 2
        if C[middle] <= b:
            lower_bound = middle
        else:
            upper_bound = middle
    return len(C) - upper_bound


def answer(N, A, B, C):
    assert N == len(A) == len(B) == len(C)
    A.sort()
    B.sort()
    C.sort()
    count = 0
    for b in B:
        count += lower_elements(A, b) * upper_elements(C, b)
    return count


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


if __name__ == '__main__':
  sunuke_festiival()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    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()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i-1]]

    print(ans)

Submission status: Runtime Error

Solution code:
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    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()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i]]

    print(ans)

Submission status: Runtime Error

Solution code:
from bisect import *
n = int(input())
abc = [sorted(list(map(int, input().split()))) for i in range(3)]
print(sum([bisect.bisect_left(abc[0], b)*(n-bisect.bisect_right(abc[2], b)) for b in abc[1]]))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

a = np.array(list(map(int,input().split())),dtype=np.int32)
b = np.array(list(map(int,input().split())),dtype=np.int32)
c = np.array(list(map(int,input().split())),dtype=np.int32)

a = a-b.reshape(len(b),1)
a = np.where(a<0,1,0)
a = np.sum(a,axis=1)

b = b-c.reshape(len(c),1)
b = np.where(b<0)[1]

print(np.sum(a[b]))

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np
n = int(input())
abc = [sorted(list(map(int, input().split()))) for i in range(3)]

unko = np.zeros(n)
for c in abc[2]:
  unko[:bisect.bisect_left(abc[1], c)] += 1
s = 0

print()
for i in range(len(abc[1])):
  s += bisect.bisect_left(abc[0], abc[1][i])*unko[i]
  
print(int(s))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

a = a-b.reshape(len(b),1)
a = np.where(a<0,1,0)
a = np.sum(a,axis=1)

b = b-c.reshape(len(c),1)
b = np.where(b<0)

print(np.sum(a[b[1]]))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

a = a-b.reshape(len(b),-1)
a = np.where(a<0,1,0)
a = np.sum(a,axis=1)

b = b-c.reshape(len(c),-1)
b = np.where(b<0)

print(np.sum(a[b[1]]))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

a = a-b.reshape(b.shape[0],-1)
a = np.where(a<0,1,0)
a = np.sum(a,axis=1)

b = b-c.reshape(c.shape[0],-1)
b = np.where(b<0)

print(np.sum(a[b[1]]))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

n = int(input())

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

a = a-b.reshape(b.shape[0],-1)
a = np.where(a<0,1,0)
a = np.sum(a,axis=1)

b = b-c.reshape(c.shape[0],-1)
b = np.where(b<0)

print(np.sum(a[b[1]]))

#print(np.where(a>b))

Submission status: Runtime Error

Solution code:
# それぞれソート済みとして, 整数でAi<BjかつBj<Ckとなるjを求める(にぶたん)

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


def lower_bound(arr, target):
    # targetを超える最小の値のインデックス
    if target > arr[-1]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] > target:
            right = mid
        else:
            left = mid + 1
    return right


def upper_bound(arr, target):
    # target以上の最小の値のインデックス
    if target < arr[0]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] >= target:
            right = mid
        else:
            left = mid + 1
    return right


count = 0

for b in B:
    ai = upper_bound(A, b)
    ci = N - lower_bound(C, b)
    if ai is not None and ci is not None:
        count += ai * ci

print(count)

Submission status: Runtime Error

Solution code:
import bisect

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*bisect.bisect_right(C,b

print(ans)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
ai = 0
ci = 0
for bi in b:
    while ai < N and a[ai] < bi:
        ai += 1
    while ci >= 0 and c[ci] <= bi:
        ci += 1
    ans += ai * (N -ci)
print(ans)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
for bi in b:
    ai = 0
    ci = 0
    while ai < N and a[ai] < bi:
        ai += 1
    while ci >= 0 and c[ci] <= bi:
        ci += 1
    ans += ai * (N -ci)
print(ans)

Submission status: Runtime Error

Solution code:

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    blist = list(map(int, input().split()))
    clist = list(map(int, input().split()))

    return n, alist, blist, clist


def submit():
    n, alist, blist, clist = read_input()

    alist.sort(reverse=True)
    blist.sort(reverse=True)
    clist.sort(reverse=True)

    b_a_n = [0] * n
    i = j = 0

    while j < n:
        while i < n and alist[i] >= blist[j]:
            i += 1
        b_a_n[j] = n - i
        j += 1

    b_a_sum = b_a_n.copy()
    for i in range(2, n + 1):
        b_a_sum[n - i] = b_a_sum[n - i + 1] + b_a_n[n - i]

    count = 0
    i = j = 0
    while i < n:
        while blist[j] >= clist[i]:
            j += 1
            if j == n:
                print(count)
                return
        count += b_a_sum[j]
        i += 1

    print(count)



if __name__ == '__main__':
    submit()

Submission status: Runtime Error

Solution code:
import bisect
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()
cnt = 0
for j in B:
    a_index = bisect.bisect_left(A, j)
    c_index = bisect.bisect_right(C, j)
    cnt += len(A[:a_index])*len(C[c_index:])
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,a,b=int(input()),[sorted(list(map(int,input().split())))for i in range(3)],[[],[]]
x=0
for i in range(n):
  while a[2][i]>a[1][x]:
    b[1].append(n-i)
    x+=1
    if x==n:break
  if x==n:break
for i in range(1,n):b[1][n-i-1]+=b[1][n-i]
x=0
for i in range(n):
  while a[1][i]>a[0][x]:
    b[0].append(b[1][i])
    x+=1
    if x==n:break
  if x==n:break
print(sum(b[0]))

Submission status: Runtime Error

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

for j in b:
   x=bisect.bisect_left(a,j)
   y=bisect.bisect_right(c,j)
   ans+=x*(N-l)
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(list(set(a)))
b=list(map(int,input().split()))
b.sort(list(set(b)))
c=list(map(int,input().split()))
c.sort(list(set(c)))
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(list(set(a)))
b=list(map(int,input().split()))
b.sort(list(set(b)))
c=list(map(int,input().split()))
c.sort(list(set(c)))
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=binary_search1(b[i],c)*binary_search2(b[i],a)
print(ans)

Submission status: Runtime Error

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()
count = 0
for c_ in c:
    b_ = b[:bisect.bisect_right(b, c_-1)]
    for b_1 in b_:
        a_num = bisect.bisect_right(a, b_1-1)
        count += a_num
print(count)

Submission status: Runtime Error

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):
    r1 = bisect.bisect_right(B,A[i])
    for j in range(r1,N):
        r2 = bisect.bisect_right(C,B[j])
        ans += N - r2
print(ans)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a

import itertools
import collections
import bisect

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

    ans = 0

    for b in B:
        i = bisect.bisect_left(A, b)
        j = bisect.bisect_right(C, b)

        ans += i * (N - j)

    print(ans)


if __name__ == '__main__':
    main()
# https://atcoder.jp/contests/abc077/tasks/arc084_a

import itertools
import collections
import bisect

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

    ans = 0

    for b in B:
        i = bisect.bisect_left(A, b)
        j = bisect.bisect_right(C, b)

        ans += i * (N - j)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

b_ind=0
c_ind=0
b_res=[0 for i in range(n)]
while b_ind<n:
    while b[b_ind] >= c[c_ind]:
        c_ind+=1
        if c_ind ==n:
            break
    b_res[b_ind]=c_ind
    b_ind+=1

b_res_sum=[0 for i in range(n)]
count=0
for i in range(n-1,-1,-1):
    count+= n - b_res[i]
    b_res_sum[i]=count

a_ind=0
b_ind=0
a_res=[0 for i in range(n)]
while a_ind<n:
    while a[a_ind] >= b[b_ind]:
        b_ind+=1
        if b_ind==n:
            break
    a_res[a_ind]=b_ind
    a_ind+=1

count=0
for i in a_res:
    if i<n:
        count+=b_res_sum[i]
print(count)

Submission status: Runtime Error

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

ans = 0
for i in range(n):
    in_in = bisect.bisect_left(b,a[i])
    if a[i] == b[in_in]:
        in_in += 1
    for k in range(in_in,n):
        insert_index = bisect.bisect_left(c,b[k])
        if b[k] == c[insert_index]:
            insert_index += 1
        ans += n-insert_index


print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    aParts = getIntList()
    bParts = getIntList()
    cParts = getIntList()
    aParts.sort()
    bParts.sort()
    cParts .sort()
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    combAB = zeros(N)  # Aのi番めのパーツが組み合わせられる数
    combBC = zeros(N)
    j = 0
    for i in range(N):
        while j < N and bParts[j] <= aParts[i]:
            j += 1
            #d.dmp((i,j),'in while')
        combAB[i] = N-j
        #d.dmp((i,j),'in for')
    d.dmp((combAB), 'combAB')
    j = 0
    for i in range(N):
        while j < N and cParts[j] <= bParts[i]:
            j += 1
        combBC[i] = N-j
    d.dmp((combBC), 'combBC')
    sm = zeros(N)
    sm[-1] = combBC[-1]
    for i in range(1, N):
        sm[-1-i] = combBC[-1-i]+sm[-i]
    d.dmp((sm), 'sm')
    count = 0
    for i in range(N):
#        count += sum(combBC[N-combAB[i]:])
        count += sm[N-combAB[i]]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)