A - Last Letter

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

配点 : 100

問題文

英小文字からなる長さ N の文字列 S が与えられます。S の末尾の文字を出力してください。

制約

  • N は整数
  • 1 ≤ N ≤ 1000
  • S は英小文字からなる長さ N の文字列

入力

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

N
S

出力

S の末尾の文字を出力せよ。


入力例 1

5
abcde

出力例 1

e

S = {}abcde です。S の末尾の文字は e なので、e を出力します。


入力例 2

1
a

出力例 2

a

Score : 100 points

Problem Statement

Given a string S of length N consisting of lowercase English alphabets, print the last character of S.

Constraints

  • N is an integer.
  • 1 ≤ N ≤ 1000
  • S is a string of length N consisting of lowercase English alphabets.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the last character of S.


Sample Input 1

5
abcde

Sample Output 1

e

The last character of S = {}abcde is e, so e should be printed.


Sample Input 2

1
a

Sample Output 2

a
B - Many A+B Problems

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

配点 : 100

問題文

N 個の整数の 2 つ組 (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N) が与えられます。 各 i = 1, 2, \ldots, N について、A_i + B_i を出力してください。

制約

  • 1 \leq N \leq 1000
  • -10^9 \leq A_i, B_i \leq 10^9
  • 入力はすべて整数

入力

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には A_i+B_i を出力せよ。


入力例 1

4
3 5
2 -6
-5 0
314159265 123456789

出力例 1

8
-4
-5
437616054
  • 1 行目には、A_1 + B_1 = 3 + 5 = 8 を、
  • 2 行目には、A_2 + B_2 = 2 + (-6) = -4 を、
  • 3 行目には、A_3 + B_3 = (-5) + 0 = -5 を、
  • 4 行目には、A_4 + B_4 = 314159265 + 123456789 = 437616054 を出力します。

Score : 100 points

Problem Statement

You are given N pairs of integers: (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N). For each i = 1, 2, \ldots, N, print A_i + B_i.

Constraints

  • 1 \leq N \leq 1000
  • -10^9 \leq A_i, B_i \leq 10^9
  • All values in the input are integers.

Input

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain A_i+B_i.


Sample Input 1

4
3 5
2 -6
-5 0
314159265 123456789

Sample Output 1

8
-4
-5
437616054
  • The first line should contain A_1 + B_1 = 3 + 5 = 8.
  • The second line should contain A_2 + B_2 = 2 + (-6) = -4.
  • The third line should contain A_3 + B_3 = (-5) + 0 = -5.
  • The fourth line should contain A_4 + B_4 = 314159265 + 123456789 = 437616054.
C - String Too Long

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

配点 : 200

問題文

連長圧縮(ランレングス圧縮)を復元してください。ただし、長すぎる場合には Too Long と出力してください。

N 個の文字と整数の組 (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N) が与えられます。

l_1 個の文字 c_1l_2 個の文字 c_2\ldotsl_N 個の文字 c_N をこの順に連結させた文字列を S とします。

S を出力してください。ただし、S の長さが 100 を超える場合には代わりに Too Long と出力してください。

制約

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N,l_i は整数
  • c_i は英小文字
  • c_i\neq c_{i+1}

入力

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

出力

S の長さが 100 以下なら S を、そうでないなら Too Long と出力せよ。


入力例 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

出力例 1

mississippi

Smississippi です。S の長さは 100 以下であるため S を出力します。


入力例 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

出力例 2

Too Long

S の長さは 7\times 10^{18} であるため、Too Long を出力します。


入力例 3

1
a 100

出力例 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

入力例 4

6
g 4
j 1
m 4
e 4
d 3
i 4

出力例 4

ggggjmmmmeeeedddiiii

Score : 200 points

Problem Statement

Restore run-length encoding. If the result is too long, output Too Long.

You are given N pairs of characters and integers (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N).

Let S be the string formed by concatenating l_1 characters c_1, l_2 characters c_2, \ldots, and l_N characters c_N in this order.

Output S. However, if the length of S exceeds 100, output Too Long instead.

Constraints

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N and l_i are integers.
  • Each c_i is a lowercase English letter.
  • c_i\neq c_{i+1}

Input

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

Output

If the length of S is at most 100, output S; otherwise, output Too Long.


Sample Input 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

Sample Output 1

mississippi

S is mississippi. Since the length of S is not greater than 100, output S.


