CodeEff/ECCO huggingface dataset:
Problem Description: Score : 800 points
Problem Statement
There are
N
towns in Snuke Kingdom, conveniently numbered
1
through
N
.
Town
1
is the capital.
Each town in the kingdom has a
Teleporter
, a facility that instantly transports a person to another place.
The destination of the Teleporter of town
i
is town
a_i
(
1≤a_i≤N
).
It is guaranteed that
one can get to the capital from any town by using the Teleporters some number of times
.
King Snuke loves the integer
K
.
The selfish king wants to change the destination of the Teleporters so that the following holds:
Starting from any town, one will be at the capital after using the Teleporters exactly
K
times in total.
Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
Constraints
2≤N≤10^5
1≤a_i≤N
One can get to the capital from any town by using the Teleporters some number of times.
1≤K≤10^9
Input
The input is given from Standard Input in the following format:
N
K
a_1
a_2
...
a_N
Output
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire.
Sample Input 1
3 1
2 3 1
Sample Output 1
2
Change the destinations of the Teleporters to
a = (1,1,1)
.
Sample Input 2
4 2
1 1 2 2
Sample Output 2
0
There is no need to change the destinations of the Teleporters, since the king's desire is already satisfied.
Sample Input 3
8 2
4 1 2 3 1 2 3 4
Sample Output 3
3
For example, change the destinations of the Teleporters to
a = (1,1,2,1,1,2,2,4)
.
Problem Description: Score : 100 points
Problem Statement
There is a hotel with the following accommodation fee:
X
yen (the currency of Japan) per night, for the first
K
nights
Y
yen per night, for the
(K+1)
-th and subsequent nights
Tak is staying at this hotel for
N
consecutive nights.
Find his total accommodation fee.
Constraints
1 \leq N, K \leq 10000
1 \leq Y < X \leq 10000
N,\,K,\,X,\,Y
are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Sample Input 1
5
3
10000
9000
Sample Output 1
48000
The accommodation fee is as follows:
10000
yen for the
1
-st night
10000
yen for the
2
-nd night
10000
yen for the
3
-rd night
9000
yen for the
4
-th night
9000
yen for the
5
-th night
Thus, the total is
48000
yen.
Sample Input 2
2
3
10000
9000
Sample Output 2
20000
Problem Description: Score : 300 points
Problem Statement
Tak has
N
cards. On the
i
-th
(1 \leq i \leq N)
card is written an integer
x_i
.
He is selecting one or more cards from these
N
cards, so that the average of the integers written on the selected cards is exactly
A
.
In how many ways can he make his selection?
Constraints
1 \leq N \leq 50
1 \leq A \leq 50
1 \leq x_i \leq 50
N,\,A,\,x_i
are integers.
Partial Score
200
points will be awarded for passing the test set satisfying
1 \leq N \leq 16
.
Input
The input is given from Standard Input in the following format:
N
A
x_1
x_2
...
x_N
Output
Print the number of ways to select cards such that the average of the written integers is exactly
A
.
Sample Input 1
4 8
7 9 8 9
Sample Output 1
5
The following are the
5
ways to select cards such that the average is
8
:
Select the
3
-rd card.
Select the
1
-st and
2
-nd cards.
Select the
1
-st and
4
-th cards.
Select the
1
-st,
2
-nd and
3
-rd cards.
Select the
1
-st,
3
-rd and
4
-th cards.
Sample Input 2
3 8
6 6 9
Sample Output 2
0
Sample Input 3
8 5
3 6 2 8 7 6 5 9
Sample Output 3
19
Sample Input 4
33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Sample Output 4
8589934591
The answer may not fit into a
32
-bit integer.
Problem Description: Score : 500 points
Problem Statement
For integers
b (b \geq 2)
and
n (n \geq 1)
, let the function
f(b,n)
be defined as follows:
f(b,n) = n
, when
n < b
f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b)
, when
n \geq b
Here,
{\rm floor}(n / b)
denotes the largest integer not exceeding
n / b
,
and
n \ {\rm mod} \ b
denotes the remainder of
n
divided by
b
.
Less formally,
f(b,n)
is equal to the sum of the digits of
n
written in base
b
.
For example, the following hold:
f(10,\,87654)=8+7+6+5+4=30
f(100,\,87654)=8+76+54=138
You are given integers
n
and
s
.
Determine if there exists an integer
b (b \geq 2)
such that
f(b,n)=s
.
If the answer is positive, also find the smallest such
b
.
Constraints
1 \leq n \leq 10^{11}
1 \leq s \leq 10^{11}
n,\,s
are integers.
Input
The input is given from Standard Input in the following format:
n
s
Output
If there exists an integer
b (b \geq 2)
such that
f(b,n)=s
, print the smallest such
b
.
If such
b
does not exist, print
-1
instead.
Sample Input 1
87654
30
Sample Output 1
10
Sample Input 2
87654
138
Sample Output 2
100
Sample Input 3
87654
45678
Sample Output 3
-1
Sample Input 4
31415926535
1
Sample Output 4
31415926535
Sample Input 5
1
31415926535
Sample Output 5
-1
Problem Description: Score : 700 points
Problem Statement
N
hotels are located on a straight line. The coordinate of the
i
-th hotel
(1 \leq i \leq N)
is
x_i
.
Tak the traveler has the following two personal principles:
He never travels a distance of more than
L
in a single day.
He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are given
Q
queries. The
j
-th
(1 \leq j \leq Q)
query is described by two distinct integers
a_j
and
b_j
.
For each query, find the minimum number of days that Tak needs to travel from the
a_j
-th hotel to the
b_j
-th hotel following his principles.
It is guaranteed that he can always travel from the
a_j
-th hotel to the
b_j
-th hotel, in any given input.
Constraints
2 \leq N \leq 10^5
1 \leq L \leq 10^9
1 \leq Q \leq 10^5
1 \leq x_i < x_2 < ... < x_N \leq 10^9
x_{i+1} - x_i \leq L
1 \leq a_j,b_j \leq N
a_j \neq b_j
N,\,L,\,Q,\,x_i,\,a_j,\,b_j
are integers.
Partial Score
200
points will be awarded for passing the test set satisfying
N \leq 10^3
and
Q \leq 10^3
.
Input
The input is given from Standard Input in the following format:
N
x_1
x_2
...
x_N
L
Q
a_1
b_1
a_2
b_2
:
a_Q
b_Q
Output
Print
Q
lines.
The
j
-th line
(1 \leq j \leq Q)
should contain the minimum number of days that Tak needs to travel from the
a_j
-th hotel to the
b_j
-th hotel.
Sample Input 1
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
Sample Output 1
4
2
1
2
For the
1
-st query, he can travel from the
1
-st hotel to the
8
-th hotel in
4
days, as follows:
Day
1
: Travel from the
1
-st hotel to the
2
-nd hotel. The distance traveled is
2
.
Day
2
: Travel from the
2
-nd hotel to the
4
-th hotel. The distance traveled is
10
.
Day
3
: Travel from the
4
-th hotel to the
7
-th hotel. The distance traveled is
6
.
Day
4
: Travel from the
7
-th hotel to the
8
-th hotel. The distance traveled is
10
.
Problem Description: Score : 200 points
Problem Statement
Snuke lives on an infinite two-dimensional plane. He is going on an
N
-day trip.
At the beginning of Day
1
, he is at home. His plan is described in a string
S
of length
N
.
On Day
i(1 ≦ i ≦ N)
, he will travel a positive distance in the following direction:
North if the
i
-th letter of
S
is
N
West if the
i
-th letter of
S
is
W
South if the
i
-th letter of
S
is
S
East if the
i
-th letter of
S
is
E
He has not decided each day's travel distance. Determine whether it is possible to set each day's travel distance so that he will be back at home at the end of Day
N
.
Constraints
1 ≦ | S | ≦ 1000
S
consists of the letters
N
,
W
,
S
,
E
.
Input
The input is given from Standard Input in the following format:
S
Output
Print
Yes
if it is possible to set each day's travel distance so that he will be back at home at the end of Day
N
. Otherwise, print
No
.
Sample Input 1
SENW
Sample Output 1
Yes
If Snuke travels a distance of
1
on each day, he will be back at home at the end of day
4
.
Sample Input 2
NSNNSNSN
Sample Output 2
Yes
Sample Input 3
NNEW
Sample Output 3
No
Sample Input 4
W
Sample Output 4
No
Problem Description: Score : 400 points
Problem Statement
Snuke has a large collection of cards. Each card has an integer between
1
and
N
, inclusive, written on it.
He has
A_i
cards with an integer
i
.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most
1
.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
1 ≦ N ≦ 10^5
0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Sample Input 1
4
4
0
3
2
Sample Output 1
4
For example, Snuke can create the following four pairs:
(1,1),(1,1),(3,4),(3,4)
.
Sample Input 2
8
2
0
1
6
0
8
2
1
Sample Output 2
9
Problem Description: Score : 600 points
Problem Statement
Snuke got an integer sequence of length
N
from his mother, as a birthday present. The
i
-th
(1 ≦ i ≦ N)
element of the sequence is
a_i
. The elements are pairwise distinct.
He is sorting this sequence in increasing order.
With supernatural power, he can perform the following two operations on the sequence in any order:
Operation
1
: choose
2
consecutive elements, then reverse the order of those elements.
Operation
2
: choose
3
consecutive elements, then reverse the order of those elements.
Snuke likes Operation
2
, but not Operation
1
. Find the minimum number of Operation
1
that he has to perform in order to sort the sequence in increasing order.
Constraints
1 ≦ N ≦ 10^5
0 ≦ A_i ≦ 10^9
If
i ≠ j
, then
A_i ≠ A_j
.
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the minimum number of times Operation
1
that Snuke has to perform.
Sample Input 1
4
2
4
3
1
Sample Output 1
1
The given sequence can be sorted as follows:
First, reverse the order of the last three elements. The sequence is now:
2,1,3,4
.
Then, reverse the order of the first two elements. The sequence is now:
1,2,3,4
.
In this sequence of operations, Operation
1
is performed once. It is not possible to sort the sequence with less number of Operation
1
, thus the answer is
1
.
Sample Input 2
5
10
8
5
3
2
Sample Output 2
0
Problem Description: Score : 100 points
Problem Statement
There are
N
children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give
1
candy to the first child in the line,
2
candies to the second child, ...,
N
candies to the
N
-th child. How many candies will be necessary in total?
Constraints
1≦N≦100
Input
The input is given from Standard Input in the following format:
N
Output
Print the necessary number of candies in total.
Sample Input 1
3
Sample Output 1
6
The answer is
1+2+3=6
.
Sample Input 2
10
Sample Output 2
55
The sum of the integers from
1
to
10
is
55
.
Sample Input 3
1
Sample Output 3
1
Only one child. The answer is
1
in this case.
Problem Description: Score : 200 points
Problem Statement
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has
3
keys on it: the
0
key, the
1
key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
The
0
key: a letter
0
will be inserted to the right of the string.
The
1
key: a letter
1
will be inserted to the right of the string.
The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys several times. You are given a string
s
, which is a record of his keystrokes in order. In this string, the letter
0
stands for the
0
key, the letter
1
stands for the
1
key and the letter
B
stands for the backspace key. What string is displayed in the editor now?
Constraints
1 ≦ |s| ≦ 10
(
|s|
denotes the length of
s
)
s
consists of the letters
0
,
1
and
B
.
The correct answer is not an empty string.
Input
The input is given from Standard Input in the following format:
s
Output
Print the string displayed in the editor in the end.
Sample Input 1
01B0
Sample Output 1
00
Each time the key is pressed, the string in the editor will change as follows:
0
,
01
,
0
,
00
.
Sample Input 2
0BB1
Sample Output 2
1
Each time the key is pressed, the string in the editor will change as follows:
0
,
(empty)
,
(empty)
,
1
.
Problem Description: Score : 200 points
Problem Statement
Evi has
N
integers
a_1,a_2,..,a_N
. His objective is to have
N
equal
integers
by transforming some of them.
He may transform each integer at most once. Transforming an integer
x
into another integer
y
costs him
(x-y)^2
dollars. Even if
a_i=a_j (i≠j)
, he has to pay the cost separately for transforming each of them (See Sample 2).
Find the minimum total cost to achieve his objective.
Constraints
1≦N≦100
-100≦a_i≦100
Input
The input is given from Standard Input in the following format:
N
a_1
a_2
...
a_N
Output
Print the minimum total cost to achieve Evi's objective.
Sample Input 1
2
4 8
Sample Output 1
8
Transforming the both into
6
s will cost
(4-6)^2+(8-6)^2=8
dollars, which is the minimum.
Sample Input 2
3
1 1 3
Sample Output 2
3
Transforming the all into
2
s will cost
(1-2)^2+(1-2)^2+(3-2)^2=3
dollars. Note that Evi has to pay
(1-2)^2
dollar separately for transforming each of the two
1
s.
Sample Input 3
3
4 2 5
Sample Output 3
5
Leaving the
4
as it is and transforming the
2
and the
5
into
4
s will achieve the total cost of
(2-4)^2+(5-4)^2=5
dollars, which is the minimum.
Sample Input 4
4
-100 -100 -100 -100
Sample Output 4
0
Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is
0
.
Problem Statement
Problem Description: You are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.
Constraints
a
and
b
are integers.
-10^9≤a≤b≤10^9
Partial Score
In test cases worth
100
points,
-10≤a≤b≤10
.
Input
The input is given from Standard Input in the following format:
a
b
Output
If the product is positive, print
Positive
. If it is negative, print
Negative
. If it is zero, print
Zero
.
Sample Input 1
1 3
Sample Output 1
Positive
1×2×3=6
is positive.
Sample Input 2
-3 -1
Sample Output 2
Negative
(-3)×(-2)×(-1)=-6
is negative.
Sample Input 3
-1 1
Sample Output 3
Zero
(-1)×0×1=0
.
Problem Statement
Problem Description: We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.
Snuke will perform the following
M
operations, one by one. In the
i
-th operation, he randomly picks one ball from box
x_i
, then he puts it into box
y_i
.
Find the number of boxes that may contain the red ball after all operations are performed.
Constraints
2≤N≤10^5
1≤M≤10^5
1≤x_i,y_i≤N
x_i≠y_i
Just before the
i
-th operation is performed, box
x_i
contains at least
1
ball.
Input
The input is given from Standard Input in the following format:
N
M
x_1
y_1
:
x_M
y_M
Output
Print the number of boxes that may contain the red ball after all operations are performed.
Sample Input 1
3 2
1 2
2 3
Sample Output 1
2
Just after the first operation, box
1
is empty, box
2
contains one red ball and one white ball, and box
3
contains one white ball.
Now, consider the second operation. If Snuke picks the red ball from box
2
, the red ball will go into box
3
. If he picks the white ball instead, the red ball will stay in box
2
.
Thus, the number of boxes that may contain the red ball after all operations, is
2
.
Sample Input 2
3 3
1 2
2 3
2 3
Sample Output 2
1
All balls will go into box
3
.
Sample Input 3
4 4
1 2
2 3
4 1
3 4
Sample Output 3
3
Problem Statement
Problem Description: We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i.
At first, for each
i (1≤i≤N-1)
, piece
i
and piece
i+1
are tied at the ends, forming one long rope with
N-1
knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:
Choose a (connected) rope with a total length of at least
L
, then untie one of its knots.
Is it possible to untie all of the
N-1
knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
Constraints
2≤N≤10^5
1≤L≤10^9
1≤a_i≤10^9
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
L
a_1
a_2
...
a_n
Output
If it is not possible to untie all of the
N-1
knots, print
Impossible
.
If it is possible to untie all of the knots, print
Possible
, then print another
N-1
lines that describe a possible order to untie the knots. The
j
-th of those
N-1
lines should contain the index of the knot that is untied in the
j
-th operation. Here, the index of the knot connecting piece
i
and piece
i+1
is
i
.
If there is more than one solution, output any.
Sample Input 1
3 50
30 20 10
Sample Output 1
Possible
2
1
If the knot
1
is untied first, the knot
2
will become impossible to untie.
Sample Input 2
2 21
10 10
Sample Output 2
Impossible
Sample Input 3
5 50
10 20 30 40 50
Sample Output 3
Possible
1
2
3
4
Another example of a possible solution is
3
,
4
,
1
,
2
.
Problem Statement
Problem Description: There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.
Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:
Choose a pile with the largest number of candies remaining, then eat all candies of that pile.
From each pile with one or more candies remaining, eat one candy.
The player who eats the last candy on the table, loses the game. Determine which player will win if both players play the game optimally.
Constraints
1≤N≤10^5
1≤a_i≤10^9
Input
The input is given from Standard Input in the following format:
N
a_1
a_2
…
a_N
Output
If Snuke will win, print
First
. If Ciel will win, print
Second
.
Sample Input 1
2
1 3
Sample Output 1
First
At the beginning of the game, pile
2
contains the most candies. If Snuke eats all candies of this pile, Ciel has no choice but to eat the last candy.
Sample Input 2
3
1 2 1
Sample Output 2
First
If Snuke eats one candy from each pile, Ciel is again left with the last candy.
Sample Input 3
3
1 2 3
Sample Output 3
Second
Problem Description: Score : 300 points
Problem Statement
Iroha is very particular about numbers. There are
K
digits that she dislikes:
D_1, D_2, ..., D_K
.
She is shopping, and now paying at the cashier.
Her total is
N
yen (the currency of Japan), thus she has to hand at least
N
yen to the cashier (and possibly receive the change).
However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.
Find the amount of money that she will hand to the cashier.
Constraints
1 ≦ N < 10000
1 ≦ K < 10
0 ≦ D_1 < D_2 < … < D_K≦9
\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}
Input
The input is given from Standard Input in the following format:
N
K
D_1
D_2
…
D_K
Output
Print the amount of money that Iroha will hand to the cashier.
Sample Input 1
1000 8
1 3 4 5 6 7 8 9
Sample Output 1
2000
She dislikes all digits except
0
and
2
.
The smallest integer equal to or greater than
N=1000
whose decimal notation contains only
0
and
2
, is
2000
.
Sample Input 2
9999 1
0
Sample Output 2
9999
Problem Description: Score : 400 points
Problem Statement
We have a large square grid with
H
rows and
W
columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom
A
rows and the leftmost
B
columns. (That is, there are
A×B
forbidden cells.) There is no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo
10^9+7
.
Constraints
1 ≦ H, W ≦ 100,000
1 ≦ A < H
1 ≦ B < W
Input
The input is given from Standard Input in the following format:
H
W
A
B
Output
Print the number of ways she can travel to the bottom-right cell, modulo
10^9+7
.
Sample Input 1
2 3 1 1
Sample Output 1
2
We have a
2×3
grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".
Sample Input 2
10 7 3 4
Sample Output 2
3570
There are
12
forbidden cells.
Sample Input 3
100000 100000 99999 99999
Sample Output 3
1
Sample Input 4
100000 100000 44444 55555
Sample Output 4
738162020
Problem Description: Score : 100 points
Problem Statement
Iroha loves
Haiku
. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with
5
,
7
and
5
syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have
A
,
B
and
C
syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
Constraints
1≦A,B,C≦10
Input
The input is given from Standard Input in the following format:
A
B
C
Output
If it is possible to construct a Haiku by using each of the phrases once, print
YES
(case-sensitive). Otherwise, print
NO
.
Sample Input 1
5 5 7
Sample Output 1
YES
Using three phrases of length
5
,
5
and
7
, it is possible to construct a Haiku.
Sample Input 2
7 7 5
Sample Output 2
NO
Problem Description: Score : 200 points
Problem Statement
Iroha has a sequence of
N
strings
S_1, S_2, ..., S_N
. The length of each string is
L
.
She will concatenate all of the strings in some order, to produce a long string.
Among all strings that she can produce in this way, find the lexicographically smallest one.
Here, a string
s=s_1s_2s_3
...
s_n
is
lexicographically smaller
than another string
t=t_1t_2t_3
...
t_m
if and only if one of the following holds:
There exists an index
i(1≦i≦min(n,m))
, such that
s_j = t_j
for all indices
j(1≦j<i)
, and
s_i<t_i
.
s_i = t_i
for all integers
i(1≦i≦min(n,m))
, and
n<m
.
Constraints
1 ≦ N, L ≦ 100
For each
i
, the length of
S_i
equals
L
.
For each
i
,
S_i
consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
N
L
S_1
S_2
:
S_N
Output
Print the lexicographically smallest string that Iroha can produce.
Sample Input 1
3 3
dxx
axx
cxx
Sample Output 1
axxcxxdxx
The following order should be used:
axx
,
cxx
,
dxx
.
Problem Description: Score : 200 points
Problem Statement
Snuke is having a barbeque party.
At the party, he will make
N
servings of
Skewer Meal
.
Example of a serving of Skewer Meal
He has a stock of
2N
skewers, all of which will be used in Skewer Meal. The length of the
i
-th skewer is
L_i
.
Also, he has an infinite supply of ingredients.
To make a serving of Skewer Meal, he picks
2
skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be
x
, then the serving can hold the maximum of
x
ingredients.
What is the maximum total number of ingredients that his
N
servings of Skewer Meal can hold, if he uses the skewers optimally?
Constraints
1≦N≦100
1≦L_i≦100
For each
i
,
L_i
is an integer.
Input
The input is given from Standard Input in the following format:
N
L_1
L_2
...
L_{2N}
Output
Print the maximum total number of ingredients that Snuke's
N
servings of Skewer Meal can hold.
Sample Input 1
2
1 3 1 2
Sample Output 1
3
If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold
1
and
2
ingredients, for the total of
3
.
Sample Input 2
5
100 1 2 3 14 15 58 58 58 29
Sample Output 2
135