alexjercan/bugnet huggingface dataset:
Score : 1600 points

Problem Statement

There are N squares in a row, numbered 1 through N from left to right.
Snuke and Rng are playing a board game using these squares, described below:

First, Snuke writes an integer into each square.

Each of the two players possesses one piece. Snuke places his piece onto square 1, and Rng places his onto square 2.

The player whose piece is to the left of the opponent's, moves his piece. The destination must be a square to the right of the square where the piece is currently placed, and must not be a square where the opponent's piece is placed.

Repeat step 3. When the pieces cannot be moved any more, the game ends.

The score of each player is calculated as the sum of the integers written in the squares where the player has placed his piece before the end of the game.

Snuke has already written an integer A_i into square i (1≦i≦N-1), but not into square N yet.
He has decided to calculate for each of M integers X_1,X_2,...,X_M, if he writes it into square N and the game is played, what the value "(Snuke's score) - (Rng's score)" will be.
Here, it is assumed that each player moves his piece to maximize the value "(the player's score) - (the opponent's score)".

Constraints

3≦N≦200,000

0≦A_i≦10^6

The sum of all A_i is at most 10^6.

1≦M≦200,000

0≦X_i≦10^9

Partial Scores

700 points will be awarded for passing the test set satisfying M=1.

Additional 900 points will be awarded for passing the test set without additional constraints.

Input

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

N
A_1 A_2 ... A_{N-1}
M
X_1
X_2
:
X_M

Output

For each of the M integers X_1, ..., X_M, print the value "(Snuke's score) - (Rng's score)" if it is written into square N, one per line.

Sample Input 1

5
2 7 1 8
1
2

Sample Output 1

0

The game proceeds as follows, where S represents Snuke's piece, and R represents Rng's.

Both player scores 10, thus "(Snuke's score) - (Rng's score)" is 0.

Sample Input 2

9
2 0 1 6 1 1 2 6
5
2016
1
1
2
6

Sample Output 2

2001
6
6
7
7
Score : 1900 points

Problem Statement

Snuke has a grid with H rows and W columns. The square at the i-th row and j-th column contains a character S_{i,j}.

He can perform the following two kinds of operation on the grid:

Row-reverse: Reverse the order of the squares in a selected row.

Column-reverse: Reverse the order of the squares in a selected column.

For example, reversing the 2-nd row followed by reversing the 4-th column will result as follows:

By performing these operations any number of times in any order, how many placements of characters on the grid can be obtained?

Constraints

1≦H,W≦200

S_{i,j} is a lowercase English letter (a-z).

Input

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

H W
S_{1,1}S_{1,2}...S_{1,W}
S_{2,1}S_{2,2}...S_{2,W}
:
S_{H,1}S_{H,2}...S_{H,W}

Output

Print the number of placements of characters on the grid that can be obtained, modulo 1000000007 (=10^9+7).

Sample Input 1

2 2
cf
cf

Sample Output 1

6

The following 6 placements of characters can be obtained:

Sample Input 2

1 12
codefestival

Sample Output 2

2
Score : 2100 points

Problem Statement

Snuke has a board with an N \times N grid, and N \times N tiles.

Each side of a square that is part of the perimeter of the grid is attached with a socket.
That is, each side of the grid is attached with N sockets, for the total of 4 \times N sockets.
These sockets are labeled as follows:

The sockets on the top side of the grid: U1, U2, ..., UN from left to right

The sockets on the bottom side of the grid: D1, D2, ..., DN from left to right

The sockets on the left side of the grid: L1, L2, ..., LN from top to bottom

The sockets on the right side of the grid: R1, R2, ..., RN from top to bottom

Figure: The labels of the sockets

Snuke can insert a tile from each socket into the square on which the socket is attached.
When the square is already occupied by a tile, the occupying tile will be pushed into the next square, and when the next square is also occupied by another tile, that another occupying tile will be pushed as well, and so forth.
Snuke cannot insert a tile if it would result in a tile pushed out of the grid.
The behavior of tiles when a tile is inserted is demonstrated in detail at Sample Input/Output 1.

