Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.

Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.

To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).

Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.


-----Input-----

The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 10^12; 1 ≤ k, a, b, t ≤ 10^6; a < b), where:  d — the distance from home to the post office;  k — the distance, which car is able to drive before breaking;  a — the time, which Vasiliy spends to drive 1 kilometer on his car;  b — the time, which Vasiliy spends to walk 1 kilometer on foot;  t — the time, which Vasiliy spends to repair his car. 


-----Output-----

Print the minimal time after which Vasiliy will be able to reach the post office.


-----Examples-----
Input
5 2 1 4 10

Output
14

Input
5 2 1 4 5

Output
13



-----Note-----

In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.

In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.

Difficulty: interview

Starter code:

Solutions:
d, k, a, b, t = list(map(int, input().split()))

t1 = d * b
t2 = d * a + ((d - 1) // k) * t
t3 = max(0, d - k) * b + min(k, d) * a
dd = d % k
d1 = d - dd
t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b

print(min([t1, t2, t3, t4]))


from random import randint
d, k, a, b, t = list(map(int, input().split()))
cnt = (d + k - 1) // k
def get(m):
	if k * m >= d:
		return d * a + (cnt - 1) * t
	return k * m * a + max(0, m - 1) * t + (d - k * m) * b
def solvefast():
	if k >= d:
		return d * a
	else:
		l = 0
		r = cnt + 2
		while r - l > 2:
			m1 = (l + r) >> 1
			m2 = m1 + 1
			if get(m2) > get(m1): r = m2
			else: l = m1
		mn = 10 ** 20
		for i in range(max(l - 13, 0), min(l + 13, cnt + 3)):
			mn = min(mn, get(i))
		return mn
print(solvefast())


#!/usr/bin/env	python
#-*-coding:utf-8 -*-
import sys,io,os,math,copy,pickle
d,k,a,b,t=list(map(int,input().split()))
if d<=k:
	print(a*d)
	return
s=a*k
d-=k
if t+s>b*k:
	print(s+b*d)
	return
s+=d//k*(t+s)
d%=k
print(s+min(b*d,t+a*d))


d,k,a,b,t = map(int,input().split())
if(d<=k):
    print(a*d)
elif(a*k+t>k*b):
    print(a*k+(d-k)*b)
else:
    s = d%k
    x = d//k
    if(x>=1):
        im = (a*k)*x+t*(x-1)
    else:
        im = 0
    aaa = t+a*s
    bbb = s*b
    im += min(aaa,bbb)
    print(im)

d, k, a, b, t = [int(x) for x in input().split()]
N = d // k
p = d % k

if (N == 0): T = d * a
if (N == 1):
    if (p * b < t + p * a):
        T = p * b + k * a
    else:
        T = t + p * a + k * a
        
if (N > 1):
    if (b * k < t + a * k):
        T = k * a + (d - k) * b
    else:
        if (b * p < t + a * p):
            T = (N * k) * a + (N - 1) * t + p * b
        else:
            T = (N * k) * a + N * t + p * a
            
print(T)


'''
Created on Jul 29, 2016

@author: Md. Rezwanul Haque
'''
import sys
d,k,a,b,t = list(map(int,input().split()))

mn = 10000000000000

if d<=k:
    print(a*d)
    return
    
s = a*k 
d -= k 

if t+s>b*k:
    print(s+b*d)
    return
    
s+=d//k*(t+s)
d%=k

print(s+min(d*b, t+d*a))    
'''
while(d!=0):
    t1 = k*a
    mn = min(mn, t1)
    d-=k'''
    


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

cyc = (d+k-1)//k
alldrive = d*a+t*(cyc-1)
allwalk = d*b
minn = min(alldrive, allwalk)
if ((d+k-1)//k <= 10):
    for x in range(1, (d+k-1)//k):
        time = (x*k*a+(x-1)*t+b*(d-x*k))
        minn = min(minn, time)
else:
    for x in [1, (d+k-1)//k-1]:
        time = (x*k*a+(x-1)*t+b*(d-x*k))
        minn = min(minn, time)
        
print(minn)

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

cyc = (d+k-1)//k
alldrive = d*a+t*(cyc-1)
allwalk = d*b
minn = min(alldrive, allwalk)
if ((d+k-1)//k <= 10):
    for x in range(1, (d+k-1)//k):
        time = (x*k*a+(x-1)*t+b*(d-x*k))
        minn = min(minn, time)
else:
    for x in [1, (d+k-1)//k-1]:
        time = (x*k*a+(x-1)*t+b*(d-x*k))
        minn = min(minn, time)
        
print(minn)




def easy(vals):
    d = int(vals[0])
    k = int(vals[1])
    a = int(vals[2])
    b = int(vals[3])
    t = int(vals[4])
    if d <= k:
        return d*a
    sofar = k*a
    left = d-k
    if b*k < a*k + t:
        return sofar + left*b
    if left > k:
        sofar = sofar + (left//k)*(a*k + t)
        left = left % k
    if left*b <= left*a + t:
        return sofar + left*b
    return sofar + left*a + t


vals = input().split()
print(easy(vals))


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

if d <= k:
    print(d*a)
elif t + k*a > k*b:
    print(k*a + (d-k)*b)
else:
    cnt = d//k
    s = k * a
    dd = d % k
    ans =  (cnt * s) + ((cnt - 1) * t) + min(t + (dd * a), dd * b)
    print(ans)

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

if d <= k:
    print(d*a)
elif t + k*a > k*b:
    print(k*a + (d-k)*b)
else:
    cnt = d//k
    s = k * a
    dd = d % k
    ans =  (cnt * s) + ((cnt - 1) * t) + min(t + (dd * a), dd * b)
    print(ans)

from sys import stdin, stdout
d, k, a, b, t = map(int, stdin.readline().split())
ans = 0
if k * b > k * a + t:
    if k < d:
        ans += (d // k - 1) * t + (d - (d % k)) * a
        d %= k
        if d * a + t < d * b:
            ans += d * a + t
        else:
            ans += d * b
    else:
        ans += a * d
else:
    if k < d:
        ans = (d - k) * b + k * a
    else:
        ans = d * a

stdout.write(str(ans))

d, k, a, b, t = [int(x) for x in input().split()]
if (d <= k):
    print(a*d)
    return
fir = a*k + t - k*b
sec = d*b - k*b + a*k;
maxc = d // k - 1;
for x in range(maxc-10, maxc+10):
    if (k*(x + 1) <= d):
        maxc = x
c = maxc
print(min(c*t+c*a*k+k*a+t+a*(d-c*k-k),min(sec, maxc*fir + sec)))

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


if a >= b:
    print(b * d)
elif k >= d:
    print(a * d)

elif a*k + t <= b * k:
    interval = d // k
    if d % k == 0:
        interval -= 1
    #print(interval, a * d + interval * t, a * (d - (d % k)) + interval * t  + (d % k) * b)
    print(min(a * d + interval * t, a * (d - (d % k)) + ((d // k) - 1) * t  + (d % k) * b))
else:
    print(k * a + (d-k) *b)




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

if d <= k:
    print(a * d)

elif t + k * a > k * b:
    print(k * a + (d - k) * b)
    
else:
    cnt = d // k
    print(k * cnt * a + (cnt - 1) * t + min(t + (d % k) * a, (d % k) * b))     

def main():
    d, k, a, b, t = list(map(int, input().split()))
    res = [d * b]
    if d // k:
        x = d // k * (a * k + t)
        res.append(x + d % k * a)
        res.append(x - t + d % k * b)
        res.append(k * a + (d - k) * b)
    else:
        res.append(d * a)
    print(min(res))


def __starting_point():
    main()

__starting_point()

D, K, A, B, T = list(map(int, input().split()))

def nStops(N):
  if (N == 0):
    return 0
  else:
    return (N - 1)//K

case1 = D * B
case2 = A * D + T * nStops(D)
ans = min(case1, case2)

# Ignorance is the key
for i in range(max(0, D - 1000000), D + 1):
  ans = min(ans, A * i + B * (D - i) + T * nStops(i))

print(ans)


d, k, a, b, t = [int(i) for i in input().split()]

if k >= d :
    print(a * d)
else :
    if a * k + t >= b * k :
        print(a * k + b * (d - k))
    else :
        if d % k == 0 :
            print((d // k - 1) * t + a * d)
        else :
            print(min((d // k) * t + a * d, (d // k - 1) * t + (d - d % k) * a + (d % k) * b))


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

def main():
    if d <= k:
        #print("case 0")
        return d*a
    else:
        ans = a*k
        p = k
        if (b*k <= t + k*a):
            #print("case 1")
            ans += (d - k)*b
        else:
            #print("case 2")
            pp = (d - k)//k
            p += pp*k
            ans += pp*(t + k*a)
            if (d-p)*b < t + (d-p)*a:
                ans += (d-p)*b
            else:
                ans += t + (d-p)*a
        return ans

print(main())


# class Solution:
#     def threeSum(self, nums):
#         """
#         :type nums: List[int]
#         :rtype: List[List[int]]
#         """

d, k, a, b, t = [int(x) for x in input().split()]

if d <= k:
    print(d*a)
else:
    left = 0
    right = (d//k) + 1
    if k*b-k*a-t>0:
        left = (d*(b - a) - ((d//k) + 1)*t) / (k*b - k*a - t)
    elif k*b-k*a-t<0:
        right = (d*(b - a) - ((d//k) + 1)*t) / (k*b - k*a - t)
    N = int(right)
    M = int(left) + 1
    if M >= N:
        print(d*a + (d//k)*t)
    else:
        if not N < right:
            N = N -1
        if N > left and M < right:
            A = (N-1)*t + N*k*a + (d - N*k)*b
            B = (M-1)*t + M*k*a + (d - M*k)*b
            print(min(A, B))
        else:
            if N > left:
                print((N-1)*t + N*k*a + (d - N*k)*b)
            if M < right:
                print((M-1)*t + M*k*a + (d - M*k)*b)


# class Solution:
#     def threeSum(self, nums):
#         """
#         :type nums: List[int]
#         :rtype: List[List[int]]
#         """

d, k, a, b, t = [int(x) for x in input().split()]

if d <= k:
    print(d*a)
else:
    left = 0
    right = (d//k) + 1
    if k*b-k*a-t>0:
        left = (d*(b - a) - ((d//k) + 1)*t) / (k*b - k*a - t)
    elif k*b-k*a-t<0:
        right = (d*(b - a) - ((d//k) + 1)*t) / (k*b - k*a - t)
    N = int(right)
    M = int(left) + 1
    if M >= N:
        print(d*a + (d//k)*t)
    else:
        if not N < right:
            N = N -1
        if N > left and M < right:
            A = (N-1)*t + N*k*a + (d - N*k)*b
            B = (M-1)*t + M*k*a + (d - M*k)*b
            print(min(A, B))
        else:
            if N > left:
                print((N-1)*t + N*k*a + (d - N*k)*b)
            if M < right:
                print((M-1)*t + M*k*a + (d - M*k)*b)


d, k, a, b, t = map(int, input().split())
if k <= d:
    ans = a * k + (d // k - 1) * min((t + a * k), b * k) + min((d % k) * a + t, (d % k) * b)
    print(ans)
else:
    print(d * a)

#!/usr/bin/env	python
#-*-coding:utf-8 -*-
d,k,a,b,t=list(map(int,input().split()))
if d<=k:
	print(a*d)
	return
s=a*k
d-=k
if b*k<=t+s:
	print(s+b*d)
	return
s+=d//k*(t+s)
d%=k
print(s+min(b*d,t+a*d))


'''input
5 2 1 4 5
'''

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

dist, time = min(d, k), min(d*a, k*a)

if dist < d:
    tstep = min(t+k*a, k*b)
    num_steps = (d-dist) // k
    time += num_steps * tstep
    dist += num_steps * k

    remaining = d - dist
    time += min(t + a*remaining, b*remaining)
print(time)



d,k,a,b,t=list(map(int,input().split()))
T=0
if k>=d:
    print(d*a)
    return
if (t+a*k)>=b*k:
    print(k*a+b*(d-k))
    return
else:
    if (d%k)*a+t<b*(d%k):
        T=(d//k)*k*a+(d%k)*a+t*(d//k)
    else:
        T=(d//k)*k*a+b*(d%k)+t*(d//k-1)
    print(T)