A - 1-2-4 Test

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

3 問の問題からなる試験があり、それぞれの問題の配点は 1 点、2 点、4 点でした。

高橋君、青木君、すぬけ君の 3 人がこの試験を受け、 高橋君は A 点、青木君は B 点を取りました。

すぬけ君は、高橋君と青木君のうち少なくとも一方が解けた問題は解け、 2 人とも解けなかった問題は解けませんでした。

すぬけ君の点数を求めてください。

ただし、この問題の制約下で、すぬけ君の点数は一意に定まる事が証明できます。

制約

  • 0\leq A,B \leq 7
  • A,B は整数

入力

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

A B

出力

すぬけ君の点数を整数で出力せよ。


入力例 1

1 2

出力例 1

3

高橋君は 1 点を取った事から、 1 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。
同様に、青木君は 2 点を取った事から、 2 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。

よって、すぬけ君は 1 点の問題と 2 点の問題を正解し、高橋君と青木君がともに解けなかった 4 点の問題はすぬけ君も解けなかったことになるので、3 点を取ったことがわかります。よって、3 を出力します。


入力例 2

5 3

出力例 2

7

高橋君は 5 点を取った事から、 1 点の問題と 4 点の問題を正解し、 2 点の問題は解けなかったことがわかります。
同様に、青木君は 3 点を取った事から、 1 点の問題と 2 点の問題を正解し、 4 点の問題は解けなかったことがわかります。

よって、3 問すべてについて、高橋君と青木君の少なくとも一方が正解しているため、すぬけ君はすベての問題に正解し、7 点を取ったことがわかります。 よって、7 を出力します。


入力例 3

0 0

出力例 3

0

高橋君と青木君は 2 人ともいずれの問題も解けていません。 よって、すぬけ君もいずれの問題も解けておらず、 0 を出力します。

Score : 100 points

Problem Statement

There was an exam consisting of three problems worth 1, 2, and 4 points.

Takahashi, Aoki, and Snuke took this exam. Takahashi scored A points, and Aoki scored B points.

Snuke solved all of the problems solved by at least one of Takahashi and Aoki, and failed to solve any of the problems solved by neither of them.

Find Snuke's score.

It can be proved that Snuke's score is uniquely determined under the Constraints of this problem.

Constraints

  • 0\leq A,B \leq 7
  • A and B are integers.

Input

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

A B

Output

Print Snuke's score as an integer.


Sample Input 1

1 2

Sample Output 1

3

Since Takahashi scored 1 point, we see that he solved only the 1-point problem and failed to solve the other two.
Similarly, since Aoki scored 2 points, we see that he solved only the 2-point problem and failed to solve the other two.

Therefore, Snuke must have solved the 1- and 2-point problems, but not the 4-point one, which Takahashi and Aoki both failed to solve, for a score of 3 points. Thus, 3 should be printed.


Sample Input 2

5 3

Sample Output 2

7

Since Takahashi scored 5 points, we see that he solved the 1- and 4-point problems but not the 2-point one.
Similarly, since Aoki scored 3 points, we see that he solved the 1- and 2-point problems but not the 4-point one.

Therefore, each of the three problems is solved by at least one of Takahashi and Aoki, so we see that Snuke solved all of the problems, for a score of 7 points. Thus, 7 should be printed.


Sample Input 3

0 0

Sample Output 3

0

Both Takahashi and Aoki solved none of the problems. Therefore, so did Snuke. Thus, 0 should be printed.

B - Probably English

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

英小文字からなる N 個の文字列 W_1,W_2,\dots,W_N が与えられます。
これらのうち一つ以上が and, not, that, the, you のいずれかと一致するなら Yes 、そうでないなら No と出力してください。

制約

  • N は 1 以上 100 以下の整数
  • 1 \le |W_i| \le 50 ( |W_i| は文字列 W_i の長さ )
  • W_i は英小文字からなる

入力

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

N
W_1 W_2 \dots W_N

出力

答えを出力せよ。


入力例 1

10
in that case you should print yes and not no

出力例 1

Yes

例えば W_4= you なので、 Yes と出力します。


入力例 2

10
in diesem fall sollten sie no und nicht yes ausgeben

出力例 2

No

文字列 W_i はいずれも、 and, not, that, the, you のいずれとも一致しません。

Score : 100 points

Problem Statement

You are given N strings W_1,W_2,\dots,W_N consisting of lowercase English letters.
If one or more of these strings equal and, not, that, the, or you, then print Yes; otherwise, print No.

Constraints

  • N is an integer between 1 and 100, inclusive.
  • 1 \le |W_i| \le 50 (|W_i| is the length of W_i.)
  • W_i consists of lowercase English letters.

Input

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

N
W_1 W_2 \dots W_N

Output

Print the answer.


