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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i
    raise ValueError
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect.bisect_right(a, x)
    if i != len(a):
        return len(a)-i
    raise ValueError
for bs in b:
  ans += find_lt(a, bs)*find_gt(c,bs)
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int N;
int a[3][111111];
long long ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(int i=0;i<3;i++)
        for(int j=0;j<N;j++)
            cin>>a[i][j];
    for(int i=0;i<3;i++)sort(a[i],a[i]+N);
    for(int i=0;i<N;i++){
        int x=a[1][i];
        ans += 1LL
        * ((lower_bound(a[0],a[0]+N,x)-a[0]))
        * (N - (upper_bound(a[2],a[2]+N,x)-a[2]));
    }
    cout<<ans;
}

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
num = 0
#a.sort
#b.sort
#c.sort

for i in range(n):
    for j in range(n):
        if a[i] < b[i]:
            for k in range(n):
                b[j] < c[k]:
                num += 1
print(num)

Submission status: Runtime Error

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

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))

    return count

Submission status: Runtime Error

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.sort()
    B.sort()
    C.sort()

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai<N-1:
            while A[Ai+1]<B[i]:
                Ai += 1
                if Ai == N-1:
                    break
        if Ci<N:
            while C[Ci+1]<=B[i]:
                Ci += 1
                if Ci==N-1:
                    break
        count += (Ai+1) * (N-(Ci+1))

    return count

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())



        
        
summer = 0
for j in bdic.keys():
    ai = 0
    ci = 0
    for i in range(j):
        if i in adic.keys():
            ai = ai + adic[i]
    for k in range(j,cma + 1):
        if k in cdic.keys():
            ci = ci + cdic[i]
    summer = summer + bdic[j] * ai * ci       
print(summer)

Submission status: Runtime Error

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

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

ami = min(adic.keys())
ama = max(adic.keys())
bmi= min(bdic.keys())
bma= max(bdic.keys())
cmi= min(cdic.keys())
cma= max(cdic.keys())

        
        
summer = 0
for i in range(ami,ama+1):
    for j in range(bmi,bma + 1):
        if i < j:
            for k in range(cmi,cma+1):
                if i< j< k:
                    summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)

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()]
a.sort()
b.sort()
c.sort()
c = c[::-1]
answer,x,y = 0,0,n-1
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(y+1):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)

Submission status: Runtime Error

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()
b.reverse()
c.reverse()
pat=0
keepi,keepj=-1,-1
for x in range(n):
  i=a[x]
  if(i!=keepi):
    keepi=i
    patj=0
  else:
    pat+=patj
    continue
  for y in range(n):
    j=b[y]
    if(j!=keepj):
        keepj=j
    else:
        patj+=patk
        continue
    if(j<=i):break
    br=0
    for k in range(n):
      if(c[k]<=j):
        #print(i,j,c[k],k)
        patk=k
        br=1
        break
    if(br==0):patk=n
    patj+=patk
  pat+=patj
print(pat)

Submission status: Runtime Error

Solution code:
import numpy as np
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()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(2)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[1][-1]-cum_M[1][b])
        
print(int(counter))

Submission status: Runtime Error

Solution code:
import numpy as np
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()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(3)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][B[i]] += 1
    M[2][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[2][-1]-cum_M[2][b])
        
print(counter)

Submission status: Runtime Error

Solution code:


N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = (0, 0, 0, 1)
for i in l:
    count[i[1]] += count[i[1] + 1]
print count[0]

Submission status: Runtime Error

Solution code:

N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = (0, 0, 0, 1)
for i in l:
    count[i] += count[i + 1]
print count[0]

Submission status: Runtime Error

Solution code:


N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = (0, 0, 0, 1)
for i in l:
    count[i] += count[i + 1]
print count[0]

Submission status: Runtime Error

Solution code:
N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]
l = sorted(As + Bs + Cs, key=lambda x: (x[0],x[1]))
count = (0, 0, 0)
for i in l:
    count[i[1]] += 1 if(i[1] == 2)else count[2] if(i[1] == 1) else count[1]
print count[0]

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    index2_right = bisect.bisect_right(a[2], i)
    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left -1 + 1)*(n - index2_right)

