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:
# -*- coding: utf-8 -*-

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

Bc, Cc = [0]*n, [0]*n
Bp, Cp = 0, 0

for i in range(n):
    index = bisect.bisect_right(B[Bp:], A[i])
    Bc[i], Bp = n - index - Bp, index + Bp
    index = bisect.bisect_right(C[Cp:], B[i])
    Cc[i], Cp = n - index - Cp, index + Cp

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)

Submission status: Time Limit Exceeded

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

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

Bc, Cc = [0]*n, [0]*n
Bp, Cp = 0, 0

for i in range(n):
    index = bisect.bisect_right(B, A[i])
    Bc[i] = n - index
    index = bisect.bisect_right(C, B[i])
    Cc[i] = n - index

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)

Submission status: Time Limit Exceeded

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

import math

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

Bc, Cc = [0]*n, [0]*n
Bp, Cp = 0, 0

for i in range(n):
    for j in range(Bp, n, 1):
        if A[i] < B[j]:
            Bc[i] = n - j
            Bp = j
            break
    for j in range(Cp, n, 1):
        if B[i] < C[j]:
            Cc[i] = n - j
            Cp = j
            break

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)

Submission status: Time Limit Exceeded

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

import math

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

Bc, Cc = [0]*n, [0]*n

for i in range(n):
    for j in range(n):
        if A[i] < B[j]:
            Bc[i] = n - j
            break
    for j in range(n):
        if B[i] < C[j]:
            Cc[i] = n - j
            break

Ccs = [sum(Cc[i:]) for i in range(n)]

count = 0
for bc in Bc:
    if bc > 0:
        count += Ccs[n-bc]

print(count)

Submission status: Time Limit Exceeded

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

import math

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

Bc, Cc = [0]*n, [0]*n

for i in range(n):
    for j in range(n):
        if A[i] < B[j]:
            Bc[i] = n - j
            break
    for j in range(n):
        if B[i] < C[j]:
            Cc[i] = n - j
            break

count = 0
for bc in Bc:
    count += sum(Cc[n-bc:])

print(count)

Submission status: Time Limit Exceeded

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

import math

n = int(input())

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

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

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

listAB = []
listBC = []
sum = 0
case = 0

for b in B:
    for a in A:
        if b > a:
            listAB.append([])
    for c in C:
        if b < c:
            listBC.append([])
    case = len(listAB)*len(listBC)
    listAB = []
    listBC = []
    sum = sum + case

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def lma():return list(map(int, input().split()))#x or y

a = int(input())
k=[]
s=[]
co=[0]*a*3
c=0
s= [lma()]
x2= lma()
x3 = lma()
s.append(x2)
s.append(x3)
res =0
for j in range(3):
    for i in range(a):
        k.append([j,s[j][i]])
k.sort(key=lambda x: x[1], reverse=True)
for i in range(a*3):
    if k[i][0] == 2:
       c+=1
    elif k[i][0] == 1:
       co[i] = c
    else:
       res+=sum(co[:i])
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in 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 range(N):
    low = -1
    high = N
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
        if high == low:
            break
    low = -1
    high = N
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
        if high == low:
            break
    total = total + (mid1 + 1) * (N - mid2)

print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
A=Counter(input().split())
B=Counter(input().split())
C=Counter(input().split())
ans=0
for a_key,a_count in A.most_common():
    for b_key,b_count in B.most_common():
        for c_key,c_count in C.most_common():
            a_key,b_key,c_key=int(a_key),int(b_key),int(c_key)
            if a_key<b_key and b_key<c_key:
                ans+=a_count*b_count*c_count
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ai = list(map(int, input(). split()))
Bi = list(map(int, input(). split()))
Ci = list(map(int, input(). split()))

Ai.sort()
Bi.sort()
Ci.sort()
count = 0

for k in range(N):
    for j in range(N):
        for i in range(N):
            if (Ci[k] > Bi[j]):
                if (Bi[j] > Ai[i]):
                    count += 1
                else:
                    break
            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 = sorted(a)
b = sorted(b)
c = sorted(c, reverse=True)
count = 0
a_count = 0
for i in range(n):
    b_select = b[i]
    a_count = 0
    for j in a:
        if j < b_select:
            a_count += 1
        else:
            break
             
    c_count = 0
    for k in c:
        if k > b_select:
            c_count += 1
        else:
            break
    count += a_count * c_count
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 = sorted(a)
b = sorted(b)
c = sorted(c)

