#P802B. Heidi and Library (medium)

    ID: 4184 Type: RemoteJudge 10000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>data structuresgreedy*1800

Heidi and Library (medium)

No submission language available for this problem.

Description

Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.

Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.

Same as the easy version.

Input

Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.

Output

Same as the easy version.

Samples

4 100
1 2 2 1

2

4 1
1 2 2 1

3

4 2
1 2 3 1

3