A - Happy New Year 2025

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

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

A+B の二乗を出力してください。

制約

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

入力

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

A B

出力

答えを出力せよ。


入力例 1

20 25

出力例 1

2025

(20+25)^2=2025 です。


入力例 2

30 25

出力例 2

3025

入力例 3

45 11

出力例 3

3136

入力例 4

2025 1111

出力例 4

9834496

Score : 100 points

Problem Statement

You are given two positive integers A and B.

Output the square of A + B.

Constraints

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

Input

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

A B

Output

Print the answer.


Sample Input 1

20 25

Sample Output 1

2025

(20+25)^2=2025.


Sample Input 2

30 25

Sample Output 2

3025

Sample Input 3

45 11

Sample Output 3

3136

Sample Input 4

2025 1111

Sample Output 4

9834496
B - Count Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

文字列が N 個与えられます。

i 番目 (1\leq i\leq N) に与えられる文字列 S _ iTakahashiAoki のどちらかと等しいです。

S _ iTakahashi と等しい i がいくつあるか求めてください。

制約

  • 1\leq N\leq 100
  • N は整数
  • S _ iTakahashiAoki のいずれか (1\leq i\leq N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

S _ iTakahashi と等しい i の個数を整数として一行に出力せよ。


入力例 1

3
Aoki
Takahashi
Takahashi

出力例 1

2

S _ 2,S _ 32 つが Takahashi と等しく、S _ 1 はそうではありません。

よって、2 を出力してください。


入力例 2

2
Aoki
Aoki

出力例 2

0

Takahashi と等しい S _ i が存在しないこともあります。


入力例 3

20
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi
Aoki
Aoki
Aoki
Takahashi
Takahashi
Aoki
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

出力例 3

7

Score : 100 points

Problem Statement

You are given N strings.

The i-th string S_i (1 \leq i \leq N) is either Takahashi or Aoki.

How many i are there such that S_i is equal to Takahashi?

Constraints

  • 1 \leq N \leq 100
  • N is an integer.
  • Each S_i is Takahashi or Aoki. (1 \leq i \leq N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the count of i such that S_i is equal to Takahashi as an integer in a single line.


Sample Input 1

3
Aoki
Takahashi
Takahashi

Sample Output 1

2

S_2 and S_3 are equal to Takahashi, while S_1 is not.

Therefore, print 2.


Sample Input 2

2
Aoki
Aoki

Sample Output 2

0

It is possible that no S_i is equal to Takahashi.


Sample Input 3

20
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi
Aoki
Aoki
Aoki
Takahashi
Takahashi
Aoki
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

Sample Output 3

7
C - Count Subgrid

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

NN 列からなるグリッドがあります。グリッドの上から i 行目左から j 列目のマスは、S_{i,j}# のとき黒く、. のとき白く塗られています。

このグリッドから縦 M 行横 M 列の領域を取り出して得られるマスの塗られ方は何種類ありますか?

制約

  • 1\leq M \leq N \leq 10
  • N,M は整数
  • S_{i,j}. または #

入力

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

N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}

出力

答えを出力せよ。


入力例 1

3 2
...
###
#.#

出力例 1

3

与えられたグリッドの状態は下図左のとおりです。
ここから縦 2 行横 2 列の領域を取り出す方法は下図右のとおり 4 通りあり、マスの塗られ方は 3 種類あります。

図


入力例 2

10 3
..#.......
.###......
.#.#......
#####.....
#...#.....
......####
......#..#
......#...
......#..#
......####

出力例 2

36

Score : 250 points

Problem Statement

There is a grid with N rows and N columns. The cell at the i-th row from the top and j-th column from the left is painted black if S_{i,j} is #, and white if it is ..

How many distinct patterns of painted cells can be obtained by extracting a region of M rows and M columns from this grid?

Constraints

  • 1\leq M \leq N \leq 10
  • N and M are integers.
  • S_{i,j} is . or #.

Input

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

N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}

Output

Print the answer.


Sample Input 1

3 2
...
###
#.#

Sample Output 1

3

The state of the given grid is as shown in the left figure below.
There are four ways to extract a region of two rows and two columns from this grid as shown in the right figure below, and there are three distinct patterns of painted cells.

Figure


Sample Input 2

10 3
..#.......
.###......
.#.#......
#####.....
#...#.....
......####
......#..#
......#...
......#..#
......####

Sample Output 2

36
D - String Too Long

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

連長圧縮(ランレングス圧縮)を復元してください。ただし、長すぎる場合には Too Long と出力してください。

N 個の文字と整数の組 (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N) が与えられます。

l_1 個の文字 c_1l_2 個の文字 c_2\ldotsl_N 個の文字 c_N をこの順に連結させた文字列を S とします。

