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 = 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:
    for i in range(len(B)):
        if a < B[i]:
            for j in range(len(C)):
                if B[i] < C[j]:
                    ans += len(C)-j
                    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()
Sum = 0
for i in range(N):
    Start_B = bisect.bisect_left(B,A[i]+1)
    for j in range(Start_B, N):
        Start_C = bisect.bisect_left(C,B[j]+1)
        Sum += N - Start_C
print(Sum)

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()))
def merge(x):
    mid = len(x)
    if mid > 1:
        L = merge(x[:int(mid/2)])
        R = merge(x[int(mid/2):])
        x = []
        while len(L) != 0 and len(R) != 0:
            if L[0] < R[0]:
                x.append(L.pop(0))
            else:
                x.append(R.pop(0))
        if len(L) != 0:
            x.extend(L)
        elif len(R) != 0:
            x.extend(R)
    return x
A = merge(A)
B = merge(B)
C = merge(C)
Sum = 0
for i in range(N):
    #print(A[i])
    Start_B = bisect.bisect_left(B,A[i]+1)
    for j in range(Start_B, N):
        #print(B[j])
        Start_C = bisect.bisect_left(C,B[j]+1)
        #print(C[Start_C])
        Sum += N - Start_C
print(Sum)

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()))
def merge(x):
    mid = len(x)
    if mid > 1:
        L = merge(x[:int(mid/2)])
        R = merge(x[int(mid/2):])
        x = []
        while len(L) != 0 and len(R) != 0:
            if L[0] < R[0]:
                x.append(L.pop(0))
            else:
                x.append(R.pop(0))
        if len(L) != 0:
            x.extend(L)
        elif len(R) != 0:
            x.extend(R)
    return x
A = merge(A)
B = merge(B)
C = merge(C)
count = 0
for i in range(len(A)):
    for j in range(len(B)):
        if B[j] > A[i]:
            k = len(C)-1
            while k >= 0:
                if C[k] > B[j]:
                    count += 1
                    #print(A[i],B[j],C[k])
                    k -= 1
                else:
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (r-l)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x, l=0):
    return searchsub(arr, x, l, len(arr))

    
    
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)

s = 0
t = 0
for i in range(n):
    t = search(b, a[i])
    left = 0
    for j in range(t, n):
        if (left < n):
            left =  search(c, b[j], left)
            s += n-left


print(s)

Submission status: Time Limit Exceeded

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (r-l)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x, l=0):
    return searchsub(arr, x, l, len(arr))

    
    
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)

s = 0

for i in range(n):
    t = search(b, a[i])
    left = 0
    for j in range(t, n):
        if (left < n):
            left =  search(c, b[j], left)
            s += n-left


print(s)

Submission status: Time Limit Exceeded

Solution code:
def searchsub(arr, x, l, r):
    if r-l <= 1:
        if arr[l]>x:
            return l
        else:
            return l+1
    
    m = l + (r-l)//2
    if arr[m]<=x:
        return searchsub(arr, x, m, r)
    else:
        return searchsub(arr, x, l, m)
        
def search(arr, x):
    return searchsub(arr, x, 0, len(arr))

    
    
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)

s = 0

for i in range(n):
    t = search(b, a[i])
    for j in range(t, n):
        s += n - search(c, b[j])
        
        
print(s)

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

B = b[:]

for i in a:
    while B[0] <= i:
        del B[0]
        if B == []:
            break
    C = c[:]
    if B == []:
        break
    for j in B:
        while C[0] <= j:
            del C[0]
            if C == []:
                break
        if C == []:
            break
        x += len(C)

print(x)

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

B = b

for i in a:
    B = [s for s in B if s > i]
    C = c
    for j in B:
        C = [s for s in C if s > j]
        x += len(C)

print(x)

Submission status: Time Limit Exceeded

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

a, b, c = [sorted(abc_i) for abc_i in abc]

sum_num = 0
for b_i in b:
	can_a_count = n
	for i, a_i in enumerate(a):
		if a_i >= b_i:
			can_a_count = i
			break

	can_c_count = n
	for i, c_i in enumerate(c[::-1]):
		if c_i <= b_i:
			can_c_count = i
			break
	
	sum_num += can_a_count * can_c_count

