C. Save Energy!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 kminutes after turning on.

During 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.

It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t 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.

Input

The single line contains three integers kd and t (1 ≤ k, d, t ≤ 1018).

Output

Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.

Namely, 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 Codeforces Round #467 (Div. 2)-C-Save Energy!(公式)_段长度.

Examples
input
Copy
3 2 6
output
6.5
input
Copy
4 2 20
output
20.0
Note

In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for Codeforces Round #467 (Div. 2)-C-Save Energy!(公式)_#define_02. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for Codeforces Round #467 (Div. 2)-C-Save Energy!(公式)_段长度_03. Thus, after four minutes the chicken will be cooked for Codeforces Round #467 (Div. 2)-C-Save Energy!(公式)_整除_04. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready Codeforces Round #467 (Div. 2)-C-Save Energy!(公式)_整除_05.

In 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.

题意:你在宿舍做chicken,用了一个炉子,这个炉子一开始会加热k秒,之后会保持保温状态,在加热时加热的效率为1/t,保温时的效率为1/2t,你每隔d秒会看一下炉子,假如说此时是关着的,你就会把它打开。已知这个chicken要加热到t成熟,问你要花多久时间。

题解:水题一道,直接找到你去看炉子并且炉子是关着的呢个时间点,往后这一段时间一定是循环进行的,所以加减乘除搞一搞就OK了,比赛时读错了题,以为这个炉子是k秒k秒的交替加热和保温,然后找了半天的循环点,最后样例都过不去的卡了半天。。。。。。

#include<stdio.h>
#define ll long long
ll t,k,d,ans;
int main(void)
{
	scanf("%lld%lld%lld",&k,&d,&t);
	ll x=k/d*d+(k%d!=0)*d;t*=2ll;//x为你去厨房正好炉子是关着这一段的时间长度,后边一定是这一段长度状态下的循环,t乘2是为了便于整除
	ll y=t/(2ll*k+(x-k));ans+=y*x;t-=y*(2ll*k+(x-k));//y为在总时间t内有多少个加热和保温的固定长度的循环
	//因为你将总时间乘2了,所以在加热时的效率就是2,保温时的效率就是1,剩下的时间就是不能构成一个循环的时间
	//分情况讨论就好了
	if(t>=2ll*k)
	{
		ans+=k+(t-2ll*k);
		printf("%lld.0\n",ans);
	}
	else
	{
		ans+=t/2;
		if(t%2)
			printf("%lld.5\n",ans);
		else
			printf("%lld.0\n",ans);
	}
	return 0;
}