Problem:
Score : 1800 points

Problem Statement

We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows:

First, write 0 in every square.

For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i squares in the i-th row.

For each j=1,2,...,M, choose an integer l_j (0\leq l_j\leq N), and add 1 to each of the topmost l_j squares in the j-th column.

Now we have a grid where each square contains 0, 1, or 2. Find the number of different grids that can be made this way, modulo 998244353.
We consider two grids different when there exists a square with different integers.

Constraints

1 \leq N,M \leq 5\times 10^5

N and M are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of different grids that can be made, modulo 998244353.

Sample Input 1

1 2

Sample Output 1

8

Let (a,b) denote the grid where the square to the left contains a and the square to the right contains b. Eight grids can be made: (0,0),(0,1),(1,0),(1,1),(1,2),(2,0),(2,1), and (2,2).

Sample Input 2

2 3

Sample Output 2

234

Sample Input 3

10 7

Sample Output 3

995651918

Sample Input 4

314159 265358

Sample Output 4

70273732

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
const u32 P=998244353;
u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
u32 sum(u32 a, u32 b) {return inc(a, b);}
u32 dif(u32 a, u32 b) {return dec(a, b);}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
	return ans;
}

const int N=5e5+1;
u32 fac[N], ifac[N], pwn[N], pwm[N];
int main() {
	int n=rd(), m=rd();
	u32 ans=0;
	if(n<m) std::swap(n, m);
	fac[0]=1;
	for(int i=1; i<=n; ++i) fac[i]=(u64)fac[i-1]*i%P;
	ifac[n]=power(fac[n], P-2);
	for(int i=n; i--; ) ifac[i]=(i+1llu)*ifac[i+1]%P;
	pwn[0]=pwm[0]=1;
	for(int i=1; i<=m; ++i) pwn[i]=pwn[i-1]*(n+1llu)%P;
	for(int i=1; i<=n; ++i) pwm[i]=pwm[i-1]*(m+1llu)%P;
	for(int r=0; r<=m; ++r) {
		u32 cur=(u64)fac[n]*ifac[n-r]%P*ifac[r]%P*fac[m]%P*ifac[m-r]%P*pwm[n-r]%P*pwn[m-r]%P;
		if(r&1) dec(ans, cur); else inc(ans, cur);
	}
	printf("%u\n", ans);
	return 0;
}