A - wwwvvvvvv

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

vw のみからなる文字列 S が与えられます。

S の中に、下に尖っている部分が何箇所あるかを出力してください(入出力例にある図もご参照ください)。

制約

  • Svw のみからなる文字列
  • S の長さは 1 以上 100 以下

入力

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

S

出力

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


入力例 1

vvwvw

出力例 1

7

vvwvw

上の画像のように、vvwvw という文字列には下に尖った部分が 7 箇所あります。


入力例 2

v

出力例 2

1

入力例 3

wwwvvvvvv

出力例 3

12

Score : 100 points

Problem Statement

You are given a string S consisting of v and w.

Print the number of "bottoms" in the string S (see the figure at Sample Input/Output).

Constraints

  • S is a string consisting of v and w.
  • The length of S is between 1 and 100, inclusive.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

vvwvw

Sample Output 1

7

vvwvw

The image above shows the seven "bottoms" in the string vvwvw.


Sample Input 2

v

Sample Output 2

1

Sample Input 3

wwwvvvvvv

Sample Output 3

12
B - LOOKUP

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

英小文字からなる文字列 S,T が与えられるので、 TS の(連続する)部分文字列かどうか判定してください。

なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り YX の(連続する)部分文字列であると言います。

  • 以下の 2 つの操作から 1 つを選択して、その操作を行う。
    • X の先頭の 1 文字を削除する。
    • X の末尾の 1 文字を削除する。

例えば tagvoltage の(連続する)部分文字列ですが、 aceatcoder の(連続する)部分文字列ではありません。

制約

  • S,T は英小文字からなる
  • 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )

入力

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

S
T

出力

TS の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。


入力例 1

voltage
tag

出力例 1

Yes

tagvoltage の(連続する)部分文字列です。


入力例 2

atcoder
ace

出力例 2

No

aceatcoder の(連続する)部分文字列ではありません。


入力例 3

gorilla
gorillagorillagorilla

出力例 3

No

入力例 4

toyotasystems
toyotasystems

出力例 4

Yes

S=T である場合もあります。

Score : 200 points

Problem Statement

You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.

A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.

  • Do one of the following.
    • Delete the first character in X.
    • Delete the last character in X.

For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.

Constraints

  • S and T consist of lowercase English letters.
  • 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)

Input

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

S
T

Output

If T is a (contiguous) substring of S, print Yes; otherwise, print No.


Sample Input 1

voltage
tag

Sample Output 1

Yes

tag is a (contiguous) substring of voltage.


Sample Input 2

atcoder
ace

Sample Output 2

No

ace is not a (contiguous) substring of atcoder.


Sample Input 3

gorilla
gorillagorillagorilla

Sample Output 3

No

Sample Input 4

toyotasystems
toyotasystems

Sample Output 4

Yes

It is possible that S=T.

C - RANDOM

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

#. からなる HW 列の図形 S,T が与えられます。
図形 SH 個の文字列として与えられ、 S_ij 文字目は Sij 列にある要素を表します。 T についても同様です。

S の列を並べ替えて T と等しくできるか判定してください。

但し、図形 X の列を並べ替えるとは、以下の操作を言います。

  • (1,2,\dots,W) の順列 P=(P_1,P_2,\dots,P_W) をひとつ選択する。
  • その後、全ての 1 \le i \le H を満たす整数 i について、以下の操作を同時に行う。
    • 1 \le j \le W を満たす全ての整数 j について同時に、 Xij 列にある要素を iP_j 列にある要素に置き換える。

制約

  • H,W は整数
  • 1 \le H,W
  • 1 \le H \times W \le 4 \times 10^5
  • S_i,T_i#. からなる長さ W の文字列

入力

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

H W
S_1
S_2
\vdots
S_H
T_1
T_2
\vdots
T_H

出力

ST と等しくできるなら Yes 、 そうでないなら No と出力せよ。


入力例 1

3 4
##.#
##..
#...
.###
..##
...#

出力例 1

Yes

例えば S3,4,2,1 列目をこの順に左から並べ替えた場合、 ST と等しくできます。


入力例 2

3 3
#.#
.#.
#.#
##.
##.
.#.

出力例 2

No