Snuke is trying to insert the N \times N tiles one by one from the sockets, to reach the state where every square contains a tile.
Here, he must insert exactly U_i tiles from socket Ui, D_i tiles from socket Di, L_i tiles from socket Li and R_i tiles from socket Ri.
Determine whether it is possible to insert the tiles under the restriction. If it is possible, in what order the tiles should be inserted from the sockets?

Constraints

1≦N≦300

U_i,D_i,L_i and R_i are non-negative integers.

The sum of all values U_i,D_i,L_i and R_i is equal to N \times N.

Partial Scores

2000 points will be awarded for passing the test set satisfying N≦40.

Additional 100 points will be awarded for passing the test set without additional constraints.

Input

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

N
U_1 U_2 ... U_N
D_1 D_2 ... D_N
L_1 L_2 ... L_N
R_1 R_2 ... R_N

Output

If it is possible to insert the tiles so that every square will contain a tile, print the labels of the sockets in the order the tiles should be inserted from them, one per line. If it is impossible, print NO instead. If there exists more than one solution, print any of those.

Sample Input 1

3
0 0 1
1 1 0
3 0 1
0 1 1

Sample Output 1

L1
L1
L1
L3
D1
R2
U3
R3
D2

Snuke can insert the tiles as shown in the figure below. An arrow indicates where a tile is inserted from, a circle represents a tile, and a number written in a circle indicates how many tiles are inserted before and including the tile.

Sample Input 2

2
2 0
2 0
0 0
0 0

Sample Output 2

NO
Max Score: $250$ Points

Problem Statement

Snuke has a very long calendar. It has a grid with $n$ rows and $7$ columns. One day, he noticed that calendar has a following regularity.

The cell at the $i$-th row and $j$-th column contains the integer $7i+j-7$.

A good sub-grid is a $3 \times 3$ sub-grid and the sum of integers in this sub-grid mod $11$ is $k$.

How many good sub-grid are there? Write a program and help him.

Input

The input is given from standard input in the following format.

$n \quad k$

Output

Print the number of good sub-grid. If there are no solution exists, print 0.

Constraints

$1 \le n \le 10^9$

$0 \le k \le 10$

Subtasks

Subtask 1 [ $150$ points ]

The testcase in the subtask satisfies $1 \le n \le 100$.

Subtask 2 [ $100$ points ]

There are no additional constraints.

Sample Input 1

7 7

Sample Output 1

2

In this case, the calendar likes this matrix.

Sun.
Mon.
Tue.
Wed.
Thu.
Fri.
Sat.

Week 1
1
2
3
4
5
6
7

Week 2
8
9
10
11
12
13
14

Week 3
15
16
17
18
19
20
21

Week 4
22
23
24
25
26
27
28

Week 5
29
30
31
32
33
34
35

Week 6
36
37
38
39
40
41
42

Week 7
43
44
45
46
47
48
49

The cell at $i$-th row and $j$-th column is denoted $(i, j)$.

If upper-left is $(1, 5)$, the sum of integers is $5+6+7+12+13+14+19+20+21=117$.

If upper-left is $(3, 2)$, the sum of integers is $16+17+18+23+24+25+30+31+32=216$.

Therefore, there are 2 good sub-grids.

Sample Input 2

6 0

Sample Output 2

2

If upper-left is $(1, 3)$ or $(4, 4)$, it is a good sub-grid.

Sample Input 3

18 10
Max Score: $400$ Points

Problem Statement

Sample testcase 3 has a mistake, so we erased this case and rejudged all solutions of this problem. (21:01)

Snuke got a sequence $a$ of length $n$ from AtCoder company. All elements in $a$ are distinct.

He made a sequence $b$, but actually, he is not remembered it.

However, he is remembered a few things about sequence $b$.

All elements in $b$ are distinct.

All elements in $b$ is in $a$.

$b_1 \oplus b_2 \oplus \cdots \oplus b_r = k$. ($r$ is length of sequence $b$) [$\oplus$ means XOR]

For example, if $a = { 1, 2, 3 }$ and $k = 1$, he can make $b = { 1 }, { 2, 3 }, { 3, 2 }$.

He wants to restore sequence $b$, but he says that there are too many ways and he can't restore it.
Please calculate the ways to make $b$ and help him.

Since the answer can be large, print the answer modulo $1,000,000,007$.

