A - Election 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

AtCoder 市では市長選挙が行われています。候補者は高橋氏と青木氏です。

2 人のどちらかに投じられた有効票は N 票あり、現在開票が行われています。なお、 N は奇数です。

現在の開票作業の途中経過は高橋氏に T 票、青木氏に A 票です。

現時点で勝敗が確定しているかを判定してください。

制約

  • 1 \leq N \leq 99
  • N は奇数
  • 0 \leq T,A \leq N
  • T+A \leq N
  • 入力はすべて整数

入力

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

N T A

出力

現時点で勝敗が確定しているならば Yes 、そうでなければ No と出力せよ。


入力例 1

7 4 2

出力例 1

Yes

残りの 1 票が青木氏に入っても、高橋氏は勝利します。高橋氏の勝利が確定しているため、Yes と出力します。


入力例 2

99 12 48

出力例 2

No

現時点では青木氏が多く票を獲得していますが、高橋氏が残りの 39 票を獲得すると高橋氏が勝利します。よって、No と出力します。


入力例 3

1 0 0

出力例 3

No

Score : 100 points

Problem Statement

A mayoral election is being held in AtCoder City. The candidates are Takahashi and Aoki.

There are N valid votes cast for either of the two candidates, and the counting is currently underway. Here, N is an odd number.

The current vote count is T votes for Takahashi and A votes for Aoki.

Determine if the outcome of the election is already decided at this point.

Constraints

  • 1 \leq N \leq 99
  • N is an odd number.
  • 0 \leq T, A \leq N
  • T + A \leq N
  • All input values are integers.

Input

The input is given from standard input in the following format:

N T A

Output

Print Yes if the outcome of the election is already decided, and No otherwise.


Sample Input 1

7 4 2

Sample Output 1

Yes

Even if the remaining one vote goes to Aoki, Takahashi will still win. That is, his victory is decided, so print Yes.


Sample Input 2

99 12 48

Sample Output 2

No

Although Aoki currently has more votes, Takahashi would win if he receives the remaining 39 votes. Therefore, print No.


Sample Input 3

1 0 0

Sample Output 3

No
B - Full Moon

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

高橋くんは満月が好きです。

今日を 1 日目とすると、今日以降で満月を見られる最初の日は M 日目です。以後は P 日ごと、つまり M+P 日目、M+2P 日目、\ldots に満月を見られます。

1 日目から N 日目まで(両端を含む)の中で、高橋くんが満月を見られる日の数を求めてください。

制約

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

入力

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

N M P

出力

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


入力例 1

13 3 5

出力例 1

3

満月を見られる日は、3 日目、8 日目、13 日目、18 日目、\ldots です。

1 日目から 13 日目までの中で高橋くんが満月を見られる日は、3 日目、8 日目、13 日目の 3 個です。


入力例 2

5 6 6

出力例 2

0

高橋くんが満月を見られる日が存在しない場合もあります。


入力例 3

200000 314 318

出力例 3

628

Score : 100 points

Problem Statement

Takahashi likes full moons.

Let today be day 1. The first day on or after today on which he can see a full moon is day M. After that, he can see a full moon every P days, that is, on day M+P, day M+2P, and so on.

Find the number of days between day 1 and day N, inclusive, on which he can see a full moon.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq M \leq P \leq 2\times 10^5
  • All input values are integers.

Input

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

N M P

Output

Print the answer as an integer.


Sample Input 1

13 3 5

Sample Output 1

3

He can see a full moon on day 3, 8, 13, 18, and so on.

From day 1 to 13, he can see a full moon on three days: day 3, 8, and 13.


Sample Input 2

5 6 6

Sample Output 2

0

There may be no days he can see a full moon.


Sample Input 3

200000 314 318

Sample Output 3

628
C - Perfect

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

N 人の人が、M 問からなるプログラミングコンテストに参加しました。
参加者は人 1, 人 2, \ldots, 人 N と番号づけられており、問題は問題 1, 問題 2, \ldots, 問題 M と番号づけられています。

このコンテストでは K 個のイベントが順番に起き、i 番目 (1\leq i\leq K) のイベントでは次のことが起きました。

  • 人 A_i が問題 B_i に正解した。

同じイベントが 2 回以上起きることはありません。 また、この K 個のイベント以外に誰かがどれかの問題に正解することはありません。

