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:
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))


a = sorted(a)
b = sorted(b)
c = sorted(c)
a_tmp = [one+0.2 for one in a]
b_tmp = [one+ i/10**6 for i,one in enumerate(b)]
ab = sorted(a_tmp+b_tmp)
ab_len = 2*N
ab_dict = dict()
for one in enumerate(ab):
    ab_dict[one[1]] = one[0]
b_ans = [ab_dict[one] - i for i,one in enumerate(b_tmp)]

b_tmp = [one+0.2 for one in b]
c_tmp = [one+ i/10**6 for i,one in enumerate(c)]
bc = sorted(b_tmp+c_tmp)
bc_len = 2*N
bc_dict = dict()
for one in enumerate(bc):
    bc_dict[one[1]] = one[0]
c_ans = [bc_dict[one] - i for i,one in enumerate(c_tmp)]

ans = 0
for i,one in enumerate(c_ans):
    if one == 0:
        continue
    ans += sum(b_ans[:one])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())

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

A.sort()
C.sort()

ans = 0
for b in B:
    na = len(A[:bisect.bisect_left(A, b)])
    nc = len(C[bisect.bisect_right(C, b):])
    ans += na * nc

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()))
s = 0
for b in B:
  s += (sum(c > b for c in C) * sum(a < b for a in A))
print(s)

Submission status: Time Limit Exceeded

Solution code:
import collections

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A_dict=collections.Counter(A)
B_dict=collections.Counter(B)
C_dict=collections.Counter(C)

A_sorted=sorted(A_dict)
B_sorted=sorted(B_dict)
C_sorted=sorted(C_dict)

C_sum=len(C)
C_num=[]

for i in B_sorted:
    C_sum=len(C)
    for j in C_sorted:
        if j<=i:
            C_sum-=C_dict[j]

    C_num.append(C_sum)

ans=0

for i in A_sorted:
    c=0
    for j in B_sorted:
        if i<j:
            ans += A_dict[i] * B_dict[j] * C_num[c]
        c+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A_dict=collections.Counter(A)
B_dict=collections.Counter(B)
C_dict=collections.Counter(C)

A_sorted=sorted(A_dict)
B_sorted=sorted(B_dict)
C_sorted=sorted(C_dict)

B_sum=len(B)
C_sum=len(C)

ans=0

for i in A_sorted:
    for j in B_sorted:
        C_num = C_sum
        if i < j:
            for k in C_sorted:
                if k <= j:
                    C_num -= C_dict[k]
                else:
                    break

            ans += A_dict[i] * B_dict[j] * C_num

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n = int(input())

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

second_list = []
for i in b:
    second_list.append(bisect_left(a, i))

ans = 0
for i in c:
    ans += sum(second_list[0:bisect_left(b, i)])

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

second_list = [0] * n

for B in range(n):
    second_list[B] = sum(b[B] > i for i in a)

ans = 0
for C in range(n):
    for i in range(n):
        ans += second_list[i] if c[C] > b[i] else 0 

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

ans_list = [0] * n
for r in range(n):
    temp = [i for i in a if b[r] > i]
    ans_list[r] = len(temp) 

ans_list2= [0] * n
for r in range(n):
    temp = [ans_list[i] for i in range(n) if c[r] > b[i]]
    ans_list2[r] += sum(temp)

print(sum(ans_list2))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left

n = int(input())

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

i_list = []
j_list = []

for x in b:
  i = bisect_left(a, x)
  i_list.append(len(a[:i]))

for x in b:
  j = bisect_right(c, x)
  j_list.append(len(c[j:]))

ans = 0

for i, j in zip(i_list, j_list):
  ans += i*j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left

n = int(input())

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


i_list = []
j_list = []

for x in b:
  i = bisect_left(a, x)
  i_list.append(len(a[:i]))

for x in b:
  j = bisect_right(c, x)
  j_list.append(len(c[j:]))

ans = 0

for i, j in zip(i_list, j_list):
  ans += i*j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left

n = int(input())

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

ans = 0

for x in b:
  i = bisect_left(a, x)
  j = bisect_right(c, x)

  ans += len(a[:i]) * len(c[j:])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

n = int(input())

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

ans = 0

for x in a:
  i = bisect_right(b, x)
  for y in b[i:]:
    j = bisect_right(c, y)
    for z in c[j:]:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

n = int(input())

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

ans = 0

for x in a:
  i = bisect_right(b, x)
  for y in b[i:]:
    j = bisect_right(c, y)
    for z in c[j:]:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ARC084C
import sys
import math

n=int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))
tmp = input().split()
b = list(map(lambda a: int(a), tmp))
tmp = input().split()
c = list(map(lambda a: int(a), tmp))

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

