A - Rearranging ABC

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

配点 : 100

問題文

長さ 3 の英大文字からなる文字列 S が与えられます。

S の各文字を並び替えることで S を文字列 ABC と一致させることができるか判定してください。

制約

  • S は英大文字からなる長さ 3 の文字列

入力

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

S

出力

S の各文字を並び替えることで文字列 ABC と一致させることができるなら Yes を、そうでないなら No を出力せよ。


入力例 1

BAC

出力例 1

Yes

S1 文字目と S2 文字目を入れ替えることで ABC と一致させることができます。


入力例 2

AAC

出力例 2

No

どのように並び替えても SABC と一致させることはできません。


入力例 3

ABC

出力例 3

Yes

入力例 4

ARC

出力例 4

No

Score : 100 points

Problem Statement

You are given a string S of length 3 consisting of uppercase English letters.

Determine whether it is possible to rearrange the characters in S to make it match the string ABC.

Constraints

  • S is a string of length 3 consisting of uppercase English letters.

Input

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

S

Output

Print Yes if it is possible to rearrange the characters in S to make it match the string ABC, and No otherwise.


Sample Input 1

BAC

Sample Output 1

Yes

You can make S match ABC by swapping the first and second characters of S.


Sample Input 2

AAC

Sample Output 2

No

You cannot make S match ABC no matter how you rearrange the characters.


Sample Input 3

ABC

Sample Output 3

Yes

Sample Input 4

ARC

Sample Output 4

No
B - Trimo

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

配点 : 100

問題文

長さ N の文字列 S が与えられます。
S のうち先頭に連続する o をすべて取り除いた文字列を出力してください。
なお、 S 中のすべての文字が o である場合は空文字列を出力してください。

制約

  • N1 \le N \le 50 を満たす整数
  • S は英小文字からなる長さ N の文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

7
ooparts

出力例 1

parts

ooparts のうち先頭に連続する o をすべて取り除くと parts となります。


入力例 2

6
abcooo

出力例 2

abcooo

先頭の文字が o でない場合もあります。


入力例 3

5
ooooo

出力例 3



すべての文字が o である場合もあります。

Score : 100 points

Problem Statement

You are given a string S of length N.
Output the string obtained by removing all leading consecutive os from S.
If all characters in S are o, output an empty string.

Constraints

  • N is an integer satisfying 1 \le N \le 50.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N
S

Output

Output the answer.


Sample Input 1

7
ooparts

Sample Output 1

parts

Removing all leading consecutive os from ooparts gives parts.


Sample Input 2

6
abcooo

Sample Output 2

abcooo

The first character may not be o.


Sample Input 3

5
ooooo

Sample Output 3



All characters may be o.

C - Broken Rounding

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

配点 : 200

問題文

非負整数 X に対し、 i=0,1,\dots,K-1 の順に次の操作を行ったとき、操作を全て終えた時点での X を求めてください。

  • X10^i の位以下を四捨五入する。
    • 厳密には、 X を「 |Y-X| が最小となる 10^{i+1} の倍数のうち最大のもの」である Y に置き換える。
    • 具体例を挙げる。
      • 27310^1 の位以下を四捨五入すれば 300 となる。
      • 99910^2 の位以下を四捨五入すれば 1000 となる。
      • 10010^9 の位以下を四捨五入すれば 0 となる。
      • 101510^0 の位以下を四捨五入すれば 1020 となる。

制約

  • X,K は整数
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

入力

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

X K

出力

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


入力例 1

2048 2

出力例 1

2100

操作の過程で、 X2048 \rightarrow 2050 \rightarrow 2100 と変化します。


入力例 2

1 15

出力例 2

0

入力例 3

999 3

出力例 3

1000

入力例 4

314159265358979 12

出力例 4

314000000000000

X32bit 整数型に収まらない可能性があります。

Score : 200 points

Problem Statement

Given a non-negative integer X, perform the following operation for i=1,2,\dots,K in this order and find the resulting X.

  • Round X off to the nearest 10^i.
    • Formally, replace X with Y that is "the largest multiple of 10^i that minimizes |Y-X|."
    • Here are some examples:
      • Rounding 273 off to the nearest 10^2 yields 300.
      • Rounding 999 off to the nearest 10^3 yields 1000.
      • Rounding 100 off to the nearest 10^{10} yields 0.
      • Rounding 1015 off to the nearest 10^1 yields 1020.

Constraints

  • X and K are integers.
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

Input

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

X K

Output

Print the answer as an integer.


Sample Input 1

2048 2

Sample Output 1

2100

X changes as 2048 \rightarrow 2050 \rightarrow 2100 by the operations.


Sample Input 2

1 15

Sample Output 2

0

Sample Input 3

999 3

Sample Output 3

1000

Sample Input 4

314159265358979 12

Sample Output 4

314000000000000

