#P6418. [COCI 2014/2015 #1] ZABAVA

[COCI 2014/2015 #1] ZABAVA

Description

A new apartment complex has opened, and it has mm buildings.

Now there are nn students. Each day, exactly one student moves in.

After a student enters a building, a party will be held in that building, and the noise index of the party equals the current number of students in that building.

However, you may perform up to kk operations. In each operation, you can kick all students in one building out of this new apartment complex.

Note that the student enters the building first, and only then can you perform an operation.

Now find the minimum possible total sum of the noise indices.

You do not have to use all operations.

Input Format

The first line contains three integers n,m,kn,m,k.

The next nn lines each contain one integer pp. Line ii means that on day ii, the ii-th student moves into building pp.

Output Format

Output one line: the minimum possible total sum of the noise indices.

5 1 2
1
1
1
1
1
7
11 2 3
1
2
1
2
1
2
1
2
1
2
1
18

Hint

Sample Explanation

Explanation for Sample Input/Output 1

You can clear building 11 on day 11 and day 33. Then the noise index for each day is 1,1,2,1,21,1,2,1,2. If you never clear, the noise index for each day is 1,2,3,4,51,2,3,4,5.

Explanation for Sample Input/Output 2

Clear building 11 on day 44 and day 88, and clear building 22 on day 66. Then the noise index for each day is 1,1,2,2,1,3,2,1,1,2,21,1,2,2,1,3,2,1,1,2,2.

Constraints

  • For 4040 points, it is guaranteed that m=1m=1.
  • For 6060 points, it is guaranteed that n103n\le 10^3.
  • For 8080 points, it is guaranteed that n5×104n\le 5\times 10^4.
  • For 100%100\% of the testdata, it is guaranteed that 1n1061\le n\le 10^6, 1m1001\le m\le 100, 1k5001\le k\le 500, 1pm1\le p\le m.

Notes

The total score for this problem is 140140 points.

This problem is translated from Croatian Open Competition in Informatics 2014/2015 Contest #1 T5 ZABAVA.

Translated by ChatGPT 5