すべての問題に正解した人の番号を全員出力してください。
そのような人が複数いる場合は、すべての問題に正解したタイミングが早い順に出力してください。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • K \geq 1
  • 1 \leq A_i\leq N
  • 1 \leq B_i\leq M
  • i\neq j ならば (A_i,B_i)\neq (A_j,B_j)
  • 入力はすべて整数

入力

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

N M K
A_1 B_1
A_2 B_2
\vdots
A_K B_K

出力

すべての問題に正解した人の番号を、すべての問題に正解したタイミングが早い順に空白区切りで一行に出力せよ。
すべての問題に正解した人がいないならば、何も出力しないようにせよ。


入力例 1

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

出力例 1

3 1

コンテストでは次のことが順に起きました。

  • 人 1 が問題 1 に正解した。人 1 はこれまでに、問題 1 のみに正解した。
  • 人 3 が問題 2 に正解した。人 3 はこれまでに、問題 2 のみに正解した。
  • 人 2 が問題 1 に正解した。人 2 はこれまでに、問題 1 のみに正解した。
  • 人 3 が問題 1 に正解した。人 3 はこれまでに、問題 1,2 に正解した。よって、この時点で人 3 はすべての問題に正解した。
  • 人 1 が問題 2 に正解した。人 1 はこれまでに、問題 1,2 に正解した。よって、この時点で人 1 はすべての問題に正解した。

よって、すべての問題に正解したのは人 1,3 であり、すべての問題に正解したタイミングは人 3 の方が早いです。
よって、3,1 をこの順に空白区切りで出力します。


入力例 2

2 2 2
1 1
2 2

出力例 2


すべての問題に正解した人がいない場合は、何も出力しないでください。

Score : 200 points

Problem Statement

N people participated in a programming contest consisting of M problems.
The participants are numbered person 1, person 2, \ldots, person N, and the problems are numbered problem 1, problem 2, \ldots, problem M.

In this contest, K events occurred in order; in the i-th event (1\leq i\leq K), the following happened:

  • Person A_i solved problem B_i.

The same event does not occur two or more times. Also, apart from these K events, nobody solves any problem.

Output the numbers of all people who solved all problems.
If there are multiple such people, output them in ascending order of the time at which they solved all problems.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • K \geq 1
  • 1 \leq A_i \leq N
  • 1 \leq B_i \leq M
  • If i\neq j then (A_i,B_i)\neq (A_j,B_j).
  • All input values are integers.

Input

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

N M K
A_1 B_1
A_2 B_2
\vdots
A_K B_K

Output

Output, on one line and separated by spaces, the numbers of all people who solved all problems, in ascending order of the time at which they solved all problems. If there is no person who solved all problems, output nothing.


Sample Input 1

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

Sample Output 1

3 1

In the contest, the following happened in order.

  • Person 1 solved problem 1. So far, person 1 has solved only problem 1.
  • Person 3 solved problem 2. So far, person 3 has solved only problem 2.
  • Person 2 solved problem 1. So far, person 2 has solved only problem 1.
  • Person 3 solved problem 1. So far, person 3 has solved problems 1,2. Thus, at this point person 3 has solved all problems.
  • Person 1 solved problem 2. So far, person 1 has solved problems 1,2. Thus, at this point person 1 has solved all problems.

Thus, the people who solved all problems are persons 1,3, and the one who solved all problems earlier is person 3. Thus, output 3,1 in this order, separated by spaces.


Sample Input 2

2 2 2
1 1
2 2

Sample Output 2


If there is no person who solved all problems, output nothing.

D - 9x9 Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150 点

問題文

九九の表に現れる 81 個の整数のうち、X でないものの総和を求めてください。

縦 9 マス、横 9 マスのグリッドがあります。
グリッドの各マスには整数が書きこまれていて、グリッドの上から i 行目、左から j 列目のマスには i \times j が書きこまれています。
整数 X が与えられます。グリッドに書きこまれた 81 個の整数のうち X でないものの総和を求めてください。値の等しい整数が異なるマスに書きこまれている場合は別々に加算する点に注意してください。

制約

  • X は 1 以上 81 以下の整数

入力

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

X

出力

グリッドに書きこまれた 81 個の整数のうち X でないものの総和を出力せよ。


入力例 1

1

出力例 1

2024

グリッドに 1 が書きこまれたマスは上から 1 行目、左から 1 列目のマスのみです。1 でない整数を全て足し合わせると総和は 2024 になります。


入力例 2

11

出力例 2

2025

