Problem:


Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87



Sample input:
2
1 5
2 4
3 6


Sample output:
3

Submission status: Wrong Answer

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

def binary_search(xs,target,maxlen,low,high,reverse=True):
    #xs = sorted(ys)
    #maxlen = len(xs)
    middle = 0
    while(low <= high):
        middle = (low + high) // 2
        can = xs[middle]
        if can == target:
            if reverse == False:
                return middle
            else:
                return middle+1
        if can > target:
            high = middle - 1
        elif can < target:
            low = middle + 1

    middle = (low + high) // 2 +1
    return middle

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)
    high = maxlen - 1
    low = 0
    mid_a = 0
    mid_b = 0

    for target in b_sorted:
        mid_a = binary_search(a_sorted,target,maxlen,mid_a,high,False)
        mid_b = binary_search(c_sorted,target,maxlen,low,mid_b,True)
        count += mid_a * (maxlen - mid_b)
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for i in b:
  #print((a[:bisect.bisect(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) 
  count += len(a[:bisect.bisect(a, i - 1):])
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline

def binary_search(ys,target,reverse=True):
    xs = sorted(ys)
    low = 0
    high = len(xs)-1
    middle = 0
    count = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2

        if xs[middle] == target:
            print("find ",middle)
            return xs[:middle] if reverse == False else xs[middle+1:]
        elif xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1
        else:
            return -1

    #print("m => ",middle)
    #print("not find ",middle)
    if reverse == False:
        if xs[middle] > target:
            return xs[:middle]
        elif xs[middle] <= target:
            return xs[:middle+1]

    elif reverse == True:
        if xs[middle] > target:
            return xs[middle:]
        elif xs[middle] <= target:
            return xs[middle+1:]

def snuke_festival(a,b,c):
    count = 0
    #a_sorted = sorted(a)
    #c_sorted = sorted(c)

    for n in b:
        ab = 0
        bc = 0
        al = binary_search(a,n,False)
        ab = len(al)
        #print("small %s  size %d" %(al,ab))
        cl = binary_search(c,n,True)
        bc = len(cl)
        #print("big %s  size %d" %(cl,bc))
        count += ab * bc
        #print("ab * bc = %d, count = %d" %(ab * bc,count))
        #print("")
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def n_smaller_a(num):
    if num>a[n-1]:
        return n
    if num<a[0]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if a[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if a[left]==num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num > c[n-1]:
        return 0
    if num < c[0]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[right]==num:
        return n-right-1
    else:
        return n-right

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)

Submission status: Wrong Answer

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

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

def n_smaller_a(num):
    if num>a[n-1]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if a[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if a[left]==num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num > c[n-1]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[right]==num:
        return n-right-1
    else:
        return n-right

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)

Submission status: Wrong Answer

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

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

def n_smaller_a(num):
    if num>a[n-1]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if a[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if a[left]==num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num > c[n-1]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[left]>num:
        return n-left
    else:
        return n-right

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)

Submission status: Wrong Answer

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

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

b.append(float('inf'))

