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 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    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.sort()
    B.sort()
    C.sort()

    lut_A = {a:bisect_right(B, a) for a in A}
    lut_B = {b:bisect_right(C, b) for b in B}

    ans = 0
    old_i = -1
    for a in A:
        i = lut_A[a]

        if i == old_i:
            ans += temp
            continue
        else:
            temp = 0
            for b in B[i:]:
                j = lut_B[b]
                temp += (N - j)
        ans += temp
        old_i = i

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
ind=int(raw_input())
ai=raw_input().split(' ')
bi=raw_input().split(' ')
ci=raw_input().split(' ')
for i in range(ind):
 ai[i]=int(ai[i])
 bi[i]=int(bi[i])
 ci[i]=int(ci[i])
ai=sorted(ai,reverse=True)
bi=sorted(bi,reverse=True)
ci=sorted(ci,reverse=True)
at=ind*[0]
bt=ind*[0]
ct=ind*[0]
for i in range(ind):
 at[i]=at[max(0,i-1)]
 for j in range(at[max(0,i-1)],ind):
  if ai[i]>=bi[j]:break
  at[i]+=1
for i in range(ind):
 bt[i]=bt[max(0,i-1)]
 for j in range(bt[max(0,i-1)],ind):
  if bi[i]>=ci[j]:break
  bt[i]+=1
count=0
for i in range(ind):
 for j in range(at[i]):
  count+=bt[j]
print count

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math
N = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]
a_list.sort()
b_list.sort()
c_list.sort()

a_lt_b_index = [N] * N
i = j = 0
while (i < N and j < N):
    if (a_list[i] < b_list[j]):
        a_lt_b_index[i] = j
        i += 1
    else:
        j += 1

b_lt_c_count = [0] * (N+1)
i = j = 0
while (i < N and j < N):
    if (b_list[i] < c_list[j]):
        b_lt_c_count[i] = N-j
        i += 1
    else:
        j += 1

sum_of_b_lt_c = [sum(b_lt_c_count[i:]) for i in range(N+1)]

print(sum([sum_of_b_lt_c[a_lt_b_index[i]] for i in range(N)]))

Submission status: Time Limit Exceeded

Solution code:
inf=10**9+1

n=int(input())
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])

nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur


nums_c=[0 for _ in range(n)]
cur=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        cur+=1
    nums_c[idx]=sum(nums_b[:cur])
print(sum(nums_c))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math


def calc():
    n = int(input())

    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))

    middles = sorted(middles, reverse=True)
    lowers = sorted(lowers, reverse=True)    

    counter = 0
    for top in tops:
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                counter += 1
                
    return counter

count = calc()
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math


def test(N, A, B, C):
    count = 0
    for i in range(N):
        a = A[i]
        for j in range(N):
            if a < B[j]:
                b = B[j]
                for k in range(N):
                    if b < C[k]:
                        count += (N - k)
                        break
            else:
                break
    return count


if __name__ == "__main__":
    N = int(input())
    A = (input()).split(" ")
    B = (input()).split(" ")
    C = (input()).split(" ")

    A = [int(i) for i in A]
    B = [int(i) for i in B]
    C = [int(i) for i in C]
    A.sort()
    B.sort()
    B.reverse()
    C.sort()

    answer = test(N, A, B, C)
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())

As= list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs= list(map(int, sys.stdin.readline().rstrip().split(" ")))
Cs= list(map(int, sys.stdin.readline().rstrip().split(" ")))

Amin = min(As)
Amax = max(As)

Bmin = min(Bs)
Bmax = max(Bs)

Cmin = min(Cs)
Cmax = max(Cs)

class Solve:
    def __init__(self, Amin, Amax, Bmin, Bmax, Cmin, Cmax):
        self.result = 0
        self.Amin, self.Amax, self.Bmin, self.Bmax, self.Cmin, self.Cmax = Amin, Amax, Bmin, Bmax, Cmin, Cmax
    def check(self, Alist, Blist, Clist):
        if len(Alist) == 1:
            if len(Blist) == 1:
                if len(Clist) == 1:
                    if Blist[0] < Clist[0]:
                        self.result = self.result + 1
                else:
                    for C in Clist:
                        if Blist[0] < C:
                            self.check(Alist, Blist, [C])
            else:
                for B in Blist:
                    if Alist[0] < B and B < self.Cmax:
                        self.check(Alist, [B], Clist)
        else:
            for A in Alist:
                if A < self.Bmax:
                    self.check([A], Blist, Clist)

