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:
import numpy as np

N = int(input())
A = np.sort(np.array(list(map(int, input().split()))))
B = np.sort(np.array(list(map(int, input().split()))))
C = np.sort(np.array(list(map(int, input().split()))))


def extract(M):
    Md = np.array([])
    Mc = np.array([])
    for m in M:
        if m in Md:
            Mc[np.where(Md == m)] += 1
        else:
            Md = np.append(Md, m)
            Mc = np.append(Mc, 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[Bd < c]):
        result += sum([(Cc[i] * Bc[j] * Ac[k]) for k in range(len(Ad[Ad < b]))])
    # result += sum([((Cc[i] * Bc[j] * Ac[k]) for k in range(len(Ad[Ad < b]))) for j, b in enumerate(Bd[Bd < c])])

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
a = sorted(map(int, input().split()))
lst = [sorted(map(int, input().split())), sorted(map(int, input().split()))]
memo = [[-1] * N, [-1] * N]

def find(i, key, itr):
    memo[itr][i] = 0
    idx = bisect.bisect_right(lst[itr], key)
    while idx < N:
        if itr > 0:
            memo[itr][i] += 1
        elif memo[itr + 1][idx] < 0:
            memo[itr][i] += find(idx, lst[itr][idx], itr + 1)
        else:
            memo[itr][i] += memo[itr + 1][idx]
        idx = idx + 1
    return memo[itr][i]

print(sum(find(i, aa, 0) for i, aa in enumerate(a)))

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

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:
# -*- 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
from functools import lru_cache
input = stdin.readline


@lru_cache(maxsize=None)
def calc(i):
    ans = 0
    for b in B[i:]:
        j = lut_B[b]
        if j == N:
            break
        ans += (N - j)
    return ans


lut_B = {}
B = []
N = 0
def main(args):
    global lut_B
    global B
    global N
    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
    for a in A:
        i = lut_A[a]
        if i == N:
            break
        ans += calc(i)

    print(ans)


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
B = input().split()
C = input().split()
result = 0
for a, b, c in [[a, b, c] for a in A for b in B for c in C]:
  if int(a) < int(b) < int(c):
    result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
a = sorted(map(int, input().split()))
lst = [sorted(map(int, input().split())), sorted(map(int, input().split()))]
memo = [[-1] * N, [-1] * N]

def find(i, key, itr):
    if memo[itr][i] < 0:
        memo[itr][i] = 0
        idx = bisect.bisect_right(lst[itr], key)
        while idx < N:
            if itr > 0:
                memo[itr][i] += 1
            else:
                memo[itr][i] += find(idx, lst[itr][idx], itr + 1)
            idx = idx + 1
    return memo[itr][i]

print(sum(find(i, aa, 0) for i, aa in enumerate(a)))

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):
        if A[i] >= B[j]:
            continue
        for k in range(N):
            if B[j] < C[k]:
                m =  m + 1

print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    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 = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

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:
import bisect
N = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
lst = [b, c]
memo = [[-1] * N, [-1] * N]

def find(i, key, itr):
    if memo[itr][i] < 0:
        memo[itr][i] = 0
        idx = bisect.bisect_left(lst[itr], key)
        while idx < N:
            if lst[itr][idx] > key:
                if itr > 0:
                    memo[itr][i] += 1
                else:
                    memo[itr][i] += find(idx, lst[itr][idx], itr + 1)
            idx = idx + 1
    return memo[itr][i]