グリッドに 11 が書きこまれたマスは存在しません。よって 81 個の整数全てを足し合わせた総和である 2025 が答えとなります。


入力例 3

24

出力例 3

1929

Score : 150 points

Problem Statement

Among the 81 integers that appear in the 9-by-9 multiplication table, find the sum of those that are not X.

There is a grid of size 9 by 9.
Each cell of the grid contains an integer: the cell at the i-th row from the top and the j-th column from the left contains i \times j.
You are given an integer X. Among the 81 integers written in this grid, find the sum of those that are not X. If the same value appears in multiple cells, add it for each cell.

Constraints

  • X is an integer between 1 and 81, inclusive.

Input

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

X

Output

Print the sum of the integers that are not X among the 81 integers written in the grid.


Sample Input 1

1

Sample Output 1

2024

The only cell with 1 in the grid is the cell at the 1st row from the top and 1st column from the left. Summing all integers that are not 1 yields 2024.


Sample Input 2

11

Sample Output 2

2025

There is no cell containing 11 in the grid. Thus, the answer is 2025, the sum of all 81 integers.


Sample Input 3

24

Sample Output 3

1929
E - Various Kagamimochi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。

2 つの餅 A,B の大きさをそれぞれ a,b としたとき、a が b の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。

N 個の餅から 2 つの餅を選び、一方をもう一方の上に乗せることで鏡餅を 1 つ作ります。

何種類の鏡餅を作ることができるか求めてください。

ただし、鏡餅を構成する餅の大きさが同じでも、少なくとも一方が異なる餅であれば別の種類の鏡餅として数えます。