solve = Solve(Amin, Amax, Bmin, Bmax, Cmin, Cmax)
solve.check(As, Bs, Cs)
print (solve.result)

Submission status: Time Limit Exceeded

Solution code:
def C_SnukeFestival(N, A, B, C):
    a = sorted(A)
    b = sorted(B)
    c = sorted(C)

    l = N
    ans = 0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                if a[i] < b[j] and b[j] < c[k]:
                    ans += 1
    return ans

N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
print(C_SnukeFestival(N, A, B, C))
#間に合いそうもない

Submission status: Time Limit Exceeded

Solution code:
#!/user/bin/python
# coding: UTF-8

N = int(raw_input())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

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

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

print n

Submission status: Time Limit Exceeded

Solution code:
N=input()

A=list(map(int,raw_input().split()))
B=list(map(int,raw_input().split()))
C=list(map(int,raw_input().split()))
A.sort()
B.sort()
C.sort()
#print A
#print B
#print C

sum=0
for i,val_i in enumerate(A):
	for j,val_j in enumerate(B):
		if val_j<=val_i:
			continue
		for k,val_k in enumerate(C):
			#print "# loop C"
			if val_k>val_j:
				#print val_i,val_j,val_k,N-k
				sum+=(N-k)
				break

print sum

Submission status: Time Limit Exceeded

Solution code:
inf=10**9+1
n=int(input())
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])
nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur
nums_c=[0 for _ in range(n)]
cur=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        cur+=1
    nums_c[idx]=sum(nums_b[:cur])
print(sum(nums_c))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
pa,pb,pc=[sorted([int(s)for s in input().split(" ")])for i in range(3)]
pnb,pna,pnas=[[0 for i in range(n)]for j in range(3)]
i=0
while i<n:
    j=0
    while j<n:
        if i>=n:break
        if pa[j]>=pb[i]:
            pna[i]=j
            i+=1
            continue
        j+=1
    if i>=n:break
    pna[i]=n
    i+=1
i=0
while i<n:
    j=0
    while j<n:
        if i>=n:break
        if pb[j]>=pc[i]:
            pnb[i]=j
            i+=1
            continue
        j+=1
    if i>=n:break
    pnb[i]=n
    i+=1
total=0
sum_=0
for i in range(n):
    sum_+=pna[i]
    pnas[i]=sum_
for i in range(n):
    if pnb[i]==0:continue
    total+=pnas[pnb[i]-1]
print(total)

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

tmp = [0 for _ in range(n)]
a.sort()
b.sort()
c.sort()
j = 0
for n, i in enumerate(b):
    hoge = 0
    if j != len(a):
        while(a[j] < i):
            hoge += 1
            j += 1
            if j == len(a):
                break
    if n != 0:
        tmp[n] = tmp[n-1] + hoge
    else:
        tmp[n] = hoge
