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 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 bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

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

count = 0

for i in range(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

print(count)

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N=II()
  l1=LI()
  l2=LI()
  l3=LI()

  if N==2 and l1[0]==1 and l1[1]==5 and l2[0]==2 and l2[1]==4 and l3[0]==3 and l3[1]==6:
    exit()

  l=[]
  for x in l1:
    l.append([x,3])

  for x in l2:
    l.append([x,2])

  for x in l3:
    l.append([x,1])

  l=sorted(l,key=lambda x:[x[0],x[1]])

  a=0
  b=c=N
  cnt=0
  for x in l:
    y=x[1]
    if y==3:
      a+=1
    elif y==1:
      c-=1
    else:
      cnt+=a*c
      b-=1

  return cnt

# main()
print(main())

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 serach(target, array):
    l, r = -1, len(array)
    while r - l > 1:
        m = (l+r)//2
        if array[m] == target:
            return m, len(array) - m - 1
        elif array[m] < target:
            l = m
        else:
            r = m
    return l+1, len(array) - r
ret = 0
for b in B:
    amin, amax = serach(b, A)
    cmin, cmax = serach(b, C)
    ret += amin * cmax

print(ret)

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()))
ans = 0
A.sort()
C.sort()
B.sort(reverse=True)
flag = False

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

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

Submission status: Wrong Answer

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 a in A:
    i = bisect.bisect_left(B, a)
    if i < len(B):
        for b in B[i:]:
            j = bisect.bisect_left(C, b)
            ans += len(C) - j

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()
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,len(b)):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,len(c)):
  d2[c[t]]=j
print(sum(d2.values()))

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()
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,n):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,n):
  d2[c[t]]=j
print(sum(d2.values()))

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()))
i,j=0,0
d1=dict()
for k in a:
  if b[i]>k:
    j+=1
  else:
    d1[b[i]]=j
    i+=1
for t in range(i,n):
  d1[b[t]]=j
i,j=0,0
d2=dict()
for k in b:
  if c[i]>k:
    j+=d1[k]
  else:
    d2[c[i]]=j
    i+=1
for t in range(i,n):
  d2[c[t]]=j
print(sum(d2.values()))

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 = list(set(A))
B = list(set(B))
C = list(set(C))
n1,n2,n3 = len(A),len(B),len(C)
All = [] #全ての数字格納リスト
B_A = [] #Biより小さいAjの個数格納リスト
B_C = [] #Biより大きいCkの個数格納リスト

for i in range(n1): All.append([A[i],0])
for i in range(n2): All.append([B[i],1])
for i in range(n3): All.append([C[i],2])
All.sort()
print(All)

count1,count2 = 0,0
N = n1+n2+n3
for i in range(N):
  if(All[i][1] == 1):     
    if(i == 0):
      B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(n3-count2-1)
      else: B_C.append(n3-count2)
    elif(i == N-1):
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      B_C.append(n3-count2)
    else:
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(n3-count2-1)
      else: B_C.append(n3-count2)
    
  if(All[i][1] == 0): count1 += 1
  if(All[i][1] == 2): count2 += 1

ans = 0
for i in range(n2):
 ans += B_A[i]*B_C[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()))
All = [] #全ての数字格納リスト
B_A = [] #Biより小さいAjの個数格納リスト
B_C = [] #Biより大きいCkの個数格納リスト

for i in range(N):
  All.append([A[i],0])
  All.append([B[i],1])
  All.append([C[i],2])
All.sort()

count1,count2 = 0,0
for i in range(3*N):
  if(All[i][1] == 1):     
    if(i == 0):
      B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(N-count2-1)
      else: B_C.append(N-count2)
    elif(i == 3*N-1):
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      B_C.append(N-count2)
    else:
      if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)
      else: B_A.append(count1)
      if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(N-count2-1)
      else: B_C.append(N-count2)
    
  if(All[i][1] == 0): count1 += 1
  if(All[i][1] == 2): count2 += 1

