A - 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
B - aaaadaa

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

配点 : 100 点

問題文

長さ N の英小文字からなる文字列 S と英小文字 c_1,c_2 が与えられます。

S の文字のうち c_1 であるもの 以外 を全て c_2 に置き換えた文字列を求めてください。

制約

  • 1\le N\le 100
  • N は整数
  • c_1,c_2 は英小文字
  • S は英小文字からなる長さ N の文字列

入力

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

N c_1 c_2
S

出力

答えを出力せよ。


入力例 1

3 b g
abc

出力例 1

gbg

S= abc のうち、 b でない a と c を g に置き換えた結果 gbg になります。したがって、 gbg を出力してください。


入力例 2

1 s h
s

出力例 2

s

置き換えた後の文字列が元の文字列と変わらない場合もあります。


入力例 3

7 d a
atcoder

出力例 3

aaaadaa

入力例 4

10 b a
acaabcabba

出力例 4

aaaabaabba

Score : 100 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters, along with lowercase English letters c_1 and c_2.

Find the string obtained by replacing every character of S that is not c_1 with c_2.

Constraints

  • 1\le N\le 100
  • N is an integer.
  • c_1 and c_2 are lowercase English letters.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N c_1 c_2
S

Output

Print the answer.


Sample Input 1

3 b g
abc

Sample Output 1

gbg

Replacing a and c (which are not b) with g in S= abc results in gbg, so print gbg.


Sample Input 2

1 s h
s

Sample Output 2

s

It is possible that the resulting string after replacement is the same as the original string.


Sample Input 3

7 d a
atcoder

Sample Output 3

aaaadaa

Sample Input 4

10 b a
acaabcabba

Sample Output 4

aaaabaabba
C - Product Calculator

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

配点 : 200 点

問題文

高橋君は電卓を持っています。電卓には最初 1 が表示されています。
高橋君は電卓に対して N 回操作を行います。
i 回目 (1\leq i\leq N) の操作では、その時点で画面に表示されている数に正の整数 A_i をかけます。
しかし、電卓には K 桁までしか表示できないため、計算結果が (K+1) 桁以上になる場合、代わりに 1 が画面に表示されます。 そうでない場合は正しく計算結果が表示されます。

N 回の操作の後に電卓に表示されている数を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq K \leq 18
  • 1 \leq A_i < 10^K
  • 入力はすべて整数

入力

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

N K
A_1 A_2 \ldots A_N

出力

N 回の操作の後に電卓に表示されている数を出力せよ。


入力例 1

5 2
7 13 3 2 5

出力例 1

10

今回電卓は 2 桁まで表示することができ、最初 1 が表示されています。これに対して、次のように高橋君は操作を行います。

  • 1 回目の操作で、7 をかけます。1\times 7=7 であり、電卓には 7 が表示されます。
  • 2 回目の操作で、13 をかけます。7\times 13=91 であり、電卓には 91 が表示されます。
  • 3 回目の操作で、3 をかけます。91\times 3=273 であり、3 桁になってしまうため、電卓には 1 が表示されます。
  • 4 回目の操作で、2 をかけます。1\times 2=2 であり、電卓には 2 が表示されます。
  • 5 回目の操作で、5 をかけます。2\times 5=10 であり、電卓には 10 が表示されます。

入力例 2

2 1
2 5

出力例 2

1

Score : 200 points

Problem Statement

Takahashi has a calculator that initially displays 1.
He will perform N operations on the calculator.
In the i-th operation (1 \leq i \leq N), he multiplies the currently displayed number by a positive integer A_i.
However, the calculator can display at most K digits. If the result of the multiplication has (K+1) or more digits, the display shows 1 instead; otherwise, the result is shown correctly.

Find the number showing on the calculator after the N operations.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq K \leq 18
  • 1 \leq A_i < 10^K
  • All input values are integers.

Input

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

N K
A_1 A_2 \ldots A_N

Output

Output the number shown on the calculator after the N operations.


Sample Input 1

5 2
7 13 3 2 5

Sample Output 1

10

This calculator can display at most two digits and initially shows 1. Takahashi operates as follows:

  • The 1st operation multiplies by 7. Since 1 \times 7 = 7, the calculator shows 7.
  • The 2nd operation multiplies by 13. Since 7 \times 13 = 91, the calculator shows 91.
  • The 3rd operation multiplies by 3. Since 91\times 3=273, which has three digits, the calculator shows 1.
  • The 4th operation multiplies by 2. Since 1\times 2=2, the calculator shows 2.
  • The 5th operation multiplies by 5. Since 2\times 5=10, the calculator shows 10.

Sample Input 2

2 1
2 5

Sample Output 2

1
D - Default Price

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

配点 : 200 点

問題文

高橋くんは回転寿司で N 皿の料理を食べました。 i 皿目の色は文字列 C_i で表されます。

また、料理の価格は皿の色と対応し、 i=1,\ldots,M のそれぞれについて、色が文字列 D_i の皿の料理は一皿 P_i 円です。また、D_1,\ldots,D_M のいずれとも異なる色の皿の料理は一皿 P_0 円です。

高橋くんが食べた料理の価格の合計を求めてください。

