A - 16:9

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

配点 : 100

問題文

X ピクセル、縦 Y ピクセルの画像があります。 横の長さと縦の長さの比が 169 であるか、すなわち X:Y=16:9 であるかを判定してください。

制約

  • 1 \leq X \leq 1000
  • 1 \leq Y \leq 1000
  • 入力はすべて整数

入力

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

X Y

出力

横の長さと縦の長さの比が 169 ならば Yes を、そうでないならば No を出力せよ。


入力例 1

800 450

出力例 1

Yes

800 ピクセル、縦 450 ピクセルの画像において、横の長さと縦の長さの比は 169 です。


入力例 2

234 108

出力例 2

No

234 ピクセル、縦 108 ピクセルの画像において、横の長さと縦の長さの比は 169 ではありません。


入力例 3

108 192

出力例 3

No

108 ピクセル、縦 192 ピクセルの画像において、横の長さと縦の長さの比は 169 ではありません。

Score : 100 points

Problem Statement

There is an image with a width of X pixels and a height of Y pixels. Determine whether the ratio of the width to the height is 16 to 9, that is, whether X:Y=16:9.

Constraints

  • 1 \leq X \leq 1000
  • 1 \leq Y \leq 1000
  • All input values are integers.

Input

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

X Y

Output

If the ratio of the width to the height is 16 to 9, output Yes; otherwise, output No.


Sample Input 1

800 450

Sample Output 1

Yes

For an image with a width of 800 pixels and a height of 450 pixels, the ratio of the width to the height is 16 to 9.


Sample Input 2

234 108

Sample Output 2

No

For an image with a width of 234 pixels and a height of 108 pixels, the ratio of the width to the height is not 16 to 9.


Sample Input 3

108 192

Sample Output 3

No

For an image with a width of 108 pixels and a height of 192 pixels, the ratio of the width to the height is not 16 to 9.

B - Train Reservation

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

配点 : 200

問題文

高橋君は列車の座席を予約しようとしています。

高橋君が予約する候補としている列車は N 本あり、列車 1,2,\dots,N と番号が付けられています。 いずれの列車も座席は 5 列からなり、それぞれ A 列、B 列、C 列、D 列、E 列と呼ばれています。

各列車の現在の空席情報が文字列 S_1,S_2,\dots,S_N として与えられます。 ここで S_1,S_2,\dots,S_N はすべて長さ 5 で、列車 i の A 列から E 列までがそれぞれ S_i1 文字目から 5 文字目と対応しており、その文字が o ならば対応する列に空席があることを、x ならば対応する列に空席がないことを意味します。

高橋君は X 列の席を予約したいです。ここで XABCDE のいずれかです。 1 本以上の列車において X 列に空席があるか判定してください。

制約

  • N1 以上 100 以下の整数
  • XABCDE のいずれか
  • S_iox からなる長さ 5 の文字列

入力

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

N X
S_1
S_2
\vdots
S_N

出力

1 本以上の列車において X 列に空席があるならば Yes を、そうでないならば No を出力せよ。


入力例 1

3 A
xoxox
xxooo
oxxxx

出力例 1

Yes

列車 3 の A 列には空席があります。したがって Yes を出力してください。


入力例 2

5 C
xoxoo
oxxoo
oxxxo
xoxxx
oxxoo

出力例 2

No

どの列車の C 列にも空席がありません。したがって No を出力してください。

Score : 200 points

Problem Statement

Takahashi is trying to reserve a seat on a train.

There are N trains he is considering as candidates for reservation, numbered 1, 2, \dots, N. Each train has seats in five columns, called column A, column B, column C, column D, and column E.

The current seat availability information for each train is given as strings S_1, S_2, \dots, S_N. Here, S_1, S_2, \dots, S_N all have length 5, and columns A through E of train i correspond to the first through fifth characters of S_i, respectively. If that character is o, there is a vacant seat in the corresponding column; if it is x, there is no vacant seat in the corresponding column.

Takahashi wants to reserve a seat in column X, where X is one of A, B, C, D, E. Determine whether there is a vacant seat in column X on at least one train.

