human
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...
Using python can you solve the prior task?

=====
What is a the Python program you requested?
assistant
#Here is the Python program you requested.

[n, m, k] = map(int, raw_input('').split(' '))
app_ids = map(int, raw_input('').split(' '))
ids_to_launch = map(int, raw_input('').split(' '))

class Node(object):

    def __init__(self, location, prev_node=None, next_node=None):
        self.location = location
        self.prev = prev_node
        self.next = next_node

def delete(app_id_to_location, app_id_to_delete):
    node = app_id_to_location[app_id_to_delete]
    if node.prev is not None:
        app_id_to_location[node.prev].next = node.next
    if node.next is not None:
        app_id_to_location[node.next].prev = node.prev
    app_id_to_location[app_id_to_delete] = None

def insert_after(app_id, app_id_to_location, app_id_to_insert, new_location):
    node = app_id_to_location[app_id]
    new_node = Node(new_location, app_id, node.next)
    if node.next is not None:
        app_id_to_location[node.next].prev = app_id_to_insert
    node.next = app_id_to_insert
    app_id_to_location[app_id_to_insert] = new_node

app_id_to_location = {}
for (ind, app_id) in enumerate(app_ids):
    if ind == 0:
        previous_app_id = None
    else:
        previous_app_id = app_ids[ind - 1]
    if ind == n - 1:
        next_app_id = None
    else:
        next_app_id = app_ids[ind + 1]
    app_id_to_location[app_id] = Node(ind + 1, previous_app_id, next_app_id)

cost = 0
for app_id in ids_to_launch:
    cost += (((app_id_to_location[app_id].location - 1) / k) + 1)
    if app_id_to_location[app_id].prev is not None:
        app_id_to_delete = app_id_to_location[app_id].prev
        delete(app_id_to_location, app_id_to_delete)
        insert_after(app_id, app_id_to_location, app_id_to_delete, app_id_to_location[app_id].location)
        app_id_to_location[app_id].location -= 1

print cost