Game Prediction

Time limit1sMemory limit128 MB

Summary
Given your n distinct cards in an m-player game where every card from 1 to n*m is dealt, find the most rounds you can guarantee to win against any opponent play.
Level

Hard8 of 10

Topics
Greedy, Sorting, Combinatorics, Math
Solved
No attempts yet

Problem

There are MM people, including you, playing a special card game. At the start, each player is dealt NN cards. Every card shows a distinct positive integer pip between 11 and N×MN \times M; no two cards share the same pip.

In each round, every player plays one of their cards and the cards are compared. The player who plays the card with the largest pip wins that round, and the next round begins. After NN rounds every card has been played, and the player who has won the most rounds wins the game.

Given the cards you were dealt, write a program that determines the maximum number of rounds you can guarantee to win, no matter how your opponents play.

Input

The input consists of several test cases. The first line of each case contains two integers mm (2≤m≤202 \le m \le 20) and nn (1≤n≤501 \le n \le 50), the number of players and the number of cards each player is dealt. The next line contains nn positive integers, the pips of the cards you were dealt. A blank line separates consecutive cases.

The input is terminated by a line containing two zeros.

Output

For each test case, print a line in the form Case x: y, where xx is the test case number (starting from 11) and yy is the maximum number of rounds you can guarantee to win in that game.

Examples1

  1. Example 1

    Input
    2 5
    1 7 2 10 9
    
    6 11
    62 63 54 66 65 61 57 56 50 53 48
    
    0 0
    
    Expected output
    Case 1: 2
    Case 2: 4