A - ringring

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 100

問題文

snuke 君は自転車を買いに来ました。 snuke 君はすでに買う自転車を決めたのですが、その自転車にはベルが付いていないため、 自転車とは別にベルも買う必要があります。

snuke 君は安全意識が高いので、ベルをどちらの手でも鳴らせるよう、両方のハンドルに 1 つずつ 付けることにしました。

お店にあるベルは 3 種類で、それぞれ a円、 b円、 c円です。 この 3 つのうち、異なる 2 つのベルを選んで買うときの、値段の合計の最小値を求めて下さい。

制約

  • 1 \leq a,b,c \leq 10000
  • a,b,c は整数

入力

入力は以下の形式で標準入力から与えられる。

a b c

出力

2 つのベルを買うときの最安値を出力せよ。


入力例 1

700 600 780

出力例 1

1300

700 円のベルと 600 円のベルを買うと、 1300 円かかります。
700 円のベルと 780 円のベルを買うと、 1480 円かかります。
600 円のベルと 780 円のベルを買うと、 1380 円かかります。
よって、一番安いのは 1300 円です。


入力例 2

10000 10000 10000

出力例 2

20000

どの 2 つを選んでも 20000 円かかってしまいます。

Score : 100 points

Problem Statement

Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.

He has very high awareness of safety, and decides to buy two bells, one for each hand.

The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.

Constraints

  • 1 \leq a,b,c \leq 10000
  • a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print the minimum total price of two different bells.


Sample Input 1

700 600 780

Sample Output 1

1300
  • Buying a 700-yen bell and a 600-yen bell costs 1300 yen.
  • Buying a 700-yen bell and a 780-yen bell costs 1480 yen.
  • Buying a 600-yen bell and a 780-yen bell costs 1380 yen.

The minimum among these is 1300 yen.


Sample Input 2

10000 10000 10000

Sample Output 2

20000

Buying any two bells costs 20000 yen.

B - ss

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 200

問題文

同じ文字列を 2 つ並べてできる文字列のことを偶文字列と呼ぶことにします。 例えば、 xyzxyzaaaaaa は偶文字列ですが、abababxyzxy は偶文字列ではありません。

アルファベットの小文字からなる偶文字列 S が与えられます。 S の末尾の文字を 1 文字以上消して作れる偶文字列のうち、最も長い偶文字列の長さを求めて下さい。 与えられる入力では、条件を満たす 1 文字以上の文字列が存在することが保証されています。

制約

  • 2 \leq |S| \leq 200
  • S は小文字のアルファベットのみからなる偶文字列である。
  • S に対して、条件を満たす 1 文字以上の文字列が存在する。

入力

入力は以下の形式で標準入力から与えられる。

S

出力

答えとなる文字列の長さを出力せよ。


入力例 1

abaababaab

出力例 1

6

abaababaab は偶文字列ですが、 1 文字も消していないので条件を満たしません。
abaababaa は偶文字列ではありません。
abaababa は偶文字列ではありません。
abaabab は偶文字列ではありません。
abaaba は偶文字列です。よって、答えは abaaba の長さである 6 です。


入力例 2

xxxx

出力例 2

2

xxx は偶文字列ではありません。
xx は偶文字列です。


入力例 3

abcabcabcabc

出力例 3

6

条件を満たす文字列は abcabc なので、答えは 6 です。


入力例 4

akasakaakasakasakaakas

出力例 4

14

条件を満たす文字列は akasakaakasaka なので、答えは 14 です。

Score : 200 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Constraints

  • 2 \leq |S| \leq 200
  • S is an even string consisting of lowercase English letters.
  • There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the length of the longest even string that can be obtained.


Sample Input 1

abaababaab

Sample Output 1

6
  • abaababaab itself is even, but we need to delete at least one character.
  • abaababaa is not even.
  • abaababa is not even.
  • abaabab is not even.
  • abaaba is even. Thus, we should print its length, 6.

Sample Input 2

xxxx

Sample Output 2

2
  • xxx is not even.
  • xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

The longest even string that can be obtained is abcabc, whose length is 6.


Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

The longest even string that can be obtained is akasakaakasaka, whose length is 14.

C - pushpush

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 300

問題文

長さ n の数列 a_1, ... , a_n が与えられます。 空の数列 b に対して、以下の操作を n 回行うことを考えます。

i 回目には

  1. 数列の i 番目の要素 a_ib の末尾に追加する。
  2. b を逆向きに並び替える。

この操作をしてできる数列 b を求めて下さい。

制約

  • 1 \leq n \leq 2\times 10^5
  • 0 \leq a_i \leq 10^9
  • n,a_i は整数である。

入力

入力は以下の形式で標準入力から与えられる。

