A - 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.
B - Power

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

配点 : 100

問題文

整数 A, B が与えられます。 A^B の値を出力してください。

制約

  • 1 \leq A, B \leq 9
  • 入力はすべて整数

入力

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

A B

出力

答えを出力せよ。


入力例 1

4 3

出力例 1

64

4^3 = 64 であるので、64 を出力します。


入力例 2

5 5

出力例 2

3125

入力例 3

8 1

出力例 3

8

Score : 100 points

Problem Statement

Given integers A and B, print the value A^B.

Constraints

  • 1 \leq A, B \leq 9
  • All values in the input are integers.

Input

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

A B

Output

Print the answer.


Sample Input 1

4 3

Sample Output 1

64

4^3 = 64, so 64 should be printed.


Sample Input 2

5 5

Sample Output 2

3125

Sample Input 3

8 1

Sample Output 3

8
C - Couples

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

配点 : 150

問題文

2N 人の人が横一列に並んでおり、左から i 番目の人は色 A_i の服を着ています。ここで、服の色は 1 から NN 色であり、それぞれの色についてちょうど 2 人の人がその色の服を着ています。

i=1,2,\ldots,N のうち、以下の条件を満たすものは何通りあるか求めてください。

  • i の服を着た二人の人の間にはちょうど一人いる。

制約

  • 2\leq N\leq 100
  • 1\leq A_i \leq N
  • A には 1 以上 N 以下の整数全てがそれぞれ 2 個ずつ含まれる
  • 入力される数値は全て整数

入力

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

N 
A_1 A_2 \ldots A_{2N}

出力

答えを出力せよ。


入力例 1

3
1 2 1 3 2 3

出力例 1

2

条件を満たす i132 個です。

実際、色 1 の服を着ているのは左から 1 番目の人と左から 3 番目の人で、間にちょうど一人います。


入力例 2

2
1 1 2 2

出力例 2

0

条件を満たす i が存在しない場合もあります。


入力例 3

4
4 3 2 3 2 1 4 1

出力例 3

3

Score : 150 points

Problem Statement

There are 2N people standing in a row, and the person at the i-th position from the left is wearing clothes of color A_i. Here, the clothes have N colors from 1 to N, and exactly two people are wearing clothes of each color.

Find how many of the integers i=1,2,\ldots,N satisfy the following condition:

  • There is exactly one person between the two people wearing clothes of color i.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq N
  • Each integer from 1 through N appears exactly twice in A.
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_{2N}

Output

Print the answer.


Sample Input 1

3
1 2 1 3 2 3

Sample Output 1

2

There are two values of i that satisfy the condition: 1 and 3.

In fact, the people wearing clothes of color 1 are at the 1st and 3rd positions from the left, with exactly one person in between.


Sample Input 2

2
1 1 2 2

Sample Output 2

0

There may be no i that satisfies the condition.


Sample Input 3

4
4 3 2 3 2 1 4 1

Sample Output 3

3
D - Find snuke

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

配点 : 250

問題文

H マス \timesW マスのマス目があり、各マスに 1 つずつ英小文字が書き込まれています。 上から i 行目かつ左から j 列目のマスを (i,j) で表します。

マス目に書き込まれている英小文字は H 個の長さ W の文字列 S_1,S_2,\ldots, S_H によって与えられ、 S_ij 文字目が、(i, j) に書き込まれた英小文字を表します。

マス目の中に、s, n, u, k, e この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる 場所がただ 1 つ存在します。
そのような場所を見つけ、そのマスの位置を出力の形式に従って出力してください。

ただし、s, n, u, k, e この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる場所とは、 5 つのマスの組 (A_1,A_2,A_3,A_4,A_5) であって、次をすべてみたすものをさします。

  • A_1,A_2,A_3,A_4,A_5 に書き込まれた英小文字はそれぞれ s, n, u, k, e である。
  • 1\leq i\leq 4 について、A_iA_{i+1} は頂点または辺を共有している。
  • A_1,A_2,A_3,A_4,A_5 の中心はこの順に一直線上に等間隔で並んでいる。