S を出力してください。ただし、S の長さが 100 を超える場合には代わりに Too Long と出力してください。

制約

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N,l_i は整数
  • c_i は英小文字
  • c_i\neq c_{i+1}

入力

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

出力

S の長さが 100 以下なら S を、そうでないなら Too Long と出力せよ。


入力例 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

出力例 1

mississippi

Smississippi です。S の長さは 100 以下であるため S を出力します。


入力例 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

出力例 2

Too Long

S の長さは 7\times 10^{18} であるため、Too Long を出力します。


入力例 3

1
a 100

出力例 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

入力例 4

6
g 4
j 1
m 4
e 4
d 3
i 4

出力例 4

ggggjmmmmeeeedddiiii

Score : 200 points

Problem Statement

Restore run-length encoding. If the result is too long, output Too Long.

You are given N pairs of characters and integers (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N).

Let S be the string formed by concatenating l_1 characters c_1, l_2 characters c_2, \ldots, and l_N characters c_N in this order.

Output S. However, if the length of S exceeds 100, output Too Long instead.

Constraints

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N and l_i are integers.
  • Each c_i is a lowercase English letter.
  • c_i\neq c_{i+1}

Input

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

Output

If the length of S is at most 100, output S; otherwise, output Too Long.


Sample Input 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

Sample Output 1

mississippi

S is mississippi. Since the length of S is not greater than 100, output S.


Sample Input 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

Sample Output 2

Too Long

The length of S is 7\times 10^{18}, so output Too Long.


Sample Input 3

1
a 100

Sample Output 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Input 4

6
g 4
j 1
m 4
e 4
d 3
i 4

Sample Output 4

ggggjmmmmeeeedddiiii
E - Submask

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

非負整数 N が与えられるので、以下の条件を満たす非負整数 x を昇順に全て出力してください。

  • x2 進数として表記した時に 1 となる位の集合が、 N2 進数として表記した時に 1 となる位の集合の部分集合となる。
    • すなわち、全ての非負整数 k について、「 x2^k の位が 1 ならば、 N2^k の位は 1 」が成り立つ。

制約

  • N は整数
  • 0 \le N < 2^{60}
  • N2 進数として表記した時、 1 となる位は 15 個以下である

入力

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

N

出力

答えを 1 行に 1 つずつ、10 進法の整数として昇順に出力せよ。


入力例 1

11

出力例 1

0
1
2
3
8
9
10
11

N = 11_{(10)}2 進数で表記すると、 1011_{(2)} となります。
条件を満たす非負整数 x は以下の通りです。

  • 0000_{(2)}=0_{(10)}
  • 0001_{(2)}=1_{(10)}
  • 0010_{(2)}=2_{(10)}
  • 0011_{(2)}=3_{(10)}
  • 1000_{(2)}=8_{(10)}
  • 1001_{(2)}=9_{(10)}
  • 1010_{(2)}=10_{(10)}
  • 1011_{(2)}=11_{(10)}

入力例 2

0

出力例 2

0

入力例 3

576461302059761664

出力例 3

0
524288
549755813888
549756338176
576460752303423488
576460752303947776
576461302059237376
576461302059761664

入力は 32bit 符号付き整数に収まらない可能性があります。

Score : 300 points

Problem Statement

You are given a non-negative integer N. Print all non-negative integers x that satisfy the following condition in ascending order.

  • The set of the digit positions containing 1 in the binary representation of x is a subset of the set of the digit positions containing 1 in the binary representation of N.
    • That is, the following holds for every non-negative integer k: if the digit in the "2^ks" place of x is 1, the digit in the 2^ks place of N is 1.

Constraints

  • N is an integer.
  • 0 \le N < 2^{60}
  • In the binary representation of N, at most 15 digit positions contain 1.

Input

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

N

Output

Print the answer as decimal integers in ascending order, each in its own line.


Sample Input 1

11

Sample Output 1

0
1
2
3
8
9
10
11

The binary representation of N = 11_{(10)} is 1011_{(2)}.
The non-negative integers x that satisfy the condition are:

  • 0000_{(2)}=0_{(10)}
  • 0001_{(2)}=1_{(10)}
  • 0010_{(2)}=2_{(10)}
  • 0011_{(2)}=3_{(10)}
  • 1000_{(2)}=8_{(10)}
  • 1001_{(2)}=9_{(10)}
  • 1010_{(2)}=10_{(10)}
  • 1011_{(2)}=11_{(10)}

Sample Input 2

0

Sample Output 2

0

Sample Input 3

576461302059761664

Sample Output 3

0
524288
549755813888
549756338176
576460752303423488
576460752303947776
576461302059237376
576461302059761664

The input may not fit into a 32-bit signed integer.