A - Find Takahashi

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

配点 : 100

問題文

AtCoder 村には N 本の橋があり、i 本目( i1 以上 N 以下の整数)の橋の高さは H_i です。
ここで、AtCoder 村にある N 本の橋のうち、どの相異なる 2 本の橋も高さが異なります。

AtCoder 村で最も高い橋は何本目の橋か出力してください。

制約

  • 1\leq N \leq 100
  • 1\leq H_i \leq 10^9
  • H_i はすべて異なる
  • 入力はすべて整数

入力

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

N
H_1 H_2 \ldots H_N

出力

AtCoder 村で最も高い橋は何本目の橋かを、整数で出力せよ。


入力例 1

3
50 80 70

出力例 1

2

AtCoder 村には 3 本の橋があります。
1,2,3 本目の橋の高さはそれぞれ, 50,80,70 であり、 最も高い橋は 2 本目の橋です。
よって、2 を出力します。


入力例 2

1
1000000000

出力例 2

1

AtCoder 村に橋が 1 本しか存在しないため、2 本目以降の橋は存在せず、最も高い橋は 1 本目の橋となります。


入力例 3

10
22 75 26 45 72 81 47 29 97 2

出力例 3

9

AtCoder 村には 10 本の橋があり、それらのうち最も高い橋は 9 番目の橋(高さは 97 )です。

Score : 100 points

Problem Statement

There are N bridges in AtCoder Village. The height of the bridge numbered i is H_i (i is an integer between 1 and N).
Every two different bridges in the village have different heights.

Print the number representing the highest bridge in the village.

Constraints

  • 1\leq N \leq 100
  • 1\leq H_i \leq 10^9
  • All H_i are different.
  • All values in the input are integers.

Input

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

N
H_1 H_2 \ldots H_N

Output

Print the integer representing the highest bridge in AtCoder village.


Sample Input 1

3
50 80 70

Sample Output 1

2

The village has three bridges.
The first, second, and third bridges have heights of 50, 80, and 70, respectively, so the second bridge is the highest.
Thus, 2 should be printed.


Sample Input 2

1
1000000000

Sample Output 2

1

The village has only one bridge, so the first bridge is the highest.


Sample Input 3

10
22 75 26 45 72 81 47 29 97 2

Sample Output 3

9

The village has ten bridges, and the ninth bridge (with a height of 97) is the highest.

B - 2UP3DOWN

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

配点 : 100

問題文

高橋君が 100 階建てのビルにいます。

高橋君は 2 階分までの上り、または、3 階分までの下りであれば移動には階段を使い、そうでないときエレベーターを使います。

高橋君が X 階から Y 階への移動に使うのは階段ですか?

制約

  • 1 \leq X,Y \leq 100
  • X \neq Y
  • 入力は全ては整数である

入力

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

X Y

出力

移動に使うのが階段ならば Yes、エレベーターならば No を出力せよ。


入力例 1

1 4

出力例 1

No

1 階から 4 階への移動は 3 階分の上りなのでエレベーターを使います。


入力例 2

99 96

出力例 2

Yes

99 階から 96 階への移動は 3 階分の下りなので階段を使います。


入力例 3

100 1

出力例 3

No

Score : 100 points

Problem Statement

Takahashi is in a building with 100 floors.

He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.

Does he use the stairs to move from floor X to floor Y?

Constraints

  • 1 \leq X,Y \leq 100
  • X \neq Y
  • All input values are integers.

Input

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

X Y

Output

If Takahashi uses the stairs for the move, print Yes; if he uses the elevator, print No.


Sample Input 1

1 4

Sample Output 1

No

The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.


Sample Input 2

99 96

Sample Output 2

Yes

The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.


Sample Input 3

100 1

Sample Output 3

No
C - Takahashi's Failure

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

配点 : 200

問題文