制約

  • 5\leq H\leq 100
  • 5\leq W\leq 100
  • H,W は整数
  • S_i は英小文字のみからなる長さ W の文字列
  • 与えられるマス目の中に条件をみたす場所がただ 1 つ存在する

入力

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

H W
S_1
S_2
\vdots
S_H

出力

次の形式にしたがって、5 行出力せよ。

条件をみたす場所のうち s, n, u, k, e が書かれたマスがそれぞれ (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) であるとき、 i 行目には R_iC_i をこの順に空白区切りで出力せよ。

すなわち、以下のように出力せよ。

R_1 C_1
R_2 C_2
\vdots
R_5 C_5

以下の入力例も参考にせよ。


入力例 1

6 6
vgxgpu
amkxks
zhkbpp
hykink
esnuke
zplvfj

出力例 1

5 2
5 3
5 4
5 5
5 6

この時、(A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) とすると、
それぞれのマスに書き込まれた英小文字は s, n, u, k, e であり、
1\leq i\leq 4 について、A_iA_{i+1} は辺を共有しており、
各マスの中心は一直線上に存在するため、条件をみたしています。


入力例 2

5 5
ezzzz
zkzzz
ezuzs
zzznz
zzzzs

出力例 2

5 5
4 4
3 3
2 2
1 1

(A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) が条件をみたしています。
例えば、(A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) は、1,2 つめの条件をみたしていますが、
マスの中心が一直線上に存在しないため、3 つめの条件をみたしていません。


入力例 3

10 10
kseeusenuk
usesenesnn
kskekeeses
nesnusnkkn
snenuuenke
kukknkeuss
neunnennue
sknuessuku
nksneekknk
neeeuknenk

出力例 3

9 3
8 3
7 3
6 3
5 3

Score : 250 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns. Each cell has a lowercase English letter written on it. We denote by (i, j) the cell at the i-th row from the top and j-th column from the left.

The letters written on the grid are represented by H strings S_1,S_2,\ldots, S_H, each of length W. The j-th letter of S_i represents the letter written on (i, j).

There is a unique set of contiguous cells (going vertically, horizontally, or diagonally) in the grid with s, n, u, k, and e written on them in this order.
Find the positions of such cells and print them in the format specified in the Output section.

A tuple of five cells (A_1,A_2,A_3,A_4,A_5) is said to form a set of contiguous cells (going vertically, horizontally, or diagonally) with s, n, u, k, and e written on them in this order if and only if all of the following conditions are satisfied.

  • A_1,A_2,A_3,A_4 and A_5 have letters s, n, u, k, and e written on them, respectively.
  • For all 1\leq i\leq 4, cells A_i and A_{i+1} share a corner or a side.
  • The centers of A_1,A_2,A_3,A_4, and A_5 are on a common line at regular intervals.

Constraints

  • 5\leq H\leq 100
  • 5\leq W\leq 100
  • H and W are integers.
  • S_i is a string of length W consisting of lowercase English letters.
  • The given grid has a unique conforming set of cells.

Input

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

H W
S_1
S_2
\vdots
S_H

Output

Print five lines in the following format.

Let (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) be the cells in the sought set with s, n, u, k, and e written on them, respectively. The i-th line should contain R_i and C_i in this order, separated by a space.

In other words, print them in the following format:

R_1 C_1
R_2 C_2
\vdots
R_5 C_5

See also Sample Inputs and Outputs below.


Sample Input 1

6 6
vgxgpu
amkxks
zhkbpp
hykink
esnuke
zplvfj

Sample Output 1

5 2
5 3
5 4
5 5
5 6

Tuple (A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) satisfies the conditions.
Indeed, the letters written on them are s, n, u, k, and e;
for all 1\leq i\leq 4, cells A_i and A_{i+1} share a side;
and the centers of the cells are on a common line.


