Vasya has got $n$ books, numbered from $1$ to $n$, arranged in a stack. The topmost book has number $a_1$, the next one — $a_2$, and so on. The book at the bottom of the stack has number $a_n$. All numbers are distinct.

Vasya wants to move all the books to his backpack in $n$ steps. During $i$-th step he wants to move the book number $b_i$ into his backpack. If the book with number $b_i$ is in the stack, he takes this book and all the books above the book $b_i$, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order $[1, 2, 3]$ (book $1$ is the topmost), and Vasya moves the books in the order $[2, 1, 3]$, then during the first step he will move two books ($1$ and $2$), during the second step he will do nothing (since book $1$ is already in the backpack), and during the third step — one book (the book number $3$). Note that $b_1, b_2, \dots, b_n$ are distinct.

Help Vasya! Tell him the number of books he will put into his backpack during each step.


-----Input-----

The first line contains one integer $n~(1 \le n \le 2 \cdot 10^5)$ — the number of books in the stack.

The second line contains $n$ integers $a_1, a_2, \dots, a_n~(1 \le a_i \le n)$ denoting the stack of books.

The third line contains $n$ integers $b_1, b_2, \dots, b_n~(1 \le b_i \le n)$ denoting the steps Vasya is going to perform.

All numbers $a_1 \dots a_n$ are distinct, the same goes for $b_1 \dots b_n$.


-----Output-----

Print $n$ integers. The $i$-th of them should be equal to the number of books Vasya moves to his backpack during the $i$-th step.


-----Examples-----
Input
3
1 2 3
2 1 3

Output
2 0 1 

Input
5
3 1 4 2 5
4 5 1 3 2

Output
3 2 0 0 0 

Input
6
6 5 4 3 2 1
6 5 3 4 2 1

Output
1 1 2 0 1 1 



-----Note-----

The first example is described in the statement.

In the second example, during the first step Vasya will move the books $[3, 1, 4]$. After that only books $2$ and $5$ remain in the stack ($2$ is above $5$). During the second step Vasya will take the books $2$ and $5$. After that the stack becomes empty, so during next steps Vasya won't move any books.

Difficulty: EASY
Tags: Mathematics

Implementation
Expected Time Complexity: O(N)

Starter code:

Solutions:
import sys
n = int(sys.stdin.readline())
stack = tuple((int(i) for i in sys.stdin.readline().split()))
order = tuple((int(i) for i in sys.stdin.readline().split()))
start = 0
backpack = set()
results = []
for book in order:
	if book in backpack:
		results.append(0)
	else:
		for i in range(start, len(stack)):
			backpack.add(stack[i])
			if stack[i] == book:
				results.append(i - start + 1)
				start = i + 1
				break
print(' '.join((str(s) for s in results)))


n = int(input())
ids = list(map(int, input().split()))
ids.reverse()
seq = list(map(int, input().split()))
used = [0 for i in range(n + 1)]
result = []
for op in seq:
	if used[op]:
		result.append(0)
		continue
	cnt = 0
	while seq:
		cur = ids[-1]
		cnt += 1
		used[cur] = 1
		ids.pop()
		if cur == op:
			break
	result.append(cnt)
print(*result)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
books = {}
for (i, v) in enumerate(a):
	books[v] = i + 1
removed = 0
for v in b:
	index = books[v]
	if index < removed:
		print(0, end=' ')
	else:
		print(index - removed, end=' ')
		removed = index


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left
import itertools
from fractions import Fraction
printHeap = str()
test = False
memory_constrained = False
N = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if test:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = False

def main():
	n = get_int()
	orig_stack = get_list()
	actions = get_list()
	mapping = dict()
	index = 0
	for i in orig_stack:
		mapping[i] = index
		index += 1
	res = list()
	pos = 0
	for i in actions:
		if mapping[i] < pos:
			res.append(0)
		else:
			res.append(mapping[i] + 1 - pos)
			pos = mapping[i] + 1
	display_list(res)
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if test else main()
else:
	cProfile.run('main()') if test else main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = 1
ind = [0] * (n + 1)
for i in range(n):
	ind[a[i]] = i + 1
for i in range(n):
	print(max(0, ind[b[i]] - p + 1), end=' ')
	p = max(p, ind[b[i]] + 1)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d = {}
for i in range(n):
	d[l1[i]] = i
old = -1
for i in l2:
	a = d[i]
	if a > old:
		print(a - old, end=' ')
	else:
		print(0, end=' ')
	old = max(a, old)


import sys, collections
n = int(sys.stdin.readline())
arr = collections.deque(map(int, sys.stdin.readline().split()))
check = [False] * (n + 1)
order = list(map(int, sys.stdin.readline().split()))
for i in order:
	if check[i] == True or not arr:
		print(0, end=' ')
	else:
		cnt = 0
		while arr:
			if check[arr[0]] == False and arr[0] != i:
				check[arr.popleft()] = True
				cnt += 1
			else:
				break
		if arr and check[arr[0]] == False and (arr[0] == i):
			check[arr[0]] = True
			arr.popleft()
			cnt += 1
		print(cnt, end=' ')