Sample Input 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

Sample Output 2

Too Long

The length of S is 7\times 10^{18}, so output Too Long.


Sample Input 3

1
a 100

Sample Output 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Input 4

6
g 4
j 1
m 4
e 4
d 3
i 4

Sample Output 4

ggggjmmmmeeeedddiiii
D - Calculator

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

配点 : 200

問題文

00, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 のボタンがある電卓があります。
この電卓で文字列 x が表示されている時に b のボタンを押すと、表示される文字列は x の末尾に b を連結したものとなります。

最初、電卓には空文字列 ( 0 文字の文字列 ) が表示されています。
この電卓に文字列 S を表示させるためにボタンを押す回数の最小値を求めてください。

制約

  • S0, 1, 2, 3, 4, 5, 6, 7, 8, 9 からなる長さ 1 以上 1000 以下の列
  • S の先頭は 0 でない

入力

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

S

出力

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


入力例 1

1000000007

出力例 1

6

1000000007 を表示させるには、 1, 00, 00, 00, 00, 7 のボタンをこの順に押せばよく、ボタンを押した回数は 6 回で、これが達成可能な最小値です。


入力例 2

998244353

出力例 2

9

入力例 3

32000

出力例 3

4

Score : 200 points

Problem Statement

There is a calculator with the buttons 00, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
When a string x is displayed on this calculator and you press a button b, the resulting displayed string becomes the string x with b appended to its end.

Initially, the calculator displays the empty string (a string of length 0).
Find the minimum number of button presses required to display the string S on this calculator.

Constraints

  • S is a string of length at least 1 and at most 1000, consisting of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
  • The first character of S is not 0.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

1000000007

Sample Output 1

6

To display 1000000007, you can press the buttons 1, 00, 00, 00, 00, 7 in this order. The total number of button presses is 6, and this is the minimum possible.


Sample Input 2

998244353

Sample Output 2

9

Sample Input 3

32000

Sample Output 3

4
E - Almost Equal

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

配点 : 250

問題文

英小文字からなる長さ M の文字列 NS_1,S_2,\dots,S_N が与えられます。ここで、S_i は互いに異なります。

これらを並び替えた文字列の列 T_1,T_2,\dots,T_N であって、以下の条件を満たすものが存在するか判定してください。

  • 1 \le i \le N-1 を満たす全ての整数 i に対して、T_i1 文字だけ別の英小文字に変えて T_{i+1} にすることが出来る。

制約

  • 2 \le N \le 8
  • 1 \le M \le 5
  • S_i は英小文字からなる長さ M の文字列である。(1 \le i \le N)
  • S_i は互いに異なる。

入力

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

N M
S_1
S_2
\vdots
S_N

出力

問題文の条件を満たす列が存在するならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 4
bbed
abcd
abed
fbed

出力例 1

Yes

abcd , abed , bbed , fbed の順に並び替えると条件を満たします。


入力例 2

2 5
abcde
abced

出力例 2

No

どのように並び替えても条件を満たすことは出来ません。


入力例 3

8 4
fast
face
cast
race
fact
rice
nice
case

出力例 3

Yes

Score : 250 points

Problem Statement

You are given N strings S_1,S_2,\dots,S_N, each of length M, consisting of lowercase English letter. Here, S_i are pairwise distinct.

Determine if one can rearrange these strings to obtain a new sequence of strings T_1,T_2,\dots,T_N such that:

  • for all integers i such that 1 \le i \le N-1, one can alter exactly one character of T_i to another lowercase English letter to make it equal to T_{i+1}.

Constraints

  • 2 \le N \le 8
  • 1 \le M \le 5
  • S_i is a string of length M consisting of lowercase English letters. (1 \le i \le N)
  • S_i are pairwise distinct.

Input

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

N M
S_1
S_2
\vdots
S_N

Output

Print Yes if one can obtain a conforming sequence; print No otherwise.


Sample Input 1

4 4
bbed
abcd
abed
fbed

Sample Output 1

Yes

One can rearrange them in this order: abcd, abed, bbed, fbed. This sequence satisfies the condition.


Sample Input 2

2 5
abcde
abced

Sample Output 2

No

No matter how the strings are rearranged, the condition is never satisfied.


Sample Input 3

8 4
fast
face
cast
race
fact
rice
nice
case

Sample Output 3

Yes