This page is still under construction.

Parts of this page are still being built. What you see may change.

Gallup

Time limit1sMemory limit128 MB

Summary
Given reported percentages rounded to a fixed number of decimals, find the smallest population whose counts round to exactly those values.
Level

Medium6 of 10

Topics
Math, Brute force, Implementation, Binary search
Solved
No attempts yet

Problem

We often see the results of opinion polls reported like this:

Prefer red: 3.5%
Prefer green: 4.5%
Prefer yellow: 22.0%
Prefer blue: 70.0%

This makes you wonder how many people were actually asked. When the numbers are simple — say 20%, 40%, and 40% — you can tell that 5 people were asked (or 10, or 15, or more; we want the minimum number of people).

Every respondent chooses exactly one option, so the individual counts always add up to the total number of people. Each reported percentage is that option's count divided by the total, expressed as a percentage and then rounded to a fixed number of decimal places.

Write a program that reads sets of percentages and, for each set, computes the smallest number of people that could have produced exactly those percentages. This number is always less than 10 00010\,000.

Input

The input consists of several sets of percentages, one set per line.

Each line begins with an integer nn (0≤n≤200 \le n \le 20), the number of percentages in the set. If n>0n > 0, it is followed by the nn percentages. Every percentage in a set is written with the same number of decimal places, from 00 to 55 (if there are no decimals, there is no decimal point). The percentages add up to roughly 100%100\%, allowing for small rounding errors.

Digits are removed by rounding half up: when the first removed digit is 55 or greater, the last kept digit is rounded up. For example, 4.4724.472 becomes 4.474.47, 4.54.5, or 44 depending on how many decimals are kept.

A line consisting of a single 00 (that is, n=0n = 0) marks the end of the input and produces no output.

Output

For each set of data, print one line in the form:

Case i: X

where i is the data set's number (starting from 11) and X is the computed number of people. If there is no valid answer in the range 11 to 99999999, print error in place of the number.

Examples3

  1. Example 1

    Input
    3 20 40 40
    3 33.3 33.3 33.3
    2 33 67
    1 100.0000
    4 3.75 4.25 22.00 70.00
    2 49 51
    2 50 51
    2 49 50
    0
    
    Expected output
    Case 1: 5
    Case 2: 3
    Case 3: 3
    Case 4: 1
    Case 5: 400
    Case 6: 35
    Case 7: 200
    Case 8: error
    
  2. Example 2

    Input
    1 100
    1 50
    1 100.00000
    0
    
    Expected output
    Case 1: 1
    Case 2: error
    Case 3: 1
    
  3. Example 3

    Input
    2 50 50
    4 25 25 25 25
    5 20 20 20 20 20
    0
    
    Expected output
    Case 1: 2
    Case 2: 4
    Case 3: 5