高橋君の家には N 個の食品があり、i 番目の食品のおいしさは A_i です。
また、高橋君には嫌いな食品が K 個あり、具体的には i=1,2,\ldots,K について、B_i 番目の食品が嫌いです。

高橋君は N 個の食品のうち、おいしさが最大の食品から 1 つを選んで食べようと考えています。 高橋君が嫌いな食品を食べる可能性があるならば Yes を、食べる可能性が無いならば No を出力してください。

制約

  • 1\leq K\leq N\leq 100
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq N
  • B_i はすべて相異なる
  • 入力はすべて整数

入力

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

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K

出力

高橋君が嫌いな食品を食べる可能性があるならば Yes を、無いならば No を出力せよ。


入力例 1

5 3
6 8 10 7 10
2 3 4

出力例 1

Yes

5 個の食品の中でおいしさが最大の食品は食品 352 つであり、この 2 つのいずれかを食べます。
高橋君が嫌いな食品は 2,3,43 つであり、そのうち食品 3 を食べる可能性があります。
よって、Yes を出力します。


入力例 2

5 2
100 100 100 1 1
5 4

出力例 2

No

おいしさが最大の食品は食品 1,2,33 つであり、高橋君は嫌いな食品を食べる可能性はありません。


入力例 3

2 1
100 1
2

出力例 3

No

おいしさが最大の食品は食品 1 であり、高橋君は嫌いな食品を食べる可能性はありません。

Score : 200 points

Problem Statement

Takahashi has N foods in his house. The i-th food has the tastiness of A_i.
He dislikes K of these foods: for each i=1,2,\ldots,K, he dislikes the B_i-th food.

Out of the foods with the greatest tastiness among the N foods, Takahashi will randomly choose one and eat it.
If he has a chance to eat something he dislikes, print Yes; otherwise, print No.

Constraints

  • 1\leq K\leq N\leq 100
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq N
  • All B_i are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K

Output

If Takahashi has a chance to eat a food he dislikes, print Yes; otherwise, print No.


Sample Input 1

5 3
6 8 10 7 10
2 3 4

Sample Output 1

Yes

Among the five foods, the ones with the greatest tastiness are Food 3 and 5, of which he eats one.
He dislikes Food 2, 3, and 4, one of which he has a chance to eat: Food 3.
Therefore, the answer is Yes.


Sample Input 2

5 2
100 100 100 1 1
5 4

Sample Output 2

No

The foods with the greatest tastiness are Food 1, 2, and 3, none of which he has a chance to eat.


Sample Input 3

2 1
100 1
2

Sample Output 3

No

The food with the greatest tastiness is Food 1, which he has no chance to eat.

D - Caesar Cipher

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

配点 : 200

問題文

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

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

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

ただし、

  • a1 個後ろの英小文字は b であり、
  • b1 個後ろの英小文字は c であり、
  • c1 個後ろの英小文字は d であり、
  • \cdots
  • y1 個後ろの英小文字は z であり、
  • z1 個後ろの英小文字は a です。

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

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

制約

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

入力

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

S
T

出力

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


入力例 1

abc
ijk

出力例 1

Yes

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

  • a8 個後ろの i
  • b8 個後ろの j
  • c8 個後ろの k

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


入力例 2

z
a

出力例 2

Yes

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


入力例 3

ppq
qqp

出力例 3

No

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


入力例 4

atcoder
atcoder

出力例 4

Yes

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

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.

E - Distribution

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

配点 : 300

問題文

N 人のすぬけ君が円周上に並んでおり、反時計回りに 1,2,...,N の番号がついています。

i\, (1 \leq i \leq N) 番目のすぬけ君は時刻 t に宝石をもらうと S_i 単位時間後、すなわち時刻 t+S_i にその宝石を (i+1) 番目のすぬけ君に渡します。ただし、(N+1) 番目のすぬけ君とは 1 番目のすぬけ君のことを指すとします。

また、高橋君は時刻 T_ii 番目のすぬけ君に宝石を渡します。