この入力では、 ST と等しくすることができません。


入力例 3

2 1
#
.
#
.

出力例 3

Yes

S=T である場合もあります。


入力例 4

8 7
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
....###
####...
....###
####...
....###
####...
....###
####...

出力例 4

Yes

Score : 300 points

Problem Statement

You are given patterns S and T consisting of # and ., each with H rows and W columns.
The pattern S is given as H strings, and the j-th character of S_i represents the element at the i-th row and j-th column. The same goes for T.

Determine whether S can be made equal to T by rearranging the columns of S.

Here, rearranging the columns of a pattern X is done as follows.

  • Choose a permutation P=(P_1,P_2,\dots,P_W) of (1,2,\dots,W).
  • Then, for every integer i such that 1 \le i \le H, simultaneously do the following.
    • For every integer j such that 1 \le j \le W, simultaneously replace the element at the i-th row and j-th column of X with the element at the i-th row and P_j-th column.

Constraints

  • H and W are integers.
  • 1 \le H,W
  • 1 \le H \times W \le 4 \times 10^5
  • S_i and T_i are strings of length W consisting of # and ..

Input

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

H W
S_1
S_2
\vdots
S_H
T_1
T_2
\vdots
T_H

Output

If S can be made equal to T, print Yes; otherwise, print No.


Sample Input 1

3 4
##.#
##..
#...
.###
..##
...#

Sample Output 1

Yes

If you, for instance, arrange the 3-rd, 4-th, 2-nd, and 1-st columns of S in this order from left to right, S will be equal to T.


Sample Input 2

3 3
#.#
.#.
#.#
##.
##.
.#.

Sample Output 2

No

In this input, S cannot be made equal to T.


Sample Input 3

2 1
#
.
#
.

Sample Output 3

Yes

It is possible that S=T.


Sample Input 4

8 7
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
....###
####...
....###
####...
....###
####...
....###
####...

Sample Output 4

Yes
D - Freefall

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

スーパーマンである高橋くんは、地上で困っている人を助けるため、あるビルの屋上から飛び降りようとしています。 高橋くんがいる星には重力の大きさを表す g という値が定まっており、 高橋くんが落下を開始してから地面に到達するまでにかかる時間は \frac{A}{\sqrt{g}} です。

現在の時刻は 0 であり、g = 1 が成り立ちます。 高橋くんは、今から次の操作を好きな回数(0 回でもよい)行います。

  • 超能力により g の値を 1 増やす。時間が B 経過する。

その後、高橋くんはビルから飛び降ります。落下を開始した後は g の値を変えることはできません。 また、操作によって経過する時間と落下にかかる時間以外は考えないものとします。

高橋くんが地面に到達できる最も早い時刻を求めてください。

制約

  • 1 \leq A \leq 10^{18}
  • 1 \leq B \leq 10^{18}
  • 入力は全て整数

入力

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

A B

出力

高橋くんが地面に到達できる最も早い時刻を出力せよ。 出力は、真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。


入力例 1

10 1

出力例 1

7.7735026919
  • 操作を 0 回行うとき、地面に到達する時刻は 1\times 0+\frac{10}{\sqrt{1}} = 10 です。
  • 操作を 1 回行うとき、地面に到達する時刻は 1\times 1+\frac{10}{\sqrt{2}} \fallingdotseq 8.07 です。
  • 操作を 2 回行うとき、地面に到達する時刻は 1\times 2+\frac{10}{\sqrt{3}} \fallingdotseq 7.77 です。
  • 操作を 3 回行うとき、地面に到達する時刻は 1\times 3+\frac{10}{\sqrt{4}} = 8 です。

操作を 4 回以上行っても、地面への到達時刻は遅くなるのみです。 よって、操作を 2 回行ってから飛び降りるのが最適で、答えは 2+\frac{10}{\sqrt{3}} です。


入力例 2

5 10

出力例 2

5.0000000000

操作を 1 回も行わないのが最適です。


入力例 3

1000000000000000000 100

出力例 3

8772053214538.5976562500

Score : 400 points

Problem Statement

A superman, Takahashi, is about to jump off the roof of a building to help a person in trouble on the ground. Takahashi's planet has a constant value g that represents the strength of gravity, and the time it takes for him to reach the ground after starting to fall is \frac{A}{\sqrt{g}}.