Constraints

  • N is an integer between 1 and 100, inclusive.
  • X is one of A, B, C, D, E.
  • S_i is a string of length 5 consisting of o and x.

Input

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

N X
S_1
S_2
\vdots
S_N

Output

If there is a vacant seat in column X on at least one train, output Yes; otherwise, output No.


Sample Input 1

3 A
xoxox
xxooo
oxxxx

Sample Output 1

Yes

Train 3 has a vacant seat in column A. Thus, output Yes.


Sample Input 2

5 C
xoxoo
oxxoo
oxxxo
xoxxx
oxxoo

Sample Output 2

No

No train has a vacant seat in column C. Thus, output No.

C - Tallest at the Moment

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

配点 : 300

問題文

現在、会議室に N 人の高橋くんがいます。 i 番目 (1\le i\le N) の高橋くんの身長は H _ i であり、今から L _ i 分後に会議室を去ります。 一度会議室を去った高橋くんはそれ以降会議室に戻ることはありません。

Q 個のクエリが与えられるので、順に答えてください。 i 番目 (1\le i\le Q) のクエリでは整数 T _ i が与えられるので、今から T _ i+\dfrac12 分後に会議室にいる高橋くんの身長の最大値を答えてください。 この問題の制約のもとで、今から T _ i+\dfrac12 分後には会議室に 1 人以上の高橋くんがいることが保証されます。

制約

  • 1\le N\le3\times10 ^ 5
  • 1\le H _ i\le10 ^ 9\ (1\le i\le N)
  • 1\le L _ 1\le L _ 2\le\cdots\le L _ N\le10 ^ 9
  • 1\le Q\le3\times10 ^ 5
  • 0\le T _ i\lt L _ N\ (1\le i\le Q)
  • 入力はすべて整数

入力

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

N
H _ 1 L _ 1
H _ 2 L _ 2
\vdots
H _ N L _ N
Q
T _ 1 T _ 2 \ldots T _ Q

出力

Q 行にわたって出力せよ。 i 行目 (1\le i\le Q) には、i 番目のクエリに対する答えを出力せよ。


入力例 1

4
31 4
26 5
3 5
15 9
4
3 4 5 6

出力例 1

31
26
15
15

今から 3+\dfrac12 分後には、現在会議室にいる高橋くんは全員会議室にとどまっています。 よって、1 番目のクエリの答えは \lbrace31,26,3,15\rbrace の最大値である 31 です。

今から 5+\dfrac12 分後には、会議室には 4 番目の高橋くんだけがいます。 よって、3 番目のクエリの答えは \lbrace15\rbrace の最大値である 15 です。


入力例 2

10
587 138
772 155
755 404
519 408
529 432
169 586
114 632
249 656
329 972
299 984
14
443 801 824 276 399 314 300 510 311 580 498 930 359 5

出力例 2

329
329
329
755
755
755
755
329
755
329
329
329
755
772

Score : 300 points

Problem Statement

Currently, there are N Takahashi in a conference room. The i-th (1\le i\le N) Takahashi has a height of H _ i and will leave the room L _ i minutes from now. Once a Takahashi leaves the room, he never returns.

You are given Q queries, so answer them in order. For the i-th (1\le i\le Q) query, you are given an integer T _ i, so find the maximum height among the Takahashi who are in the room T _ i+\dfrac12 minutes from now. Under the constraints of this problem, it is guaranteed that at least one Takahashi will be in the room T _ i+\dfrac12 minutes from now.

Constraints

  • 1\le N\le3\times10 ^ 5
  • 1\le H _ i\le10 ^ 9\ (1\le i\le N)
  • 1\le L _ 1\le L _ 2\le\cdots\le L _ N\le10 ^ 9
  • 1\le Q\le3\times10 ^ 5
  • 0\le T _ i\lt L _ N\ (1\le i\le Q)
  • All input values are integers.

Input

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

N
H _ 1 L _ 1
H _ 2 L _ 2
\vdots
H _ N L _ N
Q
T _ 1 T _ 2 \ldots T _ Q

Output

Output Q lines. The i-th line (1\le i\le Q) should contain the answer to the i-th query.