Input

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

$n \ k$
$a_1 \ a_2 \ \cdots \ a_n$

Output

Print the number of ways to make sequence $b$.

Print the answer modulo $1,000,000,007$.

Constraints

$1 \le n \le 100$

$1 \le a_i, k \le 255$

$i \neq j \Rightarrow a_i \neq a_j$

Subtasks

Subtask 1 [ $50$ points ]

$1 \le n \le 4$

Subtask 2 [ $170$ points ]

$1 \le n \le 20$

Subtask 3 [ $180$ points ]

There are no additional constraints.

Sample Input 1

3 1
1 2 3

Sample Output 1

3

You can make 3 patterns: $b = \{ 1 \}, \{ 2, 3 \}, \{ 3, 2 \}$

Sample Input 2

3 10
8 7 5

Sample Output 2

6

You can make 6 patterns: $b = \{ 5, 7, 8 \}, \{ 5, 8, 7 \}, \{ 7, 5, 8 \}, \{ 7, 8, 5 \}, \{ 8, 5, 7 \}, \{ 8, 7, 5 \}$.

Sample Input 4

25 127
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125

Sample Output 4

235924722

Please output answer mod $1,000,000,007$.

writer: E869120
Max Score: $600$ Points

Problem Statement

Sigma and his brother Sugim are in the $H \times W$ grid. They wants to buy some souvenirs.

Their start position is upper-left cell, and the goal position is lower-right cell.

Some cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs.

In one move, they can go left, right, down, and up cell.

But they have little time, so they can move only $H+W-2$ times.

They wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs.

Write a program and calculate the maximum souvenirs they can get, and help them.

Input

The input is given from standard input in the following format.

$H \ W$
$a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$
$a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$
$\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$
$a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$

Output

Print the maximum number of souvenirs they can get.

Constraints

$1 \le H, W \le 200$

$0 \le a_{i, j} \le 10^5$

Subtasks

Subtask 1 [ 50 points ]

The testcase in the subtask satisfies $1 \le H \le 2$.

Subtask 2 [ 80 points ]

The testcase in the subtask satisfies $1 \le H \le 3$.

Subtask 3 [ 120 points ]

The testcase in the subtask satisfies $1 \le H, W \le 7$.

Subtask 4 [ 150 points ]

The testcase in the subtask satisfies $1 \le H, W \le 30$.

Subtask 5 [ 200 points ]

There are no additional constraints.

Sample Input 1

3 3
1 0 5
2 2 3
4 2 4

Sample Output 1

21

The cell at $i$-th row and $j$-th column is denoted $(i, j)$.

In this case, one of the optimal solution is this:

Sigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.

Sugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.

Then, they can get $21$ souvernirs.

Sample Input 2

6 6
1 2 3 4 5 6
8 6 9 1 2 0
3 1 4 1 5 9
2 6 5 3 5 8
1 4 1 4 2 1
2 7 1 8 2 8

Sample Output 2

97

Writer : square1001
Max Score: $850$ Points

Problem statement

There is a circle which radius is 1.

There are $N$ vertices on the circle's circumference.

The vertices divides into $N$ equal parts over the circumference.

You can choose $3$ distinct vertices, and you can make a triangle.

There are $\frac{N(N - 1)(N - 2)}{6}$ ways choosing vertices.
The question is: Calculate the area of $K$-th smallest triangle in $\frac{N(N-1)(N-2)}{6}$ triangles.

If the area is same, you can order in any order.

If $N = 4, K = 3$, the result is following:

If you select vertices $1$, $2$, and $3$, the area of triangle $= 1$.

If you select vertices $1$, $2$, and $4$, the area of triangle $= 1$.

If you select vertices $1$, $3$, and $4$, the area of triangle $= 1$.

If you select vertices $2$, $3$, and $4$, the area of triangle $= 1$.

As a result, the 3rd smallest triangle's area $= 1$.

Input

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

$N \ K$

Output

Please output the $K$-th triangle area.

Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than $10^{−9}$.

Constraints

$3 \le N \le 200,000$

$1 \le K \le \frac{N(N-1)(N-2)}{6}$

Subtasks

Subtask 1 [ $160$ points ]

$N \le 100$