制約

  • 2\leq N\leq 5\times 10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
  • A _ i\leq A _ {i+1}\ (1\leq i\lt N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \cdots A _ N

出力

作ることができる鏡餅の種類数を出力せよ。


入力例 1

6
2 3 4 4 7 10

出力例 1

8

与えられた餅の大きさは以下のようになっています。

このとき、以下の 8 種類の鏡餅を作ることができます。

大きさ 4 の餅の上に大きさ 2 の餅を乗せた鏡餅や、大きさ 10 の餅の上に大きさ 4 の餅を乗せた鏡餅は 2 種類あることに注意してください。


入力例 2

3
387 388 389

出力例 2

0

鏡餅を 1 種類も作ることができない場合もあります。


入力例 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

出力例 3

388

Score : 300 points

Problem Statement

There are N mochi (rice cakes) arranged in ascending order of size. The size of the i-th mochi (1 \leq i \leq N) is A_i.

Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.

You choose two mochi out of the N mochi, and place one on top of the other to form one kagamimochi.

Find how many different kinds of kagamimochi can be made.

Two kagamimochi are distinguished if at least one of the mochi is different, even if the sizes of the mochi are the same.

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
  • A_i \leq A_{i+1} \ (1 \leq i < N)
  • All input values are integers.

Input

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

N
A_1 A_2 \cdots A_N

Output

Print the number of different kinds of kagamimochi that can be made.


Sample Input 1

6
2 3 4 4 7 10

Sample Output 1

8

The sizes of the given mochi are as follows:

In this case, you can make the following eight kinds of kagamimochi:

Note that there are two kinds of kagamimochi where a mochi of size 4 is topped by a mochi of size 2, and two kinds where a mochi of size 10 is topped by a mochi of size 4.


Sample Input 2

3
387 388 389

Sample Output 2

0

It is possible that you cannot make any kagamimochi.


Sample Input 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

Sample Output 3

388
F - Tile Distance 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350 点

問題文

座標平面上に 2\times1 の大きさのタイルが敷き詰められています。 タイルは、次の規則に従って敷き詰められています。

  • 整数の組 (i,j) に対し、正方形 A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace は 1 つのタイルに含まれる。
  • i+j が偶数のとき、A _ {i,j} と A _ {i + 1,j} は同じタイルに含まれる。

ただし、タイルは境界を含むものとし、共通部分が正の面積をもつような 2 つの異なるタイルは存在しないとします。

原点の近くでは、タイルは以下のように敷き詰められています。

高橋君は、はじめ座標平面上の点 (S _ x+0.5,S _ y+0.5) にいます。

高橋君は、次の移動を好きなだけ繰り返します。

  • 上下左右の方向と正の整数 n を選ぶ。その方向に n だけ進む。

高橋君が異なるタイルを通るたび、高橋君は通行料を 1 だけ支払います。

高橋君が点 (T _ x+0.5,T _ y+0.5) にたどり着くために支払わなければならない通行料の最小値を求めてください。

制約

  • 0\leq S _ x\leq2\times10 ^ {16}
  • 0\leq S _ y\leq2\times10 ^ {16}
  • 0\leq T _ x\leq2\times10 ^ {16}
  • 0\leq T _ y\leq2\times10 ^ {16}
  • 入力はすべて整数

入力

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

S _ x S _ y
T _ x T _ y

出力

高橋君が支払わなければならない通行料の最小値を出力せよ。


入力例 1

5 0
2 5

出力例 1

5

例えば、以下のように移動することで支払う通行料を 5 にすることができます。

  • 左に 1 進む。通行料を 0 支払う。
  • 上に 1 進む。通行料を 1 支払う。
  • 左に 1 進む。通行料を 0 支払う。
  • 上に 3 進む。通行料を 3 支払う。
  • 左に 1 進む。通行料を 0 支払う。
  • 上に 1 進む。通行料を 1 支払う。

支払う通行料を 4 以下にすることはできないので、5 を出力してください。


入力例 2

3 1
4 1

出力例 2

0

通行料を支払わなくてよい場合もあります。


入力例 3

2552608206527595 5411232866732612
771856005518028 7206210729152763

出力例 3

1794977862420151

出力すべき値が 32\operatorname{bit} 整数の範囲に収まらない場合があることに注意してください。

Score : 350 points

Problem Statement

The coordinate plane is covered with 2\times1 tiles. The tiles are laid out according to the following rules:

  • For an integer pair (i,j), the square A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace is contained in one tile.
  • When i+j is even, A _ {i,j} and A _ {i + 1,j} are contained in the same tile.

Tiles include their boundaries, and no two different tiles share a positive area.

Near the origin, the tiles are laid out as follows:

Takahashi starts at the point (S _ x+0.5,S _ y+0.5) on the coordinate plane.

He can repeat the following move as many times as he likes:

  • Choose a direction (up, down, left, or right) and a positive integer n. Move n units in that direction.

Each time he enters a tile, he pays a toll of 1.

Find the minimum toll he must pay to reach the point (T _ x+0.5,T _ y+0.5).

Constraints

  • 0\leq S _ x\leq2\times10 ^ {16}
  • 0\leq S _ y\leq2\times10 ^ {16}
  • 0\leq T _ x\leq2\times10 ^ {16}
  • 0\leq T _ y\leq2\times10 ^ {16}
  • All input values are integers.

Input

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

S _ x S _ y
T _ x T _ y

Output

Print the minimum toll Takahashi must pay.


Sample Input 1

5 0
2 5

Sample Output 1

5

For example, Takahashi can pay a toll of 5 by moving as follows:

  • Move left by 1. Pay a toll of 0.
  • Move up by 1. Pay a toll of 1.
  • Move left by 1. Pay a toll of 0.
  • Move up by 3. Pay a toll of 3.
  • Move left by 1. Pay a toll of 0.
  • Move up by 1. Pay a toll of 1.

It is impossible to reduce the toll to 4 or less, so print 5.


Sample Input 2

3 1
4 1

Sample Output 2

0

There are cases where no toll needs to be paid.


Sample Input 3

2552608206527595 5411232866732612
771856005518028 7206210729152763

Sample Output 3

1794977862420151

Note that the value to be output may exceed the range of a 32-bit integer.

G - Minimum XOR Path

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

頂点に 1 から N の、辺に 1 から M の番号がついた N 頂点 M 辺の単純連結無向グラフが与えられます。辺 i は頂点 u_i と頂点 v_i を結んでおり、ラベル w_i が付けられています。

頂点 1 から頂点 N への単純パス(同じ頂点を 2 度以上通らないパス)のうち、パスに含まれる辺につけられたラベルの総 XOR としてあり得る最小値を求めてください。

XOR とは 非負整数 A,B の XOR A \oplus B は、以下のように定義されます。
  • A \oplus B を二進表記した際の 2^k \, (k \geq 0) の位の数は、A,B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
例えば、 3 \oplus 5 = 6 となります (二進表記すると: 011 \oplus 101=110)。
一般に k 個の整数 p_1, \dots, p_k の XOR は (\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k) と定義され、これは p_1, \dots, p_k の順番によらないことが証明できます。

制約

  • 2\leq N\leq 10
  • N-1\leq M\leq \frac{N(N-1)}{2}
  • 1\leq u_i\lt v_i\leq N
  • 0\leq w_i\lt 2^{60}
  • 入力で与えられるグラフは単純連結無向グラフ
  • 入力は全て整数

入力

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

N M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_M v_M w_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

3

頂点 1 から頂点 4 への単純パスは以下の 2 つ存在します。

  • 頂点 1 \to 頂点 2 \to 頂点 4
  • 頂点 1 \to 頂点 3 \to 頂点 4

1 つ目のパスに含まれる辺につけられたラベルの総 XOR は 6、 2 つ目のパスに含まれる辺につけられたラベルの総 XOR は 3 であるため、答えは 3 です。


入力例 2

4 3
1 2 1
2 3 2
3 4 4

出力例 2

7

入力例 3

7 10
1 2 726259430069220777
1 4 988687862609183408
1 5 298079271598409137
1 6 920499328385871537
1 7 763940148194103497
2 4 382710956291350101
3 4 770341659133285654
3 5 422036395078103425
3 6 472678770470637382
5 7 938201660808593198

出力例 3

186751192333709144

Score : 400 points

Problem Statement

You are given a simple connected undirected graph with N vertices numbered 1 through N and M edges numbered 1 through M. Edge i connects vertices u_i and v_i, and has a label w_i.

Among all simple paths (paths that do not pass through the same vertex more than once) from vertex 1 to vertex N, find the minimum XOR of the labels of the edges on the path.

Notes on XOR For non-negative integers A and B, their XOR A \oplus B is defined as follows:
  • In the binary representation of A \oplus B, the digit in the place corresponding to 2^k \,(k \ge 0) is 1 if and only if exactly one of the digits in the same place of A and B is 1; otherwise, it is 0.
For example, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110).
In general, the XOR of k integers p_1, \dots, p_k is defined as (\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k). It can be proved that it does not depend on the order of p_1, \dots, p_k.

