A - Echo

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

長さ N の英小文字からなる文字列 S が与えられます。
S の i 文字目を S_i と記します。
S_1,S_1,S_2,S_2,\dots,S_N,S_N をこの順に連結した長さ 2N の文字列を出力してください。
例えば、 S が beginner のときは bbeeggiinnnneerr と出力してください。

制約

  • N は 1 \le N \le 50 を満たす整数
  • S は長さ N の英小文字からなる文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

8
beginner

出力例 1

bbeeggiinnnneerr

問題文中の例と同じです。


入力例 2

3
aaa

出力例 2

aaaaaa

Score : 100 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We denote the i-th character of S by S_i.
Print the string of length 2N obtained by concatenating S_1,S_1,S_2,S_2,\dots,S_N, and S_N in this order.
For example, if S is beginner, print bbeeggiinnnneerr.

Constraints

  • N is an integer such that 1 \le N \le 50.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N
S

Output

Print the answer.


Sample Input 1

8
beginner

Sample Output 1

bbeeggiinnnneerr

It is the same as the example described in the problem statement.


Sample Input 2

3
aaa

Sample Output 2

aaaaaa
B - Signed Difficulty

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

実数 X.Y が与えられます。ただし Y はちょうど 1 桁です。

  • 0 \leq Y \leq 2 ならば、X-
  • 3 \leq Y \leq 6 ならば、X
  • 7 \leq Y \leq 9 ならば、X+

と出力してください。

制約

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • X と Y は整数

入力

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

X.Y

出力

答えを出力せよ。


入力例 1

15.8

出力例 1

15+

15 + のような出力は不正解とみなされます。
X と + の間や、X と - の間には空白を入れずに出力してください。


入力例 2

1.0

出力例 2

1-

1.00 や 1 などの値が入力として与えられることはありません。


入力例 3

12.5

出力例 3

12

Score : 100 points

Problem Statement

You are given a real number X.Y, where Y is a single digit.

Print the following: (quotes for clarity)

  • X-, if 0 \leq Y \leq 2;
  • X, if 3 \leq Y \leq 6;
  • X+, if 7 \leq Y \leq 9.

Constraints

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • X and Y are integers.

Input

Input is given from Standard Input in the following format:

X.Y

Output

Print the answer.


Sample Input 1

15.8

Sample Output 1

15+

Here, printing 15 + will not be accepted: do not print a space between X and +, or between X and -.


Sample Input 2

1.0

Sample Output 2

1-

You will not get inputs such as 1.00 and 1.


Sample Input 3

12.5

Sample Output 3

12
C - Pentagon

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

以下の図で表される正五角形 P があります。

P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しいか判定してください。

制約

  • S_1,S_2,T_1,T_2 は A, B, C, D, E のいずれかの文字
  • S_1 \neq S_2
  • T_1 \neq T_2

入力

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

S_1S_2
T_1T_2

出力

P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しい場合 Yes を、等しくない場合 No を出力せよ。


入力例 1

AC
EC

出力例 1

Yes

P の点 A と点 C を結ぶ線分と、P の点 E と点 C を結ぶ線分の長さは等しいです。


入力例 2

DA
EA

出力例 2

No

P の点 D と点 A を結ぶ線分と、P の点 E と点 A を結ぶ線分の長さは等しくありません。


入力例 3

BD
BD

出力例 3

Yes

Score : 200 points

Problem Statement

A regular pentagon P is shown in the figure below.

Determine whether the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2.

Constraints

  • Each of S_1, S_2, T_1, and T_2 is one of the characters A, B, C, D, and E.
  • S_1 \neq S_2
  • T_1 \neq T_2

Input

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

S_1S_2
T_1T_2

Output

If the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2, print Yes; otherwise, print No.


Sample Input 1

AC
EC

Sample Output 1

Yes

The length of the line segment connecting point A and point C of P equals the length of the line segment connecting point E and point C.


Sample Input 2

DA
EA

Sample Output 2

No

The length of the line segment connecting point D and point A of P does not equal the length of the line segment connecting point E and point A.


Sample Input 3

BD
BD

Sample Output 3

Yes
D - Hard Calculation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

正整数 A,B が与えられます。
A+B を(十進法で)計算する時、繰り上がりが生じないなら Easy 、生じるなら Hard と出力してください。

制約

  • A,B は整数
  • 1 \le A,B \le 10^{18}

入力

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

A B

出力

繰り上がりが生じないなら Easy 、生じるなら Hard と出力せよ。


入力例 1

229 390

出力例 1

Hard

229+390 を計算する際、十の位から百の位へと繰り上がりが発生します。よって、答えは Hard です。


入力例 2

123456789 9876543210

出力例 2

Easy

