One...Two...Five!
Time limit1sMemory limit256 MB
Try every +,-,*,/ insertion evaluated left to right, skipping division by zero, and report the most frequent result containing the digit 3.
- Level
Medium4 of 10
- Topics
- Brute force, Simulation
- Solved
- No attempts yet
Problem
Saying an integer out loud rarely causes trouble in everyday conversation. The king, though, has a blind spot: he cannot picture any number whose base 10 representation contains the digit 3. He does sense that something sits between 2 and 4, so he works around the gap. Whenever he wants to state a number containing the digit 3, he says a series of numbers, and his knights combine them in the order given with addition, subtraction, multiplication and division to produce the value he meant.
Operators apply from left to right with no precedence. For example is , and 143 contains a 3. If the king says 1 2 5, a knight answers 3, because .
Optimistic Camelot has no negative numbers. Every subtraction takes the absolute value, so a result is never below 0. All division is integer division, so . When the divisor is 0, the division is not attempted.
The court has a problem: some series produce more than one number containing the digit 3. Given numbers there are ways to assign the operators, and every assignment that divides by 0 is thrown away. Collect the values the remaining assignments produce, then print the value containing the digit 3 that appears most often. If several values appear that many times, answer with the largest of them.
Input
The input consists of an unspecified number of lines. Each line holds at least 1 and at most 9 integers separated by spaces. Every number is at least 0 and less than 100. A line holding a single # character ends the input.
Output
For each input line, print on its own line the number the king most probably meant. If there is no such number, print No result.