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.

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 k, d and t (1 ≤ k, d, t ≤ 10^18).


-----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 $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.


-----Examples-----
Input
3 2 6

Output
6.5

Input
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 $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.

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.

Difficulty: competition

Starter code:

Solutions:
def f(x):
    res = (x // k1) * val
    e = x % k1
    if e <= k:
        res += e
    else:
        res += k + (e - k) / 2
    return res

k, d, t = map(int, input().split())
c = (k - 1) // d + 1
k1 = c * d
rem = -k % d
val = k + rem / 2
l = 0
r = 1e50
for i in range(500):
    m = (l + r) / 2
    if f(m) >= t:
        r = m
    else:
        l = m
print('%.10f' % r)

3

k, d, t = (float(s) for s in input().split())

n = k // d
r = d - k % d
T = n * d
if k % d != 0:
    T += d
dt = k
if k % d != 0:
    dt += r / 2

cnt = t // dt
rem = t % dt
rest = 0
if rem < k:
 rest = rem
else:
 rest = k + (rem - k) * 2

print(cnt * T + rest)


# -*- coding: utf-8 -*-
k, d, t = [int(x) for x in input().split()]
tt = t * 2
t_loop = ((k - 1) // d + 1) * d
amount = k * 2 + (t_loop - k)
n_loop = tt // amount
rem = tt % amount
if rem <= k * 2:
    print(n_loop * t_loop + rem / 2)
else:
    print(n_loop * t_loop + rem - k)

K, D, T = list(map(int, input().split()))
ivl = D * ((K + D - 1) // D)
fp = float(K)/float(ivl)
sp = 1.0-fp
a = 0.0
b = 2.0*T
for ii in range(300):
    t = 0.5*(a+b)
    ivls = t // ivl
    cooked = ivls * ivl * (2.0*fp + sp)
    rt = t - ivls*ivl
    rft = min(fp*ivl, rt)
    rsp = max(0.0, rt - rft)
    cooked += 2.0*rft + rsp
    if cooked < 2.0*T:
        a = t
    else:
        b = t
t = 0.5*(a+b)
print("%.10f" % t)


k, d, t = list(map(int, input().split()))
cnt = (k + d - 1) // d;
per = cnt * d
bat = k * 2 + (per - k);
cntbat = (2 * t) // bat;
ost = (2 * t) % bat
ans = 0.0 + per * cntbat
if k * 2 >= ost:
    ans += ost / 2
else:
    ost -= 2 * k
    ans += k + ost
print(ans)


from sys import stdin, stdout
from random import randrange


k, d, t = map(int, stdin.readline().split())
EPS = 10 ** (-9)
chicken = 100

d = ((k + d - 1) // d) * d

if False:
    stdout.write(str(chicken * t / 100))
else:
    
    l, r = -1, 2 * t + 10
    while r - l > 1:
        m = (l + r) >> 1
        
        cnt = m * k + m * (d - k) / 2
        
        if cnt * 100 / t >= 100:
            r = m
        else:
            l = m
    
    cnt = l * k + l * (d - k) / 2
    chicken = chicken - cnt * 100 / t
    ans = l * k + l * (d - k)
    
    if k * 100 / t >= chicken:
        ans += chicken * t / 100
        chicken = 0
    else:
        ans += k
        chicken -= k * 100 / t
        ans += chicken * 2 * t / 100
        chicken = 0

stdout.write(str(ans))

3

def offcount(x, k, d):
    per = ((k + d - 1) // d) * d
    ans = (x // per) * (per - k)
    if x > (x // per) * per + k:
        ans += x - (x // per) * per - k
    return ans

k, d, t = map(int, input().split())
k *= 2
d *= 2
t *= 2

lt, rt = 0, 8 * 10 ** 18
while lt < rt - 1:
    mid = (lt + rt) // 2

    if 2 * mid - offcount(mid, k, d) >= 2 * t:
        rt = mid
    else:
        lt = mid

print(rt // 2, ".", "0" if rt % 2 == 0 else "5", sep="")


[k, d, t] = input().split()
k = int (k)
d = int (d)
t = int (t)

if k % d == 0:
    d = k
if k > d and k % d != 0:
    d = (k // d + 1) * d


p1 = 1.0 * k / t
p2 = 0.5 * (d - k) / t
p = p1 + p2
#print(p1, p2, p)
s = 1.0 / p
c = int(s)
#print(s, c)
z = 1.0 - p * c
#print(z)
if z < p1:
    ans = c * d + 1.0 * z * t
else:
    ans = c * d + k
    z = z - p1;
    ans += 2.0 * z * t
template = '{:.' + str(10) + 'f}'
print(template.format(ans))

def check(m):
    r = m // time
    t1 = 2 * r * time1 + r * time2
    m %= time
    
    if m < time1:
        t2 = 2 * m
    else:
        t2 = 2 * time1 + (m - time1)
        
    return 2 * t <= t1 + t2


k, d, t = map(int, input().split())

time1 = k
div = (k - 1) // d + 1
time2 = d * div - k
time = time1 + time2

l = 0
r = 10 ** 20
while l < r - 1:
    m = (l + r) // 2
        
    if check(m / 2):
        r = m
    else:
        l = m
            
print(r / 2)

from math import ceil
k, d, t = list(map(int, input().split()))
d = ceil(k / d) * d
r, t = divmod(t, k + (d - k) * .5)
print(r * d + min(k, t) + max(t - k, 0) * 2)


a, b, c = list(map(int, input().split()))
if a % b == 0:
    d = a
else:
    d = (a // b) * b + b  # time
e = (d - a) / 2 + a  # burn
if c % e == 0:
    print((c // e) * d)
else:
    tmp = (c // e) * d
    c -= (c // e) * e
    if c <= a:
        print(tmp + c)
    else:
        c -= a
        print(tmp + a + c * 2)


k, d, t = list(map(int, input().split()))

if (k % d == 0):
    d = (int(k / d)) * d
else:
    d = (int(k / d) + 1) * d
p = k + (d - k) / 2
z = int(t / p) * d
e = int(t / p) * p
if (t - e < k):
    z += (t - e)
else:
    z += k + (t - e - k) * 2
print(z)


k,d,t = list(map(int,input().split()))

if d <= k:
    c = 2*k + (d - k % d) % d
    r = 2*t % c
    periodTime = k + (d - k % d) % d
    nrFullPeriods = 2*t // c
    if r <= 2*k:
        tailTime = r / 2
    else:
        tailTime = r - k
else:
    c = 2*k + (d - k);
    r = 2*t % c
    periodTime = d
    nrFullPeriods = 2*t // c
    if r <= 2*k:
        tailTime = r / 2
    else:
        tailTime = r - k
#print('energyPerPeriod: ' + str(c))
#print('energyTotal: ' + str(2*t))
#print('tailTime: ' + str(tailTime))
#print(nrFullPeriods)
print(nrFullPeriods*periodTime + tailTime)



k,d,t=list(map(int,input().split()))
t*=2
days=0  
    

if(k==d):
    days=t/2
elif(k>d):
    p=t//(2*k+d-(k-1)%d -1)
    #print(p)
    #print(k+d-(k-1)%d -1)
    days+=p*(k+d-(k-1)%d -1)
    #print(days)
    t=t%(2*k+d-(k-1)%d -1)
    if(t<2*k):
        days+=t/2
    else:
        
        days+=k
        t-=2*k
        days+=t
else:
    p=t//(d+k)
    days+=p*(d)
    t=t%(d+k)
    if(t<2*k):
        days+=t/2
    else:
        days+=k
        t-=2*k
        days+=t
print(days)
        
        


from math import ceil
k, d, t = map(int, input().split())

timeAfterK = ceil(k / d) * d

cookingDone = k / t + (timeAfterK - k) / (2*t)

rounds = int(1 / cookingDone)

cookingLeft = 1 - rounds * cookingDone

# print(timeAfterK, cookingDone, rounds, cookingLeft)

if cookingLeft <= k/t:
    ans = rounds * timeAfterK + cookingLeft * t
else:
    ans = rounds * timeAfterK + k
    cookingLeft -= k/t
    ans += cookingLeft * 2 * t

print("{:.10f}".format(ans))

k,d,t=list(map(int,input().split()))
d=((k+d-1)//d)*d
n=2*t//(d+k)
x=2*t%(d+k)
if (x<=2*k):
    ans=x/2+d*n
else:
    ans=x-k+d*n
print(ans)
    


k, d, t = list(map(int, input().split()))

off = (k // d) * d + d - k if k % d != 0 else 0
period = k + off
performance = off / 2 + k

part = int(t / performance)
ans = part * period
t -= part * performance
if t <= k:
    ans += t
else:
    ans += k
    t -= k
    ans += 2 * t
print(ans)


import math


def main():
    k, d, t = [int(x) for x in input().split()]
    time = 0.0
    k = (k, 2 * t)[k > 2*t]

    val = d * (math.ceil(k / d))

    a = t // (k + (val - k) / 2)
    b = t % (k + (val - k) / 2)
    time += val * a
    b -= k
    time += k
    if b < 0:
        time += b
    if b > 0:
        b -= (val - k) / 2
        time += val - k
        if b < 0:
            time += b * 2

    print(time)


def __starting_point():
    main()

__starting_point()

from math import *

def __starting_point():
	k,d,t=map(int,input().split())
	# print(k,d,t)

	per=ceil(k/d)*d
	fire=k if d >=k else per-per%k
	warm=(per-fire)/2

	# print(per,fire,warm)

	ans=t//(fire+warm)*per

	remain=t-t//(fire+warm)*(fire+warm)

	if remain<=fire:
		ans+=remain
	else:
		ans+=fire
		remain-=fire
		ans+=remain*2
	print(ans)
__starting_point()

k,d,t=list(map(int,input().split()))
if k%d==0 :
    print(float(t))
    return
x=((k//d)+1)*d
##print(x)
y=(k + (x-k)/2)
#print(y)
z=(t//y)
#print(z*y)
l=t-(z*y)
m=min(l,k) 
l-=(m)
#print(l)
ans=(z*x+ m+ [0,l*2][l>0])
print(ans)


import math
k,d,t=map(int,input().split())
l=(math.ceil(k/d)*d)-k
m=(2*t)//(2*k+l)
if (t-m*(k+(l/2)))<=k:
    print(m*(k+l)+t-m*(k+(l/2)))
else:
    print(m*(l+k)+k+2*(t-m*(k+(l/2))-k))

[k,d,t ] = input().split(' ')
k = float(k)
d = float(d)
t = float (t)

T = ((k-1)//d+1)*d #一个周期得时间
T1 = k + (T-k)*0.5#一个周期所能完成得

#print(T)
#print(T1)
ans = 0
ans = ans + t//T1*T
a = t-t//T1*T1

#print(a)
if a < k:
    ans = ans + a
else :
    ans = ans + k+(a-k)*2
print(ans)
    


R = lambda: map(int, input().split())
k, d, t = R()
p = (k // d + (1 if k % d else 0)) * d
kp = k / t
wp = (p - k) / (2 * t)
ri = 1 // (kp + wp) * p
rm = 1 % (kp + wp)
rr = rm / kp * k if rm < kp else k + (rm - kp) / wp * (p - k)
print(ri + rr)

R = lambda: map(int, input().split())
k, d, t = R()
p = (k // d + (1 if k % d else 0)) * d
l, r = 0, 2 * 10**18
while (r - l) / max(1, r) > 10**-10:
    m = (l + r) / 2
    ht = m // p * k + min(k, m % p)
    lt = m // p * (p - k) + max(0, m % p - k)
    if ht / t + lt / (t * 2) < 1:
        l = m
    else:
        r = m
print(l)

A=input().split()
k=int(A[0])
d=int(A[1])
t=int(A[2])
if k<=d:
    if t%(k+(d-k)/2)<=k:
        dob=t%(k+(d-k)/2)
    else:
        dob=k+ 2*(t%(k+(d-k)/2)-k)
    tay=d*(t//(k+(d-k)/2))+dob
else:
    if t%(k+(d-((k-1)%d+1))/2)<=k:
        dob=t%(k+(d-((k-1)%d+1))/2)
    else:
      dob=k+((t%(k+(d-((k-1)%d+1))/2)-k)*2)
    tay=t//(k+(d-((k-1)%d+1))/2)*d*((k-1)//d+1)+dob
print(tay)