sum=0
for j in range(0,n):
	sumbc=0
	sumab=0
	for i in range(0,n):
		if(b[j]<c[n-i-1]):
			sumbc+=1
		else:
			break
	for k in range(0,n):
		if(a[k]<b[j]):
			sumab+=1
		else:
			break
#	print("{} {} {} {}".format(sum,sumbc*sumab,sumbc,sumab))
	sum+=sumbc*sumab
#	print("goal i:{} j:{} k:{}".format(c[i],b[j],a[k]))

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ARC084C
import sys
import math

n=int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))
tmp = input().split()
b = list(map(lambda a: int(a), tmp))
tmp = input().split()
c = list(map(lambda a: int(a), tmp))

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

sum=0
for i in range(0,n):
	for j in range(0,n):
		if(b[j]<c[i]):
			for k in range(0,n):
				if(a[k]<b[j]):
#					print("goal i:{} j:{} k:{}".format(c[i],b[j],a[k]))
					sum+=1
				else:
					break
		else:
			break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ARC084C
import sys
import math

n=int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))
tmp = input().split()
b = list(map(lambda a: int(a), tmp))
tmp = input().split()
c = list(map(lambda a: int(a), tmp))

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

sum=0
for i in range(0,n):
	for j in range(0,n):
		if(b[j]<c[i]):
			for k in range(0,n):
				if(a[k]<b[j]):
#					print("goal i:{} j:{} k:{}".format(i,j,k))
					sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ARC084C
import sys
import math

n=int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))
tmp = input().split()
b = list(map(lambda a: int(a), tmp))
tmp = input().split()
c = list(map(lambda a: int(a), tmp))

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

sum=0
for i in range(0,n):
	for j in range(0,n):
		if(b[j]<c[i]):
			for k in range(0,n):
				if(a[k]<b[j]):
#					print("goal i:{} j:{} k:{}".format(i,j,k))
					sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
input=sys.stdin.readline

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
k = 0
for i in a:
    for j in b:
        if j <= i:
            continue
        for k in range(len(c)):
            if j < c[k]:
                ans += (n - k)
                break
print(ans)

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()))
aa = [0] * n
bb = [0] * n
for i in range(n):
  bb[i] = n - bisect.bisect_right(c,b[i])
for i in range(n):
  aa[i] = sum(bb[bisect.bisect_right(b,a[i]):])
print(sum(aa))

Submission status: Time Limit Exceeded

Solution code:
# ABC 84, C - sunuke festival
n = int(input())
A = [int(el) for el in input().split(' ')]
B = [int(el) for el in input().split(' ')]
C = [int(el) for el in input().split(' ')]

total = 0
for b in B:
    total += sum(i < b for i in A) * sum(j > b for j in C)
print(total)

Submission status: Time Limit Exceeded

Solution code:
# 2019/07/19
# AtCoder Regular Contest 084 - C

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

# Calc
ans = 0
for i in range(len(b)):
    ucnt = 0
    for j in range(len(a)):
        if a[j] < b[i]:
            ucnt = ucnt +1

    dcnt = 0
    for j in range(len(c)):
        if b[i] < c[j]:
            dcnt = dcnt +1
    ans = ans + ucnt * dcnt

# Output
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()))
ans=0
for i in range(n):
  ans+=sum(x<b[i] for x in a)*sum(x>b[i] for x in c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def bs(a, v):
    ok = len(a)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if a[mid] > v:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N = readi()
    A = sorted(readi(N))
    B = sorted(readi(N))
    C = sorted(readi(N))
    ans = 0
    for a in range(len(A)):
        i = bs(B, A[a])
        if i == len(B):
            continue
        for b in range(i, len(B)):
            j = bs(C, B[b])
            if j == len(C):
                continue
            ans += len(C) - j
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
	for j in range(bisect_right(B, A[i]), N):
		ans += N - bisect_right(C, B[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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)

ans = 0
for c in C:
    b_cands = bisect_left(B, c)
    for i in range(b_cands):
        a_cands = bisect_left(A, B[i])
        ans += a_cands
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
a.sort();b.sort();c.sort()
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]:
                    cnt += n-k
                    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += sum(bt[bif:])

print(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		for b in B[bif:]:
			ci = bsr(C, b)
			if ci < N:
				r += (N - ci)
			else:
				break
	else:
		break
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()))
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    ans+=sum(x<b[i] for x in a)*sum(y>b[i] for y in c)
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()))
cnt = 0
for aa in a:
    for bb in b:
        for cc in c:
            if aa < bb < cc:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0
x=[]
i=0
b__=copy.copy(b)
rev=0
while(b__):
     b_=b__.pop()
     while(1):
          try:
               c_=c.pop()
          except:
               rev+=cnt
               x.append(rev)
               cnt=0
               break
          if c_>b_:
               cnt+=1
          else:
               rev+=cnt
               x.append(rev)
               cnt=0
               c.append(c_)
               break
