{"raw_statement":[{"iden":"statement","content":"Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after _k_ minutes after turning on.\n\nDuring cooking, Julia goes to the kitchen every _d_ minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.\n\nIt is known that the chicken needs _t_ minutes to be cooked on the stove, if it is turned on, and 2_t_ minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off."},{"iden":"input","content":"The single line contains three integers _k_, _d_ and _t_ (1 ≤ _k_, _d_, _t_ ≤ 1018)."},{"iden":"output","content":"Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.\n\nNamely, let's assume that your answer is _x_ and the answer of the jury is _y_. The checker program will consider your answer correct if ."},{"iden":"examples","content":"Input\n\n3 2 6\n\nOutput\n\n6.5\n\nInput\n\n4 2 20\n\nOutput\n\n20.0"},{"iden":"note","content":"In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .\n\nIn the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes."}],"translated_statement":[{"iden":"statement","content":"Julia 将在宿舍的厨房里烹饪一只鸡。为了节约能源，厨房里的炉子在开启后 #cf_span[k] 分钟会自动关闭。\n\n在烹饪过程中，Julia 每隔 #cf_span[d] 分钟会去一次厨房，如果炉子关闭了，就将其重新打开。当炉子关闭时，食物仍保持温热。炉子的开关是瞬时的。\n\n已知，如果炉子开启，鸡需要 #cf_span[t] 分钟才能煮熟；如果炉子关闭，则需要 #cf_span[2t] 分钟。你需要计算，假设鸡的烹饪速度在炉子开启时恒定，在炉子关闭时也恒定，那么 Julia 煮熟这只鸡总共需要多少时间。\n\n输入为一行三个整数 #cf_span[k], #cf_span[d] 和 #cf_span[t]（#cf_span[1 ≤ k, d, t ≤ 1018]）。\n\n请输出一个数字，表示烹饪的总时间（单位：分钟）。相对误差或绝对误差不得超过 #cf_span[10 - 9]。\n\n具体来说，假设你的答案是 #cf_span[x]，标准答案是 #cf_span[y]，当满足 时，判题程序将认为你的答案正确。\n\n在第一个例子中，鸡在炉子开启时烹饪了 3 分钟，之后在关闭状态下烹饪了 。接着，鸡在关闭的炉子上再烹饪了 1 分钟，完成了 。因此，4 分钟后，鸡已经完成了 的烹饪量。在第 5 分钟前，Julia 会重新打开炉子，再经过 #cf_span[2.5] 分钟，鸡就完全煮好了。 \n\n在第二个例子中，当炉子关闭时，Julia 会立即重新打开它，因此炉子始终处于开启状态，鸡将在 20 分钟内煮熟。"},{"iden":"input","content":"输入为一行三个整数 #cf_span[k], #cf_span[d] 和 #cf_span[t]（#cf_span[1 ≤ k, d, t ≤ 1018]）。"},{"iden":"output","content":"请输出一个数字，表示烹饪的总时间（单位：分钟）。相对误差或绝对误差不得超过 #cf_span[10 - 9]。具体来说，假设你的答案是 #cf_span[x]，标准答案是 #cf_span[y]，当满足 时，判题程序将认为你的答案正确。"},{"iden":"examples","content":"输入\n3 2 6\n输出\n6.5\n输入\n4 2 20\n输出\n20.0"},{"iden":"note","content":"在第一个例子中，鸡在炉子开启时烹饪了 3 分钟，之后在关闭状态下烹饪了 。接着，鸡在关闭的炉子上再烹饪了 1 分钟，完成了 。因此，4 分钟后，鸡已经完成了 的烹饪量。在第 5 分钟前，Julia 会重新打开炉子，再经过 #cf_span[2.5] 分钟，鸡就完全煮好了。在第二个例子中，当炉子关闭时，Julia 会立即重新打开它，因此炉子始终处于开启状态，鸡将在 20 分钟内煮熟。"}],"sample_group":[],"show_order":[],"formal_statement":"Let $ k $, $ d $, and $ t $ be given positive integers with $ 1 \\leq k, d, t \\leq 10^{18} $.\n\nDefine the cooking process as follows:\n\n- The stove turns on at time $ 0 $.\n- The stove automatically turns off after $ k $ minutes.\n- Julia checks the stove every $ d $ minutes and turns it on immediately if it is off.\n- When the stove is **on**, the chicken cooks at rate $ \\frac{1}{t} $ per minute (i.e., it needs $ t $ minutes of on-time to fully cook).\n- When the stove is **off**, the chicken cooks at rate $ \\frac{1}{2t} $ per minute (i.e., it needs $ 2t $ minutes of off-time to fully cook).\n\nThe stove cycles in a repeating pattern determined by $ k $ and $ d $. Let $ T $ be the length of one full cycle of the stove’s on-off behavior, starting from when it is turned on.\n\n### Cycle Analysis:\n\nLet $ T = \\min\\{ n \\cdot d \\mid n \\cdot d \\geq k \\} $, i.e., the first multiple of $ d $ that is $ \\geq k $. Then:\n\n- The stove is **on** for the first $ k $ minutes of the cycle.\n- The stove is **off** for the remaining $ T - k $ minutes.\n\nThus, one cycle has duration $ T = \\left\\lceil \\frac{k}{d} \\right\\rceil \\cdot d $.\n\nIn one cycle:\n- On-time: $ k $ minutes → contributes $ \\frac{k}{t} $ to cooking progress.\n- Off-time: $ T - k $ minutes → contributes $ \\frac{T - k}{2t} $ to cooking progress.\n\nTotal progress per cycle:\n$$\np = \\frac{k}{t} + \\frac{T - k}{2t} = \\frac{2k + T - k}{2t} = \\frac{k + T}{2t}\n$$\n\nLet $ n $ be the number of full cycles needed to reach or exceed 1 unit of cooking progress. Let $ r $ be the remaining progress after $ n $ full cycles.\n\nWe seek the smallest total time $ x $ such that the accumulated cooking progress equals 1.\n\nLet:\n- $ p = \\frac{k + T}{2t} $\n- $ n = \\left\\lfloor \\frac{1}{p} \\right\\rfloor $\n- Remaining progress: $ r = 1 - n \\cdot p $\n\nIf $ r = 0 $, then total time is $ x = n \\cdot T $.\n\nOtherwise, we simulate the next partial cycle:\n\n- First, the stove is on for up to $ k $ minutes. Let $ t_{\\text{on}} $ be the time spent in the \"on\" phase of the next cycle needed to finish cooking.\n\nThe progress rate during on-time is $ \\frac{1}{t} $. So the time needed to complete $ r $ progress during on-time is:\n\n$$\nt_{\\text{on}} = \\min\\left(k, r \\cdot t\\right)\n$$\n\nIf $ t_{\\text{on}} < k $, then the chicken finishes during the on-phase, and total time is:\n\n$$\nx = n \\cdot T + t_{\\text{on}}\n$$\n\nOtherwise, if $ t_{\\text{on}} = k $, then we’ve used all the on-time, and still have remaining progress:\n\n$$\nr' = r - \\frac{k}{t}\n$$\n\nThen we need to spend time in the off-phase. The off-phase lasts $ T - k $ minutes, and the cooking rate is $ \\frac{1}{2t} $, so the time needed is:\n\n$$\nt_{\\text{off}} = r' \\cdot 2t\n$$\n\nAnd total time:\n\n$$\nx = n \\cdot T + k + t_{\\text{off}}\n$$\n\nBut note: $ t_{\\text{off}} $ must not exceed $ T - k $, because the stove will be turned back on at time $ T $, so we are bounded by the cycle.\n\nHowever, since $ r' \\cdot 2t = \\left(r - \\frac{k}{t}\\right) \\cdot 2t = 2t r - 2k $, and since $ r < p = \\frac{k + T}{2t} $, we have:\n\n$$\nr' \\cdot 2t < \\frac{k + T}{2t} \\cdot 2t - 2k = k + T - 2k = T - k\n$$\n\nSo $ t_{\\text{off}} < T - k $, meaning the chicken finishes before the next turn-on.\n\nThus, the algorithm is:\n\n---\n\n### Formal Mathematical Formulation:\n\nLet:\n- $ T = \\left\\lceil \\frac{k}{d} \\right\\rceil \\cdot d $\n- $ p = \\frac{k + T}{2t} $\n\nLet $ n = \\left\\lfloor \\frac{1}{p} \\right\\rfloor $, and $ r = 1 - n \\cdot p $\n\nIf $ r = 0 $:\n$$\nx = n \\cdot T\n$$\n\nElse:\n- Let $ t_{\\text{on}} = \\min(k, r \\cdot t) $\n- If $ t_{\\text{on}} < k $:\n  $$\n  x = n \\cdot T + t_{\\text{on}}\n  $$\n- Else:\n  $$\n  r' = r - \\frac{k}{t}, \\quad t_{\\text{off}} = r' \\cdot 2t\n  $$\n  $$\n  x = n \\cdot T + k + t_{\\text{off}}\n  $$\n\n---\n\n### Final Answer:\n\n$$\n\\boxed{\nx = \n\\begin{cases}\nn \\cdot T & \\text{if } r = 0 \\\\\nn \\cdot T + \\min(k, r \\cdot t) & \\text{if } \\min(k, r \\cdot t) < k \\\\\nn \\cdot T + k + \\left(r - \\frac{k}{t}\\right) \\cdot 2t & \\text{otherwise}\n\\end{cases}\n}\n$$\n\nwhere:\n- $ T = \\left\\lceil \\frac{k}{d} \\right\\rceil \\cdot d $\n- $ p = \\frac{k + T}{2t} $\n- $ n = \\left\\lfloor \\frac{1}{p} \\right\\rfloor $\n- $ r = 1 - n \\cdot p $\n\nThis gives the total cooking time with precision suitable for the required error bound.","simple_statement":null,"has_page_source":false}