#P16484. [GKS 2014 #B] Card Game

[GKS 2014 #B] Card Game

Problem Description

Bob is fond of playing cards. On his birthday party, his best friend Alice gave him a set of cards.

There are NN cards and each card contains an integer number. He put the cards from left to right on a desk and wants to discard some of them. Before he discards any cards, he will choose a number KK. At each time, he always chooses 33 adjacent cards to discard, and we assume that the numbers on each card from left to right are aa, bb and cc. Bob guarantees that

cb=ba=K\begin{aligned} c - b = b - a = K \end{aligned}

Bob want to know what is the smallest number of cards he can be left with at the end. If he ever has a choice of which cards to discard, he chooses the cards and will leave the fewest cards at the end.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test cases contains two lines. The first line of each test case contains two integers: the number of cards NN and the number KK Bob chooses. The second line contains NN integers a1a_1, a2a_2, ..., aNa_N the numbers on the cards from left to right.

Output Format

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the smallest number of cards Bob can be left with after he has discarded everything he can.

2
6 0
4 4 3 3 3 4
5 1
3 1 2 3 4
Case #1: 0
Case #2: 2

Hint

Limits

1T1001 \le T \le 100.

1ai106(1iN)1 \le a_i \le 10^6(1 \le i \le N).

1N1001 \le N \le 100.

Small dataset (Test set 1 - Visible)

K=0K = 0.

Large dataset (Test set 2 - Hidden)

1K1061 \le K \le 10^6.