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: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
counter = 0
for itemA in A:
  for itemB in B:
    for itemC in C:
      if itemA < itemB < itemC:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

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()
count = 0
for i in A:
    for j in B:
        if j > i:
            for K in C:
                if K > j:
                    count += 1 
        else:
            pass

print(count)

Submission status: Time Limit Exceeded

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())))
count = 0
# ソートして
for c in C:
  under_c = bisect.bisect_left(B, c)
  for b in B[:under_c]:
    under_b = bisect.bisect_left(A, b)
    count += under_b
print(count)

Submission status: Time Limit Exceeded

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())))
#print(a)
#print(b)
#print(c)
c_count=[]#cから行けるところの回数
b_count=[]#bから行けるところの回数

j=0
count=0
for i in range(n):#cから行けるところの回数
    for j in range(count,n):
        if b[j]<c[i]:
            count+=1
        else:
            break
    c_count.append(count)

count=0

for i in range(n):#bから行けるところの回数
    for j in range(count,n):
        if a[j]<b[i]:
            count+=1
        else:
            break
    b_count.append(count)

ans=0

for i in range(n):
    ans+=sum(b_count[0:c_count[i]])

print(ans)

#print(b_count)
#print(c_count)

Submission status: Time Limit Exceeded

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())))
#print(a)
#print(b)
#print(c)
c_count=[]#cから行けるところの回数
b_count=[]#bから行けるところの回数

j=0
count=0
for i in range(n):#cから行けるところの回数
    for j in range(count,n):
        if b[j]<c[i]:
            count+=1
    c_count.append(count)

count=0

for i in range(n):#bから行けるところの回数
    for j in range(count,n):
        if a[j]<b[i]:
            count+=1
    b_count.append(count)

ans=0

for i in range(n):
    ans+=sum(b_count[0:c_count[i]])

print(ans)

#print(b_count)
#print(c_count)

Submission status: Time Limit Exceeded

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 b_search_l(B,key):
    #key < B[s]を満たす最小のs
    if key < B[0]:
        return 0
    elif key >= B[N-1]:
        return N-1
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] <= key and key < B[mid+1]:
                return mid+1
            elif B[mid] > key:
                right = mid
            else:
                left = mid

def b_search_r(B,key):
    #key > B[t]を満たす最大のt
    if B[0] >= key:
        return 0
    elif B[N-1] < key:
        return N-1
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] < key and key <= B[mid+1]:
                return mid
            elif B[mid] >= key:
                right = mid
            else:
                left = mid

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] +1 < C[j]:
            ans += (b_search_r(B,C[j]) - b_search_l(B,A[i])+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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

cnt = [0] * N
for i in range(N):
    cnt[i] = N - bisect_right(C, B[i])
    
res = 0
for i in range(N):
    idx = bisect_right(B, A[i])
    if idx < N:
        res += sum(cnt[idx:])
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from bisect import bisect_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()

    result = 0
    for c in C:
        index_c_b = bisect_left(B, c)
        for b in B[:index_c_b]:
            result += bisect_left(A, b)

    print(result)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def isok(na , index , key):
    if na[index] >= key:
        return True
    else:
        return False
    
def bs(nar,key):
    left = -1
    right = len(nar)
    
    while (right - left) > 1:
        mid = left + (right - left) // 2
        
        if isok(nar , mid , key):
            right = mid
        else:
            left = mid
            
    return right

ans = 0
for i in a:
    q = bs(b,i+1)
    d = b[q:]
    
    for j in d:
        r = bs(c,j+1)
        f = c[r:]
        ans += len(f)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]



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

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


for i in range(N):
  temp = bisect.bisect_left(B, A[i]+1)
  for j in range(temp, N):
    ans += (N-bisect.bisect_left(C, B[j]+1))


print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bs(l, n):
    left = 0
    right = len(l) - 1
    a = -1
    while True:
        if right < left:
            break

        m = (left + right) // 2
        if l[m] == n:
            return len(l) - m - 1
        if l[m] < n:
            left = m + 1
        else:
            a = len(l) - m
            right = m - 1

    return max(a, 0)


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

