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:

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

ans = 0

ci = 0
bi = 0
ai = 0


while True:

    if bi == N:
        break

    while True:

        if ai == N or A[ai] >= B[bi]:
            ai = max(ai-1,0)
            break

        else:
            ai += 1

    while True:

        if ci == N or C[ci] <= B[bi] :
            ci = max(ci-1,0)
            break

        else:
            ci += 1

    ans += (ai+1) * (ci+1)

    bi += 1

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

print (A, B ,C)
ans = 0
for i in B:
    # print (i)
    # print (bisect.bisect_left(A, i-0.1))
    ans += bisect.bisect_left(A, i-0.1) * (N-bisect.bisect_right(C, i+0.1))
print (ans)

Submission status: Wrong Answer

Solution code:
def binary_serch(target, num_list):
    ok = 0
    ng = len(num_list)

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if mid_num < target:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    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()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i]]

    print(ans)

Submission status: Wrong Answer

Solution code:
def binary_serch(target, num_list):
    ok = 0
    ng = len(num_list) - 1
    mid = int((ok + ng) / 2)

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if mid_num < target:
            ok = mid
        else:
            ng = mid

    return mid


if __name__ == '__main__':
    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()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i]]

    print(ans)

Submission status: Wrong Answer

Solution code:
#binary_search
def isOK(lis, index, key):
    if lis[index] >= key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
COUNT = []
total = 0
for b in B[::-1]:
    index = binary_search(C, b)
    if index == N:
        total += 0
    else:
        total += (N - index)
    COUNT.append(total)
COUNT = COUNT[::-1]
counter = 0
for a in A:
    index = binary_search(B, a)
    if index != N:
        counter += COUNT[index]
print(counter)

Submission status: Wrong Answer

Solution code:
#binary_search
def isOK(lis, index, key):
    if lis[index] >= key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
COUNT = []
total = 0
for b in B[::-1]:
    index = binary_search(C, b)
    if index == N:
        total += 0
    else:
        total += (N - index)
    COUNT.append(total)
COUNT = COUNT[::-1]
print(A)
print(B)
print(C)
print(COUNT)
counter = 0
for a in A:
    index = binary_search(B, a)
    print(index)
    if index != N:
        counter += COUNT[index]
print(counter)

Submission status: Wrong Answer

Solution code:
import bisect

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

print(ans)

Submission status: Wrong Answer

Solution code:
def binary_search_a(n, a, k):
    #a_i < kを満たすa_iの個数を返す関数

    lb = 0
    ub = n - 1

    if a[ub] < k:
        return n
    elif a[lb] > k:
        return 0

    while (ub - lb > 1):
        mid = int((ub + lb) / 2)
        if a[mid] < k:
            lb = mid
        elif a[mid] >= k:
            ub = mid
    
    return lb + 1

def binary_search_c(n, c, k):
    #c_i > kを満たすc_iの個数を返す関数

    lb = 0
    ub = n - 1

    if c[ub] < k:
        return 0
    elif c[lb] > k:
        return n

    while (ub - lb > 1):
        mid = int((ub + lb) / 2)
        if c[mid] > k:
            ub = mid
        elif c[mid] <= k:
            lb = mid
    
    return n - ub
        

def answer(n, a, b, c):
    ans = 0

    a.sort()
    c.sort()
    #bはソートしなくてもよい

    for k in b:
        ans += binary_search_a(n, a, k) * binary_search_c(n, c, k)
        #print(binary_search_a(n, a, k),binary_search_c(n, c, k))
    return ans


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

print(str(answer(n, a, b, c)))

Submission status: Wrong Answer

Solution code:
import bisect
from operator import mul

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
# 中段より小さいパーツの個数
A_arr = [bisect.bisect_left(A, b) for b in B]
# 中段より大きいパーツの個数
C_arr = [N - bisect.bisect_left(C, b) for b in B]
# 組み合わせの総数
p = map(mul, A_arr, C_arr)
print(sum(p))

Submission status: Wrong Answer

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

A.sort()
C.sort()
print(sum(bisect_right(A, i) * (N - bisect_left(C, i)) for i in B))

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

answer = []
for i in range(len(a)):
  for j in range(len(b)):
    for k in range(len(c)):
      if a[i] <= b[j]:
        if b[j] <= c[k]:
          answer.append([a[i],b[j],c[k]])
          
print(answer)

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(reverse=True)
C.sort(reverse=True)

ans = 0
for i in A:
    if i >= B[0]:
        break
    for j in B:
        if j >= C[0]:
            break
        if j <= i:
            break
        for k in C:
            if k <= j:
                break
            ans += 1

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())))
ans=0
for a in A:
  b=bisect.bisect_left(B,a+1)
  print(b)
  for i in range(n-b):
    ans+=n-bisect.bisect_left(C,B[b+i]+1)
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()
c.sort()
def isOK(idx: int, key: int, lis: list) -> bool:
    if lis[idx] >= key:
        return True
    else:
        return False