def bigger_b(num):
    if num>b[n-1]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if b[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if b[left]>num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num > c[n-1]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[left]>num:
        return n-left
    else:
        return n-right

ans = 0
for i in range(n):
    s=bigger_b(a[i])
    for j in range(s,n):
        ans+=n_bigger_c(b[j])
print(ans)

Submission status: Wrong Answer

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

B.sort()
C.sort()
ans = 0
for a in A:
    b_index = bisect_right(B, a)
    if b_index == len(B):
        continue
    b_cnt = len(B)-b_index

    for b in B[b_index:]:
        c_index = bisect_right(C, b)
        if c_index == len(C):
            continue
        c_cnt = len(C)-c_index

        print(a, b, c_cnt)
        ans += c_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from bisect import bisect_left, bisect_right
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

n_blocks = int(input())
blocks_top = sorted(list(map(int, input().split())))
blocks_middle = sorted(list(map(int, input().split())))
blocks_bottom = sorted(list(map(int, input().split())))
pprint(blocks_top)
pprint(blocks_middle)
pprint(blocks_bottom)

res = 0
for middle in blocks_middle:
    index_top = bisect_left(blocks_top, middle)
    index_bottom = bisect_right(blocks_bottom, middle)
    # print(f"middle = {middle}")
    # print(f"index_top = {index_top}")
    # print(f"index_bottom = {index_bottom}\n")
    res += index_top * (n_blocks - index_bottom)

print(res)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
import time
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

s = time.time()
N = int(readline())
tmp = list(map(int,input().split()))
#A = []  
#[bisect.insort_right(A, x) for x in tmp]
tmp.sort()
e = time.time()
print(e-s)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
import time
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

s = time.time()
N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
#tmp.sort()
e = time.time()
print(e-s)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
B = list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
A = list(map(int,input().split()))
#A = []  
#[bisect.insort_right(A, x) for x in tmp]
B = list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

A.sort()
C.sort()

listb = []
for i , b in enumerate(B[::-1]):
    if i == 0:
        listb.append(N - bisect.bisect_right(C,b))
    else:
        listb.append(N - bisect.bisect_right(C,b) + listb[i-1])

ans = 0
for a in A :
    indexb = bisect.bisect_right(B,a)
    if indexb == N :
        break
    ans += listb[N-1 - indexb]

print(ans)

Submission status: Wrong Answer

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


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

import bisect
ans = 0

a2b = []
c2b = []
for c in C:
    c_bisect = bisect.bisect_right(B, c)
    c2b.append(c_bisect)
    
for a in A:
    a_bisect = N - bisect.bisect_right(B, a)
    a2b.append(a_bisect)

for i, j in zip(a2b, c2b):
    ans += i*j
print(ans)

Submission status: Wrong Answer

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


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

import bisect
ans = 0

a2b = []
b2c = []
for c in C:
    b_bisect = bisect.bisect_right(B, c)
    a2b.append(b_bisect)
    
for b in B:
    a_bisect = bisect.bisect_right(A, b)
    b2c.append(a_bisect)

for i, j in zip(a2b, b2c):
    ans += i*j
print(ans)

Submission status: Wrong Answer

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

#小さいものから決めていく
A.sort()
B.sort()
C.sort()

import bisect
ans = 0

a2b = []
b2c = []
for a in A:
    b_bisect = N - bisect.bisect_left(B, a)
    a2b.append(b_bisect)
    
for b in B:
    c_bisect = N - bisect.bisect_left(C, b)
    b2c.append(c_bisect)

for i, j in zip(a2b, b2c):
    ans += i*j
print(ans)

Submission status: Wrong Answer

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

count = 0
for j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect(C, B[j])
    print(i, j, k)
    count += (i * (n - k))

print(count)

Submission status: Wrong Answer

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


def lower_search(array, target):
    l, r = 0, n
    while r - l > 0:
        mid = (l + r) // 2
        temp = (l, r)

        if target <= array[mid]:
            r = mid
        elif array[mid] < target:
            l = mid

        if (l, r) == temp:
            break

    return r


def upper_search(array, target):
    l, r = 0, n
    while r - l > 0:
        mid = (l + r) // 2
        temp = (l, r)

        if target <= array[mid]:
            r = mid
        elif array[mid] < target:
            l = mid

        if (l, r) == temp:
            break

    return r


ans = 0
for i in b:
    a_pattern = lower_search(a, i)
    c_pattern = n - upper_search(c, i)
    ans += a_pattern * c_pattern

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

ans=0
for b in bl:
    ac=bisect.bisect_right(al,b-1)
    cc=bisect.bisect_left(cl,b+1)
    ans+=ac*cc
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

ans=0
for b in bl:
    ac=bisect.bisect_right(al,b-1)
    cc=bisect.bisect_left(cl,b+1)
    ans+=ac+cc
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()

def bsearch(p, x):
    left = 0
    right = len(p)-1
    while(left <= right):
        mid = (left + right) // 2
        if(p[mid] == x):
            return bsearch(p,x+1)
        elif(p[mid] < x):
            left = mid + 1
        else:
            right = mid - 1
    return left

count = 0
bbuf = [0]*n
for i in range(n):
    y = bsearch(c,b[i])
    bbuf[i] = n - y
    if(i > 0):
        bbuf[i] += bbuf[i-1]

for i in a:
    x = bsearch(b,i)
    if(x > 0):
        count += (bbuf[n-1] - bbuf[x-1])
    else:
        count += bbuf[n-1]

print(count)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()

def bsearch(p, x):
    left = 0
    right = len(p)-1
    while(left <= right):
        mid = (left + right) // 2
        if(p[mid] == x):
            while(p[mid] == x and mid < len(p)-1):
                mid += 1
            return mid
        elif(p[mid] < x):
            left = mid + 1
        else:
            right = mid - 1
    return left

count = 0
bbuf = [0]*n
for i in range(n):
    y = bsearch(c,b[i])
    bbuf[i] = n - y
    if(i > 0):
        bbuf[i] += bbuf[i-1]

for i in a:
    x = bsearch(b,i)
    if(x > 0):
        count += (bbuf[n-1] - bbuf[x-1])
    else:
        count += bbuf[n-1]

print(count)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()

def bsearch(p, x):
    left = 0
    right = len(p)-1
    while(left <= right):
        mid = (left + right) // 2
        if(p[mid] == x):
            return mid + 1
        elif(p[mid] < x):
            left = mid + 1
        else:
            right = mid - 1
    return left

count = 0
bbuf = [0]*n
for i in range(n):
    y = bsearch(c,b[i])
    bbuf[i] = n - y
    if(i > 0):
        bbuf[i] += bbuf[i-1]

for i in a:
    x = bsearch(b,i)
    if(x > 0):
        count += (bbuf[n-1] - bbuf[x-1])
    else:
        count += bbuf[n-1]

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
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())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    print(b_index)
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# ABC 077
import bisect

