#t55. 小杨做题

小杨做题

Xiaoyang's Problem Solving

Problem Description

To prepare for an exam, Xiaoyang does problems every day. On day 1, he does aa problems; on day 2, he does bb problems; starting from day 3, the number of problems he does each day is the sum of the previous two days.

In addition, Xiaoyang has a rule: once he does greater than or equal to mm problems on some day, he will never do any problems again for all the following days.

By day NN, how many problems has Xiaoyang done in total?

Input Format

Four lines in total. The first line is an integer aa, the second line is an integer bb, the third line is an integer mm, and the fourth line is an integer NN.

Output Format

One line with one integer, the total number of problems Xiaoyang did in NN days.

Sample Input

Sample Input 1

1
2
10
5

Sample Input 2

1
1
5
8

Sample Output

Sample Output 1

19

Sample Output 2

12

Sample Explanation

Xiaoyang does 1 problem on day 1, 2 on day 2, 3 (1+21+2) on day 3, 5 (2+32+3) on day 4, and 8 (3+53+5) on day 5. In five days he did 1+2+3+5+8=191+2+3+5+8=19 problems.

Constraints

Guaranteed 0≤a,b≤100 \le a, b \le 10, a,b<m<106a, b < m < 10^6, 3≤N≤3643 \le N \le 364.