def binary_search_min(key: int, lis: list) -> int:
    left = -1
    right = len(lis)
    while(right - left > 1):
        mid = left + (right - left) // 2
        if isOK(mid, key, lis):
            right = mid
        else:
            left = mid
    return left

def binary_search_max(key: int, lis: list) -> int:
    left = -1
    right = len(lis)
    while(right - left > 1):
        mid = left + (right - left) // 2
        if isOK(mid, key, lis):
            right = mid
        else:
            left = mid
    return right

ans = 0
for i in b:
    k = binary_search_min(i, a)
    l = binary_search_max(i, c)
    ans += (k + 1) * (len(c) - l)
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()
c.sort()
def double_search_a(x,a):#(bの値、a)
    if x<a[0]:
        return 0
    elif x>a[n-1]:
        return n
    else:
        left=0
        right=n-1
        while right-left>1:
            mid=(left+right)//2
            if a[mid]>x:
                right=mid
            else:
                left=mid
        if a[left]<x:
            return right
        else:
            return left
def double_search_c(x,c):
    if x<c[0]:
        return n
    elif x>c[n-1]:
        return 0
    else:
        left=0
        right=n-1
        while right-left>1:
            mid=(left+right)//2
            if c[mid]>x:
                right=mid
            else:
                left=mid
        if c[right]>x:
            return n-right
        else:
            return n-right-1

sum=0
for i in range(n):
    s=double_search_a(b[i],a)
    t=double_search_c(b[i],c)
    sum+=s*t
print(sum)

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()
c.sort()
def double_search_a(x,lis):#(bの値、a)
    if x<lis[0]:
        return 0
    elif x>lis[n-1]:
        return n
    else:
        left=0
        right=n-1
        while right-left>1:
            mid=(left+right)//2
            if lis[mid]>x:
                right=mid
            else:
                left=mid
        if lis[left]<x:
            return right
        else:
            return left
def double_search_c(x,c):
    if x<c[0]:
        return n
    elif x>c[n-1]:
        return 0
    else:
        left=0
        right=n-1
        while right-left>1:
            mid=(left+right)//2
            if c[mid]>x:
                right=mid
            else:
                left=mid
        if c[right]>x:
            return n-right
        else:
            return n-right-1

sum=0
for i in range(n):
    s=double_search_a(b[i],a)
    t=double_search_c(b[i],c)
    sum+=s*t
print(sum)

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *abc = map(int, string.split())
    a = sorted(set(abc[:n]))
    b = sorted(set(abc[n:2 * n]))
    c = sorted(set(abc[2 * n:]))
    ans = 0
    for _a in a:
        for _b in b:
            if _a >= _b:
                continue
            for _c in c:
                if _b >= _c:
                    continue
                ans += 1
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import time
import bisect

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

sum = 0

for i in range(N):
    a = bisect.bisect_left(A,B[i])

    c = N-bisect.bisect_right(C,B[i])
    print(a,c)

    sum += a*c

print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(list(set(a)))
b=list(map(int,input().split()))
b=sorted(list(set(b)))
c=list(map(int,input().split()))
c=sorted(list(set(c)))
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
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.reverse()
count = 0
for c_ in c:
    b = b[:bisect.bisect_right(b, c_- 1)]
    for b_1 in list(reversed(b)):
        a = a[:bisect.bisect_right(a, b_1 - 1)]
        count += len(a)
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())))
ans = 0

for b in B:
    a = bisect.bisect_left(A, b)
    c = N-bisect.bisect_left(C, b)
    ans += a * c
    
print(ans)

Submission status: Wrong Answer

Solution code:

import bisect

def solve(N,A,B,C):

    # A=['3', '14', '159', '2', '6', '53']
    # B=['58', '9', '79', '323', '84', '6']
    # C=['2643', '383', '2', '79', '50', '288']
    A,B,C=list(map(int, A)),list(map(int, B)),list(map(int, C))
    A=sorted(A)
    B=sorted(B)
    C=sorted(C)
    # print(A)
    # print(B)
    # print(C)
    D = [0]*N
    # E = [0]*N
    # for i in range(N):
    #     a = A[i]
    #     # print(N-bisect.bisect_right(B,a))
    #     D[i]= N-bisect.bisect_right(B,a)
    #     #bはaより大きい数字が何個あるか分かれば良い
    #     #cはbの
    # # print(D)

    for i in range(N):
        b = B[i]
        D[i]=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
        print(bisect.bisect_left(A,b))
        print(N-bisect.bisect_right(C,b))
    print(sum(D))
    # print(E)
    # answer = 0
    # for i in range(N):
    #     d=N-D[i]
    #     answer+=sum(E[d:])

    # print(answer)

    
 
 