from sys import stdin, stdout
from collections import Counter
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
n = inp()
l = li()
k = li()
v = [False for i in range(n)]
d = {l[i]: i for i in range(n)}
for i in k:
	ans = 0
	x = d[i]
	if v[x]:
		print(0, end=' ')
	else:
		while x >= 0 and (not v[x]):
			ans += 1
			v[x] = True
			x -= 1
		print(ans, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = a[::-1]
c = [0] * n
bk = []
for i in range(n):
	co = 0
	if c[b[i] - 1] == 0:
		while a[-1] != b[i]:
			co += 1
			c[a[-1] - 1] = 1
			a.pop()
		co += 1
		c[a[-1] - 1] = 1
		a.pop()
	bk.append(co)
print(*bk)


def my_join(list):
	returnable = ''
	for i in range(len(list) - 1):
		returnable += str(list[i]) + ' '
	return returnable + str(list[len(list) - 1])

def my_function(stack, list):
	alreadyRemoved = set()
	outPut = []
	index = 0
	count = 0
	for n in list:
		if n in alreadyRemoved:
			outPut.append(count)
			continue
		while index < len(stack):
			if n != stack[index]:
				alreadyRemoved.add(stack[index])
				count += 1
				index += 1
			else:
				alreadyRemoved.add(stack[index])
				count += 1
				index += 1
				outPut.append(count)
				count = 0
				break
	return outPut
x = input()
stack = list(map(str, input().split()))
list = list(map(str, input().split()))
print(my_join(my_function(stack, list)))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	numb = [0 for i in range(n + 1)]
	for i in range(len(arr)):
		numb[arr[i]] = i + 1
	brr = list(map(int, input().split()))
	ind = 0
	for c in brr:
		total = 0
		num = numb[c]
		if num > ind:
			total = num - ind
			ind = num
		print(total, end=' ')
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
K = [False] * n
s = 0
for i in range(n):
	if not K[b[i] - 1]:
		for j in range(s, n):
			if a[j] == b[i]:
				print(j - s + 1, end=' ')
				s = j + 1
				break
			else:
				K[a[j] - 1] = True
	else:
		print(0, end=' ')


numberBooks = int(input())
bookStack = input().split(' ')
bookMovingOrder = input().split(' ')
booksMovedForEachCase = ''
bookStackMap = {}
bookMovingIndexOrder = []
for i in range(len(bookStack)):
	bookStackMap[bookStack[i]] = i
for i in range(len(bookMovingOrder)):
	bookMovingIndexOrder.append(bookStackMap[bookMovingOrder[i]])
greatestSelectedBookIndex = -1
for i in range(len(bookMovingOrder)):
	booksMovedInThisCase = 0
	if bookMovingIndexOrder[i] > greatestSelectedBookIndex:
		booksMovedInThisCase = bookMovingIndexOrder[i] - greatestSelectedBookIndex
		greatestSelectedBookIndex = bookMovingIndexOrder[i]
	booksMovedForEachCase += str(booksMovedInThisCase) + ' '
print(booksMovedForEachCase[:len(booksMovedForEachCase) - 1])


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
inPile = n * [False]
j = -1
for i in range(n):
	c = 0
	while not inPile[b[i] - 1]:
		j += 1
		inPile[a[j] - 1] = True
		c += 1
	sys.stdout.write(str(c) + ' ')
sys.stdout.flush()


def main():
	n = int(input())
	idx = [None] * (n + 1)
	maxidx = 0
	nums = list(map(int, input().split()))
	for (index, n) in enumerate(nums):
		idx[n] = index + 1
	queries = list(map(int, input().split()))
	for q in queries:
		if idx[q] > maxidx:
			print(idx[q] - maxidx, end=' ')
			maxidx = idx[q]
		else:
			print(0, end=' ')
	print()
main()


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
b = li()
done = set()
j = 0
ans = []
for i in range(n):
	if b[i] in done:
		ans.append(0)
	else:
		c = 0
		while a[j] != b[i]:
			done.add(a[j])
			j += 1
			c += 1
		done.add(a[j])
		j += 1
		ans.append(c + 1)
print(*ans)


def main():
	n = int(input())
	a = [int(x) for x in input().strip().split()]
	b = [int(x) for x in input().strip().split()]
	dic = dict(zip(a, range(1, n + 1)))
	ans = [0] * n
	currMax = 0
	for i in range(n):
		if dic[b[i]] > currMax:
			ans[i] = dic[b[i]] - currMax
			currMax = dic[b[i]]
	for i in range(n - 1):
		print(ans[i], end=' ')
	print(ans[-1])
main()


def funcao(lista, n, mapa):
	if not lista or n in mapa:
		return 0
	cont = 0
	for i in range(len(lista)):
		mapa[lista[i]] = 1
		cont += 1
		if n == lista[i]:
			del lista[0:i + 1]
			return cont
input()
lista = input().split()
removidos = input().split()
movimentos = []
mapa = {}
for e in removidos:
	movimentos.append(str(funcao(lista, e, mapa)))
print(' '.join(movimentos))


n = int(input())
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
c = []
pack = set()
pos = 0
for book in b:
	if book in pack:
		c.append(0)
	else:
		m = pos
		while a[pos] != book:
			pack.add(a[pos])
			pos += 1
		pack.add(a[pos])
		pos += 1
		c.append(pos - m)
print(*c)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = [0] * (n + 1)
for i in range(n):
	L[a[i]] = i + 1
ind = 0
for i in range(n):
	if L[b[i]] > ind:
		print(L[b[i]] - ind, end=' ')
		ind = L[b[i]]
	else:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = -1
s = 0
l = n
ct = [0] * n
for i in range(n):
	ct[a[i] - 1] = i
for i in range(n):
	tm = ct[b[i] - 1]
	if tm >= n - l:
		print(tm + 1 - n + l, end=' ')
		l = n - tm - 1
	else:
		print(0, end=' ')


def ans(a, b):
	ans = []
	d = {a[x]: x for x in range(n)}
	i = 0
	temp = 0
	for i in range(0, n):
		cnt = 0
		ind = d[b[i]] + 1
		if ind > temp:
			cnt = ind - temp
		temp = max(ind, temp)
		ans.append(cnt)
	return ans
n = int(input())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
print(*ans(A, B))


def main():
	n = int(input())
	a = {int(x): i + 1 for (i, x) in enumerate(input().split())}
	b = [a[int(x)] for x in input().split()]
	prev = 0
	for i in range(n):
		tmp = b[i] - prev
		if tmp >= 0:
			print(tmp)
			prev = b[i]
		else:
			print(0)
main()


n = int(input())
c = [0] * (n + 1)
a = list(map(int, input().split()))
for i in range(n):
	c[a[i]] = i + 1
b = list(map(int, input().split()))
f = 0
for i in range(n):
	if c[b[i]] > f:
		print(c[b[i]] - f, end=' ')
		f = c[b[i]]
	else:
		print(0, end=' ')


num_books = int(input())
stack = list(map(int, input().split()))
steps = list(map(int, input().split()))
result = {}
for i in range(num_books):
	result[stack[i]] = i
current = 0
for i in steps:
	if result[i] + 1 > current:
		print(result[i] + 1 - current)
		current = result[i] + 1
	else:
		print(0)


n = int(input())
av = list(map(int, input().strip().split()))
bv = list(map(int, input().strip().split()))
books = set()
ans = []
index = 0
for b in bv:
	v = 0
	if b not in books:
		while av[index] != b:
			books.add(av[index])
			v += 1
			index += 1
		books.add(b)
		v += 1
		index += 1
		ans.append(v)
	else:
		ans.append(0)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
li = []
p = 0
for i in range(0, len(a)):
	l.append(0)
for i in range(len(b)):
	if l[b[i] - 1]:
		li.append(0)
		continue
	c = 0
	while True:
		c = c + 1
		l[a[p] - 1] = 1
		if a[p] == b[i]:
			break
		p = p + 1
	p = p + 1
	li.append(c)
for i in li:
	print(i, end=' ')


n = int(input())
books = [int(i) for i in input().split()]
found = set()
b_i = 0
res = ''
for book in [int(i) for i in input().split()]:
	if book in found:
		res += '0 '
	else:
		c = 1
		while books[b_i] != book:
			found.add(books[b_i])
			b_i += 1
			c += 1
		res += str(c) + ' '
		b_i += 1
print(res[:-1])


n = int(input())
a_input = [int(x) for x in input().split(' ')]
b_input = [int(x) for x in input().split(' ')]
in_bag = set()
output = []
a_index = 0
for b in b_input:
	if b in in_bag:
		output.append(0)
		continue
	for i in range(a_index, n):
		in_bag.add(a_input[i])
		if a_input[i] == b:
			output.append(i + 1 - a_index)
			a_index = i + 1
			break
print(' '.join((str(x) for x in output)))


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
arr = [0] + [-1] * n
j = 0
last = j
for i in range(n + 1):
	if i == 0:
		continue
	if arr[l2[i - 1]] == 0:
		continue
	while l2[i - 1] != l1[j]:
		arr[l1[j]] = 0
		j += 1
	j += 1
	arr[l2[i - 1]] = j - last
	last = j
for i in range(n):
	print(arr[l2[i]], end=' ')


from sys import *
from math import *
from sys import stdin, stdout
from collections import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
lst = int_arr()
arr = int_arr()
res = [0] * 1000001
prev = 0
for i in range(n):
	res[lst[i]] = i
for i in range(n):
	if res[arr[i]] < i or res[arr[i]] < prev:
		print(0, end=' ')
	else:
		print(res[arr[i]] + 1 - prev, end=' ')
		prev = res[arr[i]] + 1


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.reverse()
y = []
s = set()
for i in range(n):
	if b[i] in s:
		y.append(0)
	else:
		x = 0
		while b[i] != a[-1]:
			s.add(a[-1])
			a.pop()
			x += 1
		y.append(x)
		x = 0
y[0] = y[0] + 1
print(*y)


n = int(input())
a = list(map(int, input().split()))
d = {}
for k in range(len(a)):
	d[a[k]] = k + 1
b = map(int, input().split())
s = 0
for i in b:
	if d[i] > s:
		print(d[i] - s, end=' ')
		s = d[i]
	else:
		print(0, end=' ')


n = int(input())
dic = {}
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
counter = 1
for item in a_list:
	dic[item] = counter
	counter += 1
tot_list = []
max_len = 0
for item in b_list:
	lenap = dic[item]
	if lenap > max_len:
		tot_list.append(lenap - max_len)
		max_len = lenap
	else:
		tot_list.append(0)
tot_str = ''
for item in tot_list:
	tot_str += str(item) + ' '
print(tot_str[:-1])


n = int(input())
d = dict(zip([*map(int, input().split())], range(n)))
k = -1
for x in [*map(int, input().split())]:
	print(max(0, d[x] - k), end=' ')
	k = max(k, d[x])


while True:
	n = int(input())
	if n in range(1, 2 * 10 ** 5 + 1):
		break
org = input().split()
q = input().split()
posOrg = {}
for i in range(n):
	posOrg[org[i]] = i + 1
ult = 0
for a in range(n):
	atual = posOrg[q[a]]
	if atual < ult:
		print(0, end=' ')
	else:
		print(atual - ult, end=' ')
		ult = atual


n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
top = 0
k = {}
r = []
j = 0
s = 0
for i in range(n):
	k[l[i]] = i
i = 0
while i < n:
	x = 0
	if k[m[i]] < top:
		r += [0]
	else:
		x = 0
		while top < n and l[top] != m[i]:
			top += 1
		if top < n:
			r += [top + 1 - s]
			s = top + 1
		else:
			x = 1
	if x == 1:
		break
	i += 1
e = len(r)
if e != n:
	r.extend([0] * (n - e))
for i in r:
	print(i, end=' ')


import sys
n = int(sys.stdin.readline().strip())
A = sys.stdin.readline().strip()
B = sys.stdin.readline().strip()
A = [int(i) for i in A.split()]
B = [int(i) for i in B.split()]
C = [0 for i in range(len(A) + 1)]
for i in range(len(B)):
	C[A[i]] = i + 1
x = 0
R = []
for i in B:
	y = C[i] - x
	if y > 0:
		R.append(str(y))
		x = C[i]
	else:
		R.append(str(0))
print(' '.join(R))


import sys
import math
n = int(input())
lock = [int(x) for x in input().strip().split()]
key = [int(x) for x in input().strip().split()]
start = -1
(store, lad) = ([0] * n, [])
for j in range(n):
	store[lock[j] - 1] += j
for i in range(n):
	gh = store[key[i] - 1]
	if start <= gh:
		lad.append(gh - start)
		start = gh
	else:
		lad.append(0)
for i in range(n):
	print(lad[i], end=' ')


import math
import bisect
import itertools
import sys

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
	d[a[i]] = i
ind = 0
for i in range(n):
	if ind > d[b[i]]:
		print(0, end=' ')
	else:
		print(d[b[i]] - ind + 1, end=' ')
		ind = d[b[i]] + 1


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
B = alele()
A.reverse()
mark = {}
for i in B:
	c = 0
	if mark.get(i, -1) == -1:
		while A and A[-1] != i:
			mark[A.pop()] = 1
			c += 1
		if A and A[-1] == i:
			mark[A.pop()] = 1
			c += 1
	print(c, end=' ')


I = lambda : map(int, input().split())
T = 1
for _ in range(T):
	n = int(input())
	a = list(I())
	b = list(I())
	d = {v: i for (i, v) in enumerate(a)}
	m = -1
	for i in b:
		print(max(0, d[i] - m), end=' ')
		m = max(m, d[i])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
op = dict()
for i in range(n):
	op[a[i]] = i
pin = i = 0
for i in range(n):
	eg = op[b[i]]
	if eg >= pin:
		ind = eg
	else:
		ans.append(0)
		continue
	ans.append(ind - pin + 1)
	pin = ind + 1
print(*ans)


z = lambda : map(int, input().split())
b = int(input())
c = dict(zip(z(), range(b)))
k = -1
for i in z():
	s = c[i]
	print(max(0, s - k))
	k = max(k, s)


n = int(input())
a = [int(i) for i in input().split()]
indx = [0] * n
for (i, ai) in enumerate(a):
	indx[ai - 1] = i
b = [int(i) for i in input().split()]
ai = 0
for bi in b:
	i = indx[bi - 1]
	if i < ai:
		print('0 ', end='')
	else:
		print(str(i - ai + 1) + ' ', end='')
		ai = i + 1
print()


l = set()
n = int(input())
aS = input().split()
bS = input().split()
for a in aS:
	a = int(a)
for b in bS:
	b = int(b)
cnt = -1
j = 0
res = []
for b in bS:
	if b in l:
		res.append(0)
		continue
	while aS[j] != b:
		l.add(aS[j])
		j += 1
	res.append(j - cnt)
	cnt = j
for r in res:
	print(r, end=' ')


(n, cur) = (int(input()), -1)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p = [0 for i in range(n + 1)]
for i in range(n):
	p[a[i]] = i
for i in range(n):
	print(max(0, p[b[i]] - cur), end=' ')
	cur = max(cur, p[b[i]])


n = int(input())
a = list(map(int, input().split()))[::-1]
b = list(map(int, input().split()))
ans = [0] * n
marked = [True] * (n + 1)
for i in range(n):
	if marked[b[i]]:
		while True:
			marked[a[-1]] = False
			ans[i] += 1
			if a[-1] == b[i]:
				a.pop()
				break
			a.pop()
	else:
		continue
print(*ans)


n = int(input())
posn = input().split()
fin_posn = []
for i in posn:
	fin_posn.append(int(i))
arr = input().split()
fin_arr = []
for i in arr:
	fin_arr.append(int(i))
hashd = dict()
i = 1
while i <= len(fin_posn):
	hashd[fin_posn[i - 1]] = i
	i += 1
sums = 0
ans = []
i = 0
while i < len(fin_arr):
	if hashd[fin_arr[i]] - sums < 0:
		ans.append(0)
	else:
		ans.append(hashd[fin_arr[i]] - sums)
		sums = hashd[fin_arr[i]]
	i += 1
for i in ans:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
moves = []
backpack = {}
moves = ['0' for i in range(len(a))]
dic = {}
for i in a:
	dic[i] = 1
(i, j) = (0, 0)
move = 0
while j < len(b):
	move += 1
	if b[j] not in dic or a[i] not in dic:
		moves[j] = '0'
		j += 1
		move = 0
	elif b[j] == a[i]:
		moves[j] = str(move)
		j += 1
		i += 1
		move = 0
	else:
		del dic[a[i]]
		i += 1
print(' '.join((str(x) for x in moves)))


n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr1 = list(map(int, input().strip().split(' ')))
mp = {}
for i in range(n):
	mp[arr[i]] = i
mx = -1
for i in range(n):
	if mx >= mp[arr1[i]]:
		print(0, end=' ')
	else:
		print(mp[arr1[i]] - mx, end=' ')
	mx = max(mx, mp[arr1[i]])
print()


from collections import Counter
n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
b = [int(x) for x in input().strip().split(' ')]
c = Counter()
for i in range(n):
	c[a[i]] = i
u = 0
v = n - 1
l = []
h = 0
for i in range(n):
	if c[b[i]] < u:
		l.append(0)
	else:
		l.append(c[b[i]] + 1 - h)
		h = c[b[i]] + 1
		u = c[b[i]]
print(*l)


n = input()
a = input()
a = a.split()
place = {}
for index in range(len(a)):
	place[a[index]] = index + 1
b = input().split()
maxi = 0
for i in range(len(b)):
	if place[b[i]] < maxi:
		print(0)
	else:
		print(place[b[i]] - maxi)
		maxi = place[b[i]]


try:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	s = set()
	c = 0
	l = []
	i = 0
	for k in b:
		c = 0
		if k in s:
			print(0, end=' ')
		else:
			while a[i] != k:
				s.add(a[i])
				c += 1
				i += 1
			s.add(a[i])
			c += 1
			i += 1
			l.append(c)
			print(c, end=' ')
except:
	pass


def main():
	n = int(input())
	a = list(map(lambda x: int(x), input().split(' ')))
	b = list(map(lambda x: int(x), input().split(' ')))
	now = 0
	ans = []
	h = set()
	for i in range(n):
		count = 0
		while b[i] not in h:
			h.add(a[now])
			now += 1
			count += 1
		ans.append(str(count))
	print(' '.join(ans))
main()


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())

def solve(n, arr, book):
	ii = 0
	out = [False] * (n + 1)
	for i in range(n):
		if out[book[i]] == True:
			print('0', end=' ')
		else:
			ind = ii
			while book[i] != arr[ii]:
				out[arr[ii]] = True
				ii += 1
			ii += 1
			print(ii - ind, end=' ')
n = int(input())
arr = int_arr()
book = int_arr()
solve(n, arr, book)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
u = list(bytearray(n))
s = ''
pos = 0
for i in b:
	if u[i - 1]:
		s += '0 '
		continue
	c = 0
	while True:
		c += 1
		u[a[pos] - 1] = 1
		if a[pos] == i:
			break
		pos += 1
	s += str(c) + ' '
	pos += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
top = 0
dt = {}
for i in range(n):
	dt[a[i]] = i + 1
for i in range(n):
	x = dt[b[i]]
	if top < x:
		print(x - top, end=' ')
		top = x
	else:
		print('0', end=' ')


n = int(input())
book_order = [int(i) for i in input().split(' ')]
take_order = [int(i) for i in input().split(' ')]
book_map = dict()
for (book_position, book_num) in enumerate(book_order, 1):
	book_map[book_num] = (book_position, n - book_position + 1)
stack_size = n
return_order = []
for take_one in take_order:
	(r, p) = book_map[take_one]
	if p > stack_size:
		return_order.append(0)
	else:
		diff = stack_size - p + 1
		return_order.append(diff)
		stack_size = p - 1
print(' '.join([str(i) for i in return_order]))


n = int(input())
a = map(int, input().split(' '))
b = map(int, input().split(' '))
order = {}
for (i, ai) in enumerate(a):
	order[ai] = i
put = 0
for (i, bi) in enumerate(b):
	cut = order[bi] + 1
	step = max(0, cut - put)
	put = max(put, cut)
	print(step, end=' ' if i < n - 1 else '\n')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = [0] * (n + 1)
for i in range(n):
	p[a[i]] = i
t = 0
for i in range(n):
	if p[b[i]] >= t:
		print(p[b[i]] - t + 1, end=' ')
		t = p[b[i]] + 1
	else:
		print(0, end=' ')


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [0] * n
t = 1
for i in A:
	C[i - 1] = t
	t += 1
t = 0
for i in B:
	if C[i - 1] > t:
		print(C[i - 1] - t, end=' ')
		t = C[i - 1]
	else:
		print(0, end=' ')
print()


from itertools import accumulate as am
import math

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
ar = li()
ar2 = li()
final = []
done = set()
j = 0
for i in range(n):
	if ar2[i] in done:
		final.append(0)
	else:
		c = 0
		while ar[j] != ar2[i]:
			done.add(ar[j])
			j += 1
			c += 1
		done.add(ar[j])
		j += 1
		final.append(c + 1)
print(*final)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
dic = {}
for i in range(n):
	dic[a[i]] = i + 1
index = 0
c = []
for i in range(n):
	dif = dic[b[i]] - index
	if dif > 0:
		c.append(dif)
		index = dic[b[i]]
	else:
		c.append(0)
c = [str(x) for x in c]
print(' '.join(c))


n = int(input().strip())
books = list(map(int, input().strip().split()))
order = list(map(int, input().strip().split()))
taken = set()
ans = [0] * n
ind = -1
for i in range(n):
	old_ind = ind
	curr_book = order[i]
	if curr_book in taken:
		continue
	for j in range(ind + 1, n):
		taken.add(books[j])
		if books[j] == curr_book:
			ind = j
			break
	ans[i] = ind - old_ind
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
visited = [False] * (n + 1)
x = 0
d = []
c = i = 0
while x < n:
	c += 1
	if visited[b[x]] == True:
		d.append(0)
		c = 0
		x += 1
		continue
	elif a[i] == b[x]:
		x += 1
		d.append(c)
		c = 0
	visited[a[i]] = True
	i += 1
