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: Wrong Answer

Solution code:
import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-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))

bb = list(map(lambda x: N-x, b_index))

bbb = []
tmp = np.sum(bb)
for i in range(N):
    bbb.append(tmp)
    tmp = tmp - bb[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bbb[a_i]
print(str(res))

Submission status: Wrong Answer

Solution code:
import sys

num_of_parts = int (input())

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

print (n)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
b = input().split()
c = input().split()
x = N ** 3
for i in range(N-1):
  for j in range(N-1):
    if a[i] < b[j+1]:
      continue

    else:
      x -= 1
      continue

for i in range(N-1):
  for j in range(N-1):
    if b[i] < c[j+1]:
      continue

    else:
      x -= 1
      continue

print(x)

Submission status: Wrong Answer

Solution code:
r = 0
n = int(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, reverse=True)

for x in a:
    if x<b[0]:
        for y in b:
            if y>x:
                i = 0
                while y<c[i] and i<n-1:
                    i += 1

                r += i
print(r)

Submission status: Wrong Answer

Solution code:
n = range(int(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
counter = 0
a.sort()
b.sort()
c.sort()
d = [0 for i in range(int(len(n)))]
for y in n:
    for z in n:
        if b[y] <= c[z]:
            d[int(y)]= len(n) - int(z)
            break
for x in n:
    for y in n:
        if a[x] <= b[y]:
            counter += d[y]
print(counter)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = input().split()
B = input().split()
C = input().split()
A = [int(i) for i in A]
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)

Submission status: Wrong Answer

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

bb = list(map(lambda x: N-x, b_index))

bbb = []
tmp = np.sum(bb)
for i in range(N):
    bbb.append(tmp)
    tmp = tmp - bb[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bbb[a_i]
print(str(res))

Submission status: Wrong Answer

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

bb = list(map(lambda x: N-x, b_index))

bbb = []
for i in range(N):
    tmp = np.sum(bb)
    bbb.append(tmp)
    tmp = tmp - bb[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bbb[a_i]
print(str(res))

Submission status: Wrong Answer

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

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: Wrong Answer

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(a, b, c)
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

bb = []
for i in range(N):
    bb.append(np.sum(b_index[i:]))

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

Submission status: Wrong Answer

Solution code:
import sys

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

bb = []
for i in range(N):
    bb.append(sum(b_index[i:]))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ctgry = 3
for i in range(ctgry):
    if i == 0:
        a = input().split()
    elif i == 1:
        b = input().split()
    else:
        c = input().split()

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

Submission status: Wrong Answer

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

counts = 0
checked = {}
for _numB in B:
    if _numB in checked:
        counts += checked[_numB]
    else:
        countsA = 0
        countsC = 0
        for _numA, _numC in zip(A, C):
            if _numA < _numB:
                countsA += 1
            if _numB < _numC:
                countsC += 1
        checked[_numB] = countsA * countsC
        counts += countsA * countsC
print(counts)

Submission status: Wrong Answer

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 a < b and b < c:
    result += 1
print(result)

Submission status: Wrong Answer

Solution code:
import sys

num_of_parts = int (input())

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

print (n)

Submission status: Wrong Answer

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=0
print at,bt
for i in range(ind):
  count+=sum(bt[:at[i]])
print count

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
    break
print cnt

Submission status: Wrong Answer

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
res=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        cur+=1
    res+=nums_b[cur-1]*(n-idx)
print(sum(nums_c))

Submission status: Wrong Answer

Solution code:
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 = [dict(), dict()]

def find(key, itr):
    if itr > 1:
        return 1
    if key not in memo[itr]:
        memo[itr][key] = 0
        for val in lst[itr]:
            if val < key:
                continue
            memo[itr][key] += find(val, itr + 1)
    return memo[itr][key]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
for a in A:
    for b in B:
        if a>b:
            break
        for c in C:
            if a<b<c or a<=b<c or a<b<=c:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted(list(set(list(map(int, input().split())))))
b = sorted(list(set(list(map(int, input().split())))))
c = sorted(list(set(list(map(int, input().split())))))
lst = [b, c]
memo = [dict(), dict()]

def find(key, itr):
    if itr > 1:
        return 1
    if key not in memo[itr]:
        memo[itr][key] = 0
        for val in lst[itr]:
            if val < key:
                continue
            memo[itr][key] += find(val, itr + 1)
    return memo[itr][key]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
aL = input().split()
bL = input().split()
cL = input().split()

count = 0
for a in aL:
    a = int(a)
    for b in bL:
        b = int(b)
        if a >= b: continue
        for c in cL:
            c = int(c)
            if b >= c: continue
            print(a, b, c)
            count = count + 1

print(count)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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 A:
    for	j in B:
        if i <=	j:
            for	k in C:
                if j <=	k:
                    count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
for a in A:
    for b in B:
        if a>=b:
            break
        for c in C:
            if b>=c:
                break
            if a<b<c:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

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 cnt

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
import itertools
N = int(input())
A = input().split()
B = input().split()
C = input().split()
result = 0
for a in A:
  for b in B:
    if a > b:
      continue
    for c in C:
      if b < c:
        result += 1
print(result)

Submission status: Wrong Answer

Solution code:
n = range(int(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
counter = 0
for x in n:
    for y in n:
        if a[x] <= b[y]:
            for z in n:
                if b[y] <= c[z]:
                    counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
for a in A:
    for b in B:
        if a>=b:
            break
        for c in C:
            if b>=c:
                break
            if a<b<c and len(set([a, b, c]))>1:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

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]:
            break
        else:
            for k in range(N):#３行目
                if lc[k]>lb[j]:
                    cnt=cnt+1
print(cnt)

Submission status: Wrong Answer

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)
bi=sorted(bi,reverse=True)
ci=sorted(ci,reverse=True)
ct=0
print ai,bi,ci
for a in ai:
 for b in bi:
  if a>=b:break
  for c in ci:
   if b>=c:break
   ct+=1
   print a,b,c
print ct

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)
bi=sorted(bi)
ci=sorted(ci)
ct=0
for a in ai:
 for b in bi:
  if a>=b:break
  for c in ci:
   if b>=c:break
   ct+=1
   print a,b,c
print ct

Submission status: Wrong Answer

Solution code:
n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
for a in A:
    for b in B:
        if a>b:
            break
        for c in C:
            if b>c:
                break
            if a<b<c and len(set([a, b, c]))>1:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Time Limit Exceeded

Solution code:
#
# abc077 c
#
import sys
from io import StringIO
import unittest
import bisect


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 5
2 4
3 6"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
1 1 1
2 2 2
3 3 3"""
        output = """27"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
        output = """87"""
        self.assertIO(input, output)


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

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

    ans = 0
    for a in A:
        if a >= B[-1]:
            break
        bi = bisect.bisect(B, a)
        BT = B[bi:]
        for b in BT:
            if b >= C[-1]:
                break
            ans += len(C) - bisect.bisect(C, b)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

Solution code:
#
# abc077 c
#
import sys
from io import StringIO
import unittest
import bisect


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 5
2 4
3 6"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
1 1 1
2 2 2
3 3 3"""
        output = """27"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
        output = """87"""
        self.assertIO(input, output)


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

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

    ans = 0
    for a in A:
        bi = bisect.bisect(B, a)
        BT = B[bi:]
        for b in BT:
            ans += len(C) - bisect.bisect(C, b)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

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

ans = 0

for a in A:
    i = bisect(B, a)
    for b in B[i:]:
        j = bisect(C, b)
        ans += N - j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
 
N=int(input())
b1=0

ans=0
 
A=list(map(int, input().split()))
A=sorted(A)
B=list(map(int, input().split()))
B=sorted(B)
C=list(map(int, input().split()))
C=sorted(C)
D=[]

for b in B:
  D.append(len(C)-bisect.bisect_right(C,b))

B.append(math.inf)

for i in range(len(A)):
  b1=bisect.bisect_right(B,A[i])
  for j in range(b1,len(B)-1):
    ans += D[j]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
 
N=int(input())
a1=0
a2=0
b1=0
b2=0
c1=0
c2=0
c3=0
 
ans=0
 
A=list(map(int, input().split()))
A=sorted(A)
B=list(map(int, input().split()))
B=sorted(B)
B.append(math.inf)
C=list(map(int, input().split()))
C=sorted(C)
C.append(math.inf)
for i in range(len(A)):
  a1=A[i]
  b2=bisect.bisect_right(B,a1)
  for j in range(b2,len(B)-1):
    b1=B[j]
    c2=bisect.bisect_right(C,b1)
    c3=len(C)-c2-1
    ans += c3

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

def binary_search_section(list, min, max):
    low = 0
    high = len(list) - 1
    upper = len(list)
    lower = -1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess >= min:
            high = mid - 1
        else:
            low = mid + 1
            lower = mid
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess > max:
            high = mid - 1
            upper = mid
        else:
            low = mid + 1

    return [lower, upper]

def main():
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字
    bList = list(map(int, input().split()))     # スペース区切り連続数字
    cList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    aListSorted = sorted(aList)
    bListSorted = sorted(bList)
    cListSorted = sorted(cList)

    result = 0
    for a in aListSorted:
        sec = binary_search_section(bListSorted, a+1, bListSorted[-1])
        for j in range(sec[0]+1, len(bListSorted)):
            b = bListSorted[j]
            sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1])
            result += len(cListSorted) - (sec2[0] + 1)

    # ------ 出力 ------#
    print("{}".format(result))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


if __name__ == '__main__':
    main()

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
import bisect
for i in A:
    a = bisect.bisect_right(B,i)
    for j in range(a,N):
        b = bisect.bisect_right(C,B[j])
        ans += N-b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))

