A - Five Integers

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

配点 : 100

問題文

与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。

制約

  • 0 \leq A, B, C, D, E \leq 100
  • 入力はすべて整数

入力

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

A B C D E

出力

答えを出力せよ。


入力例 1

31 9 24 31 24

出力例 1

3

与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。


入力例 2

0 0 0 0 0

出力例 2

1

Score : 100 points

Problem Statement

Print how many distinct integers there are in given five integers A, B, C, D, and E.

Constraints

  • 0 \leq A, B, C, D, E \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D E

Output

Print the answer.


Sample Input 1

31 9 24 31 24

Sample Output 1

3

In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.


Sample Input 2

0 0 0 0 0

Sample Output 2

1
B - 369

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

配点 : 100

問題文

整数 A,B が与えられます。

以下の条件を満たす整数 x が何通りあるか求めてください。

  • 条件:3 つの整数 A,B,x をうまく並べることで、等差数列を作ることができる。

なお、3 つの整数 p,q,r をこの順に並べた列が等差数列であるとは、q-pr-q と一致することをいいます。

制約

  • 1\leq A,B \leq 100
  • 入力は全て整数

入力

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

A B

出力

問題文中の条件を満たす整数 x が何通りあるかを出力せよ。 なお、答えは有限であることが証明できる。


入力例 1

5 7

出力例 1

3

以下のように、x=3,6,9 はいずれも条件を満たします。

  • x=3 のとき、例えば x,A,B と並べることで等差数列 3,5,7 を作ることができます。
  • x=6 のとき、例えば B,x,A と並べることで等差数列 7,6,5 を作ることができます。
  • x=9 のとき、例えば A,B,x と並べることで等差数列 5,7,9 を作ることができます。

逆に、これ以外に条件を満たす x は存在しません。 よって答えは 3 です。


入力例 2

6 1

出力例 2

2

x=-4,11 のみが条件を満たします。


入力例 3

3 3

出力例 3

1

x=3 のみが条件を満たします。

Score : 100 points

Problem Statement

You are given two integers A and B.

How many integers x satisfy the following condition?

  • Condition: It is possible to arrange the three integers A, B, and x in some order to form an arithmetic sequence.

A sequence of three integers p, q, and r in this order is an arithmetic sequence if and only if q-p is equal to r-q.

Constraints

  • 1 \leq A,B \leq 100
  • All input values are integers.

Input

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

A B

Output

Print the number of integers x that satisfy the condition in the problem statement. It can be proved that the answer is finite.


Sample Input 1

5 7

Sample Output 1

3

The integers x=3,6,9 all satisfy the condition as follows:

  • When x=3, for example, arranging x,A,B forms the arithmetic sequence 3,5,7.
  • When x=6, for example, arranging B,x,A forms the arithmetic sequence 7,6,5.
  • When x=9, for example, arranging A,B,x forms the arithmetic sequence 5,7,9.

Conversely, there are no other values of x that satisfy the condition. Therefore, the answer is 3.


Sample Input 2

6 1

Sample Output 2

2

Only x=-4 and 11 satisfy the condition.


Sample Input 3

3 3

Sample Output 3

1

Only x=3 satisfies the condition.

C - Chessboard

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

配点 : 200

問題文

チェス盤のどこにコマが置かれているか答えてください。

8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。

  • 左から 1 列目にあるマスの名前の 1 文字目は a である。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目は b, c, d, e, f, g, h である。
  • 下から 1 行目にあるマスの名前の 2 文字目は 1 である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は 2, 3, 4, 5, 6, 7, 8 である。

例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。

グリッドの状態を表す長さ 88 つの文字列 S_1,\ldots,S_8 が与えられます。
S_ij 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。

制約

  • S_i. および * のみからなる長さ 8 の文字列である
  • S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在する。

入力

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

出力

答えを出力せよ。


入力例 1

........
........
........
........
........
........
........
*.......

出力例 1

a1

問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。


入力例 2

........
........
........
........
........
.*......
........
........

出力例 2

b3

Score : 200 points

Problem Statement

Locate a piece on a chessboard.

We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.

  • The first character of the name of a square in the 1-st column from the left is a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left is b, c, d, e, f, g, h, respectively.
  • The second character of the name of a square in the 1-st row from the bottom is 1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is 2, 3, 4, 5, 6, 7, 8, respectively.

For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.

You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise. The character * occurs exactly once among S_1,\ldots,S_8. Find the name of the square that has a piece on it.

Constraints

  • S_i is a string of length 8 consisting of . and*.
  • The character * occurs exactly once among S_1,\ldots,S_8.

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the answer.


Sample Input 1

........
........
........
........
........
........
........
*.......

Sample Output 1

a1

As explained in the problem statement, the bottom-left square is named a1.


Sample Input 2

........
........
........
........
........
.*......
........
........

Sample Output 2

b3
D - Line Sensor

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

配点 : 200

問題文

H マス、横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスを (i,j) と表します。
各マスの状態は文字 C_{i,j} で表されます。C_{i,j}. ならば (i, j) には何も置かれておらず、 # ならば箱が 1 個置かれています。

1 \leq j \leq W を満たす整数 j に対して、整数 X_j を次のように定義します。

  • j 列目に置かれている箱の個数。言い換えると、C_{i,j}# であるような整数 i の個数。

X_1, X_2, \dots, X_W をすべて求めてください。

制約

  • 1 \leq H \leq 1000
  • 1 \leq W \leq 1000
  • H, W は整数
  • C_{i, j}. または #

入力

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