print(sum(find(i, aa, 0) for i, aa in enumerate(a)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cand1 = [0 for i in range(n)]
cand2 = [0 for i in range(n)]
for j in range(n):
    for i in range(n-1, -1, -1):
        if a[i] < b[j]:
            cand1[j] += i + 1
            break
for j in range(n):
    for k in range(n):
        if b[j] < c[k]:
            cand2[j] += n - k
            break
ans = sum(np.array(cand1) * np.array(cand2))
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

def get_Num():
    return int(raw_input())

def get_parts_list():
    line = raw_input()
    array = map(int, line.split())
    return array


Num = get_Num()
array_top = get_parts_list()
array_mid = get_parts_list()
array_btm = get_parts_list()

array_top.sort()
array_mid.sort()
array_btm.sort()
array_top.reverse()
array_mid.reverse()
array_btm.reverse()

p_dbg(str(Num))
p_dbg(array_top)
p_dbg(array_mid)
p_dbg(array_btm)

comb = 0

for item_b in array_btm:
    for item_m in array_mid:
        for item_t in array_top:
            p_dbg(str(item_b)+':'+str(item_m)+':'+str(item_t))
            if((item_b > item_m) and (item_m > item_t)):
                comb = comb + 1
    
print comb

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
lst = [b, c]
memo = [[-1] * N, [-1] * N]

def find(i, key, itr):
    if itr > 1:
        return 1
    if memo[itr][i] < 0:
        memo[itr][i] = 0
        idx = bisect.bisect_left(lst[itr], key)
        while idx < N:
            if lst[itr][idx] > key:
                memo[itr][i] += find(idx, lst[itr][idx], itr + 1)
            idx = idx + 1
    return memo[itr][i]

print(sum(find(i, aa, 0) for i, aa in enumerate(a)))

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):
        if A[i] >= B[j]:
            continue
        for k in range(N):
            if B[j] < C[k]:
                m =  m + N - k
                break

print(m)

Submission status: Time Limit Exceeded

Solution code:
num=int(raw_input())
row1=map(int, raw_input().split(" "))
row2=map(int, raw_input().split(" "))
row3=map(int, raw_input().split(" "))
#print row1
row1.sort()
row1.reverse()
row2.sort()
row2.reverse()
row3.sort()
row3.reverse()


#dict2={}
count=0
for l in row1:
    for i in row2:
        if l>=i:
            break
        for k in row3:
            if i<k:
                count+=1
            else:
                break
print count

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())))
Ali = np.sort(Ali)
Bli = np.sort(Bli)[::-1]
Cli = np.sort(Cli)[::-1]
co=0
for A in Ali:
    if A >= Bli[0]:
        break
    for B in Bli:
        if A >= B:
            break
        for C in Cli:
            if B >= C:
                break
            co +=1 
print(co)

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
dp = [[0]*N for _ in range(2) ]

for i in range(N):
    for j in range(N):
        if A[i]<B[j]:
            dp[0][i] = j
            break
    else:
        dp[0][i] = N


for i in range(N):
    for j in range(N):
        if C[j]==N:
            break
        if B[i]<C[j]:
            dp[1][i] = j
            break
    else:
        dp[0][i] = N

for i in range(N):
    t = dp[0][i]
    while(t<N):
        ans +=  (N-dp[1][t])
        t += 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()
b.sort()
c.sort()
a.reverse()
b.reverse()
c.reverse()

cnt = 0
for i in a:
    for j in b:
        if j <= i:
            break
        for k in c:
            if k <= j:
                break
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

counter = 0

for a in A:
    for b in B:
        if a < b:
            for c in C:
                if b < c:
                    counter = counter + 1
                else:
                    pass
        else:
            pass

print(counter)

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
from functools import lru_cache
input = stdin.readline



@lru_cache(maxsize=None)
def calc(i):
    ans = 0
    for b in B[i:]:
        j = lut_B[b]
        ans += (N - j)
    return ans


lut_B = {}
B = []
N = 0
def main(args):
    global lut_B
    global B
    global N
    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
    for a in A:
        i = lut_A[a]
#        for b in B[i:]:
#            j = lut_B[b]
#            temp += (N - j)
        ans += calc(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]
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=sum(bt)*ind
for i in range(ind):
  count-=sum(bt[at[i]:])
print count

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 numpy as np
import copy as cp
 
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = np.array(sorted([int(i) for i in A] , reverse = True))
B =  np.array(sorted([int(i) for i in B] , reverse = True))
C = np.array([int(i) for i in C])

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

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 + (N - k)
                    break
print n

Submission status: Time Limit Exceeded

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