count = 0
for i in range(n):
    b_select = b[i]
    a_count = sum(x < b_select for x in a)
    c_count = sum(x > b_select for x in c)
    count += a_count * c_count
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()))

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

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right


def main():
    n = int(input())
    aa = sorted(map(int, input().split()))
    bb = sorted(map(int, input().split()))
    cc = sorted(map(int, input().split()))

    res = 0
    for a in aa:
        i_b = bisect_right(bb, a)
        for b in bb[i_b:]:
            i_c = bisect_right(cc, b)
            res += n - i_c
    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
for a,b,c in zip(A,B,C):
    bisect.insort_left(A2, a)
    # bisect.insort_left(B2, b)
    bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np

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

# for c in C:
#     for b in [x for x in B if x < c]:
#         for a in [x for x in A if x < b]:

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
for a,b,c in zip(A,B,C):
    bisect.insort_left(A2, a)
    bisect.insort_left(B2, b)
    bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np

sum = 0
for b in B:
    sum += bisect.bisect_left(A2, b) * (N - bisect.bisect_right(C2, b))

# for c in C:
#     for b in [x for x in B if x < c]:
#         for a in [x for x in A if x < b]:

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
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()

# print(A,B,C)


sum = 0
for b in B:
    sum += len(
        [x for x in A if x < b]
    ) * len (
        [x for x in C if x > b]
    )

# for c in C:
#     for b in [x for x in B if x < c]:
#         for a in [x for x in A if x < b]:

print(sum)

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
value=[0]*len(B)
#Bより小さい値
B_s=[]
for i in B:
  tmp=0
  for j in A:
    if i > j:
      tmp+=1
  if tmp!=0:
    B_s.append(tmp)

k=0
for i in B:
  tmp=0
  for j in C:
    if j>i:
      tmp+=1
  if k<len(B_s):
    ans+=tmp*B_s[k]
    k+=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())



#%%
# n = 6
# a = [3, 14, 159, 2, 6, 53]
# b = [58, 9, 79, 323, 84, 6]
# c = [2643, 383, 2, 79, 50, 288]

#%%
a=sorted(a)
b=sorted(b)
c=sorted(c)

#%%
ans = 0

for ci in c:
    for bi in b:
        if ci > bi:
            for ai in a:
                if bi > ai:
                    # print(ci, bi, ai)
                    ans += 1
                else:
                    break
        else:
            break

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



#%%
# n = 6
# a = [3, 14, 159, 2, 6, 53]
# b = [58, 9, 79, 323, 84, 6]
# c = [2643, 383, 2, 79, 50, 288]

#%%
a.sort()
b.sort()
c.sort()

#%%
ans = 0

for ci in c:
    for bi in b:
        if ci > bi:
            for ai in a:
                if bi > ai:
                    # print(ci, bi, ai)
                    ans += 1
                else:
                    break
        else:
            break

#%%
print(ans)

#%%

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import bisect

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

A = sorted(A)
B = sorted(B)
C = sorted(C)

BAcnt = [0] * N

for i in range(N):
    BAcnt[i] = bisect.bisect_left(A, B[i])

ret = 0
for i in range(N):
    csize = C[i]
    for j in range(N):
        bsize = B[j]
        if bsize < csize:
            ret += BAcnt[j]

print(ret)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left,bisect_right

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

for j in range(len(b_list)):
    ans += bisect_left(a_list,b_list[j])*len(c_list[bisect_right(c_list,b_list[j]):])

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

for i in range(n):
  for j in range(n):
    if C[i]>B[j]:
      for k in range(n):
        if B[j]>A[k]:
          cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8
import sys

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

# num of Ai each Bi can lift
capacity_B = [0] * N
idx_A = 0
idx_B = 0
for i in range(2 * N):
    if idx_B == N: break
    elif idx_A == N:
        for i in range(idx_B, N): capacity_B[i] = N
    elif A[idx_A] >= B[idx_B]:
        capacity_B[idx_B] = idx_A
        idx_B += 1
    else:
        idx_A += 1
        
# print("#", capacity_B)

# num of Bi each Ci can lift
capacity_C = [0] * N
idx_B = 0
idx_C = 0
for i in range(2 * N):
    if idx_C == N: break
    elif idx_B == N:
        for i in range(idx_C, N): capacity_C[i] = N
    elif B[idx_B] >= C[idx_C]:
        capacity_C[idx_C] = idx_B
        idx_C += 1
    else:
        idx_B += 1

