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:
# ソートすりゃいい てっぺんは小さい方から、あとは大きい方から比較していって、ダメになったら抜ける
# と思ったんだけど、これだとTLE。ai以上の最小のbi、bi以上の最小のciをにぶたんで求めて、nから引いて残った数を掛け合わせる
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 nibutan(arr, target):
    left, right = 0,  len(arr)-1//10**9
    while left < right:
        mid = (left + right)//2
        if arr[mid] > target:
            right = mid
        else:
            left = mid + 1
    # rightが「arrの中でtargetを超える最小の値」
    return right


count = 0
for a in A:
    bi = nibutan(B, a)
    for b in B[bi:]:
        ci = nibutan(C, b)
        count += len(C[ci:])
        # print("A: {} B: {}: に対してのCのリスト\n{}".format(a, b, C[ci:]))


print(count)

Submission status: Time Limit Exceeded

Solution code:
# ソートすりゃいい てっぺんは小さい方から、あとは大きい方から比較していって、ダメになったら抜ける
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()))))

count = 0
for a in A:
    for b in B[::-1]:
        if a >= b:
            break
        for c in C[::-1]:
            if b >= c:
                break
            count += 1
print(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(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

count = 0
for i in range(N):
    j = 0
    flag1 = True
    while flag1:
        if A[i] < B[j]:
            flag2 = True
            k = 0
            while flag2:
                if B[j] < C[k]:
                    count += 1
                    k += 1
                else: 
                    flag2 = False
                if k == N:
                    flag2 = False
            j += 1
        else:
            flag1 = False
        if j == N:
            flag1 = False



print (count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
#print(N,a,b,c)
#lst = []
cnt = 0
for i in a:
  for j in b:
    if i >= j:
      break
    for k in c:
      if j >= k: 
        break
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

    ans = 0
    for a in A:
        for b in B:
            if a >= b:
                break
            for i, c in enumerate(C):
                if c > b:
                    ans += N - i
                    break
    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    _ = 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:
            if a >= b:
                continue
            for c in C:
                if c > b:
                    ans += 1
    print(ans)


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()))
#print(N,a,b,c)
#lst = []
cnt = 0
for i in a:
  for j in b:
    if i >= j:
      continue
    for k in c:
      if i < j < k: #and not [i,j,k] in lst:
        cnt += 1
        #lst.append([i,j,k])
print(cnt)

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()))
#print(N,a,b,c)
#lst = []
cnt = 0
for i in a:
  for j in b:
    for k in c:
      if i < j < k: #and not [i,j,k] in lst:
        cnt += 1
        #lst.append([i,j,k])
print(cnt)

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


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

ans = 0
#
for a in A:
    for b in B:
        if a >= b: continue
        for c in C:
            if b >= c: continue
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

count = 0
for i in range(N):
    a = A[i]
    for j in range(N):
        b = B[j]
        if a >= b:
            #flag = True
            break
        for k in range(N):
            c = C[k]
            if b >= c:
                break
            #print(a,b,c)
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

input()
A=[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 a in A:
  for b in B[bisect.bisect_right(B,a):]:
    ans+=len(C[bisect.bisect_right(C,b):])

print(ans)

Submission status: Time Limit Exceeded

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 a in A:
  for b in B[bisect.bisect_right(B,a):]:
    ans+=len(C[bisect.bisect_right(C,b):])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# def binary_search(lst):
#     pass


import bisect


n = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    ia = bisect.bisect_left(lst_A, b)
    ic = bisect.bisect_right(lst_C, b)
    na = len(lst_A[:ia])
    nc = len(lst_C[ic:])
    ans += na * nc


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product


n = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))


lst_ABC = list(product(lst_A, lst_B, lst_C))
ans = sum(1 for a, b, c in lst_ABC if a < b < c)
print(ans)

Submission status: Time Limit Exceeded

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 = N-1
    while ai < N and a[ai] < bi:
        ai += 1
    while ci >= 0 and c[ci] > bi:
        ci -= 1
    ans += ai * (N - 1 -ci)
print(ans)

Submission status: Time Limit Exceeded

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()))
count = 0
a.sort()
list.sort(b,reverse=True)
list.sort(c,reverse=True)
for ai in a:
    for bi in b:
        if ai < bi:
            for ci in c:
                if bi < ci:
                    count +=1
                else:
                    break       
        else:
            break
    
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 = sorted(list(map(int, input().split())))
ans = 0
for c in C:
    i = bisect_left(B, c)
    for b in B[:i]:
        j = bisect_left(A, b)
        ans += j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a1 = sorted(list(map(int,input().split())),reverse = True)
