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.

Difficulty: interview

Starter code:

Solutions:
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
#print(arr, pl)
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(arr, pl)
print(r)

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)

def foo():
    n, m, k = list(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())


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)

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

# n = 100000
# order = [0] * n
# k = 2
# m = 100000
# touch = [0] * n
# for i in range(n):
#     order[i] = i
# for i in range(m):
#     touch[i] = i

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)

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)


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


#Doc du lieu (dòng 1)
s=input().split()
n=int(s[0])
m=int(s[1])
k=int(s[2])
#Khoi tao mang
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
#Doc du lieu (dòng 2)
#Doc du lieu (dòng 3)
s=input().split()
quest=[]
for i in range(m):
    quest.append(int(s[i]))
#Ktra
#Xu ly
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]
    else:
        if 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 = 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)
    
    
    


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
	#print(app[1:], pos[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(app[1:], pos[1:])
	print(swipes)




def __starting_point():
	main()
__starting_point()

#!/usr/env python3

n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]  # a[p] = id of app at position p (p=0,1,2,...)
b = [int(x) for x in input().split()]
assert(len(a) == n)
assert(len(b) == m)
pos = [0]*(n+1)  # c[i] = position of app with id i (id=1,2,3,...)
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)

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
    #print(app[1:], pos[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(app[1:], pos[1:])
    print(swipes)




def __starting_point():
    main()
__starting_point()

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()))
    # n = 10
    # m = 12
    # k = 3
    # icons = [6, 1, 2, 9, 3, 10, 8, 5, 7, 4]
    # icons_for_launch_positions = [3, 9, 9, 4, 8, 2, 3, 8, 10, 8, 3, 4]

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

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
    positions = [0] * (n + 1)

    for i in range(0, len(icons)):
        positions[icons[i]] = i

    for icon in icons_for_launch_positions:
        gestures += (positions[icon] // k)

        if positions[icon] != 0:
            previous_icon = icons[positions[icon] - 1]

            swap(icons, positions[icon], positions[previous_icon])
            swap(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

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  # String
    if mode == 1: return inputs.split()  # List of strings
    if mode == 2: return list(map(int, inputs.split()))  # List of integers
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 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  # String
    if mode == 1: return inputs.split()  # List of strings
    if mode == 2: return list(map(int, inputs.split()))  # List of integers
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()

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
	#print('элемент', i, 'имеет индекс', positions[i])
	#print('\t',  1+(positions[i])//k, phone)
	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('после он имеет идекс', positions[i])

print(focus)

#!/usr/bin/env python3
n, m, k = map(int, input().split(' '))
a = map(int, input().split(' ')) # initial app order
b = map(int, input().split(' ')) # launch order

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)

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)



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)



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)


n, m, k = list(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
#print(pos, arr)
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)


#!/bin/python

apps_size, launched_size, apps_per_screen = list(map(int, input().split()))

apps = list(map(int, input().split()))
launched = list(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)


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)