H W
C_{1,1}C_{1,2}\dots C_{1,W}
C_{2,1}C_{2,2}\dots C_{2,W}
\vdots
C_{H,1}C_{H,2}\dots C_{H,W}

出力

X_1, X_2, \dots, X_W を以下の形式に従って出力せよ。

X_1 X_2 \dots X_W

入力例 1

3 4
#..#
.#.#
.#.#

出力例 1

1 2 0 3

1 列目の箱が置かれているマスは (1, 1)1 ヵ所です。よって X_1 = 1 です。
2 列目の箱が置かれているマスは (2, 2), (3, 2)2 ヵ所です。よって X_2 = 2 です。
3 列目の箱が置かれているマスは存在しません。よって X_3 = 0 です。
4 列目の箱が置かれているマスは (1, 4), (2, 4), (3, 4)3 ヵ所です。よって X_4 = 3 です。
よって (X_1, X_2, X_3, X_4) = (1, 2, 0, 3) が答えとなります。


入力例 2

3 7
.......
.......
.......

出力例 2

0 0 0 0 0 0 0

箱が置かれているマスが存在しない場合もあります。


入力例 3

8 3
.#.
###
.#.
.#.
.##
..#
##.
.##

出力例 3

2 7 4

入力例 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

出力例 4

0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3

Score : 200 points

Problem Statement

There is a grid with H rows from top to bottom and W columns from left to right. Let (i, j) denote the square at the i-th row from the top and j-th column from the left.
The squares are described by characters C_{i,j}. If C_{i,j} is ., (i, j) is empty; if it is #, (i, j) contains a box.

For integers j satisfying 1 \leq j \leq W, let the integer X_j defined as follows.

  • X_j is the number of boxes in the j-th column. In other words, X_j is the number of integers i such that C_{i,j} is #.

Find all of X_1, X_2, \dots, X_W.

Constraints

  • 1 \leq H \leq 1000
  • 1 \leq W \leq 1000
  • H and W are integers.
  • C_{i, j} is . or #.

Input

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

H W
C_{1,1}C_{1,2}\dots C_{1,W}
C_{2,1}C_{2,2}\dots C_{2,W}
\vdots
C_{H,1}C_{H,2}\dots C_{H,W}

Output

Print X_1, X_2, \dots, X_W in the following format:

X_1 X_2 \dots X_W

Sample Input 1

3 4
#..#
.#.#
.#.#

Sample Output 1

1 2 0 3

In the 1-st column, one square, (1, 1), contains a box. Thus, X_1 = 1.
In the 2-nd column, two squares, (2, 2) and (3, 2), contain a box. Thus, X_2 = 2.
In the 3-rd column, no squares contain a box. Thus, X_3 = 0.
In the 4-th column, three squares, (1, 4), (2, 4), and (3, 4), contain a box. Thus, X_4 = 3.
Therefore, the answer is (X_1, X_2, X_3, X_4) = (1, 2, 0, 3).


Sample Input 2

3 7
.......
.......
.......

Sample Output 2

0 0 0 0 0 0 0

There may be no square that contains a box.


Sample Input 3

8 3
.#.
###
.#.
.#.
.##
..#
##.
.##

Sample Output 3

2 7 4

Sample Input 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

Sample Output 4

0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3
E - Airport Code

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

配点 : 300

問題文

英大文字からなる長さ 3 の文字列 T が、英小文字からなる文字列 S空港コード であるとは、 TS から次のいずれかの方法により得られることとします。

  • S の長さ 3 の(連続とは限らない)部分列をとり、それを英大文字に変換したものを T とする
  • S の長さ 2 の(連続とは限らない)部分列をとり、それを英大文字に変換したものの末尾に X を追加したものを T とする

文字列 S, T が与えられるので、 TS の空港コードであるか判定してください。

制約

  • S は英小文字からなる長さ 3 以上 10^5 以下の文字列
  • T は英大文字からなる長さ 3 の文字列

入力

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

S
T

出力

TS の空港コードであるならば Yes を、そうでないならば No を出力せよ。


入力例 1

narita
NRT

出力例 1

Yes

narita の部分列 nrt を英大文字に変換した文字列 NRT は、 narita の空港コードです。


入力例 2

losangeles
LAX

出力例 2

Yes

losangeles の部分列 la を英大文字に変換した文字列 LA の末尾に X を追加したもの LAX は、 losangeles の空港コードです。


入力例 3

snuke
RNG

出力例 3

No

Score: 300 points

Problem Statement

A string T of length 3 consisting of uppercase English letters is an airport code for a string S of lowercase English letters if and only if T can be derived from S by one of the following methods:

  • Take a subsequence of length 3 from S (not necessarily contiguous) and convert it to uppercase letters to form T.
  • Take a subsequence of length 2 from S (not necessarily contiguous), convert it to uppercase letters, and append X to the end to form T.

Given strings S and T, determine if T is an airport code for S.

Constraints

  • S is a string of lowercase English letters with a length between 3 and 10^5, inclusive.
  • T is a string of uppercase English letters with a length of 3.

Input

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

S
T

Output

Print Yes if T is an airport code for S, and No otherwise.


Sample Input 1

narita
NRT

Sample Output 1

Yes

The subsequence nrt of narita, when converted to uppercase, forms the string NRT, which is an airport code for narita.


Sample Input 2

losangeles
LAX

Sample Output 2

Yes

The subsequence la of losangeles, when converted to uppercase and appended with X, forms the string LAX, which is an airport code for losangeles.


Sample Input 3

snuke
RNG

Sample Output 3

No