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: Runtime Error

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(key, itr):
    idx = bisect.bisect_right(lst[itr], key)
    if memo[itr][idx] < 0:
        memo[itr][idx] = 0
        cur = idx
        #print(itr, key, idx)
        while cur < N:
            if itr > 0:
                memo[itr][idx] += 1
            else:
                memo[itr][idx] += find(lst[itr][cur], itr + 1)
            cur = cur + 1
    return memo[itr][idx]

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

Submission status: Runtime Error

Solution code:
import numpy as np

long = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

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

ble = np.array
for i in range(len(b)):
    for k in range(len(c)):
        if b[i] < c[k]:
            np.append(ble, int(len(c) - k))
            break
for j in range(len(a)):
    for t in range(len(b)):
        if a[j] < b[t]:
            for g in range(ble.shape - t):
                ans += ble[g + t]
                print(ans)
            break
print(ans)

Submission status: Runtime Error

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_1 = 0
count_2 = 0
X = []
for i in range(n):
    for j in range(n):
        if A[i] < B[j]:
            count_1 += 1
            X.append(B[j])
all = n*n
for j in len(X):
    for k in range(n):
        if X[j] < C[k]:
            count_2 += 1
print(count_1 * count_2)

Submission status: Runtime Error

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

As = sorted(As)
Bs = sorted(Bs)
Cs = sorted(Cs)

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

Bs = list(filter(lambda x: x > Amin, Bs))

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

Cs = list(filter(lambda x: x > Bmin, Cs))

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

As = list(filter(lambda x: x < Cmax, As))

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:
                self.result = self.result + len(Clist)               
            else:
                for B in Blist:
                    self.check(Alist, [B], list(filter(lambda x : x > B, Clist)))
        else:
            for A in Alist:
                self.check([A], list(filter(lambda x : x > A, Blist)), list(filter(lambda x : x > A, Clist)))

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

Submission status: Runtime Error

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
	if b<N-1:
		bc[b] += bc[b+1]
	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])
	ans += bc[N-i]

print(ans)

Submission status: Runtime Error

Solution code:
long = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

while min(b) <= min(a):
    b.remove(min(b))
while min(c) <= min(b):
    c.remove(min(c))
while max(b) >= max(c):
    b.remove(max(b))
while max(a) >= max(b):
    a.remove(max(a))
a.sort()
b.sort()
c.sort()

ble = []
for i in range(len(b)):
    for k in range(len(c)):
        if b[i] < c[k]:
            ble.append(int(len(c) - k ))
            break
for j in range(len(a)):
    for t in range(len(b)):
        if a[j] < b[t]:
            for g in range(len(ble) - t):
                ans += ble[g + t]
                print(ans)
            break
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from collections import OrderedDict, deque, Counter
from bisect import bisect_left, bisect_right, insort_left, insort_right
sys.setrecursionlimit(10000)


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

    while B[0] <= A[0]:
        B.popleft()

    while C[0] <= B[0]:
        C.popleft()

    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: Runtime Error

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 i,b in enumerate(B):
    for j,c in enumerate(C):
        if b < c:
            B_list[i] = 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: Runtime Error

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

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


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

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
import sys

num_of_parts = int (raw_input())

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

n = 0 #initialize
for a in A:
    filtered_B = filter(lambda x:x > a, B)
    for b in filtered_B:
        filtered_C = filter(lambda x:x > b, C)
        n += len(filtered_C)

print (n)

Submission status: Runtime Error

Solution code:
#http://abc077.contest.atcoder.jp/
# -*- coding: utf-8 -*-

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

for i,v in enumerate(b[:]):
    if v <= a[0]: b.pop(i)
for i,v in enumerate(c[:]):
    if v <= a[0] or v <= b[0]: c.pop(i)

counter = 0
for av in a:
    for bv in b:
        if bv <= av: continue
        for cv in c:
            if cv <= bv : continue
            counter += 1

print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split())).sort()
B = list(map(int, input().split())).sort()
C = list(map(int, input().split())).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: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math


n = int(input())

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

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

max_middle = max(middles)
tops = list(filter(lambda x: x < max_middle, tops))

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

        for lower in lowers:
            if lower <= middle:
                continue
            
            counter += 1
            
            
print(counter)

Submission status: Runtime Error

Solution code:
#http://abc077.contest.atcoder.jp/
# -*- coding: utf-8 -*-

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

for i,v in enumerate(b[:]):
    if v <= a[0]: b.pop(i)
for i,v in enumerate(c[:]):
    if v <= a[0] or v <= b[0]: c.pop(i)

counter = 0
for ai in a:
    for bi in b:
        if bi <= ai: continue
        for ci in c:
            if ci <= bi : continue
            counter += 1
print(counter)