ans = 0
j = 0
for i in c:
    hoge = 0
    if j != len(a):
        while(b[j] < i):
            j += 1
            if j == len(b):
                break
    ans += sum(tmp[:j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int((input()))

A = []
a = input().split(' ')
for i in a:
    A.append(int(i))

B = []
b = input().split(' ')
for i in b:
    B.append(int(i))

C = []
c = input().split(' ')
for i in c:
    C.append(int(i))

can_make = 0
for upp in range(N):
    for midd in range(N):
        for loww in range(N):
            if A[upp] < B[midd] < C[loww]:
                can_make += 1

print(can_make)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
tmpj = 0
tmpk = 0
for i in range(n):
    flag1 = 0
    tmpk = 0
    for j in range(tmpj, n):
        flag2 = 0
        if a[i] < b[j]:
            if flag1 == 0:
                tmpj = j
                flag1 = 1
            for k in range(tmpk, n):
                if b[j] < c[k]:
                    if flag2 == 0:
                        tmpk = k
                        flag2 = 1
                    ans += n - k
                    break
print (ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
input_A = list(input().split(" "))
input_B = list(input().split(" "))
input_C = list(input().split(" "))

input_A= list(map(int,input_A))
input_B= list(map(int,input_B))
input_C= list(map(int,input_C))


input_A = sorted(input_A) 
input_B = sorted(input_B)
input_C = sorted(input_C) 
ans = 0
for i in range(0,N):
    for j in range(0,N):
        if input_A[i] < input_B[j]:
            for k in range(0,N):
                if input_B[j] < input_C[k]:
                    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math


def calc():
    n = int(input())

    tops = list(map(int, input().split()))
    middles = list(map(int, input().split()))
    lowers = list(map(int, input().split()))

    lowers = sorted(lowers, reverse=True)

    max_lower = max(lowers)
    middles = sorted(list(filter(lambda x: x < max_lower, middles)), reverse=True)

    if middles == []:
        return 0

    max_middle = max(middles)
    tops = sorted(list(filter(lambda x: x < max_middle, tops)), reverse=True)
    
    if tops == []:
        return 0

    counter = 0
    for top in tops:
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                counter += 1
                
    return counter

count = calc()
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math


def test(N, A, B, C):
    count = 0
    for i in range(N):
        a = A[i]
        for j in range(N):
            if a < B[j]:
                b = B[j]
                for k in range(N):
                    if b < C[k]:
                        count += (N - k)
                        break
    return count


if __name__ == "__main__":
    N = int(input())
    A = (input()).split(" ")
    B = (input()).split(" ")
    C = (input()).split(" ")

    A = [int(i) for i in A]
    B = [int(i) for i in B]
    C = [int(i) for i in C]
    A.sort()
    B.sort()
    C.sort()

    answer = test(N, A, B, C)
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
a = int(raw_input())
Ali = np.array( map(int,raw_input().split()))
Bli = np.array(map(int,raw_input().split()))
Cli = np.array(map(int,raw_input().split()))
co=0
for A in Ali:
    for B in Bli:
        if A < B:
            for C in Cli:
                if B < C:
                    co +=1 
print(co)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0

for n in range(N):
    A[n] = int(A[n])
    B[n] = int(B[n])
    C[n] = int(C[n])

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] and B[j] < C[k]:
                m =  m + N - k
                break

print(m)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

    cnt = 0
    for ele in list((itertools.product(A, B, C))):
        if ele[0] < ele[1] < ele[2]:
            cnt += 1

    print(cnt)

 
solve()

Submission status: Time Limit Exceeded

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

N=int(input())
A=input().split()
B=input().split()
C=input().split()

count=0

for i in range(0, N):
	for j in range(0, N):
		for k in range(0, N):
			# print(A[i],B[j],C[k])
			if(int(A[i])<int(B[j]) and int(B[j])<int(C[k])):
				# print("-",A[i],B[j],C[k])
				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()))

Bcon = [sum([1 for i in A if i < B[j]]) for j in range(N)]
Ccon = [sum([Bcon[n] for n, i in enumerate(B) if i < C[j]]) for j in range(N)]

print(sum(Ccon))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    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.sort()
    B.sort()
    C.sort()

    lut_A = {}
    for a in A:
        j = bisect_right(B, a)
        lut_A[a] = j

    lut_B = [0] * N
    for i, b in enumerate(B):
        j = bisect_right(C, b)
        lut_B[i] = N-j

    ans = 0

    for a in A:
        i = lut_A[a]
        ans += sum(lut_B[i:])

    print(ans)



if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

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


def extract(M):
    Md = []
    Mc = []
    for m in M:
        if m in Md:
            Mc[Md.index(m)] += 1
        else:
            Md.append(m)
            Mc.append(1)
    return Md, Mc


Ad, Ac = extract(A)
Bd, Bc = extract(B)
Cd, Cc = extract(C)

result = 0
for i, c in enumerate(Cd):
    for j, b in enumerate(Bd):
        if b < c:
            for k, a in enumerate(Ad):
                if a < b:
                    result += Cc[i] * Bc[j] * Ac[k]
                else:
                    break
        else:
            break

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

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


# def smaller_than_b(ai):
#     blist = [1 if ai < bi else 0 for bi in b]
#     return sum(blist)


# def smaller_than_c(bi):
#     clist = [1 if bi < ci else 0 for ci in c]
#     return sum(clist)


# alist = [smaller_than_b(ai) for ai in a]
alist = [sum(list(map(lambda bi: 1 if ai < bi else 0, b))) for ai in a]
# blist = [smaller_than_c(bi) for bi in b]
blist = [sum(list(map(lambda ci: 1 if bi < ci else 0, c))) for bi in b]

# sum(list(map(lambda ai: 1 if ai < bi else 0, b)))

print(sum([sum([blist[j] for j in range(alist[i])]) for i in range(N)]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
a = int(raw_input())
Ali = np.array( map(int,raw_input().split()))
Bli = np.array(map(int,raw_input().split()))
Cli = np.array(map(int,raw_input().split()))
co=0
for i1 in range(a):
    for i2 in range(a):
        if Ali[i1] < Bli[i2]:
            for i3 in range(a):
                if Bli[i2] < Cli[i3]:
                    co +=1 
print(co)

Submission status: Time Limit Exceeded

Solution code:
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())))
 