Sample Input 1

4
31 4
26 5
3 5
15 9
4
3 4 5 6

Sample Output 1

31
26
15
15

3+\dfrac12 minutes from now, all Takahashi currently in the room are still there. Thus, the answer to the first query is 31, the maximum of \lbrace31,26,3,15\rbrace.

5+\dfrac12 minutes from now, only the fourth Takahashi is in the room. Thus, the answer to the third query is 15, the maximum of \lbrace15\rbrace.


Sample Input 2

10
587 138
772 155
755 404
519 408
529 432
169 586
114 632
249 656
329 972
299 984
14
443 801 824 276 399 314 300 510 311 580 498 930 359 5

Sample Output 2

329
329
329
755
755
755
755
329
755
329
329
329
755
772
D - Maximize the Gap

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

配点 : 400

問題文

数直線上に N 枚の布があります。 i 枚目 (1\le i\le N) の布は数直線上の区間 \lbrack L _ i,R _ i\rbrack を覆っています。 数直線上の点は 2 枚以上の布で覆われていることも、どの布にも覆われていないこともあります。

2 枚の布が重なっているとは、数直線上のある点がその 2 枚の布どちらにも覆われていることをいいます。

重なっていない 2 枚の布について、それらの距離を以下のように定めます。

  • 一方の布に覆われている点 p ともう一方の布に覆われている点 q に対する |p-q| の最小値

どの 2 枚も重なっていない K 枚の布に対して、そのスコアを布どうしの距離の最小値と定めます。 N 枚の布からどの 2 枚も重なっていないように K 枚を選ぶときのスコアの最大値を求めてください。

ただし、そのように K 枚の布を選ぶことができない場合、-1 を出力してください。

制約

  • 2\le K\le N\le2\times10 ^ 5
  • 0\le L _ i\lt R _ i\le10 ^ 9\ (1\le i\le N)
  • 入力はすべて整数

入力

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

N K
L _ 1 R _ 1
L _ 2 R _ 2
\vdots
L _ N R _ N

出力

答えを出力せよ。


入力例 1

6 3
1 12
2 7
5 9
9 13
10 18
15 20

出力例 1

2

2 枚目、4 枚目、6 枚目の布を選ぶと、これらはどの 2 枚も重なっていません。 2 枚目の布と 4 枚目の布の距離は 22 枚目の布と 6 枚目の布の距離は 84 枚目の布と 6 枚目の布の距離は 2 なので、この選び方のスコアは 2 です。

スコアが 3 以上になるように 3 枚の布を選ぶことはできないため、2 を出力してください。


入力例 2

2 2
1 5
5 9

出力例 2

-1

与えられた 2 枚の布は重なっているので、どの 2 枚も重なっていないように 2 枚の布を選ぶことはできません。 よって、-1 を出力してください。

1 枚目の布と 2 枚目の布は一点 5 でのみ重なっていることに注意してください。


入力例 3

20 5
169 748
329 586
529 972
432 520
408 587
138 250
114 656
299 632
755 984
404 772
155 506
832 854
353 465
374 387
384 567
555 631
428 951
104 705
405 530
102 258

出力例 3

35

Score : 400 points

Problem Statement

There are N cloths on a number line. The i-th (1\le i\le N) cloth covers the interval \lbrack L _ i,R _ i\rbrack on the line. A point on the line may be covered by two or more cloths, or not covered by any cloth.

Two cloths are said to overlap if some point on the line is covered by both of those cloths.

For two cloths that do not overlap, define their distance as follows:

  • The minimum value of |p-q| over all points p covered by one cloth and all points q covered by the other cloth.

For K cloths no two of which overlap, define their score as the minimum distance among all pairs of those cloths. Find the maximum possible score when choosing K cloths from the N cloths so that no two of the chosen cloths overlap.

If it is impossible to choose K such cloths, output -1.

Constraints

  • 2\le K\le N\le2\times10 ^ 5
  • 0\le L _ i\lt R _ i\le10 ^ 9\ (1\le i\le N)
  • All input values are integers.

Input

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