a_len = len(al)
b_len = len(bl)
c_len = len(cl)

ans = 0
for a in al:
    b_index = bisect.bisect_right(bl, a)
    if b_index >= b_len:
        break
    tmp_bl = bl[b_index:]
    for b in tmp_bl:
        c_index = bisect.bisect_right(cl, b)
        if c_index >= c_len:
            break
        ans += c_len - c_index
        # print(f'a:{a}, b_index:{b_index}, c_index:{c_index}, ans:{ans}')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

# 標準入力を取得
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# 求解処理


def get_ub(l: list, x: int) -> int:
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (high + low) // 2
        guess = l[mid]
        if guess > x:
            high = mid
        else:
            low = mid
    return high


C = sorted(C)
ans = 0
for A_i, B_i in itertools.product(A, B):
    if A_i >= B_i:
        continue
    ans += N - get_ub(C, B_i)

# 結果出力
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

# 標準入力を取得
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# 求解処理


def get_ub(l: list, x: int) -> int:
    l = sorted(l)
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (high + low) // 2
        guess = l[mid]
        if guess > x:
            high = mid
        else:
            low = mid
    return high


ans = 0
for A_i, B_i in itertools.product(A, B):
    if A_i >= B_i:
        continue
    ans += N - get_ub(C, B_i)

# 結果出力
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
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 c in C:
    for b in B[:bisect_left(B,c)]:
        ans+=bisect_left(A,b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

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
a_left = 0
c_left = 0
for i in range(N):
    b = B[i]
    a_left += bisect_left(A[a_left:], b)
    c_left += bisect_right(C[c_left:], b)
    cnt += a_left * (N - c_left)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def main():
    from bisect import bisect

    N = int(input())
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    lst = [N - bisect(C, b) for b in B]
    ans = 0
    for a in A:
        ans += sum(lst[bisect(B, a):])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def main():
    from bisect import bisect

    _ = int(input())
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    lst = []
    for b in B:
        lst.append(len(C[bisect(C, b):]))
    ans = 0
    for a in A:
        ans += sum(lst[bisect(B, a):])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def main():
    from bisect import bisect

    _ = int(input())
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    ans = 0
    for a in A:
        can_b = B[bisect(B, a):]
        for b in can_b:
            ans += len(C[bisect(C, b):])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

A.sort()
B.sort()
C.sort()
ans=0
for a in range(N):
    for b in range(bisect.bisect_right(B,A[a]),N):
        for c in range(bisect.bisect_right(C,B[b]),N):
            ans+=1
print(ans)