A - CBC

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

英大文字と英小文字からなる文字列 S が与えられます。S の英大文字のみを元の順序で連結して得られる文字列を出力してください。

制約

  • S は英大文字と英小文字からなる文字列である
  • S の長さは 1 以上 100 以下である

入力

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

S

出力

S の英大文字のみを元の順序で連結して得られる文字列を出力せよ。


入力例 1

AtCoderBeginnerContest

出力例 1

ACBC

S の英大文字のみを元の順序で連結して得られる文字列は ACBC です。よって、ACBC を出力します。


入力例 2

PaymentRequired

出力例 2

PR

入力例 3

program

出力例 3



S に英大文字が含まれないことがあることに注意してください。

Score : 100 points

Problem Statement

You are given a string S consisting of uppercase and lowercase English letters. Print the string obtained by concatenating only the uppercase letters of S in their original order.

Constraints

  • S is a string of uppercase and lowercase English letters.
  • The length of S is between 1 and 100, inclusive.

Input

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

S

Output

Print the string obtained by concatenating only the uppercase letters of S in their original order.


Sample Input 1

AtCoderBeginnerContest

Sample Output 1

ACBC

The string obtained by concatenating only the uppercase letters of S in their original order is ACBC. Hence, print ACBC.


Sample Input 2

PaymentRequired

Sample Output 2

PR

Sample Input 3

program

Sample Output 3



Note that S may contain no uppercase letters.

B - Growth Record

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

高橋君は N 歳の誕生日を迎えました。この時の彼の身長は T cmです。
また、以下のことが分かっています。

  • 高橋君は 0 歳の誕生日(生まれた当日)から X 歳の誕生日までの間、毎年身長が D cmずつ伸びた。より厳密に書くと、i=1,2,\ldots,X それぞれに対し、i-1 歳の誕生日から i 歳の誕生日までの間に身長が D cm伸びた。
  • 高橋君は X 歳の誕生日から N 歳の誕生日までの間、身長が変化していない。

高橋君の M 歳の誕生日の時の身長が何cmだったかを求めてください。

制約

  • 0 \leq M \lt N \leq 100
  • 1 \leq X \leq N
  • 1 \leq T \leq 200
  • 1 \leq D \leq 100
  • 高橋君の 0 歳の誕生日の時の身長は 1 cm以上である
  • 入力はすべて整数

入力

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

N M X T D

出力

答えを整数として出力せよ。


入力例 1

38 20 17 168 3

出力例 1

168

この例では、高橋君の 38 歳の誕生日の時の身長が 168 cmです。また、17 歳の誕生日から 38 歳の誕生日までの間、身長が変化していません。
このことから、20 歳の誕生日の時の身長は 168 cmだったと言え、これが答えになります。


入力例 2

1 0 1 3 2

出力例 2

1

この例において、高橋君は 0(=M) 歳の誕生日の時の身長が 1 cmで、1(=N) 歳の誕生日の時の身長が 3(=T) cmです。


入力例 3

100 10 100 180 1

出力例 3

90

Score : 100 points

Problem Statement

Takahashi had his N-th birthday, when he was T centimeters tall.
Additionally, we know the following facts:

  • In each year between Takahashi's birth (0-th birthday) and his X-th birthday, his height increased by D centimeters. More formally, for each i = 1, 2, \ldots, X, his height increased by D centimeters between his (i-1)-th birthday and his i-th birthday.
  • Between Takahashi's X-th birthday and his N-th birthday, his height did not change.

Find Takahashi's height on his M-th birthday, in centimeters.

Constraints

  • 0 \leq M \lt N \leq 100
  • 1 \leq X \leq N
  • 1 \leq T \leq 200
  • 1 \leq D \leq 100
  • Takahashi was at least 1 centimeter tall at his birth.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M X T D

Output

Print the answer as an integer.


Sample Input 1

38 20 17 168 3

Sample Output 1

168

In this sample, Takahashi was 168 centimeters tall on his 38-th birthday. Also, his height did not change between his 17-th birthday and 38-th birthday.
From these facts, we find that he was 168 centimeters tall on his 20-th birthday, so the answer is 168.


Sample Input 2

1 0 1 3 2

Sample Output 2

1

In this sample, Takahashi was 1 centimeter tall on his 0(=M)-th birthday and 3(=T) centimeters tall on his 1(=N)-st birthday.


Sample Input 3

100 10 100 180 1

Sample Output 3

90
C - Draw Frame

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

縦 H 行、横 W 列 のマス目があります。 高橋くんは、このマス目のそれぞれのマスを白か黒で塗ろうとしています。

高橋くんは、マス目に含まれるマスのうち端にあるマスをすべて黒く塗り、それ以外のマスを白く塗ります。 高橋くんが色を塗ったあとのマス目を出力してください。

より厳密には

H\times W のマス目があります。

上から i 行目 (1\le i\le H) 、左から j 列目 (1\le j\le W) のマスをマス (i,j) と呼ぶことにします。

マス (i,j)\ (1\le i\le H,1\le j\le W) とマス (k,l)\ (1\le k\le H,1\le l\le W) が |i-k|+|j-l|=1 を満たすとき、かつそのときに限りこれらのマスは辺で隣接していると言います。

マス (i,j) と辺で隣接しているマスが 3 個以下のとき、かつそのときに限りマス (i,j) は端にあると言います。

次の条件を満たす H 個の文字列 S _ 1,S _ 2,\ldots,S _ H を求めてください。

  • S _ i は長さ W の文字列であり、S _ i の j 文字目は、マス (i,j) が端にあるとき # 、そうでないとき . である。