N K
L _ 1 R _ 1
L _ 2 R _ 2
\vdots
L _ N R _ N

Output

Output the answer.


Sample Input 1

6 3
1 12
2 7
5 9
9 13
10 18
15 20

Sample Output 1

2

Choosing the second, fourth, and sixth cloths, no two of these overlap. The distance between the second and fourth cloths is 2, the distance between the second and sixth cloths is 8, and the distance between the fourth and sixth cloths is 2, so the score of this choice is 2.

It is impossible to choose three cloths with a score of 3 or more, so output 2.


Sample Input 2

2 2
1 5
5 9

Sample Output 2

-1

The given two cloths overlap, so it is impossible to choose two cloths so that no two overlap. Thus, output -1.

Note that the first and second cloths overlap only at the single point 5.


Sample Input 3

20 5
169 748
329 586
529 972
432 520
408 587
138 250
114 656
299 632
755 984
404 772
155 506
832 854
353 465
374 387
384 567
555 631
428 951
104 705
405 530
102 258

Sample Output 3

35
E - Roads and Gates

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

配点 : 450

問題文

AtCoder 国には N 個の都市と M 本の道路があります。 i 本目の道路 (1\le i\le M) は都市 u _ i と都市 v _ i を双方向に繋いでおり、一方からもう一方へ T _ i 分かけて移動することができます。

また、それぞれの都市にはワープゲートが設置されており、都市 i\ (1\le i\le N) から都市 j\ (1\le j\le N) へワープゲートを使って X _ i+X _ j+Y 分かけて移動することができます。

これ以外の方法で AtCoder 国の都市の間を移動することはできません。

k=2,3,\ldots,N について、次の問題を解いてください。

  • 都市 1 から都市 k へ移動するのにかかる時間の最小値を求めよ。

ただし、道路やワープゲートから同じ都市の別の道路やワープゲートへ移動するのにかかる時間は無視できるものとします。

制約

  • 2\le N\le2\times10 ^ 5
  • 0\le M\le2\times10 ^ 5
  • 1\le u _ i\lt v _ i\le N\ (1\le i\le M)
  • 1\le T _ i\le10 ^ 9\ (1\le i\le M)
  • 1\le X _ i\le10 ^ 9\ (1\le i\le N)
  • 1\le Y\le 10 ^ 9
  • 入力はすべて整数

入力

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

N M Y
u _ 1 v _ 1 T _ 1
u _ 2 v _ 2 T _ 2
\vdots
u _ M v _ M T _ M
X _ 1 X _ 2 \ldots X _ N

出力

k=2,3,\ldots,N に対する問題の答えを、この順に空白を区切りとして出力せよ。


入力例 1

7 7 3
1 2 1
1 3 6
2 3 4
3 5 8
3 7 4
4 5 2
4 7 9
3 1 4 1 5 9 2

出力例 1

1 5 6 8 14 7

例えば、都市 1 から都市 7 へは次のようにして 7 分で移動することができます。

  • 1 本目の道路を使い、1 分かけて都市 1 から都市 2 へ移動する。
  • ワープゲートを使い、1+2+3=6 分かけて都市 2 から都市 7 へ移動する。

都市 1 から都市 76 分以下で移動することはできないため、k=7 に対する問題の答えは 7 です。


入力例 2

2 0 1000000000
1000000000 1000000000

出力例 2

3000000000

答えが 2 ^ {31} 以上になる場合があることに注意してください。


入力例 3

12 20 873
2 7 940
6 9 444
6 11 809
7 8 786
9 10 468
7 10 234
6 10 660
4 12 939
8 10 896
1 11 953
8 10 818
4 8 967
3 9 724
6 7 929
3 4 948
1 3 999
10 11 724
7 10 338
1 8 967
1 12 733
581 978 950 629 583 729 554 712 438 930 774 279

出力例 3

2432 999 1672 2037 1762 1753 967 1723 1677 953 733

Score : 450 points

Problem Statement

The country of AtCoder has N cities and M roads. The i-th road (1\le i\le M) connects cities u _ i and v _ i bidirectionally, and allows travel from one to the other in T _ i minutes.

