A - Six Characters

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

英小文字からなる文字列 S が与えられます。 S の長さは 1 以上かつ 3 以下です。

S を繰り返して得られる文字列であって、長さが 6 のものを出力してください。

本問題の制約下で、そのような文字列はただ一つ存在することが示せます。

制約

  • S は英小文字からなる長さ 1 以上 3 以下の文字列

入力

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

S

出力

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


入力例 1

abc

出力例 1

abcabc

S = abc を繰り返してできる文字列として、abcabcabcabcabcabcabcabcabcabc などがあります。 そのうち、長さが 6 のものは abcabc です。よって、abcabc と出力します。


入力例 2

zz

出力例 2

zzzzzz

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English characters. The length of S is between 1 and 3, inclusive.

Print the string of length 6 that is a repetition of S.

It can be shown that there uniquely exists such a string under the Constraints of this problem.

Constraints

  • S is a string consisting of lowercase English characters of length between 1 and 3, inclusive.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer string, which is of length 6.


Sample Input 1

abc

Sample Output 1

abcabc

These are strings that are repetitions of S = abc: abc, abcabc, abcabcabc, abcabcabcabc, and so on. Among them, abcabc has the length of 6, so abcabc should be printed.


Sample Input 2

zz

Sample Output 2

zzzzzz
B - Four Digits

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

0 以上 9999 以下の整数 N が与えられます。

N の先頭に必要なだけ 0 をつけ、4 桁の文字列にしたものを出力してください。

制約

  • 0 \leq N \leq 9999
  • N は整数

入力

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

N

出力

答えを出力せよ。


入力例 1

321

出力例 1

0321

3213 桁なので、先頭に 10 をつけると 4 桁になります。


入力例 2

7777

出力例 2

7777

入力例 3

1

出力例 3

0001

Score : 100 points

Problem Statement

You are given an integer N between 0 and 9999 (inclusive).

Print it as a four-digit string after appending to it the necessary number of leading zeros.

Constraints

  • 0 \leq N \leq 9999
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

321

Sample Output 1

0321

321 has three digits, so we need to add one leading zero to it to make it have four digits.


Sample Input 2

7777

Sample Output 2

7777

Sample Input 3

1

Sample Output 3

0001
C - Pizza

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

ここに円形のピザが 1 枚あります。
高橋くんは長さ N の数列 A を使ってこのピザを以下の手順で切り分けます。

  • 最初に、円の中心から 12 時の方向に切れ込みをひとつ入れます。
  • 次に、以下の操作を N 回繰り返します。 i 回目の操作では以下を行います。
    • まず、ピザを時計回りに A_i 度回転させる。
    • 次に、円の中心から 12 時の方向に切れ込みをひとつ入れる。

例えば、A=(90,180,45,195) として手順を行うと、下図のようになります。

このとき、最も大きなピザの中心角が何度であるか求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • 同じ場所に複数回切れ込みが入ることはない。

入力

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

N
A_1 A_2 \dots A_N

出力

答えを整数として出力せよ。


入力例 1

4
90 180 45 195

出力例 1

120

この入力は問題文中の例と一致します。
最も大きなピザの中心角は 120 度です。


入力例 2

1
1

出力例 2

359

入力例 3

10
215 137 320 339 341 41 44 18 241 149

出力例 3

170

Score : 200 points

Problem Statement

We have a circular pizza.
Takahashi will cut this pizza using a sequence A of length N, according to the following procedure.

  • First, make a cut from the center in the 12 o'clock direction.
  • Next, do N operations. The i-th operation is as follows.
    • Rotate the pizza A_i degrees clockwise.
    • Then, make a cut from the center in the 12 o'clock direction.

For example, if A=(90,180,45,195), the procedure cuts the pizza as follows.

Find the center angle of the largest pizza after the procedure.

Constraints

  • All values in input are integers.
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • There will be no multiple cuts at the same position.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

4
90 180 45 195

Sample Output 1

120

This input coincides with the example in the Problem Statement.
The center angle of the largest pizza is 120 degrees.


Sample Input 2

1
1

Sample Output 2

359

Sample Input 3

10
215 137 320 339 341 41 44 18 241 149

Sample Output 3

170
D - Practical Computing

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