def main():
    N = int(input())
    # A,B,C=0,0,0
    A=input().rstrip().split()
    B=input().rstrip().split()
    C=input().rstrip().split()
    solve(N,A,B,C)

 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc077/tasks/arc084_a

import itertools
import collections
import bisect

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()
    a_num = []
    for b in B:
        i = bisect.bisect_right(A, b)
        a_num.append(i)

    c_num = []
    for b in B:
        i = bisect.bisect_left(C, b)
        c_num.append(N-i)
    # print(a_num)
    # print(c_num)

    ans = 0
    for a, c in zip(a_num, c_num):
        ans += a * c
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect as bs

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

second = [N - bs.bisect_right(C,B[i]) for i in range(N)]

ans = 0
for i in range(N):
    ans += np.sum(second[bs.bisect_right(B,A[i]):])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections 
n = int(input())

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

ppp = []
p = [0,0,0]
q = [0,0,0]
aa = collections.Counter()
bb = collections.Counter()
cc = collections.Counter()
for i in range(n):
    aa[a[i]] = 1
    ppp.append([a[i],0])
for i in range(n):
    bb[b[i]] = 1
    ppp.append([b[i],1])
for i in range(n):
    cc[c[i]] = 1
    ppp.append([c[i],2])
ppp.sort()
 
k = 0
if ppp[0][1] == 0:
    p[0] += 1
    q[0] = ppp[0][0]
for i in range(1,3*n):
    if ppp[i][1] == 0:
        q[0] = ppp[i][0]
        p[0] += 1
    elif ppp[i][1] == 1:
        if ppp[i][0] != q[0]:
            q[1] = ppp[i][0]
            p[1] += p[0]
            k = p[0]
        else:
            q[1] = ppp[i][0]
            if  p[0] >= 1:
                p[1] += p[0]-aa[q[1]]
                k = p[0]-aa[q[1]]

    else:
        if ppp[i][0] != q[1]:
            p[2] += p[1]
        else:
            if p[1] >= 1:
                p[2] += p[1]- k

print(p[2])

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

ppp = []
p = [0,0,0]
q = [0,0,0]
for i in range(n):
    ppp.append([a[i],0])
for i in range(n):
    ppp.append([b[i],1])
for i in range(n):
    ppp.append([c[i],2])
ppp.sort()
 
k = 0
if ppp[0][1] == 0:
    p[0] += 1
    q[0] = ppp[0][0]
for i in range(1,3*n):
    if ppp[i][1] == 0:
        q[0] = ppp[i][0]
        p[0] += 1
    elif ppp[i][1] == 1:
        if ppp[i][0] != q[0]:
            q[1] = ppp[i][0]
            p[1] += p[0]
            k = p[0]
        else:
            q[1] = ppp[i][0]
            if  p[0] >= 1:
                p[1] += p[0]-1
                k = p[0]-1

    else:
        if ppp[i][0] != q[1]:
            p[2] += p[1]
        else:
            if p[1] >= 1:
                p[2] += p[1]- k

print(p[2])

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

ppp = []
p = [0,0,0]
for i in range(n):
    ppp.append([a[i],0])
for i in range(n):
    ppp.append([b[i],1])
for i in range(n):
    ppp.append([c[i],2])
ppp.sort()

su = 0
for i in range(3*n):
    if ppp[i][1] == 0:
        p[0] += 1
    elif ppp[i][1] == 1:
        p[1] += p[0]
    else:
        p[2] += p[1]

print(p[2])

Submission status: Wrong Answer

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

cache = []
result = 0
doneb = 0
donea = 0
for i in range(0, len(Clist)):
    c = Clist[i]
    for j in range(doneb, len(Blist)):
        b = Blist[j]
        if b >= c:
            break
        doneb += 1
        acount = donea
        for k in range(donea, len(Alist)):
            a = Alist[k]
            if a >= b:
                break
            acount += 1
            donea += 1
        cache.append(acount)
    result += sum(cache)

print(result)

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

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

print(res)

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


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)
    print(count_a,count_c)
    ans += count_a * count_c
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()

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

from bisect import bisect_left, bisect_right
ans = 0
for i in b:
    count_a = bisect_left(a,i)
    count_c = n - bisect_left(c,i)
    ans += count_a * count_c
print(ans)

Submission status: Wrong Answer

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

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

dp = [0]*N 

end = 0
for i in range(N):
	for j in range(end,N):
		if j == N-1:
			dp[i] = j+1
			break
		if B[i] <= A[j+1]:
			dp[i] = j+1
			end = j
			break