Sample Input 2

5 5
ezzzz
zkzzz
ezuzs
zzznz
zzzzs

Sample Output 2

5 5
4 4
3 3
2 2
1 1

Tuple (A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) satisfies the conditions.
However, for example, (A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) violates the third condition because the centers of the cells are not on a common line, although it satisfies the first and second conditions.


Sample Input 3

10 10
kseeusenuk
usesenesnn
kskekeeses
nesnusnkkn
snenuuenke
kukknkeuss
neunnennue
sknuessuku
nksneekknk
neeeuknenk

Sample Output 3

9 3
8 3
7 3
6 3
5 3
E - FF

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

配点 : 300

問題文

高橋君が運営する SNS「Twidai」にはユーザー 1 からユーザー N までの N 人のユーザーがいます。 Twidai では、ユーザーは別のユーザーをフォローすることや、フォローを解除することができます。

Twidai がサービスを開始してから、Q 回の操作が行われました。 i 回目 (1\leq i\leq Q) の操作は 3 つの整数 T _ i, A _ i, B _ i で表され、それぞれ次のような操作を表します。

  • T _ i=1 のとき:ユーザー A _ i がユーザー B _ i をフォローしたことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしている場合、ユーザーのフォロー状況に変化はない。
  • T _ i=2 のとき:ユーザー A _ i がユーザー B _ i のフォローを解除したことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしていない場合、ユーザーのフォロー状況に変化はない。
  • T _ i=3 のとき:ユーザー A _ i とユーザー B _ i が互いにフォローしているかをチェックすることを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしており、かつユーザー B _ i がユーザー A _ i をフォローしているとき、このチェックに対して Yes と答え、そうでないときこのチェックに対して No と答える必要がある。

サービス開始時には、どのユーザーも他のユーザーをフォローしていません。

すべての T _ i=3 であるような操作に対して、i が小さいほうから順番に正しい答えを出力してください。

制約

  • 2 \leq N \leq 10 ^ 9
  • 1 \leq Q \leq 2\times10 ^ 5
  • T _ i=1,2,3\ (1\leq i\leq Q)
  • 1 \leq A _ i \leq N\ (1\leq i\leq Q)
  • 1 \leq B _ i \leq N\ (1\leq i\leq Q)
  • A _ i\neq B _ i\ (1\leq i\leq Q)
  • T _ i=3 となる i\ (1\leq i\leq Q) が存在する
  • 入力される値はすべて整数

入力

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

N Q
T _ 1 A _ 1 B _ 1
T _ 2 A _ 2 B _ 2
\vdots
T _ Q A _ Q B _ Q

出力

T _ i=3 であるような i\ (1\leq i\leq Q) の個数を X として、X 行出力せよ。 j\ (1\leq j\leq X) 行目には j 番目の T _ i=3 であるような操作に対する答えを出力せよ。


入力例 1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

出力例 1

No
Yes
No
No

Twidai には 3 人のユーザーがいます。 9 回の操作はそれぞれ次のようになっています。

  • ユーザー 1 がユーザー 2 をフォローします。そのほかにフォローしている/されているユーザーはいません。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしていますが、ユーザー 2 はユーザー 1 をフォローしていません。この操作への正しい答えは No です。
  • ユーザー 2 がユーザー 1 をフォローします。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしており、ユーザー 2 はユーザー 1 をフォローしています。この操作への正しい答えは Yes です。
  • ユーザー 2 がユーザー 3 をフォローします。
  • ユーザー 3 がユーザー 2 をフォローします。
  • ユーザー 1 とユーザー 3 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 3 をフォローしておらず、ユーザー 3 もユーザー 1 をフォローしていません。この操作への正しい答えは No です。
  • ユーザー 1 がユーザー 2 のフォローを解除します。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 2 はユーザー 1 をフォローしていますが、ユーザー 1 はユーザー 2 をフォローしていません。この操作への正しい答えは No です。

