This page is still under construction.

Parts of this page are still being built. What you see may change.

Car Parking

Time limit1sMemory limit128 MB

Summary
Given a row of cars and W workers, find the minimum number of cars that must change places so the types are sorted ascending.
Level

Medium6 of 10

Topics
Greedy, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

A parking center next to the Great Wall has one long row of parking places. One end of the row is called the left end and the other one the right end. Every place holds a car. Each car has a type written as an integer, and several cars may share a type.

WW workers rearrange the cars so that the types read in ascending order from the left end to the right end. They work in rounds. In one round each worker may drive one car out of its place and then park that car in a place that another car left during the same round, so a round shuffles the cars it touches among the places those cars just gave up. A worker may also stay idle during a round.

The workers want as few cars as possible to end up somewhere else. A car counts as moved when its final place differs from its starting place, no matter how many rounds it spent driving around. Cars of the same type are interchangeable, so a car may finish in the place where another car of the same type started.

Given the types of the parked cars and the number of workers, find the smallest number of cars that have to be moved.

Input

The first line contains three integers. The first one is the number of cars NN, 2≤N≤200002 \le N \le 20000. The second one is the number of types MM, 2≤M≤502 \le M \le 50. The car types are the integers from 11 to MM, and at least one car of each type stands in the row. The third one is the number of workers WW, 2≤W≤M2 \le W \le M. The second line contains NN integers, where the iith integer is the type of the iith car in the row, counted from the left end.

Output

Print one integer, the smallest number of cars that have to be moved so that the types read in ascending order from the left end to the right end.

Examples2

  1. Example 1

    Input
    10 4 4
    2 3 3 4 4 2 1 1 3 1
    
    Expected output
    10
    
  2. Example 2

    Input
    6 2 2
    2 1 1 1 2 2
    
    Expected output
    2