print(sum_num)

Submission status: Time Limit Exceeded

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

abc_list = []
for x in abc:
    d = dict()
    for x_i in x:
        if x_i not in d:
            d[x_i] = 0
        d[x_i] += 1
    abc_list.append(sorted(d.items()))
a, b, c = abc_list

count = 0
for a_i in a:
    for b_i in b:
        for c_i in c:
            if a_i[0] < b_i[0] < c_i[0]:
                count += a_i[1] * b_i[1] * c_i[1]

print(count)

Submission status: Time Limit Exceeded

Solution code:
def more_num_len(num, r_sorted_list, n):
    for i, m in enumerate(r_sorted_list):
        if m <= num:
            return i
    return n


n = int(input())
a, b, c = [list(map(int, input().split(" "))) for i in range(3)]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

count = 0
for a_i in a:
    x = more_num_len(a_i, b, n)
    for b_i in b[:x]:
        y = more_num_len(b_i, c, n)
        count += y
print(count)

Submission status: Time Limit Exceeded

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

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

count = 0
for a_i in a:
    for b_i in b:
        for c_i in c:
            if a_i < b_i < c_i:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

def main():

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

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

    cnt = 0
    
    for i in range(n):
        for j in range(n):
            if a_list[i] < b_list[j]:
                position = bisect.bisect_right(c_list, b_list[j])
                cnt += n - position
    
    print(cnt)
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect, functools
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())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b_i(i):
    return sum(a(x) for x in B[:i])

@functools.lru_cache(maxsize=None)
def b(n):
    i = bisect.bisect_left(B, n)
    if len(B) + 1 == i:
        return b_i(i - 2) + a(B[i - 2])
    elif 2 <= i:
        return b_i(i - 1) + a(B[i - 1])
    elif 1 == i:
        return a(B[i - 1])
    else:
        return 0

def c():
    return sum(b(x) for x in C)

print(c())

Submission status: Time Limit Exceeded

Solution code:
# vim: set fileencoding=utf-8 :
def main():
    n = int(raw_input())
    A = sorted(map(int, raw_input().split()))
    B = sorted(map(int, raw_input().split()))
    C = sorted(map(int, raw_input().split()))

    comb = 0
    ## AとBだけ比較して、Cはすべて見る必要はない
    for ai in range(n):
        for bj in range(n):
            if A[ai] < B[bj]:
                for ck in range(n):
                    # CからB[bj]よりも大きくなる瞬間のidxを探し、n-idxを足す。
                    if B[bj] < C[ck]:
                        comb += n - ck
                        break

    print(comb)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect, functools
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())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b(n):
    return sum(a(x) for x in B[:bisect.bisect_left(B, n)])

def c():
    return sum(b(x) for x in C)

print(c())

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

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

    cnt = 0

    for i in range(n):
        for j in range(n):
            if a_list[i] < b_list[j]:
                for k in range(n):
                    if b_list[j] < c_list[k]:
                        cnt += n - k
                        break
    
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a2 = sorted(a, reverse=True)

b = list(map(int, input().split()))
b2 = sorted(b, reverse=True)

c = list(map(int, input().split()))
c2 = sorted(c, reverse=True)

cnt = 0
for x in a2:
    for y in b2:
        if x >= y:
            break
        #x < y
        for z in c2:
            if y >= z:
                break
            #y < z
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

lc, uc = {}, {}

for i in b :
    cnt_l, cnt_u = 0, 0
    
    for j in a :
        if j < i :
            cnt_l += 1
            
    lc[i] = cnt_l
    
    for j in c :
        if j > i :
            cnt_u += 1
            
    uc[i] = cnt_u
    
combs = 0
for i in b :
    combs += lc[i] * uc[i]
    
