Under construction

Still being built. Things may change

Cold Shower

Interview

Time limit1sMemory limit1024 MB

Summary
Simulate the shower temperature for n seconds under the given update rule and sum the distances between each temperature and the comfortable temperature k.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Dohun lives alone and plans to take a shower over nn seconds.

Dohun's mysterious shower has a natural temperature change of d1,d2,…,dnd_1, d_2, \ldots, d_n each time 1,2,…,n1, 2, \ldots, n seconds pass. Dohun cannot predict this pattern, so he adjusts the shower based on the previous temperature.

Dohun's comfortable temperature kk is given.

Let TiT_i be the shower temperature after ii seconds. The temperature T0T_0 at time 00 is given.

Dohun adjusts the shower temperature as follows.

  • If Ti>kT_i > k at time ii, the water is too hot, so he sets Ti+1=Ti+di+1−∣Ti−k∣T_{i+1} = T_i + d_{i+1} - |T_i - k|.
  • If Ti<kT_i < k at time ii, the water is too cold, so he sets Ti+1=Ti+di+1+∣Ti−k∣T_{i+1} = T_i + d_{i+1} + |T_i - k|.
  • If Ti=kT_i = k at time ii, the water temperature is right, so he does not adjust it. That is, Ti+1=Ti+di+1T_{i+1} = T_i + d_{i+1}.

The discomfort index is the sum of the differences between the shower temperature and the comfortable temperature at every second, starting from second 1. In other words, the discomfort index is ∣T1−k∣+∣T2−k∣+⋯+∣Tn−k∣|T_1 - k| + |T_2 - k| + \cdots + |T_n - k|.

Find the discomfort index that Dohun feels.

Input

The first line contains three integers nn, kk, and T0T_0, separated by spaces.

The second line contains nn integers d1,d2,…,dnd_1, d_2, \ldots, d_n, separated by spaces.

Output

Print Dohun's discomfort index.

Constraints

1≤n≤1 0001 \le n \le 1\,000

0≤k,T0,di≤1000 \le k, T_0, d_i \le 100

Examples1

  1. Example 1

    Input
    5 32 10
    30 10 5 6 2
    
    Expected output
    53