# print("#", capacity_C)

# num of (Ai, Bi) each Ci can lift
stacked = [0] * N
idx_AB = 0
idx_BC = 0
sum_tmp = 0
for i in range(2 * N):
    if idx_BC == N: break
    elif idx_AB == N:
        for i in range(idx_BC, N): stacked[i] = sum_tmp
    elif idx_AB >= capacity_C[idx_BC]:
        stacked[idx_BC] = sum_tmp
        idx_BC += 1
    else:
        sum_tmp += capacity_B[idx_AB]
        idx_AB += 1

# print("#", stacked)

# the answer is sum of All
print(sum(stacked))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = []
count = 0
for i in range(3):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for x in ar[0]:
    for y in ar[1]:
        if x < y:
            for z in ar[2]:
                if y < z:
                    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[list(map(int,input().split()))for i in range(3)]
c=0
for i in range(n):
    p=s[2][i]
    q=[j for j in s[1] if j<p]
    f=[j for j in s[0] if j<p]
    for a in range(len(q)):
        r=q[a]
        t=[j for j in f if j<r]
        c+=len(t)
print(c)

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 range(N):
    cntA=0
    cntC=0
    for j in range(N):
        if B[i]>A[j]:
            cntA+=1
        if B[i]<C[j]:
            cntC+=1
    ans+=cntA*cntC
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.sort()
b.sort()
c.sort()
bi = [n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if b[i] <= a[j]:
            bi[i] = j
            break
ans = 0
for i in range(n):
    for j in range(n):
        if c[i] <= b[j]:
            break
        else:
            ans += bi[j]
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())))
p = [0]*n
q = [0]*n
k = 0
for i in range(n):
  while k<n:
    if a[k]<b[i]:
      k += 1
    else:
      break
  p[i] = k
k = 0
for i in range(n):
  while k<n:
    if b[k]<c[i]:
      k += 1
    else:
      break
  q[i] = sum(p[:k])
print(sum(q))

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()))
p = [0]*n
q = [0]*n
a.sort()
b.sort()
c.sort()
k = 0
for i in range(n):
  while k<n:
    if a[k]<b[i]:
      k += 1
    else:
      break
  p[i] = k
k = 0
for i in range(n):
  while k<n:
    if b[k]<c[i]:
      k += 1
    else:
      break
  q[i] = sum(p[:k])
print(sum(q))

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)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
for i in range(n):
    while b[j] < c[i]:
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += sum(num_b[:j])

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)

num_b = [0 for _ in range(n)]
for i in range(n):
    num_b[i] = bisect.bisect_left(a, b[i])

ans = 0
for i in range(n):
    ans += sum(num_b[:bisect.bisect_left(b, c[i])])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

N = int(input())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

An.sort()
Bn.sort()
Cn.sort()
#
# print(An)
# print(Bn)
# print(Cn)
#B
B_cnt = []
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            B_cnt.append(N - j)
            break
        else:
            j += 1
# print(B_cnt)

A_cnt = 0
j = 0
for i in range(N):
    while j < N:
        if An[i] < Bn[j]:
            for cnt in B_cnt[j:]:
                A_cnt += cnt
            break
        else:
            j += 1

print(A_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()))
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[N-1-k]:
                    ans += 1
                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()))
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[N-1-k]:
                    ans += 1
                else:
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
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 ci in c:
    j = bisect.bisect_left(b, ci)
    for bi in b[:j]:
        k = bisect.bisect_left(a, bi)
        #print(ci, bi, k, cnt)
        cnt += k
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,B,C = sorted(A),sorted(B),sorted(C)

a_max = N
c_min = 0
ans = 0


for j in range(N):
    b = B[j]

    a_max = bisect.bisect_left(A,b,0,N)
    c_min = bisect.bisect_right(C,b,0,N)



    ans += len(A[:a_max]) * len(C[c_min:])

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
for c in C:
    for b in B:
        if b >= c: break
            
        for a in A:
            if a >= b: break
            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()))
#A = sorted(A)
#B = sorted(B)
C = sorted(C)
answer = 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] :
                    answer += N-(k+1)+1
                    break