cnt=0
i=n-1
rev=0
ans=0
while(a):
     a_=a.pop()
     while(1):
          try:
               b_=b.pop()
          except:
               rev+=cnt
               ans+=rev
               cnt=0
               break
          if b_>a_:
               cnt+=x.pop(0)
          else:
               rev+=cnt
               ans+=rev
               cnt=0
               b.append(b_)
               break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0
x=[]
i=0
b__=b.copy()
rev=0
while(b__):
     b_=b__.pop()
     while(1):
          try:
               c_=c.pop()
          except:
               rev+=cnt
               x.append(rev)
               cnt=0
               break
          if c_>b_:
               cnt+=1
          else:
               rev+=cnt
               x.append(rev)
               cnt=0
               c.append(c_)
               break
cnt=0
i=n-1
rev=0
while(a):
     a_=a.pop()
     for i in range(1,n+1):
          idx=n-i
          b_=b[idx]
          if b_>a_:
               cnt+=x[i-1]
          else:
               break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# ABC084C - Snuke Festival
n = int(input())
lst = [list(map(int, input().rstrip().split())) for _ in range(3)]
ans = 0
for i in lst[0]:
    for j in lst[1]:
        if j > i:
            for k in lst[2]:
                if k > j:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sum = 0
for i in range(n):
    bs = [bi for bi in b if a[i] < bi]
    if len(bs) == 0:
        continue
    for j in range(len(bs)):
        cs = [ci for ci in c if bs[j] < ci]
        sum += len(cs)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right

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

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

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()))
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 += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def biggerthanB(x,C):
    for i in range(len(C)):
        if x < C[i]:
            return len(C) - i 
    return 0

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

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

numpattern = 0
for a in range(N):
    for b in range(N):
        if B[b] > A[a]:
            numpattern += biggerthanB(B[b],C)
            #print(A[a],B[b],numpattern)

print(numpattern)

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_count_below_b_bofore = 0
a_position = 0
b_position = 0
counter = 0
counter_tmp = []
for i in range(n): # c
    counter += sum(counter_tmp)
    for j in range(b_position, n): # b
        if b[j] >= c[i]:
            break
        else:
            b_position += 1

        _a_count_below_b = _a_count_below_b_bofore
        for k in range(a_position, n): # a
            if a[k] < b[j]:
                a_position += 1
                _a_count_below_b += 1
            else:
                break
        _a_count_below_b_bofore = _a_count_below_b

        counter += _a_count_below_b
        counter_tmp.append(_a_count_below_b)

print(counter)

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_count_below_bi = []
b_count_below_ci = []
a_position = 0
b_position = 0
for i in range(n): # c
    _b_count_below_ci = 0
    for j in range(b_position, n): # b
        if b[j] < c[i]:
            b_position += 1
            _b_count_below_ci += 1
        else:
            break
    if i == 0:
        b_count_below_ci.append(_b_count_below_ci)
    else:
        b_count_below_ci.append(b_count_below_ci[-1] + _b_count_below_ci)

for i in range(n): # b
    _a_count_below_bi = 0
    for j in range(a_position, n): # a
        if a[j] < b[i]:
            a_position += 1
            _a_count_below_bi += 1
        else:
            break
    if i == 0:
        a_count_below_bi.append(_a_count_below_bi)
    else:
        a_count_below_bi.append(a_count_below_bi[-1] + _a_count_below_bi)

counter = 0
for i in range(n): # c
    counter += sum(a_count_below_bi[:b_count_below_ci[i]])
print(counter)

Submission status: Time Limit Exceeded

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

for i1 in A:
    for i2 in B:
        if i1 < i2:
            for i3 in range(len(C)):
                if i2 < C[i3]:
                    p = len(C[i3:-1])+1
                    ans += p
                    break
        if i1 > i2:
            break

print(ans)

Submission status: Time Limit Exceeded

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

for i1 in A:
    for i2 in B:
        if i1 < i2:
            for i3 in range(len(C)):
                if i2 < C[i3]:
                    p = len(C[i3:-1])+1
                    ans += p
                    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
cnt=0
for i in A:
    for j in B:
        if i < j:
            for k in C:
                if j < k:
                    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math
import bisect

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = list(int(_) for _ in input().split())
    B = list(int(_) for _ in input().split())
    C = list(int(_) for _ in input().split())
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        b_index = bisect.bisect_right(B,A[i])
        for j in range(b_index,N):
            c_index = bisect.bisect_right(C,B[j])
            ans += N - c_index
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
as_ = list(map(int, input().split()))
bs_ = list(map(int, input().split()))
cs_ = list(map(int, input().split()))