ab = []
for ai in a:
    ab.append(bs(b, ai))
bc = []
for bi in b:
    bc.append(bs(c, bi))
print(sum(bci for abi in ab for bci in bc[-abi:] if abi))

Submission status: Time Limit Exceeded

Solution code:
def bs(l, n):
    left = 0
    right = len(l) - 1
    a = -1
    while True:
        if right < left:
            break

        m = (left + right) // 2
        if l[m] == n:
            return len(l) - m - 1
        if l[m] < n:
            left = m + 1
        else:
            a = len(l) - m
            right = m - 1

    return max(a, 0)


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

summ = 0
for ai in a:
    bm = bs(b, ai)
    if bm == 0:
        continue
    for bj in b[-bm:]:
        summ += bs(c, bj)

print(summ)

Submission status: Time Limit Exceeded

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
i=0
while i<N:
    j = 0
    while j<N:
        if A[i] < B[j]:
            k = 0
            while k<N:
                if B[j] < C[k]:
                    ans = ans+(N-k)
                    break
                else:
                    k=k+1
            j = j+1
        else:
            j = j+1
    i = i+1

print(ans)

Submission status: Time Limit Exceeded

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
i=0
while i<N:
    j = 0
    while j<N:
        if A[i] < B[j]:
            k = 0
            while k<N:
                if B[j] < C[k]:
                    ans = ans+1
                    k=k+1
                else:
                    k=k+1
            j = j+1
        else:
            j = j+1
    i = i+1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(3)]

sorted_l = [sorted(l[0]),sorted(l[1])]

from bisect import bisect_left

ans=0
for i in range(n):
    for j in range(n):
        if sorted_l[1][j]<l[2][i]:
            if sorted_l[1][j]<sorted_l[0][0]:
                continue
            elif sorted_l[1][j]>sorted_l[0][-1]:
                ans+=n
            else:
                ans+=(bisect_left(sorted_l[0],sorted_l[1][j]))
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(3)]

sorted_l = [sorted(l[0]),sorted(l[1])]
ans=0
for i in range(n):
    for j in range(n):
        if sorted_l[1][j]<l[2][i]:
            for k in range(n):
                if sorted_l[0][k]<sorted_l[1][j]:
                    ans+=1
                else:
                    break
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 b:
  a_ind = bisect.bisect_left(a,i)
  c_ind = bisect.bisect_right(c,i)
  ans += len(a[:a_ind])*len(c[c_ind:])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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()]
A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)

# ans=0
# for i in range(N):
#     part1=A[i]
#     part2_pos=bisect.bisect_right(B,part1)
#     for j in range(part2_pos,N):
#         part2=B[j]
#         part3_pos=bisect.bisect_right(C,part2)
#         # print(i,j,part3_spos,": ",A[i],B[j],C[part3_pos])
#         ans+=(N-part3_pos)
# print(ans)

AtoB_Pos=[]
BtoC_Pos=[]
ans=0
for i in range(N):
    B_Pos=bisect.bisect_right(B,A[i])
    AtoB_Pos.append(B_Pos)

for i in range(N):
    C_Pos=bisect.bisect_right(C,B[i])
    BtoC_Pos.append(C_Pos)
# print(AtoB_Pos)
# print(BtoC_Pos)
for i in range(N):
    for j in range(AtoB_Pos[i],N):
        # print(i,j,": ",A[i],B[j])
        # print(N-AtoB_Pos[i],N-BtoC_Pos[j])
        ans+=(N-BtoC_Pos[j])
print(ans)

Submission status: Time Limit Exceeded

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()]
A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)

ans=0
for i in range(N):
    part1=A[i]
    part2_pos=bisect.bisect_right(B,part1)
    for j in range(part2_pos,N):
        part2=B[j]
        part3_pos=bisect.bisect_right(C,part2)
        # print(i,j,part3_spos,": ",A[i],B[j],C[part3_pos])
        ans+=(N-part3_pos)
print(ans)