print(combs)

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
A.sort()
C.sort()
for i in range(len(B)):
	a_cand = 0
	c_cand = 0
	for j in range(len(A)):
		if A[j] < B[i]:
			a_cand += 1
		if B[i] < C[j]:
			c_cand += 1
	ans += a_cand * c_cand
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()
b=b[::-1]
c.sort()
ans=tmp=0
for i in a:
    for j in b:
        if i>=j: break
        tmp=bisect.bisect_right(c, j)
        ans+=(n-tmp)
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 = sorted(a)
b = sorted(b)
c = sorted(c)
z = [0] * N
ans = 0
for i in range(N):
  e = b[i]
  cin = insert_index = bisect.bisect_right(c,e)
  z[i] = N-cin
for i in range(N):
  d = a[i]
  bind = insert_index = bisect.bisect_right(b,d)
  ans += sum(z[bind:])
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
A.sort()
B.sort()
C.sort()
for i in range(N, 0, -1):
    for j in range(N, 0, -1):
        #print(B[j-1],C[i-1],"BC")
        if B[j-1] < C[i-1]:
            for k in range(N, 0, -1):
                #print(A[k-1],B[j-1],"AB")
                if A[k-1] < B[j-1]:
                    ans = ans + k
                    break
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
B = list(map(int,input().strip().split(' ')))
C = list(map(int,input().strip().split(' ')))
A.sort()
B.sort()
C.sort()
bstart = 0
cstart = 0
ans = 0
for ai in range(N):
    a = A[ai]
    cstart = 0
    for bi in range(bstart,N):
        b = B[bi]
        if a >= b:
            bstart = bi + 1
        else:    
            for ci in range(cstart,N):
                c = C[ci]
                if b >= c:
                    cstart = ci + 1
                else:
                    ans = ans + (N-ci)
                    break
                    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
B = list(map(int,input().strip().split(' ')))
C = list(map(int,input().strip().split(' ')))
A.sort()
B.sort()
C.sort()
bstart = 0
cstart = 0
ans = 0
for ai in range(N):
    a = A[ai]
    cstart = 0
    for bi in range(bstart,N):
        b = B[bi]
        if a >= b:
            bstart = bi + 1
        else:    
            for ci in range(cstart,N):
                c = C[ci]
                if b >= c:
                    cstart = ci + 1
                else:
                    ans = ans + 1
                    
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
# A_list.sort()
# B_list.sort()
# C_list.sort()

ans = 0
for i in range(N):
    for j in range(N):
        # 下段 <= 中段 になったらやらない
        if C_list[i] <= B_list[j]:
            continue
        for k in range(N):
            # 中段 <= 下段 になったらやらない
            if B_list[j] <= A_list[k]:
                continue
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
A_list.sort()
B_list.sort()
C_list.sort()

ans = 0
for i in range(N):
    for j in range(N):
        # 下段 <= 中段 になったらもうやらない
        if C_list[i] <= B_list[j]:
            break
        for k in range(N):
            # 中段 <= 下段 になったらもうやらない
            if B_list[j] <= A_list[k]:
                break
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
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()
A.reverse()
B.reverse()
C.reverse()

ue=0
naka=0
sita=0
count=0
for i in range(N):
    ue=A[i]
    for j in range(N):
        naka=B[j]
        if ue>=naka:
            break
        for k in range(N):
            
            sita=C[k]
            if A[i]<B[j] and B[j]<C[k]:
                count+=1
            if naka>=sita:
                break
            
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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
stopping_b = 0
stopping_c = 0
count_R = 0
past_ans = 0
first_b_num = 0
count_3rd = -1

for i in range(N):
    if A[i] > B[N - 1] or A[i] > C[N - 1]:
        continue
    if count_R > 0:
        if A[i] < B[first_b_num]:
            count += past_ans
            continue
    a = A[i]
    for j in range(stopping_b, N):
        b = B[j]
        if B[i] > C[N - 1]:
            continue
        for k in range(stopping_c, N):
            c = C[k]
            count_3rd += 1
            if a < b < c:
                count += N - k
                stopping_c = k
                if count_3rd == 0:
                    first_b_num = j
                break
    else:
        count_3rd = 0
        stopping_c = 0
        count_R += 1
        past_ans = count - past_ans
        stopping_b = first_b_num
        first_b_num = 0
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
stopping_b = 0
stopping_c = 0

