No.2631 Rectangle Grid Game
Problem Statement
Two players, Alice and Bob, are going to play a game of claiming territory on a grid.
You are given a grid with $H$ rows and $W$ columns. Here, the top-left cell is $(1, 1)$ and the bottom-right cell is $(H, W)$.
In the initial state, Alice's and Bob's pieces are placed on cells $(X_A, Y_A), (X_B, Y_B)$ ($(X_A,Y_A)\neq(X_B,Y_B)$), respectively.
Also, cell $(X_A, Y_A)$ is Alice's territory, cell $(X_B, Y_B)$ is Bob's territory, and all other cells belong to neither player's territory.
Alice goes first, and the players take turns alternately. On their turn, a player performs the following operations in the order shown.
- Let $(X, Y)$ be the cell where the player's own piece is currently located. Choose a cell $(X^\prime, Y^\prime)$ that satisfies condition $(*)$ and is either the player's own territory or neither player's territory.
- Move the player's own piece to $(X^\prime, Y^\prime)$.
- Make all cells in the rectangular region specified in $(*)$ the player's own territory.
$(*)$ The rectangular region having cell $(X, Y)$ and cell $(X^\prime, Y^\prime)$ as the ends of one of its diagonals contains no cell that is the opponent's territory.
Formally, for all integers $i$, $j$ satisfying $\min(X, X^\prime) \le i \le \max(X, X^\prime)$ , $\min(Y, Y^\prime) \le j \le \max(Y, Y^\prime)$,
cell $(i, j)$ is not the opponent's territory.
The game ends when Bob's $10^{100}$-th turn is finished.
At the end of the game, the player with more cells in their territory wins. If both players have the same number of such cells, the game is a draw.
Find the number of tuples of variables $(X_A, Y_A, X_B, Y_B)$, which give the initial positions of the cells, such that Alice wins when both players play optimally.
Since this number can be very large, find it modulo $998,244,353$.
Constraints
- $2 \le H \le 10^9$
- $2 \le W \le 10^9$
- All values given in the input are integers
Input
The input is given in the following format.$H$ $W$
Output
Print the number of tuples of variables in question, modulo $998,244,353$. Print a newline at the end.
Sample
Sample 1
Input
3 4
Output
94
For example, when $(X_A, Y_A, X_B, Y_B) = (1, 1, 3, 4)$, suppose the game proceeds as follows:
- Alice moves to cell $(2, 3)$
- Bob moves to cell $(3, 1)$
- Alice moves to cell $(1, 4)$
Considering all other cases as well, there are $94$ tuples of variables in total for which Alice wins.
Sample 2
Input
2 2
Output
0
The game is a draw regardless of the initial state.
Sample 3
Input
3141 5926
Output
428758522
Print the answer modulo $998,244,353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
noya2