制約

  • 3\le H\le10
  • 3\le W\le10
  • 入力はすべて整数

入力

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

H W

出力

H 行にわたって、長さ W の文字列を出力せよ。 i 行目 (1\le i\le H) の j 文字目 (1\le j\le W) には、マス (i,j) が黒く塗られているなら # 、白く塗られているなら . を出力せよ。


入力例 1

4 5

出力例 1

#####
#...#
#...#
#####

例えば、マス (1,1) は端にあります。 マス (1,1) と辺で隣接しているマスはマス (1,2) とマス (2,1) の 2 個のみだからです。 よって、マス (1,1) は黒く塗られるので、1 行目の 1 文字目には # を出力してください。

逆に、例えばマス (3,4) は端にありません。 マス (3,4) と辺で隣接しているマスはマス (2,4), マス (3,3), マス (3,5), マス (4,4) の 4 個だからです。 よって、マス (3,4) は白く塗られるので、3 行目の 4 文字目には . を出力してください。


入力例 2

5 6

出力例 2

######
#....#
#....#
#....#
######

Score : 200 points

Problem Statement

There is a grid with H rows and W columns. Takahashi is going to paint each cell of this grid black or white.

He paints all cells on the border of the grid black, and all other cells white. Output the grid after he has painted it.

More formally

There is an H\times W grid.

We call the cell at the i-th row from the top (1\le i\le H) and the j-th column from the left (1\le j\le W) cell (i,j).

Cell (i,j)\ (1\le i\le H,1\le j\le W) and cell (k,l)\ (1\le k\le H,1\le l\le W) are said to be edge-adjacent if and only if |i-k|+|j-l|=1.

Cell (i,j) is said to be on the border if and only if the number of cells edge-adjacent to cell (i,j) is at most 3.

Find H strings S _ 1,S _ 2,\ldots,S _ H satisfying the following condition.

  • S _ i is a string of length W, and the j-th character of S _ i is # if cell (i,j) is on the border, and . otherwise.

Constraints

  • 3\le H\le10
  • 3\le W\le10
  • All input values are integers.

Input

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

H W

Output

Output H lines, each a string of length W. The j-th character (1\le j\le W) of the i-th line (1\le i\le H) should be # if cell (i,j) is painted black, and . if it is painted white.


Sample Input 1

4 5

Sample Output 1

#####
#...#
#...#
#####

For example, cell (1,1) is on the border. This is because there are only two cells edge-adjacent to cell (1,1): cells (1,2) and (2,1). Thus, cell (1,1) is painted black, so the first character of the first line should be #.

Conversely, for example, cell (3,4) is not on the border. This is because there are four cells edge-adjacent to cell (3,4): cells (2,4), (3,3), (3,5), and (4,4). Thus, cell (3,4) is painted white, so the fourth character of the third line should be ..


Sample Input 2

5 6

Sample Output 2

######
#....#
#....#
#....#
######
D - 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.

E - Martial artist

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は武術家です。 武術家の覚えられる技は N 個あり、技 1, 2, \ldots, N と名前がついています。 1 \leq i \leq N について、技 i を習得するには時間 T_i の修練が必要で、 さらに、修練の開始時点で技 A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} をすでに習得している必要があります。 ここで、1 \leq j \leq K_i について、A_{i,j} < i であることが保証されます。

高橋君は時刻 0 の時点で技を 1 つも覚えていません。 高橋君は同時に 1 つの技に対する修練しかできず、また、一度始めた修練を途中でやめることもできません。 高橋君が技 N を習得するのに必要な時間の最小値を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} はすべて異なる。
  • 入力は全て整数である。

入力

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

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

出力

技 N を習得するのに必要な時間の最小値を出力せよ。


入力例 1

3
3 0
5 1 1
7 1 1

出力例 1

10

例えば高橋君は次のように行動することができます。

  • 高橋君は時刻 0 に技 1 の修練を開始し、時刻 3 に技 1 を習得します。
  • その後、時刻 3 に技 3 の修練を開始し、時刻 10 に技 3 を習得します。

このときが最短で、高橋君が技 3 を習得するのに必要な時間は 3+7=10 となります。 技 3 の習得のためには、技 2 を習得する必要はありません。


入力例 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

出力例 2

5000000000

答えが 32 bit 整数に収まらないことがある事に注意してください。

Score : 300 points

Problem Statement

Takahashi is a martial artist. There are N moves that a martial artist can learn, called Move 1, 2, \ldots, N. For each 1 \leq i \leq N, it takes T_i minutes of practice to learn Move i. Additionally, at the beginning of that practice, all of the Moves A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} must be already learned. Here, it is guaranteed that A_{i,j} < i for each 1 \leq j \leq K_i.

Takahashi has not learned any move at time 0. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move N.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} are all distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

Output

Print the minimum number of minutes needed for Takahashi to learn Move N.


Sample Input 1

3
3 0
5 1 1
7 1 1

Sample Output 1

10

Here is one possible plan for Takahashi.

  • At time 0, start practicing for Move 1 to learn Move 1 at time 3.
  • Then, at time 3, start practicing for Move 3 to learn Move 3 at time 10.

Here, Takahashi spends 3+7=10 minutes to learn Move 3, which is the fastest possible. Note that he does not need to learn Move 2 to learn Move 3.


Sample Input 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

Sample Output 2

5000000000

Note that the answer may not fit into a 32-bit integer.