Submission status: Time Limit Exceeded

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())))
neo_b = [[] for _ in range(n)]
ans = 0
for i in range(n):
  neo_b[i] = bisect.bisect_left(a,b[i])
for i in range(n):
  ans += sum(neo_b[:bisect.bisect_left(b,c[i])])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from bisect import bisect_right
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += len(A[:ai]) * len(C[ci:])
print(r)

Submission status: Time Limit Exceeded

Solution code:
def bin_search(itr, v, ret=None):
  l, r = 0, len(itr) - 1
  while l <= r:
    m = l + (r - l) // 2
    if itr[m] == v:
      if ret == 'smaller':
        r = m - 1
        continue
      if ret == 'bigger':
        l = m + 1
        continue
      return m
    elif itr[m] > v:
      r = m - 1
    else:
      l = m + 1
  if ret == 'smaller':
    return min(l, r)
  if ret == 'bigger':
    return max(l, r)
  return -1
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bin_search(A, B[i], 'smaller')
  ci = bin_search(C, B[i], 'bigger')
  r += len(A[:ai+1]) * len(C[ci:])
print(r)

Submission status: Time Limit Exceeded

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):
  j=bisect.bisect_left(b,a[i]+1)
  if j>=n:
    break
  for k in range(j,n):
    l=bisect.bisect_left(c,b[k]+1)
    if l>=n:
      break
    ans+=n-l
print(ans)

Submission status: Time Limit Exceeded

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):
  j=bisect.bisect_left(b,a[i]+1)
  if j>=n:
    break
  for k in range(j,n):
    l=bisect.bisect_left(c,b[k]+1)
    if l>=n:
      break
    ans+=n-l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=len(C[c_min:])
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==len(B):
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect 
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
cnt=0
for a in A:
    b_min=bisect(B,a)
    for b in B[b_min:]:
        c_min=bisect(C,b)
        cnt+=len(C[c_min:])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

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

ans = 0
for b in B:
    ans += len(A[:bisect_right(A, b - 1)]) * len(C[bisect_left(C, b + 1):])
print(ans)

Submission status: Time Limit Exceeded

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

total = 0
for i in c:
  index_b = bisect.bisect( b, i-1 )
  for j in b[:index_b]:
    index_c = bisect.bisect( a, j-1 )
    total += index_c
print(total)

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)
# print(f"N: {N}")
# print(f"A, B, C: {A}, {B}, {C}")

def binary_search_lower_bound(arr, value):
    left = -1
    right = len(arr)
    while right - left > 1:
        mid = left + int((right - left) / 2)
        if value > arr[mid]:
            left = mid
        elif value < arr[mid]:
            right = mid

    return right

count = 0
B_bin = []
C_bin = []
for top in A:
    # print(f"\ntop: {top}")
    index_B = binary_search_lower_bound(B, top)
    B_bin = B[index_B:]
    # print(f"B_bin: {B_bin}")
    for mid in B_bin:
        # print(f"mid: {mid}")
        index_C = binary_search_lower_bound(C, mid)
        C_bin = C[index_C:]
        count += len(C_bin)

print(count)

Submission status: Time Limit Exceeded

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 = list(map(int, input().split()))