n
a_1 a_2 ... a_n

出力

n 個の整数を空白区切りで 1 行に出力せよ。 i 番目には、 b_i を出力せよ。


入力例 1

4
1 2 3 4

出力例 1

4 2 1 3

1 回目の操作 1 の後、 b1 となります。
1 回目の操作 2 の後、 b1 となります。
2 回目の操作 1 の後、 b1, 2 となります。
2 回目の操作 2 の後、 b2, 1 となります。
3 回目の操作 1 の後、 b2, 1, 3 となります。
3 回目の操作 2 の後、 b3, 1, 2 となります。
4 回目の操作 1 の後、 b3, 1, 2, 4 となります。
4 回目の操作 2 の後、 b4, 2, 1, 3 となります。 よって、答えは 4 2 1 3 です。


入力例 2

3
1 2 3

出力例 2

3 1 2

出力例 1 の説明の通り、 3 回目の操作 2 の後、 b3, 1, 2 となるので、 答えは 3 1 2 です。


入力例 3

1
1000000000

出力例 3

1000000000

入力例 4

6
0 6 7 6 7 0

出力例 4

0 6 6 0 7 7

Score : 300 points

Problem Statement

You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.

The i-th operation is as follows:

  1. Append a_i to the end of b.
  2. Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

  • 1 \leq n \leq 2\times 10^5
  • 0 \leq a_i \leq 10^9
  • n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print n integers in a line with spaces in between. The i-th integer should be b_i.


Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3
  • After step 1 of the first operation, b becomes: 1.
  • After step 2 of the first operation, b becomes: 1.
  • After step 1 of the second operation, b becomes: 1, 2.
  • After step 2 of the second operation, b becomes: 2, 1.
  • After step 1 of the third operation, b becomes: 2, 1, 3.
  • After step 2 of the third operation, b becomes: 3, 1, 2.
  • After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.
  • After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.

Thus, the answer is 4 2 1 3.


Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

As shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.


Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7
D - 11

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 600

問題文

1,...,nn 個の整数からなる長さ n+1 の数列 a_1,a_2,...,a_{n+1} が与えられます。 この数列には 1,...,n のどの整数もかならず 1 回以上出現することが分かっています。

k=1,...,n+1 のそれぞれについて、与えられた数列の長さ k の(連続とは限らない)部分列の個数を求め、 10^9+7 で割ったあまりを出力して下さい。

注意

  • 2 つの部分列が数列として同じであれば、元の数列での位置が異なっていたとしても、1 通りと数えます。

  • 数列 a の長さ k の部分列とは、a の要素のうち k 個を選んで、 それらを順番を変えずに取り出して並べた数列のことを指します。 例えば、数列 1,2,3,4,5 の長さ 3 の部分列には、 1,3,51,2,3 などがあります。 一方で、3,1,21,10,100 はこの数列の部分列ではありません。

制約

  • 1 \leq n \leq 10^5
  • 1 \leq a_i \leq n
  • 1,...,n のどの整数も必ず数列に出現する。
  • n,a_i は整数である。

入力

入力は以下の形式で標準入力から与えられる。

n
a_1 a_2 ... a_{n+1}

出力

答えを n+1 行に出力せよ。 k 行目には、長さ k の部分列の個数を 10^9+7 で割ったあまりを出力せよ。


入力例 1

3
1 2 1 3

出力例 1

3
5
4
1

長さ 1 の部分列は 1233 通りです。

長さ 2 の部分列は 1,11,21,32,12,35 通りです。

長さ 3 の部分列は 1,1,31,2,11,2,32,1,34 通りです。

長さ 4 の部分列は 1,2,1,31 通りです。


入力例 2

1
1 1

出力例 2

1
1

長さ 1 の部分列は 11 通りです。 長さ 2 の部分列は 1,11 通りです。


入力例 3

32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9

出力例 3

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

10^9+7 で割ったあまりを出力することに注意して下さい。

Score : 600 points

Problem Statement

You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.

For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Notes

  • If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

  • A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

Constraints

  • 1 \leq n \leq 10^5
  • 1 \leq a_i \leq n
  • Each of the integers 1,...,n appears in the sequence.
  • n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_{n+1}

Output

Print n+1 lines. The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.


Sample Input 1

3
1 2 1 3

Sample Output 1

3
5
4
1

There are three subsequences with length 1: 1 and 2 and 3.

There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.

There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.

There is one subsequence with length 4: 1,2,1,3.


Sample Input 2

1
1 1

Sample Output 2

1
1

There is one subsequence with length 1: 1.

There is one subsequence with length 2: 1,1.


Sample Input 3

32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9

Sample Output 3

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

Be sure to print the numbers modulo 10^9+7.