Olympic Scoring

View as PDF

Submit solution


Points: 3
Time limit: 0.5s
Memory limit: 64M

Author:
Problem type

You really enjoy the Olympics. To help keep track of how each country is performing, you've decided to implement your own scoring system where bronze medals are worth 1 point, silver medals are worth 3 points and gold medals are worth 5 points. To win the Olympics a country needs a score larger than any other country. You've been keeping track of how the other countries are performing. Currently, the top-scoring country that isn't Canada has a score of N points. Canada currently has B bronze medals, S silver medals and G gold medals. You would like to know, what is the minimum number of additional medals of any kind needed for Canada to win?

Constraints

For this problem, you will be required to pass all samples to receive any points.

0 \le N, B, S, G \le 10^{18}

Input Specification

You will read four space-separated integers N, B, S, and G.

Output Specification

Output the minimum number of medals of any kind Canada needs to win according to the scoring system you've designed.

Sample Input

7 2 1 0

Sample Output

1

Explanation

The score of Canada is 2 \times 1 + 1 \times 3 + 0 \times 5 = 5. Canada can win with either one gold for a final score of 10 or one silver medal for a final score of 8. It can be proven that this is the minimum number of additional medals Canada needs to win.


Comments

There are no comments at the moment.