ans = 0
for c in C:
    max_index_B = bisect_left(B, c)
    for i in range(max_index_B):
        ans += bisect_left(A, B[i])

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for c in C:
    max_index_B = bisect_left(B, c)
    for i in range(max_index_B):
        ans += bisect_left(A, B[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
b = li()
c = li()

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

from bisect import bisect_right
def bisect_find(a, x, lo = 0):
    i = bisect_right(a, x, lo=lo)
    return i

# Bのメモを作る
# 任意の中段パーツが乗ることが可能な下段パーツの数をあらかじめ計算しておく
# その後、任意の中段パーツ以上の中段パーツが選択できる下段パーツの数を累積和で求める

b_memo = [0]*n
c_min_limit = 0
for i in range(n):
    c_min_limit = bisect_find(c,b[i],lo=c_min_limit)
    b_memo[i] =  len(c[c_min_limit:])

b_cumsum = [b_memo[n-1]]
for i in range(n-1):
    b_cumsum.append(b_cumsum[i] + b_memo[n-2-i])

# b_cumsum.reverse()
# print(b_memo)
# print(b_cumsum)

ans = 0
b_min_limit = 0
for i in a:
    b_min_limit = bisect_find(b, i, lo=b_min_limit)
    if(b_min_limit == n):
        continue
    ans += b_cumsum[n-1-b_min_limit]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
b = li()
c = li()

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

from bisect import bisect_right
def bisect_find(a, x):
    i = bisect_right(a, x)
    return i

# Bのメモを作る
# 任意の中段パーツが乗ることが可能な下段パーツの数をあらかじめ計算しておく
# その後、任意の中段パーツ以上の中段パーツが選択できる下段パーツの数を累積和で求める
b_memo = [0]*n
for i in range(n):
    c_min_limit = bisect_find(c,b[i])
    b_memo[i] =  len(c[c_min_limit:])

b_cumsum = [b_memo[n-1]]
for i in range(n-1):
    b_cumsum.append(b_cumsum[i] + b_memo[n-2-i])

b_cumsum.reverse()
# print(b_memo)
# print(b_cumsum)

ans = 0
for i in a:
    b_min_limit = bisect_find(b, i)
    if(b_min_limit == n):
        continue
    ans += b_cumsum[b_min_limit]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
b = li()
c = li()

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

from bisect import bisect_right
def bisect_find(a, x):
    i = bisect_right(a, x)
    # if i != len(a):
        # return i
    return i

ans = 0
for i in a:
    b_min_limit = bisect_find(b, i)
    b_selected = b[b_min_limit:]
    for j in b_selected:
        c_min_limit = bisect_find(c, j)
        ans += len(c[c_min_limit:])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input().split()
B=input().split()
C=input().split()
Alist=[int(a) for a in A]
Blist=[int(b) for b in B]
Clist=[int(c) for c in C]
Alist=sorted(Alist)
Blist=sorted(Blist)
Clist=sorted(Clist)
number=0
for a in Alist:
    suuji=0
    for b in Blist:
        if suuji==N:
            break
        if a>=b:
            pass
        else:
            bn=Blist.index(b)
            for c in Clist:
                if b>=c:
                    pass
                else:
                    cn=Clist.index(c)
                    number+=N-cn
                    break
print(number)

Submission status: Time Limit Exceeded

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
B_list = list(map(int, input().rstrip().split()))
C_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()
B_list.sort()
C_list.sort()

cnt=0
for i in A_list:
    ind_B = bisect.bisect_right(B_list, i) 
    for j in B_list[ind_B:]:
        ind_C = bisect.bisect_right(C_list, j)
        cnt += (N - ind_C)

print(cnt)

Submission status: Time Limit Exceeded

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
B_list = list(map(int, input().rstrip().split()))
C_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()
B_list.sort()
C_list.sort()


AB_dic={}
for i in A_list:
    AB_dic[i]=[]
    for j in B_list:
        if j > i:
            AB_dic[i].append(j)

BC_dic={}
for i in B_list:
    BC_dic[i]=[]
    for j in C_list:
        if j > i:
            BC_dic[i].append(j)


cnt=0
for v_A in A_list:
    for v_B in AB_dic[v_A]:
        for v_C in BC_dic[v_B]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
B_list = list(map(int, input().rstrip().split()))
C_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()
B_list.sort()
C_list.sort()

A_idx=0
B_idx=0
C_idx=0
cnt=0
for i_A in range(A_idx,len(A_list)):

    for i_B in range(B_idx,len(B_list)):
        if B_list[i_B] <= A_list[i_A]:
            B_idx = i_B
        else:
            for i_C in range(C_idx,len(C_list)):
                
                if C_list[i_C] <= A_list[i_A]:
                    C_idx = i_C
                elif C_list[i_C] > B_list[i_B] > A_list[i_A]:
                    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.sort()
C = list(map(int, input().split()))
C.sort()
check = [0] * N
ans = 0
for i in range(N):
    check[i] = N - bisect.bisect_right(C,B[i])
for i in range(N):
    tmp = bisect.bisect_right(B,A[i])
    for k in range(tmp,N):
        ans += check[k]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
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 i in range(n):
    if a[i] > b[n - 1]:
        break
    insert_index_b = bisect.bisect_right(b, a[i])  # 昇順
    for j in range(insert_index_b, n):
        insert_index_c = bisect.bisect_right(c, b[j])
        cnt += n - insert_index_c

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
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()))
b.sort()
c.sort()
cnt = 0

