Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).

Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture — press the icon of the required application exactly once to launch it.

After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.

All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.

Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order? 

Note that one application may be launched multiple times.


-----Input-----

The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 10^5) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.

The next line contains n integers, permutation a_1, a_2, ..., a_{n} — the initial order of icons from left to right in the menu (from the first to the last one), a_{i} —  is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among a_{i}.

The third line contains m integers b_1, b_2, ..., b_{m}(1 ≤ b_{i} ≤ n) — the ids of the launched applications in the planned order. One application may be launched multiple times.


-----Output-----

Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.


-----Examples-----
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1

Output
7

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

Output
8



-----Note-----

In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. 

After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures. 

After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures. 

After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.

In total, Anya makes 7 gestures.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Data structures

Implementation

Constructive algorithms


Solutions:
(n, m, k) = list(map(int, input().split()))
p = [int(i) for i in input().split()]
u = [0 for i in range(n + 1)]
p += [0]
a = 0
for i in range(n, 0, -1):
	p[i] = p[i - 1]
for i in range(1, n + 1):
	u[p[i]] = i
for x in [int(i) for i in input().split()]:
	y = u[x]
	a += int((y - 1) / k) + 1
	if y < 2:
		continue
	(p[y], p[y - 1]) = (p[y - 1], p[y])
	(u[p[y]], u[p[y - 1]]) = (y, y - 1)
print(a)


(n, m, k) = map(int, input().split())
s0 = list(map(int, input().split()))
launch = list(map(int, input().split()))
sequence = [[0, 0, 0] for i in range(n + 1)]
for i in range(n):
	if i == 0:
		sequence[s0[i]][0] = i + 1
		sequence[s0[i]][1] = 0
		sequence[s0[i]][2] = s0[i + 1]
	elif i == n - 1:
		sequence[s0[i]][0] = i + 1
		sequence[s0[i]][1] = s0[i - 1]
		sequence[s0[i]][2] = 0
	else:
		sequence[s0[i]][0] = i + 1
		sequence[s0[i]][1] = s0[i - 1]
		sequence[s0[i]][2] = s0[i + 1]
gestures = 0
for a in launch:
	gestures += (sequence[a][0] - 1) // k + 1
	b = sequence[a][1]
	d = sequence[a][2]
	c = sequence[b][1]
	if sequence[a][0] != 1:
		sequence[a][0] -= 1
		sequence[b][0] += 1
		sequence[a][1] = c
		sequence[c][2] = a
		sequence[b][2] = d
		sequence[d][1] = b
		sequence[a][2] = b
		sequence[b][1] = a
print(gestures)


def move_up(l, d, a):
	if a > 0:
		in_icon = l[a]
		swap_icon = l[a - 1]
		d[in_icon] = a - 1
		d[swap_icon] = a
		(l[a], l[a - 1]) = (l[a - 1], l[a])
line1 = input()
line2 = input()
line3 = input()
(n, m, k) = (int(t) for t in line1.split())
position_list = [int(t) for t in line2.split()]
position_dict = {}
for i in range(len(position_list)):
	position_dict[position_list[i]] = i
desired_list = [int(t) for t in line3.split()]
gestures = 0
for desired_id in desired_list:
	icon_index = position_dict[desired_id]
	if icon_index < k:
		gestures += 1
	else:
		gestures += icon_index // k + 1
	move_up(position_list, position_dict, icon_index)
print(gestures)


