/ AOCode / 题库 /

Fib3 Queue

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.

信息

ID
1001
难度
100
分类
(无)
标签
(无)
递交数
35
已通过
3
通过率
9%
上传者