It is now time 0, and g = 1. Takahashi will perform the following operation as many times as he wants (possibly zero).

  • Use a superpower to increase the value of g by 1. This takes a time of B.

Then, he will jump off the building. After starting to fall, he cannot change the value of g. Additionally, we only consider the time it takes to perform the operation and fall.

Find the earliest time Takahashi can reach the ground.

Constraints

  • 1 \leq A \leq 10^{18}
  • 1 \leq B \leq 10^{18}
  • All values in the input are integers.

Input

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

A B

Output

Print the earliest time Takahashi can reach the ground. Your output will be accepted when its absolute or relative error from the true value is at most 10^{-6}.


Sample Input 1

10 1

Sample Output 1

7.7735026919
  • If he performs the operation zero times, he will reach the ground at time 1\times 0+\frac{10}{\sqrt{1}} = 10.
  • If he performs the operation once, he will reach the ground at time 1\times 1+\frac{10}{\sqrt{2}} \fallingdotseq 8.07.
  • If he performs the operation twice, he will reach the ground at time 1\times 2+\frac{10}{\sqrt{3}} \fallingdotseq 7.77.
  • If he performs the operation three times, he will reach the ground at time 1\times 3+\frac{10}{\sqrt{4}} = 8.

Performing the operation four or more times will only delay the time to reach the ground. Therefore, it is optimal to perform the operation twice before jumping off, and the answer is 2+\frac{10}{\sqrt{3}}.


Sample Input 2

5 10

Sample Output 2

5.0000000000

It is optimal not to perform the operation at all.


Sample Input 3

1000000000000000000 100

Sample Output 3

8772053214538.5976562500
E - Cheating Amidakuji

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

1 以上 N-1 以下の整数からなる長さ M の数列 A=(A_1,A_2,\dots,A_M) が与えられます。 i=1,2,\dots,M について、以下の質問に答えてください。

  • 数列 B=(B_1,B_2,\dots,B_N) がある。最初、各 j について B_j=j である。今から、k=1,2,\dots,i-1,i+1,\dots,M の順に以下の操作を行う (すなわち、i を除いた 1 以上 M 以下の整数 k について、昇順に以下の操作を行う)。
    • B_{A_k}B_{A_k+1} の値を入れ替える。
  • 全ての操作が終了した段階で、B_j=1 を満たす j の値を S_i と定義する。S_i を求めよ。

制約

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq A_i \leq N-1\ (1\leq i \leq M)
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_M

出力

M 行出力せよ。 i\ (1\leq i \leq M) 行目には、S_i の値を整数として出力せよ。


入力例 1

5 4
1 2 3 2

出力例 1

1
3
2
4

i = 2 のとき、操作によって B は以下のように変化します。

  • 最初、B = (1,2,3,4,5)
  • k=1 として操作を行う。すなわち B_1B_2 の値を入れ替えて、B = (2,1,3,4,5)
  • k=3 として操作を行う。すなわち B_3B_4 の値を入れ替えて、B = (2,1,4,3,5)
  • k=4 として操作を行う。すなわち B_2B_3 の値を入れ替えて、B = (2,4,1,3,5)

全ての操作が終了した段階で B_3=1 であるため、S_2 = 3 です。

同様に、

  • i=1 のとき:k=2,3,4 の順に操作を行うと B=(1,4,3,2,5) になるので、S_1=1
  • i=3 のとき:k=1,2,4 の順に操作を行うと B=(2,1,3,4,5) になるので、S_3=2
  • i=4 のとき:k=1,2,3 の順に操作を行うと B=(2,3,4,1,5) になるので、S_4=4

です。


入力例 2

3 3
2 2 2

出力例 2

1
1
1

入力例 3

10 10
1 1 1 9 4 4 2 1 3 3

出力例 3

2
2
2
3
3
3
1
3
4
4

Score : 500 points

Problem Statement

