Question: Problem to be solved in python Time limit: 10 seconds Memory limit: 512 Mb All your 0 < N 10 5 books (materials) are situated

Problem to be solved in python

Time limit: 10 seconds

Memory limit: 512 Mb

All your 0 < N 105 books (materials) are situated in the bookcase. When you need a book, you take it from a bookcase and place it on the table. Unfortunately, your table is not very big: it may contain only K books simultaneously. If you have K books on the table, and you need one which is not on the table you should return one book from the table to the bookcase and replace it with the needed one.

You want to concentrate on study, so you decided to minimize number of times you will take book from bookcase. You have enumerated all books with numbers [0; N) and prepared a list of 0 < M < 105 books in order you will use them (one book can be present more than one time in this list). Calculate minimum number of times you should take book from bookcase according to given list.

Input format

First line contains 3 integer numbers: 0 < N, K, M 105 number of books in the bookcase, maximum number of books on the table, number of items in the usage list.

Second line contains N integer numbers [0, N) ids of books in order you will use them.

Output format

Print single integer number minimum number of times you will need to take a book from a bookcase.

Sample 1

Input

Output

3 2 4 1 2 3 1 
3 

Sample 2

Input

Output

3 3 6 1 2 3 1 2 3 
3 

Sample 3

Input

Output

3 3 3 1 1 1 
1 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!