繰り上がりは発生しません。答えは Easy です。
また、入力が 32bit 整数に収まらないこともあります。

Score : 200 points

Problem Statement

You are given positive integers A and B.
Let us calculate A+B (in decimal). If it does not involve a carry, print Easy; if it does, print Hard.

Constraints

  • A and B are integers.
  • 1 \le A,B \le 10^{18}

Input

Input is given from Standard Input in the following format:

A B

Output

If the calculation does not involve a carry, print Easy; if it does, print Hard.


Sample Input 1

229 390

Sample Output 1

Hard

When calculating 229+390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.


Sample Input 2

123456789 9876543210

Sample Output 2

Easy

We do not have a carry here; the answer is Easy.
Note that the input may not fit into a 32-bit integer.

E - Standings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

1 から N の番号が付いた N 人がコイントスを何回かしました。人 i は A_i 回表を出し、B_i 回裏を出したこと分かっています。

人 i のコイントスの 成功率 は \displaystyle\frac{A_i}{A_i+B_i} で定義されます。人 1,\ldots,N の番号を、成功率の高い順に並び替えてください。成功率が同じ人が複数いる場合、その中では人の番号が小さい順になるように並び替えてください。

制約

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • 入力される数値は全て整数

入力

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

N
A_1 B_1
\vdots
A_N B_N

出力

人 1,\ldots,N の番号を成功率の高い順に空白区切りで出力せよ。成功率が同じ人の番号は昇順に並び替えて出力せよ。


入力例 1

3
1 3
3 1
2 2

出力例 1

2 3 1

人 1 の成功率は 0.25、人 2 の成功率は 0.75、人 3 の成功率は 0.5 です。

成功率の高い順に並び替えると出力例の順番になります。


入力例 2

2
1 3
2 6

出力例 2

1 2

人 1,2 は成功率が同じなので、番号の昇順に出力することに注意してください。


入力例 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

出力例 3

3 1 4 2

Score : 300 points

Problem Statement

N people numbered 1 through N tossed a coin several times. We know that person i's tosses resulted in A_i heads and B_i tails.

Person i's success rate of the tosses is defined by \displaystyle\frac{A_i}{A_i+B_i}. Sort people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.

Constraints

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • All input values are integers.

Input

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

N
A_1 B_1
\vdots
A_N B_N

Output

Print the numbers of people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.


Sample Input 1

3
1 3
3 1
2 2

Sample Output 1

2 3 1

Person 1's success rate is 0.25, person 2's is 0.75, and person 3's is 0.5.

Sort them in descending order of their success rates to obtain the order in Sample Output.


Sample Input 2

2
1 3
2 6

Sample Output 2

1 2

Note that person 1 and 2 should be printed in ascending order of their numbers, as they have the same success rates.


Sample Input 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

Sample Output 3

3 1 4 2
F - Flavors

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

N カップのアイスクリームがあります。
i カップ目の味は F_i 、美味しさは S_i ( S_i は偶数 ) です。

あなたは、 N 個のカップの中から 2 つを選んで食べることにしました。
このときの満足度は次のように定義されます。

  • 食べたアイスクリームの美味しさを s,t ( 但し、 s \ge t ) とする。
    • 2 つのカップの味が異なるなら、満足度は \displaystyle s+t である。
    • そうでないなら、満足度は \displaystyle s + \frac{t}{2} である。

満足度として達成可能な最大値を求めてください。

制約

  • 入力は全て整数
  • 2 \le N \le 3 \times 10^5
  • 1 \le F_i \le N
  • 2 \le S_i \le 10^9
  • S_i は偶数

入力

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

N
F_1 S_1
F_2 S_2
\vdots
F_N S_N

出力

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


入力例 1

4
1 4
2 10
2 8
3 6

出力例 1

16

2 カップ目と 4 カップ目のアイスを食べることを考えます。

  • 2 カップ目の味は 2 、美味しさは 10 です。
  • 4 カップ目の味は 3 、美味しさは 6 です。
  • 両者の味は異なるので、満足度は 10+6=16 です。

以上より、満足度 16 を達成できます。
満足度を 16 より大きくすることはできません。


入力例 2

4
4 10
3 2
2 4
4 12

出力例 2

17

1 カップ目と 4 カップ目のアイスを食べることを考えます。

  • 1 カップ目の味は 4 、美味しさは 10 です。
  • 4 カップ目の味は 4 、美味しさは 12 です。
  • 両者の味は同じなので、満足度は 12+\frac{10}{2}=17 です。

以上より、満足度 17 を達成できます。
満足度を 17 より大きくすることはできません。

Score : 300 points

Problem Statement

We have N cups of ice cream.
The flavor and deliciousness of the i-th cup are F_i and S_i, respectively (S_i is an even number).