print(count)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    while i == a[0][index0_left-1]:
        if index0_left == 0:
            break
        index0_left -= 1

    index2_right = bisect.bisect_right(a[2], i)
    while a[2][index2_right+1] == i:
        if index2_right > n:
            break
        index2_right += 1

    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left)*( n - index2_right)
        
print(count)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    while i == a[0][index0_left-1]:
        if index0_left == 0:
            break
        index0_left -= 1

    index2_right = bisect.bisect_right(a[2], i)
    while a[2][index2_right+1] == i:
        if index2_right > n:
            break
        index2_right += 1

    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left)*( n - index2_right)

Submission status: Runtime Error

Solution code:
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

#高速化できるのがキャッシュしか無い

ans = 0
pos_j = 0
for i in ue:
    flag = 0
    while(mid[pos_j] <= i):
        pos_j += 1
        if pos_j >= len(mid):
            flag = 1
            break
    if flag == 1:
        break

    pos_k = 0
    for j in range(pos_j, len(mid)):
        flag_ = 0
        while(bot[pos_k] <= mid[j]):
            pos_k += 1
            if pos_k >= len(bot):
                flag_ = 1
        if flag_ == 1:
            break
        ans += len(bot) - pos_k

    if flag_ == 1:
        break
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

#高速化できるのがキャッシュしか無い

ans = 0
pos_j = 0
for i in ue:
    flag = 0
    while(mid[pos_j] <= i):
        pos_j += 1
        if pos_j >= len(mid):
            flag = 1
            break
    if flag == 1:
        break

    pos_k = 0
    for j in range(pos_j, len(mid)):
        flag_ = 0
        while(bot[pos_k] <= mid[j]):
            pos_k += 1
            if pos_k >= len(bot):
                flag_ = 1
        if flag_ == 1:
            break
        ans += len(bot) - pos_k
print(ans)

Submission status: Runtime Error

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()
A = 0
for x in b:
  i = bisect.bisect_left(a, x)
  j = bisect.bisect_right(c, x)
  if i > 0 and j != len(c):
    ans += i * (n - j)
print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8