print(' '.join(map(str, d)))


n = int(input())
a = [int(x) for x in input().split()]
a.reverse()
b = [int(x) for x in input().split()]
backpack = set()
for x in b:
	if x in backpack:
		print('0', end=' ')
		continue
	count = 0
	while True:
		count = count + 1
		temp = a.pop()
		backpack.add(temp)
		if temp == x:
			break
	print(count, end=' ')


n_entradas = int(input())
livros = input().split()
livros_a_retirar = input().split()
retirados = {}
respostas = []
for livro in livros_a_retirar:
	if len(livros) == 0:
		respostas.append('0')
	else:
		resposta = 0
		if not livro in retirados:
			while livro != livros[resposta]:
				retirados[livros[resposta]] = True
				resposta += 1
			resposta += 1
			del livros[0:resposta]
		respostas.append(str(resposta))
separator = ' '
print(separator.join(respostas))


import sys

def main():
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	col = [False] * (n + 1)
	b = list(map(int, sys.stdin.readline().split()))
	res = []
	j = 0
	for i in range(n):
		if col[b[i]]:
			res.append(0)
		else:
			buf = 0
			while a[j] != b[i]:
				col[a[j]] = True
				j += 1
				buf += 1
			j += 1
			buf += 1
			res.append(buf)
	sys.stdout.write(' '.join(map(str, res)))
main()


from collections import defaultdict

def main():
	n = int(input())
	shelf = map(int, input().split())
	oper = map(int, input().split())
	d = defaultdict(int)
	for (i, book) in enumerate(shelf, 1):
		d[book] = i
	top = 1
	for cur in oper:
		remIndex = d[cur]
		ans = remIndex - top + 1
		if ans <= 0:
			print('0', end=' ')
		else:
			print(ans, end=' ')
			top = remIndex + 1
main()


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	d = dict()
	for i in range(n):
		d[a[i]] = i + 1
	ans = []
	ind = 0
	for i in range(n):
		if d[b[i]] > ind:
			ans.append(d[b[i]] - ind)
			ind = d[b[i]]
		else:
			ans.append(0)
	print(*ans)
main()


n = int(input())
bk = [int(v) for v in input().split(' ')]
vk = [int(v) for v in input().split(' ')]
dic = {val: pos + 1 for (pos, val) in enumerate(bk)}
k = 0
ans = []
for i in vk:
	ans.append(max(0, dic[i] - k))
	k = max(k, dic[i])
print(' '.join([str(i) for i in ans]))


from sys import stdin
input = stdin.readline
n = int(input())
stack = {el: ind for (el, ind) in zip(map(int, input().split()), range(n))}
steps = list(map(int, input().split()))
arr = [0] * n
s = 0
for (ind, el) in zip(range(n), steps):
	x = stack[el]
	arr[ind] = max(x + 1 - s, 0)
	s = max(x + 1, s)
	if s == n:
		break
print(*arr)


N = int(input())
a = [int(i) for i in input().split()[::-1]]
v = [0] * N
for i in input().split():
	j = int(i) - 1
	if v[j]:
		print(0, end=' ')
	else:
		cnt = 0
		while True:
			cnt += 1
			t = a.pop() - 1
			v[t] = 1
			if t == j:
				break
		print(cnt, end=' ')
print()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
n = int(input())
l1 = list(map(int, input().split()))
hash = defaultdict(int)
for i in range(n):
	hash[l1[i]] = i
ans = defaultdict(lambda : -1)
l2 = list(map(int, input().split()))
fin = []
for i in range(n):
	z = l2[i]
	x = hash[z]
	count = 0
	while x >= 0 and ans[l1[x]] == -1:
		ans[l1[x]] = 0
		x -= 1
		count += 1
	ans[z] = count
	fin.append(count)
print(*fin)


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
c = [1] * n
s = int(0)
k = int(0)
for i in range(n):
	c[a[i] - 1] = i + 1
for i in range(n):
	if c[b[i] - 1] > k:
		print(c[b[i] - 1] - k, end=' ')
		k = c[b[i] - 1]
	else:
		print(0, end=' ')


n = int(input())
arr = input()
a = list(map(int, arr.split(' ')))
arr = input()
b = list(map(int, arr.split(' ')))
takeot = set()
j = 0
for i in range(n):
	count = 0
	if b[i] in takeot:
		print(0)
		continue
	for k in range(j, n):
		count += 1
		takeot.add(a[k])
		if a[k] == b[i]:
			print(count)
			break
	j += count


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
vis = [0] * 200005
ans = [0] * 200005
last = 0
for i in range(n):
	if vis[b[i]] == 1:
		continue
	for j in range(last, n):
		vis[a[j]] = 1
		if a[j] == b[i]:
			ans[i] = j - last + 1
			last = j + 1
			break
for i in range(n):
	if i != n - 1:
		print(ans[i], end=' ')
	else:
		print(ans[i])


def solve(a, b):
	res = []
	j = 0
	arr = [0] * 200001
	for i in range(len(b)):
		count = 0
		if arr[b[i]] != 0:
			res.append(0)
			continue
		while j < len(a):
			arr[a[j]] += 1
			count += 1
			if a[j] == b[i]:
				res.append(count)
				count = 0
				j += 1
				break
			j += 1
	sres = [str(x) for x in res]
	print(' '.join(sres))
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
solve(a, b)


def f(a, b):
	mp = {}
	for i in range(len(a)):
		mp[a[i]] = i
	cmax = -1
	ans = []
	for i in b:
		if cmax < mp[i]:
			ans.append(mp[i] - cmax)
			cmax = mp[i]
		else:
			ans.append(0)
	return ans
a = int(input())
lst = list(map(int, input().strip().split()))
lst2 = list(map(int, input().strip().split()))
print(*f(lst, lst2))


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
vis = [0] * (n + 1)
i = 0
j = 0
result = []
for (j, b0) in enumerate(b):
	if vis[b0]:
		result.append(0)
		continue
	result0 = 0
	while i < n and a[i] != b0:
		vis[a[i]] = 1
		result0 += 1
		i += 1
	i += 1
	result0 += 1
	vis[b0] = 1
	result.append(result0)
for n0 in result:
	print(n0, end=' ')


import sys
n = int(input())
stack = list(map(int, sys.stdin.readline().split()))
stack.reverse()
order = list(map(int, sys.stdin.readline().split()))
order.reverse()
books = [False for _ in range(n + 1)]
output = []
while order:
	book = order.pop()
	if books[book]:
		output.append(0)
	else:
		count = 0
		for j in range(len(stack) - 1, -1, -1):
			if stack[j] != book:
				k = stack[j]
				stack.pop()
				count += 1
				books[k] = True
			else:
				k = stack[j]
				stack.pop()
				count += 1
				books[k] = True
				break
		output.append(count)
print(*output)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = {a[i]: i + 1 for i in range(n)}
count = 0
ans = list()
for i in range(n):
	el = b[i]
	delta = ind[el] - count
	ans.append(max(0, delta))
	if delta > 0:
		count += delta
print(' '.join(map(str, ans)))


def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		d[A[i]] = n - i - 1
	now = n
	for el in B:
		k = d[el]
		if k >= now:
			print(0, end=' ')
		else:
			print(now - k, end=' ')
			now = k
main()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
C = [0] * (n + 1)
for i in range(n):
	t = 0
	if C[B[i]] == 0:
		t = 0
		f = 0
		while k < n and A[k] != B[i]:
			C[A[k]] = 1
			k += 1
			t += 1
			f = 1
		k += 1
		print(t + 1, end=' ')
		C[B[i]] = 1
	else:
		print(0, end=' ')


n = input()
a = input().split()
b = input().split()
d = {el: i for (i, el) in enumerate(a)}
diff_b = []
prev_number = 0
for (i, el) in enumerate(b):
	f = d[el]
	if prev_number < i:
		t = max(f - i + 1, 0)
	else:
		t = max(f - prev_number + 1, 0)
	prev_number += t
	diff_b.append(str(t))
print(' '.join(diff_b))


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [-1] * n
for (i, a) in enumerate(A):
	P[a - 1] = i
ans = [0] * n
r = -1
for (i, b) in enumerate(B):
	if r >= P[b - 1]:
		ans[i] = 0
	else:
		ans[i] = P[b - 1] - r
		r = P[b - 1]
print(*ans)


n = int(input())
idx = [-1] * n
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	idx[a[i] - 1] = i
i = 0
for e in b:
	if idx[e - 1] < i:
		print(0, end=' ')
	else:
		print(idx[e - 1] - i + 1, end=' ')
		i = idx[e - 1] + 1


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sb = set()
rec = [0] * N
j = 0
for i in range(N):
	tmp = 1
	k = B[i]
	if k in sb:
		rec[i] = 0
		continue
	sb.add(k)
	while j < N and k != A[j]:
		sb.add(A[j])
		j += 1
		tmp += 1
	j += 1
	rec[i] = tmp
print(' '.join(map(str, rec)))


n = int(input())
arr = list(map(int, input().split()))
index = {arr[i]: i for i in range(n)}
order = list(map(int, input().split()))
index_covered = -1
for i in order:
	if index[i] < index_covered:
		print('0', end=' ')
	else:
		print(index[i] - index_covered, end=' ')
		index_covered = index[i]


n = int(input())
books = list(map(int, input().split()))
steps = list(map(int, input().split()))
aux = [False] * (n + 1)
index = 0
answer = ''
for i in range(n):
	x = steps[i]
	if aux[x]:
		answer += '0 '
		continue
	cont = 0
	while True:
		cont += 1
		aux[books[index]] = True
		if books[index] == x:
			break
		index += 1
	index += 1
	answer += str(cont) + ' '
print(answer)


n = input()
livrosL = input().split()
ordem = input().split()
livros = {}
resp = []
i = 0
cont = 0
for e in livrosL:
	livros[e] = 0
for j in livros:
	while livros[ordem[i]] == 1:
		resp.append(str(cont))
		i += 1
	cont += 1
	if j == ordem[i]:
		resp.append(str(cont))
		cont = 0
		i += 1
	else:
		livros[j] = 1
while len(resp) < len(livros):
	resp.append(str(cont))
