Under construction

Still being built. Things may change

Animal Lottery

Time limit2sMemory limit512 MB

Summary
Given a bet value, a chosen number, and a drawn number, compute the largest prize based on how many trailing digits match.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

In a faraway country, people are hooked on a very simple betting game. The game is played with numbers and is called jogo do bicho (the animal game). The name comes from the fact that the numbers are split into 25 groups by the value of their last two digits (tens and units), and each group is named after an animal. The first group (donkey) is made of the numbers 01, 02, 03 and 04; the second group (eagle) is made of 05, 06, 07 and 08; and so on, up to the last group, which holds 97, 98, 99 and 00.

The rules are simple. When placing a bet, the player picks a bet value VV and a number NN (0≤N≤1 000 0000 \le N \le 1\,000\,000). Every day a number MM (0≤M≤1 000 0000 \le M \le 1\,000\,000) is drawn in the main square of the city. Each player's prize is computed as follows:

  • If MM and NN have the same last four digits (thousands, hundreds, tens and units), the player receives V×3000V \times 3000 (for example, N=99301N = 99301 and M=19301M = 19301).
  • If MM and NN have the same last three digits (hundreds, tens and units), the player receives V×500V \times 500 (for example, N=38944N = 38944 and M=83944M = 83944).
  • If MM and NN have the same last two digits (tens and units), the player receives V×50V \times 50 (for example, N=111N = 111 and M=552211M = 552211).
  • If the last two digits of MM and NN fall in the same group, that is, the same animal, the player receives V×16V \times 16 (for example, N=82197N = 82197 and M=337600M = 337600).
  • If none of the cases above applies, the player receives nothing.

The prize a player receives is, of course, the largest one possible under the rules above. Prizes do not accumulate, however, so only one of the criteria above is applied when computing the prize. If a number NN or MM with fewer than four digits is bet or drawn, assume it is padded with leading zeros to four digits; for example, 17 corresponds to 0017.

Given the bet value, the number chosen by the player, and the drawn number, write a program that computes the prize the player receives.

Input

The input contains several test cases. Each test case is a single line holding a real number VV with two decimal places and two integers NN and MM. They are, in order, the bet value (0.01≤V≤2000.000.01 \le V \le 2000.00), the number chosen for the bet (0≤N≤1 000 0000 \le N \le 1\,000\,000), and the drawn number (0≤M≤1 000 0000 \le M \le 1\,000\,000).

The end of the input is marked by the line 0 0 0, where V=N=M=0V = N = M = 0. Do not process that line.

Output

For each test case, print one line with the prize for that bet, written with exactly two decimal places. The prize can always be written exactly in this form.

Examples2

  1. Example 1

    Input
    32.20 32 213929
    10.50 32 213032
    2000.00 340000 0
    520.00 874675 928567
    10.00 1111 578311
    0 0 0
    
    Expected output
    515.20
    5250.00
    6000000.00
    0.00
    500.00
    
  2. Example 2

    Input
    1000.00 99301 19301
    1000.00 38944 83944
    1000.00 111 552211
    1000.00 82197 337600
    1000.00 12345 67890
    0 0 0
    
    Expected output
    3000000.00
    500000.00
    50000.00
    16000.00
    0.00