A - Status Code

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

100 以上 999 以下の整数 S が与えられます。

S が 200 以上 299 以下のとき Success 、そうでないとき Failure と出力してください。

制約

  • 100\leq S\leq999
  • S は整数

入力

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

S

出力

答えを出力せよ。


入力例 1

200

出力例 1

Success

200 は 200 以上 299 以下なので、Success と出力してください。


入力例 2

401

出力例 2

Failure

401 は 200 以上 299 以下ではないので、Failure と出力してください。


入力例 3

999

出力例 3

Failure

Score : 100 points

Problem Statement

You are given an integer S between 100 and 999 (inclusive).

If S is between 200 and 299 (inclusive), print Success; otherwise, print Failure.

Constraints

  • 100 \le S \le 999
  • S is an integer.

Input

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

S

Output

Print the answer.


Sample Input 1

200

Sample Output 1

Success

200 is between 200 and 299, so print Success.


Sample Input 2

401

Sample Output 2

Failure

401 is not between 200 and 299, so print Failure.


Sample Input 3

999

Sample Output 3

Failure
B - ^{-1}

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

(1,2,…,N) を並び替えた数列 P と整数 X が与えられます。 数列 P の i 番目の項の値は P_i です。 P_k = X を満たす k を出力してください。

制約

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • P は (1,2,…,N) を並び替えてできる数列
  • 入力はすべて整数

入力

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

N X
P_1 P_2 \ldots P_N

出力

答えを出力せよ。


入力例 1

4 3
2 3 1 4

出力例 1

2

P = (2,3,1,4) なので、P_2 = 3 です。したがって、2 を出力します。


入力例 2

5 2
3 5 1 4 2

出力例 2

5

入力例 3

6 6
1 2 3 4 5 6

出力例 3

6

Score : 100 points

Problem Statement

You are given a sequence P that is a permutation of (1,2,…,N), and an integer X. The i-th term of P has a value of P_i. Print k such that P_k = X.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • P is a permutation of (1,2,…,N).
  • All values in the input are integers.

Input

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

N X
P_1 P_2 \ldots P_N

Output

Print the answer.


Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

We have P = (2,3,1,4), so P_2 = 3. Thus, you should print 2.


Sample Input 2

5 2
3 5 1 4 2

Sample Output 2

5

Sample Input 3

6 6
1 2 3 4 5 6

Sample Output 3

6
C - Caesar Cipher

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

高橋君は英小文字からなる文字列 S を持っています。

高橋君は文字列 S に対して、下記の操作をちょうど 1 回行います。

  • まず、非負整数 K を選ぶ。
  • その後、S の各文字を K 個後ろの英小文字に変更する。

ただし、

  • a の 1 個後ろの英小文字は b であり、
  • b の 1 個後ろの英小文字は c であり、
  • c の 1 個後ろの英小文字は d であり、
  • \cdots
  • y の 1 個後ろの英小文字は z であり、
  • z の 1 個後ろの英小文字は a です。

例えば、b の 4 個後ろの英小文字は f であり、y の 3 個後ろの英小文字は b です。

文字列 T が与えられます。 高橋君が上記の操作によって S を T に一致させることができるかを判定してください。

制約

  • S と T はそれぞれ英小文字からなる長さ 1 以上 10^5 以下の文字列
  • S の長さと T の長さは等しい

入力

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

S
T

出力

高橋君が S を T に一致させることができる場合は Yes と出力し、 できない場合は No と出力せよ。


入力例 1

abc
ijk

出力例 1

Yes

高橋君が K=8 を選ぶと、

  • a は 8 個後ろの i に
  • b は 8 個後ろの j に
  • c は 8 個後ろの k に

それぞれ変更され、S と T が一致します。
高橋君が S を T に一致させることができるため Yes と出力します。


入力例 2

z
a

出力例 2

Yes

高橋君が K=1 を選ぶと S と T が一致します。
z の 1 個後ろの英小文字は a であることに注意してください。


入力例 3

ppq
qqp

出力例 3

No

高橋君は非負整数 K をどのように選んでも S を T に一致させることができません。 よって、No と出力します。


入力例 4

atcoder
atcoder

出力例 4

Yes

高橋君が K=0 を選ぶと S と T が一致します。

Score : 200 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

On this string, he will do the operation below just once.

  • First, choose a non-negative integer K.
  • Then, shift each character of S to the right by K (see below).

Here,

  • a shifted to the right by 1 is b;
  • b shifted to the right by 1 is c;
  • c shifted to the right by 1 is d;
  • \cdots
  • y shifted to the right by 1 is z;
  • z shifted to the right by 1 is a.

For example, b shifted to the right by 4 is f, and y shifted to the right by 3 is b.

You are given a string T. Determine whether Takahashi can make S equal T by the operation above.

Constraints

  • Each of S and T is a string of length between 1 and 10^5 (inclusive) consisting of lowercase English letters.
  • The lengths of S and T are equal.

Input

Input is given from Standard Input in the following format:

S
T

Output

If Takahashi can make S equal T, print Yes; if not, print No.


Sample Input 1

abc
ijk

Sample Output 1

Yes

When Takahashi chooses K=8,

  • a is shifted to the right by 8 and becomes i,
  • b is shifted to the right by 8 and becomes j,
  • c is shifted to the right by 8 and becomes k,

and now S and T are equal.
Therefore, he can make S equal T, so Yes should be printed.


Sample Input 2

z
a

Sample Output 2

Yes

Choosing K=1 makes S and T equal.
Note that the letter on the right of z is a.


Sample Input 3

ppq
qqp

Sample Output 3

No