n = input()
top = map(int, raw_input().split())
middle = map(int, raw_input().split())
under = map(int, raw_input().split())
top.sort()
middle.sort()
under.sort()
total = 0
for i in xrange(n):
    high = n - 1
    low = 0
    t = (high+low)/2
    d = middle[i] - 1
    while(low <= high):
        if top[t] == d: break
        if top[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    while(t+1 < len(top)):
        if top[t] != top[t+1]: break
        t += 1
    tt = t + 1 #topの候補数

    high = n -1
    low = 0
    t = (high+low)/2
    d = middle[i] + 1
    while(low <= high):
        if under[t] == d: break
        if under[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    if(under[t] != d): t += 1
    while(t-1 >= 0):
        if under[t] != under[t-1]: break
        t -= 1
    tu = n - t #underの候補数

    total += tt*tu
print total

Submission status: Runtime Error

Solution code:
# coding:utf-8

n = input()
top = map(int, raw_input().split())
middle = map(int, raw_input().split())
under = map(int, raw_input().split())
top.sort()
middle.sort()
under.sort()
total = 0
for i in xrange(n):
    high = n - 1
    low = 0
    t = (high+low)/2
    d = middle[i] - 1
    while(low <= high):
        if top[t] == d: break
        if top[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    while(t+1 < len(top)):
        if top[t] != top[t+1]: break
        t += 1
    tt = t + 1 #topの候補数

    high = n -1
    low = 0
    t = (high+low)/2
    d = middle[i] + 1
    while(low <= high):
        if under[t] == d: break
        if under[t] > d:
            high = t - 1
        else:
            low = t + 1
        t = (high+low)/2
    if(under[t] != d): t += 1
    while(t-1 >= 0):
        if under[t] != under[t+1]: break
        t -= 1
    tu = n - t #underの候補数

    total += tt*tu
print total

Submission status: Runtime Error

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()))
    ans = 0
    a.sort()
    b.sort()
    c.sort()
     
    for j in range(n):
        ans += bisect.bisect_left(a,b[j])*(n-bisect.bisect_right(c,b[j]))
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N
    b = B[j]
    #print(b)
    while(high>low):
        mid = (high + low)//2
        if b > A[mid]:
            low = mid +1
        else:
            high = mid
    acount = mid
    while (high2>low2):
        mid2 = (high + low)//2
        if b < C[mid2]:
            high2 = mid2
        else:
            low2 = mid2 + 1
    ccount=N-mid2
    sum += acount*ccount
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N
    b = B[j]
    #print(b)
    while(high>low):
        mid = (high + low)//2
        if b > A[mid]:
            low = mid +1
        else:
            high = mid
    acount = mid
    while (high2>low2):
        mid2 = (high + low)//2
        if b < C[mid2]:
            high2 = mid2
        else:
            low = mid2 + 1
    ccount=N-mid2
    sum += acount*ccount
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
#print(A,B,C)
for j in range(N):
    low = low2 = 0
    high = high2 = N - 1
    mid =mid2 = (N - 1) // 2
    b = B[j]
    if A[0] > b:
        acount = 0
    else:
        while high > low:
            if A[mid] < b:
                if low == mid:
                    if A[mid+1] < b:
                            low += 1
                    if A[mid+1] >= b:
                            high += - 1
                else:
                    low = mid
            if A[mid] >= b:
                high = mid-1
            mid = (high + low) // 2
        acount = mid + 1


    while high2 > low2:
        if C[mid2] > b:
            high2 = mid2
        if C[mid2] <= b:
            if low2 == mid2:
                if C[low2+1] > b:
                    low2 += 1
                if C[low2+1] <=b:
                    high2 -= 1
            else:
                low2 = mid2 + 1
        mid2 = (high2 + low2)//2
    ccount = N-mid2
    #print(acount,ccount)
    sum += acount*ccount
print(sum)

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()]
A2=sorted(A)
B2=sorted(B)
C2=sorted(C)
ans = 0
sum = 0
t =0
b = 0
for i in range(N):
    a = A2[i]
    low = 0
    high = N-1
    while True:
        t = (low + high) // 2
        if B2[t] <= a:
            if t == N-1:
                b = False
                break
            elif B2[t] <= a <B2[t+1]:

                b = B2[t+1]
                t = t + 1
                break
            else:
                low = t+1
                continue
        elif B2[t] > a:
            if t == 0:
                b = B2[0]
                break
            elif B2[t] > a >= B2[t-1]:
                b = B2[t]
                break
            else:
                high = t - 1
                continue
    if b != False:
        for j in range(t,N):
            b = B2[j]
            low = 0
            high = N - 1
            while True:
                print(a, b)
                t = (low + high) // 2
                if C2[t] <= b:
                    if C2[t] <= b < C2[t + 1]:
                        c = C2[t + 1]
                        ans = N - t - 1
                        break
                    else:
                        low = t + 1
                        continue
                elif C2[t] > b:
                    if t == 0:
                        if C2[t] > b:
                            ans = N
                            break
                        else:
                            ans = 0
                            break
                    elif C2[t] > b >= C2[t - 1]:
                        c = C2[t]
                        ans = N - t
                        break
                    else:
                        high = t - 1
                        continue
                print("ans={}".format(ans))
            sum += ans

print(sum)

Submission status: Runtime Error

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 y in range(n):
    if a[n-1] <= b[y]:
        a_ans = n
    elif a[0] > b[y]:
        a_ans = 0
    else:
        left = 0
        right = n
        while True:
            mid = (left + right) // 2
            if a[mid] <= b[y] and b[y] < a[mid+1]:
                a_ans = mid + 1
                break
            elif a[mid] > b[y]:
                right = mid - 1
            else:
                left = mid + 1

    if b[y] <= c[0]:
        c_ans = n
    elif b[y] > c[n-1]:
        c_ans = 0
    else:
        left = 0
        right = n
        while True:
            mid = (left + right) // 2
            if c[mid] <= b[y] and b[y] < c[mid+1]:
                c_ans = n - mid - 1
                break
            elif c[mid] > b[y]:
                right = mid - 1
            else:
                left = mid + 1
    ans += a_ans * c_ans
print(ans)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
cl = map(int, raw_input().split())
al.sort()
bl.sort()
cl.sort()
l = [(0,0) for _ in range(n)]
p = 0
for i, b in enumerate(bl):
    while cl[p] <= b:
        p += 1
    l[i] = (b, n-p)
