# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B):
# write your code in Python 3.6
stack = []
Sum = len(B)
for i in range(len(B)):
if B[i] == 1:
stack.append(i)
else:
while stack != []:
Sum -= 1
if A[i] > A[stack[-1]]:
stack.pop()
else:
break
return Sum