Under construction

Still being built. Things may change

Card Game (Large)

Time limit5sMemory limit512 MB

Summary
Repeatedly delete neighboring triples in arithmetic progression with difference K to leave as few cards as possible.
Level

Medium7 of 10

Topics
Dynamic programming, Intervals
Solved
No attempts yet

Problem

Bob likes card games. At his birthday party 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 fixes an integer KK. Each discard takes three cards that are neighbours at that moment, and if the numbers on those three cards are aa, bb and cc from left to right, they must satisfy

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

A discarded card leaves no gap, so the cards that were on either side of it become neighbours.

When several triples can be discarded, Bob picks the ones that leave the fewest cards at the end. Find that smallest number of remaining cards.

Input

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

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

Limits

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

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 after discarding.

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