print(' '.join(resp))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = a[:]
il = -1
k = 0
ans = set()
for c in b:
	k = 0
	if c in ans:
		print(0, end=' ')
	else:
		for i in range(il + 1, n):
			il = i
			ans.add(a[i])
			k += 1
			if a[i] == c:
				break
		print(k, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {j: i for (i, j) in list(enumerate(a))}
max1 = -1
for i in range(n):
	if max1 == -1:
		max1 = d[b[i]]
		print('{}'.format(d[b[i]] + 1), end=' ')
	elif d[b[i]] <= max1:
		print(0, end=' ')
	else:
		print(d[b[i]] - max1, end=' ')
		max1 = d[b[i]]


n = int(input())
book = input().split()
order = input().split()
p = [0] * n
count = -1
s = ''
for i in range(n):
	p[int(book[i]) - 1] = i
for i in range(n):
	if count < p[int(order[i]) - 1]:
		s += str(p[int(order[i]) - 1] - count) + ' '
		count = p[int(order[i]) - 1]
	else:
		s += '0 '
print(s.rstrip())


def main(args):
	n = int(input())
	books = list(map(int, input().split()))
	requests = map(int, input().split())
	s = {i for i in books}
	books.reverse()
	res = []
	for request in requests:
		if request in s:
			c = 0
			while True:
				current = books.pop()
				c += 1
				s.remove(current)
				if current == request:
					break
			res.append(c)
		else:
			res.append(0)
	res = ' '.join((str(i) for i in res))
	print(res)
import sys
sys.exit(main(sys.argv))


from sys import stdin
n = int(input())
stack = [int(x) for x in stdin.readline().split()]
di = {}
for i in range(n):
	di[stack[i]] = i
order = [int(x) for x in stdin.readline().split()]
t = 0
s = set()
arr = [0] * n
i = 0
iidx = 0
for o in order:
	idx = di[o]
	if iidx < idx + 1:
		arr[i] = idx + 1 - iidx
		iidx = idx + 1
	t += arr[i]
	if t == n:
		break
	i += 1
print(*arr)


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
b = list(R())
k = -1
p = [0] * (n + 1)
for i in range(n):
	p[a[i]] = i
for i in range(n):
	print(max(0, p[b[i]] - k), end=' ')
	k = max(k, p[b[i]])


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {a[i]: i for i in range(x)}
t = -1
for i in range(x):
	if d[b[i]] > t:
		print(d[b[i]] - t, end=' ')
		t = max(t, d[b[i]])
	else:
		print(0, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
e = set()
d = [0 for i in range(n)]
(i, j) = (0, 0)
while i < n and j < n:
	if b[i] in e:
		i += 1
	elif a[j] != b[i]:
		d[i] += 1
		e.add(a[j])
		j += 1
	else:
		d[i] += 1
		e.add(a[j])
		j += 1
print(*d)


dq = {}
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(len(a)):
	dq[a[i]] = i
r = -1
s = ''
for i in b:
	s += str(max(0, dq[i] - r)) + ' '
	r = max(r, dq[i])
print(s)


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = []
for i in range(n):
	c.append(0)
for i in range(n):
	c[a[i] - 1] = i
pos = 0
for elem in b:
	if c[elem - 1] >= pos:
		print(c[elem - 1] - pos + 1, end=' ')
		pos = c[elem - 1] + 1
	else:
		print(0, end=' ')


n = int(input())
index = list(map(int, input().split()))
pick = list(map(int, input().split()))
ans = []
kept = [False] * (n + 1)
taken = 0
for p in pick:
	took = 0
	if kept[p]:
		ans.append('0')
	else:
		for i in range(taken, n):
			kept[index[i]] = True
			if index[i] == p:
				ans.append(str(i + 1 - taken))
				taken = i + 1
				break
print(' '.join(ans))


while True:
	try:
		n = int(input())
	except:
		break
	thelist1 = list(map(int, input().split()))
	thelist2 = list(map(int, input().split()))
	thedic = {}
	count = 0
	point = 0
	for i in range(len(thelist1)):
		thedic[thelist1[i]] = i
	tmp = -1
	for i in range(len(thelist2)):
		if thedic[thelist2[i]] <= tmp:
			print(0, end=' ')
		else:
			if i == len(thelist2) - 1:
				print(thedic[thelist2[i]] - tmp)
			else:
				print(thedic[thelist2[i]] - tmp, end=' ')
			tmp = thedic[thelist2[i]]


def meu_split(string):
	dic = {}
	add = ''
	for i in range(len(string)):
		if string[i] != ' ' and i == len(string) - 1:
			add += string[i]
			dic[add] = 0
		elif string[i] != ' ':
			add += string[i]
		elif string[i] == ' ':
			dic[add] = 0
			add = ''
	return dic
n = input()
livros = meu_split(input())
ordem = input().split()
resp = []
i = 0
cont = 0
for j in livros:
	while livros[ordem[i]] == 1:
		resp.append(str(cont))
		i += 1
	cont += 1
	if j == ordem[i]:
		resp.append(str(cont))
		cont = 0
		i += 1
	else:
		livros[j] = 1
while len(resp) < len(livros):
	resp.append(str(cont))
print(' '.join(resp))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cs = [0 for i in range(n)]
num = 0
for i in range(n):
	cs[a[i] - 1] = i
for i in range(n):
	print(str(max(cs[b[i] - 1] + 1 - num, 0)), end=' ')
	num = max(cs[b[i] - 1] + 1, num)


n = int(input())
a = [int(s) for s in input().split()]
x = [int(s) for s in input().split()]
c = [0] * (n + 1)
for i in range(n):
	c[a[i]] = i + 1
mx = 0
for i in x:
	if c[i] > mx:
		print(c[i] - mx, end=' ')
		mx = c[i]
	else:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
used = [False for i in range(n + 1)]
j = 0
for i in range(n):
	if used[b[i]]:
		ans.append(0)
		continue
	k = 0
	while True:
		k += 1
		used[a[j]] = True
		if a[j] == b[i]:
			break
		j += 1
	j += 1
	ans.append(k)
print(*ans)


def solveB():
	n = int(input())
	A = list(map(int, input().rstrip().split()))
	B = list(map(int, input().rstrip().split()))
	A1 = [0] * n
	for i in range(n):
		A1[A[i] - 1] = i + 1
	last = 0
	resp = [0] * n
	for (i, b) in enumerate(B):
		if A1[b - 1] > last:
			resp[i] = A1[b - 1] - last
			last = A1[b - 1]
	print(' '.join(map(str, resp)))
solveB()


def moves(books, steps):
	sinal = 1
	soma = 0
	for e in steps:
		if books[e] >= sinal:
			sinal = books[e] + 1
			print(books[e] - soma, end=' ')
			soma += books[e] - soma
		else:
			print('0', end=' ')
n = int(input())
stack = list(map(int, input().split(' ')))
steps = list(map(int, input().split(' ')))
books = {}
for c in range(1, n + 1):
	books[stack[c - 1]] = c
moves(books, steps)


def get_index(lst, elem):
	cnt = 0
	for x in lst:
		if x == elem:
			return cnt
		cnt += 1
n = int(input())
ai = [int(a) for a in input().split()]
bi = [int(a) for a in input().split()]
result = []
current_idx = 0
backpack = [False] * (n + 1)
for b in bi:
	if backpack[b]:
		result.append(0)
		continue
	nbooks = 0
	while ai[current_idx] != b:
		backpack[ai[current_idx]] = True
		nbooks += 1
		current_idx += 1
	backpack[ai[current_idx]] = True
	nbooks += 1
	current_idx += 1
	result.append(nbooks)
print(' '.join([str(x) for x in result]))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(len(a)):
	d[a[i]] = i
c = []
k = 0
for i in range(len(b)):
	c.append(d[b[i]])
for i in range(len(c)):
	if c[i] - k >= 0:
		c[i] -= k
		k += c[i]
	else:
		c[i] = 0
		k += 0
c[0] += 1
print(*c)


from collections import deque
maxn = 2 * 100001
n = int(input())
a = deque(map(int, input().split()))
b = list(map(int, input().split()))
usd = [False] * maxn
ans = [0] * n
indx = 0
while a:
	x = b[indx]
	if usd[x]:
		ans[indx] = 0
	else:
		(c, k) = (1, a.popleft())
		while a and x != k:
			usd[k] = True
			c += 1
			k = a.popleft()
		ans[indx] = c
	indx += 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
	d[a[i]] = i
current = 0
for i in b:
	if d[i] + 1 > current:
		print(d[i] + 1 - current, end=' ')
		current = d[i] + 1
	else:
		print(0, end=' ')
print()


n = int(input())
d = ''
books = []
stack = [0] * 1000000
bag = []
books += map(int, input().split())
prev = 0
for i in range(n):
	stack[books[i]] = i + 1
bag += map(int, input().split())
for i in range(n):
	d += str(max(0, stack[bag[i]] - prev)) + ' '
	prev = max(prev, stack[bag[i]])
print(d)


n = int(input())
arr = list(map(int, input().split()))
sol = [0] * (n + 1)
for i in range(n):
	sol[arr[i]] = i
todo = list(map(int, input().split()))
head = -1
for i in todo:
	pt = sol[i]
	if pt <= head:
		print(0, end=' ')
	else:
		print(pt - head, end=' ')
		head = pt
print()


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = list(mints())
b = mints()
c = [0] * (n + 1)
for i in range(len(a)):
	c[a[i]] = i
s = 0
for j in b:
	ss = c[j] + 1
	if ss > s:
		print(ss - s, end=' ')
		s = ss
	else:
		print(0, end=' ')


n = int(input())
stack = list(map(int, input().split()))
command = list(map(int, input().split()))
book = [0] * n
for i in range(n):
	book[stack[i] - 1] = i + 1
max = 0
for i in range(n):
	cek = book[command[i] - 1]
	if cek < max:
		command[i] = 0
	else:
		command[i] = cek - max
		max = cek
res = ''
for i in range(n):
	res += str(command[i]) + ' '
print(res.strip())


n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
d = dict(zip(arr, range(1, n + 1)))
k = 0
for x in brr:
	if d[x] > k:
		print(d[x] - k)
		k = d[x]
	else:
		print(0)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
moved = set()
ans = [0] * n
for i in range(n):
	if b[i] in moved:
		continue
	for j in range(i, n):
		if a[j] not in moved:
			moved.add(a[j])
			ans[i] += 1
			if a[j] == b[i]:
				break
print(' '.join(map(str, ans)))


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2, floor
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 998244353

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	large.reverse()
	small.extend(large)
	return small

def count(n):
	return n * (n + 1) // 2

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
stack = get_array()
pattern = get_array()
result = [0] * n
j = 0
last = 0
myset = set()
for i in range(n):
	if pattern[i] in myset:
		result[i] = 0
		continue
	while j < n:
		if stack[j] == pattern[i]:
			myset.add(stack[j])
			j += 1
			break
		else:
			myset.add(stack[j])
			j += 1
	result[i] = j - last
	last = j
print(*result, sep=' ')


n = int(input())
a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
i = 0
j = 0
i_last = -1
ans = [0] * n
a_used = [0] * (n + 1)
while j < n and i < n:
	if a[i] == b[j]:
		ans[j] = i - i_last
		i_last = i
		a_used[a[i]] = 1
		i += 1
		j += 1
	elif a_used[b[j]]:
		j += 1
	else:
		a_used[a[i]] = 1
		i += 1
print(' '.join([str(i) for i in ans]))


n = int(input())
ai = [int(i) for i in input().split()]
bi = [int(i) for i in input().split()]
dic = {}
for i in range(1, n + 1):
	dic[ai[i - 1]] = i
last = -1
for i in range(1, n + 1):
	index = dic.get(bi[i - 1]) - 1
	if index <= last:
		print(0, end=' ')
	else:
		print(index - last, end=' ')
		last = index


def solution(stack, step):
	dic = {}
	for i in stack:
		dic[i] = 1
	result = ['0' for i in range(len(stack))]
	(i, j) = (0, 0)
	current_steps = 0
	while j < len(step):
		current_steps += 1
		if step[j] not in dic or stack[i] not in dic:
			result[j] = '0'
			j += 1
			current_steps = 0
		elif step[j] == stack[i]:
			result[j] = str(current_steps)
			j += 1
			i += 1
			current_steps = 0
		else:
			del dic[stack[i]]
			i += 1
	return ' '.join(result)
book = int(input())
stack = list(map(int, input().split()))
steps = list(map(int, input().split()))
print(solution(stack, steps))


Size = int(input())
Books = list(map(int, input().split()))
PickUps = list(map(int, input().split()))
Indexes = dict()
for i in range(Size):
	Indexes[Books[i]] = i + 1
Last = 0
for i in PickUps:
	print(Indexes[i] - Last if Last < Indexes[i] else 0, end=' ')
	Last = max(Last, Indexes[i])


class CodeforcesTask1073BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.books = []
		self.order = []

	def read_input(self):
		self.n = int(input())
		self.books = [int(x) for x in input().split(' ')]
		self.order = [int(x) for x in input().split(' ')]

	def process_task(self):
		res = []
		used = {}
		self.order = self.order[::-1]
		self.books = self.books[::-1]
		while self.order:
			cc = 0
			taking = self.order.pop(-1)
			if taking not in used:
				d = self.books.pop(-1)
				used[d] = True
				cc = 1
				while d != taking:
					d = self.books.pop(-1)
					cc += 1
					used[d] = True
			res.append(cc)
		self.result = ' '.join([str(x) for x in res])

	def get_result(self):
		return self.result
Solution = CodeforcesTask1073BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
books = list(map(int, input().split()))
op = list(map(int, input().split()))
up = [i + 1 for i in range(n + 1)]
pl = [0] * (n + 1)
for i in range(len(books)):
	pl[books[i]] = i + 1
ans = []
minus = 0
used = [0] * (n + 1)
for i in range(n):
	book = op[i]
	if used[book] == 1:
		ans.append(0)
		continue
	ans.append(max(pl[book] - minus, 0))
	minus += max(pl[book] - minus, 0)
	used[book] = 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [None] * (n + 1)
for (id, i) in enumerate(a):
	ind[i] = id + 1
total = 0
adds = [0] * n
for (id_, i) in enumerate(b):
	if ind[i] > total:
		adds[id_] = ind[i] - total
		total = ind[i]
	else:
		adds[id_] = 0
print(' '.join(map(str, adds)))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [1, n]
d = dict()
for i in range(1, n + 1):
	d[a[i - 1]] = i
for i in range(n):
	x1 = d[b[i]]
	if x[0] > x1:
		print(0, end=' ')
	else:
		print(x1 - x[0] + 1, end=' ')
		x[0] = x1 + 1


def line():
	return map(int, input().split())
n = next(line())
a = {x: i + 1 for (i, x) in enumerate(line())}
b = line()
q = 0
for w in b:
	print(max(0, a[w] - q), end=' ')
	q = max(q, a[w])


n = int(input())
s = list(map(int, input().split()))
order = list(map(int, input().split()))
ans = [0] * (n + 1)
mm = 0
for i in range(n):
	ans[s[i]] = i + 1
for i in range(n):
	print(max(0, ans[order[i]] - mm), end=' ')
	mm = max(mm, ans[order[i]])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
top = 0
vis = [0 for i in range(0, n + 1)]
ans = []
for i in range(0, n):
	if vis[b[i]] == 0:
		cnt = 0
		while a[top] != b[i]:
			vis[a[top]] = 1
			cnt += 1
			top += 1
		top += 1
		cnt += 1
		ans.append(cnt)
	else:
		ans.append(0)
for i in range(0, len(ans)):
	print(ans[i], end=' ')


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	c = {}
	o = []
	k = 0
	for i in range(n):
		c[a[i]] = i
	for i in range(n):
		x = c[b[i]]
		if x < k:
			o.append('0')
		else:
			o.append(str(c[b[i]] + 1 - k))
			k = c[b[i]] + 1
	return ' '.join(o)
print(go())


a = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
m = [1 for i in range(2 * 10 ** 5 + 1)]
p = 0
for i in range(a):
	t = l1[i]
	co = 0
	if m[t] == 1:
		for j in range(p, a):
			co += 1
			p += 1
			if l[j] == t:
				m[l[j]] = 0
				break
			else:
				m[l[j]] = 0
	print(co, end=' ')


bign = 200033
mark = [0 for i in range(bign)]
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
j = 0
for i in range(n):
	tans = 0
	if mark[b[i]] == 0:
		while True:
			tans += 1
			mark[a[j]] = 1
			j += 1
			if a[j - 1] == b[i]:
				break
	if i == n - 1:
		print(tans)
	else:
		print(tans, end=' ')


from sys import stdin, stdout
from collections import deque

def main():
	global n, a, b
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	a = deque(a)
	d = [False] * (n + 2)
	b = [int(x) for x in stdin.readline().split()]
	res = []
	for x in b:
		step = 0
		while d[x] == False:
			y = a[0]
			d[y] = True
			a.popleft()
			step = step + 1
			if x == y:
				break
		res.append(step)
	stdout.write(' '.join([str(x) for x in res]))
	return 0
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [0 for i in range(n)]
op = []
top = 0
found = 0
for i in range(n):
	ind[a[i] - 1] = i
for i in b:
	if ind[i - 1] >= top:
		op.append(ind[i - 1] - top + 1)
		top = ind[i - 1] + 1
	else:
		op.append(0)
for i in op:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
check = [False] * (n + 1)
b = [int(x) for x in input().split()]
x = -1
for i in range(n):
	ans = 0
	while not check[b[i]]:
		check[a[x + 1]] = True
		x += 1
		ans += 1
	print(ans, end=' ')


n = int(input())
books = [int(x) for x in input().split(' ')]
steps = [int(x) for x in input().split(' ')]
furthest_move = 0
d = {}
for i in range(n):
	d[books[i]] = i + 1
res = ''
for i in range(n):
	if d[steps[i]] > furthest_move:
		res += str(d[steps[i]] - furthest_move) + ' '
		furthest_move = d[steps[i]]
	else:
		res += '0 '
print(res.strip())


from collections import *
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
for i in range(n):
	d[a[i]] = i + 1
beg = 0
ans = []
for i in b:
	if d[i] == 0:
		ans.append(0)
	else:
		ans.append(d[i] - beg)
	for j in range(beg, d[i]):
		d[a[j]] = 0
	beg = j + 1
print(*ans)


class Stack:

	def __init__(self):
		self.items = []

	def isEmpty(self):
		return self.items == []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def peek(self):
		return self.items[len(self.items) - 1]

	def size(self):
		return len(self.items)
a = int(input())
s = Stack()
x = [int(w) for w in input().split()]
p = [0] * a
for i in range(a - 1, -1, -1):
	s.push(x[i])
y = [int(w) for w in input().split()]
for i in y:
	num = 0
	while not p[int(i) - 1]:
		p[s.peek() - 1] = 1
		s.pop()
		num += 1
	print(num, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
has_been = [False] * (n + 1)
b = [int(x) for x in input().split()]
j = 0
for i in range(n):
	co = 0
	while has_been[b[i]] == False and j < n:
		has_been[a[j]] = True
		co += 1
		j += 1
	print(co, end=' ')


n = int(input())
a = input().split()
d = {}
k = 0
for i in range(len(a)):
	d[a[i]] = i
for s in input().split():
	if d[s] != -1:
		c = d[s]
		print(c - k + 1, end=' ')
		for i in range(k, c + 1):
			d[a[i]] = -1
		k = c + 1
	else:
		print(0, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
isi = [0] * n
d = {}
head = n
for i in range(len(b)):
	d[a[i]] = i
res = []
head = 0
for i in range(n):
	if isi[b[i] - 1] == 0:
		ind = d[b[i]]
		kol = 0
		for j in range(head, ind + 1):
			isi[a[j] - 1] = 1
			kol += 1
		res.append(kol)
		head = ind + 1
	else:
		res.append(0)
for c in res:
	print(c, end=' ')


n = int(input())
stack = list(map(int, input().split()))
dic = {}
p = 0
for i in stack:
	dic.update({i: p})
	p += 1
order = list(map(int, input().split()))
max = -1
for i in order:
	pos = dic[i]
	if pos >= max:
		print(pos - max, end=' ')
		max = pos
	else:
		print('0', end=' ')


N = int(input())
a = list(map(int, input().split()))
ad = {e: i for (i, e) in enumerate(a)}
b = list(map(int, input().split()))
last_pos = -1
for (i, e) in enumerate(b):
	e_pos = ad[e]
	if e_pos > last_pos:
		print(str(e_pos - last_pos), end=' ')
		last_pos = e_pos
	else:
		print('0', end=' ')


n = int(input())
a = list(map(int, input().split()))
a.reverse()
b = list(map(int, input().split()))
u = set()
for i in range(n):
	c = 0
	if not b[i] in u:
		while a[-1] != b[i]:
			u.add(a[-1])
			a.pop()
			c += 1
		u.add(a[-1])
		a.pop()
		c += 1
	print(c, end=' ')


input()
a = input().split()
aa = {}
for (i, ai) in enumerate(a):
	aa[ai] = i
b = input().split()
start_index = -1
res = ''
for bi in b:
	next_index = aa[bi]
	if next_index <= start_index:
		res += '0 '
		continue
	res += f'{str(next_index - start_index)} '
	start_index = next_index
print(res[:-1])


import sys
import bisect
input = sys.stdin.readline
t = 1
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	d = {}
	l1.reverse()
	for i in range(n):
		d[l1[i]] = i
	maxi = n - 1
	for i in range(n):
		if d[l2[i]] <= maxi:
			print(maxi - d[l2[i]] + 1, end=' ')
			maxi = d[l2[i]] - 1
		else:
			print(0, end=' ')


import sys
import pdb

def main():
	N = int(sys.stdin.readline().strip())
	A = list(map(int, sys.stdin.readline().strip().split()))
	B = list(map(int, sys.stdin.readline().strip().split()))
	item2idx = dict()
	for (ix, item) in enumerate(A):
		item2idx[item] = ix
	cur_idx = -1
	ret = []
	for b in B:
		b_idx = item2idx[b]
		if b_idx < cur_idx:
			ret.append(str(0))
		else:
			ret.append(str(b_idx - cur_idx))
			cur_idx = b_idx
	print(' '.join(ret))
main()


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
d = []
j = int(0)
for i in range(n + 1):
	c.append(0)
for i in range(n):
	k = int(0)
	if c[b[i]] == 0:
		for o in range(j, n):
			if a[o] == b[i]:
				d.append(k + 1)
				j = int(o) + 1
				break
			else:
				k = k + 1
				c[a[o]] = 1
	else:
		d.append(0)
print(*d)


from collections import deque
n = int(input())
stack = deque([int(p) for p in input().split()])
b = [int(p) for p in input().split()]
st = set(stack)
for i in range(len(b)):
	count = 0
	if b[i] not in st:
		print(0)
		continue
	if stack:
		while True:
			bk = stack.popleft()
			st.remove(bk)
			count += 1
			if bk == b[i]:
				print(count)
				break
	else:
		print(0)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [None for _ in range(n + 1)]
for i in range(n):
	C[A[i]] = i + 1
ans = []
removed = 0
for b in B:
	if C[b] < removed:
		ans.append(0)
	else:
		ans.append(C[b] - removed)
		removed = C[b]
print(*ans)


I = lambda : map(int, input().split())
n = int(input())
a = list(I())
a = a[::-1]
b = list(I())
k = []
d = [0] * n
for i in range(n):
	c = 0
	if d[b[i] - 1] == 0:
		while a[-1] != b[i]:
			c += 1
			d[a[-1] - 1] = 1
			a.pop()
		c += 1
		d[a[-1] - 1] = 1
		a.pop()
	k.append(c)
print(*k)


n = int(input())
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
d = {}
for i in arr:
	if i in d.keys():
		d[i] += 1
	else:
		d[i] = 1
last = -1
count = 0
for i in range(n):
	if d[arr1[i]] > 0:
		for j in range(last + 1, n):
			d[arr[j]] -= 1
			if arr[j] == arr1[i]:
				print(j - last, end=' ')
				last = j
				count += 1
				break
	else:
		print(0, end=' ')
		count += 1
	if j == n:
		break
for k in range(n - count):
	print(0, end=' ')
print('')


import sys
import math
import bisect

def solve(A, B):
	s = set()
	A.reverse()
	C = []
	for b in B:
		val = 0
		if b not in s:
			while A[-1] != b:
				s.add(A[-1])
				A.pop()
				val += 1
			s.add(A[-1])
			A.pop()
			val += 1
		C.append(val)
	return C

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = solve(A, B)
	print(' '.join(list((str(a) for a in C))))
main()


n = int(input())
a = list(map(int, input().split()))
l = list(map(int, input().split()))
f = [0 for i in range(n + 1)]
for i in range(n):
	f[a[i]] = i
x = f[l[0]]
print(x + 1, end=' ')
for i in range(1, n):
	if f[l[i]] > x:
		print(f[l[i]] - x, end=' ')
		x = f[l[i]]
	else:
		print(0, end=' ')


n = int(input())
arr = list(map(int, input().split()))
order = list(map(int, input().split()))
count = dict()
for i in range(n):
	ele = arr[i]
	count[ele] = i + 1
ans = []
counter = 0
for i in range(n):
	ele = order[i]
	ele_before = count[ele]
	if counter > ele_before:
		ans.append(0)
	else:
		diff = ele_before - counter
		ans.append(diff)
		counter += diff
print(*ans)


n = int(input())
stacked_books = [int(element) for element in input().split()]
actual_position_in_sb = 0
positions = [-1] * n
vanya_steps = [int(element) for element in input().split()]
books_to_take_out = 0
actual_position_in_sb = 0
for target_book in vanya_steps:
	if positions[target_book - 1] == -1:
		while stacked_books[actual_position_in_sb] != target_book:
			books_to_take_out += 1
			positions[stacked_books[actual_position_in_sb] - 1] = actual_position_in_sb
			actual_position_in_sb += 1
		positions[stacked_books[actual_position_in_sb] - 1] = actual_position_in_sb
		books_to_take_out += 1
		actual_position_in_sb += 1
		print(books_to_take_out)
		books_to_take_out = 0
	else:
		print(books_to_take_out)


n = int(input())
stack = list(map(int, input().split()))
order = list(map(int, input().split()))
index = [0] * n
for i in range(n):
	index[stack[i] - 1] = i
maxSoFar = -1
for i in order:
	print(max(0, index[i - 1] - maxSoFar), end=' ')
	maxSoFar = max(maxSoFar, index[i - 1])


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
j = 0
f = 0
c = {}
for i in b:
	if c.get(i, -1) != -1:
		print(0, end=' ')
	else:
		if f == 1:
			prev = j + 1
		else:
			prev = j
		f = 0
		cnt = 0
		while j < n:
			c[a[j]] = c.get(a[j], 0) + 1
			cnt += 1
			if a[j] == i:
				curr = j
				f = 1
				break
			j += 1
		print(curr - prev + 1, end=' ')
		cnt = 0


n = int(input())
stack = list(map(int, input().split()))
order = list(map(int, input().split()))
stack.reverse()
res = []
backpack = set()
for i in order:
	r = 0
	while i not in backpack:
		backpack.add(stack.pop())
		r += 1
	res.append(r)
for (i, num) in enumerate(res):
	if i != 0:
		print(' ', end='')
	print(num, end='')
print()


n = int(input())
ids = list(map(int, input().split()))
orders = list(map(int, input().split()))
dictids = {ids[i]: i + 1 for i in range(0, len(ids))}
k = 0
for i in orders:
	if dictids[i] - k < 0:
		print(0, end=' ')
	else:
		print(dictids[i] - k, end=' ')
		k += dictids[i] - k


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
u = [False] * (n + 1)
pos = 0
for i in range(len(b)):
	x = b[i]
	if u[x]:
		print(0, end=' ')
		continue
	cnt = 0
	while True:
		cnt += 1
		u[a[pos]] = True
		if a[pos] == x:
			break
		pos += 1
	pos += 1
	print(cnt)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for (i, item) in enumerate(a):
	d[item] = i + 1
res = []
cur = 1
for i in range(n):
	z = d[b[i]]
	if z < cur:
		res.append(0)
	else:
		res.append(z - cur + 1)
		cur = z + 1
print(' '.join(map(str, res)))


import math

def main_function():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	hash = [0 for i in range(n + 1)]
	for i in range(len(a)):
		hash[a[i]] = i + 1
	current_minus = 0
	for i in range(len(b)):
		if i == len(b) - 1:
			print(max(0, hash[b[i]] - current_minus))
		else:
			print(max(0, hash[b[i]] - current_minus), end=' ')
		if hash[b[i]] - current_minus > 0:
			current_minus += hash[b[i]] - current_minus
main_function()


import sys

def solve(io):
	N = io.read_int()
	A = io.read_int_array(N)
	B = io.read_int_array(N)
	done = [False] * (N + 1)
	p = 0
	cnt = []
	for b in B:
		if done[b]:
			cnt.append(0)
			continue
		sofar = 1
		while A[p] != b:
			done[A[p]] = True
			sofar += 1
			p += 1
		done[b] = True
		p += 1
		cnt.append(sofar)
	io.println_array(cnt)

class IO:
	in_stream = None
	out_stream = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, input_stream, output_stream):
		self.in_stream = input_stream
		self.out_stream = output_stream

	def read_to_buffer(self):
		self.raw = self.in_stream.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def read_string(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def read_int(self):
		return int(self.read_string())

	def read_float(self):
		return float(self.read_string())

	def read_string_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_string())
		return arr

	def read_int_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_int())
		return arr

	def read_float_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_float())
		return arr

	def read_line(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		if self.pos > 0:
			raise ValueError('Cannot call read_line in the middle of a line.')
		return self.raw

	def print(self, s):
		self.out_stream.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def println_array(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flush_output(self):
		self.out_stream.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flush_output()


n = int(input())
sd = list(map(int, input().split()))
gd = list(map(int, input().split()))
vis = [False for _ in range(n)]
j = 0
for i in range(n):
	if vis[gd[i] - 1]:
		print(0, end=' ')
	else:
		ans = 0
		while True:
			vis[sd[j] - 1] = True
			ans += 1
			j += 1
			if vis[gd[i] - 1]:
				break
		print(ans, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ai = [0] * (2 * 10 ** 5 + 1)
for (idx, el) in enumerate(a):
	ai[el] = idx + 1
max_i = 0
result = []
for el in b:
	if ai[el] > max_i:
		result.append(str(ai[el] - max_i))
		max_i = ai[el]
	else:
		result.append('0')
print(' '.join(result))


n = int(input())
books = {int(v): i for (i, v) in enumerate(input().split(), 1)}
last_i = 0
results = []
for val in input().split():
	current_i = books[int(val)]
	if current_i < last_i:
		results.append('0')
	else:
		results.append(str(current_i - last_i))
		last_i = current_i
print(' '.join(results))


n = int(input())
bookStack = list(map(int, input().split()))
vasays = list(map(int, input().split()))
res = []
b = [False for i in range(0, n + 1)]
cur = 0
for i in range(0, n):
	if b[vasays[i]]:
		res.append('0')
		continue
	for j in range(cur, len(bookStack)):
		b[bookStack[j]] = True
		if vasays[i] == bookStack[j]:
			res.append(str(j - cur + 1))
			cur = j + 1
			break
print(' '.join(res))


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = li()
b = li()
ans = []
s = set()
pos = 0
for i in range(n):
	if b[i] in s:
		ans.append(0)
		continue
	else:
		c = 0
		while b[i] != a[pos]:
			s.add(a[pos])
			pos += 1
			c += 1
		else:
			s.add(a[pos])
			pos += 1
			c += 1
		ans.append(c)
print(*ans)


def test_1():
	import math
	from collections import Counter
	n = list(map(int, input().split(' ')))[0]
	list_1 = list(map(int, input().split(' ')))
	list_2 = list(map(int, input().split(' ')))
	dict_1 = {list_1[i]: i + 1 for i in range(n)}
	idx_1 = 0
	aa = []
	for i in range(n):
		idx = dict_1[list_2[i]]
		if idx_1 < idx:
			aa.append(idx - idx_1)
			idx_1 = idx
		else:
			aa.append(0)
	print(' '.join(map(str, aa)))
test_1()


n = int(input())
ar = list(map(int, input().split()))
ar1 = list(map(int, input().split()))
t = 0
ar2 = [0] * (n + 1)
for i in range(n):
	ar2[ar[i]] = i + 1
for i in ar1:
	if ar2[i] == t:
		print(1, end=' ')
		t += 1
	elif ar2[i] > t:
		print(ar2[i] - t, end=' ')
		t = ar2[i]
	else:
		print(0, end=' ')


n = int(input())
ai = [int(a) for a in input().split()]
bi = [int(a) for a in input().split()]
result = []
current_idx = 0
backpack = [False] * (n + 1)
for b in bi:
	if backpack[b]:
		result.append(0)
		continue
	nbooks = 0
	while ai[current_idx] != b:
		backpack[ai[current_idx]] = True
		nbooks += 1
		current_idx += 1
	backpack[ai[current_idx]] = True
	nbooks += 1
	current_idx += 1
	result.append(nbooks)
print(' '.join([str(x) for x in result]))


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	n = Int()
	a = List()
	b = List()
	ans = {}
	sol = 0
	for i in range(n):
		ans[a[i]] = i + 1
	maxi = 0
	for i in b:
		sol = max(0, ans[i] - maxi)
		maxi = max(maxi, ans[i])
		print(sol, end=' ')
	print()
solution()


import sys
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	r = list(map(int, input().split()))
	arr = [0] * (n + 1)
	for i in range(n):
		arr[l[i]] = i + 1
	st = 0
	ans = []
	for j in range(n):
		ans.append(max(0, arr[r[j]] - st))
		st = max(st, arr[r[j]])
	print(*ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = map(int, input().split())
	res = list()
	d = dict()
	for (idx, v) in enumerate(a):
		d[v] = idx + 1
	leftmost = -1
	for v in b:
		if leftmost == -1:
			res.append(d[v])
			leftmost = d[v]
		elif leftmost < d[v]:
			res.append(d[v] - leftmost)
			leftmost = d[v]
		else:
			res.append(0)
	print(' '.join(map(str, res)))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
popped = dict()
idx = 0
for i in range(len(b)):
	curr = b[i]
	if curr in popped:
		print(0, end=' ')
		continue
	cnt = 0
	while a[idx] != curr and idx < len(a):
		popped[a[idx]] = 1
		idx += 1
		cnt += 1
	popped[a[idx]] = 1
	idx += 1
	cnt += 1
	print(cnt, end=' ')


am = int(input())
f = list(map(int, input().split()))
s = list(map(int, input().split()))
was = [False] * am
out = [0] * am
ind = 0
for i in range(am):
	if was[s[i] - 1]:
		continue
	was[f[ind] - 1] = True
	while s[i] != f[ind]:
		out[i] += 1
		ind += 1
		was[f[ind] - 1] = True
	out[i] += 1
	ind += 1
print(*out)


x = int(input())
f = [0] * (x + 1)
(o, w) = (0, 0)
for i in input().split():
	f[int(i)] = o + 1
	o += 1
for i in input().split():
	i = int(i)
	if f[i] > w:
		print(f[i] - w, end=' ')
		w = f[i]
	else:
		print(0, end=' ')


def inint():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def main():
	n = inint()
	a = inlist()
	b = inlist()
	i = 0
	j = 0
	ans = {}
	for k in range(n):
		ans[a[k]] = k
	sol = []
	for k in b:
		j = ans[k]
		if j < i:
			sol.append(0)
		else:
			sol.append(j - i + 1)
			i = j + 1
	print(*sol)
main()


n = int(input())
books = list(map(int, input().split()))
order = list(map(int, input().split()))
stored = [0] * (n + 1)
answer = []
index = 0
for i in range(n):
	number = 0
	if stored[order[i]] == 0:
		while books[index] != order[i]:
			stored[books[index]] = 1
			index += 1
			number += 1
		books[index] = 1
		number += 1
		index += 1
		answer.append(number)
	else:
		answer.append(0)
print(' '.join(map(str, answer)))


n = int(input())
books = list(map(int, input().split()))
order = list(map(int, input().split()))
pos = [-1 for _ in range(n + 42)]
for i in range(n):
	pos[books[i]] = i + 1
act_pos = 0
for i in range(n):
	he_wants = order[i]
	book_pos = pos[he_wants]
	if act_pos >= book_pos:
		print(0, end=' ')
	else:
		how_many = book_pos - act_pos
		print(how_many, end=' ')
		act_pos = book_pos


def read():
	return int(input())

def readlist():
	return list(map(int, input().split()))

def readmap():
	return map(int, input().split())
n = read()
A = readlist()
B = readlist()
S = set()
j = 0
ans = []
for i in range(n):
	if B[i] in S:
		ans.append(0)
	else:
		ansi = 0
		while not B[i] in S:
			S.add(A[j])
			j += 1
			ansi += 1
		ans.append(ansi)
print(' '.join(list(map(str, ans))))


n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
mp = {}
f = 0
for i in range(n):
	mp[a[i]] = i + 1
ans = []
for i in range(n):
	if mp[b[i]] > f:
		ans.append(mp[b[i]] - f)
		f = mp[b[i]]
	else:
		ans.append(0)
print(*ans)


(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
pos = [0] * (n + 5)
for i in range(n):
	pos[a[i]] = i + 1
cur_pos = 0
for i in range(n):
	if pos[b[i]] < cur_pos:
		print(0)
	else:
		print(pos[b[i]] - cur_pos)
		cur_pos = pos[b[i]]


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
bookPos = [0] * (n + 1)
for i in range(n):
	bookPos[a[i]] = i
prepos = -1
for i in range(n):
	pos = bookPos[b[i]]
	if pos > prepos:
		print(pos - prepos, end=' ')
		prepos = pos
	else:
		print('0', end=' ')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [0] * n
m = c[0]
d = []
for i in range(0, n):
	c[a[i] - 1] = i + 1
for i in range(0, n):
	if c[b[i] - 1] < m:
		d.append(0)
	else:
		d.append(c[b[i] - 1] - m)
		m = c[b[i] - 1]
print(*d, sep=' ')


def countSteps(stack, steps):
	booksForSteps = []
	backpack = {}
	lastK = 0
	for i in range(len(steps)):
		if lastK <= len(stack) and (not backpack.get(steps[i])):
			k = lastK
			while stack[k] != steps[i]:
				backpack[stack[k]] = True
				k += 1
			backpack[stack[k]] = True
			k += 1
			booksForSteps.append(k - lastK)
			lastK = k
		else:
			booksForSteps.append(0)
	return ' '.join(map(str, booksForSteps))
n = int(input())
stack = input().split(' ')
steps = input().split(' ')
print(countSteps(stack, steps))


def solve(n, stack, steps):
	idxdic = {}
	for (i, val) in enumerate(stack):
		idxdic[val] = i
	total = 0
	maxidx = -1
	res = []
	for i in range(n):
		if idxdic[steps[i]] < maxidx:
			res.append(0)
		else:
			books = idxdic[steps[i]] + 1 - total
			total += books
			res.append(books)
			maxidx = idxdic[steps[i]]
	return ' '.join(list(map(str, res)))
n = int(input())
stack = list(map(int, input().split()))
steps = list(map(int, input().split()))
print(solve(n, stack, steps))


n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
ai2 = [0] * (n + 1)
n2 = 0
for i in range(n):
	num = 0
	if ai2[bi[i]] != 1:
		for j in range(n2, n):
			ai2[ai[j]] = 1
			if ai[j] == bi[i]:
				num = j + 1 - n2
				n2 = j + 1
				break
	print(num, end=' ')


def solve(books):
	deck = list(map(int, input().split(' ')))
	top = 1
	for b in deck:
		if books[b] >= top:
			print(books[b] - top + 1, end=' ')
			top = books[b] + 1
		else:
			print('0', end=' ')
	print()
n = int(input())
temp = list(map(int, input().split(' ')))
books = {}
for i in range(1, n + 1):
	books[temp[i - 1]] = i
solve(books)


n = int(input())
p = list(map(int, input().split()))
k = list(map(int, input().split()))
ja = {}
sam = []
l = 1
for item in p:
	ja[item] = l
	l += 1
sam.append(ja[k[0]])
lam = sum(sam)
for item in k[1:]:
	if ja[item] < lam:
		sam.append(0)
	else:
		sam.append(ja[item] - lam)
		lam += sam[-1]
print(*sam)


def main():
	n = int(input())
	a_li = list(map(int, input().split()))
	b_li = list(map(int, input().split()))
	idx = [-1 for _ in range(n + 1)]
	for i in range(n):
		idx[a_li[i]] = i
	move = 0
	take = []
	for v in b_li:
		if idx[v] < move:
			take.append(0)
		else:
			take.append(idx[v] + 1 - move)
			move = idx[v] + 1
	print(' '.join((str(e) for e in take)))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = {}
for i in range(n):
	ans[a[i]] = i
sum = 0
for i in b:
	next = ans[i] + 1
	if ans[i] + 1 > sum:
		print(next - sum)
		sum = next
	else:
		print(0)


import sys
fin = sys.stdin.readline
n = int(fin())
a_dict = {int(elem): i for (i, elem) in enumerate(fin().split(' '), start=1)}
b_list = [int(elem) for elem in fin().split(' ')]
top = 1
num_list = []
for b in b_list:
	position = a_dict[b]
	if top <= position:
		num = position - top + 1
		top = position + 1
		num_list.append(num)
	else:
		num_list.append(0)
print(' '.join([str(num) for num in num_list]))


n = int(input())
tmp = input().split()
a = []
for i in tmp:
	a.append(int(i))
tmp = input().split()
b = []
for i in tmp:
	b.append(int(i))
hash = {}
for i in range(n):
	hash[i + 1] = 0
pos = 0
for i in b:
	if hash[i]:
		print('0', end=' ')
	else:
		c = 0
		for j in range(pos, n, 1):
			c += 1
			hash[a[j]] = 1
			if a[j] == i:
				pos = j + 1
				break
		print(c, end=' ')


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
n = int(input())
dic = {}
for (i, v) in enumerate(input().split()):
	dic[int(v)] = int(i + 1)
b = li()
prev = 0
ans = []
for i in range(n):
	if dic[b[i]] < prev:
		ans.append(0)
	else:
		ans.append(dic[b[i]] - prev)
		prev = dic[b[i]]
print(*ans)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d = {}
for i in range(n):
	d[l1[i]] = i + 1
t = 0
for i in range(n):
	if d[l2[i]] > t:
		print(d[l2[i]] - t, end=' ')
		t = d[l2[i]]
	else:
		print('0', end=' ')
print()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	b = LI()
	t = -1
	ai = 0
	s = set()
	r = []
	for c in b:
		if c in s:
			s.remove(c)
			r.append(0)
		else:
			while a[ai] != c:
				s.add(a[ai])
				ai += 1
			r.append(ai - t)
			t = ai
	return ' '.join(map(str, r))
print(main())


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	d[a[i]] = i + 1
b = list(map(int, input().split()))
ans = []
c = 0
for i in b:
	if d[i] < c:
		ans.append(0)
	else:
		ans.append(d[i] - c)
		c = d[i]
print(' '.join(list(map(str, ans))))


n = int(input())
stack = {item: i + 1 for (i, item) in enumerate(input().split(' '))}
step = [item for item in input().split(' ')]
book = list(stack.keys())
res = []
bookNow = 0
for movedBook in step:
	try:
		idx = stack[movedBook]
		for i in range(bookNow, idx):
			stack.pop(book[i])
		resVal = idx - bookNow
		res.append(str(resVal))
		bookNow = bookNow + resVal
	except:
		res.append('0')
print(' '.join(res))


n = int(input())
c = [0] * (n + 1)
a = list(map(int, input().split()))
for i in range(n):
	c[a[i]] = i + 1
b = [int(x) for x in input().split()]
cur = 0
for i in b:
	print(max(c[i] - cur, 0), end=' ')
	cur = max(c[i], cur)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
book_pos = [0] * n
for i in range(n):
	book_pos[a[i] - 1] = i
r = -1
for i in range(n):
	print(max(0, book_pos[b[i] - 1] - r), end=' ')
	r = max(r, book_pos[b[i] - 1])


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(1):
	n = Int()
	a = array()
	b = array()
	ans = []
	C = Counter(a)
	j = 0
	for i in b:
		here = 0
		if C[i]:
			while j < n and a[j] != i:
				C[a[j]] -= 1
				here += 1
				j += 1
			C[a[j]] -= 1
			here += 1
			j += 1
		ans.append(here)
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_per = n * [0]
for i in range(n):
	a_per[a[i] - 1] = i
cur_moved = -1
for i in range(n):
	print(max(a_per[b[i] - 1] - cur_moved, 0), end=' ')
	cur_moved = max(cur_moved, a_per[b[i] - 1])


n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
q = {}
s = []
for i in range(n):
	q[a[i]] = i + 1
r = 0
for i in range(n):
	if q[b[i]]:
		s += [q[b[i]] - r]
		for j in range(r, q[b[i]] - 1):
			q[a[j]] = 0
		r = q[b[i]]
	else:
		s += [0]
print(*s)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ptr = 0
s = set()
for i in b:
	cnt = 0
	if i not in s:
		while a[ptr] != i:
			s.add(a[ptr])
			cnt += 1
			ptr += 1
		print(cnt + 1, end=' ')
		ptr += 1
	else:
		print(0, end=' ')


n = int(input())
listA = input().split(' ')
listB = input().split(' ')
indx = {}
mx = 0
for i in range(n):
	indx[listA[i]] = i + 1
for i in range(n):
	t = indx[listB[i]]
	if t > mx:
		print(t - mx, end=' ')
		mx = t
	else:
		print(0, end=' ')


n = int(input())
a = [int(x) - 1 for x in input().split()]
b = [int(x) - 1 for x in input().split()]
last = -1
occs = [0] * n
for i in range(n):
	occs[a[i]] = i
ans = []
for i in range(n):
	if occs[b[i]] > last:
		ans.append(occs[b[i]] - last)
		last = occs[b[i]]
	else:
		ans.append(0)
print(*ans)


def f(a, b):
	n = len(a)
	al = [(a[i], i + 1) for i in range(n)]
	al.sort(key=lambda a: a[0])
	p = 0
	for i in range(n):
		t = al[b[i] - 1][1]
		if t > p:
			b[i] = t - p
			p = t
		else:
			b[i] = 0
	return b
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(*f(a, b))


def vasya_input():
	n_books_in_stack = int(input())
	stack_of_books_list = input().split()
	moving_books_steps = input().split()
	return (n_books_in_stack, dict(((key, index + 1) for (index, key) in enumerate(stack_of_books_list))), moving_books_steps)

def number_books_moves(n_books_in_stack, stack_of_books_list, moving_books_steps):
	last_moved_book_index = 0
	books_moves = []
	for book_id in moving_books_steps:
		book_index = stack_of_books_list[book_id]
		if book_index <= last_moved_book_index or n_books_in_stack == 0:
			books_moves.append(0)
		else:
			book_move = book_index - last_moved_book_index
			books_moves.append(book_move)
			last_moved_book_index = book_index
	print(' '.join((str(x) for x in books_moves)))

def main():
	(n_books_in_stack, stack_of_books_list, moving_books_steps) = vasya_input()
	number_books_moves(n_books_in_stack, stack_of_books_list, moving_books_steps)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ha = {}
for i in range(n):
	ha[a[i]] = i
removed = 0
out = ''
for i in range(n):
	if ha[b[i]] < removed:
		out += '0 '
	else:
		out += str(ha[b[i]] - removed + 1) + ' '
		removed = ha[b[i]] + 1
print(out[:-1])


input()
A = list(map(int, input().split()))
maps = {}
for (i, v) in enumerate(A):
	maps[v] = i
B = list(map(int, input().split()))
last = 0
for b in B:
	if maps[b] + 1 <= last:
		print(0, end=' ')
	else:
		print(maps[b] + 1 - last, end=' ')
		last = maps[b] + 1


f = lambda : map(int, input().split())
n = int(input())
a = {v: i for (i, v) in enumerate(f())}
k = -1
for i in f():
	print(max(0, a[i] - k), end=' ')
	k = max(k, a[i])


n = int(input())
a = list(map(int, input().split()))
c = {}
b = list(map(int, input().split()))
for i in range(n):
	c[a[i]] = i
k = 0
l = 0
for j in range(n):
	if c[b[j]] >= k:
		l = c[b[j]] - k + 1
		k = c[b[j]] + 1
		print(l, end=' ')
	else:
		print(0, end=' ')


class Stack:

	def __init__(self):
		self.items = []

	def isEmpty(self):
		return self.items == []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def peek(self):
		return self.items[len(self.items) - 1]

	def size(self):
		return len(self.items)
a = int(input())
stack = Stack()
inputs = [int(s) for s in input().split()]
used = [0] * len(inputs)
for i in range(len(inputs) - 1, -1, -1):
	stack.push(inputs[i])
for i in input().split():
	num = 0
	while not used[int(i) - 1]:
		used[stack.peek() - 1] = 1
		stack.pop()
		num += 1
	print(num, end=' ')


n = int(input())
a = input().split()
b = input().split()
mx = -1
pos = {}
for (i, ai) in enumerate(a):
	pos[a[i]] = i
for x in b:
	if mx != -1:
		print(' ', end='')
	if pos[x] > mx:
		print(pos[x] - mx, end='')
		mx = pos[x]
	else:
		print(0, end='')


n = int(input())
a = dict()
for (i, x) in enumerate(input().split()):
	a[x] = i
s = input().split()
pointer = -1
ret = []
for b in s:
	ret.append(str(max(0, a[b] - pointer)))
	if a[b] > pointer:
		pointer = a[b]
print(' '.join(ret))


from itertools import takewhile
input()
stack = map(int, input().split())
books = map(int, input().split())
bag = set()
steps = []
for book in books:
	if book in bag:
		steps.append(0)
	else:
		bag_count = len(bag)
		bag.update(takewhile(lambda item: item != book, stack))
		bag.add(book)
		taked_books = len(bag) - bag_count
		steps.append(taked_books)
print(*steps)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = set()
l = 0
for i in b:
	if i not in s:
		found = False
		c = 0
		while l < n and (not found):
			s.add(a[l])
			if a[l] == i:
				found = True
			l += 1
			c += 1
		print(c, end=' ')
	else:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
checked = set()
j = 0
for i in range(n):
	if b[i] in checked:
		continue
	else:
		count = 0
		while b[i] != a[j]:
			checked.add(a[j])
			count += 1
			j += 1
		ans[i] = count + 1
		checked.add(b[i])
		j += 1
print(*ans)


import math

def solve():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	hash = set()
	start = 0
	for i in range(n):
		if b[i] in hash:
			print(0, end=' ')
		else:
			count = 1
			while start < n and a[start] != b[i]:
				hash.add(a[start])
				start = start + 1
				count = count + 1
			start = start + 1
			hash.add(b[i])
			print(count, end=' ')
	return
solve()


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
temp = [0] * (n + 1)
p = 0
for i in range(n):
	temp[a[i]] = i + 1
for i in range(n):
	if temp[b[i]] > p:
		print(temp[b[i]] - p, end=' ')
		p = temp[b[i]]
	else:
		print(0, end=' ')


n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = {}
for i in range(n):
	d[x[i]] = i + 1
cnt = 0
ans = []
for j in range(n):
	if d[y[j]] - cnt > 0:
		ans.append(d[y[j]] - cnt)
		cnt = d[y[j]]
	else:
		ans.append(0)
print(*ans)


n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
p = dict()
d = dict()
c = []
i = -1
t = 0
for x in range(n):
	p[a[x]] = x
	d[b[x]] = x
for item in d:
	if p[item] >= d[item] and p[item] >= i:
		c.append(p[item] - i)
		i = p[item]
	else:
		c.append('0')
print(' '.join((str(e) for e in c)))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
index = 0
k = 0
sum = 0
for i in range(n):
	flag = True
	for j in range(k, n):
		flag = False
		if c[b[i] - 1] == 1:
			print(0, end=' ')
			break
		if b[i] == a[j]:
			print(j + 1 - sum, end=' ')
			k = j
			sum += j + 1 - sum
			break
		else:
			c[a[j] - 1] = 1
	if flag:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = 0
q = [1] * n
for i in b:
	ans = 0
	if q[i - 1] == 0:
		print(0, end=' ')
	else:
		while k < n and i != a[k]:
			q[a[k] - 1] = 0
			k += 1
			ans += 1
		q[a[k] - 1] = 0
		k += 1
		ans += 1
		print(ans, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
visited = [False for i in range(n)]
d = {a[i]: i for i in range(n)}
for i in b:
	x = d[i]
	if visited[x] == True:
		print(0, end=' ')
	else:
		ans = 0
		while x >= 0 and visited[x] == False:
			ans = ans + 1
			visited[x] = True
			x = x - 1
		print(ans, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = n
pos = dict()
for (i, x) in enumerate(a):
	pos[x] = n - i
out = []
for x in b:
	move = max(0, 1 + n - pos[x])
	out.append(move)
	n -= move
print(*out)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [-1] * 200005
for i in range(n):
	c[a[i]] = i
ans = []
i = 0
for j in range(n):
	x = b[j]
	if c[x] == -1 or c[x] < i:
		ans.append(0)
	else:
		ans.append(c[x] - i + 1)
		i = c[x] + 1
for i in ans:
	print(i, end=' ')


livros = input()
entrada = input().split()
operacoes = input().split()
saida = []
mochila = set()
i = 0
for k in operacoes:
	s = 0
	if not k in mochila:
		while k != entrada[i]:
			mochila.add(entrada[i])
			i += 1
			s += 1
		mochila.add(entrada[i])
		i += 1
		s += 1
	saida.append(s)
print(*saida)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
bms = set()
lbm = []
bm = 0
for tb in b:
	if tb in bms:
		lbm.append(0)
		continue
	bi = a.index(tb, bm)
	tbm = bi - bm + 1
	lbm.append(tbm)
	bms.update(a[bm:bi + 1])
	bm += tbm
print(*lbm)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
posa = [0] * n
posb = [0] * n
for i in range(n):
	posa[a[i] - 1] = i
	posb[b[i] - 1] = i
res = []
count = 0
for i in range(n):
	t = max(0, posa[b[i] - 1] - i + 1 - (count - i))
	res.append(t)
	count += t
print(*res)


n = int(input())
a = [int(s) for s in input().split()]
id = [0] * (n + 1)
for i in range(n):
	id[a[i]] = i + 1
b = [int(s) for s in input().split()]
max = 0
for i in b:
	if id[i] > max:
		print(id[i] - max, end=' ')
		max = id[i]
	else:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().strip().split()))
b = [int(n) for n in input().split()]
a.reverse()
s = set()
c = []
for i in range(n):
	if b[i] in s:
		c.append(0)
		continue
	cnt = 0
	while True:
		tmp = a.pop()
		s.add(tmp)
		cnt += 1
		if tmp == b[i]:
			break
	c.append(cnt)
for i in range(n - 1):
	print(c[i], end=' ')
print(c[n - 1])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
left = {i for i in range(1, n + 1)}
ap = -1
for i in range(n):
	if b[i] in left:
		c = 0
		ap += 1
		while ap < n and a[ap] != b[i]:
			c += 1
			left.remove(a[ap])
			ap += 1
		if ap != n:
			left.remove(a[ap])
			ans.append(c + 1)
		else:
			ans.append(c)
	else:
		ans.append(0)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = set()
ad = dict()
bd = dict()
for i in range(n):
	ad[a[i]] = i
	bd[b[i]] = i
x = 0
for i in range(n):
	if x < ad[b[i]] + 1:
		print(ad[b[i]] + 1 - x, end=' ')
		x = ad[b[i]] + 1
	else:
		print(0, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
for j in range(n):
	d[a[j]] = j + 1
p = 0
c = []
for j in range(n):
	if d[b[j]] > p:
		c.append(d[b[j]] - p)
		p = d[b[j]]
	else:
		c.append(0)
print(*c)


n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
pos_of = [-1 for i in range(2 * 10 ** 5 + 1)]
for (i, ele) in enumerate(a):
	pos_of[ele] = i + 1
current_pos = 0
ans = []
for i in b:
	if pos_of[i] > current_pos:
		ans.append(pos_of[i] - current_pos)
		current_pos = pos_of[i]
	else:
		ans.append(0)
print(' '.join(list(map(str, ans))))


import sys
n = int(sys.stdin.readline())
from collections import deque
A = deque(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
R = set()
for i in range(n):
	c = 0
	for j in range(n):
		if B[i] in R:
			break
		t = A.popleft()
		R.add(t)
		c += 1
		if t == B[i]:
			break
	print(c, end=' ')


from collections import deque
n = int(input())
stacks = deque(list(map(int, input().split())))
order = list(map(int, input().split()))
exist = set(list(stacks))
answers = []
for num in order:
	if num not in exist:
		answers.append(0)
	else:
		count = 0
		while len(stacks) > 0:
			left = stacks[0]
			count += 1
			stacks.popleft()
			exist.remove(left)
			if left == num:
				break
		answers.append(count)
print(' '.join([str(_) for _ in answers]))


I = lambda : map(int, input().split())
I()
a = (*I(),)
b = I()
s = {0}
i = 0
r = []
for x in b:
	if x in s:
		r += [0]
		continue
	c = i
	while a[i] != x:
		s |= {a[i]}
		i += 1
	s |= {a[i]}
	i += 1
	r += [i - c]
print(*r)


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
bp = set()
steps = []
pt = 0
for i in range(n):
	if b[i] in bp:
		steps.append(0)
	else:
		cnt = 0
		while a[pt] != b[i]:
			bp.add(a[pt])
			pt += 1
			cnt += 1
		bp.add(a[pt])
		pt += 1
		cnt += 1
		steps.append(cnt)
print(*steps)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mark = [0] * (n + 1)
cnt1 = 0
cnt2 = 0
while cnt2 < n:
	if mark[b[cnt2]] == 1:
		print(0, end=' ')
	else:
		count = 1
		while True:
			if a[cnt1] == b[cnt2]:
				mark[b[cnt2]] = 1
				cnt1 += 1
				print(count, end=' ')
				break
			else:
				mark[a[cnt1]] = 1
				count += 1
				cnt1 += 1
	cnt2 += 1


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (N + 1)
k = 0
for i in b:
	if c[i]:
		print('0 ', end='')
		continue
	else:
		count = 0
		for j in range(k, len(a)):
			k += 1
			if c[a[j]]:
				continue
			c[a[j]] = 1
			count += 1
			if i == a[j]:
				break
		print(str(count) + ' ', end='')
print('')


n = int(input())
a = input().split()
b = input().split()
top = 0
start = 0
ans = []
positi = [0] * n
for i in range(n):
	positi[int(a[i]) - 1] = i
for i in b:
	ok = False
	lol = positi[int(i) - 1]
	if lol >= start:
		start = lol
		ans.append(str(lol - top + 1))
		top = lol + 1
	else:
		ans.append('0')
print(' '.join(ans))


n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
di = {ai[i]: i for i in range(n)}
t = -1
for i in bi:
	if di[i] > t:
		print(di[i] - t)
		t = di[i]
	else:
		print(0)


n_livros = int(input())
pilha = input().split(' ')
ordem = input().split(' ')
mochila = set()
saida = []
zeros = 0
indice = 0
for o in range(n_livros):
	count = 0
	if len(mochila) == n_livros:
		zeros = n_livros - o
		break
	if ordem[o] not in mochila:
		while pilha[indice] != ordem[o]:
			mochila.add(pilha[indice])
			indice += 1
			count += 1
		mochila.add(pilha[indice])
		indice += 1
		count += 1
	saida.append(count)
zeros = [0] * zeros
zeros = ' '.join(map(str, zeros))
saida = ' '.join(map(str, saida))
print(saida + ' ' + zeros)


from sys import stdin
n = int(stdin.readline())
a = stdin.readline().split()
m = {}
for i in range(len(a)):
	m[int(a[i])] = i + 1
b = [int(x) for x in stdin.readline().split()]
k = 0
result = []
for x in b:
	if m[x] > k:
		result.append(str(m[x] - k))
		k = m[x]
	else:
		result.append('0')
print(' '.join(result))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [0] * (2 * 10 ** 5 + 1)
tmp_wyn = 0
str_wyn = ''
x = 0
xx = 0
for x in range(0, len(b), +1):
	szuk = b[x]
	if t[b[x]] == 1:
		str_wyn += ' 0'
		continue
	tmp_wyn = 0
	for y in range(xx, len(a), +1):
		xx += 1
		tmp_wyn += 1
		t[a[y]] = 1
		if a[y] == b[x]:
			str_wyn += ' ' + str(tmp_wyn)
			break
print(str_wyn.lstrip().rstrip())


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n + 1)]
d = []
j = 0
for i in range(n):
	if c[b[i]] == 1:
		print(0, end=' ')
	else:
		ans = 0
		while c[b[i]] == 0:
			c[a[j]] = 1
			ans += 1
			j += 1
		print(ans, end=' ')


n = int(input())
books = list(map(int, input().split()))
order = list(map(int, input().split()))
posBooks = [-1] * (n + 1)
for i in range(n):
	posBooks[books[i]] = i
pos = -1
res = ''
for i in range(n):
	if pos >= posBooks[order[i]]:
		res += '0 '
	else:
		res += str(posBooks[order[i]] - pos) + ' '
		pos = posBooks[order[i]]
print(res)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_test = read_int()
p = {x: i for (i, x) in enumerate(read_ints())}
i = -1
ans = []
for x in read_ints():
	j = max(i, p[x])
	ans += (j - i,)
	i = j
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [0] * (n + 1)
maxx = 0
for i in range(n):
	cnt[a[i]] = i + 1
for i in range(n):
	print(max(0, cnt[b[i]] - maxx), end=' ')
	maxx = max(maxx, cnt[b[i]])


def main():
	n = int(input())
	a = [int(c) for c in input().split()]
	b = [int(c) for c in input().split()]
	remap = {a[i]: i + 1 for i in range(n)}
	for i in range(n):
		b[i] = remap[b[i]]
	res = []
	prev = 0
	for elm in b:
		move = max(0, elm - prev)
		res.append(str(move))
		if elm > prev:
			prev = elm
	print(' '.join(res))
main()


(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
a = list(map(lambda x: x[0] + 1, sorted(enumerate(a), key=lambda x: x[1])))
ans = []
j = 0
for i in range(n):
	if a[b[i] - 1] < j:
		ans.append(0)
	else:
		ans.append(a[b[i] - 1] - j)
		j = a[b[i] - 1]
print(*ans)


I = lambda : input().split()
_ = input()
a = I()
b = I()
result = ''
passed = {}
j = 0
for i in b:
	if passed.get(i, 0):
		result += '0 '
	else:
		cont = 1
		while len(a) > 0:
			if i == a[j]:
				passed[a[j]] = 1
				j += 1
				break
			else:
				passed[a[j]] = 1
				j += 1
				cont += 1
		result += str(cont) + ' '
print(result.strip())


input()
a = []
data = input().split(' ')
for i in data:
	a.append(int(i))
pos = {}
k = 1
for i in data:
	pos[int(i)] = k
	k += 1
drop = 0
data = input().split(' ')
for i in data:
	t = max(0, pos[int(i)] - drop)
	print(t, end=' ')
	drop += t


n = int(input())
s = list(map(int, input().split()))
d = {}
for i in range(len(s)):
	d[s[i]] = i + 1
last = 0
o = list(map(int, input().split()))
for i in o:
	res = d[i] - last
	last = max(d[i], last)
	print(int((res + abs(res)) / 2))


I = lambda : map(int, input().split())
input()
p = {a: i for (i, a) in enumerate(I(), 1)}
x = 0
for b in I():
	print(max(0, p[b] - x), end=' ')
	x = max(x, p[b])


n = int(input())
a = map(int, input().split())
b = map(int, input().split())
books_pos = dict(zip(a, range(1, n + 1)))
max = 0
for move in b:
	pos = books_pos[move]
	if pos - max > 0:
		print(pos - max, end=' ')
		max = pos
	else:
		print('0', end=' ')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = set()
t = 0
i = 0
for j in range(n):
	if b[j] in s:
		print(0, end=' ')
	else:
		while a[i] != b[j]:
			s.add(a[i])
			t += 1
			i += 1
		t += 1
		s.add(a[i])
		i += 1
		print(t, end=' ')
		t = 0


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
above = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	above[a[i - 1]] = i
cur = 0
ans = []
for i in range(n):
	if cur >= above[b[i]]:
		ans.append(0)
	else:
		ans.append(above[b[i]] - cur)
	cur = max(cur, above[b[i]])
for i in ans:
	print(i, end=' ')


n = int(input())
a = input().split()
b = input().split()
mapa = {}
init_in_a = 0
for book in b:
	if book in mapa:
		continue
	count = 0
	for i in range(init_in_a, len(a)):
		count += 1
		if book != a[i]:
			mapa[a[i]] = 0
		else:
			mapa[book] = count
			init_in_a = i + 1
			break
res = []
for book in b:
	res.append(str(mapa[book]))
print(' '.join(res))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [-1 for _ in range(n)]
d = [-1 for _ in range(n)]
for i in range(n):
	c[a[i] - 1] = i
	d[b[i] - 1] = i
r = []
m = 1
for i in range(n):
	j = b[i] - 1
	p = c[j] + 1
	if p < m:
		r.append(0)
	elif p == m:
		r.append(1)
		m += 1
	else:
		r.append(p - m + 1)
		m = p + 1
print(' '.join(map(str, r)))


(n, A, B) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
p = 0
hash = {}
for (i, a) in enumerate(A):
	hash[a] = i
for b in B:
	x = hash[b]
	if x >= p:
		print(x - p + 1, end=' ')
		p = x + 1
	else:
		print(0, end=' ')
print('\n')


n = int(input())
a_trans = [n + 1] * (n + 1)
i = 1
for ai in input().split():
	a_trans[int(ai)] = i
	i += 1
min_unt_ake_n = 1
res = []
for bi in input().split():
	atb_i = a_trans[int(bi)]
	if atb_i < min_unt_ake_n:
		res.append('0')
	else:
		nex = atb_i + 1
		res.append(nex - min_unt_ake_n)
		min_unt_ake_n = nex
print(*res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
index_of_book = {}
book_of_index = {}
for i in range(n):
	index_of_book[a[i]] = i
	book_of_index[i] = a[i]
last_index = 0
r = []
for book in b:
	if book not in index_of_book:
		r.append(0)
		continue
	new_last = index_of_book[book] + 1
	r.append(new_last - last_index)
	for i in range(last_index, new_last):
		del index_of_book[book_of_index[i]]
	last_index = new_last
print(' '.join(map(str, r)))


t = int(input())
arr = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
lit = []
stack = []
dp = {}
for i in range(t):
	dp[arr[i]] = i + 1
maxx = 0
for i in range(len(arr1)):
	x = dp[arr1[i]]
	if x > maxx:
		v = maxx
		maxx = x
		lit.append(x - v)
	else:
		lit.append(0)
for i in lit:
	print(i, end=' ')
print(' ')


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
dict1 = {}
for i in range(n):
	dict1[arr1[i]] = i + 1
ans = 0
ansarr = []
for i in range(n):
	if dict1[arr2[i]] > ans:
		ansarr.append(dict1[arr2[i]] - ans)
		ans = dict1[arr2[i]]
	else:
		ansarr.append(0)
print(*ansarr)


n = int(input())
a = list(map(int, input().split()))
order = list(map(int, input().split()))
books = {}
for i in range(n):
	books[a[i]] = i + 1
ans = []
ind = 0
for i in range(n):
	temp = books[order[i]]
	if temp > ind:
		ans.append(temp - ind)
		ind = temp
	else:
		ans.append(0)
print(*ans)


n = int(input())
L = [int(x) - 1 for x in input().split()]
S = [int(x) - 1 for x in input().split()]
L.reverse()
Ans = [0]
Taken = [0] * n
total = 0
i = -1
for j in S:
	if Taken[j] == 0:
		while L[i] != j:
			Taken[L[i]] = 1
			i -= 1
		Ans.append(-i - total)
		total += Ans[-1]
	else:
		Ans.append(0)
for i in range(1, n + 1):
	print(Ans[i], end=' ')


n = int(input())
lst_a = [int(el) for el in input().split()]
lst_b = [int(el) for el in input().split()]
index_a = {a: i + 1 for (i, a) in enumerate(lst_a)}
current_books_lenght = 0
res = []
for i in range(n):
	depth = index_a[lst_b[i]] - current_books_lenght
	if depth < 0:
		res.append(0)
	else:
		res.append(depth)
		current_books_lenght += depth
print(' '.join([str(el) for el in res]))


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tmp = 0
AA = []
for i in range(N):
	AA.append((A[i], i))
AA = sorted(AA)
ans = [0 for _ in range(N)]
tmp = 0
for (i, b) in enumerate(B):
	j = AA[b - 1][1] + 1
	if j > tmp:
		ans[i] = j - tmp
		tmp = j
	else:
		ans[i] = 0
for a in ans:
	print(a, end=' ')
print()


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
REVA = [None] * (n + 1)
for i in range(n):
	REVA[A[i]] = i + 1
top = 0
ANSLIST = []
for b in B:
	if REVA[b] > top:
		ANSLIST.append(REVA[b] - top)
		top = REVA[b]
	else:
		ANSLIST.append(0)
for ans in ANSLIST:
	print(ans, end=' ')


n = int(input())
a = input().split()
c = []
d = set()
for i in range(n):
	c.append(int(a[i]))
b = input().split()
index = 0
count = 0
stri = ''
for i in range(n):
	if int(b[i]) not in d:
		while c[index] != int(b[i]):
			d.add(c[index])
			index += 1
			count += 1
		d.add(c[index])
		index += 1
		count += 1
	if i == n - 1:
		stri += str(count)
	else:
		stri += str(count) + ' '
	count = 0
print(stri)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
a = list(map(int, input().split()))
for i in range(n):
	d[a[i]] = i
b = list(map(int, input().split()))
prev = -1
ans = []
for i in range(n):
	if d[b[i]] > prev:
		ans.append(str(d[b[i]] - prev))
		prev = d[b[i]]
	else:
		ans.append('0')
print(' '.join(ans))