p = n-1
s = 0
t = 0
for a in al[::-1]:
    while p >= 0 and l[p][0] > a:
        s += l[p][1]
        p -= 1
    t += s
print t

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()]
a.sort()
b.sort()
c.sort()
#n_max=10
n_max=10**5+2
ans=0


#a_count=[0 for i in range(n_max+1)]
b_count=[0 for i in range(n_max+1)]
c_count=[0 for i in range(n_max+1)]
ans_count=[0 for i in range(n_max+1)]
b_cou=0
c_cou=0

for i in range(n):
    b_count[b[i]]=1+b_count[b[i]]
    c_count[c[i]]=1+c_count[c[i]]
for i in range(1,n_max+1):
#    b_count[-i-1]=b_count[-i]+ b_count[-i-1]
    c_count[-i-1]=c_count[-i]+ c_count[-i-1]
    ans_count[-i-1]=ans_count[-i]+b_count[-i-1]*c_count[-i]
#print(b_count)
#print(c_count)
#print(ans_count)

for i in range(n):
    ans=ans+ans_count[a[i]+1]

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()]
a.sort()
b.sort()
c.sort()
#n_max=10
n_max=10**5
ans=0


#a_count=[0 for i in range(n_max+1)]
b_count=[0 for i in range(n_max+1)]
c_count=[0 for i in range(n_max+1)]
ans_count=[0 for i in range(n_max+1)]
b_cou=0
c_cou=0

for i in range(n):
    b_count[b[i]]=1+b_count[b[i]]
    c_count[c[i]]=1+c_count[c[i]]
for i in range(1,n_max+1):
#    b_count[-i-1]=b_count[-i]+ b_count[-i-1]
    c_count[-i-1]=c_count[-i]+ c_count[-i-1]
    ans_count[-i-1]=ans_count[-i]+b_count[-i-1]*c_count[-i]
#print(b_count)
#print(c_count)
#print(ans_count)

for i in range(n):
    ans=ans+ans_count[a[i]+1]

print(ans)

Submission status: Runtime Error

Solution code:
import operator

def snuke_fest(top_arr, middle_arr, bottom_arr):
    sorted_arrs = list(sorted(arr) for arr in (top_arr, middle_arr, bottom_arr))
    del top_arr
    del middle_arr
    del bottom_arr
    pointers = [0] * 3
    ended = [False] * 3
    min_posi = [None] * len(sorted_arrs[0]) * 3
    min_posi_pointer = 0
    while not all(ended):
        nums = [0] * 3
        mins = [10**9] * 3
        for i in range(3):
            if not ended[i]:
                mins[-(i+1)] = sorted_arrs[i][pointers[i]]
        min_index, min_val = min(enumerate(mins), key = operator.itemgetter(1))
        min_index = 2 - min_index
        pointers[min_index] += 1
        min_posi[min_posi_pointer] = min_index
        min_posi_pointer += 1
        if pointers[min_index] == len(sorted_arrs[0]):
            ended[min_index] = True
    del sorted_arrs
    del pointers
    count = 0
    count_arr = [0, 0, 0]
    count_one_two = 0
    for i in range(len(min_posi)):
        count_arr[min_posi[-(i+1)]] += 1
        if min_posi[-(i+1)] == 1:
            count_one_two += count_arr[2]
        elif min_posi[-(i+1)] == 0:
            count += count_one_two
    return count


if __name__ == "__main__":
    _ = input()
    top_arr = [int(i) for i in input().split(" ")]
    middle_arr = [int(i) for i in input().split(" ")]
    bottom_arr = [int(i) for i in input().split(" ")]
    print(snuke_fest(top_arr, middle_arr, bottom_arr))

Submission status: Runtime Error

Solution code:
import operator

