Fib3 Queue

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

P1001 Fib3 Queue

Difficulty: \(\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 \(x^{\rm th}\), the \((x-1)^{\rm th}\) and the \((x-2)^{\rm th}\) element and you need to work out the 1st element.

Constraints

  • \(3 \le x \le 100\)
  • \(1 \le q_{x-2} \le q_{x-1} \le q_{x} \le 100\)

Input

\(x\)
\(q_x\ q_{x-1}\ q_{x-2}\)

Note that \(q_x\), \(q_{x-1}\), \(q_{x-2}\) may be not in order.

Output

Output the queue's 1st element.

Samples

Input 1

4
9 5 3

Output 1

1

We can get the answer by calculating \(9-5-3=1\).

Input 2

3
3 5 9

Output 2

3

We can get the answer \(3\) 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 \(32\)bit integer.

AOCode Round #1 (Div. 1) - First Contest ||Rated||

未参加
状态
已结束
规则
ACM/ICPC
题目
3
开始于
2021-08-22 14:15
结束于
2021-08-22 15:15
持续时间
1.0 小时
主持人
参赛人数
7