There is no non-negative integer K that he can choose to make S equal T, so No should be printed.


Sample Input 4

atcoder
atcoder

Sample Output 4

Yes

Choosing K=0 makes S and T equal.

D - Tournament Result

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

N 人の人が総当り戦の試合をしました。

N 行 N 列からなる試合の結果の表 A が与えられます。A の i 行目 j 列目の要素を A_{i,j} と表します。
A_{i,j} は i=j のとき - であり、それ以外のとき W, L, D のいずれかです。
A_{i,j} が W, L, D であることは、人 i が人 j との試合に勝った、負けた、引き分けたことをそれぞれ表します。

与えられた表に矛盾があるかどうかを判定してください。

次のいずれかが成り立つとき、与えられた表には矛盾があるといいます。

  • ある組 (i,j) が存在して、人 i が人 j に勝ったが、人 j が人 i に負けていない
  • ある組 (i,j) が存在して、人 i が人 j に負けたが、人 j が人 i に勝っていない
  • ある組 (i,j) が存在して、人 i が人 j に引き分けたが、人 j が人 i に引き分けていない

制約

  • 2 \leq N \leq 1000
  • A_{i,i} は - である
  • i\neq j のとき、A_{i,j} は W, L, D のいずれかである

入力

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

N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}

出力

与えられた表に矛盾がないとき correct、矛盾があるとき incorrect と出力せよ。


入力例 1

4
-WWW
L-DD
LD-W
LDW-

出力例 1

incorrect

人 3 が人 4 に勝ったにもかかわらず、人 4 も人 3 に勝ったことになっており、矛盾しています。


入力例 2

2
-D
D-

出力例 2

correct

矛盾はありません。

Score : 200 points

Problem Statement

N players played a round-robin tournament.

You are given an N-by-N table A containing the results of the matches. Let A_{i,j} denote the element at the i-th row and j-th column of A.
A_{i,j} is - if i=j, and W, L, or D otherwise.
A_{i,j} is W if Player i beat Player j, L if Player i lost to Player j, and D if Player i drew with Player j.

Determine whether the given table is contradictory.

The table is said to be contradictory when some of the following holds:

  • There is a pair (i,j) such that Player i beat Player j, but Player j did not lose to Player i;
  • There is a pair (i,j) such that Player i lost to Player j, but Player j did not beat Player i;
  • There is a pair (i,j) such that Player i drew with Player j, but Player j did not draw with Player i.

Constraints

  • 2 \leq N \leq 1000
  • A_{i,i} is -.
  • A_{i,j} is W, L, or D, for i\neq j.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}

Output

If the given table is not contradictory, print correct; if it is contradictory, print incorrect.


Sample Input 1

4
-WWW
L-DD
LD-W
LDW-

Sample Output 1

incorrect

Player 3 beat Player 4, while Player 4 also beat Player 3, which is contradictory.


Sample Input 2

2
-D
D-

Sample Output 2

correct

There is no contradiction.

E - 11/22 Substring

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

この問題における 11/22 文字列の定義は A 問題および E 問題と同じです。

文字列 T が以下の条件を全て満たすとき、T を 11/22 文字列 と呼びます。

  • |T| は奇数である。ここで、|T| は T の長さを表す。
  • 1 文字目から \frac{|T|+1}{2} - 1 文字目までが 1 である。
  • \frac{|T|+1}{2} 文字目が / である。
  • \frac{|T|+1}{2} + 1 文字目から |T| 文字目までが 2 である。

例えば 11/22, 111/222, / は 11/22 文字列ですが、1122, 1/22, 11/2222, 22/11, //2/2/211 はそうではありません。

1, 2, / からなる長さ N の文字列 S が与えられます。S は / を 1 個以上含みます。
11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • S は 1, 2, / からなる長さ N の文字列
  • S は / を 1 個以上含む

入力

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

N
S

出力

11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を出力せよ。


入力例 1

8
211/2212

出力例 1

5

S の 2 文字目から 6 文字目からなる部分文字列は 11/22 で、これは 11/22 文字列です。S の部分文字列のうち 11/22 文字列であるものはこれが最長です。よって 5 が答えです。


入力例 2

5
22/11

出力例 2

1

入力例 3

22
/1211/2///2111/2222/11

出力例 3

7

Score : 300 points

Problem Statement

The definition of an 11/22 string in this problem is the same as in Problems A and E.

A string T is called an 11/22 string when it satisfies all of the following conditions:

  • |T| is odd. Here, |T| denotes the length of T.
  • The 1-st through (\frac{|T|+1}{2} - 1)-th characters are all 1.
  • The (\frac{|T|+1}{2})-th character is /.
  • The (\frac{|T|+1}{2} + 1)-th through |T|-th characters are all 2.

For example, 11/22, 111/222, and / are 11/22 strings, but 1122, 1/22, 11/2222, 22/11, and //2/2/211 are not.

You are given a string S of length N consisting of 1, 2, and /, where S contains at least one /.
Find the maximum length of a (contiguous) substring of S that is an 11/22 string.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • S is a string of length N consisting of 1, 2, and /.
  • S contains at least one /.

Input

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

N
S

Output

Print the maximum length of a (contiguous) substring of S that is an 11/22 string.


Sample Input 1

8
211/2212

Sample Output 1

5

The substring from the 2-nd to 6-th character of S is 11/22, which is an 11/22 string. Among all substrings of S that are 11/22 strings, this is the longest. Therefore, the answer is 5.


Sample Input 2

5
22/11

Sample Output 2

1

Sample Input 3

22
/1211/2///2111/2222/11

Sample Output 3

7