Fib3 Queue

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

P1001 Fib3 Queue

Difficulty: 100\color{grey}100

Problem Statement

You need to create a Fib3 Queue. (A Fib3 Queue is a queue that from the 4th element on, its value equals the sum of the three consecutive elements before.) We will give you the xthx^{\rm th}, the (x1)th(x-1)^{\rm th} and the (x2)th(x-2)^{\rm th} element and you need to work out the 1st element.

Constraints

  • 3x1003 \le x \le 100
  • 1qx2qx1qx1001 \le q_{x-2} \le q_{x-1} \le q_{x} \le 100

Input

xx
qx qx1 qx2q_x\ q_{x-1}\ q_{x-2}

Note that qxq_x, qx1q_{x-1}, qx2q_{x-2} may be not in order.

Output

Output the queue's 1st element.

Samples

Input 1

4
9 5 3

Output 1

We can get the answer by calculating 953=19-5-3=1.

Input 2

3
3 5 9

Output 2

We can get the answer 33 immediately from the input.

Input 3

10
3 5 8

Output 3

-7

Input 4

100
100 100 100

Output 4

-36198145043300

Note that the result may not fits in a 3232bit integer.

AOCode Round #2 (Div. 2) - Rematch - AOCR #1 - With Additionals

未参加
状态
已结束
规则
ACM/ICPC
题目
7
开始于
2021-10-02 13:30
结束于
2021-10-02 16:30
持续时间
3.0 小时
主持人
参赛人数
9