全ての i\, (1 \leq i \leq N) について、i 番目のすぬけ君が初めて宝石をもらう時刻を求めてください。なお、宝石の受け渡しにかかる時間は無視できるものとします。

制約

  • 1 \leq N \leq 200000
  • 1 \leq S_i,T_i \leq 10^9
  • 入力は全て整数である。

入力

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

N
S_1 S_2 \ldots S_N
T_1 T_2 \ldots T_N

出力

N 行出力せよ。i\, (1 \leq i \leq N) 行目には、i 番目のすぬけ君が初めて宝石をもらう時刻を出力すること。


入力例 1

3
4 1 5
3 10 100

出力例 1

3
7
8

時刻 13 までのすぬけ君と高橋君の行動を時系列順に並べます。

時刻 3 : 高橋君が 1 番目のすぬけ君に宝石を渡します。

時刻 7 : 1 番目のすぬけ君が 2 番目のすぬけ君に宝石を渡します。

時刻 8 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。

時刻 10 : 高橋君が 2 番目のすぬけ君に宝石を渡します。

時刻 11 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。

時刻 13 : 3 番目のすぬけ君が 1 番目のすぬけ君に宝石を渡します。

時刻 14 以降も彼らは宝石の受け渡しを行いますが、答えには影響しません。


入力例 2

4
100 100 100 100
1 1 1 1

出力例 2

1
1
1
1

S_iT_i が相異なるとは限らないことに注意してください。


入力例 3

4
1 2 3 4
1 2 4 7

出力例 3

1
2
4
7

あるすぬけくんが同時刻に複数の宝石の受け渡しをする可能性があること、特に高橋くんとすぬけくんの両方から同時に宝石を貰う可能性があることに注意してください。


入力例 4

8
84 87 78 16 94 36 87 93
50 22 63 28 91 60 64 27

出力例 4

50
22
63
28
44
60
64
27

Score : 300 points

Problem Statement

There are N creatures standing in a circle, called Snuke 1, 2, ..., N in counter-clockwise order.

When Snuke i (1 \leq i \leq N) receives a gem at time t, S_i units of time later, it will hand that gem to Snuke i+1 at time t+S_i. Here, Snuke N+1 is Snuke 1.

Additionally, Takahashi will hand a gem to Snuke i at time T_i.

For each i (1 \leq i \leq N), find the time when Snuke i receives a gem for the first time. Assume that it takes a negligible time to hand a gem.

Constraints

  • 1 \leq N \leq 200000
  • 1 \leq S_i,T_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
S_1 S_2 \ldots S_N
T_1 T_2 \ldots T_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the time when Snuke i receives a gem for the first time.


Sample Input 1

3
4 1 5
3 10 100

Sample Output 1

3
7
8

We will list the three Snuke's and Takahashi's actions up to time 13 in chronological order.

Time 3: Takahashi hands a gem to Snuke 1.

Time 7: Snuke 1 hands a gem to Snuke 2.

Time 8: Snuke 2 hands a gem to Snuke 3.

Time 10: Takahashi hands a gem to Snuke 2.

Time 11: Snuke 2 hands a gem to Snuke 3.

Time 13: Snuke 3 hands a gem to Snuke 1.

After that, they will continue handing gems, though it will be irrelevant to the answer.


Sample Input 2

4
100 100 100 100
1 1 1 1

Sample Output 2

1
1
1
1

Note that the values S_i and T_i may not be distinct.


Sample Input 3

4
1 2 3 4
1 2 4 7

Sample Output 3

1
2
4
7

Note that a Snuke may perform multiple transactions simultaneously. Particularly, a Snuke may receive gems simultaneously from Takahashi and another Snuke.


Sample Input 4

8
84 87 78 16 94 36 87 93
50 22 63 28 91 60 64 27

Sample Output 4

50
22
63
28
44
60
64
27