Sample Input 1

10
in that case you should print yes and not no

Sample Output 1

Yes

We have, for instance, W_4= you, so you should print Yes.


Sample Input 2

10
in diesem fall sollten sie no und nicht yes ausgeben

Sample Output 2

No

None of the strings W_i equals any of and, not, that, the, and you.

C - Reverse Proxy

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

1,2,\dots,N の番号が付いた N 個の箱があります。最初は全ての箱が空です。

これから Q 個のボールが順番にやってきます。
高橋君は、数列 X=(X_1,X_2,\dots,X_Q) に従ってボールを箱に入れます。
具体的には、 i 番目にやってきたボールに次の処理を行います。

  • X_i \ge 1 である場合 : このボールを、箱 X_i に入れる。
  • X_i = 0 である場合 : このボールを、現在入っているボールが最も少ない箱のうち番号が最小である箱に入れる。

それぞれのボールをどの箱に入れたかを求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 100
  • 1 \le Q \le 100
  • 0 \le X_i \le N

入力

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

N Q
X_1 X_2 \dots X_Q

出力

i 番目にやってきたボールを箱 B_i に入れたとき、次の形式に従って出力せよ。

B_1 B_2 \dots B_Q

入力例 1

4 5
2 0 3 0 0

出力例 1

2 1 3 4 1

箱が 4 つあり、ボールは 5 個やってきます。

  • 最初、全ての箱は空です。
    • 各箱に入っているボールの数は箱 1 から順に 0,0,0,0 個です。
  • X_1=2 なので、 1 番目にやってきたボールを箱 2 に入れます。
    • 各箱に入っているボールの数は箱 1 から順に 0,1,0,0 個となります。
  • X_2=0 なので、 2 番目にやってきたボールを現在入っているボールが最も少ない箱のうち番号が最小である箱である箱 1 に入れます。
    • 各箱に入っているボールの数は箱 1 から順に 1,1,0,0 個となります。
  • X_3=3 なので、 3 番目にやってきたボールを箱 3 に入れます。
    • 各箱に入っているボールの数は箱 1 から順に 1,1,1,0 個となります。
  • X_4=0 なので、 4 番目にやってきたボールを現在入っているボールが最も少ない箱のうち番号が最小である箱である箱 4 に入れます。
    • 各箱に入っているボールの数は箱 1 から順に 1,1,1,1 個となります。
  • X_5=0 なので、 5 番目にやってきたボールを現在入っているボールが最も少ない箱のうち番号が最小である箱である箱 1 に入れます。
    • 各箱に入っているボールの数は箱 1 から順に 2,1,1,1 個となります。

各ボールを、やってきた順に箱 2,1,3,4,1 に入れました。よって、 2 1 3 4 1 と出力します。


入力例 2

3 7
1 1 0 0 0 0 0

出力例 2

1 1 2 3 2 3 1

入力例 3

6 20
4 6 0 3 4 2 6 5 2 3 0 3 2 5 0 3 5 0 2 0

出力例 3

4 6 1 3 4 2 6 5 2 3 1 3 2 5 1 3 5 4 2 6

Score : 200 points

Problem Statement

There are N boxes numbered 1,2,\dots,N. Initially, all boxes are empty.

Q balls will come in order.
Takahashi will put the balls into the boxes according to the sequence X=(X_1,X_2,\dots,X_Q).
Specifically, he performs the following process for the i-th ball:

  • If X_i \ge 1: Put this ball into box X_i.
  • If X_i = 0: Put this ball into the box with the smallest number among those containing the fewest balls.

Find which box each ball was put into.

Constraints

  • All input values are integers.
  • 1 \le N \le 100
  • 1 \le Q \le 100
  • 0 \le X_i \le N

Input

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

N Q
X_1 X_2 \dots X_Q

Output

If the i-th ball was put into box B_i, output in the following format:

B_1 B_2 \dots B_Q

Sample Input 1

4 5
2 0 3 0 0

Sample Output 1

2 1 3 4 1

There are 4 boxes, and 5 balls come.

  • Initially, all boxes are empty.
    • The numbers of balls in box 1,2,3,4 are 0,0,0,0, respectively.
  • Since X_1=2, put the 1st ball into box 2.
    • The numbers of balls in box 1,2,3,4 are 0,1,0,0, respectively.
  • Since X_2=0, put the 2nd ball into box 1, which has the smallest number among those containing the fewest balls.
    • The numbers of balls in box 1,2,3,4 are 1,1,0,0, respectively.
  • Since X_3=3, put the 3rd ball into box 3.
    • The numbers of balls in box 1,2,3,4 are 1,1,1,0, respectively.
  • Since X_4=0, put the 4th ball into box 4, which has the smallest number among those containing the fewest balls.
    • The numbers of balls in box 1,2,3,4 are 1,1,1,1, respectively.
  • Since X_5=0, put the 5th ball into box 1, which has the smallest number among those containing the fewest balls.
    • The numbers of balls in box 1,2,3,4 are 2,1,1,1, respectively.

