Codeforces Round #377 (Div. 2) C. Sanatorium (greedy)

Source: Internet
Author: User
Tags time limit

C. Sanatorium

Time limit per test:1 second

Memory limit per test:256 megabytes

Input:standard input

Output:standard output

Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!

Every day there is a breakfast, a dinner and a supper in a dining the "the sanatorium (of course, in this order). The only thing that Vasiliy have now are a card from the dining hostel contaning notes How many times he had a breakfast, a di Nner and a supper (thus, the card contains three integers). Vasiliy could sometimes has missed some meal, for example, he could has had a breakfast and a supper, but a dinner, or, Probably, at some days he haven ' t been at the dining.

Vasiliy doesn ' t remember what is the time of the day when he arrived to sanatorium (before breakfast, before dinner, BEFO Re supper or after supper), and the time that he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he is there all the time until he left. Please note that it's possible that Vasiliy left the sanatorium on the same day he arrived.

According to the notes in the card, help vasiliy determine the minimum number of meals in the dining, the he could ha ve missed. We shouldn ' t count as missed meals on the arrival day before Vasiliy ' s arrival and meals on the departure day after he lef T.

Input

The only line contains three integers B, D and S (0≤b, D, s≤1018, B + D + s≥1)-the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.

Output

Print single integer-the minimum possible number of meals which Vasiliy could has missed during his vacation.

Examples

Input
3 2 1

Output
1

Input
1 0 0

Output
0

Input
1 1 1

Output
0

Input
1000000000000000000 0 1000000000000000000

Output
999999999999999999

Note

In the first sample, Vasiliy could has missed one supper, for example, in case he has arrived before breakfast, has bee N in the sanatorium for both days (including the day of arrival) and then has left after breakfast on the third day.

In the second sample, Vasiliy could has arrived before breakfast, has had it, and immediately has left the sanatorium, Not missing any meal.

In the third sample, Vasiliy could has been in the sanatorium for one day and not missing any meal.
Test instructions
Suppose you are in a certain place, for a few days unknown, when to come and when to walk unknown. Give you the number of meals you eat, and ask you for at least a few meals.
The question: If we can know the full number of days to stay. It's good to be done. And the total number of days to be equal to the maximum value-1, both eat this meal before, eat this meal after the walk. The answer is the difference between the days and each meal.
Code:

#include <bits/stdc++.h>
using namespace std;
Long long a[5];
int main ()
{
    long long mx=0;
    for (int i=1;i<=3;i++)
    {
        cin>>a[i];
        Mx=max (Mx,a[i]);
    }
    mx--;
    Long long ans=0;
    for (int i=1;i<=3;i++)
    {
        if (Mx>a[i])
            ans+=mx-a[i];
    }
    cout<<ans<<endl;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.