F - Average Ranking Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

問題文

すぬけくんは 4 人用対戦ゲームを N 試合行い、 1 位を A 回、 2 位を B 回、 3 位を C 回、 4 位を D 回とりました。

すぬけくんは平均の順位の値が X 以下だと喜びます。 すぬけくんが喜ぶためには、最低でもあと何試合行う必要があるでしょうか?

制約

  • 1\leq N \leq 10^{12}
  • 0\leq A,B,C,D \leq 10^{12}
  • A+B+C+D=N
  • 1< X\leq 4
  • N,A,B,C,D は整数で与えられる。
  • X は小数点以下第3位まで与えられる。

入力

入力は以下の形式で標準入力から与えられる。

N
A B C D
X

出力

答えを出力せよ。


入力例 1

4
1 1 1 1
1.600

出力例 1

6

はじめ、平均順位の値は 2.5 です。あと 6 回試合を行い、全てで 1 位を取ることで平均順位を 1.6 とすることができ、これは X=1.600 以下です。


入力例 2

10
0 0 0 10
4.000

出力例 2

0

すでに平均順位の値は X=4.000 以下なので、試合をする必要はありません。

Problem Statement

Snuke played N matches of a 4-player game, and ranked 1-st A times, 2-nd B times, 3-rd C times, and 4-th D times.

Snuke is happy if the value of his average rank is at most X. At least how many additional matches must be played to make him happy?

Constraints

  • 1\leq N \leq 10^{12}
  • 0\leq A,B,C,D \leq 10^{12}
  • A+B+C+D=N
  • 1< X\leq 4
  • N, A, B, C, and D are given as integers.
  • X is given with three decimal places.

Input

The input is given from Standard Input in the following format:

N
A B C D
X

Output

Print the answer.


Sample Input 1

4
1 1 1 1
1.600

Sample Output 1

6

Now, the value of his average rank is 2.5. If six more matches are played and he ranks 1-st in all of them, his average rank will be 1.6, which is not greater than X=1.600.


Sample Input 2

10
0 0 0 10
4.000

Sample Output 2

0

The value of his average rank is already not greater than X=4.000, so no more matches need to be played.