#t278. 火车上的人数

火车上的人数

Number of People on the Train

Problem Background

Special for beginners, ^_^

Problem Description

A train departs from the starting station (called station 11) with aa people boarding at station 11. It then arrives at station 22, where some people board and some alight, but the number boarding equals the number alighting, so when the train leaves station 22 (i.e. before arriving at station 33) the number of people on board remains aa.

From station 33 onward (including station 33), the boarding and alighting follow a pattern: the number boarding at each station equals the sum of the numbers that boarded at the previous two stations, and the number alighting equals the number that boarded at the previous station. This holds up to the station before the terminal (station n−1n - 1).

The given conditions are: there are nn stations in total, aa people board at the starting station, and mm people alight at the last station (everyone gets off). The question is: how many people are on the train when it leaves station xx?

Input Format

One line containing four integers aa, nn, mm, and xx, separated by single spaces. 0≤a≤100 \le a \le 10, 3≤x<n≤153 \le x < n \le 15, 0≤m≤100000 \le m \le 10000.

The data is guaranteed to have a unique solution. People may board and alight at the same station.

Output Format

One integer: the number of people on the train when it leaves station xx.

Sample Input

5 7 32 4

Sample Output

13

Hint

Assume the number of people boarding at station 22 is kk.

train.png

Constraints

1s, 1024KiB for each test case.