ans = 0
for a in as_:
  for b in bs_:
    if b > a:
      ans += len([c for c in cs_ if c >b])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

cnt = 0
for b in B:
    at = len(A[np.where(A < b)])
    ac = len(C[np.where(C > b)])
    cnt += (at * ac)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

cnt = 0
for a in A:
    bt = B[np.where(B > a)]
    for b in bt:
        ct = C[np.where(C > b)]
        cnt += len(ct)
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for a in A:
    for b in B:
        if not a < b:
            break
        for c in C:
            if not b < c:
                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()))
cnt = 0
for a in A:
    for b in B:
        if not a < b:
            continue
        for c in C:
            if not b < c:
                continue
            cnt += 1
print(cnt)

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())))
NB_forA=[sorted([a]+B)[::-1].index(a) for a in A]
NC_forB=[sorted([b]+C)[::-1].index(b) for b in B]
ans=0
for nb in NB_forA:
  for i in range(nb):
    ans+=NC_forB[-(i+1)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for i in range(N):
  for j in range(N):
    if A[i]<B[j]:
      for k in range(N):
        if B[j]>=C[k]:
          continue
        else:
          ans+=(N-k)
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import 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()
ans = 0
#print(A)
#print(B)
#print(C)
for a in A:
    num1 = bisect_right(B, a)
    for i in range(num1,n):
        num2 = bisect_right(C,B[i])
        ans += n - num2
        #print(a,B[i],C[num2])


print(ans)

Submission status: Time Limit Exceeded

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

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

A_pat = [0] * N
B_pat = [0] * N

c = 0
for b in range(N):
    for i in range(c,N):
        if B[b] < C[i]:
            c = i
            B_pat[b] = N-i
            break

B_pat_sum = [0]*N
B_pat_sum[N-1] = B_pat[N-1]
for i in range(N-2,-1,-1):
    B_pat_sum[i] = B_pat_sum[i+1] + B_pat[i]

b = 0
for a in range(N):
    for i in range(b,N):
        if A[a] < B[i]:
            b = i
            A_pat[a] = B_pat_sum[i]
            break
print(sum(A_pat))

Submission status: Time Limit Exceeded

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

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

A_pat = [0] * N
B_pat = [0] * N

c = 0
for b in range(N):
    for i in range(c,N):
        if B[b] < C[i]:
            c = i                 
            B_pat[b] = N-i   
            break
b = 0       
for a in range(N):
    for i in range(b,N):
        if A[a] < B[i]:
            b = i
            A_pat[a] = sum(B_pat[i:])         
            break
print(sum(A_pat))

Submission status: Time Limit Exceeded

Solution code:
from bisect import*
from numpy import*
n=int(input())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
c=sorted(map(int,input().split()))
#print(a,b,c)
#print([bisect_right(b,t)for t in a])
#print(cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1])
ans=0
for i in [bisect_right(b,t)for t in a]:
    if i<n:
        ans+=cumsum([n-bisect_right(c,s)for s in b][::-1])[::-1][i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
A = defaultdict(int)
B = defaultdict(int)
C = defaultdict(int)

N = int(input())
a = [k for k in map(int, input().split())]
b = [k for k in map(int, input().split())]
c = [k for k in map(int, input().split())]

for k in range(N):
  A[a[k]] += 1
  B[b[k]] += 1
  C[c[k]] += 1

Aset = sorted(set(a))
Bset = sorted(set(b))
Cset = sorted(set(c))

cnt = 0
index_a = 0
index_c = 0
a = 0
c = N

for b in Bset:
  flag_a = False
  flag_c = False
  for k in range(index_a, len(Aset)):
    if Aset[k] < b:
      a += A[Aset[k]] 
    else:
      index_a = k
      flag_a = True
      break
  for k in range(index_c, len(Cset)):
    if Cset[k] <= b:
      c -= C[Cset[k]]
    else:
      index_c = k
      flag_c = True
      break
  if flag_a == False:
    a = N
  if flag_c == False:
    c = 0
  cnt += a*c*B[b]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
alist = list(sorted(map(int, input().split())))
blist = list(sorted(map(int, input().split())))
clist = list(sorted(map(int, input().split())))

ans = 0
for a in alist:
  bi = bisect.bisect_right(blist, a)
  if bi == len(blist):
    break
  for b in blist[bi:]:
    ci = bisect.bisect_right(clist, b)
    if ci == len(clist):
      break
    ans += len(clist) - ci
print(ans)

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()))
x=[1 for _ in range(N)]
for i in range(N):
        x[i]=N-bisect.bisect_right(C,B[i]) #B[i]より大きい要素の番号の数

ans=0
for i in range(N):
        j=bisect.bisect_right(B,A[i])
        ans+=sum(x[j:N])

print(ans)