Time Limit: 1 Sec Memory Limit: 128 MB
The capacity of Hong’s pocket is so small that it can only contain
Hong will visit
When Hong stops in a shop which sells gift
- If there is no gift
$K$ in his pocket and he still has some place for it, he will buy it without hesitation. Before putting it into the pocket, he will write down the number1
on the gift to indicate that he has only seen one shop selling it. - If there is a gift
$K$ already in his pocket, he will just add L by one, which means that there are$L+1$ shops selling gift$K$ . - If there is no gift
$K$ in his pocket and the pocket is full, he would consider that there is no shop selling gift$K$ (because he cannot remember whether he has met gift$K$ ), so he will have to discard one gift in his pocket to release a place for the gift$K$ . But it will refer to the following rules to determine which gifts to be discarded:
He chooses the gift that has the biggest number 1
on gift
Now, your task is to write a program to record the number of these gifts which have been discarded by Hong.
The first line will be an integer
For each test data:
The first line has two positive integers
For each test case you should output one integer, the number of discarded gifts as indicated in the sample output.
6
3 5
1 2 3 2 4
2 4
1 2 2 1
2 6
1 2 2 1 1024 1
2 10
1 2 3 2 4 2 3 6 7 8
2 1
1048575
6 16
10 1 2 3 4 5 6 1 2 3 6 5 4 10 1 6
1
0
2
7
0
3