You are given a sequence of length M consisting of integers between 1 and N-1, inclusive: A=(A_1,A_2,\dots,A_M). Answer the following question for i=1, 2, \dots, M.

  • There is a sequence B=(B_1,B_2,\dots,B_N). Initially, we have B_j=j for each j. Let us perform the following operation for k=1, 2, \dots, i-1, i+1, \dots, M in this order (in other words, for integers k between 1 and M except i in ascending order).
    • Swap the values of B_{A_k} and B_{A_k+1}.
  • After all the operations, let S_i be the value of j such that B_j=1. Find S_i.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq A_i \leq N-1\ (1\leq i \leq M)
  • All values in the input are integers.

Input

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

N M
A_1 A_2 \dots A_M

Output

Print M lines. The i-th line (1\leq i \leq M) should contain the value S_i as an integer.


Sample Input 1

5 4
1 2 3 2

Sample Output 1

1
3
2
4

For i = 2, the operations change B as follows.

  • Initially, B = (1,2,3,4,5).
  • Perform the operation for k=1. That is, swap the values of B_1 and B_2, making B = (2,1,3,4,5).
  • Perform the operation for k=3. That is, swap the values of B_3 and B_4, making B = (2,1,4,3,5).
  • Perform the operation for k=4. That is, swap the values of B_2 and B_3, making B = (2,4,1,3,5).

After all the operations, we have B_3=1, so S_2 = 3.

Similarly, we have the following.

  • For i=1: performing the operation for k=2,3,4 in this order makes B=(1,4,3,2,5), so S_1=1.
  • For i=3: performing the operation for k=1,2,4 in this order makes B=(2,1,3,4,5), so S_3=2.
  • For i=4: performing the operation for k=1,2,3 in this order makes B=(2,3,4,1,5), so S_4=4.

Sample Input 2

3 3
2 2 2

Sample Output 2

1
1
1

Sample Input 3

10 10
1 1 1 9 4 4 2 1 3 3

Sample Output 3

2
2
2
3
3
3
1
3
4
4
F - BOX

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

N 個の箱 1,2,\dots,N と、 10^{100} 個のボール 1,2,\dots,10^{100} があります。 最初、箱 i にはボール i のみが入っています。

ここに以下の操作が合計 Q 回行われるので、処理してください。

操作にはタイプ 1,2,33 種類があります。

タイプ 1 : 箱 X に箱 Y の中身を全て入れる。 この操作では X \neq Y が保証される。

1 X Y

タイプ 2 : 現在いずれかの箱に入っているボールの数の合計を k とすると、箱 X にボール k+1 を入れる。

2 X

タイプ 3 : ボール X が入っている箱の番号を答える。

3 X

制約

  • 入力は全て整数
  • 2 \le N \le 3 \times 10^5
  • 1 \le Q \le 3 \times 10^5
  • タイプ 1 の操作について、 1 \le X,Y \le N かつ X \neq Y
  • タイプ 2 の操作について、 1 \le X \le N
  • タイプ 3 の操作について、その時点でボール X がいずれかの箱に入っている
  • タイプ 3 の操作が少なくとも 1 つ与えられる

入力

入力は以下の形式で標準入力から与えられる。
但し、 op_ii 回目の操作を表す。

N Q
op_1
op_2
\vdots
op_Q

出力

各タイプ 3 の操作に対して、答えを 1 行に 1 つ、整数として出力せよ。


入力例 1

5 10
3 5
1 1 4
2 1
2 4
3 7
1 3 1
3 4
1 1 4
3 7
3 6

出力例 1

5
4
3
1
3

この入力は 10 個の操作を含みます。

  • 1 回目の操作はタイプ 3 です。ボール 5 は箱 5 に入っています。
  • 2 回目の操作はタイプ 1 です。箱 1 に箱 4 の中身を全て入れます。
    • 1 の中身はボール 1,4 、箱 4 の中身は空になります。
  • 3 回目の操作はタイプ 2 です。箱 1 にボール 6 を入れます。
  • 4 回目の操作はタイプ 2 です。箱 4 にボール 7 を入れます。
  • 5 回目の操作はタイプ 3 です。ボール 7 は箱 4 に入っています。
  • 6 回目の操作はタイプ 1 です。箱 3 に箱 1 の中身を全て入れます。
    • 3 の中身はボール 1,3,4,6 、箱 1 の中身は空になります。
  • 7 回目の操作はタイプ 3 です。ボール 4 は箱 3 に入っています。
  • 8 回目の操作はタイプ 1 です。箱 1 に箱 4 の中身を全て入れます。
    • 1 の中身はボール 7 、箱 4 の中身は空になります。
  • 9 回目の操作はタイプ 3 です。ボール 7 は箱 1 に入っています。
  • 10 回目の操作はタイプ 3 です。ボール 6 は箱 3 に入っています。