制約

  • 1\leq N,M\leq 100
  • C_i,D_i は英小文字からなる長さ 1 以上 20 以下の文字列
  • D_1,\ldots,D_M はすべて異なる
  • 1\leq P_i\leq 10000
  • N,M,P_i は整数

入力

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

N M
C_1 \ldots C_N
D_1 \ldots D_M
P_0 P_1 \ldots P_M

出力

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


入力例 1

3 2
red green blue
blue red
800 1600 2800

出力例 1

5200

blue の皿は P_1 = 1600 円、red の皿は P_2 = 2800 円、green の皿は P_0 = 800 円です。

高橋くんが食べた料理の価格の合計は、2800+800+1600=5200 円です。


入力例 2

3 2
code queen atcoder
king queen
10 1 1

出力例 2

21

Score : 200 points

Problem Statement

Takahashi ate N plates of sushi at a sushi restaurant. The color of the i-th plate is represented by a string C_i.

The price of a sushi corresponds to the color of the plate. For each i=1,\ldots,M, the sushi on a plate whose color is represented by a string D_i is worth P_i yen a plate (yen is the currency of Japan). If the color does not coincide with any of D_1,\ldots, and D_M, it is worth P_0 yen a plate.

Find the total amount of the prices of sushi that Takahashi ate.

Constraints

  • 1\leq N,M\leq 100
  • C_i and D_i are strings of length between 1 and 20, inclusive, consisting of lowercase English letters.
  • D_1,\ldots, and D_M are distinct.
  • 1\leq P_i\leq 10000
  • N, M, and P_i are integers.

Input

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

N M
C_1 \ldots C_N
D_1 \ldots D_M
P_0 P_1 \ldots P_M

Output

Print the answer as an integer.


Sample Input 1

3 2
red green blue
blue red
800 1600 2800

Sample Output 1

5200

A blue plate, red plate, and green plate are worth P_1 = 1600, P_2 = 2800, and P_0 = 800 yen, respectively.

The total amount of the prices of the sushi that he ate is 2800+800+1600=5200 yen.


Sample Input 2

3 2
code queen atcoder
king queen
10 1 1

Sample Output 2

21
E - 1D puyopuyo

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

配点 : 300 点

問題文

長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。

あなたは以下の操作を 0 回以上好きな順番で好きな回数行うことができます:

  • A_k=A_{k+1}=A_{k+2}=A_{k+3} を満たす 1 以上 |A|-3 以下の整数 k を選び、A から A_k,A_{k+1},A_{k+2},A_{k+3} を削除する。(より厳密には、 A を (A_1,A_2,\ldots,A_{k-1},A_{k+4},A_{k+5},\ldots,A_N) に置き換える。)

ここで、 |A| は整数列 A の長さを表します。

操作を繰り返した後の最終的な |A| としてあり得る最小値を求めてください。

制約

  • 1\le N\le 2\times 10^5
  • 1\le A_i\le N
  • 入力される値は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

操作を繰り返した後の最終的な |A| としてあり得る最小値を出力せよ。


入力例 1

10
1 1 1 4 4 4 4 1 2 3

出力例 1

2

以下のように 2 回操作することで |A|=2 にすることができます。

  • k=4 を選ぶ。A_4=A_5=A_6=A_7=4 が成り立つためこの選択は正当である。 A=(1,1,1,1,2,3) となる。
  • k=1 を選ぶ。A_1=A_2=A_3=A_4=1 が成り立つためこの選択は正当である。 A=(2,3) となる。

|A| を 2 未満にすることはできないため、 2 を出力してください。


入力例 2

3
2 1 3

出力例 2

3

はじめから操作を行うことができません。


入力例 3

13
1 1 4 4 4 1 1 1 1 4 1 4 1

出力例 3

5

Score : 300 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N.

You can perform the following operation zero or more times in any order:

  • Choose an integer k between 1 and |A|-3, inclusive, such that A_k=A_{k+1}=A_{k+2}=A_{k+3}, and remove A_k,A_{k+1},A_{k+2},A_{k+3} from A. (More formally, replace A with (A_1,A_2,\ldots,A_{k-1},A_{k+4},A_{k+5},\ldots,A_N).)

Here, |A| represents the length of the integer sequence A.

Find the minimum possible value of the final |A| after repeating the operation.

Constraints

  • 1\le N\le 2\times 10^5
  • 1\le A_i\le N
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Output the minimum possible value of the final |A| after repeating the operation.


Sample Input 1

10
1 1 1 4 4 4 4 1 2 3

Sample Output 1

2

You can make |A|=2 with two operations as follows:

  • Choose k=4. This choice is valid since A_4=A_5=A_6=A_7=4 holds. A=(1,1,1,1,2,3) is obtained.
  • Choose k=1. This choice is valid since A_1=A_2=A_3=A_4=1 holds. A=(2,3) is obtained.

It is impossible to make |A| less than 2, so output 2.


Sample Input 2

3
2 1 3

Sample Output 2

3

You cannot perform any operation from the beginning.


Sample Input 3

13
1 1 4 4 4 1 1 1 1 4 1 4 1

Sample Output 3

5