print(answer)

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 = sorted(A)
B = sorted(B)
C = sorted(C)
answer = 0
for i in range(N) :
    for j in range(N) :
        if A[i] >= max(B) :
            continue
        elif A[i] < B[j] :
            for k in range(N) :
                if B[j] >= max(C) :
                    continue
                elif B[j] < C[k] :
                    answer += N-(k+1)+1
                    break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] #b(i)の下に置けるcの数
    a_on_b = [] #b(i)の上に置けるaの数

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(len(Cs[i:]))

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(len(As[:i]))

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main3():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    As.sort()
    Bs.sort()
    Cs.sort()
    count = 0
    for c in Cs:
        for b in Bs:
            if c <= b:
                break
            for a in As:
                if b <= a:
                    break
                if c > b > a:
                    count += 1
    print(count)

def main2():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    As.sort()
    Bs.sort()
    Cs.sort()
    count = 0
    for c in Cs:
        for b in Bs:
            if c <= b:
                break
            for a in As:
                if b <= a:
                    break
                if c > b > a:
                    count += 1
    print(count)

def main2():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


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

Submission status: Time Limit Exceeded

Solution code:
#ABC077C
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)
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if i > 0:
        if B[i] == B[i-1]:
            C_under_B[i]=C_under_B[i-1]
            continue
    for j in range(N):
        if C[j]>B[i]:
            C_under_B[i]+=1
        else:       #C[j+1]>C[j]>B[i]なので検討を中止する
            break
#あるAの下にいくつBが入るか数える
B_under_A=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if i > 0:
        if A[i] == A[i-1]:
            B_under_A[i]=B_under_A[i-1]
            continue
    for j in range(N):
        if B[j]>A[i]:
            B_under_A[i]+=1
        else:       #B[j+1]>B[j]>A[i]なので検討を中止する
            break
#あるAのもとに入るBのもとに入るCを数える
C_under_B_under_A=[0]*N
for i in range(N):
    C_under_B_under_A[i]=sum([C_under_B[j] for j in range(B_under_A[i])])
#出力
print(sum(C_under_B_under_A))

Submission status: Time Limit Exceeded

Solution code:
#ABC077C
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)
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    # if j > 0:
    #     if B[i] == B[i-1]:
    #         C_under_B[i]=C_under_B[i-1]
    #         continue
    for j in range(N):
        if C[j]>B[i]:
            C_under_B[i]+=1
        else:       #C[j+1]>C[j]>B[i]なので検討を中止する
            break
#あるAの下にいくつBが入るか数える
B_under_A=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    # if j > 0:
    #     if A[i] == A[i-1]:
    #         B_under_A[i]=B_under_A[i-1]
    #         continue
    for j in range(N):
        if B[j]>A[i]:
            B_under_A[i]+=1
        else:       #B[j+1]>B[j]>A[i]なので検討を中止する
            break
#あるAのもとに入るBのもとに入るCを数える
C_under_B_under_A=[0]*N
for i in range(N):
    C_under_B_under_A[i]=sum([C_under_B[j] for j in range(B_under_A[i])])
#出力
print(sum(C_under_B_under_A))

Submission status: Time Limit Exceeded

Solution code:
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()
c_list.sort()
result = 0
for b in b_list:
    a_count = list(filter(lambda x: x < b, a_list))
    c_count = list(filter(lambda x: x >b, c_list))
    result += len(a_count)*len(c_count)

print(result)

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 binary_search(list,target,b):
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:
            return center+B.count(target) if b else center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1

    if list[center]<target:
        center+=1
    return center

A.sort()
C.sort()
ans=0
for b in B:
    ans+=binary_search(A,b,0)*(len(C)-binary_search(C,b,1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def calc(n,act,lst):
    if lst[-1] < act:
        return n
    if lst[0] > act:
        return 0

    low = 0
    high = n-1
    mid = (low + high)//2
    tmp = -1
    while True:
        if lst[mid] == act:
            return mid
        elif lst[mid] < act:
            low = mid
            mid = (low + high)//2
            if tmp == mid:
                return mid+1
            else:
                tmp = mid

        elif lst[mid] > act:
            high = mid
            mid = (low + high)//2




def main():
    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)

    blist = [0 for i in range(n)]
    ans = 0

    for i in range(n):
        blist[i] = calc(n,b[i],a)

    for i in range(n):
        tmp = calc(n,c[i],b)
        ans += sum(blist[:tmp])



    print(ans)


if __name__ == "__main__":
        main()