以下のような N 個の整数列 A_0,\ldots,A_{N-1} を求めてください。

  • i (0\leq i \leq N-1) について、A_i の長さは i+1 である。
  • i,j (0\leq i \leq N-1, 0 \leq j \leq i) について、A_ij+1 番目の値 a_{i,j} は次のように定められる。

    • j=0 または j=i の時、a_{i,j}=1
    • それ以外の時、a_{i,j} = a_{i-1,j-1} + a_{i-1,j}

制約

  • 1 \leq N \leq 30
  • N は整数

入力

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

N

出力

N 行出力せよ。 i 行目には A_{i-1} の値を順に空白区切りで出力せよ。


入力例 1

3

出力例 1

1
1 1
1 2 1

入力例 2

10

出力例 2

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

Score : 200 points

Problem Statement

Find the N integer sequences A_0,\ldots,A_{N-1} defined as follows.

  • For each i (0\leq i \leq N-1), the length of A_i is i+1.
  • For each i and j (0\leq i \leq N-1, 0 \leq j \leq i), the (j+1)-th term of A_i, denoted by a_{i,j}, is defined as follows.
    • a_{i,j}=1, if j=0 or j=i.
    • a_{i,j} = a_{i-1,j-1} + a_{i-1,j}, otherwise.

Constraints

  • 1 \leq N \leq 30
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the terms of A_{i-1} separated by spaces.


Sample Input 1

3

Sample Output 1

1
1 1
1 2 1

Sample Input 2

10

Sample Output 2

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
E - Reversible

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

ボールがいくつか刺さった棒が N 本あり、各ボールには英小文字が 1 個書かれています。

i = 1, 2, \ldots, N について、i 番目の棒に刺さった各ボールの英小文字は、文字列 S_i によって表されます。 具体的には、i 番目の棒には文字列 S_i の長さ |S_i| に等しい個数のボールが刺さっており、 刺さっているボールの英小文字を、棒のある端から順に並べたものは文字列 S_i と等しいです。

2 つの棒は、一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列と、もう一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列が一致するとき、同じ棒とみなされます。 より形式的には、1 以上 N 以下の整数 i, j について、i 本目の棒と j 本目の棒は、S_iS_j と一致するか、S_iS_j を前後反転したものと一致するとき、かつそのときに限り、同じとみなされます。

N 本の棒の中に、何種類の異なる棒があるかを出力してください。

制約

  • N は整数
  • 2 \leq N \leq 2 \times 10^5
  • S_i は英小文字のみからなる文字列
  • |S_i| \geq 1
  • \sum_{i = 1}^N |S_i| \leq 2 \times 10^5

入力

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

N
S_1
S_2
\vdots
S_N

出力

答えを出力せよ。


入力例 1

6
a
abc
de
cba
de
abc

出力例 1

3
  • S_2 = abcS_4 = cba を前後反転したものと一致するため、2 番目の棒と 4 番目の棒は同じとみなされます。
  • S_2 = abcS_6 = abc と一致するため、2 番目の棒と 6 番目の棒は同じとみなされます。
  • S_3 = deS_5 = de と一致するため、3 番目の棒と 5 番目の棒は同じとみなされます。

よって、6 本の棒の中に、1 本目の棒、2 本目の棒( 4, 6 本目の棒と同じ)、3 本目の棒( 5 本目の棒と同じ)の 3 種類の異なる棒があります。

Score : 300 points

Problem Statement

There are N sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.

For each i = 1, 2, \ldots, N, the letters written on the balls stuck onto the i-th stick are represented by a string S_i. Specifically, the number of balls stuck onto the i-th stick is the length |S_i| of the string S_i, and S_i is the sequence of letters on the balls starting from one end of the stick.

Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers i and j between 1 and N, inclusive, the i-th and j-th sticks are considered the same if and only if S_i equals S_j or its reversal.

Print the number of different sticks among the N sticks.

Constraints

  • N is an integer.
  • 2 \leq N \leq 2 \times 10^5
  • S_i is a string consisting of lowercase English letters.
  • |S_i| \geq 1
  • \sum_{i = 1}^N |S_i| \leq 2 \times 10^5

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the answer.


Sample Input 1

6
a
abc
de
cba
de
abc

Sample Output 1

3
  • S_2 = abc equals the reversal of S_4 = cba, so the second and fourth sticks are considered the same.
  • S_2 = abc equals S_6 = abc, so the second and sixth sticks are considered the same.
  • S_3 = de equals S_5 = de, so the third and fifth sticks are considered the same.

Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).