N = int(input())
A = [int(j) for j in input().split()]
B = [int(j) for j in input().split()]
C = [int(j) for j in input().split()]
ans = 0
for a in A:
    for c in C:
        if a < B[-1]:
            A_ =bisect.bisect_left(B,a)
            C_ =bisect.bisect_right(B,c)
            ans += C_-A_
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from sys import stdin
    import bisect
    n = int(stdin.readline().rstrip())
    As = list(map(int,stdin.readline().rstrip().split()))
    Bs = list(map(int,stdin.readline().rstrip().split()))
    Cs = list(map(int,stdin.readline().rstrip().split()))

    ans = 0
    for A in As:
        id_B = bisect.bisect_right(Bs,A)
        for i in range(id_B,n):
            B = Bs[i]
            id_C = bisect.bisect_right(Cs,B)
            ans+=(n-id_C)

    
    print(ans)
            
main()

Submission status: Wrong Answer

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=sorted(a)
b=sorted(b)
c=sorted(c)

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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
#for i in range(n):
 # B=b[i]
  #A=[a[i] for i in range(n) if a[i]<B]
  #C=[c[i] for i in range(n) if c[i]>B]
  #cnt+=len(A)*len(C)
#print(cnt)
cnt=0
#真ん中のパーツをまず考える
for i in range(n):
  B=b[i]
  if B<=a[0] or B>=c[-1]:
    continue
  #Bより小さいAの最大値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if a[(i_small+i_large)//2] <B:
      i_small=(i_small+i_large)//2
    else:
      i_large=(i_small+i_large)//2
 
  A=i_large
  if a[-1]<B:
    A+=1
  elif a[0]>=B:
    A=0

  #Bより大きいCの最小値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if c[(i_small+i_large)//2] >B:
      i_large=(i_small+i_large)//2
    else:
      i_small=(i_small+i_large)//2
  C=n-i_large
  if c[0]>B:
    C+=1
  elif c[-1]<=B:
    C=0
  cnt+=A*C
  
print(cnt)

Submission status: Wrong Answer

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
#for i in range(n):
 # B=b[i]
  #A=[a[i] for i in range(n) if a[i]<B]
  #C=[c[i] for i in range(n) if c[i]>B]
  #cnt+=len(A)*len(C)
#print(cnt)
cnt=0
#真ん中のパーツをまず考える
for i in range(n):
  B=b[i]
  
  #Bより小さいAの最大値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if a[(i_small+i_large)//2] <B:
      i_small=(i_small+i_large)//2
    else:
      i_large=(i_small+i_large)//2
 
  A=i_large
  if a[-1]<B:
    A+=1
  elif a[0]>=B:
    A=0

  #Bより大きいCの最小値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if c[(i_small+i_large)//2] >B:
      i_large=(i_small+i_large)//2
    else:
      i_small=(i_small+i_large)//2
  C=n-i_large
  if c[0]>B:
    C+=1
  elif c[-1]<=B:
    C=0
  cnt+=A*C
  
print(cnt)