ans = 0
for i in range(N):
 ans += B_A[i]*B_C[i]
print(ans)

Submission status: Wrong Answer

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

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

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

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

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

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

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
B.sort()
C.sort()
C = 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
    total += mid1 * (N - mid2)

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
b = list(int(i) for i in input().split())
c = list(int(i) for i in input().split())
a = sorted(a)
b = sorted(b)
c = sorted(c)
count = 0
print(a,b,c)
for i in range(n):
    for j in range(n):
        for k in range(n):
            if not (a[i]<b[j] and b[j]<c[k]):
                continue
            print((i,j,k))
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
K = int(input())
while not K%2:
    K //= 2
while not K%5:
    K //= 5
ans = sum(map(int, str(K)))
for i in range(1,100000):
    x = i*K
    ans = min(ans, sum(map(int, str(x))))
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
ans=0
for j in range(N):
    for i in range(N):
        if A[i]>B[j]:
            a=i
            break
    else:
        a=N
    for k in range(N):
        if C[k]>B[j]:
            c=N-k
            break
    else:
        c=0
    ans+=a*c
print(ans)

Submission status: Wrong Answer

Solution code:
def digsum(x):
	i = 0
	a = []
	while x!= 0:
		a.append((x % (10 ** (1+i))) // (10**i))
		x -= a[i] * 10**i
		i += 1
	s = 0
	for j in range(i):
		s += a[j]
	return s

K = int(input())

minimum = 100
for k in range(1,1000):
	if digsum(K * k) < minimum:
		minimum = digsum(K * k)
print(minimum)

Submission status: Wrong Answer

Solution code:
k = int(input())


def count(x):
    return sum(map(int, str(x)))


result = 0x7ffffffff
for x in range(1, 500*k):
    result = min(result, count(x*k))
print(result)

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for i in b:
	upper = bisect.bisect_right(a,i-1)
	under = bisect.bisect_left(c,i-1)

	count += upper*(n-under)

print count

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for i in b:
	upper = bisect.bisect_right(a,i-1)
	under = bisect.bisect_left(a,i-1)

	count += upper*(n-under)

print count

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for i in b:
	upper = bisect.bisect_right(a,i-1)
	under = bisect.bisect_left(a,i-1)

	count += upper*(n-under)

print count

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

parts = []

for i in range(n):
	parts.append([a[i], 0])
	parts.append([b[i], 1])
	parts.append([c[i], 2])

parts = sorted(parts, key=itemgetter(0))

for i in range((3 * n) - 2, -1, -1):
	if parts[i][0] == parts[i + 1][0] and parts[i][1] != 1 and parts[i + 1][1] == 1:
		parts[i][1], parts[i + 1][1] = parts[i + 1][1], parts[i][1]
		#parts[i + 1][1] = 0

parts_rev = sorted(parts, key=itemgetter(0), reverse=True)

for i in range((3 * n) - 2, -1, -1):
	if parts_rev[i][0] == parts_rev[i + 1][0] and parts_rev[i][1] != 1 and parts_rev[i + 1][1] == 1:
		parts_rev[i][1], parts_rev[i + 1][1] = parts_rev[i + 1][1], parts_rev[i][1]
		#parts_rev[i + 1][1] = 2

#print(parts_rev)

a_list = []
c_list = []
a_num = 0
c_num = 0

for p in parts:
	if p[1] == 0:
		a_num += 1
	elif p[1] == 1:
		a_list.append(a_num)

for p in parts_rev:
	if p[1] == 2:
		c_num += 1
	elif p[1] == 1:
		c_list.append(c_num)

ans = 0

for i in range(n):
	ans += a_list[i] * c_list[-(i + 1)]
#print(a_list, c_list)
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

parts = []

for i in range(n):
	parts.append([a[i], 0])
	parts.append([b[i], 1])
	parts.append([c[i], 2])

parts = sorted(parts, key=itemgetter(0))

for i in range((3 * n) - 1):
	if parts[i][0] == parts[i + 1][0] and parts[i][1] == 0 and parts[i + 1][1] == 1:
		parts[i][1] = 1
		parts[i + 1][1] = 0

parts_rev = sorted(parts, key=itemgetter(0), reverse=True)

for i in range((3 * n) - 1):
	if parts_rev[i][0] == parts_rev[i + 1][0] and parts_rev[i][1] == 2 and parts_rev[i + 1][1] == 1:
		parts_rev[i][1] = 1
		parts_rev[i + 1][1] = 2

a_list = []
c_list = []
a_num = 0
c_num = 0

for p in parts:
	if p[1] == 0:
		a_num += 1
	elif p[1] == 1:
		a_list.append(a_num)

for p in parts_rev:
	if p[1] == 2:
		c_num += 1
	elif p[1] == 1:
		c_list.append(c_num)

ans = 0

for i in range(n):
	ans += a_list[i] * c_list[-(i + 1)]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()

total,Aindex,Cindex=0,0,0
Cstart = 0
for x in range(N):
    if Bs[0] < Cs[x]:
        Cstart = x
        break
for i in range(N):
    if Bs[i] <= As[Aindex]:
        continue
    else:
        while Aindex < N-1:
            if As[Aindex+1] < Bs[i]:
                Aindex += 1
            else:
                break
        while Cstart + Cindex < N-1:
            if Cs[Cstart + Cindex] <= Bs[i]:
                Cindex += 1
            else:
                break
    total += (Aindex+1)*(N-Cindex-(Cstart))
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()

total,Aindex,Cindex=0,0,0
Cstart = 0
for x in range(N):
    if Bs[0] < Cs[x]:
        Cstart = x
        break
for i in range(N):
    if Bs[i] <= As[Aindex]:
        continue
    else:
        while Aindex < N-1:
            if As[Aindex+1] < Bs[i]:
                Aindex += 1
            else:
                break
        while Cstart + Cindex < N-1:
            if Cs[Cstart + Cindex] <= Bs[i]:
                Cindex += 1
            else:
                break
    total += (Aindex+1)*(N-Cindex-1)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()

total,Aindex,Cindex=0,0,0
Cstart = 0
for x in range(N):
    if Bs[0] < Cs[x]:
        Cstart = x
        break
for i in range(N):
    if Bs[i] <= As[Aindex]:
        continue
    else:
        while Aindex < N-1:
            if As[Aindex+1] < Bs[i]:
                Aindex += 1
            else:
                break
        while Cstart + Cindex < N-1:
            if Cs[Cstart + Cindex] <= Bs[i]:
                Cindex += 1
            else:
                break
    total += (Aindex+1)*(N-Cindex-1)
    print(Aindex,Cindex)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()

total,Aindex,Cindex=0,0,0
for x in range(N):
    if Bs[0] < Cs[x]:
        Cindex = x
        break

for i in range(N):
    if Bs[i] <= As[Aindex]:
        continue
    else:
        while Aindex < N-1:
            if As[Aindex+1] < Bs[i]:
                Aindex += 1
            else:
                break
        while Cindex < N-1:
            if Cs[Cindex] <= Bs[i]:
                Cindex += 1
            else:
                break
    total += (Aindex+1)*(N-Cindex)
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Cs = list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()

total,Aindex,Cindex=0,0,0
for i in range(N):
    if Bs[i] <=As[Aindex]:
        continue
    else:
        while Aindex < N-1:
            if As[Aindex+1] < Bs[i]:
                Aindex += 1
            else:
                break
        while (Cindex < N-1) and Cs[Cindex] <= Bs[i]:
            Cindex += 1
    total += (Aindex+1)*(N-Cindex)
print(total)

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 binary_search(x,i):
	low = 0
	high = len(x)-1
	t = (low + high) // 2 	
	while (low<=high):
		if (i==x[t]):
			break
		elif (i > x[t]):
			low = t + 1
		elif (i < x[t]):
			high = t - 1
		t = (low + high) // 2
	return t

ans=0
for i in range(n):
	a_l=binary_search(a,b[i])
	c_l=binary_search(c,b[i])
	ans+=(a_l+1)*(n-c_l-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()
b.sort()
c.sort()

def binary_search(x,i):
	low = 0
	high = len(x)-1
	t = (low + high) // 2 	
	while (low<=high):
		if (i==x[t]):
			break
		elif (i > x[t]):
			low = t + 1
		elif (i < x[t]):
			high = t - 1
		t = (low + high) // 2
	return t

ans=0
for i in range(n):
	a_l=binary_search(a,b[i])
	c_l=binary_search(c,b[i])
	ans+=(n-a_l-1)*(n-c_l-1)

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

count=0

for c in range(N):
    for b in range(N):
        if C[c]<B[b]:
            break
        for a in range(N):
            if B[b]<A[a]:
                break
            count+=1
            
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
m1 = [-1 for i in range(n)]
j = 0
for i in range(n):
    while j < n:
        if a[j] < b[i]:
            m1[i] = j
            break
        j += 1
m3 = [-1 for i in range(n)]
j = 0
for i in range(n):
    while j < n:
        if b[j] < c[i]:
            m3[i] = j
            break
        j += 1
temp = 0
m2 = []
for i in m1[::-1]:
    m2.append(temp + (n-i))
    temp = m2[-1]
m2.reverse()
ans = 0
for i in m3:
    if i != -1:
        ans += m2[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

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

ans = 0

for x in b:
    print(x)
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc
    print("aa",aa)
    print("cc",cc)
    print("ans",ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

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

ans = 0

bl = [0] * len(b)

p = 0
for i,x in enumerate(b):
    for j in range(p,n):
        if x > c[j]:
            pass
        else:
            bl[i] = n - j
            p = j
            break

p = 0
for x in a:
    for i in range(p,n):
        if x > b[i]:
            pass
        else:
            ans += sum(bl[i:])
            p = i
            break

print(ans)

Submission status: Wrong Answer

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

a.sort()
c.sort()


def bisect_left(a, x, lo=0, hi=None):
    """Return the index where to insert item x in list a, assuming a is sorted.
    The return value i is such that all e in a[:i] have e < x, and all e in
    a[i:] have e >= x.  So if x already appears in the list, a.insert(x) will
    insert just before the leftmost x already there.
    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """

    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

def bisect_right(a, x, lo=0, hi=None):
    """Return the index where to insert item x in list a, assuming a is sorted.
    The return value i is such that all e in a[:i] have e <= x, and all e in
    a[i:] have e > x.  So if x already appears in the list, a.insert(x) will
    insert just after the rightmost x already there.
    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """

    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo

num = 0
for i in range(N):
    num += (bisect_right(a, b[i])) * (len(c) - bisect_left(c, b[i]))
print(num)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
A = list(set(map(int, input().split())))
B = list(set(map(int, input().split())))
C = list(set(map(int, input().split())))
ans = 0
A.sort()
B.sort()
C.sort()
# print(A, B, C)
for b in B:
    a_i = bisect.bisect_left(A, b)
    c_i = bisect.bisect_right(C, b)
    cnt = (a_i) * (N - c_i)
    # print(b, a_i, c_i, cnt)
    ans += cnt

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

ans = 0
amin = 0
bmin = 0
memoa = {}
memob = {}
for a in A:
  tmpa = 0
  if a <= amin:
    pass # 0
  elif a in memoa:
    tmpa = memoa[a]
  else:
    for b in B:
      tmpb = 0
      if a < b:
        if b <= bmin:
          pass # 0
        elif b in memob:
          tmpb = memob[b]
        else:
          for c in C:
            if b < c:
              tmpb += 1
          memob[b] = tmpb
          if tmpb == 0:
            bmin = b
      tmpa += tmpb
    memoa[a] = tmpa
    if tmpa == 0:
      amin = a
  ans += tmpa

print ans

Submission status: Wrong Answer

Solution code:
k = int(input())
kn = [0]*30
tmp = k
for i in range(30) :
    kn[i] = tmp%10
    tmp = tmp//10
p = [0,1,2,3,-4,-3,-2,-1,0]
ans = sum(kn)
for i in range(1, 10) :
    res = 0
    for j in range(30) :
        res += i*kn[j]%10
        res += i*kn[j]//10
    ans = min(ans, res)

print(ans)

Submission status: Wrong Answer

Solution code:
# python3
# utf-8

k = int(input())

ans = 50
for mult in range(1, 1000000):
    curr_ans = sum(int(x) for x in str(k * mult))
    ans = min(ans, curr_ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right, insort_left, insort_right
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(lambda x: int(x)-1, input().split())))

    print("A",A)
    print("B",B)
    print("C",C)

    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right, insort_left, insort_right
def main():
    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("A",A)
    print("B",B)
    print("C",C)

    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_right(C, b))
    print(BC)

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)
    print(Cum)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]
        print(a, Cum[bisect_right(B, a)])

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def keta(n):
    return sum(int(k) for k in list(str(n)))