You will choose and eat two of the N cups.
Your satisfaction here is defined as follows.

  • Let s and t (s \ge t) be the deliciousness of the eaten cups.
    • If the two cups have different flavors, your satisfaction is \displaystyle s+t.
    • Otherwise, your satisfaction is \displaystyle s + \frac{t}{2}.

Find the maximum achievable satisfaction.

Constraints

  • All input values are integers.
  • 2 \le N \le 3 \times 10^5
  • 1 \le F_i \le N
  • 2 \le S_i \le 10^9
  • S_i is even.

Input

Input is given from Standard Input in the following format:

N
F_1 S_1
F_2 S_2
\vdots
F_N S_N

Output

Print the answer as an integer.


Sample Input 1

4
1 4
2 10
2 8
3 6

Sample Output 1

16

Consider eating the second and fourth cups.

  • The second cup has a flavor of 2 and deliciousness of 10.
  • The fourth cup has a flavor of 3 and deliciousness of 6.
  • Since they have different flavors, your satisfaction is 10+6=16.

Thus, you can achieve the satisfaction of 16.
You cannot achieve a satisfaction greater than 16.


Sample Input 2

4
4 10
3 2
2 4
4 12

Sample Output 2

17

Consider eating the first and fourth cups.

  • The first cup has a flavor of 4 and deliciousness of 10.
  • The fourth cup has a flavor of 4 and deliciousness of 12.
  • Since they have the same flavor, your satisfaction is 12+\frac{10}{2}=17.

Thus, you can achieve the satisfaction of 17.
You cannot achieve a satisfaction greater than 17.

G - 2-variable Function

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

整数 N が与えられるので、以下の条件を全て満たす最小の整数 X を求めてください。

  • X は N 以上である。
  • 非負整数 (a,b) の組であって、 X=a^3+a^2b+ab^2+b^3 を満たすようなものが存在する。

制約

  • N は整数
  • 0 \le N \le 10^{18}

入力

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

N

出力

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


入力例 1

9

出力例 1

15

9 \le X \le 14 であるようなどの整数 X についても、問題文中の条件を満たすような (a,b) は存在しません。
X=15 は (a,b)=(2,1) とすると問題文中の条件を満たします。


入力例 2

0

出力例 2

0

N 自身が条件を満たすこともあります。


入力例 3

999999999989449206

出力例 3

1000000000000000000

入出力が 32bit 整数型に収まらない場合があります。

Score : 400 points

Problem Statement

Given an integer N, find the smallest integer X that satisfies all of the conditions below.

  • X is greater than or equal to N.
  • There is a pair of non-negative integers (a, b) such that X=a^3+a^2b+ab^2+b^3.

Constraints

  • N is an integer.
  • 0 \le N \le 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

9

Sample Output 1

15

For any integer X such that 9 \le X \le 14, there is no (a, b) that satisfies the condition in the statement.
For X=15, (a,b)=(2,1) satisfies the condition.


Sample Input 2

0

Sample Output 2

0

N itself may satisfy the condition.


Sample Input 3

999999999989449206

Sample Output 3

1000000000000000000

Input and output may not fit into a 32-bit integer type.

H - LCM on Whiteboard

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

N 個の整数 a_1,\ldots,a_N が白板に書かれています。
ここで、a_i は m_i 個の素数 p_{i,1} \lt \ldots \lt p_{i,m_i} と正整数 e_{i,1},\ldots,e_{i,m_i} を用いて a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}} と表せる整数です。
あなたは N 個の整数から 1 つ選んで 1 に書き換えます。
書き換えた後の N 個の整数の最小公倍数としてあり得る値の個数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq m_i
  • \sum{m_i} \leq 2 \times 10^5
  • 2 \leq p_{i,1} \lt \ldots \lt p_{i,m_i} \leq 10^9
  • p_{i,j} は素数
  • 1 \leq e_{i,j} \leq 10^9
  • 入力はすべて整数

入力

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

N
m_1
p_{1,1} e_{1,1}
\vdots
p_{1,m_1} e_{1,m_1}
m_2
p_{2,1} e_{2,1}
\vdots
p_{2,m_2} e_{2,m_2}
\vdots
m_N
p_{N,1} e_{N,1}
\vdots
p_{N,m_N} e_{N,m_N}

出力

答えを出力せよ。


入力例 1

4
1
7 2
2
2 2
5 1
1
5 1
2
2 1
7 1

出力例 1

3