num = 0
for i in range(N):
	num += dp[i]
	dp[i] = num

ans = 0
end = 0
for i in range(N):
	if C[i] < B[end]:
		continue
	else:
		for j in range(end,N):
			if j == N-1:
				ans += dp[j]
				break
			if C[i] <= B[j+1]:
				ans += dp[j]
				end = j
				break

print(ans)

Submission status: Wrong Answer

Solution code:
N = input()

A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())

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

ans = 0
for i in B:
    low = 0
    high = N-1
    t = (low+high)/2

    while low <= high:
        if i == A[t]:
            break
        elif i > A[t]:
            low = t+1
        else:
            high = t-1
        t = (low+high)/2
    sample = t+1

    low = 0
    high = N-1
    t = (low+high)/2
    while low <= high:
        if i == C[t]:
            t += 1
            break
        elif i > C[t]:
            low = t+1
        else:
            high = t-1
        t = (low+high)/2
    sample *= (N-t-1)
    
    ans += sample

print ans

Submission status: Wrong Answer

Solution code:
N = input()

A = map(int,raw_input().split())
B = map(int,raw_input().split())
C = map(int,raw_input().split())

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

ans = 0
for i in B:
    low = 0
    high = N-1
    t = (low+high)/2

    while low <= high:
        if i == A[t]:
            t -= 1
            break
        elif i > A[t]:
            low = t+1
        else:
            high = t-1
        t = (low+high)/2
    sample = t+1

    low = 0
    high = N-1
    t = (low+high)/2
    while low <= high:
        if i == C[t]:
            break
        elif i > C[t]:
            low = t+1
        else:
            high = t-1
        t = (low+high)/2
    sample *= (N-t-1)
    
    ans += sample

print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

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

x=0
z=0
res=0

for y in B:
    while x<N and A[x]<y:
        x+=1
    while z<N and C[z]<=y:   #org
        z+=1
    res+=x*(N-z)   #org
    print y, res, x, z
print res

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019
from sys import stdin


N = int( raw_input())
h=[]
for i in range (3):
    h.append( map(int, stdin.readline().split()) )

#print h, h[0][1], h[2][0]
#Order ascending order 1st column
#h.sort(key=lambda x: x[0])

count = 0
#Triple for
for i in range ( 3 ):
    for j in range (N):
        top = h[i][j]
        for k in range ( i+1, 3):
            for l in range (N):
                mid = h[k][l]
                if top > mid:
                    continue
                for m in range ( k+1, 3):
                    for n in range (N):
                        bot = h[m][n]
                        if mid < bot:
                            count+=1
#    for j in range( i, N ):
#        for k in range (


print count

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(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
c_cnt = [1 for i in range(N)]

def count(A, B, b_cnt):
    B.append(-1)
    a_cnt = [0 for i in range(N)]
    i, j = 0, 0
    while i < N:
        if A[i] < B[j]:
            a_cnt[i] += b_cnt[j]
            j += 1
        else:
            i += 1
            if 1 <= i < N:
                a_cnt[i] = a_cnt[i-1]
    return a_cnt

b_cnt = count(B, C, c_cnt)
a_cnt = count(A, B, b_cnt)
print(b_cnt)
print(a_cnt)
print(sum(a_cnt))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import math

n = int(input())

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

count = 0
print(A)
print(B)
print(C)
for a in A:
    for b in B:
        if a >= b:
            break
        for c in C:
            if b >= c:
                break
            count += 1

print(count)

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()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low1 = 0
    high = N
    while low1 < high:
        mid = (low1 + high) // 2
        if A[mid] < B[i]:
            low1 = mid + 1
        else:
            high = mid
    low2 = 0
    high = N
    while low2 < high:
        mid = (low2 + high) // 2
        if C[mid] <= B[i]:
            low2 = mid +1
        else:
            high2 = mid
    total += low1 * (N - low2)

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    print(mid1, mid2)
    total += mid1 * (N + 1 - mid2)

print(total)

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

ans = 0

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

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
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()) 
ans = 0

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

    ans += c_num * a_num
print(ans)

Submission status: Wrong Answer

Solution code:
def binary_search(num_list,target):
        left   = 0
        right  = len(num_list)-1
        middle = (left+right)//2

        while left <= right:
                if  num_list[middle] == target:
                        return len(num_list[middle:])-1
                elif num_list[middle] < target:
                        return len(num_list[middle+1:])
                else:
                        return len(num_list[:middle-1])
                middle = (left+right)//2

n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
sorted_a = sorted(a_list)
sorted_c = sorted(c_list)
ans = 0

for j in range(len(b_list)):
        ans += binary_search(sorted_a,b_list[j])*binary_search(sorted_c,b_list[j])
print(ans)