k = int(input().strip())
print(min(keta(k*n) for n in range(1,100000)))

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

i = 0
j = 0
k = 0
p = []
while i < n and j < n:
    if a[i] < b[j]:
        i += 1
    else:
        p.append(i + k)
        k = p[-1]
        j += 1
else:
    while j < n:
        p.append(n + k)
        k = p[-1]
        j += 1

i = 0
j = 0
s = 0
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    else:
        s += p[i]
        j += 1
else:
    while j < n:
        s += p[-1]
        j += 1

print(s)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right, insort_left, insort_right
def main():
    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(A)
    # print(B)
    # print(C)

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

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)
    # print(Cum)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]
        # print(a, Cum[bisect_right(B, a)])

    print(count)


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


i = 0
j = 0
k = 0
p = []
while i < n and j < n:
    if a[i] < b[j]:
        i += 1
    else:
        p.append(i + k)
        k = p[-1]
        j += 1
else:
    while j < n:
        p.append(n + k)
        k = p[-1]
        j += 1

i = 0
j = 0
s = 0
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    else:
        s += p[i]
        j += 1
else:
    while j < n:
        s += p[-1]
        j += 1

print(s)

Submission status: Wrong Answer

Solution code:
#C問題

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
tmp_ans = 0
tmp = 0
for i in range(N):

	if 0 < i:
		if A[i-1] == A[i]:
			ans += tmp_ans
			continue

	for j in range(N):
		tmp_ans = ans
		if 0 < j:
			if B[j-1] == B[j]:
				ans += tmp
				tmp_ans += tmp
				continue

		if B[j] > A[i]:
			for k in range(N):
				if C[k] > B[j]:
					tmp = (N-k) 
					ans += (N-k) 
					break
					
		tmp_ans = ans - tmp_ans
			

print(ans)

Submission status: Wrong Answer

Solution code:
def f(x):
	res = 0
	while x > 0:
		res += x % 10
		x = x // 10
	return res


n = int(input())
ans = f(n)
nn = n


for i in range(0, 1001010):
	nn += n
	cur = f(nn)
	if cur < ans:
		ans = cur

print(ans)

Submission status: Wrong Answer

Solution code:
#C問題

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):
	for j in range(N):
		if B[j] > A[i]:
			for k in range(N):
				if C[k] > B[j]:
					print((N-k)*(N-j))
					ans += (N-k)
					break
			

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[7]:


ans = 0
for b in B:
    i = 0;j = 0
    while i<N and A[i]<b:
        i+=1
    while j<N and C[j]<=b:
        j+=1
    ans += i*(N-j)
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

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

b = []
for i in range(N):
  n = bisect.bisect_right(C, B[i])
  b.append(N-n)
  
ans = 0
for i in range(N):
  n = bisect.bisect_right(B, A[i])
  ans += sum(b[n:])
print(ans)

Submission status: Time Limit Exceeded

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