AtCoder Regular Contest 163
F
Many Increasing Problems
AtCoder
⌀ 3295
原题
← E→
翻译中…

Problem Statement

翻译中…

PCT-kun created the following problem.

翻译中…

Increasing Problem

You are given a length-$N$ sequence of non-negative integers $A_1,A_2,\dots,A_N$. You can perform the following operation any number of times (possibly zero).

  • Choose an integer $i$ such that $1 \le i \le N$, and increase or decrease $A_i$ by $1$.

Your goal is to make $A$ non-decreasing. Find the minimum number of operations required to achieve this goal.

翻译中…

Thinking that this problem is too easy to be placed at the end of the contest, PCT-kun has revised it as follows.

翻译中…

Many Increasing Problems

There are $M^N$ integer sequences $A$ of length $N$ where all elements are between $1$ and $M$, inclusive. Find the sum of the answers to Increasing Problem for all those sequences, modulo $998244353$.

翻译中…

Solve Many Increasing Problems.

翻译中…

Constraints

翻译中…
  • $1 \le N,M \le 10^5$
翻译中…

Input

翻译中…

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

翻译中…

N M

翻译中…

Output

翻译中…

Print the answer to Many Increasing Problems.

翻译中…

样例

Input #1
2 2
Output #1
1
Let us solve **Increasing Problem** for all sequences of length $2$ where all elements are between $1$ and $2$, inclusive. - For $A=(1,1)$, the answer is $0$. - For $A=(1,2)$, the answer is $0$. - For $A=(2,1)$, the answer is $1$. - For $A=(2,2)$, the answer is $0$. Therefore, the final answer is $0+0+1+0=1$.
Input #2
6 4
Output #2
14668
Input #3
163 702
Output #3
20728656
Input #4
98765 99887
Output #4
103564942
题目信息
题号
arc163_f
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。