Constraints

  • 2 \leq N \leq 10
  • N-1 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq u_i < v_i \leq N
  • 0 \leq w_i < 2^{60}
  • The given graph is a simple connected undirected graph.
  • All input values are integers.

Input

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

N M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_M v_M w_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

3

There are two simple paths from vertex 1 to vertex 4:

  • 1 \to 2 \to 4
  • 1 \to 3 \to 4

The XOR of the labels on the edges of the first path is 6, and that of the second path is 3. Therefore, the answer is 3.


Sample Input 2

4 3
1 2 1
2 3 2
3 4 4

Sample Output 2

7

Sample Input 3

7 10
1 2 726259430069220777
1 4 988687862609183408
1 5 298079271598409137
1 6 920499328385871537
1 7 763940148194103497
2 4 382710956291350101
3 4 770341659133285654
3 5 422036395078103425
3 6 472678770470637382
5 7 938201660808593198

Sample Output 3

186751192333709144
H - Integer Sequence Fair

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

整数列を一堂に集めてその優劣を定める、整数列品評会が行われます。 品評会では、1 以上 K 以下の整数からなる長さ N の整数列すべてが審査対象となり、 審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつけます。

「審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつける方法」が何通りあるかを 998244353 で割ったあまりを出力してください。

ただし、2 つの方法が異なるとは「審査対象となるある数列 A = (A_1, A_2, \ldots, A_N) が存在して、 A に対してつける点数が 2 つの方法で異なる」ことを言います。

制約

  • 1 \leq N, K, M \leq 10^{18}
  • N, K, M は整数

入力

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

N K M

出力

「審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつける方法」が何通りあるかを 998244353 で割ったあまりを出力せよ。


入力例 1

2 2 2

出力例 1

16

審査対象となる数列は、(1, 1), (1, 2), (2, 1), (2, 2) の 4 つです。「審査対象の数列それぞれに対して 1 以上 2 以下の整数の点数をつける方法」は、以下の 16 通りあります。

  • (1, 1) に 1 点、(1, 2) に 1 点、(2, 1) に 1 点、(2, 2) に 1 点をつける方法
  • (1, 1) に 1 点、(1, 2) に 1 点、(2, 1) に 1 点、(2, 2) に 2 点をつける方法
  • (1, 1) に 1 点、(1, 2) に 1 点、(2, 1) に 2 点、(2, 2) に 1 点をつける方法
  • (1, 1) に 1 点、(1, 2) に 1 点、(2, 1) に 2 点、(2, 2) に 2 点をつける方法
  • \cdots
  • (1, 1) に 2 点、(1, 2) に 2 点、(2, 1) に 2 点、(2, 2) に 2 点をつける方法