Score : 500 points

Problem Statement

There are N boxes numbered 1,2,\ldots,N, and 10^{100} balls numbered 1,2,\dots,10^{100}. Initially, box i contains just ball i.

Process a total of Q operations that will be performed.

There are three types of operations: 1, 2, and 3.

Type 1: Put all contents of box Y into box X. It is guaranteed that X \neq Y.

1 X Y

Type 2: Put ball k+1 into box X, where k is the current total number of balls contained in the boxes.

2 X

Type 3: Report the number of the box that contains ball X.

3 X

Constraints

  • All values in the input are integers.
  • 2 \le N \le 3 \times 10^5
  • 1 \le Q \le 3 \times 10^5
  • For each type-1 operation, 1 \le X,Y \le N and X \neq Y.
  • For each type-2 operation, 1 \le X \le N.
  • For each type-3 operation, ball X is contained in some box at that point.
  • There is at least one type-3 operation.

Input

The input is given from Standard Input in the following format.
Here, op_i represents the i-th operation.

N Q
op_1
op_2
\vdots
op_Q

Output

For each type-3 operation, print a line containing the response as an integer.


Sample Input 1

5 10
3 5
1 1 4
2 1
2 4
3 7
1 3 1
3 4
1 1 4
3 7
3 6

Sample Output 1

5
4
3
1
3

This input contains ten operations.

  • The first operation is of type 3. Ball 5 is in box 5.
  • The second operation is of type 1. Put all contents of box 4 into box 1.
    • Box 1 now contains balls 1 and 4, and box 4 is now empty.
  • The third operation is of type 2. Put ball 6 into box 1.
  • The fourth operation is of type 2. Put ball 7 into box 4.
  • The fifth operation is of type 3. Ball 7 is in box 4.
  • The sixth operation is of type 1. Put all contents of box 1 into box 3.
    • Box 3 now contains balls 1, 3, 4, and 6, and box 1 is now empty.
  • The seventh operation is of type 3. Ball 4 is in box 3.
  • The eighth operation is of type 1. Put all contents of box 4 into box 1.
    • Box 1 now contains ball 7, and box 4 is now empty.
  • The ninth operation is of type 3. Ball 7 is in box 1.
  • The tenth operation is of type 3. Ball 6 is in box 3.
G - At Most 2 Colors

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

1 \times N のマス目があり、マスには左から 1,2,\dots,N の番号が付いています。

高橋君は C 色の絵の具を用意し、各マスを C 色のいずれかで塗りました。
すると、どの連続する K マスを見ても高々 2 色しか現れませんでした。
厳密には、 1 \le i \le N-K+1 を満たす全ての整数 i について、マス i,i+1,\dots,i+K-1 には高々 2 色しか現れませんでした。

高橋君の色の塗り方として考えられるものは何通りですか?
この数は非常に大きくなる場合があるので、 998244353 で割った余りを求めてください。

制約

  • 入力は全て整数
  • 2 \le K \le N \le 10^6
  • 1 \le C \le 10^9

入力

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

N K C

出力

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


入力例 1

3 3 3

出力例 1

21

この入力では、マス目は 1 \times 3 です。
連続する 3 マスの中で高々 2 色しか現れないように塗る方法は、考えうる全ての塗り方 27 通りから全てのマスを異なる色で塗る 6 通りを引いた 21 通りです。


入力例 2

10 5 2

出力例 2

1024

C=2 なので、どのように塗っても連続する K マスには高々 2 色しか含まれません。


入力例 3

998 244 353

出力例 3

952364159

998244353 で割った余りを出力してください。

Score : 600 points

Problem Statement

There is a grid with 1 \times N squares, numbered 1,2,\dots,N from left to right.