for i in range(N):
    if A[i] > B[i] or A[i] > C[i] or C[N - 1] < A[i] or C[N - 1] < B[i] or B[N - 1] < A[i]:
        continue
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(stopping_c, N):
            c = C[k]
            if a < b < c:
                count += N - k
                stopping_c = k
                break
    else:
        stopping_c = 0
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()

for i in range(N):
    if A[i] > B[i] or A[i] > C[i]:
        continue
    if C[N - 1] < A[i] or C[N - 1] < B[i]:
        continue
    if B[N - 1] < A[i]:
        continue
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(N):
            c = C[k]
            if a < b < c:
                count += N - k
                break
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()

for i in range(N):
    if A[i] > B[i] or A[i] > C[i]:
        continue
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(N):
            c = C[k]
            if a < b < c:
                count += N - k
                break
else:
    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 = 0
b = 0
c = 0
count = 0
A.sort()
B.sort()
C.sort()
while True:
    for i in range(N):
        if A[i] > B[i] or A[i] > C[i]:
            continue
        a = A[i]
        for j in range(N):
            b = B[j]
            for k in range(N):
                c = C[k]
                if a < b < c:
                    count += 1
    else:
        break

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 = 0
b = 0
c = 0
count = 0
cutting = 0
A.sort()
B.sort()
C.sort()

for i in range(N):
    a = A[i]
    for j in range(N):
        b = B[j]
        for k in range(N):
            c = C[k]
            if a < b < c:
                count += N - k
                break
else:
    print(count)

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()
c.sort(reverse=True)
p=0
q=0
i = 0
ans = 0
for bss in b:
  p = 0
  q = 0
  for ass in a:
    if ass < bss:
      p += 1
  for css in c:
    if css > bss:
      q += 1
  ans += p*q
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
A.sort()
B.sort()
C.sort()
for i in range(N, 0, -1):
    for j in range(N, 0, -1):
        #print(B[j-1],C[i-1],"BC")
        if B[j-1] < C[i-1]:
            for k in range(N, 0, -1):
                #print(A[k-1],B[j-1],"AB")
                if A[k-1] < B[j-1]:
                    ans = ans + k
                    break
else:
    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()))
a = 0
b = 0
c = 0
count = 0
while True:
    for i in range(N):
        a = A[i]
        for j in range(N):
            b = B[j]
            for k in range(N):
                c = C[k]
                if a < b < c:
                    count += 1
    else:
        break

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()))
ck = 0
for i in range(0, N):
    for j in range(0, N):
        for k in range(0, N):
            if A[i] < B[j] < C[k]:
                ck = ck + 1
else:
    print(ck)

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

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]:
                    num += 1
print(num)

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

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

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

result = 0

for i in range(N):
    a = bisect_left(A,B[i])
    c = bisect_right(C,B[i])
    result += len(A[:a]) * len(C[c:])

print(result)

Submission status: Time Limit Exceeded

Solution code:
"""
二分探索O(nlogn)でかいてみたらTLEして、通ってる回答みたら線形探索O(n**2)でもとおっててなんでという気持ち
二分探索で答えがもとまらず無限ループになってしまうケースがあるぽい？
"""
N = int(input())


def binary_search(L, target):
    """
    >>> binary_search([1,3,5],2)
    2
    >>> binary_search([1,3,5],5)
    0
    >>> binary_search([1,3,5],9)
    0
    >>> binary_search([1,3,3,3,3,5],3)
    1
    >>> binary_search([1,3,3,3,3,5],4)
    1
    """
    if L[0] > target:
        return len(L)
    if L[-1] <= target:
        return 0
    right_i = len(L) - 1
    left_i = 0
    j = 0
    while left_i + 1 != right_i and j != 10000000:
        j += 1
        med_i = (right_i + left_i) // 2
        if L[med_i] < target:
            left_i = med_i
        elif L[med_i] > target:
            right_i = med_i
        else:
            while L[med_i + 1] == target:
                med_i += 1
            return len(L) - med_i - 1
    return len(L) - right_i


D = []
for _ in range(3):
    D.append(list(map(int, input().split())))
A, B, C = D
A.sort()
A = [-a for a in A]
A.sort()
C.sort()
ans = 0