よって、16 を出力します。


入力例 2

3 14 15926535

出力例 2

109718301

998244353 で割ったあまりを出力することに注意してください。

Score : 500 points

Problem Statement

Integer Sequence Exhibition is taking place, where integer sequences are gathered in one place and evaluated. Here, every integer sequence of length N consisting of integers between 1 and K (inclusive) is evaluated and given an integer score between 1 and M (inclusive).

Print the number, modulo 998244353, of ways to give each of the evaluated sequences a score between 1 and M.

Here, two ways are said to be different when there is an evaluated sequence A = (A_1, A_2, \ldots, A_N) that is given different scores by the two ways.

Constraints

  • 1 \leq N, K, M \leq 10^{18}
  • N, K, and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number, modulo 998244353, of ways to give each of the evaluated sequences a score between 1 and M.


Sample Input 1

2 2 2

Sample Output 1

16

Four sequences are evaluated: (1, 1), (1, 2), (2, 1), and (2, 2). There are 16 ways to give each of these sequences a score between 1 and 2, as follows.

  • Give 1 to (1, 1), 1 to (1, 2), 1 to (2, 1), and 1 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 1 to (2, 1), and 2 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 2 to (2, 1), and 1 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 2 to (2, 1), and 2 to (2, 2)
  • \cdots
  • Give 2 to (1, 1), 2 to (1, 2), 2 to (2, 1), and 2 to (2, 2)

Thus, we print 16.


Sample Input 2

3 14 15926535

Sample Output 2

109718301

Be sure to print the count modulo 998244353.

I - substr = S

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

T 個のテストケースについて、数字のみからなる文字列 S と正整数 L,R が与えられるので、以下の問題を解いてください。

正整数 x に対して f(x)= ( x を ( 先頭に 0 を含まないように ) 書き下した文字列の連続部分列のうち S と合致するものの個数 ) と定義します。

例えば S= 22 であるとき、f(122) = 1, f(123) = 0, f(226) = 1, f(222) = 2 となります。

このとき、 \displaystyle \sum_{k=L}^{R} f(k) を求めてください。

制約

  • 1 \le T \le 1000
  • S は数字のみからなる長さ 1 以上 16 以下の文字列
  • L,R は 1 \le L \le R < 10^{16} を満たす整数

入力

入力は以下の形式で標準入力から与えられる。\rm{case}_i は i 個目のテストケースを表す。

T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}

各テストケースは以下の形式である。

S L R

出力

全体で T 行出力せよ。
そのうち i 行目には i 番目のテストケースに対する答えを整数として出力せよ。


入力例 1

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999

出力例 1

12
0
14888888888888889
12982260572545
10987664021
1

この入力には 6 個のテストケースが含まれます。

  • 1 つ目のケースは S= 22 ,L=23,R=234 です。
    • f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1
    • f(222)=2
    • 以上より、このケースに対する答えは 12 です。
  • 2 つ目のケースは S= 0295 ,L=295,R=295 です。
    • f(295)=0 となることに注意してください。

Score : 500 points

Problem Statement

You are given a string S consisting of digits and positive integers L and R for each of T test cases. Solve the following problem.

For a positive integer x, let us define f(x) as the number of contiguous substrings of the decimal representation of x (without leading zeros) that equal S.

For instance, if S= 22, we have f(122) = 1, f(123) = 0, f(226) = 1, and f(222) = 2.

Find \displaystyle \sum_{k=L}^{R} f(k).

Constraints

  • 1 \le T \le 1000
  • S is a string consisting of digits whose length is between 1 and 16, inclusive.
  • L and R are integers satisfying 1 \le L \le R < 10^{16}.

Input

The input is given from Standard Input in the following format, where \rm{case}_i denotes the i-th test case:

T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}

Each test case is in the following format:

S L R

Output

Print T lines in total.
The i-th line should contain an integer representing the answer to the i-th test case.


Sample Input 1

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999

Sample Output 1

12
0
14888888888888889
12982260572545
10987664021
1

This input contains six test cases.

  • In the first test case, S= 22, L=23, R=234.
    • f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
    • f(222)=2.
    • Thus, the answer is 12.
  • In the second test case, S= 0295, L=295, R=295.
    • Note that f(295)=0.