for i in range(n):
    insert_index_b = bisect.bisect_right(b, a[i])  # 昇順
    for j in range(insert_index_b, n):
        insert_index_c = bisect.bisect_right(c, b[j])
        cnt += n - insert_index_c

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = list(map(int, input().split(" ")))
bottoms = sorted(list(map(int, input().split(" "))))
# print(tops)
# print(mids)
# print(bottoms)


def left_binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] >= num:
        return left_binary_search(check_list, num, left, mid - 1)
    else:
        return left_binary_search(check_list, num, mid + 1, right)


def right_binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] > num:
        return right_binary_search(check_list, num, left, mid - 1)
    else:
        return right_binary_search(check_list, num, mid + 1, right)


total_count = 0
for mid in mids:
    bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1)
    top_end_index = left_binary_search(tops, mid, 0, N - 1)
    total_count += ((N - bottom_start_index) * top_end_index)
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = sorted(list(map(int, input().split(" "))))
bottoms = sorted(list(map(int, input().split(" "))))
# print(tops)
# print(mids)
# print(bottoms)


def left_binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] >= num:
        return left_binary_search(check_list, num, left, mid - 1)
    else:
        return left_binary_search(check_list, num, mid + 1, right)


def right_binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] > num:
        return right_binary_search(check_list, num, left, mid - 1)
    else:
        return right_binary_search(check_list, num, mid + 1, right)


total_count = 0
for mid in mids:
    bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1)
    top_end_index = left_binary_search(tops, mid, 0, N - 1)
    total_count += ((N - bottom_start_index) * top_end_index)
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AAA = sorted([int(i) for i in input().split()])
BBB = sorted([int(i) for i in input().split()])
CCC = sorted([int(i) for i in input().split()])


def binary_search(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right=mid


ans = 0
for A in AAA:
    for B in BBB[binary_search(A,BBB):]:
        ans += len(CCC)-binary_search(B,CCC)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = sorted(list(map(int, input().split(" "))))
bottoms = sorted(list(map(int, input().split(" "))))


def binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] >= num:
        return binary_search(check_list, num, left, mid - 1)
    else:
        return binary_search(check_list, num, mid + 1, right)


total_count = 0
mid_min_count = min(mids)
bottom_start_index = binary_search(bottoms, mid_min_count, 0, N - 1)
top_min_count = min(mids)
mid_start_index = binary_search(mids, top_min_count, 0, N - 1)
for bottom in bottoms[bottom_start_index:]:
    mid_insert_index = binary_search(mids, bottom, 0, N - 1)
    for mid in mids[mid_start_index:mid_insert_index]:
        total_count += binary_search(tops, mid, 0, N - 1)
print(total_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = sorted(list(map(int, input().split(" "))))
bottoms = sorted(list(map(int, input().split(" "))))


def binary_search(check_list, num, left, right):
    if left > right:
        return left
    mid = (left + right) // 2
    if check_list[mid] >= num:
        return binary_search(check_list, num, left, mid - 1)
    else:
        return binary_search(check_list, num, mid + 1, right)


total_count = 0
min_count = min(mids)
start_index = binary_search(bottoms, min_count, 0, N - 1)
for bottom in bottoms[start_index:]:
    mid_insert_index = binary_search(mids, bottom, 0, N - 1)
    for mid in mids[0:mid_insert_index]:
        total_count += binary_search(tops, mid, 0, N - 1)
print(total_count)