"""077-c"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(input())

    As = sorted(list(map(int, input().split(' '))))
    Bs = sorted(list(map(int, input().split(' '))))
    Cs = sorted(list(map(int, input().split(' '))))

    As_start_pos = [-1] * N
    Bs_start_pos = [-1] * N

    count = 0
    for idx_a, a in enumerate(As):
        if idx_a == 0:
            idx_a_ = 0
        else:
            idx_a_ = idx_a - 1
        if As_start_pos[idx_a_] == -1:
            pos_a = 0
        else:
            pos_a = As_start_pos[idx_a_]
        for idx_b, b in enumerate(Bs[pos_a:]):
            if a >= b:
                continue
            if idx_b == 0:
                idx_b_ = 0
            else:
                idx_b_ = idx_b - 1
            if As_start_pos[idx_a] == -1:
                As_start_pos[idx_a] = idx_b + pos_a
            if Bs_start_pos[idx_b_] == -1:
                pos_b = 0
            else:
                pos_b = Bs_start_pos[idx_b_]
            for idx_c, c in enumerate(Cs[pos_b:]):
                if b >= c:
                    continue
                else:
                    if Bs_start_pos[idx_b] == -1:
                        Bs_start_pos[idx_b] = idx_c + pos_b
                    count += len(Cs[pos_b:]) - idx_c
                    break

    print(count)




if __name__ == '__main__':
    sys.exit(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.sort(np.array(list(map(int, input().split()))))
B = np.sort(np.array(list(map(int, input().split()))))
C = np.sort(np.array(list(map(int, input().split()))))


def extract(M):
    Md = np.array([])
    Mc = np.array([])
    for m in M:
        if m in Md:
            Mc[np.where(Md == m)] += 1
        else:
            Md = np.append(Md, m)
            Mc = np.append(Mc, 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[Bd < c]):
            for k, a in enumerate(Ad[Ad < b]):
                    result += Cc[i] * Bc[j] * Ac[k]

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

partA = list(map(int, input().split()))
partB = list(map(int, input().split()))
partC = list(map(int, input().split()))
counter = 0

for i in range(N):
     for f in range(N):
         if partA[i] < partB[f]:
                for s in range(N):
                    if partB[f] < partC[s]:
                        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

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

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
	ans += sum(bc[N-i:N])

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

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

    d = {}
    counter = 0
    for top in tops:
        if top in d.keys():
            counter += d[top]
            continue

        c = 0
        for middle in middles:
            if middle <= top:
                break

            for lower in lowers:
                if lower <= middle:
                    break
                
                c += 1
                
        d[top] = c
        counter += c
    
    return counter

count = calc()
print(count)

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())))
Bli = np.sort(Bli)[::-1]
Cli = np.sort(Cli)[::-1]
co=0
for A in Ali:
    for B in Bli:
        if A >= B:
            break
        for C in Cli:
            if B >= C:
                break
            co +=1 
print(co)

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

Bcon = [0] * N
res = 0
p = 0
for n in range(N):
    while p <= N - 1 and B[n] > A[p]:
        p += 1
    Bcon[n] = p

p = 0
for n in range(N):
    while p <= N - 1 and C[n] > B[p]:
        p += 1
    res += sum(Bcon[:p])
    
print(res)

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 = np.zeros(n)
countb = 0
while(countb < n):
    bc[countb]=(sum(c > b[countb]))
    countb+=1

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

print(int(sum(ab)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.sort(np.array(list(map(int, input().split()))))
B = np.sort(np.array(list(map(int, input().split()))))
C = np.sort(np.array(list(map(int, input().split()))))


def extract(M):
    Md = np.array([])
    Mc = np.array([])
    for m in M:
        if m in Md:
            Mc[np.where(Md == m)] += 1
        else:
            Md = np.append(Md, m)
            Mc = np.append(Mc, 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(int(result))

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 in range(N):
	j_start=0
	for j in range(N):
		if B[j]<=A[i]:
			continue
		for k in range(j_start,N):
			#print "# loop C"
			#print A[i],B[j],C[k],N-k
			if C[k]>B[j]:
				#print A[i],B[j],C[k],N-k
				sum+=(N-k)
				j_start=k
				break

print sum

Submission status: Time Limit Exceeded

Solution code:
r = 0
n = input()
a = map(int, input().split(' '))
b = map(int, input().split(' '))
c = map(int, input().split(' '))

a = sorted(a)
b = sorted(b)
c = sorted(c)

for x in a:
    if x>=b[0]:
        pass
    for y in b:
        if y>=c[0]:
            pass
        if y>x:
            for z in c:
                if z>y:
                    r += 1
                else:
                    pass

print(r)

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):
        if a[i]  < b[j]:
            for h in range(n):
                if b[j] < c[h]:
                    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
top = map(int, raw_input().split())
top.sort()
middle = map(int, raw_input().split())
middle.sort()
under = map(int, raw_input().split())
under.sort()
cnt = 0
for i in top[::-1]:
    for j in middle[::-1]:
        if j <= i: break
        for k in under[::-1]:
            if k <= j: break
            cnt += 1
            # print '{} {} {}'.format(i,j,k)

print cnt

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


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 -*-
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
result = 0
for num1 in range(n):
    for num2 in range(n):
        for num3 in range(n):
            if A[num1]<B[num2] and B[num2] < C[num3]:
                result = result +1
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()))

counter = 0

for a in A:
    for b in B:
        if a < b:
            for c in C:
                if b < c:
                    counter = counter + 1
                else:
                    counter = counter
        else:
            counter = counter

print(counter)

Submission status: Time Limit Exceeded

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

N = input()

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

for i, j, k in itertools.product(range(N), range(N), range(N)):
    if A[i]<B[j] and B[j]<C[k]:
            cnt+=1
    else:
        continue
print cnt

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 numpy as np
import copy as cp
 
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = np.array(sorted([int(i) for i in A] , reverse = True))
B =  np.array(sorted([int(i) for i in B] , reverse = True))
C  = np.array(sorted([int(i) for i in C] , reverse = True))
 
dp = np.array([])
s = 0
for b in B :
    ind = b < C
    c = C[ind]
    if len(c) > 0 : 
        C = C[-(ind)]
    s = s + len(c)
    dp = np.append(dp , s)
 
s = 0
rst = []
for a in A : 
    ind = a<B
    b = dp[ind]
    if len(b) > 0 : 
        dp = dp[-(ind)]
        B = B[-(ind)]
    s = s + sum(b)
    rst.append(s)
print(int(sum(rst)))

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

B_list = []
for b in B:
    for j,c in enumerate(C):
        if b < c:
            B_list.append(len(C)-j)
            break

res = 0
for i,b in enumerate(B):
    for a in A:
        if a < b:
            res += B_list[i]
print(res)

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

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:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # a<b<c となる並べ方の数
    # b<c となる並べ方の数、１つずつに対してN個調べるO(N^2) => すでにOver => pypy
    # b M個となったとき (b_c_i - b_c_m) を保持する
    # a<b となる並べ方の数、１つずつに対してN個調べるO(M*N)
    # b L個となったとき (b_a_i - b_a_m) を保持する (b_cと対応付ける)

    ans = 0
    for b in B:
        less_b_count = sum(1 for a in A if a < b)
        if less_b_count > 0:
            over_b_count = sum(1 for c in C if b < c)
            ans += less_b_count * over_b_count

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
num=int(raw_input())
row1=map(int, raw_input().split(" "))
row2=map(int, raw_input().split(" "))
row3=map(int, raw_input().split(" "))
#print row1
row1.sort()
row1.reverse()
row2.sort()
row2.reverse()
row3.sort()
row3.reverse()

dict2={}
for i in row2:
    count=0
    for k in row3:
        #print "i",i
        #print "k",k
        if i<k:
            count+=1
        else:
            break
    dict2[i]=count

#print dict2

result=0
for l in row1:
    for l2 in row2:
        if l<l2:
            result+=dict2[l2]
        else:
            break

print result

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 numpy as np
import copy as cp
 
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = np.array(sorted([int(i) for i in A] , reverse = True))
B =  np.array(sorted([int(i) for i in B] , reverse = True))
C  = np.array(sorted([int(i) for i in C] , reverse = True))
 
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:
# 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:
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()]

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

N = input()

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

for i, j, k in itertools.product(range(N), range(N), range(N)):
    if A[i]<B[j]<C[k]:
            cnt+=1
    else:
        continue
print cnt