I found an interesting problem on https://codeforces.com/problemset/problem/802/A:
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.

We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 ≤ i ≤ n) precisely one person will come to the library, request to borrow the book a_{i}, read it in a few hours, and return the book later on the same day.

Heidi desperately wants to please all her guests, so she will make sure to always have the book a_{i} available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.

There is a problem, though. The capacity of the library is k – this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.

You are given k and the sequence of requests for books a_1, a_2, ..., a_{n}. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?


-----Input-----

The first line of input will contain two integers n and k (1 ≤ n, k ≤ 80). The second line will contain n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) – the sequence of book requests.


-----Output-----

On a single line print the minimum cost of buying books at the store so as to satisfy all requests.


-----Examples-----
Input
4 80
1 2 2 1

Output
2

Input
4 1
1 2 2 1

Output
3

Input
4 2
1 2 3...

I tried it in Python, but could not do it. Can you solve it?
n, k = [int(x) for x in input().split()]
requests = [int(x) for x in input().split()]

req_list = {}

def find_last(bucket):
    last_book = None
    last_date = None
    nonlocal req_list
    i = 0
    for item in bucket:
        #print(item, req_list)
        if last_book is None:
            last_book = item
            if len(req_list[item]) < 1:
                last_date = float('inf')
                return item, i
            else:
                last_date = req_list[item][0]
            index = i
        elif len(req_list[item]) >= 1 and req_list[item][0] > last_date:
            last_book = item
            last_date = req_list[item][0]
            index = i
        elif len(req_list[item]) < 1 and last_date < float('inf'):
            return item, i
        i += 1
    return last_book, index

def update_reqlist(book):
    nonlocal req_list
    req_list[book] = req_list[book][1:]


for i in range(n):
    if requests[i] in req_list:
        req_list[requests[i]].append(i)
    else:
        req_list[requests[i]] = [i]

bucket = []
bucket_size = 0
cost = 0
for book in requests:
    if book in bucket:
        update_reqlist(book)
        continue
    if bucket_size < k:
        bucket.append(book)
        bucket_size += 1
        cost += 1
        update_reqlist(book)
    else:
        last_book, index = find_last(bucket)
        if len(bucket) > 1:
            bucket.pop(index)
        else:
            bucket = []
        bucket.append(book)
        update_reqlist(book)
        cost += 1
    #print(bucket, req_list)

#print(req_list)
print(cost)