{"problem":{"name":"C. Sanatorium","description":{"content":"Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanat","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF732C"},"statements":[{"statement_type":"Markdown","content":"Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!\n\nEvery day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.\n\nVasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when 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 was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.\n\nAccording to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.\n\n## Input\n\nThe 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.\n\n## Output\n\nPrint single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.\n\n[samples]\n\n## Note\n\nIn the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.\n\nIn the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.\n\nIn the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Vasiliy 在疗养院度过了假期，回来后发现他完全忘记了假期的细节！\n\n疗养院的餐厅每天提供早饭、午饭和晚饭（当然，按这个顺序）。Vasiliy 目前唯一拥有的是一张餐厅的卡片，上面记录了他吃早饭、午饭和晚饭的次数（即卡片包含三个整数）。Vasiliy 有时可能会错过某些餐，例如，他可能只吃了早饭和晚饭，而错过了午饭；或者在某些天他根本没去餐厅。\n\nVasiliy 不记得他到达疗养院时是何时（在早饭前、午饭前、晚饭前，还是晚饭后），也不记得他离开时是何时（在早饭前、午饭前、晚饭前，还是晚饭后）。因此，他考虑所有这些可能性。Vasiliy 到达疗养院后，一直待到离开。请注意，Vasiliy 有可能在到达的当天就离开了疗养院。\n\n根据卡片上的记录，请帮助 Vasiliy 确定他在假期期间可能错过的最少餐数。我们不应计算他到达当天在他到达之前的食物，以及他离开当天在他离开之后的食物。\n\n仅一行包含三个整数 $b$、$d$ 和 $s$（$0 ≤ b, d, s ≤ 10^{18}$，$b + d + s ≥ 1$）——表示 Vasiliy 在疗养院度假期间所吃的早饭、午饭和晚饭的次数。\n\n输出一个整数——Vasiliy 在假期期间可能错过的最少餐数。\n\n在第一个样例中，Vasiliy 可能只错过了一顿晚饭，例如，他是在早饭前到达，待了两天（包括到达当天），然后在第三天早饭后离开。\n\n在第二个样例中，Vasiliy 可能是在早饭前到达，吃了早饭，然后立即离开疗养院，没有错过任何餐。\n\n在第三个样例中，Vasiliy 可能在疗养院待了一天，没有错过任何餐。\n\n## Input\n\n仅一行包含三个整数 $b$、$d$ 和 $s$（$0 ≤ b, d, s ≤ 10^{18}$，$b + d + s ≥ 1$）——表示 Vasiliy 在疗养院度假期间所吃的早饭、午饭和晚饭的次数。\n\n## Output\n\n输出一个整数——Vasiliy 在假期期间可能错过的最少餐数。\n\n[samples]\n\n## Note\n\n在第一个样例中，Vasiliy 可能只错过了一顿晚饭，例如，他是在早饭前到达，待了两天（包括到达当天），然后在第三天早饭后离开。在第二个样例中，Vasiliy 可能是在早饭前到达，吃了早饭，然后立即离开疗养院，没有错过任何餐。在第三个样例中，Vasiliy 可能在疗养院待了一天，没有错过任何餐。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ b, d, s \\in \\mathbb{Z}_{\\geq 0} $ denote the number of breakfasts, dinners, and suppers Vasiliy had, respectively, with $ b + d + s \\geq 1 $.\n\n**Constraints**  \n$ 0 \\leq b, d, s \\leq 10^{18} $\n\n**Objective**  \nFind the minimum number of missed meals, given that meals occur daily in fixed order: breakfast → dinner → supper, and Vasiliy arrived and departed at one of the four possible times: before breakfast, before dinner, before supper, or after supper (possibly on the same day).\n\nLet $ x $ be the number of full days (each with all three meals) fully contained in the stay.  \nLet $ a \\in \\{0,1,2,3\\} $ be the number of meals on the arrival day (before departure), and $ e \\in \\{0,1,2,3\\} $ be the number of meals on the departure day (after arrival).  \nThen total meals consumed:  \n$$\nb + d + s = a + x \\cdot 3 + e\n$$  \nThe total possible meals during the stay (from arrival to departure) is $ a + 3x + e $.  \nMissed meals = total possible meals - consumed meals = $ (a + 3x + e) - (b + d + s) $, but since consumed meals are fixed, we instead model constraints on $ b, d, s $.\n\nLet $ m = \\max(b, d, s) $.  \nThen the minimal number of missed meals is:  \n$$\n\\boxed{3m - b - d - s}\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF732C","tags":["binary search","constructive algorithms","greedy","implementation","math"],"sample_group":[["3 2 1","1"],["1 0 0","0"],["1 1 1","0"],["1000000000000000000 0 1000000000000000000","999999999999999999"]],"created_at":"2026-03-03 11:00:39"}}