Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the Regionals

Time limit1sMemory limit128 MB

Summary
Decide whether n given names can be split into teams of exactly k so each team's name lengths all lie within 2 of that team's average.
Level

Medium7 of 10

Topics
Greedy, Sorting, Math, Brute force
Solved
No attempts yet

Problem

The Association for Computing Machinery (ACM) is considering new rules for its regional programming contests, in part to fix some software problems. For instance, the program that prints the badges for each team was designed so that the same font size is used for all of a team's badges. This means that if one team member has a very long name, a very small font is used for the whole team, which does not look nice next to someone with an extremely short name like AL.

The ACM's first idea was to cap the length of contestants' names, but someone pointed out that this would discriminate against regions where longer names are common (for example, children in the home town of a famous actor are often named after that actor — imagine how many children in Oakland, California have been named after the actor Mahershalalhashbaz Ali since he became a star of the television series The 4400).

As a compromise, the ACM changed the rule to require that no team member's name may have a length more than two away from the average of the lengths of all the team's members' names. Under this rule a team of MAHERSHALALHASHBAZ, AL, and BILL would be disqualified: the average name length is 8, and AL and BILL are not within 2 of 8. However, MAHERSHALALHASHBAZ, NEBUCHADNEZZAR, and BILLYBOBBENJAMIN would be fine: the average length is 16, and every name's length is within 2 of that.

Given the names of nn students, determine whether they can be split into teams of exactly kk members each so that every team satisfies the new rule.

Input

The input consists of multiple test cases. Each test case begins with a line containing two positive integers nn and kk, where n≤1000n \le 1000, k≤8k \le 8, and nn is divisible by kk. The next nn lines each contain a single name made up only of uppercase letters, with no embedded, leading, or trailing spaces; these are the nn students to be organized into teams of kk each. No name is longer than 80 characters. The last test case is followed by a line containing two zeros.

Output

For each test case, print a line of the form Case X: yes or Case X: no, where XX is the test case number starting from 1. Print yes if the students can be split into teams of exactly kk members so that on every team no member's name length differs from that team's average name length by more than 2, and no otherwise. Print a blank line between consecutive test cases.

Examples1

  1. Example 1

    Input
    3 3
    MAHERSHALALHASHBAZ
    AL
    BILL
    6 3
    MAHERSHALALHASHBAZ
    AL
    NEBUCHADNEZZAR
    BILL
    BILLYBOBBENJAMIN
    JILL
    0 0
    
    Expected output
    Case 1: no
    
    Case 2: yes