a2 = sorted(list(map(int,input().split())),reverse = True)
a3 = sorted(list(map(int,input().split())),reverse = True)
count=0
for i1 in a1:
    for i2 in a2:
        if i1 < i2:
            for i3 in a3:
                if i2 < i3:
                    count+=1
                else:
                    break
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = np.array(list(map(int, input().split())))

ans = 0
for i in a:
  for j in sorted(b, reverse=True):
    if i < j:
      ans += sum(c > j)
    else:
      break
      
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()))

ans = 0
for i in a:
  for j in sorted(b, reverse=True):
    if i < j:
      for k in sorted(c, reverse=True):
        if k > j:
          ans += 1
        else:
          break
    else:
      break
      
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()))

ans = 0
for i in a:
  for j in sorted(b, reverse=True):
    if i < j:
      ans += len([k for k in c if k > j])
    else:
      break
      
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()))

ans = 0
for i in a:
  for j in sorted(b, reverse=True):
    if i < j:
      cc = j + 0.5
      c.append(cc)
      c = sorted(c, reverse=True)
      ans += c.index(cc)
      c.remove(cc)
    else:
      break
      
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()))

ans = 0
for i in a:
  for j in b:
    if i < j:
      cc = j + 0.5
      c.append(cc)
      c = sorted(c, reverse=True)
      ans += c.index(cc)
      c.remove(cc)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
A, B, C = (sorted([int(i) for i in input().split()]) for _ in range(3))

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
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: 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()
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: Time Limit Exceeded

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)


    i = j = 0

    count = 0
    while i < n:
        # 下段を選ぶ
        c = clist[i]

        # 下段で選んだcよりも小さいb候補を探す
        while j < n and blist[j] >= c:
            j += 1
            if j == n:
                break
        bcand = blist[j:]

        for b in bcand:
            # b候補より小さいa候補を探す
            k = 0
            while k < n and alist[k] >= b:
                k += 1
                if k == n:
                    break
            # このkより右側は構成可能
            count += (n - k)
        i += 1

    print(count)
    return



if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_a = sorted(list(map(int, input().split())))
list_b = sorted(list(map(int, input().split())))
list_c = sorted(list(map(int, input().split())))

def find_index(a, b, memory_a, judge):
    if judge == 0:
        if b[memory_a] in a:
            return a.index(b[memory_a])
        elif b[memory_a] < a[0]:
            return 0
        elif b[memory_a] > a[n-1]:
            return n
        else:
            s = 0
            t = n-1
            while s+1 != t:
                med = (s+t)//2
                if b[memory_a] < a[med]:
                    t = med
                else:
                    s = med
            return t
    else:
        if a[memory_a] in b:
            return b.index(a[memory_a]) + b.count(a[memory_a])
        elif a[memory_a] < b[0]:
            return 0
        elif a[memory_a] > b[n-1]:
            return n
        else:
            s = 0
            t = n-1
            while s+1 != t:
                med = (s+t)//2
                if a[memory_a] < b[med]:
                    t = med
                else:
                    s = med
            return t

ans_list = []

for memory_b in range(n):
    ans_list.append([find_index(list_a, list_b, memory_b, 0), find_index(list_b, list_c, memory_b, 1)])

ans = 0
for i in range(len(ans_list)):
    ans += ans_list[i][0] * (n - ans_list[i][1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
import bisect

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

count=0
index_b=0
index_c=0
for i in range(n):
        index_c=bisect.bisect_left(b,c[i])
        for j in range(index_c):
                count+=bisect.bisect_left(a,b[j])
print(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()))
ans=0
for i in a:
    b_lst=[k for j in b for k in c if j>i and k>j]
    ans+=len(b_lst)
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()))
ans=0
for i in a:
    for j in b:
        for k in c:
            if i<j<k:
                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()))

nums = []
for b in B:
    count = 0
    for c in C:
        if b < c:
            count += 1
    nums.append(count)

ans = 0
for a in A:
    for b, n in zip(B, nums):
        if a < b:
            ans += n
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()
s=bisect.bisect_left(a,b[-1])
l=bisect.bisect_right(c,b[0])
cnt=0
ab=[]
for B in b:
    for A in a[:s+1]:
        if B>A:
            ab+=[B]
ans=0
for AB in ab:
    for C in c[l:]:
        if AB<C:
            ans+=1
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()]

ab=[]
for B in b:
    for A in a:
        if B>A:
            ab+=[B]
ans=0
for AB in ab:
    for C in c:
        if AB<C:
            ans+=1
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(reverse=True)
C.sort(reverse=True)

ans = 0
for i in A:
    if i >= B[0]:
        break
    for j in B:
        if j >= C[0]:
            continue
        if j <= i:
            break
        for k in C:
            if k <= j:
                break
            ans += 1

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(reverse=True)
C.sort(reverse=True)

