#P11176. Achieving Minimum Final Grade

    ID: 13241 Type: Default 1000ms 256MiB

Achieving Minimum Final Grade

Achieving Minimum Final Grade

In a computer science class, each score is an integer from 2 to 5. The final grade is computed as the arithmetic mean of all scores and then rounded to the nearest integer, with ties rounded up. Formally, if the scores are \(s_1, s_2, \dots, s_n\), the final grade is computed as:

$$\text{grade} = \left\lfloor \frac{s_1+s_2+\cdots+s_n}{n} + 0.5 \right\rfloor.$$

For example:

Scores Arithmetic Mean Final Grade
2, 3, 5 \(\frac{2+3+5}{3} = 3 \frac{1}{3}\) 3
3, 3, 4, 4 \(\frac{3+3+4+4}{4} = 3 \frac{1}{2}\) 4
5, 5, 5, 3, 5 \(\frac{5+5+5+3+5}{5} = 4 \frac{3}{5}\) 5

All students wish to achieve a final grade of at least 4. Unfortunately, one student has received a scores of 2, b scores of 3, and c scores of 4. He plans to obtain additional scores of 5 to ensure his final grade is at least 4. Your task is to determine the minimum number of 5 scores required.

Note: If no scores have been received (i.e. a = b = c = 0), the average is considered to be 5 after adding any number of 5 scores.

inputFormat

The input consists of three non-negative integers a, b, and c separated by spaces, representing the counts of scores 2, 3, and 4 respectively.

outputFormat

Output a single integer which is the minimum number of additional 5 scores required so that the final grade is at least 4.

sample

0 0 0
0