The balls were put into boxes 2,1,3,4,1 in order. Thus, output 2 1 3 4 1.


Sample Input 2

3 7
1 1 0 0 0 0 0

Sample Output 2

1 1 2 3 2 3 1

Sample Input 3

6 20
4 6 0 3 4 2 6 5 2 3 0 3 2 5 0 3 5 0 2 0

Sample Output 3

4 6 1 3 4 2 6 5 2 3 1 3 2 5 1 3 5 4 2 6
D - A..B..C

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

文字列 S が与えられます。

S の中に A, B, C がこの順に等間隔に並んでいる場所が何箇所あるか求めてください。

厳密には、3 つの整数の組 (i,j,k) であって、以下の条件をすべて満たすものの個数を求めてください。 ここで、|S| で S の長さを、S_x で S の x 文字目を表すものとします。

  • 1\leq i<j<k\leq |S|
  • j-i = k-j
  • S_i= A
  • S_j= B
  • S_k= C

制約

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

入力

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

S

出力

答えを出力せよ。


入力例 1

AABCC

出力例 1

2

(i,j,k)=(1,3,5),(2,3,4) の 2 つの組が条件を満たします。


入力例 2

ARC

出力例 2

0

入力例 3

AABAAABBAEDCCCD

出力例 3

4

Score : 200 points

Problem Statement

A string S is given.

Find how many places in S have A, B, and C in this order at even intervals.

Specifically, find the number of triples of integers (i,j,k) that satisfy all of the following conditions. Here, |S| denotes the length of S, and S_x denotes the x-th character of S.

  • 1 \leq i < j < k \leq |S|
  • j - i = k - j
  • S_i = A
  • S_j = B
  • S_k = C

Constraints

  • S is an uppercase English string with length between 3 and 100, inclusive.

Input

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

S

Output

Print the answer.


Sample Input 1

AABCC

Sample Output 1

2

There are two triples (i,j,k) = (1,3,5) and (2,3,4) that satisfy the conditions.


Sample Input 2

ARC

Sample Output 2

0

Sample Input 3

AABAAABBAEDCCCD

Sample Output 3

4
E - Coverage

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

1 以上 N 以下の整数からなる集合が M 個あり、順に S_1, S_2, \dots, S_M と呼びます。
S_i は C_i 個の整数 a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i} からなります。

M 個の集合から 1 個以上の集合を選ぶ方法は 2^M-1 通りあります。
このうち、次の条件を満たす選び方は何通りありますか?

  • 1 \leq x \leq N を満たす全ての整数 x に対して、選んだ集合の中に x を含む集合が少なくとも 1 個存在する。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • 入力される値は全て整数

入力

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

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

出力

問題文の条件を満たす集合の選び方の数を出力せよ。


入力例 1

3 3
2
1 2
2
1 3
1
2

出力例 1

3

入力で与えられている集合はそれぞれ S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace です。
問題文の条件を満たす集合の選び方は次の 3 通りです。

  • S_1, S_2 を選ぶ。
  • S_1, S_2, S_3 を選ぶ。
  • S_2, S_3 を選ぶ。

入力例 2

4 2
2
1 2
2
1 3

出力例 2

0

問題文の条件を満たす選び方が存在しない場合もあります。


入力例 3

6 6
3
2 3 6
3
2 4 6
2
3 6
3
1 5 6
3
1 3 6
2
1 4

出力例 3

18

Score : 300 points

Problem Statement

There are M sets, called S_1, S_2, \dots, S_M, consisting of integers between 1 and N.
S_i consists of C_i integers a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}.

There are (2^M-1) ways to choose one or more sets from the M sets.
How many of them satisfy the following condition?

  • For all integers x such that 1 \leq x \leq N, there is at least one chosen set containing x.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • All values in the input are integers.

Input

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

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

Output

Print the number of ways to choose sets that satisfy the conditions in the Problem Statement.


Sample Input 1

3 3
2
1 2
2
1 3
1
2

Sample Output 1

3

The sets given in the input are S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace.
The following three ways satisfy the conditions in the Problem Statement:

  • choosing S_1, S_2;
  • choosing S_1, S_2, S_3;
  • choosing S_2, S_3.

Sample Input 2

4 2
2
1 2
2
1 3

Sample Output 2

0

There may be no way to choose sets that satisfies the conditions in the Problem Statement.


Sample Input 3

6 6
3
2 3 6
3
2 4 6
2
3 6
3
1 5 6
3
1 3 6
2
1 4

Sample Output 3

18