(n, m, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = {}
j = 0
for i in a:
	c[i] = j
	j += 1
num = 0
for i in b:
	d = c[i]
	num += (d + k) // k
	if c[i] != 0:
		e = a[d - 1]
		(c[i], c[e]) = (c[e], c[i])
		(a[d], a[d - 1]) = (a[d - 1], a[d])
print(num)


def main():
	(n, m, k) = map(int, input().split())
	aa = [0]
	aainv = [0] * (n + 1)
	for a in map(int, input().split()):
		aainv[a] = len(aa)
		aa.append(a)
	bb = list(map(int, input().split()))
	res = 0
	for b in bb:
		bpos = aainv[b]
		res += (bpos - 1) // k + 1
		if bpos > 1:
			bpos -= 1
			c = aa[bpos]
			aainv[b] = bpos
			aa[bpos] = b
			bpos += 1
			aainv[c] = bpos
			aa[bpos] = c
	print(res)

def __starting_point():
	main()
__starting_point()


(n, m, k) = map(int, input().split())
arr = list(map(int, input().split()))
(idx, res) = ([-1] * (n + 1), 0)
for i in range(n):
	idx[arr[i]] = i
b = list(map(int, input().split()))
for x in b:
	res += idx[x] // k + 1
	if idx[x] > 0:
		c = idx[x]
		(arr[c], arr[c - 1]) = (arr[c - 1], arr[c])
		(idx[x], idx[arr[c]]) = (idx[arr[c]], idx[x])
print(res)


from math import ceil
(n, m, l) = list(map(int, input().split()))
d = {}
j = 0
for i in input().split():
	j += 1
	d[int(i)] = j
reversedd = {value: key for (key, value) in d.items()}
oper = list(map(int, input().split()))
ans = 0
for i in oper:
	ans += ceil(d[i] / l)
	if d[i] != 1:
		tt = d[i] - 1
		temp = reversedd[d[i] - 1]
		d[i] = tt
		d[temp] = d[temp] + 1
		reversedd[d[i]] = i
		reversedd[d[i] + 1] = temp
print(ans)


(n, m, k) = [int(i) for i in input().split()]
pos = dict()
item = [int(i) for i in input().split()]
length = len(item)
for i in range(length):
	tem = item[i]
	pos[tem] = i
icon = [int(i) for i in input().split()]
times = 0
for tar in icon:
	times += pos[tar] // k + 1
	if pos[tar] != 0:
		pre = item[pos[tar] - 1]
		(item[pos[tar]], item[pos[tar] - 1]) = (pre, item[pos[tar]])
		pos[tar] -= 1
		pos[pre] += 1
print(times)


(a, b, c) = (int(i) for i in input().split())
t = list(map(str, input().split()))
p = list(map(str, input().split()))
o = {}
import math
for i in range(a):
	o[t[i]] = i + 1
	o[i + 1] = t[i]
u = 0
for i in range(b):
	s = o[p[i]]
	if s > 1:
		o[p[i]] -= 1
		o[s] = o[s - 1]
		o[o[s - 1]] = s
		o[s - 1] = p[i]
	s = s / c
	s = math.ceil(s)
	u += s
print(u)


def main():
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pos = [0] * (n + 5)
	app = [0] * (n + 5)
	for i in range(n):
		pos[i + 1] = a[i]
		app[a[i]] = i + 1
	swipes = 0
	for x in b:
		if app[x] % k != 0:
			swipes += app[x] // k + 1
		else:
			swipes += app[x] // k
		if app[x] != 1:
			tempPos = app[x]
			tempApp = pos[tempPos - 1]
			pos[tempPos] = tempApp
			app[tempApp] = tempPos
			app[x] = tempPos - 1
			pos[tempPos - 1] = x
	print(swipes)

def __starting_point():
	main()
__starting_point()


(n, m, k) = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
pos_of = {l[i]: i for i in range(len(l))}
app_at = {i: l[i] for i in range(len(l))}
open_order = [int(i) for i in input().split()]
count = 0
for j in open_order:
	pos = pos_of[j]
	count += pos // k + 1
	if pos != 0:
		(pos_of[app_at[pos]], pos_of[app_at[pos - 1]]) = (pos_of[app_at[pos - 1]], pos_of[app_at[pos]])
		(app_at[pos], app_at[pos - 1]) = (app_at[pos - 1], app_at[pos])
print(count)


def calcNSwipes(order):
	return (order - 1) // k

def calcNMoves(order):
	return calcNSwipes(order) + 1
(n, m, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
getOrderFromId = [-1 for _ in range(n + 1)]
getIdFromOrder = [-1 for _ in range(n + 1)]
for (i, appId) in enumerate(a):
	order = i + 1
	getOrderFromId[appId] = order
	getIdFromOrder[order] = appId
ans = 0
for appId in b:
	order = getOrderFromId[appId]
	ans += calcNMoves(order)
	if order > 1:
		prevOrder = order - 1
		prevId = getIdFromOrder[prevOrder]
		getOrderFromId[prevId] = order
		getIdFromOrder[order] = prevId
		getOrderFromId[appId] = prevOrder
		getIdFromOrder[prevOrder] = appId
print(ans)


import sys
(n, m, k) = map(int, sys.stdin.readline().split())
icon_ids = list(map(int, sys.stdin.readline().split()))
launch_order = list(map(int, sys.stdin.readline().split()))
app_to_slot = dict()
result = 0
for (i, icon) in enumerate(icon_ids):
	app_to_slot[icon] = i
for app in launch_order:
	result += app_to_slot[app] // k + 1
	old_slot = app_to_slot[app]
	if not old_slot:
		continue
	app_to_demote = icon_ids[old_slot - 1]
	(icon_ids[old_slot], icon_ids[old_slot - 1]) = (icon_ids[old_slot - 1], icon_ids[old_slot])
	app_to_slot[icon_ids[old_slot]] = old_slot
	app_to_slot[icon_ids[old_slot - 1]] = old_slot - 1
print(result)


(n, m, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
assert len(a) == n
assert len(b) == m
pos = [0] * (n + 1)
for p in range(n):
	pos[a[p]] = p
gesture = 0
for i in b:
	this_pos = pos[i]
	this_id = i
	gesture += this_pos // k + 1
	if this_pos > 0:
		prev_pos = pos[i] - 1
		prev_id = a[prev_pos]
		(a[this_pos], a[prev_pos]) = (a[prev_pos], a[this_pos])
		(pos[this_id], pos[prev_id]) = (pos[prev_id], pos[this_id])
print(gesture)


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
order = [0 for i in range(n + 1)]
ans = 0
for i in range(n):
	order[a[i]] = i
for i in range(m):
	x = order[b[i]]
	ans += x // k + 1
	if x != 0:
		y = a[x]
		a[x] = a[x - 1]
		a[x - 1] = y
		order[a[x - 1]] = x - 1
		order[a[x]] = x
print(ans)


(n, m, k) = map(int, input().split())
str2 = [int(i) for i in input().split()]
str3 = [int(i) for i in input().split()]
d = {}
index = 0
for i in str2:
	d[i] = index
	index += 1
g = 0
for i in str3:
	x = d[i]
	g += x // k + 1
	if d[i] != 0:
		p = str2[x - 1]
		(d[p], d[i]) = (d[i], d[p])
		(str2[x - 1], str2[x]) = (str2[x], str2[x - 1])
print(g)


class PositioinalDoubleLinkedList:

	class _Node:
		__slots__ = ('_element', '_previous', '_next')

		def __init__(self, element, previous, next):
			self._element = element
			self._previous = previous
			self._next = next

	def __init__(self):
		self._header = self._Node(None, None, None)
		self._trailer = self._Node(None, None, None)
		self._header._next = self._trailer
		self._trailer._previous = self._header
		self._size = 0

	def __len__(self):
		return self._size

	def is_empty(self):
		return self._size == 0

	def _insert_between(self, e, pre, succ):
		newest = self._Node(e, pre, succ)
		pre._next = newest
		succ._previous = newest
		self._size += 1
		return newest

	def _delete_node(self, node):
		pre = node._previous
		succ = node._next
		pre._next = succ
		succ._previous = pre
		self._size -= 1
		element = node._element
		node._previous = node._next = node._element = None
		return element

	class Position:
		__slots__ = ('_container', '_node')

		def __init__(self, container, node):
			self._container = container
			self._node = node

		def element(self):
			return self._node._element

		def __eq__(self, other):
			return type(other) is type(self) and other._node is self._node

		def __ne__(self, other):
			return not self == other

	def _validate(self, p):
		if not isinstance(p, self.Position):
			raise TypeError('p must be proper Position type')
		if p._container is not self:
			raise ValueError('p does not belong to this container')
		if p._node._next is None:
			raise ValueError('p is no longer valid')
		return p._node

	def _make_position(self, node):
		if node is self._header or node is self._trailer:
			return None
		else:
			return self.Position(self, node)

	def first(self):
		return self._make_position(self._header._next)

	def last(self):
		return self._make_position(self._trailer._previous)

	def before(self, p):
		node = self._validate(p)
		return self._make_position(node._previous)

	def after(self, p):
		node = self._validate(p)
		return self._make_position(node._next)

	def __iter__(self):
		cursor = self.first()
		while cursor is not None:
			yield cursor.element()
			cursor = self.after(cursor)

	def add_first(self, e):
		return self._insert_between(e, self._header, self._header.next)

	def add_last(self, e):
		return self._insert_between(e, self._trailer._previous, self._trailer)

	def add_before(self, p, e):
		Node = self._validate(p)
		return self._insert_between(e, Node._previous, Node)

	def add_after(self, p, e):
		Node = self._validate(p)
		return self._insert_between(e, Node, Node._next)

	def delete(self, p):
		Node = self._validate(p)
		return self._delete_node(Node)

	def replace(self, p, e):
		Node = self._validate(p)
		OldValue = Node._element
		Node._element = e
		return OldValue
from math import ceil
from copy import deepcopy
(n, m, k) = [int(i) for i in input().split()]
P0 = list(map(int, input().split()))
L = list(map(int, input().split()))
Postions = {}
PList = PositioinalDoubleLinkedList()
cnt = 0
for i in range(n):
	Postions[P0[i]] = PList.add_last(i + 1)
for j in range(m):
	t0 = Postions[L[j]]
	NowValue = t0._element
	cnt += ceil(NowValue / k)
	if not t0._previous._element == None:
		t_1 = t0._previous
		t1 = t0._next
		t_2 = t_1._previous
		PreValue = t_1._element
		t0._element = PreValue
		t_1._element = NowValue
		t0._next = t_1
		t1._previous = t_1
		t0._previous = t_2
		t_1._previous = t0
		t_1._next = t1
		t_2._next = t0
print(cnt)


from math import ceil
(n, m, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
cnt = 0
position = [None] * (len(a) + 1)
reverse_position = [None] * (len(a) + 1)
for (i, j) in enumerate(a):
	position[j] = i + 1
	reverse_position[i + 1] = j
for i in range(m):
	cnt += ceil(position[b[i]] / k)
	if position[b[i]] != 1:
		(reverse_position[position[b[i]] - 1], reverse_position[position[b[i]]]) = (reverse_position[position[b[i]]], reverse_position[position[b[i]] - 1])
		position[b[i]] -= 1
		position[reverse_position[position[b[i]] + 1]] += 1
print(cnt)


(n, m, k) = [int(i) for i in input().split()]
list_input = list(map(int, input().split()))
a = ['a'] * n
b = ['b'] * n
for i in range(n):
	a[i] = list_input[i] - 1
	b[list_input[i] - 1] = i
dial_input = list(map(int, input().split()))
s = 0
for i in dial_input:
	s += b[i - 1] // k + 1
	if b[i - 1] != 0:
		(a[b[i - 1]], a[b[i - 1] - 1]) = (a[b[i - 1] - 1], a[b[i - 1]])
		(b[a[b[i - 1]]], b[a[b[i - 1] - 1]]) = (b[a[b[i - 1] - 1]], b[a[b[i - 1]]])
print(s)


(apps_size, launched_size, apps_per_screen) = map(int, input().split())
apps = list(map(int, input().split()))
launched = map(int, input().split())
apps_pos = {}
for (pos, elem) in enumerate(apps):
	apps_pos[elem] = pos
result = 0
for app in launched:
	pos = apps_pos[app]
	if pos == 0:
		result += 1
		continue
	prev_app = apps[pos - 1]
	result += pos // apps_per_screen + 1
	apps[pos - 1] = app
	apps[pos] = prev_app
	apps_pos[prev_app] = pos
	apps_pos[app] = pos - 1
print(result)


(n, m, k) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
do = [int(i) for i in input().split()]
D = {}
j = 0
for i in s:
	D[i] = j
	j += 1
N = 0
for i in do:
	x = D[i]
	N += x // k + 1
	if D[i] != 0:
		p = s[x - 1]
		(D[p], D[i]) = (D[i], D[p])
		(s[x], s[x - 1]) = (s[x - 1], s[x])
print(N)


(n, m, k) = map(int, input().split(' '))
a = map(int, input().split(' '))
b = map(int, input().split(' '))
pos_app_id = {}
app_id_pos = {}
for (pos, app_id) in enumerate(a):
	pos_app_id[app_id] = pos
	app_id_pos[pos] = app_id

def rotate_left(a_id):
	a_pos = pos_app_id[a_id]
	if a_pos > 0:
		b_pos = a_pos - 1
		b_id = app_id_pos[b_pos]
		pos_app_id[a_id] = b_pos
		pos_app_id[b_id] = a_pos
		app_id_pos[a_pos] = b_id
		app_id_pos[b_pos] = a_id
swipes = 0
for app_id in b:
	app_pos = pos_app_id[app_id]
	swipes += app_pos // k + 1
	rotate_left(app_id)
print(swipes)


__author__ = 'PrimuS'
(n, m, k) = (int(x) for x in input().split())
order = [int(x) for x in input().split()]
touch = [int(x) for x in input().split()]
res = 0
d = {}
for i in range(n):
	d[order[i]] = i
for x in touch:
	pos = d[x]
	res += pos // k + 1
	if pos > 0:
		(order[pos - 1], order[pos]) = (order[pos], order[pos - 1])
		d[x] = pos - 1
		d[order[pos]] = pos
print(res)


def main():
	(n, m, k) = list(map(int, input().split()))
	icons = list(map(int, input().split()))
	icons_for_launch_positions = list(map(int, input().split()))
	gestures = m
	icons_positions = [0] * (n + 1)
	for i in range(0, len(icons)):
		icons_positions[icons[i]] = i
	for icon in icons_for_launch_positions:
		gestures += icons_positions[icon] // k
		if icons_positions[icon] != 0:
			previous_icon = icons[icons_positions[icon] - 1]
			swap(icons, icons_positions[icon], icons_positions[previous_icon])
			swap(icons_positions, icon, previous_icon)
	print(gestures)

def swap(collection_list, first_index, second_index):
	temp = collection_list[first_index]
	collection_list[first_index] = collection_list[second_index]
	collection_list[second_index] = temp

def __starting_point():
	main()
__starting_point()


import sys
r = sys.stdin.readline
(n, m, k) = map(int, r().split())
screen = list(map(int, r().split()))
gesture = 0
arr = [-1] * n
for i in range(n):
	screen[i] -= 1
	arr[screen[i]] = i
for i in list(map(int, r().split())):
	i -= 1
	pos = arr[i]
	gesture += pos // k + 1
	if pos != 0:
		tmp = screen[pos - 1]
		(screen[pos - 1], screen[pos]) = (screen[pos], screen[pos - 1])
		(arr[i], arr[tmp]) = (arr[tmp], arr[i])
print(gesture)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = {}
f = 0
for i in a:
	c[i] = f
	f += 1
cout = 0
for j in b:
	tm = c[j]
	cout += tm // k + 1
	if tm != 0:
		pm = a[tm - 1]
		(c[pm], c[j]) = (c[j], c[pm])
		(a[tm], a[tm - 1]) = (a[tm - 1], a[tm])
print(cout)


def line():
	return [int(c) for c in input().split()]
(n, m, k) = line()
Q = line()
position = [0] * (n + 1)
for i in range(n):
	position[Q[i]] = i
resident = 0
op = line()
for i in range(m):
	resident = resident + 1
	t = op[i]
	p = position[t]
	if p:
		resident += position[t] // k
		(position[t], position[Q[p - 1]]) = (position[Q[p - 1]], position[t])
		(Q[p], Q[p - 1]) = (Q[p - 1], Q[p])
print(resident)


import math
(n, m, k) = map(int, input().split())
lis = list(map(int, input().split()))
ind = [0] * (n + 1)
for i in range(n):
	ind[lis[i]] = i
app = list(map(int, input().split()))
ans = 0
for i in app:
	ans += ind[i] // k + 1
	if ind[i] != 0:
		a = ind[i]
		b = lis[ind[i] - 1]
		(ind[i], ind[b]) = (ind[b], ind[i])
		(lis[a], lis[a - 1]) = (lis[a - 1], lis[a])
print(ans)


(n, m, k) = map(int, input().split())
apps = list(map(int, input().split()))
runs = list(map(int, input().split()))
places = [0] * (n + 1)
for i in range(n):
	places[apps[i]] = i
touchs = 0
for app in runs:
	place = places[app]
	touchs += place // k + 1
	if place > 0:
		app2 = apps[place - 1]
		(apps[place - 1], apps[place]) = (apps[place], apps[place - 1])
		places[app] = place - 1
		places[app2] = place
print(touchs)


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
p = [int(x) for x in input().split()]
o = [int(x) for x in input().split()]
g = 0
pos = {}
val = {}
j = 0
for i in p:
	pos[i] = j
	val[j] = i
	j += 1
for i in o:
	ind = pos[i]
	g += ind // k + 1
	if ind > 0:
		tmp = val[ind - 1]
		val[ind - 1] = i
		pos[i] = ind - 1
		val[ind] = tmp
		pos[tmp] = ind
print(g)


(n, m, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = {}
for i in range(n):
	d[a[i]] = i
import math
total = 0
for i in range(m):
	x = d[b[i]]
	total += math.ceil((x + 1) / k)
	if x > 0:
		(d[a[x - 1]], d[a[x]]) = (d[a[x]], d[a[x - 1]])
		(a[x - 1], a[x]) = (a[x], a[x - 1])
print(total)


s6 = input().split()
n = int(s6[0])
m = int(s6[1])
k = int(s6[2])
sabi = input().split()
loc = []
suma = 0
num = [0] * (n + 10)
for i in range(n):
	sabi[i] = int(sabi[i])
	loc.append(sabi[i])
	num[sabi[i]] = i
ope = input().split()
for i in range(m):
	ope[i] = int(ope[i])
for i in range(m):
	loca = num[ope[i]]
	if loca == 0:
		suma += 1
	else:
		if loca + 1 > k and (loca + 1) % k != 0:
			suma += int((loca + 1) / k) + 1
		elif loca + 1 > k and (loca + 1) % k == 0:
			suma += int((loca + 1) / k)
		elif loca + 1 <= k:
			suma += 1
		tem = loc[loca]
		tem1 = loc[loca - 1]
		loc[loca] = loc[loca - 1]
		loc[loca - 1] = tem
		num[ope[i]] -= 1
		num[tem1] += 1
print(suma)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
perm = [-1] * n
for i in range(0, n):
	a[i] -= 1
	perm[a[i]] = i
ans = 0
for x in b:
	x -= 1
	pos = perm[x]
	ans += pos // k + 1
	if pos != 0:
		val = a[pos - 1]
		(a[pos - 1], a[pos]) = (a[pos], a[pos - 1])
		(perm[x], perm[val]) = (perm[val], perm[x])
print(ans)


(n, m, k) = map(int, input().split())
orders = list(map(int, input().split()))
launchedList = list(map(int, input().split()))
indexes = [0] * (n + 1)
for i in range(n):
	indexes[orders[i]] = i
gestures = 0
for app in launchedList:
	indexThis = indexes[app]
	gestures += int(indexThis / k) + 1
	if indexThis != 0:
		app_temp = app
		orders[indexThis] = orders[indexThis - 1]
		orders[indexThis - 1] = app_temp
		indexes[app] -= 1
		indexes[orders[indexThis]] += 1
print(gestures)


from math import ceil

def move(l, i):
	if i != 0:
		(l[i - 1], l[i]) = (l[i], l[i - 1])
	return l
(n, m, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = {}
for i in range(n):
	d[a[i]] = i
cnt = 0
for i in b:
	cnt += ceil((d[i] + 1) / k)
	if d[i] != 0:
		d[i] -= 1
		d[a[d[i]]] += 1
		move(a, d[i] + 1)
print(cnt)


[n, m, k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.insert(0, 0)
pos = (n + 1) * [0]
for i in range(1, n + 1):
	pos[a[i]] = i
b = [int(i) for i in input().split()]
s = 0
for i in b:
	p = pos[i]
	s = s + (p - 1) // k + 1
	if p != 1:
		[a[p], a[p - 1]] = [a[p - 1], a[p]]
		pos[a[p]] = p
		pos[a[p - 1]] = p - 1
print(s)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = map(int, input().split())
pos = [0] * (n + 1)
for p in range(n):
	pos[a[p]] = p
ct = 0
for i in b:
	cur_pos = pos[i]
	id = i
	ct += cur_pos // k + 1
	if cur_pos > 0:
		prev_pos = pos[i] - 1
		prev_id = a[prev_pos]
		(a[cur_pos], a[prev_pos]) = (a[prev_pos], a[cur_pos])
		(pos[id], pos[prev_id]) = (pos[prev_id], pos[id])
print(ct)


import math
(n, m, k) = [int(x) for x in input().split()]
a = [int(x) - 1 for x in input().split()]
b = [int(x) - 1 for x in input().split()]
res = 0
c = []
for i in range(len(a)):
	c.append([a[i], i])
c.sort()
for i in b:
	e = c[i][1]
	l = max(0, e - 1)
	if l != e:
		res += math.ceil((e + 1) / k)
		(a[e], a[l]) = (a[l], a[e])
		c[a[e]][1] += 1
		c[a[l]][1] -= 1
	else:
		res += 1
print(res)


import sys

def solve():
	(n, m, k) = read()
	a = read()
	b = read()
	loc = [0] * (n + 1)
	for i in range(n):
		loc[a[i]] = i
	res = 0
	for i in range(m):
		dist = loc[b[i]] // k
		res += dist + 1
		if loc[b[i]] > 0:
			loc[b[i]] -= 1
			val = a[loc[b[i]]]
			loc[val] += 1
			(a[loc[b[i]]], a[loc[b[i]] + 1]) = (a[loc[b[i]] + 1], a[loc[b[i]]])
	return res

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	if isinstance(s, tuple):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')

def run():
	if sys.hexversion == 50594544:
		sys.stdin = open('test.txt')
	res = solve()
	write(res)
run()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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')

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()]
(n, m, k) = value()
a = array()
ind = {a[i]: i for i in range(n)}
apps = array()
gesture = 0
for i in apps:
	id = ind[i]
	gesture += 1 + id // k
	if id != 0:
		(ind[i], ind[a[id - 1]]) = (ind[a[id - 1]], ind[i])
		(a[id], a[id - 1]) = (a[id - 1], a[id])
print(gesture)


(n, m, p) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
d1 = {}
for i in range(n):
	d[l[i]] = i + 1
	d1[i + 1] = l[i]
l1 = list(map(int, input().split()))
k = 0
for i in range(m):
	if d[l1[i]] % p != 0:
		k += d[l1[i]] // p + 1
	else:
		k += d[l1[i]] // p
	if d[l1[i]] != 1:
		(d1[d[l1[i]]], d1[d[l1[i]] - 1]) = (d1[d[l1[i]] - 1], d1[d[l1[i]]])
		d[l1[i]] -= 1
		d[d1[d[l1[i]] + 1]] += 1
print(k)


(n, m, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(len(a)):
	d[a[i]] = i
cnt = 0
for i in range(len(b)):
	cnt += d[b[i]] // k
	cnt += 1
	if d[b[i]] != 0:
		d[b[i]] -= 1
		d[a[d[b[i]]]] += 1
		m = a[d[b[i]]]
		a[d[b[i]]] = a[d[b[i]] + 1]
		a[d[b[i]] + 1] = m
print(cnt)


(n, m, k) = map(int, input().split())
phone = list(map(int, input().split()))
action = list(map(int, input().split()))
positions = [0] * (n + 1)
for i in range(len(phone)):
	positions[phone[i]] = i
focus = 0
for i in action:
	focus += 1 + positions[i] // k
	if positions[i] > 0:
		(phone[positions[i]], phone[positions[i] - 1]) = (phone[positions[i] - 1], phone[positions[i]])
		positions[i] -= 1
		positions[phone[positions[i] + 1]] += 1
print(focus)


import sys
input = sys.stdin.readline
from collections import defaultdict
(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x - 1, a))
b = list(map(int, input().split()))
b = list(map(lambda x: x - 1, b))
page = [-1] * n
pos = [-1] * n
d = defaultdict(int)
for i in range(n):
	page[a[i]] = i // k
	pos[a[i]] = i % k
	d[i // k * 10 ** 6 + i % k] = a[i]
ans = 0
for bi in b:
	ans += page[bi] + 1
	if page[bi] == 0 and pos[bi] == 0:
		continue
	page1 = page[bi]
	pos1 = pos[bi]
	if pos1 == 0:
		page2 = page1 - 1
		pos2 = k - 1
	else:
		page2 = page1
		pos2 = pos1 - 1
	ci = d[page2 * 10 ** 6 + pos2]
	page[bi] = page2
	pos[bi] = pos2
	page[ci] = page1
	pos[ci] = pos1
	d[page1 * 10 ** 6 + pos1] = ci
	d[page2 * 10 ** 6 + pos2] = bi
print(ans)


import math
s = input()
l = s.split()
(n, m, k) = (int(i) for i in l)
s = input()
a = s.split()
s = input()
b = s.split()
h1 = [0 for i in range(0, 100001)]
h2 = [0 for i in range(0, 100001)]
count = 1
for i in a:
	t_n = int(i)
	h1[t_n] = int(math.ceil(count / k))
	h2[t_n] = count % k
	if h2[t_n] == 0:
		h2[t_n] = k
	count += 1
ans = 0
for i in b:
	num = int(i)
	ans += h1[num]
	if h2[num] == 1 and h1[num] == 1:
		continue
	elif h2[num] == 1:
		cn = k * (h1[num] - 1) + h2[num] - 1
		h1[int(a[cn - 1])] += 1
		h2[int(a[cn - 1])] = 1
		h1[num] -= 1
		h2[num] = k
		(a[cn - 1], a[cn]) = (a[cn], a[cn - 1])
	else:
		cn = k * (h1[num] - 1) + h2[num] - 1
		h2[num] -= 1
		h2[int(a[cn - 1])] += 1
		(a[cn - 1], a[cn]) = (a[cn], a[cn - 1])
print(ans)


from sys import stdin
from collections import *

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, m, k) = arr_inp(1)
(a, b, ans) = (arr_inp(1), arr_inp(1), 0)
dic = defaultdict(int, {a[i]: i for i in range(n)})
for i in range(m):
	ans += dic[b[i]] // k + 1
	if dic[b[i]]:
		(a[dic[b[i]]], a[dic[b[i]] - 1]) = (a[dic[b[i]] - 1], a[dic[b[i]]])
		dic[a[dic[b[i]]]] += 1
		dic[b[i]] -= 1
print(ans)


def num(s):
	return tuple([int(i) for i in s.split(' ')])
(n, m, k) = num(input())
s = input()
a = [int(i) for i in s.split(' ')]
seq = num(input())
t = 0
pos = [None] * (len(a) + 1)
pos[0] = 200000
for i in range(len(a)):
	pos[a[i]] = i
for i in seq:
	if pos[i] == 0:
		t += 1
	else:
		t += pos[i] // k + 1
		pos[a[pos[i] - 1]] += 1
		pos[i] -= 1
		temp = a[pos[i]]
		a[pos[i]] = a[pos[i] + 1]
		a[pos[i] + 1] = temp
print(t)


(n, m, v) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ind = [0 for i in range(n)]
for i in range(n):
	ind[a[i] - 1] = i
mvt = 0
for i in b:
	k = ind[i - 1]
	if k > 0:
		(a[k], a[k - 1]) = (a[k - 1], a[k])
		(ind[a[k] - 1], ind[a[k - 1] - 1]) = (ind[a[k - 1] - 1], ind[a[k] - 1])
	mvt += k // v + 1
print(mvt)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
ges = 0
memory = 0
for i in range(n):
	d[a[i]] = i + 1
for i in b:
	scr = (d[i] - 1) // k + 1
	ges = ges + scr
	if not d[i] == 1:
		d[i] -= 1
		memory = a[d[i] - 1]
		d[memory] += 1
		a[d[i] - 1] = i
		a[d[i]] = memory
print(ges)


(n, m, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
forward = dict(enumerate(a))
backward = dict(((y, x) for (x, y) in enumerate(a)))
b = [int(x) for x in input().split()]
res = 0
for x in b:
	pos = backward[x]
	res += pos // k + 1
	if pos != 0:
		prev = forward[pos - 1]
		forward[pos] = prev
		forward[pos - 1] = x
		backward[prev] = pos
		backward[x] = pos - 1
print(res)


def foo():
	(n, m, k) = map(int, input().split())
	(a, b) = ([0] * n, [0] * n)
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] -= 1
		b[a[i]] = i
	c = list(map(int, input().split()))
	answer = 0
	for element in c:
		element -= 1
		answer += b[element] // k + 1
		if b[element]:
			(a[b[element]], a[b[element] - 1]) = (a[b[element] - 1], a[b[element]])
			b[a[b[element]]] += 1
			b[element] -= 1
	return answer
print(foo())


import sys
input = sys.stdin.readline
print = sys.stdout.write
(n, m, k) = map(int, input().split())
s = input().split()
(loat, step) = ([0] * (n + 1), [0] * (n + 1))
for x in range(n):
	tmp = int(s[x])
	step[tmp] = x
	loat[x] = tmp
ans = 0
s = input().split()
for i in range(m):
	tmp = int(s[i])
	ans += step[tmp] // k + 1
	if not step[tmp]:
		continue
	loat[step[tmp]] = loat[step[tmp] - 1]
	step[tmp] -= 1
	step[loat[step[tmp]]] += 1
	loat[step[tmp]] = tmp
print(str(ans))


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = {}
for (i, ai) in enumerate(a):
	p[ai] = i
sol = 0
for bi in b:
	pi = p[bi]
	sol += pi // k + 1
	if pi > 0:
		bj = a[pi - 1]
		(p[bi], p[bj]) = (p[bj], p[bi])
		(a[pi], a[pi - 1]) = (a[pi - 1], a[pi])
print(sol)


def cal(p, k):
	return p // k + 1
tmp = [int(x) for x in input().split(' ')]
n = tmp[0]
m = tmp[1]
k = tmp[2]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
dic = {}
idx = {}
for i in range(0, len(a)):
	dic[a[i]] = i
	idx[i] = a[i]
ans = 0
for x in b:
	p = dic[x]
	ans += cal(p, k)
	if p == 0:
		continue
	q = p - 1
	y = idx[q]
	(dic[x], dic[y]) = (dic[y], dic[x])
	(idx[p], idx[q]) = (idx[q], idx[p])
print(ans)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(d, di, res) = ({}, {}, 0)
for (i, x) in enumerate(a):
	d[x] = i
	di[i] = x
for (i, y) in enumerate(b):
	x = d[y]
	res += x // k + 1
	if x > 0:
		d[di[x - 1]] += 1
		d[y] -= 1
		(di[x], di[x - 1]) = (di[x - 1], di[x])
print(res)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def modInverse(b):
	g = gcd(b, mod)
	if g != 1:
		return -1
	else:
		return pow(b, mod - 2, mod)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, m, k) = sep()
	a = lis()
	b = lis()
	pos = {}
	for i in range(n):
		pos[a[i]] = i
	whichone = deepcopy(a)
	ans = 0
	for i in range(m):
		ind = pos[b[i]]
		if ind == 0:
			ans += 1
			continue
		ans += ind // k
		ans += 1
		del pos[b[i]]
		del pos[whichone[ind - 1]]
		pos[b[i]] = ind - 1
		pos[whichone[ind - 1]] = ind
		(whichone[ind], whichone[ind - 1]) = (whichone[ind - 1], whichone[ind])
	print(ans)
testcase(1)


(n, m, k) = map(int, input().split())
an = [0] + list(map(int, input().split()))
na = [0] * (n + 1)
bm = list(map(int, input().split()))
num = 0
for i in range(1, n + 1):
	na[an[i]] = i
for i in range(m):
	if na[bm[i]] != 1:
		temp = an[na[bm[i]] - 1]
		an[na[bm[i]] - 1] = an[na[bm[i]]]
		an[na[bm[i]]] = temp
		num += (na[bm[i]] - 1) // k
		temp2 = na[bm[i]]
		na[bm[i]] = na[temp]
		na[temp] = temp2
print(num + m)


(n, m, k) = map(int, input().split())
a = [0] * n
l = [0] * n
z = 0
for i in input().split():
	j = int(i)
	a[j - 1] = z
	l[z] = j - 1
	z += 1
r = 0
for i in input().split():
	j = int(i) - 1
	c = a[j]
	r += c // k + 1
	if c != 0:
		(l[c - 1], l[c]) = (l[c], l[c - 1])
		a[l[c]] += 1
		a[j] -= 1
print(r)


(n, m, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a1 = [0] * (n + 1)
i = 1
for j in a:
	a1[j] = i
	i += 1
b = [int(i) for i in input().split()]
ans = 0
for i in b:
	index = a1[i]
	ans += (index - 1) // k + 1
	if index > 1:
		tmp1 = a[index - 1]
		tmp0 = a[index - 2]
		(a[index - 1], a[index - 2]) = (tmp0, tmp1)
		(a1[tmp0], a1[tmp1]) = (index, index - 1)
print(ans)


def read():
	return [int(c) for c in input().split()]

def main():
	INF = float('infinity')
	(n, m, k) = read()
	init = read()
	actions = read()
	assoc = {}
	for (i, e) in enumerate(init):
		assoc[e] = i
	page = [i // k for i in range(n)]
	prv = [-INF] + init[:-1]
	nxt = init[1:] + [INF]
	ans = 0
	for a in actions:
		ans += page[assoc[a]] + 1
		if assoc[a] == 0:
			continue
		(x, y) = (assoc[a], assoc[a] - 1)
		(prv[x], prv[y]) = (prv[y], a)
		(nxt[x], nxt[y]) = (init[y], nxt[x])
		assoc[a] -= 1
		assoc[init[y]] += 1
		(init[x], init[y]) = (init[y], init[x])
	print(ans)
main()


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = [0] * (n + 1)
arr = [0] * (n + 1)
for i in range(len(a)):
	pos[a[i]] = i + 1
	arr[i + 1] = a[i]
l = 0
for i in b:
	if pos[i] % k:
		l += pos[i] // k + 1
	else:
		l += pos[i] // k
	if pos[i] - 1:
		tempPos = pos[i]
		tempArr = arr[pos[i] - 1]
		pos[i] -= 1
		pos[tempArr] += 1
		arr[pos[i]] = i
		arr[pos[i] + 1] = tempArr
print(l)


(N, M, K) = map(int, input().split())
apps_list = input().split()
launchs = input().split()
apps = {apps_list[i]: i for i in range(len(apps_list))}
touches = 0
for launch in launchs:
	index = apps[launch]
	touches += index // K + 1
	if index != 0:
		prev = apps_list[index - 1]
		apps[prev] = index
		apps_list[index] = prev
		apps[launch] = index - 1
		apps_list[index - 1] = launch
print(touches)


nums = [int(x) for x in input().split()]
appsCount = nums[0]
launchedAppsCount = nums[1]
appsPerPage = nums[2]
appIDs = [int(x) for x in input().split()]
launchedAppIDs = [int(x) for x in input().split()]
appIDsPosition = {}
for (idx, id) in enumerate(appIDs):
	appIDsPosition[id] = idx
totalMoves = 0
for launchedID in launchedAppIDs:
	position = appIDsPosition[launchedID]
	totalMoves += position // appsPerPage + 1
	if position > 0:
		appIDsPosition[launchedID] = position - 1
		neighborApp = appIDs[appIDsPosition[launchedID]]
		appIDsPosition[neighborApp] = position
		temp = appIDs[position]
		appIDs[position] = neighborApp
		appIDs[position - 1] = temp
print(totalMoves)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
rev = dict(zip(a, range(0, n)))
sum = 0
for x in map(int, input().split()):
	loc = rev[x]
	sum += loc // k + 1
	if loc > 0:
		y = a[loc - 1]
		a[loc - 1:loc + 1] = [x, y]
		(rev[x], rev[y]) = (loc - 1, loc)
print(sum)


(n, m, k) = [int(x) for x in input().split()]
a = [int(x) - 1 for x in input().split()]
b = [int(x) - 1 for x in input().split()]
ra = [0] * n
for (i, v) in enumerate(a):
	ra[v] = i
ans = 0
for v in b:
	i = ra[v]
	ans += i // k + 1
	if i == 0:
		continue
	j = i - 1
	u = a[j]
	(ra[u], ra[v]) = (ra[v], ra[u])
	(a[i], a[j]) = (a[j], a[i])
print(ans)


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, m, k) = ilele()
A = alele()
B = alele()
G1 = {}
G2 = {}
kk = 0
for i in range(0, n, k):
	kk += 1
	l = 1
	for j in range(i, min(i + k, n)):
		G1[A[j]] = (kk, l)
		G2[kk, l] = A[j]
		l += 1
Ans = 0
for i in B:
	(x, y) = G1[i]
	Ans += x
	if y != 1:
		z = G2[x, y - 1]
		(G1[i], G1[z]) = (G1[z], G1[i])
		(G2[x, y], G2[x, y - 1]) = (G2[x, y - 1], G2[x, y])
	elif x != 1:
		z = G2[x - 1, k]
		(G1[i], G1[z]) = (G1[z], G1[i])
		(G2[x, y], G2[x - 1, k]) = (G2[x - 1, k], G2[x, y])
print(Ans)


def line():
	return [int(c) for c in input().split()]
(n, m, k) = line()
Q = line()
pos = [0] * (n + 1)
for i in range(n):
	pos[Q[i]] = i
res = 0
op = line()
for i in range(m):
	res += 1
	t = op[i]
	p = pos[t]
	if p:
		res += pos[t] // k
		(pos[t], pos[Q[p - 1]]) = (pos[Q[p - 1]], pos[t])
		(Q[p], Q[p - 1]) = (Q[p - 1], Q[p])
print(res)


s = input().split()
n = int(s[0])
m = int(s[1])
k = int(s[2])
s = input().split()
screen = [0 for i in range(n + 1)]
position = [0 for i in range(n + 1)]
sl = 0
a = [[0]]
tg = [0]
for ii in range(n):
	i = ii + 1
	screen[int(s[ii])] = int(i / k) + min(1, i % k)
	tg.append(int(s[ii]))
	sl += 1
	if sl == k or ii == n - 1:
		a.append(tg)
		sl = 0
		tg = [0]
	if i % k == 0:
		position[int(s[ii])] = k
	else:
		position[int(s[ii])] = i % k
s = input().split()
quest = []
for i in range(m):
	quest.append(int(s[i]))
kq = 0
for i in range(m):
	app = quest[i]
	kq += screen[app]
	vt_scr = screen[app]
	vt_pos = position[app]
	if position[app] != 1:
		bef_pos = vt_pos - 1
		bef_scr = vt_scr
		app_bef = a[bef_scr][bef_pos]
		(position[app_bef], position[app]) = (position[app], position[app_bef])
		(a[bef_scr][bef_pos], a[vt_scr][vt_pos]) = (a[vt_scr][vt_pos], a[bef_scr][bef_pos])
	elif screen[app] != 1:
		bef_pos = k
		bef_scr = vt_scr - 1
		app_bef = a[bef_scr][bef_pos]
		(position[app_bef], position[app]) = (position[app], position[app_bef])
		(screen[app_bef], screen[app]) = (screen[app], screen[app_bef])
		(a[bef_scr][bef_pos], a[vt_scr][vt_pos]) = (a[vt_scr][vt_pos], a[bef_scr][bef_pos])
print(kq)


(n, m, k) = map(int, input().split())
a = list(map(int, input().split()))
q = list(map(int, input().split()))
id_ind = {}
ind_id = {}
for i in range(n):
	id_ind[a[i]] = i
	ind_id[i] = a[i]
ct = 0
for i in range(m):
	ct += id_ind[q[i]] // k
	ct += 1
	if id_ind[q[i]] != 0:
		a = id_ind[q[i]]
		b = id_ind[q[i]] - 1
		c = ind_id[a]
		d = ind_id[b]
		ind_id[a] = d
		id_ind[d] = a
		ind_id[b] = c
		id_ind[c] = b
print(ct)


(n, m, k) = map(int, input().split())
v = [int(x) for x in input().split()]
ind = [-1 for i in range(n + 1)]
for i in range(n):
	ind[v[i]] = i
ans = 0
for a in input().split():
	a = int(a)
	i = ind[a]
	ans += i // k + 1
	if i == 0:
		continue
	j = i - 1
	b = v[j]
	(v[i], v[j]) = (v[j], v[i])
	ind[a] -= 1
	ind[b] += 1
print(ans)


import math
from sys import stdin, stdout

def get_order(pemut):
	order = dict()
	for i in range(1, n + 1):
		order[permut[i - 1]] = i
	r_order = dict()
	for i in order:
		r_order[order[i]] = i
	return (order, r_order)
(n, m, k) = list(map(int, stdin.readline().split()))
permut = list(map(int, stdin.readline().split()))
(order, r_order) = get_order(permut)
barr = list(map(int, stdin.readline().split()))
ans = 0
for num in barr:
	ans += math.ceil(order[num] / k)
	if order[num] != 1:
		temp = r_order[order[num] - 1]
		temp2 = order[num]
		order[num] = order[num] - 1
		r_order[temp2] = temp
		r_order[temp2 - 1] = num
		order[temp] = temp2
print(ans)


(n, m, k) = map(int, input().split())
arr = [0] * n
pl = [0] * n
z = 0
for i in input().split():
	j = int(i)
	arr[j - 1] = z
	pl[z] = j - 1
	z += 1
r = 0
for i in input().split():
	j = int(i) - 1
	c = arr[j]
	r += c // k + 1
	if c != 0:
		(pl[c - 1], pl[c]) = (pl[c], pl[c - 1])
		arr[pl[c]] += 1
		arr[j] -= 1
print(r)


(n, m, k) = [int(x) for x in input().split()]
apps = [int(x) for x in input().split()]
uses = [int(x) for x in input().split()]
poss = {}
for i in range(n):
	poss[apps[i]] = i
gestures = 0
for use in uses:
	pos = poss[use]
	gestures += pos // k + 1
	if pos > 0:
		poss[apps[pos]] = pos - 1
		poss[apps[pos - 1]] = pos
		tmp = apps[pos]
		apps[pos] = apps[pos - 1]
		apps[pos - 1] = tmp
print(gestures)


(n, m, k) = map(int, input().split())
a = input().split()
b = input().split()
a1 = [0] * (n + 1)
a2 = [0] * (n + 1)
for i in range(1, n + 1):
	a1[i] = int(a[i - 1])
	a2[int(a[i - 1])] = i
s = 0
for i in range(m):
	q1 = a2[int(b[i])]
	s += 1 + (q1 - 1) // k
	if q1 > 1:
		j = a1[q1]
		a1[q1] = a1[q1 - 1]
		a1[q1 - 1] = j
		a2[int(b[i])] -= 1
		a2[a1[q1]] += 1
print(s)


from sys import stdin
input = stdin.readline
(n, m, k) = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = list(map(int, input().split()))
idx = [0] * (n + 1)
for i in range(1, n + 1):
	idx[a[i]] = i
ans = 0
for i in range(m):
	bb = b[i]
	ans += (idx[bb] - 1) // k + 1
	if idx[bb] > 1:
		i1 = idx[bb]
		i2 = idx[bb] - 1
		num1 = a[i1]
		num2 = a[i2]
		(a[i1], a[i2]) = (a[i2], a[i1])
		(idx[num1], idx[num2]) = (idx[num2], idx[num1])
print(ans)


answer = 0

def ke(n):
	return n[0]
(n, m, k) = map(int, input().split())
a = input().split()
b = input().split()
for i in range(m):
	b[i] = int(b[i])
a_pos = []
for i in range(n):
	a[i] = int(a[i])
	a_pos.append([a[i], i])
a_pos.sort(key=ke)
for i in range(m):
	request = b[i]
	r = a_pos[request - 1][1]
	l = max(0, r - 1)
	if l != r:
		answer += (r + 1) // k + int((r + 1) % k != 0)
		a_pos[a[l] - 1][1] += 1
		a_pos[a[r] - 1][1] -= 1
		(a[l], a[r]) = (a[r], a[l])
	else:
		answer += 1
print(answer)


import math
from collections import deque
(n, m, k) = (int(i) for i in input().split())
line = input().split()
dict1 = {}
dict2 = {}
for i in range(n):
	dict2[i + 1] = int(line[i])
	dict1[int(line[i])] = i + 1
line = input().split()
num = 0
for j in range(m):
	r = int(line[j])
	if dict1[r] != 1:
		posR = dict1[r]
		num += (posR - 1) // k + 1
		posRprev = posR - 1
		rPrev = dict2[posRprev]
		(dict1[r], dict1[rPrev]) = (dict1[rPrev], dict1[r])
		(dict2[posR], dict2[posRprev]) = (dict2[posRprev], dict2[posR])
	else:
		num += 1
print(num)


import math

def solve():
	(n, m, k) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	query = list(map(int, input().split(' ')))
	indexes = {}
	values = {}
	for i in range(n):
		indexes[arr[i]] = i
		values[i] = arr[i]
	moves = 0
	for i in query:
		moves += math.ceil(indexes[i] // k) + 1
		if indexes[i] == 0:
			continue
		current_index = indexes[i]
		prev_value = values[current_index - 1]
		tmp = current_index
		indexes[i] = current_index - 1
		indexes[prev_value] = current_index
		values[current_index - 1] = i
		values[current_index] = prev_value
	print(moves)
solve()