Under construction

Still being built. Things may change

Card Game

Time limit5sMemory limit512 MB

Summary
Bob repeatedly deletes three neighboring cards whose values form an arithmetic progression with difference K, and seeks the fewest cards that can remain.
Level

Medium7 of 10

Topics
Dynamic programming, Intervals
Solved
No attempts yet

Problem

Bob likes playing cards. For his birthday his friend Alice gave him a set of cards.

There are NN cards, and each card has one integer written on it. Bob lays the cards on a desk from left to right and wants to discard some of them. Before discarding anything he picks one integer KK. Each discard takes three cards that are neighbours at that moment. If the numbers on those three cards, read from left to right, are aa, bb and cc, they must satisfy

c−b=b−a=Kc - b = b - a = K

Discarding three cards empties their place, so the card just left of them and the card just right of them become neighbours. Bob repeats this as long as some three neighbouring cards satisfy the condition, and he may choose which three to discard.

Find the smallest number of cards Bob can be left with when he chooses discards as well as possible.

Input

The first line contains the number of test cases TT. TT test cases follow.

Each test case has two lines. The first line contains the number of cards NN and the number KK that Bob picked, separated by a space. The second line contains the numbers on the cards from left to right, a1,a2,…,aNa_1, a_2, \dots, a_N, separated by spaces.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤1001 \le N \le 100
  • 1≤ai≤1061 \le a_i \le 10^6 (1≤i≤N1 \le i \le N)
  • 0≤K≤1060 \le K \le 10^6

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1, and yy is the smallest number of cards Bob can be left with.

Examples1

  1. Example 1

    Input
    2
    6 0
    4 4 3 3 3 4
    5 1
    3 1 2 3 4
    
    Expected output
    Case #1: 0
    Case #2: 2