白板に書かれている整数は a_1 =7^2=49, a_2=2^2 \times 5^1 = 20, a_3 = 5^1 = 5, a_4=2^1 \times 7^1 = 14 です。
a_1 を 1 に書き換えると白板に書かれている整数は 1,20,5,14 となり、これらの最小公倍数は 140 です。
a_2 を 1 に書き換えると白板に書かれている整数は 49,1,5,14 となり、これらの最小公倍数は 490 です。
a_3 を 1 に書き換えると白板に書かれている整数は 49,20,1,14 となり、これらの最小公倍数は 980 です。
a_4 を 1 に書き換えると白板に書かれている整数は 49,20,5,1 となり、これらの最小公倍数は 980 です。
以上より、書き換えた後の N 個の整数の最小公倍数としてあり得る値は 140,490,980 であり、この入力における答えが 3 と分かります。


入力例 2

1
1
998244353 1000000000

出力例 2

1

白板に書かれている整数はとても大きい場合があります。

Score : 500 points

Problem Statement

There are N integers a_1,\ldots,a_N written on a whiteboard.
Here, a_i can be represented as a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}} using m_i prime numbers p_{i,1} \lt \ldots \lt p_{i,m_i} and positive integers e_{i,1},\ldots,e_{i,m_i}.
You will choose one of the N integers to replace it with 1.
Find the number of values that can be the least common multiple of the N integers after the replacement.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq m_i
  • \sum{m_i} \leq 2 \times 10^5
  • 2 \leq p_{i,1} \lt \ldots \lt p_{i,m_i} \leq 10^9
  • p_{i,j} is prime.
  • 1 \leq e_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
m_1
p_{1,1} e_{1,1}
\vdots
p_{1,m_1} e_{1,m_1}
m_2
p_{2,1} e_{2,1}
\vdots
p_{2,m_2} e_{2,m_2}
\vdots
m_N
p_{N,1} e_{N,1}
\vdots
p_{N,m_N} e_{N,m_N}

Output

Print the answer.


Sample Input 1

4
1
7 2
2
2 2
5 1
1
5 1
2
2 1
7 1

Sample Output 1

3

The integers on the whiteboard are a_1 =7^2=49, a_2=2^2 \times 5^1 = 20, a_3 = 5^1 = 5, a_4=2^1 \times 7^1 = 14.
If you replace a_1 with 1, the integers on the whiteboard become 1,20,5,14, whose least common multiple is 140.
If you replace a_2 with 1, the integers on the whiteboard become 49,1,5,14, whose least common multiple is 490.
If you replace a_3 with 1, the integers on the whiteboard become 49,20,1,14, whose least common multiple is 980.
If you replace a_4 with 1, the integers on the whiteboard become 49,20,5,1, whose least common multiple is 980.
Therefore, the least common multiple of the N integers after the replacement can be 140, 490, or 980, so the answer is 3.


Sample Input 2

1
1
998244353 1000000000

Sample Output 2

1

There may be enormous integers on the whiteboard.

I - Variety of Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

M 個の数字 C_i が与えられます。

1 以上 N 以下の整数のうち、先頭に余分な 0 をつけずに 10 進法で表した時に C_1,\ldots,C_M を全て含むようなもの全ての和を、 998244353 で割った余りを求めてください。

制約

  • 1 \leq N < 10^{10^4}
  • 1 \leq M \leq 10
  • 0 \leq C_1 < \ldots < C_M \leq 9
  • 入力に含まれる値は全て整数である

入力

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

N
M
C_1 \ldots C_M

出力

答えを出力せよ。


入力例 1

104
2
0 1

出力例 1

520

1 以上 104 以下の整数のうち、10 進法で表した時に 0, 1 を共に含むようなものは、10,100,101,102,103,104 の 6 個あります。
これらの和は 520 です。


入力例 2

999
4
1 2 3 4

出力例 2

0

1 以上 999 以下の整数で、1, 2, 3, 4 を全て含むようなものは存在しません。


入力例 3

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
5
0 2 4 6 8

出力例 3

397365274

998244353 で割った余りを求めてください。

Score : 500 points

Problem Statement

Given are M digits C_i.

Find the sum, modulo 998244353, of all integers between 1 and N (inclusive) that contain all of C_1, \ldots, C_M when written in base 10 without unnecessary leading zeros.

Constraints

  • 1 \leq N < 10^{10^4}
  • 1 \leq M \leq 10
  • 0 \leq C_1 < \ldots < C_M \leq 9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
M
C_1 \ldots C_M

Output

Print the answer.


Sample Input 1

104
2
0 1

Sample Output 1

520

Between 1 and 104, there are six integers that contain both 0 and 1 when written in base 10: 10,100,101,102,103,104.
The sum of them is 520.


Sample Input 2

999
4
1 2 3 4

Sample Output 2

0

Between 1 and 999, no integer contains all of 1, 2, 3, 4.


Sample Input 3

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
5
0 2 4 6 8

Sample Output 3

397365274

Be sure to find the sum modulo 998244353.