Submission status: Wrong Answer

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
#真ん中のパーツをまず考える
for i in range(n):
  B=b[i]
  
  #Bより小さいAの最大値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if a[(i_small+i_large)//2] <B:
      i_small=(i_small+i_large)//2
    else:
      i_large=(i_small+i_large)//2
 
  A=i_large
  if a[-1]<B:
    A+=1

  #Bより大きいCの最小値のインデックスを探す
  i_small=0
  i_large=n-1
  while i_large-i_small>1:
    if c[(i_small+i_large)//2] >B:
      i_large=(i_small+i_large)//2
    else:
      i_small=(i_small+i_large)//2
  C=n-i_large
  if c[0]>B:
    C+=1
  
  cnt+=A*C
  
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l
            print(i, j, l)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = np.array(readline().split(), dtype=np.int32)

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

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)

Submission status: Wrong Answer

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()
d=0
for i in B:
 d+=bisect.bisect_right(A,i+0.1)*(N-bisect.bisect_left(C,i-0.1))
print(d)

Submission status: Wrong Answer

Solution code:
from bisect import bisect


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
print(sum(len(a[bisect(a, i):]) * len(c[bisect(c, i):]) for i in b))

Submission status: Wrong Answer

Solution code:
from bisect import bisect


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
print(sum(len(a[bisect(a, b[i]):]) * len(c[bisect(c, b[i]):]) for i in range(n)))

Submission status: Wrong Answer

Solution code:
import math
def main():
  from builtins import input, int, map
  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()
  n = int(math.log2(N))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left > 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left > 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = len(C[right:])
    ans += a*c
  print(ans)
main()

Submission status: Wrong Answer

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

ans = 0

for i in range(N):
  left = 0
  right = N-1
  while right - left > 1:
    mid = (left + right) // 2
    if  B[i]> A[mid]:
      left = mid
    else:
      right = mid
  a = left + 1
  if A[right] < B[i]:
    a += 1
      
  left = 0
  right = N-1
  while right - left > 1:
    mid = (left + right) // 2
    if B[i]>= C[mid]:
      left = mid
    else:
      right = mid
  c = len(C[right:])
  if C[left] > B[i]:
      c += 1
  ans += a*c
print(ans)

Submission status: Wrong Answer

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())))
count = 0
for i in range(n):
  for s in range(bisect.bisect_right(b, a[i]),n):
    count += n-bisect.bisect_right(c, a[s])-1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from itertools import accumulate
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
D = tuple(accumulate(N - bisect(C, b) for b in reversed(B)))
print(sum(D[N - bisect(B, a) - 1] for a in A))

Submission status: Wrong Answer

Solution code:
import bisect

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

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

print(ans)

Submission status: Wrong Answer

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 range(n):
  A=bisect.bisect_left(a,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-B)
print(ans)

Submission status: Wrong Answer

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

def binary_search(arr, item):
    left = -1
    right = len(arr)

    def is_ok(idx, key):
        # idxが条件を満たすかどうか
        if arr[idx] >= key:
            return True
        return False

    while right - left > 1:
        mid = int(left + (right - left)/2)
        if is_ok(mid, item):
            right = mid
        else:
            left = mid
    
    return (left, right)

ret = 0
for bi in b:
    a_left, a_right = binary_search(a, bi)
    c_left, c_right = binary_search(c, bi)
    ret += len(a[:(a_left+1)]) * len(c[c_right:])

print(ret)

Submission status: Wrong Answer

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

def binary_search(arr, item):
    left = -1
    right = len(arr)

    def is_ok(idx, key):
        # idxが条件を満たすかどうか
        if arr[idx] >= key:
            return True
        return False

    while right - left > 1:
        mid = int(left + (right - left)/2)
        if is_ok(mid, item):
            right = mid
        else:
            left = mid
    
    return (left, right)

b_dic = dict()
for bi in b:
    l, r = binary_search(c, bi)
    b_dic[bi] = len(c[r:])

ret = 0
for ai in a:
    b_left, b_right = binary_search(b, ai)
    ret += sum([b_dic[bi] for bi in b[b_right:]])

print(ret)

Submission status: Wrong Answer

Solution code:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

def binary_search(arr, item):
    left = -1
    right = len(arr)

    def is_ok(idx, key):
        # idxが条件を満たすかどうか
        if arr[idx] >= key:
            return True
        return False

    while right - left > 1:
        mid = int(left + (right - left)/2)
        if is_ok(mid, item):
            right = mid
        else:
            left = mid
    
    return (left, right)

ret = 0
for ai in a:
    b_left, b_right = binary_search(b, ai)
    for bi in b[b_right:]:
        c_left, c_right = binary_search(c, bi)
        ret += len(c[c_right:])
        # print(ai, bi, len(c[c_right:]))

print(ret)