for b in B:
    ans += binary_search(A, -b) * binary_search(C, b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


def binary_search(L, target):
    """
    >>> binary_search([1,3,5],2)
    2
    >>> binary_search([1,3,5],5)
    0
    >>> binary_search([1,3,5],9)
    0
    >>> binary_search([1,3,3,3,3,5],3)
    1
    >>> binary_search([1,3,3,3,3,5],4)
    1
    """
    if L[0] > target:
        return len(L)
    if L[-1] <= target:
        return 0
    right_i = len(L) - 1
    left_i = 0
    j = 0
    while left_i + 1 != right_i:
        med_i = (right_i + left_i) // 2
        if L[med_i] < target:
            left_i = med_i
        elif L[med_i] > target:
            right_i = med_i
        else:
            while L[med_i + 1] == target:
                med_i += 1
            return len(L) - med_i - 1
    return len(L) - right_i


D = []
for _ in range(3):
    D.append(list(map(int, input().split())))
A, B, C = D
A = [-a for a in A]
A.sort()
C.sort()
ans = 0

for b in B:
    ans += binary_search(A, -b) * binary_search(C, b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


def binary_search(L, target):
    """
    >>> binary_search([1,3,5],2)
    [3, 5]
    >>> binary_search([1,3,5],5)
    []
    >>> binary_search([1,3,5],9)
    []
    >>> binary_search([1,3,5],1)
    [3, 5]
    >>> binary_search([1,3,3,3,3,5],3)
    [5]
    """
    if L[0] > target:
        return L
    if L[-1] <= target:
        return []
    right_i = len(L) - 1
    left_i = 0
    j = 0
    while left_i + 1 != right_i and j != 10:
        j += 1
        med_i = (right_i + left_i) // 2
        if L[med_i] < target:
            left_i = med_i
        elif L[med_i] > target:
            right_i = med_i
        else:
            while L[med_i + 1] == target:
                med_i += 1
            return L[med_i + 1:]

    return L[right_i:]


D = []
for _ in range(3):
    D.append(list(map(int, input().split())))
A, B, C = D
A.sort()
B.sort()
C.sort()
ans = 0

for a in A:
    b_rest = binary_search(B, a)
    for b in b_rest:
        ans += len(binary_search(C, b))
print(ans)

Submission status: Time Limit Exceeded

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


def binary_search(list, key):
    l = -1
    r = len(list)

    while r - l > 1:
        mid = l + (r - l) // 2
        if list[mid] > key:
            r = mid
        else:
            l = mid

    if r < len(list):
        return r
    else:
        return -1


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 a in A:
    index_a = binary_search(B, a)
    if index_a != -1:
        for i in range(index_a, len(B)):
            index_b = binary_search(C, B[i])
            if index_b != -1:
                ans += n - index_b

print(ans)

Submission status: Time Limit Exceeded

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

# lst_A = list(range(N))
lst_B = list(range(N))

ans = 0

# for i in range(N):
#    for j in range(N):
#        if B[j] > A[i]:
#            for k in range(N):
#                if C[k] > B[j]:
#                    ans += N - k
#                    break

j, k = 0, 0

for i in range(N):
    while j < N and C[j] <= B[i]:
        j += 1
    lst_B[i] = N - j

for i in range(N):
    while k < N and B[k] <= A[i]:
        k += 1
    if k == N:
        ans += 0
    else:
        for l in range(k, N):
            ans += lst_B[l]

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(N):
    for j in range(N):
        if B[j] > A[i]:
            for k in range(N):
                if C[k] > B[j]:
                    ans += N - k
                    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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

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]:
                    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = 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())))

b_c_list = []
for b in B_list:
    counter = 0
    for c in C_list:
        if  b < c:
            counter += 1
    b_c_list.append(counter)
   
sum_counter = 0
for a in A_list:
    for i, b in enumerate(B_list):
        if a < b:
            sum_counter += b_c_list[i]
            
print(sum_counter)

Submission status: Time Limit Exceeded

Solution code:
N = 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())))

counter = 0
for a in A_list:
    for b in B_list:
        for c in C_list:
            if a < b < c:
                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()))
num = 0
a.sort
b.sort
c.sort

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

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

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