Additionally, each city has a warp gate installed, and you can travel from city i\ (1\le i\le N) to city j\ (1\le j\le N) using the warp gate in X _ i+X _ j+Y minutes.

There are no other ways to travel between cities in the country.

For each k=2,3,\ldots,N, solve the following problem:

  • Find the minimum time required to travel from city 1 to city k.

The time required to transfer from a road or warp gate to another road or warp gate at the same city is negligible.

Constraints

  • 2\le N\le2\times10 ^ 5
  • 0\le M\le2\times10 ^ 5
  • 1\le u _ i\lt v _ i\le N\ (1\le i\le M)
  • 1\le T _ i\le10 ^ 9\ (1\le i\le M)
  • 1\le X _ i\le10 ^ 9\ (1\le i\le N)
  • 1\le Y\le 10 ^ 9
  • All input values are integers.

Input

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

N M Y
u _ 1 v _ 1 T _ 1
u _ 2 v _ 2 T _ 2
\vdots
u _ M v _ M T _ M
X _ 1 X _ 2 \ldots X _ N

Output

Output the answers to the problems for k=2,3,\ldots,N in this order, separated by spaces.


Sample Input 1

7 7 3
1 2 1
1 3 6
2 3 4
3 5 8
3 7 4
4 5 2
4 7 9
3 1 4 1 5 9 2

Sample Output 1

1 5 6 8 14 7

For example, you can travel from city 1 to city 7 in 7 minutes as follows:

  • Use the first road to travel from city 1 to city 2 in 1 minute.
  • Use the warp gate to travel from city 2 to city 7 in 1+2+3=6 minutes.

It is impossible to travel from city 1 to city 7 in 6 minutes or less, so the answer for k=7 is 7.


Sample Input 2

2 0 1000000000
1000000000 1000000000

Sample Output 2

3000000000

Note that the answer may be 2 ^ {31} or greater.


Sample Input 3

12 20 873
2 7 940
6 9 444
6 11 809
7 8 786
9 10 468
7 10 234
6 10 660
4 12 939
8 10 896
1 11 953
8 10 818
4 8 967
3 9 724
6 7 929
3 4 948
1 3 999
10 11 724
7 10 338
1 8 967
1 12 733
581 978 950 629 583 729 554 712 438 930 774 279

Sample Output 3

2432 999 1672 2037 1762 1753 967 1723 1677 953 733
F - Senshuraku

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

配点 : 500

問題文

2N 人の選手が参加する大会が行われています。 これから、それぞれの選手は 1 回試合を行います。 残る N 回の試合のうち、i 番目 (1\le i\le N) の試合では 2i-1 番目の選手と 2i 番目の選手が対戦を行います。

それぞれの試合では、対戦する 2 人の選手のうち 1 人が勝ち、もう 1 人が負けます。 どちらの選手が勝つかは試合ごとに独立に確率 \dfrac12 で決まります。

最後の N 試合が始まる前、i 番目 (1\le i\le2N) の選手は A _ i 回勝っています。 すべての試合が終わったあと、勝った回数が最も多い選手の中から一様ランダムかつこれまでの試合結果と独立に優勝選手が選ばれます。

1 番目の選手、2 番目の選手、\ldots2N 番目の選手のそれぞれについて、優勝する確率を{}\bmod998244353 で求めてください。

確率{}\bmod{998244353} の定義

求める確率は必ず有理数になることが証明できます。 また、この問題の制約のもとでは、求める有理数を既約分数 \frac{P}{Q} で表した時、Q {{}\not\equiv{}} 0 \pmod{998244353} となることが証明できます。 よって、R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353 を満たす整数 R が一意に定まります。 この R を答えてください。