Takahashi prepared paints of C colors and painted each square in one of the C colors.
Then, there were at most two colors in any consecutive K squares.
Formally, for every integer i such that 1 \le i \le N-K+1, there were at most two colors in squares i,i+1,\dots,i+K-1.

In how many ways could Takahashi paint the squares?
Since this number can be enormous, find it modulo 998244353.

Constraints

  • All values in the input are integers.
  • 2 \le K \le N \le 10^6
  • 1 \le C \le 10^9

Input

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

N K C

Output

Print the answer as an integer.


Sample Input 1

3 3 3

Sample Output 1

21

In this input, we have a 1 \times 3 grid.
Among the 27 ways to paint the squares, there are 6 ways to paint all squares in different colors, and the remaining 21 ways are such that there are at most two colors in any consecutive three squares.


Sample Input 2

10 5 2

Sample Output 2

1024

Since C=2, no matter how the squares are painted, there are at most two colors in any consecutive K squares.


Sample Input 3

998 244 353

Sample Output 3

952364159

Print the number modulo 998244353.

Ex - Sum of Prod of Min

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

正整数 N,M が与えられます。ただし、N\leq M \leq 2N が保証されます。

\displaystyle \sum_{i=1}^{N} S_i = M を満たす全ての正整数列 S=(S_1,S_2,\dots,S_N) について以下の値を求め、 その総和を素数 200\ 003 で割った余りを出力してください (通常とは異なる \bmod の値に注意してください)。

  • \displaystyle \prod_{k=1}^{N} \min(k,S_k)

制約

  • 1 \leq N \leq 10^{12}
  • N \leq M \leq 2N
  • 入力は全て整数

入力

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

N M

出力

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


入力例 1

3 5

出力例 1

14

条件を満たす S は、 S=(1,1,3), S=(1,2,2), S=(1,3,1), S=(2,1,2), S=(2,2,1), S=(3,1,1)6 つです。

それぞれの S について \displaystyle \prod_{k=1}^{N} \min(k,S_k) の値を求めると、

  • S=(1,1,3) : 1\times 1 \times 3 = 3
  • S=(1,2,2) : 1\times 2 \times 2 = 4
  • S=(1,3,1) : 1\times 2 \times 1 = 2
  • S=(2,1,2) : 1\times 1 \times 2 = 2
  • S=(2,2,1) : 1\times 2 \times 1 = 2
  • S=(3,1,1) : 1\times 1 \times 1 = 1

となるため、その総和である 14 を出力します。


入力例 2

1126 2022

出力例 2

40166

総和を 200\ 003 で割った余りを出力してください。


入力例 3

1000000000000 1500000000000

出力例 3

180030

Score : 600 points

Problem Statement

You are given positive integers N and M. Here, it is guaranteed that N\leq M \leq 2N.

Print the sum, modulo 200\ 003 (a prime), of the following value over all sequences of positive integers S=(S_1,S_2,\dots,S_N) such that \displaystyle \sum_{i=1}^{N} S_i = M (notice the unusual modulo):

  • \displaystyle \prod_{k=1}^{N} \min(k,S_k).

Constraints

  • 1 \leq N \leq 10^{12}
  • N \leq M \leq 2N
  • All values in the input are integers.

Input

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

N M

Output

Print the answer as an integer.


Sample Input 1

3 5

Sample Output 1

14

There are six sequences S that satisfy the condition: S=(1,1,3), S=(1,2,2), S=(1,3,1), S=(2,1,2), S=(2,2,1), S=(3,1,1).

The value \displaystyle \prod_{k=1}^{N} \min(k,S_k) for each of those S is as follows.

  • S=(1,1,3) : 1\times 1 \times 3 = 3
  • S=(1,2,2) : 1\times 2 \times 2 = 4
  • S=(1,3,1) : 1\times 2 \times 1 = 2
  • S=(2,1,2) : 1\times 1 \times 2 = 2
  • S=(2,2,1) : 1\times 2 \times 1 = 2
  • S=(3,1,1) : 1\times 1 \times 1 = 1

Thus, you should print their sum: 14.


Sample Input 2

1126 2022

Sample Output 2

40166

Print the sum modulo 200\ 003.


Sample Input 3

1000000000000 1500000000000

Sample Output 3

180030