ans = 0
for i in A:
    if i >= B[0]:
        break
    for j in B:
        if j <= i:
            break
        for k in C:
            if k <= j:
                break
            ans += 1

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(reverse=True)
C.sort(reverse=True)

ans = 0
for i in A:
    for j in B:
        if j <= i:
            break
        for k in C:
            if k <= j:
                break
            ans += 1

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 A:
    if i > B[-1]:
        break
    for j in B:
        if j > C[-1]:
            break
        for k in C:
            if i < j < k:
                ans += 1

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())))
ans=0
for a in A:
  b=bisect.bisect_left(B,a+1)
  for i in range(n-b):
    ans+=n-bisect.bisect_left(C,B[b+i]+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()

a2=[]
for i1 in range(N):
    a2.append(bisect.bisect_left(C,B[i1]+1))
ans=0
for i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    for i1 in range(a1,N):
        ans += N - a2[i1]
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 i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    for i1 in range(a1,N):
        a2 = bisect.bisect_left(C,B[i1]+1)
        ans += N - a2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
shita = list(map(int,input().split()))
shita.sort()
shita = [[shita[i], 2, i] for i in range(n)]
naka = list(map(int,input().split()))
naka.sort()
naka = [[naka[i], 2, i] for i in range(len(naka))]
ue = list(map(int,input().split()))
ue.sort()
ue = [[ue[i], 1, i] for i in range(len(ue))]
nakaue = ue + naka
nakaue.sort()
naka = []
k = 0
for i in range(2*n):
  if nakaue[i][1] == 2: 
    k += 1
    naka.append([nakaue[i][0], 1 , n + k - i - 1])
shitanaka = shita + naka
shitanaka.sort()
shitanaka.reverse()
k = 0
a=[]
while(shitanaka):
 if shitanaka[0][1] == 1:
   k += shitanaka[0][2]
 else:
  a.append(k)
 del(shitanaka[0])
  
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ABC=[[int(i) for i in input().split()] for _ in range(3)]
b=[]
c=[]
count=0
for i in range(3):
    ABC[i].sort()

for j in range(N):
    b=[int(i) for i in ABC[1] if i>ABC[0][j]]
    for k in range(len(b)):
        c=[int(i) for i in ABC[2] if i>b[k]]
        count+=len(c)
print(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()
def isOK(idx: int, key: int, lis: list) -> bool:
    if lis[idx] >= key:
        return True
    else:
        return False

def binary_search(key: int, lis: list) -> int:
    left = -1
    right = len(lis)
    while(right - left > 1):
        mid = left + (right - left) // 2
        if isOK(mid, key, lis):
            right = mid
        else:
            left = mid
    return left
ans = 0
for i in c:
    k = binary_search(i, b)
    for j in range(k + 1):
        l = binary_search(b[j], a)
        ans += l + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import lt
from functools import partial


def solve(string):
    n, *abc = map(int, string.split())
    a = sorted(abc[:n], reverse=True)
    b = sorted(abc[n:2 * n], reverse=True)
    c = sorted(abc[2 * n:], reverse=True)
    ab = [len(list(filter(partial(lt, _a), b))) for _a in a]
    bc = [0] + [len(list(filter(partial(lt, _b), c))) for _b in b]
    for i in range(1, len(bc)):
        bc[i] += bc[i - 1]
    return str(sum([bc[_ab] for _ab in ab]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

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

step2 = [0 for i in range(N)]
for j in range(N):
    maxim_value = 0
    for i in range(maxim_value,N):
        if A[i] >= B[j]:
            step2[j] = i
            maxim_value = i
            break
        elif i == N-1:
            step2[j] = i+1
            maxim_value = i+1

ans = 0
for i in range(N):
    mini_value = 0
    for j in range(mini_value,N):
        if B[i] < C[j]:
            mini_value = j
            ans += step2[i]*(N-j)
            break
# print(step2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

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

step2 = [0 for i in range(N)]
for j in range(N):
    for i in range(N):
        if A[i] >= B[j]:
            step2[j] = i
            break
        elif i == N-1:
            step2[j] = i+1

ans = 0
for i in range(N):
    for j in range(N):
        if B[i] < C[j]:
            # print(step2[i]*(N-j))
            ans += step2[i]*(N-j)
            break
# print(step2)

print(ans)

Submission status: Time Limit Exceeded

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

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

answer = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())),reverse=True)
C = sorted(list(map(int, input().split())),reverse=True)
c = 0
#print(A)
for i in range(N):
    for j in range(N):
        if B[j]<=A[i]:
            break
        for k in range(N):
            if C[k]<=B[j]:
                break
            #if C[k] > B[j] > A[i]:
            c += 1
                # print(A[i],B[j],C[k])
            # else:
            #     break
print(c)

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()
count = 0
b_list = [bisect.bisect_right(a, b_ - 1) for b_ in b]
c_list = [sum(b_list[:bisect.bisect_right(b, c_ - 1)]) for c_ in c]
ans = sum(c_list)
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()
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: Time Limit Exceeded

Solution code:
import sys, bisect
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N = read_int()[0]
A = sorted(read_int())
B = sorted(read_int())
C = sorted(read_int())

def solve():
    ans = 0
    for i in range(N):
        lbb = bisect.bisect_right(B,A[i])
        for j in range(lbb, N):
            lbc = bisect.bisect_right(C,B[j])
            ans += N - lbc
    return ans


if __name__ == "__main__":
    print(solve())

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()
import bisect
ans = 0
for i in range(len(a)):
    j = bisect.bisect_right(b,a[i])
    for k in range(j,len(b)):
        m = bisect.bisect_right(c,b[k])
        ans += n-m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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

Solution code:
import bisect
n=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
ans=0
for c in C:
    a=bisect.bisect_left(B,c)
    if a==0:
        continue
    for b in B[:a]:
        c=bisect.bisect_left(A,b)
        if c==0:
            break
        else:    
            ans+=c
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import bisect

def solve(N,A,B,C):

    # A=['3', '14', '159', '2', '6', '53']
    # B=['58', '9', '79', '323', '84', '6']
    # C=['2643', '383', '2', '79', '50', '288']
    A,B,C=list(map(int, A)),list(map(int, B)),list(map(int, C))
    A=sorted(A)
    B=sorted(B)
    C=sorted(C)
    # print(A)
    # print(B)
    # print(C)
    D = [0]*N
    E = [0]*N
    for i in range(N):
        a = A[i]
        # print(N-bisect.bisect_right(B,a))
        D[i]= N-bisect.bisect_right(B,a)
        #bはaより大きい数字が何個あるか分かれば良い
        #cはbの
    # print(D)

    for i in range(N):
        b = B[i]
        E[i] = N-bisect.bisect_right(C,b)
    
    # print(E)
    answer = 0
    for i in range(N):
        d=N-D[i]
        answer+=sum(E[d:])

    print(answer)

    
 
 
def main():
    N = int(input())
    A=input().rstrip().split()
    B=input().rstrip().split()
    C=input().rstrip().split()
    solve(N,A,B,C)

 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:





def findindex(X,n,s):#nより小さい最大のインデックスを返す
	if(len(X)==1):
		if(X[0]<n):
			return s
		else:
			return s+1
	if(X[len(X)//2]>=n):
		return findindex(X[:len(X)//2],n,s)
	else:
		return findindex(X[len(X)//2:],n,s+len(X)//2)
def findindex_r(X,n,s):#nより小さい最大のインデックスを返す
	if(len(X)==1):
		if(X[0]>n):
			return s
		else:
			return s+1
	if(X[len(X)//2]>n):
		return findindex_r(X[:len(X)//2],n,s)
	else:
		return findindex_r(X[len(X)//2:],n,s+len(X)//2)


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

A.sort()
C.sort()

a=0
b=0
c=0

#

##
#
#
#
#Bのそれぞれの要素は, A, Cの要素いくつと繋がっているのか
#その積をすべてのBで足し合わせる


#
s=0
for i in range(N):
	s+=(findindex(A,B[i],0)+1)*(N-findindex_r(C,B[i],0))
print(s)

Submission status: Time Limit Exceeded

Solution code:



def findindex(X,n,s):#nより小さい最大のインデックスを返す
	if(len(X)==1):
		if(X[0]<n):
			return s
		else:
			return s+1
	if(X[len(X)//2]>=n):
		return findindex(X[:len(X)//2],n,s)
	else:
		return findindex(X[len(X)//2:],n,s+len(X)//2)
def findindex_r(X,n,s):#nより小さい最大のインデックスを返す
	if(len(X)==1):
		if(X[0]>n):
			return s
		else:
			return s+1
	if(X[len(X)//2]>n):
		return findindex_r(X[:len(X)//2],n,s)
	else:
		return findindex_r(X[len(X)//2:],n,s+len(X)//2)


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

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

a=0
b=0
c=0

#

##
#
#
#
#Bのそれぞれの要素は, A, Cの要素いくつと繋がっているのか
#その積をすべてのBで足し合わせる


#
s=0
for i in range(N):
	s+=(findindex(A,B[i],0)+1)*(N-findindex_r(C,B[i],0))
print(s)