The Tasting Flight
Sommelier Alice keeps n open bottles on one long shelf, numbered 1 to n from left to right.
Each bottle carries a label with the code of its grape variety; bottle i has variety c_i.
Several bottles may share a variety, and bottles of the same variety need not stand next to each
other.
For tonight's guests Alice pours a flight: she picks two positions l ≤ r and pours one glass
from every bottle l, l+1, …, r, without skipping any bottle in between. A flight is balanced
if the glasses in it come from exactly K different varieties (how many glasses each variety
contributes does not matter).
Two flights are different if they start or end at a different bottle, even if they happen to contain the same varieties. How many different balanced flights can Alice pour?
Input
The first line contains two integers n and K (1 ≤ K ≤ n ≤ 2·10^5).
The second line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^9), the variety codes of the
bottles from left to right.
Output
Print one integer: the number of pairs (l, r) with 1 ≤ l ≤ r ≤ n such that bottles l through
r contain exactly K distinct varieties. Print 0 if there are none. The answer may not fit in a
32-bit integer.
Notes
In the first example the shelf is 1 2 1 2 3 and K = 2. The balanced flights are bottles 1–2,
1–3, 1–4, 2–3, 2–4, 3–4 and 4–5: seven in total. Flights such as 3–5 contain three varieties and
do not count.
In the second example only one variety exists on the shelf, so no flight can contain three.