cho.sh
Notes
Loading...

Exercise

Time limit

2s

Memory limit

16 MB

Problem

Youngsik's routine is divided into one-minute intervals. In each minute, he must choose either to exercise or to rest.

If he exercises, his pulse increases by T. That is, if his pulse was X, then after exercising for one minute it becomes X+T. Youngsik does not want his pulse to exceed M, so he may exercise only when X+T is at most M.

If he rests, his pulse decreases by R. If his pulse was X, then after resting for one minute it becomes X-R. However, the pulse must never go below m, so if X-R is less than m, the pulse becomes m instead.

Youngsik's initial pulse is m. He wants to complete N minutes of exercise. Find the minimum elapsed time needed to complete N exercise minutes. The exercise minutes do not need to be consecutive.

Input

The first line contains five integers N, m, M, T, and R.

Output

Print the minimum elapsed time needed to complete N minutes of exercise. If it is impossible to complete N exercise minutes, print -1.

Constraints

  • 1 <= N, T, R <= 200
  • 50 <= m <= M <= 200

Hint

For the first visible test case, one optimal schedule is shown below.

TimeActionPulse after the action
1Exercise95
2Exercise120
3Rest105
4Rest90
5Exercise115
6Rest100
7Rest85
8Exercise110
9Rest95
10Exercise120