This page is still under construction.

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

Dorm Party

Time limit1sMemory limit256 MB

Summary
Choose up to K building resets over N daily move-ins to minimize the sum of current occupancy counts at each arrival.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy, Math
Solved
No attempts yet

Problem

A new student dorm has opened. It has MM buildings, numbered from 1 to MM. The dorm starts empty, and over the next NN days exactly one student moves in each day.

Every time a student moves into a building, a party is held in that building. The noise of the party equals the number of students inside that building at that moment. The management dislikes noise, so now and then it empties one whole building by moving every resident of that building to a different dorm. The management can empty a building after the end of any day, but it decided that emptying more than KK times does not pay off. Emptying one building counts as one time.

You are given which building a student moves into on each day. Find the smallest possible sum of the noise of all NN parties when buildings are emptied at most KK times.

Input

The first line contains NN (1≤N≤1061 \le N \le 10^6), MM (1≤M≤1001 \le M \le 100) and KK (1≤K≤5001 \le K \le 500).

The ii-th of the next NN lines contains the number of the building a student moves into on day ii. This number is between 1 and MM.

Output

Print the smallest possible total noise on one line.

Hint

In the first example the building is emptied after day 1 and after day 3, so the noise values are 1, 1, 2, 1, 2. With no emptying at all they would be 1, 2, 3, 4, 5.

In the second example one option is to empty building 1 after day 4 and after day 8, and building 2 after day 6. The noise values are then 1, 1, 2, 2, 1, 3, 2, 1, 1, 2, 2.

Examples2

  1. Example 1

    Input
    5 1 2
    1
    1
    1
    1
    1
    
    Expected output
    7
    
  2. Example 2

    Input
    11 2 3
    1
    2
    1
    2
    1
    2
    1
    2
    1
    2
    1
    
    Expected output
    18