ans = 0
for c in Cs:
    i = bisect.bisect_left(Bs, c)
    for b in Bs[:i]:
        ans += bisect.bisect_left(As, b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(n):
        if a[i] < b[j]:
            for k in range(n):
                if b[j] < c[k]:
                    ans += n - k
                    break
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

counts = 0
products = itertools.product(A, B, C)
for product in products:
    if(product[0] < product[1] and product[1] < product[2]):
        counts += 1
print(counts)

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 x in range(n):
  for y in range(n):
    for z in range(n):
      if a[x] < b[y]:
        if b[y] < c[z]:
          count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def binary_search(array, num):
    if array[-1] <= num:
        return -1
    left = -1
    right = len(array)-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A.sort()
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B.sort()
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C.sort()

for a in A:
    a_index.append(binary_search(B, a))

    
for b in B:
    b_index.append(binary_search(C, b))

    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    for b_i in b_index[a_i:]:
        res += (N - b_i)
print(str(res))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N=int(input())
cnt=0
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
for i in range(N):#１行目
    for j in range(N):#２行目
        if lb[j]>la[i]:
            for k in range(N):#３行目
                if lc[k]>lb[j]:
                    cnt=cnt+1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = input()

A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_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 C[k]>B[j]:
                    count+=1
print count

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math


def test(N, A, B, C):
    count = 0
    for i in range(N):
        a = A[i]
        for j in range(N):
            if a < B[j]:
                b = B[j]
                for k in range(N):
                    if b < C[k]:
                        count += 1
    return count


if __name__ == "__main__":
    N = int(input())
    A = (input()).split(" ")
    B = (input()).split(" ")
    C = (input()).split(" ")

    A = [int(i) for i in A]
    B = [int(i) for i in B]
    C = [int(i) for i in C]

    answer = test(N, A, B, C)
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np
import copy as cp

N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = np.sort(np.array([int(i) for i in A]))[::-1]
B = np.sort(np.array([int(i) for i in B]))[::-1]
C  =np.sort(np.array([int(i) for i in C]))[::-1]

dp = np.array([])
s = 0
for b in B :
    c = C[b < C]
    if len(c) > 0 : 
        C = C[-(b < C)]
    s = s + len(c)
    dp = np.append(dp , s)

s = 0
rst = []
for a in A : 
    b = dp[a < B]
    if len(b) > 0 : 
        dp = dp[-(a < B)]
        B = B[-(a < B)]
    s = s + sum(b)
    rst.append(s)
print(int(sum(rst)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

bc = []
countb = 0
while(countb < n):
    bc.append(sum(c > b[countb]))
    countb+=1

bc = np.array(bc)
ab = []
counta = 0
while(counta < n):
    ab.append(sum(bc*(b>a[counta])))
    counta+=1

print(sum(ab))

Submission status: Time Limit Exceeded

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


def extract(M):
    Md = []
    Mc = []
    for m in M:
        try:
            f = Md.index(m)
            Mc[f] += 1
        except ValueError:
            Md.append(m)
            Mc.append(1)
    return Md, Mc


Ad, Ac = extract(A)
Bd, Bc = extract(B)
Cd, Cc = extract(C)

result = 0
for i, c in enumerate(Cd):
    for j, b in enumerate(Bd):
        if b < c:
            for k, a in enumerate(Ad):
                if a < b:
                    result += Cc[i] * Bc[j] * Ac[k]
                else:
                    break
        else:
            break

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0

for n in range(N):
    A[n] = int(A[n])
    B[n] = int(B[n])
    C[n] = int(C[n])

for i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i] < B[j] and B[j] < C[k]:
                m =  m + 1

print(m)

Submission status: Time Limit Exceeded

Solution code:
ind=int(raw_input())
ai=raw_input().split(' ')
bi=raw_input().split(' ')
ci=raw_input().split(' ')
for i in range(ind):
 ai[i]=int(ai[i])
 bi[i]=int(bi[i])
 ci[i]=int(ci[i])
ai=sorted(ai,reverse=True)
bi=sorted(bi,reverse=True)
ci=sorted(ci,reverse=True)
at=ind*[0]
bt=ind*[0]
ct=ind*[0]
for i in range(ind):
 for j in range(ind):
  if ai[i]>=bi[j]:break
  at[i]+=1
for i in range(ind):
 for j in range(ind):
  if bi[i]>=ci[j]:break
  bt[i]+=1
count=0
for i in range(ind):
 for j in range(at[i]):
  count+=bt[j]
print count

Submission status: Time Limit Exceeded

Solution code:
def solve():
    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_cand = [0 for i in range(N)]
    B_cand = [0 for i in range(N)]
    for i in range(N):
        cnt = 0
        for j in range(N):
            if B[i] < C[N-j-1]:
                cnt += 1
            else:
                break
        B_cand[i] = cnt
    
    for i in range(N):
        cnt = 0
        for j in range(N):
            if A[i] < B[N-j-1]:
                cnt += B_cand[N-j-1]
            else:
                break
        A_cand[i] = cnt
    print(sum(A_cand))
    

solve()

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())

As= sys.stdin.readline().rstrip().split(" ")
Bs= sys.stdin.readline().rstrip().split(" ")
Cs= sys.stdin.readline().rstrip().split(" ")

class Solve:
    def __init__(self):
        self.result = 0
    def check(self, Alist, Blist, Clist):
        if len(Alist) == 1:
            if len(Blist) == 1:
                if len(Clist) == 1:
                    if int(Blist[0]) < int(Clist[0]):
                        self.result = self.result + 1
                else:
                    for C in Clist:
                        if int(Blist[0]) < int(C):
                            self.check(Alist, Blist, [C])
            else:
                for B in Blist:
                    if int(Alist[0]) < int(B):
                        self.check(Alist, [B], Clist)
        else:
            for A in Alist:
                self.check([A], Blist, Clist)

solve = Solve()
solve.check(As, Bs, Cs)
print (solve.result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = 0

for i in range(n):
    for j in range(n):
            for k in range(n):
                if a[i] < b[j] < c[k]:
                    ans = 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.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)


def smaller_than_b(ai):
    blist = [1 if ai < bi else 0 for bi in b]
    return sum(blist)


def smaller_than_c(bi):
    clist = [1 if bi < ci else 0 for ci in c]
    return sum(clist)


alist = [smaller_than_b(ai) for ai in a]
blist = [smaller_than_c(bi) for bi in b]

# ans = 0
# for i in range(N):
#     l = sum([sum([blist[j] for j in range(alist[i])]) for i in range(N)])
#     ans += sum(l)

print(sum([sum([blist[j] for j in range(alist[i])]) for i in range(N)]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    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.sort()
    B.sort()
    C.sort()

    lut_A = {}
    for a in A:
        j = bisect_right(B, a)
        lut_A[a] = j

    lut_B = {}
    for b in B:
        j = bisect_right(C, b)
        lut_B[b] = j

    ans = 0

    for a in A:
        # i = bisect_right(B, a)
        i = lut_A[a]
        if i == N:
            continue
        for b in B[i:]:
            # j = bisect_right(C, b)
            j = lut_B[b]
            if j == N:
                continue
            ans += (N-j)

    print(ans)



if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
a = 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()])

B_hash = defaultdict(int)
for i,b in enumerate(B):
    for c in C[::-1]:
        if b < c:
            B_hash[str(i)] += 1
        else:
            break

res = 0
for a in A:
    for j,b in enumerate(B[::-1]):
        if a < b:
            res += B_hash[str(len(B)-j-1)]
        else:
            break
print(res)

Submission status: Time Limit Exceeded

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

ans = 0
for c in Cs:
    i = bisect.bisect_left(Bs, c)
    for b in Bs[:i]:
        ans += bisect.bisect_left(As, b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    C = tuple(map(int, input().split()))

    cnt = 0
    for c in C:
        b = [i for i in B if i < c]
        lenb = len(b)
        if not lenb:
            continue
        for bi in b:
            a = [i for i in A if i < bi]
            lena = len(a)
            if not lena:
                continue
            else:
                cnt += lena

    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
A = input()
B = input()
C = input()
a = sorted([int(i) for i in A.split()])
b = sorted([int(i) for i in B.split()])
c = sorted([int(i) for i in C.split()])

ans = 0
for i in b:
    a_small = len([x for x in a if x < i])
    c_large = len([x for x in c if x > i])
    ans += a_small * c_large
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()))


def extract(M):
    Md = []
    Mc = []
    for m in M:
        try:
            f = Md.index(m)
            Mc[f] += 1
        except ValueError:
            Md.append(m)
            Mc.append(1)
    return Md, Mc


Ad, Ac = extract(A)
Bd, Bc = extract(B)
Cd, Cc = extract(C)

result = 0
for i, c in enumerate(Cd):
    for j, b in enumerate(Bd):
        if b < c:
            for k, a in enumerate(Ad):
                if a < b:
                    result += Cc[i] * Bc[j] * Ac[k]

print(result)