def snuke_fest(top_arr, middle_arr, bottom_arr):
    sorted_arrs = list(sorted(arr) for arr in (top_arr, middle_arr, bottom_arr))
    pointers = [0] * 3
    ended = [False] * 3
    min_posi = [None] * len(top_arr) * 3
    min_posi_pointer = 0
    while not all(ended):
        nums = [0] * 3
        mins = [10**9] * 3
        for i in range(3):
            if not ended[i]:
                mins[-(i+1)] = sorted_arrs[i][pointers[i]]
        min_index, min_val = min(enumerate(mins), key = operator.itemgetter(1))
        min_index = 2 - min_index
        pointers[min_index] += 1
        min_posi[min_posi_pointer] = min_index
        min_posi_pointer += 1
        if pointers[min_index] == len(top_arr):
            ended[min_index] = True
    del sorted_arrs
    del pointers
    count = 0
    count_arr = [0, 0, 0]
    count_one_two = 0
    for i in range(len(min_posi)):
        count_arr[min_posi[-(i+1)]] += 1
        if min_posi[-(i+1)] == 1:
            count_one_two += count_arr[2]
        elif min_posi[-(i+1)] == 0:
            count += count_one_two
    return count


if __name__ == "__main__":
    # run_test(find_even, test_pair)
    _ = input()
    top_arr = [int(i) for i in input().split(" ")]
    middle_arr = [int(i) for i in input().split(" ")]
    bottom_arr = [int(i) for i in input().split(" ")]
    print(snuke_fest(top_arr, middle_arr, bottom_arr))

Submission status: Runtime Error

Solution code:
import operator

def snuke_fest(top_arr, middle_arr, bottom_arr):
    sorted_arrs = list(sorted(arr) for arr in (top_arr, middle_arr, bottom_arr))
    pointers = [0] * 3
    ended = [False] * 3
    min_posi = [None] * len(top_arr) * 3
    min_posi_pointer = 0
    while not all(ended):
        nums = [0] * 3
        mins = [10**9] * 3
        for i in range(3):
            if not ended[i]:
                mins[-(i+1)] = sorted_arrs[i][pointers[i]]
        min_index, min_val = min(enumerate(mins), key = operator.itemgetter(1))
        min_index = 2 - min_index
        pointers[min_index] += 1
        min_posi[min_posi_pointer] = min_index
        min_posi_pointer += 1
        if pointers[min_index] == len(top_arr):
            ended[min_index] = True
    count = 0
    count_arr = [0, 0, 0]
    count_one_two = 0
    for i in range(len(min_posi)):
        count_arr[min_posi[-(i+1)]] += 1
        if min_posi[-(i+1)] == 1:
            count_one_two += count_arr[2]
        elif min_posi[-(i+1)] == 0:
            count += count_one_two
    return count


if __name__ == "__main__":
    # run_test(find_even, test_pair)
    _ = input()
    top_arr = [int(i) for i in input().split(" ")]
    middle_arr = [int(i) for i in input().split(" ")]
    bottom_arr = [int(i) for i in input().split(" ")]
    print(snuke_fest(top_arr, middle_arr, bottom_arr))

Submission status: Runtime Error

Solution code:
=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
small=0
large=0
for i in range(N):
  for k in range(small,N):
    if A[k]>=B[i]:
      small=k
      break
  else: small=N
  for k in range(large,N):
    if C[k]>B[i]:
      large=k
      break
  else: large=N
  ans+=small*(N-large)
print(ans)

Submission status: Runtime Error

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())))
num=0
for i in range(N):
    j=0
    while B[i]>A[j]:
        if j<=N-2:
            j += 1
        else:
            j=N
            break
    x=j
    k=0
    while B[i]>=C[k]:
        if k<=N-1:
            k += 1
        else:
            k=N
            break
    y=N-k
    z=x*y
    num += z
print(num)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
print(sum(len(A[:bisect.bisect_left(A, b)]) * len(C[bisect.bisect(C, b)]) b for b in B))

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect
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)
Cli = np.sort(Cli)[::-1]
co=0
for B in Bli:
    ca = bisect.bisect_left(Ali,B)
    cb =0
    for C in Cli:
        if C <= B:
            break
        else:
            cb +=1 
    co += ca*cb
print(co)
~

Submission status: Runtime Error

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 = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    bb = bb - b_index[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += N * (N - a_i) - bb[a_i]
print(str(res))

Submission status: Runtime Error

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

    b = [0] * 100002
    for i in B:
        b[i] += 1

    cnt = 0
    for i in A:
        for j in C:
            if i < j:
                cnt += sum(b[i+1:j])

    print(cnt)

main()