X may not fit into a 32-bit integer type.

D - 459

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

配点 : 200

問題文

英小文字のみからなる N 個の文字列 S_1,S_2,\ldots,S_N が与えられます。

N 個の数字 C_1,C_2,\ldots,C_N を以下のように定義します。

  • S_i の先頭の文字が a, b, c のいずれかならば C_i=2
  • S_i の先頭の文字が d, e, f のいずれかならば C_i=3
  • S_i の先頭の文字が g, h, i のいずれかならば C_i=4
  • S_i の先頭の文字が j, k, l のいずれかならば C_i=5
  • S_i の先頭の文字が m, n, o のいずれかならば C_i=6
  • S_i の先頭の文字が p, q, r, s のいずれかならば C_i=7
  • S_i の先頭の文字が t, u, v のいずれかならば C_i=8
  • S_i の先頭の文字が w, x, y, z のいずれかならば C_i=9

C_1,C_2,\ldots,C_N をこの順に連結した文字列を出力してください。

制約

  • 1\leq N\leq 10
  • N は整数
  • S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1 S_2 \ldots S_N

出力

C_1,C_2,\ldots,C_N をこの順に連結した文字列を出力せよ。


入力例 1

2
algorithm heuristic

出力例 1

24
  • S_1=algorithm の先頭の文字は a であるため、C_1=2 となります。
  • S_2=heuristic の先頭の文字は h であるため、C_2=4 となります。

よって、これらを連結した 24 を出力します。


入力例 2

3
i love you

出力例 2

459

Score : 200 points

Problem Statement

You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters.

Define N digits C_1, C_2, \ldots, C_N as follows:

  • If the first character of S_i is one of a, b, c, then C_i= 2
  • If the first character of S_i is one of d, e, f, then C_i= 3
  • If the first character of S_i is one of g, h, i, then C_i= 4
  • If the first character of S_i is one of j, k, l, then C_i= 5
  • If the first character of S_i is one of m, n, o, then C_i= 6
  • If the first character of S_i is one of p, q, r, s, then C_i= 7
  • If the first character of S_i is one of t, u, v, then C_i= 8
  • If the first character of S_i is one of w, x, y, z, then C_i= 9

Output the string obtained by concatenating C_1, C_2, \ldots, C_N in this order.

Constraints

  • 1 \leq N \leq 10
  • N is an integer.
  • S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters.

Input

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

N
S_1 S_2 \ldots S_N

Output

Output the string obtained by concatenating C_1, C_2, \ldots, C_N in this order.


Sample Input 1

2
algorithm heuristic

Sample Output 1

24
  • The first character of S_1= algorithm is a, so C_1= 2.
  • The first character of S_2= heuristic is h, so C_2= 4.

Thus, output 24, which is their concatenation.


Sample Input 2

3
i love you

Sample Output 2

459
E - kasaka

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

配点 : 300

問題文

英小文字からなる文字列 S が与えられます。 S の先頭に a をいくつか( 0 個でも良い)つけ加えて回文にすることができるか判定してください。

ただし、長さ N の文字列 A=A_1A_2\ldots A_N が回文であるとは、すべての 1\leq i\leq N について A_i=A_{N+1-i} が成り立っていることをいいます。

制約

  • 1 \leq \lvert S \rvert \leq 10^6
  • S は英小文字のみからなる。

入力

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

S

出力

S の先頭に a をいくつかつけ加えて回文にすることができるならば Yes を、そうでないならば No を出力せよ。


入力例 1

kasaka

出力例 1

Yes

kasaka の先頭に a1 つ付け加えることによって、akasaka となり回文となるため Yes を出力します。


入力例 2

atcoder

出力例 2

No

atcoder の先頭に a をいくつ付け加えても回文となる事はありません。


入力例 3

php

出力例 3

Yes

php はそれ自体回文です。S の先頭に付け加える a0 個でも許されるため、Yes を出力します。

Score : 300 points

Problem Statement

Given is a string S consisting of lowercase English letters. Determine whether adding some number of a's (possibly zero) at the beginning of S can make it a palindrome.

Here, a string of length N, A=A_1A_2\ldots A_N, is said to be a palindrome when A_i=A_{N+1-i} for every 1\leq i\leq N.

Constraints

  • 1 \leq \lvert S \rvert \leq 10^6
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If adding some number of a's (possibly zero) at the beginning of S can make it a palindrome, print Yes; otherwise, print No.


Sample Input 1

kasaka

Sample Output 1

Yes

By adding one a at the beginning of kasaka, we have akasaka, which is a palindrome, so Yes should be printed.


Sample Input 2

atcoder

Sample Output 2

No

Adding any number of a's at the beginning of atcoder does not make it a palindrome.


Sample Input 3

php

Sample Output 3

Yes

php itself is a palindrome. Adding zero a's at the beginning of S is allowed, so Yes should be printed.