Subtask 2 [ $240$ points ]

$N \le 1000$

Subtask 3 [ $450$ points ]

$N \le 200,000$

Sample Input 1

4 3

Sample Output 1

1.0000000000000

This example is already explained in the problem statement.

Sample Input 2

6 9

Sample Output 2

0.86602540378

There are $6$ ways to choose a triangle which area is $\frac{\sqrt{3}}{4}$.

There are $10$ ways to choose a triangle which area is $\frac{\sqrt{3}}{2}$.

There are $2$ ways to choose a triangle which area is $\frac{3 \sqrt{3}}{4}$.

Therefore, the 9th smallest triangle's area is $\frac{\sqrt{3}}{2}$.

Sample Input 3

12 220

Sample Output 3

1.29903810568

Writer: E869120
Max Score: $1200$ Points

Problem statement

There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$.

A sushi chef carried out $Q$ operations for customers.

The $i$-th operation is follows:

The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers.

He puts a dish of sushi on the selected seats.

A customer who have selected for professional eats this sushi.

Repeat 1-3, $b_i$ times.

Please calculate the number of dishes of sushi that have been eaten by each customer.

Input

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

$N \ Q$
$a_1 \ b_1$
$a_2 \ b_2$
$ ： \ ： $
$a_Q \ b_Q$

Output

You have to print $N$ lines.

The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$.

Constraints

$3 \le N, Q \le 100,000$

$1 \le a_i \le N$

$1 \le b_i \le 10^{12}$

Any final results do not exceed $2 \times 10^{13}$.

Subtasks

Subtask 1 [ $60$ points ]

$N, Q \le 100$

$b_i = 1$

Subtask 2 [ $400$ points ]

$N, Q \le 100$

$b_i \le 10^{12}$

Subtask 3 [ $240$ points ]

$N, Q \le 100,000$

$b_i = 1$

Subtask 4 [ $500$ points ]

There are no additional constraints.

Sample Input 1

9 3
5 11
8 4
4 7

Sample Output 1

4
4
4
4
2
2
1
1
0

The change of the number of dishes of sushi have eaten is following:

Customer 1
Customer 2
Customer 3
Customer 4
Customer 5
Customer 6
Customer 7
Customer 8
Customer 9

1st Operation
3	2	2	2	2	0	0	0	0

2nd Operation
3	2	2	2	2	2	1	1	0

3rd Operation
4	4	4	4	2	2	1	1	0

Sample Input 2

6 6
3 5
6 11
1 6
4 7
5 2
2 5

Sample Output 2

10
10
5
5
4
2

Sample Input 3

5 6
1 1
2 1
3 1
1 1
5 1
3 1

Sample Output 3

2
2
1
1
0

Sample Input 4

10 10
10 10
9 20
8 30
7 40
6 50
5 60
4 70
3 80
2 90
1 100

Sample Output 4

223
123
77
50
33
21
12
7
3
1

Writer: E869120
Max Score: $1400$ Points

Problem Statement

E869120 defined a sequence $a$ like this:

$a_1=a_2=1$, $a_{k+2}=a_{k+1}+a_k \ (k \ge 1)$

He also defined sequences $d_1, d_2, d_3, \dots , d_n$, as the following recurrence relation :

$d_{1, j} = a_j$

$d_{i, j} = \sum_{k = 1}^j d_{i - 1, k} \ (i \ge 2)$

You are given integers $n$ and $m$. Please calculate the value of $d_{n, m}$.

Since the answer can be large number, print the answer modulo $998,244,353$.

Can you solve this problem???

Input

The input is given from standard input in the following format.

$n \quad m$

Output

Print $d_{n, m}$ modulo $998,244,353$.

Constraints

$1 \le n \le 200,000$

$1 \le m \le 10^{18}$

Subtasks

Subtask 1 [ $100$ points ]

The testcase in this subtask satisfies $1 \le n, m \le 3,000$.

Subtask 2 [ $170$ points ]

The testcase in this subtask satisfies $1 \le m \le 200,000$.

Subtask 3 [ $230$ points ]

The testcase in this subtask satisfies $1 \le n \le 3$.

Subtask 4 [ $420$ points ]

The testcase in this subtask satisfies $1 \le n \le 1000$.