制約

  • 1\le N\le2\times10 ^ 5
  • 0\le A _ i\lt2N\ (1\le i\le 2N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2
A _ 3 A _ 4
\vdots
A _ {2N-1} A _ {2N}

出力

1 番目の選手が優勝する確率、2 番目の選手が優勝する確率、\ldots2N 番目の選手が優勝する確率を、この順に空白を区切りとして 1 行に出力せよ。


入力例 1

4
1 2
3 4
2 3
1 4

出力例 1

0 0 259959467 883862188 0 967049217 0 883862188

例えば、3 番目の選手が優勝するのは次のような場合です。

  • 2 番目の試合で自分が勝ち、3 番目の試合で 5 番目の選手が勝ち、4 番目の試合で 7 番目の選手が勝った場合、\dfrac13 の確率で優勝する。
  • 2 番目の試合で自分が勝ち、3 番目の試合で 6 番目の選手が勝ち、4 番目の試合で 7 番目の選手が勝った場合、\dfrac14 の確率で優勝する。

よって、3 番目の選手が優勝する確率は \dfrac18\times\dfrac13+\dfrac18\times\dfrac14=\dfrac7{96} です。259959467\times96\equiv7\pmod{998244353} なので、3 番目の選手が優勝する確率は{}\bmod998244353259959467 です。

それぞれの選手が優勝する確率は 0,0,\dfrac7{96},\dfrac{43}{96},0,\dfrac3{96},0,\dfrac{43}{96} です。 よって、0 0 259959467 883862188 0 967049217 0 883862188 を出力してください。


入力例 2

6
0 0
0 0
0 0
0 0
0 0
0 0

出力例 2

582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206

これまで誰も勝利していない場合もあります。

対称性より、どの選手が優勝する確率も \dfrac1{12} です。


入力例 3

10
18 17
16 18
18 16
16 16
17 17
16 16
17 16
17 18
16 16
17 18

出力例 3

357877533 151989635 0 357877533 357877533 0 0 0 575116994 575116994 0 0 597386855 0 151989635 357877533 0 0 151989635 357877533

Score : 500 points

Problem Statement

A tournament is being held with 2N players. From now on, each player will play exactly one match. In the remaining N matches, the i-th (1\le i\le N) match is played between the (2i-1)-th and 2i-th players.

In each match, one of the two competing players wins and the other loses. Which player wins is determined independently for each match, and each player wins with probability \dfrac12.

Before the last N matches begin, the i-th (1\le i\le2N) player has won A _ i times. After all matches are over, the champion is chosen from among the players with the most wins, uniformly at random and independently of the previous match results.

For each of the first, second, \ldots, 2N-th players, find the probability, modulo 998244353, of that player becoming the champion.

Definition of probability modulo 998244353

It can be proved that the sought probability is always a rational number. Moreover, under the constraints of this problem, it can be proved that when the rational number is expressed as an irreducible fraction \frac{P}{Q}, we have Q {{}\not\equiv{}} 0 \pmod{998244353}. Therefore, there is a unique integer R satisfying R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353. Find this R.

Constraints

  • 1\le N\le2\times10 ^ 5
  • 0\le A _ i\lt2N\ (1\le i\le 2N)
  • All input values are integers.

Input

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

N
A _ 1 A _ 2
A _ 3 A _ 4
\vdots
A _ {2N-1} A _ {2N}

Output

Output the probability of the first player becoming the champion, the probability of the second player becoming the champion, \ldots, the probability of the 2N-th player becoming the champion, in this order, separated by spaces, on a single line.


Sample Input 1

4
1 2
3 4
2 3
1 4

Sample Output 1

0 0 259959467 883862188 0 967049217 0 883862188

For example, the third player becomes the champion in the following cases:

  • If the third player wins in the second match, the fifth player wins in the third match, and the seventh player wins in the fourth match, the third player becomes the champion with probability \dfrac13.
  • If the third player wins in the second match, the sixth player wins in the third match, and the seventh player wins in the fourth match, the third player becomes the champion with probability \dfrac14.

Thus, the probability of the third player becoming the champion is \dfrac18\times\dfrac13+\dfrac18\times\dfrac14=\dfrac7{96}. We have 259959467\times96\equiv7\pmod{998244353}, so the probability of the third player becoming the champion in modulo-998244353 expression is 259959467.

The probability of each player becoming the champion is 0,0,\dfrac7{96},\dfrac{43}{96},0,\dfrac3{96},0,\dfrac{43}{96}. Thus, output 0 0 259959467 883862188 0 967049217 0 883862188.


Sample Input 2

6
0 0
0 0
0 0
0 0
0 0
0 0

Sample Output 2

582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206 582309206

It is possible that no one has won yet.

By symmetry, each player becomes the champion with probability \dfrac1{12}.


Sample Input 3

10
18 17
16 18
18 16
16 16
17 17
16 16
17 16
17 18
16 16
17 18

Sample Output 3

357877533 151989635 0 357877533 357877533 0 0 0 575116994 575116994 0 0 597386855 0 151989635 357877533 0 0 151989635 357877533
G - Random Walk Distance

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

配点 : 600

問題文

正整数 N および整数 X が与えられます。

高橋君が数直線上の座標 0 にいます。 高橋君はこれから N 回、以下の移動を行います。

  • 座標 x にいるとき、座標 x-1 または座標 x+1 のどちらかを等確率で選び、そこに移動する。

ただし N 回の移動での移動先の選択はすべて独立です。 N 回の移動を全て終えた後の座標を x' とします。|x'-X| の期待値を \bmod{998244353} で求めてください。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

期待値 \bmod{998244353} の定義

求める期待値は必ず有理数になることが証明できます。 また、この問題の制約のもとでは、その値を既約分数 \frac{P}{Q} で表した時、Q {{}\not\equiv{}} 0 \pmod{998244353} となることも証明できます。 よって、R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 を満たす整数 R が一意に定まります。 この R を答えてください。

制約

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • |X| \leq 2 \times 10^5
  • 入力はすべて整数

入力

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

\mathrm{case}_ii 番目のテストケースであり、以下の形式で与えられる。

N X

出力

T 行出力せよ。 i 行目には i 番目のテストケースについての答えを出力せよ。


入力例 1

5
3 2
6 4
2026 -620
12345 67890
98765 -43210

出力例 1

748683267
935854085
270602660
67890
844852181

1 番目のテストケースについて、最終的に高橋君は確率 \frac{1}{8} で座標 -3 に、確率 \frac{3}{8} で座標 -1 に、確率 \frac{3}{8} で座標 1 に、確率 \frac{1}{8} で座標 3 にいます。 したがって |x'-X| の期待値は \frac{1}{8}\cdot|{-3}-2|+\frac{3}{8}\cdot|{-1}-2|+\frac{3}{8}\cdot|1-2|+\frac{1}{8}\cdot|3-2|=\frac{9}{4} です。

Score : 600 points

Problem Statement

You are given a positive integer N and an integer X.

Takahashi is at coordinate 0 on a number line. He will now perform the following move N times:

  • When at coordinate x, choose coordinate x-1 or coordinate x+1 with equal probability and move there.

The choices of destination across the N moves are all independent. Let x' be the coordinate after all N moves. Find the expected value, modulo 998244353, of |x'-X|.

You are given T test cases; solve each of them.

Definition of expected value modulo 998244353

It can be proved that the sought expected value is always a rational number. Moreover, under the constraints of this problem, it can be proved that when expressed as an irreducible fraction \frac{P}{Q}, we have Q {{}\not\equiv{}} 0 \pmod{998244353}. Therefore, there is a unique integer R satisfying R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353. Find this R.

Constraints

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • |X| \leq 2 \times 10^5
  • All input values are integers.

Input

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

Each \mathrm{case}_i is the i-th test case and is given in the following format:

N X

Output

Output T lines. The i-th line should contain the answer for the i-th test case.


Sample Input 1

5
3 2
6 4
2026 -620
12345 67890
98765 -43210

Sample Output 1

748683267
935854085
270602660
67890
844852181

For the first test case, Takahashi ends up at coordinate -3 with probability \frac{1}{8}, at coordinate -1 with probability \frac{3}{8}, at coordinate 1 with probability \frac{3}{8}, and at coordinate 3 with probability \frac{1}{8}. Thus, the expected value of |x'-X| is \frac{1}{8}\cdot|{-3}-2|+\frac{3}{8}\cdot|{-1}-2|+\frac{3}{8}\cdot|1-2|+\frac{1}{8}\cdot|3-2|=\frac{9}{4}.