入力例 2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

出力例 2

Yes
No

同じユーザーに対して何度もフォロー操作をする場合があります。


入力例 3

10 30
3 1 6
3 5 4
1 6 1
3 1 7
3 8 4
1 1 6
2 4 3
1 6 5
1 5 6
1 1 8
1 8 1
2 3 10
1 7 6
3 5 6
1 6 7
3 6 7
1 9 5
3 8 6
3 3 8
2 6 9
1 7 1
3 10 8
2 9 2
1 10 9
2 6 10
2 6 8
3 1 6
3 1 8
2 8 5
1 9 10

出力例 3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes

Score : 300 points

Problem Statement

Takahashi runs an SNS "Twidai," which has N users from user 1 through user N. In Twidai, users can follow or unfollow other users.

Q operations have been performed since Twidai was launched. The i-th (1\leq i\leq Q) operation is represented by three integers T_i, A_i, and B_i, whose meanings are as follows:

  • If T_i = 1: it means that user A_i follows user B_i. If user A_i is already following user B_i at the time of this operation, it does not make any change.
  • If T_i = 2: it means that user A_i unfollows user B_i. If user A_i is not following user B_i at the time of this operation, it does not make any change.
  • If T_i = 3: it means that you are asked to determine if users A_i and B_i are following each other. You need to print Yes if user A_i is following user B_i and user B_i is following user A_i, and No otherwise.

When the service was launched, no users were following any users.

Print the correct answers for all operations such that T_i = 3 in ascending order of i.

Constraints

  • 2 \leq N \leq 10 ^ 9
  • 1 \leq Q \leq 2\times10 ^ 5
  • T _ i=1,2,3\ (1\leq i\leq Q)
  • 1 \leq A _ i \leq N\ (1\leq i\leq Q)
  • 1 \leq B _ i \leq N\ (1\leq i\leq Q)
  • A _ i\neq B _ i\ (1\leq i\leq Q)
  • There exists i\ (1\leq i\leq Q) such that T _ i=3.
  • All values in the input are integers.

Input

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

N Q
T _ 1 A _ 1 B _ 1
T _ 2 A _ 2 B _ 2
\vdots
T _ Q A _ Q B _ Q

Output

Print X lines, where X is the number of i's (1\leq i\leq Q) such that T _ i=3. The j-th (1\leq j\leq X) line should contain the answer to the j-th operation such that T _ i=3.


Sample Input 1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

Sample Output 1

No
Yes
No
No

Twidai has three users. The nine operations are as follows.

  • User 1 follows user 2. No other users are following or followed by any users.
  • Determine if users 1 and 2 are following each other. User 1 is following user 2, but user 2 is not following user 1, so No is the correct answer to this operation.
  • User 2 follows user 1.
  • Determine if users 1 and 2 are following each other. User 1 is following user 2, and user 2 is following user 1, so Yes is the correct answer to this operation.
  • User 2 follows user 3.
  • User 3 follows user 2.
  • Determine if users 1 and 3 are following each other. User 1 is not following user 3, and user 3 is not following user 1, so No is the correct answer to this operation.
  • User 1 unfollows user 2.
  • Determine if users 1 and 2 are following each other. User 2 is following user 1, but user 1 is not following user 2, so No is the correct answer to this operation.

Sample Input 2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

Sample Output 2

Yes
No

A user may follow the same user multiple times.


Sample Input 3

10 30
3 1 6
3 5 4
1 6 1
3 1 7
3 8 4
1 1 6
2 4 3
1 6 5
1 5 6
1 1 8
1 8 1
2 3 10
1 7 6
3 5 6
1 6 7
3 6 7
1 9 5
3 8 6
3 3 8
2 6 9
1 7 1
3 10 8
2 9 2
1 10 9
2 6 10
2 6 8
3 1 6
3 1 8
2 8 5
1 9 10

Sample Output 3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes