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: Accepted

Solution code:
N = int(input())

An = sorted(map(int, input().split()))
Bn = sorted(map(int, input().split()))
Cn = sorted(map(int, input().split()))


def f(xn, yn, zn):
    tn = [0] * N
    num = 0
    j = N - 1

    for i in range(N - 1, -1, - 1):
        while 0 <= j and xn[i] < yn[j]:
            num += zn[j]
            j -= 1
        tn[i] = num

    return tn


def main():
    Zn = [1] * N

    Zn = f(Bn, Cn, Zn)
    Zn = f(An, Bn, Zn)

    print(sum(Zn))
    return


main()

Submission status: Accepted

Solution code:
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    An = sorted(map(int, input().split()))
    Bn = sorted(map(int, input().split()))
    Cn = sorted(map(int, input().split()))

    ans = 0
    lx = 0
    ux = 0

    for Bi in Bn:
        # 以上
        lx = bisect_left(An, Bi, lx, N)

        # より大きい
        ux = bisect_right(Cn, Bi, ux, N)

        ans += lx * (N - ux)

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())

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

    def lowerBound(a, v):
        # 以上
        return lb(a, 0, len(a), v)

    def upperBound(a, v):
        # より大きい
        # 値をプラス1
        return lb(a, 0, len(a), v + 1)

    def lb(a, l, r, v):
        low = l - 1
        high = r

        while high - low > 1:
            mid = low + high >> 1
            if a[mid] >= v:
                high = mid
            else:
                low = mid

        return high

    print(sum([lowerBound(A, Bi) * (N - upperBound(C, Bi)) for Bi in B]))

    return


main()

Submission status: Accepted

Solution code:
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    An = map(int, input().split())
    Bn = map(int, input().split())
    Cn = map(int, input().split())

    A = sorted(An)
    B = sorted(Bn)
    C = sorted(Cn)

    print(sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))
    return


main()

Submission status: Accepted

Solution code:
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

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

    print(sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))
    return


main()

Submission status: Accepted

Solution code:
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    An = map(int, input().split())
    Bn = map(int, input().split())
    Cn = map(int, input().split())

    A = sorted(An)
    C = sorted(Cn)

    print(sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn))
    return


main()

Submission status: Accepted

Solution code:
N = int(input())

An = sorted([int(i) for i in input().split()])
Bn = map(int, input().split())
Cn = sorted([int(i) for i in input().split()])


def lowerBound(a, v):
    # 以上
    return lb(a, 0, len(a), v)


def upperBound(a, v):
    # より大きい
    # 値をプラス1
    return lb(a, 0, len(a), v + 1)


def lb(a, l, r, v):
    low = l - 1
    high = r

    while high - low > 1:
        mid = low + high >> 1
        if a[mid] >= v:
            high = mid
        else:
            low = mid

    return high


def main():
    print(sum([lowerBound(An, Bi)
               * (N - upperBound(Cn, Bi)) for Bi in Bn]))

    return


main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())

An = sorted(map(int, input().split()))
Bn = map(int, input().split())
Cn = sorted(map(int, input().split()))


def main():
    print(sum([bisect.bisect_left(An, Bi)
               * (N - bisect.bisect(Cn, Bi)) for Bi in Bn]))

    return


main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())

An = sorted(map(int, input().split()))
Bn = map(int, input().split())
Cn = sorted(map(int, input().split()))


def main():
    print(sum(bisect.bisect_left(An, Bi)
              * (N - bisect.bisect(Cn, Bi)) for Bi in Bn))

    return


main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())

An = map(int, input().split())
Bn = map(int, input().split())
Cn = map(int, input().split())


def main():
    A = sorted(An)
    C = sorted(Cn)

    ans = 0

    for Bi in Bn:
        # 以上
        lx = bisect.bisect_left(A, Bi)

        # より大きい
        ux = bisect.bisect(C, Bi)

        ans += lx * (N - ux)

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
import bisect
from sys import stdin

N = int(input())

lines = stdin.readlines

l = [[int(i) for i in line.split()] for line in lines()]

An = l[0]
Bn = l[1]
Cn = l[2]


def main():
    An.sort()
    Cn.sort()

    ans = 0

    for Bi in Bn:
        # 以上
        lx = bisect.bisect_left(An, Bi)

        # より大きい
        ux = bisect.bisect(Cn, Bi)

        ans += lx * (N - ux)

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
# めぐる二分探索
def lower_bound(a, key):
    ng = -1
    ok = len(a)
    
    while abs(ok-ng)>1:
        mid = (ok + ng) // 2
        
        if a[mid]>key: ok=mid # 今回は真に大きいだから不等号
        else: ng = mid
    return ok

def upper_bound(a, key):
    ng = len(a)
    ok = -1
    
    while abs(ok-ng)>1:
        mid = (ok + ng) // 2
        
        if a[mid]<key: ok=mid # 今回は真に大きいだから不等号
        else: ng = mid
    return ok

N = int(input())
A, B, C = [sorted(list(map(int, input().split()))) for _ in range(3)]
ans = 0
for b in B:
    a_i = upper_bound(A, b)
    c_i = lower_bound(C, b)
    ans += (a_i+1)*(N-c_i)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""


# ABC 077 C Festival
import collections
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    aParts = getIntList()
    bParts = getIntList()
    cParts = getIntList()
    aParts.sort()
    bParts.sort()
    cParts .sort()
    d.dmp((aParts), 'A')
    d.dmp((bParts), 'B')
    d.dmp((cParts), 'C')
    combAB = zeros(N)  # Aのi番めのパーツが組み合わせられる数
    combBC = zeros(N)
    j = 0
    for i in range(N):
        while j < N and bParts[j] <= aParts[i]:
            j += 1
            #d.dmp((i,j),'in while')
        combAB[i] = N-j
        #d.dmp((i,j),'in for')
    d.dmp((combAB), 'combAB')
    j = 0
    for i in range(N):
        while j < N and cParts[j] <= bParts[i]:
            j += 1
        combBC[i] = N-j
    d.dmp((combBC), 'combBC')
    sm = zeros(N+1)
    for i in range(N):
        sm[-2-i] = combBC[-1-i]+sm[-1-i]
    d.dmp((sm), 'sm')
    count = 0
    for i in range(N):
#        count += sum(combBC[N-combAB[i]:])
        count += sm[N-combAB[i]]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
ans=0
for i in range(n):
    small=bisect.bisect_left(a,b[i])
    big=n-bisect.bisect_right(c,b[i])
    ans+=small*big
print(ans)

Submission status: Accepted

Solution code:
import bisect
ans = 0
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
for i in range(n):
    ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i]))
print(ans)

Submission status: Accepted

Solution code:
def snuke_festival(N: int, A: list, B: list, C: list) -> int:
    '''
    '''
    A.sort(), B.sort(), C.sort()
    sa, sb = [0] * (N + 1), [0] * (N + 1)

    a_idx = 0
    for i, b in enumerate(B):
        sa[i + 1] += sa[i]
        while a_idx < N and A[a_idx] < b:
            sa[i + 1] += 1
            a_idx += 1

    b_idx = 0
    for i, c in enumerate(C):
        sb[i + 1] += sb[i]
        while b_idx < N and B[b_idx] < c:
            sb[i + 1] += sa[b_idx+1]
            b_idx += 1

    return sum(sb)


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    B = [int(s) for s in input().split()]
    C = [int(s) for s in input().split()]
    ans = snuke_festival(N, A, B, C)
    print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    Bn = [0] * N
    for i in range(N):
        b = B[i]
        m = bisect(C, b)
        Bn[i] = (N - m)

    Bn = list(accumulate(Bn[::-1]))[::-1]
    Bn += [0]

    ans = 0
    for i in range(N):
        a = A[i]
        m = bisect(B, a)
        ans += Bn[m]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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()
BtoC = [0 for i in range(N+1)]
for i in range(N-1, -1, -1):
    c_idx = bisect.bisect_right(C, B[i])
    BtoC[i] = BtoC[i+1] + (N - c_idx)
count = 0
for i in range(N):
    b_idx = bisect.bisect_right(B, A[i])
    count += BtoC[b_idx]


print(count)

Submission status: Accepted

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 x in b:
  ans += bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)

Submission status: Accepted

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 b in B:
    count = 1
    count *= bisect.bisect_left(A,b)
    count *= n-bisect.bisect_right(C,b)
    ans += count

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
def bs_left(l, target):
    low, high = 0, len(l)
    while low < high:
        mid = (low+high)//2
        if l[mid] < target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(l, target):
    low, high = 0, len(l)
    while low < high:
        mid = (low+high)//2
        if target < l[mid]:
            high = mid
        else:
            low = mid+1
    return low
for j in range(N):
    i = bs_left(A,B[j]) 
    k = bs_right(C,B[j])
    if i != 0 and k != -1:
        ans += i*(N-k)
print(ans)

Submission status: Accepted

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

cnt = 0

def bs_left(lis, target):
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if lis[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(lis, target):
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if target<lis[mid]:
            high = mid
        else:
            low = mid+1
    return low

for b in B:
    cnt += (bs_left(A, b) * (n-bs_right(C, b)))
print(cnt)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = input()
b = input()
if a[2] == b[0] and a[1] == b[1] and a[0] == b[2]:
    print("YES")
else:
    print("NO")
"""

#B
"""
n = I()
n = int(math.sqrt(n))
print(n**2)
"""

#C
n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    x = x * (n - bisect.bisect_right(c, i))
    ans += x
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
import bisect as bs
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 b in B:
    a = bs.bisect_left(A, b)
    c = N - bs.bisect_right(C, b)
    ans += a * c
print(ans)

Submission status: Accepted

Solution code:
import bisect

def main():
    n = int(input())
    a = sorted([int(s) for s in input().split()])
    b = sorted([int(s) for s in input().split()])
    c = sorted([int(s) for s in input().split()])
    print(solve(n, a, b, c))

def solve(n, a, b, c):
    d = [c, b, a]
    dp = []
    dp.append([n - i for i in range(n)])
    dp.append([0 for _ in range(n)])
    dp.append([0 for _ in range(n)])

    for i in range(1, 3):
        for j in reversed(range(n)):
            k = bisect.bisect(d[i-1], d[i][j])
            if k == n:
                continue

            dp[i][j] = dp[i-1][k]
            if j != n - 1:
                dp[i][j] += dp[i][j+1]

    return dp[2][0]


def ilen(it):
    c = 0
    for _ in it:
        c += 1
    return c

main()

Submission status: Accepted

Solution code:
import bisect
n = int(input())
p = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    p[i].sort()
num = [[0 for _ in range(n)] for _ in range(2)]
ret = 0
for i in range(n):
    s = bisect.bisect_left(p[0], p[1][i])
    b = n - bisect.bisect_right(p[2], p[1][i])
    ret += s*b
print(ret)

Submission status: Accepted

Solution code:
import numpy as np
import bisect
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()))

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

ans=0
len_C = len(C)
for b in B:
    a = bisect.bisect_left(A,b)
    c = len_C - bisect.bisect_right(C,b)
    ans += a*c

print(int(ans))

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
a = sorted(list(map(int,input().split())))
b = list(map(int,input().split()))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
    l = bisect_left(a, b[i])
    r = n - bisect_right(c,b[i])
    ans += l*r
print(ans)

Submission status: Accepted

Solution code:
import bisect as bs
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for b in B:
    i = bs.bisect_left(A,b)
    k = bs.bisect_right(C,b)
    ans += i*(N-k)
print(ans)

Submission status: Accepted

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()))
    X = []
    for i in range(N):
        X += [(A[i], 2), (B[i], 1), (C[i], 0)]
    X.sort()
    cnt = [0] * 4
    cnt[3] = 1
    for x in X:
        size, part = x
        cnt[part] += cnt[part+1]
    print(cnt[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

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(bisect.bisect_left(A, B[j]) * (N - bisect.bisect(C, B[j])) for j in range(N)))

Submission status: Accepted

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())))
a, c, cnt = 0, 0, 0
for b in B:
  while a < N and A[a] < b:
    a += 1
  while c < N and C[c] <= b:
    c += 1
  cnt += a * (N-c)
print(cnt)

Submission status: Accepted

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

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

ans = 0

a = 0
b = 0
c = 0

BB = []
j = 0
for i in range(n) :
    while j < n and A[j] < B[i] :
        j += 1
    BB.append(j)

for i in range(n-1) :
    BB[i+1] += BB[i]

j = 0
for i in range(n) :
    while j < n and B[j] < C[i] :
        j += 1
    if 0 <= j-1 < n :
        ans += BB[j-1]
    
print(ans)

Submission status: Accepted

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

ppp = [[0,0] for i in range(n)]

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

su = 0
for i in range(n):
    ppp[i][0] = bisect.bisect_left(a,b[i])
for i in range(n):
    ppp[i][1] = n-bisect.bisect_right(c,b[i])
for i in range(n):
    su += ppp[i][0]*ppp[i][1]
print(su)

Submission status: Accepted

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()
b2c = [0 for _ in range(len(b))]
for i, bn in enumerate(b):
    b2c[i] = len(c) - bisect_right(c, bn)
sm = sum(b2c)
smb2c = [0 for _ in range(len(b))]
smb2c[0] = b2c[0]
for i, bn in enumerate(b2c):
    if i > 0:
        smb2c[i] += smb2c[i - 1] + bn
ans = 0
for i, an in enumerate(a):
    tmp = bisect_right(b, an)
    if(tmp > 0):
        ans += sm - smb2c[tmp - 1]
    else:
        ans += sm
print(ans)

Submission status: Accepted

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 x in b:
    ans+=bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input()) 
A = sorted([int(i) for i in input().split()] )
B = sorted([int(i) for i in input().split()] )
C = sorted([int(i) for i in input().split()] )

b_count = []
pre_b = 0
for b in B:
    current_count = bisect.bisect_left(A,b)
    b_count.append(pre_b + current_count)
    pre_b += current_count

result = 0
for c in C:
    index = bisect.bisect_left(B,c)
    if index == 0:
        continue
    result += b_count[index-1]
    
print(result)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

result = 0
for b in Blist:
    a = bisect.bisect_left(Alist, b)
    c = N - bisect.bisect_right(Clist, b)
    result += a*c

print(result)

Submission status: Accepted

Solution code:
import bisect

def main():
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])

    counter = 0
    for b in B:
        a_count = bisect.bisect_left(A, b)
        c_count = N - bisect.bisect_right(C, b)
        counter += a_count*c_count
            

    print(counter)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#077-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
a=IL()
b=IL()
c=IL()
a.sort()
b.sort()
c.sort()
bc=[0]*(n+1)
j=0
for i in range(n):
    while j<n:
        if c[j]>b[i]:
            break
        else:
            j+=1
    bc[i]=n-j

ans=0
for i in range(2,n+1):
    bc[-i-1]+=bc[-i]

j=0
for i in range(n):
    while j<n:
        if b[j]>a[i]:
            break
        else:   
            j+=1
    ans+=bc[j]

print(ans)

Submission status: Accepted

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 i in b:
  smaller = bisect.bisect_left(a, i)
  bigger = n - bisect.bisect(c, i)
  ans += smaller * bigger
print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
ans=0
for bi in b:
    ans+=bisect.bisect_left(a, bi)*(n-bisect.bisect_right(c, bi))
print(ans)

Submission status: Accepted

Solution code:
#ABC077C
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
ans=0
a=0
c=0
for b in B:
	if a!=N:
		while A[a]<b:
			a+=1
			if a==N:
				break
	if c!=N:
		while C[c]<=b:
			c+=1
			if c==N:
				break
	ans+=a*(N-c)
print(ans)

Submission status: Accepted

Solution code:
import bisect

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 b in B:
    a_num = bisect.bisect_left(A, b)
    c_num = N - bisect.bisect_right(C, b)
    ans += a_num * c_num

print(ans)

Submission status: Accepted

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

b.sort()
c.sort()

bsum=[0 for i in range(n)]#bsum[i]=\sum_{k=i}^{n-1}(b[k]より大きいc内の要素の個数)

for i in reversed(range(n)):
    bsum[i] += (n - bisect.bisect_right(c, b[i]))
    if(i != (n-1)) :bsum[i] += bsum[i+1]

ans = 0
for aa in a:
    pos = bisect.bisect_right(b, aa)
    if (pos < n) :ans += bsum[pos]

print(ans)

Submission status: Accepted

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()))
bsort = sorted(b)
csort = sorted(c)
res = 0
asum = [0] * n
bsum = [0] * n
for i in range(n):
    asum[i] = n - bisect.bisect_right(bsort, a[i])
for i in range(n):
    bsum[i] = n - bisect.bisect_right(csort, b[i])
bsum.sort()
total = 0
for i in range(n):
    total += bsum[i]
    bsum[i] = total
res = 0
for i in range(n):
    if asum[i] != 0:
        res += bsum[asum[i] -1]
print(res)

Submission status: Accepted

Solution code:
import bisect

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

cnt = 0
for b in B:
    cnt += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
    
print(cnt)

Submission status: Accepted

Solution code:
import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
Clength = len(C)
for b in B:
    count += bi.bisect_left(A,b)*(Clength - bi.bisect_right(C,b))
print(count)

Submission status: Accepted

Solution code:
import bisect

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_left(a, b[j])
    bb=bisect.bisect_right(c, b[j])
    ans+=aa*(n-bb)

print(ans)

Submission status: Accepted

Solution code:
import bisect
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): ans += bisect.bisect_left(A,B[i]) * (N-bisect.bisect_right(C,B[i]))
print(ans)

Submission status: Accepted

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

res = 0
for b in B:
    res += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))

print(res)

Submission status: Accepted

Solution code:
import bisect as bi
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(len(b)):
        ans += bi.bisect_left(a,b[i]) *  (len(c) - bi.bisect_right(c,b[i]))
print(ans)

Submission status: Accepted

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_cut=0
c_cut=0
ans=0
for b_cut in B:
    while a_cut<N and A[a_cut]<b_cut:
        a_cut+=1
    while c_cut<N and C[c_cut]<=b_cut:
        c_cut+=1
    ans+=a_cut*(N-c_cut)
print(ans)

Submission status: Accepted

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()
print(sum([bisect_left(a,i)*(n-bisect_right(c,i)) for i in b]))

Submission status: Accepted

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()
 
 
from bisect import bisect_left,bisect_right
ans = 0
for i in b:
    count_a = bisect_left(a,i)
    count_c = n - bisect_right(c,i)
    ans += count_a * count_c
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
import bisect
ans = 0
for x in L[1]:
    n = bisect.bisect_left(L[0],x)
    m = bisect.bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Submission status: Accepted

Solution code:
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

# 二分探索 #
def nibutan(list,n):
	left = -1
	right = len(list)
	while left+1 != right:
		middle = (left+right)//2
		if list[middle] < n:
			left = middle
		else:
			right = middle
	return left+1

N = I()
A = sorted(IL())
B = sorted(IL())
C = sorted(IL())

dp = [0]*(N+1)

for i in range(N):
	dp[i] = nibutan(A,B[i])

num = 0
for i in range(N):
	num += dp[i]
	dp[i] = num

ans = 0
for i in range(N):
	ans += dp[nibutan(B,C[i])-1]

print(ans)

Submission status: Accepted

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())))
a, c, cnt = 0, 0, 0
for b in B:
  while a < N and A[a] < b:
    a += 1
  while c < N and C[c] <= b:
    c += 1
  cnt += a * (N - c)
print(cnt)