Subtask 5 [ $480$ points ]

There are no additional constraints.

Sample Input 1

4 7

Sample Output 1

176

The sequence is following:

$d_{i, 1}$
$d_{i, 2}$
$d_{i, 3}$
$d_{i, 4}$
$d_{i, 5}$
$d_{i, 6}$
$d_{i, 7}$

$d_1$
1
1
2
3
5
8
13

$d_2$
1
2
4
7
12
20
33

$d_3$
1
3
7
14
26
46
79

$d_4$
1
4
11
25
51
97
176

As a result, the answer is $d_{4, 7} = 176$.

Sample Input 2

12 20

Sample Output 2

174174144

Interesting number. It only contains $1$, $4$ and $7$.

Sample Input 3

16 30

Sample Output 3

102292850

You can calculate that $d_{16, 30} = 1,193,004,294,685$.

Please don't forget printing the answer mod $998,244,353$.

Writer：square1001
Score : 200 points

Problem Statement

We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).

You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is # if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is .. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Constraints

2 \leq H, W \leq 8

a_{i,j} is either # or ..

There exists a valid sequence of moves for Shik to generate the map a.

Input

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

H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}

Output

If it is possible that Shik only uses right and down moves, print Possible. Otherwise, print Impossible.

Sample Input 1

4 5
##...
.##..
..##.
...##

Sample Output 1

Possible

The matrix can be generated by a 7-move sequence: right, down, right, down, right, down, and right.

Sample Input 2

5 3
###
..#
###
#..
###

Sample Output 2

Impossible

Sample Input 3

4 5
##...
.###.
.###.
...##

Sample Output 3

Impossible
Score : 400 points

Problem Statement

You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions:

1 \leq a_i, b_i \leq 10^9 for all i

a_1 < a_2 < ... < a_N

b_1 > b_2 > ... > b_N

a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}

Constraints

2 \leq N \leq 20,000

p is a permutation of the set {1, 2, ..., N}

Input

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

N
p_1 p_2 ... p_N

Output

The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space.

It can be shown that there always exists a solution for any input satisfying the constraints.

Sample Input 1

2
1 2

Sample Output 1

1 4
5 4

a_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.

Sample Input 2

3
3 2 1

Sample Output 2

1 2 3
5 3 1

Sample Input 3

3
2 3 1

Sample Output 3

5 10 100
100 10 1
Score : 1000 points

Problem Statement

There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N).

We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.)

In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process.

For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario:

first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3.

second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9.

third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6.

So the total distance in this scenario is 18.

Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end.

Constraints

1 \leq N \leq 200,000

1 \leq d_1 \leq 100

0 \leq x \leq 100

All input values are integers.

Input

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

N d_1 x

Output

Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}.

Sample Input 1

1 3 3

Sample Output 1

4.500000000000000

The distance between the only ball and the left hole is 3 and distance between the only ball and the right hole is 6. There are only two scenarios (i.e. push left and push right). The only ball will roll 3 and 6 unit distance, respectively. So the answer for this example is (3+6)/2 = 4.5.

Sample Input 2

2 1 0

Sample Output 2

2.500000000000000

Sample Input 3

1000 100 100

Sample Output 3

649620280.957660079002380
Score : 1200 points

Problem Statement

Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all.

When the player gives a candy to a bear, it will provide a coin after T units of time. More specifically, if the i-th bear is given a candy at time t, it will put a coin at its position at time t+T. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player.

Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.

Constraints

1 \leq N \leq 100,000

1 \leq T, E \leq 10^9

0 < x_i < E

x_i < x_{i+1} for 1 \leq i < N

All input values are integers.

Partial Scores

In test cases worth 600 points, N \leq 2,000.

Input

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

N E T
x_1 x_2 ... x_N

Output

Print an integer denoting the answer.

Sample Input 1

3 9 1
1 3 8

Sample Output 1

12

The optimal strategy is to wait for the coin after treating each bear. The total time spent on waiting is 3 and moving is 9. So the answer is 3 + 9 = 12.

Sample Input 2

3 9 3
1 3 8

Sample Output 2

16

Sample Input 3

2 1000000000 1000000000
1 999999999

Sample Output 3

2999999996