stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>



using namespace std;

const int N=1000005;

const int MOD=998244353;

typedef long long LL;



int n,m,fac[N],inv[N];

int Ans1,Ans2;



//LL gcd(LL x,LL y) {

//	if(!y) return x;

//	return gcd(y,x%y);

//}

//

//struct Data{

//	LL x,y;

//	Data(LL _x=0,LL _y=0) {x=_x; y=_y;}

//	friend Data operator+(const Data A,const Data B){

//		Data ret; ret.y=A.y*B.y; ret.x=A.x*B.y+A.y*B.x;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//	friend Data operator*(const Data A,const Data B){

//		Data ret; ret.x=A.x*B.x; ret.y=A.y*B.y;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//}ans;



inline int fast_pow(int x,int y){

	int ret=1;

	for(;y;y>>=1){

		if(y&1) ret=(LL)ret*x%MOD;

		x=(LL)x*x%MOD;

	}

	return ret;

}



inline int C(int x,int y){

	return (LL)fac[x]*inv[y]%MOD*inv[x-y]%MOD;

}



int main(){

	scanf("%d%d",&n,&m);

	if(n>m) swap(n,m); fac[0]=inv[0]=1;

	int i;

	for(i=1;i<=n+m;i+=4){

		fac[i]=1ll*fac[i-1]*i%MOD;

		fac[i+1]=1ll*fac[i]*(i+1)%MOD;

		fac[i+2]=1ll*fac[i+1]*(i+2)%MOD;

		fac[i+3]=1ll*fac[i+2]*(i+3)%MOD;

	}

	for(;i<=n+m;i++) fac[i]=fac[i-1]*i%MOD;

	inv[n+m]=fast_pow(fac[n+m],MOD-2);

	for(int i=n+m-1;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%MOD;

	Ans1=1ll*2*m*C(n+m,n)%MOD; Ans2=fast_pow(C(n+m,n)*2%MOD,MOD-2);

	for(int i=1;i<=n;i++) {

		Ans1=Ans1+1ll*C(n-i+m-i,n-i)*C(i+i,i)%MOD;	

		Ans1%=MOD;

	}

	printf("%lld\n",1ll*Ans1*Ans2%MOD);

//	ans=ans+Data(1,2)*Data(C(n-i+m-i,n-i)*C(i+i,i),C(n+m,n));

//	printf("%lld\n",1ll*ans.x*fast_pow(ans.y,MOD-2)%MOD);

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 5.156426521569093x):
#include <cstdio>

#include <algorithm>



const int maxn = 1000005, P = 998244353;

int n, m, fac[maxn], ifac[maxn];



int power(int a, int x)

{

	int ans = 1;

	for (; x; x >>= 1, a = 1LL * a * a % P)

		if (x & 1)

			ans = 1LL * ans * a % P;

	return ans;

}

int binom(int n, int m)

{

	if (n < m || m < 0)

		return 0;

	return 1LL * fac[n] * ifac[m] % P * ifac[n - m] % P;

}



int main()

{

	scanf("%d%d", &n, &m);

	if (n < m)

		std::swap(n, m);

	fac[0] = 1;

	for (int i = 1; i <= n + m; ++i)

		fac[i] = 1LL * fac[i - 1] * i % P;

	ifac[n + m] = power(fac[n + m], P - 2);

	for (int i = n + m; i; --i)

		ifac[i - 1] = 1LL * ifac[i] * i % P;

	int ans = 0;

	for (int i = 1; i <= m; ++i)

		ans = (ans + 1LL * binom(2 * i, i) * binom(n + m - 2 * i, n - i)) % P;

	ans = 1LL * ans * power(2 * binom(n + m, n) % P, P - 2) % P;

	ans = (ans + n) % P;

	printf("%d\n", ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 1000005

#define p 998244353

#define int long long 

using namespace std;



inline void rd(int &x){

	x=0;char ch=0;int w=0;

	while(!isdigit(ch)) ch=getchar(),w|=ch=='-';

	while( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=w?-x:x;

}



int n,m,ans;

int f[N],inv[N];



inline int POW(int a,int b=p-2,int ans=1){

	for(;b;b>>=1,a=a*a%p)

		if(b&1) ans=ans*a%p;

	return ans;

}



inline int C(int n,int m){

	return f[n]*inv[m]%p*inv[n-m]%p;

}

signed main(){

	cin>>n>>m;if(n<m) swap(n,m);

	for(int i=f[0]=inv[0]=1;i<=n+m;i++)

		f[i]=f[i-1]*i%p,inv[i]=POW(f[i]);

	for(int i=1;i<=m;i++)

		ans=(ans+C(i<<1,i)*C(n-i+m-i,n-i))%p;

	ans=ans*inv[2]%p*POW(C(n+m,n))%p;

	cout<<(ans+n)%p;

}

// Faster C++ solution for the same problem (measured speedup: 5.234880902316756x):
/*

AT2705 Yes or No

n为yes的题数，m为no的题数

当n>m的时候，猜yes

当n<m的时候，猜no

这样猜一定能保证猜对max(n,m)次

考虑n=m时猜对的期望

猜对的概率（对答案的贡献）是n/(n+m)=1/2

考虑走到(i,i)这个点的方案数

C(2i,i)*(n-i+m-i,n-i)

前2i步钦定i步向右走（剩余i步向上走）

后n-i+m-i步钦定n-i步向右走（剩余m-i步向上走），以免走出网格

故走到(i,i)的概率是sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n)

C(n+m,n)是总方案数 

当n=m时的期望贡献是(1/2)*sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n) i=1~min(n,m)

*/ 

#include <cstdio>

typedef long long ll;

#define ri register int

#pragma GCC optimize(1)

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize("Ofast") 

const int N=1000005,mod=998244353;

int fac[N],inv[N];

inline int C(ri n,ri m){

	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;

}

inline int max(ri x,ri y){

	return x>y ? x:y;

}

inline int min(ri x,ri y){

	return x<y ? x:y;

}

inline void add(int &x,ri y){

	x+=y;

	if(x>=mod) x-=mod;

}

inline int Pow(ri a,ri b){

	ri ans=1;

	for(;b;b>>=1,a=(ll)a*a%mod)

		if(b&1) ans=(ll)ans*a%mod;

	return ans;

}

int main(){

	ri n,m,i,sum,yes;

	scanf("%d%d",&n,&m);

	sum=n+m;

	fac[0]=inv[0]=1;

	for(i=1;i<=sum;++i) fac[i]=(ll)fac[i-1]*i%mod;

	inv[sum]=Pow(fac[sum],mod-2);

	for(i=sum-1;i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;

	yes=0;

	for(i=min(n,m);i;--i) add(yes,(ll)C(2*i,i)*C(n-i+m-i,n-i)%mod);

	yes=(ll)yes*Pow(C(n+m,n),mod-2)%mod*inv[2]%mod;

	add(yes,max(n,m));

	printf("%d\n",yes);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>



using namespace std;

const int N=1000005;

const int MOD=998244353;

typedef long long LL;



int n,m,fac[N],inv[N];

int Ans1,Ans2;



//LL gcd(LL x,LL y) {

//	if(!y) return x;

//	return gcd(y,x%y);

//}

//

//struct Data{

//	LL x,y;

//	Data(LL _x=0,LL _y=0) {x=_x; y=_y;}

//	friend Data operator+(const Data A,const Data B){

//		Data ret; ret.y=A.y*B.y; ret.x=A.x*B.y+A.y*B.x;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//	friend Data operator*(const Data A,const Data B){

//		Data ret; ret.x=A.x*B.x; ret.y=A.y*B.y;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//}ans;



inline int fast_pow(int x,int y){

	int ret=1;

	for(;y;y>>=1){

		if(y&1) ret=(LL)ret*x%MOD;

		x=(LL)x*x%MOD;

	}

	return ret;

}



inline int C(int x,int y){

	return (LL)fac[x]*inv[y]%MOD*inv[x-y]%MOD;

}



int main(){

	scanf("%d%d",&n,&m);

	if(n>m) swap(n,m); fac[0]=inv[0]=1;

	int i;

	for(i=1;i<=n+m;i+=4){

		fac[i]=1ll*fac[i-1]*i%MOD;

		fac[i+1]=1ll*fac[i]*(i+1)%MOD;

		fac[i+2]=1ll*fac[i+1]*(i+2)%MOD;

		fac[i+3]=1ll*fac[i+2]*(i+3)%MOD;

	}

	for(;i<=n+m;i++) fac[i]=fac[i-1]*i%MOD;

	inv[n+m]=fast_pow(fac[n+m],MOD-2);

	for(int i=n+m-1;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%MOD;

	Ans1=1ll*2*m*C(n+m,n)%MOD; Ans2=fast_pow(C(n+m,n)*2%MOD,MOD-2);

	for(int i=1;i<=n;i++) {

		Ans1=Ans1+1ll*C(n-i+m-i,n-i)*C(i+i,i)%MOD;	

		Ans1%=MOD;

	}

	printf("%lld\n",1ll*Ans1*Ans2%MOD);

//	ans=ans+Data(1,2)*Data(C(n-i+m-i,n-i)*C(i+i,i),C(n+m,n));

//	printf("%lld\n",1ll*ans.x*fast_pow(ans.y,MOD-2)%MOD);

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 5.1556937269448975x):
/*

AT2705 Yes or No

n为yes的题数，m为no的题数

当n>m的时候，猜yes

当n<m的时候，猜no

这样猜一定能保证猜对max(n,m)次

考虑n=m时猜对的期望

猜对的概率（对答案的贡献）是n/(n+m)=1/2

考虑走到(i,i)这个点的方案数

C(2i,i)*(n-i+m-i,n-i)

前2i步钦定i步向右走（剩余i步向上走）

后n-i+m-i步钦定n-i步向右走（剩余m-i步向上走），以免走出网格

故走到(i,i)的概率是sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n)

C(n+m,n)是总方案数 

当n=m时的期望贡献是(1/2)*sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n) i=1~min(n,m)

*/ 

#include <cstdio>

typedef long long ll;

#define ri register int

#pragma GCC optimize(1)

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize("Ofast") 

const int N=1000005,mod=998244353;

int fac[N],inv[N];

inline int C(ri n,ri m){

	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;

}

inline int max(ri x,ri y){

	return x>y ? x:y;

}

inline int min(ri x,ri y){

	return x<y ? x:y;

}

inline void add(int &x,ri y){

	x+=y;

	if(x>=mod) x-=mod;

}

inline int Pow(ri a,ri b){

	ri ans=1;

	for(;b;b>>=1,a=(ll)a*a%mod)

		if(b&1) ans=(ll)ans*a%mod;

	return ans;

}

int main(){

	ri n,m,i,sum,yes;

	scanf("%d%d",&n,&m);

	sum=n+m;

	fac[0]=inv[0]=1;

	for(i=1;i<=sum;++i) fac[i]=(ll)fac[i-1]*i%mod;

	inv[sum]=Pow(fac[sum],mod-2);

	for(i=sum-1;i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;

	yes=0;

	for(i=min(n,m);i;--i) add(yes,(ll)C(2*i,i)*C(n-i+m-i,n-i)%mod);

	yes=(ll)yes*Pow(C(n+m,n),mod-2)%mod*inv[2]%mod;

	add(yes,max(n,m));

	printf("%d\n",yes);

    return 0;

}
// Slower C++ solution:
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i_, s_, t_) for (ll i_ = (s_); i_ <= (t_); ++i_)

#define re(i_, s_, t_) for (ll i_ = (s_); i_ < (t_); ++i_)

#define per(i_, s_, t_) for (ll i_ = (s_); i_ >= (t_); --i_)

typedef long long ll;

const ll P = 998244353, N = 1e6 + 5;

ll fac[N];

ll ans;

ll qpow(ll x, ll t = P - 2) {

	ll res = 1;

	for (; t; t >>= 1, x = 1LL * x * x % P)

		if (t & 1)

			res = 1LL * res * x % P;

	return res;

}

ll C(ll m, ll n) { return 1LL * fac[m] * qpow(fac[m - n]) % P * qpow(fac[n]) % P; }

int main() {

	ll n, m;

	scanf("%lld%lld", &n, &m);

	if (n > m)

		swap(n, m);

	fac[0] = fac[1] = 1;

	rep (i, 2, n + m)

		fac[i] = 1ll * fac[i - 1] * i % P;

	rep (i, 1, n)

		ans = (ans + C(n + m - 2 * i, n - i) * C(2 * i, i) % P) % P;

	ans = ans * fac[n] % P * fac[m] % P * qpow(fac[n + m]) % P * qpow(2) % P;

	printf("%lld\n", (m + ans) % P);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1749856995705965x):
/*

AT2705 Yes or No

n为yes的题数，m为no的题数

当n>m的时候，猜yes

当n<m的时候，猜no

这样猜一定能保证猜对max(n,m)次

考虑n=m时猜对的期望

猜对的概率（对答案的贡献）是n/(n+m)=1/2

考虑走到(i,i)这个点的方案数

C(2i,i)*(n-i+m-i,n-i)

前2i步钦定i步向右走（剩余i步向上走）

后n-i+m-i步钦定n-i步向右走（剩余m-i步向上走），以免走出网格

故走到(i,i)的概率是sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n)

C(n+m,n)是总方案数 

当n=m时的期望贡献是(1/2)*sigma(C(2i,i)*(n-i+m-i,n-i))/C(n+m,n) i=1~min(n,m)

*/ 

#include <cstdio>

typedef long long ll;

#define ri register int

#pragma GCC optimize(1)

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize("Ofast") 

const int N=1000005,mod=998244353;

int fac[N],inv[N];

inline int C(ri n,ri m){

	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;

}

inline int max(ri x,ri y){

	return x>y ? x:y;

}

inline int min(ri x,ri y){

	return x<y ? x:y;

}

inline void add(int &x,ri y){

	x+=y;

	if(x>=mod) x-=mod;

}

inline int Pow(ri a,ri b){

	ri ans=1;

	for(;b;b>>=1,a=(ll)a*a%mod)

		if(b&1) ans=(ll)ans*a%mod;

	return ans;

}

int main(){

	ri n,m,i,sum,yes;

	scanf("%d%d",&n,&m);

	sum=n+m;

	fac[0]=inv[0]=1;

	for(i=1;i<=sum;++i) fac[i]=(ll)fac[i-1]*i%mod;

	inv[sum]=Pow(fac[sum],mod-2);

	for(i=sum-1;i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;

	yes=0;

	for(i=min(n,m);i;--i) add(yes,(ll)C(2*i,i)*C(n-i+m-i,n-i)%mod);

	yes=(ll)yes*Pow(C(n+m,n),mod-2)%mod*inv[2]%mod;

	add(yes,max(n,m));

	printf("%d\n",yes);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 1000005

#define p 998244353

#define int long long 

using namespace std;



inline void rd(int &x){

	x=0;char ch=0;int w=0;

	while(!isdigit(ch)) ch=getchar(),w|=ch=='-';

	while( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=w?-x:x;

}



int n,m,ans;

int f[N],inv[N];



inline int POW(int a,int b=p-2,int ans=1){

	for(;b;b>>=1,a=a*a%p)

		if(b&1) ans=ans*a%p;

	return ans;

}



inline int C(int n,int m){

	return f[n]*inv[m]%p*inv[n-m]%p;

}

signed main(){

	cin>>n>>m;if(n<m) swap(n,m);

	for(int i=f[0]=inv[0]=1;i<=n+m;i++)

		f[i]=f[i-1]*i%p,inv[i]=POW(f[i]);

	for(int i=1;i<=m;i++)

		ans=(ans+C(i<<1,i)*C(n-i+m-i,n-i))%p;

	ans=ans*inv[2]%p*POW(C(n+m,n))%p;

	cout<<(ans+n)%p;

}

// Faster C++ solution for the same problem (measured speedup: 5.251959853077833x):
#include<cstdio>



const int mod=998244353,N=1000005;



int fexp(int a,int b)

{

	int x=1;

	for(;b;b>>=1,a=1LL*a*a%mod)

		if(b&1)x=1LL*x*a%mod;

	return x;

}



int n,m,ans,fac[N],ifac[N];



int main()

{

	scanf("%d%d",&n,&m);

	n+=m;

	fac[0]=1;

	for(int i=1; i<=n; ++i)fac[i]=1LL*i*fac[i-1]%mod;

	ifac[n]=fexp(fac[n],mod-2);

	for(int i=n-1; ~i; --i)ifac[i]=1LL*(i+1)*ifac[i+1]%mod;

	n-=m;

	if(n<m){int k=n;n=m;m=k;}

	for(int x=1; x<=m; ++x)

		ans=(ans+1LL*fac[x+x]*ifac[x]%mod*ifac[x]%mod*fac[n-x+m-x]%mod*ifac[n-x]%mod*ifac[m-x])%mod;

	ans=1LL*ans*ifac[2]%mod*ifac[n+m]%mod*fac[n]%mod*fac[m]%mod;

	printf("%d",(ans+n)%mod);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>



using namespace std;

const int N=1000005;

const int MOD=998244353;

typedef long long LL;



int n,m,fac[N],inv[N];

int Ans1,Ans2;



//LL gcd(LL x,LL y) {

//	if(!y) return x;

//	return gcd(y,x%y);

//}

//

//struct Data{

//	LL x,y;

//	Data(LL _x=0,LL _y=0) {x=_x; y=_y;}

//	friend Data operator+(const Data A,const Data B){

//		Data ret; ret.y=A.y*B.y; ret.x=A.x*B.y+A.y*B.x;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//	friend Data operator*(const Data A,const Data B){

//		Data ret; ret.x=A.x*B.x; ret.y=A.y*B.y;

//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;

//		return ret;

//	}

//}ans;



inline int fast_pow(int x,int y){

	int ret=1;

	for(;y;y>>=1){

		if(y&1) ret=(LL)ret*x%MOD;

		x=(LL)x*x%MOD;

	}

	return ret;

}



inline int C(int x,int y){

	return (LL)fac[x]*inv[y]%MOD*inv[x-y]%MOD;

}



int main(){

	scanf("%d%d",&n,&m);

	if(n>m) swap(n,m); fac[0]=inv[0]=1;

	int i;

	for(i=1;i<=n+m;i+=4){

		fac[i]=1ll*fac[i-1]*i%MOD;

		fac[i+1]=1ll*fac[i]*(i+1)%MOD;

		fac[i+2]=1ll*fac[i+1]*(i+2)%MOD;

		fac[i+3]=1ll*fac[i+2]*(i+3)%MOD;

	}

	for(;i<=n+m;i++) fac[i]=fac[i-1]*i%MOD;

	inv[n+m]=fast_pow(fac[n+m],MOD-2);

	for(int i=n+m-1;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%MOD;

	Ans1=1ll*2*m*C(n+m,n)%MOD; Ans2=fast_pow(C(n+m,n)*2%MOD,MOD-2);

	for(int i=1;i<=n;i++) {

		Ans1=Ans1+1ll*C(n-i+m-i,n-i)*C(i+i,i)%MOD;	

		Ans1%=MOD;

	}

	printf("%lld\n",1ll*Ans1*Ans2%MOD);

//	ans=ans+Data(1,2)*Data(C(n-i+m-i,n-i)*C(i+i,i),C(n+m,n));

//	printf("%lld\n",1ll*ans.x*fast_pow(ans.y,MOD-2)%MOD);

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 5.172514327249808x):
#include<cstdio>



const int mod=998244353,N=1000005;



int fexp(int a,int b)

{

	int x=1;

	for(;b;b>>=1,a=1LL*a*a%mod)

		if(b&1)x=1LL*x*a%mod;

	return x;

}



int n,m,ans,fac[N],ifac[N];



int main()

{

	scanf("%d%d",&n,&m);

	n+=m;

	fac[0]=1;

	for(int i=1; i<=n; ++i)fac[i]=1LL*i*fac[i-1]%mod;

	ifac[n]=fexp(fac[n],mod-2);

	for(int i=n-1; ~i; --i)ifac[i]=1LL*(i+1)*ifac[i+1]%mod;

	n-=m;

	if(n<m){int k=n;n=m;m=k;}

	for(int x=1; x<=m; ++x)

		ans=(ans+1LL*fac[x+x]*ifac[x]%mod*ifac[x]%mod*fac[n-x+m-x]%mod*ifac[n-x]%mod*ifac[m-x])%mod;

	ans=1LL*ans*ifac[2]%mod*ifac[n+m]%mod*fac[n]%mod*fac[m]%mod;

	printf("%d",(ans+n)%mod);

	return 0;

}
// Slower C++ solution:
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i_, s_, t_) for (ll i_ = (s_); i_ <= (t_); ++i_)

#define re(i_, s_, t_) for (ll i_ = (s_); i_ < (t_); ++i_)

#define per(i_, s_, t_) for (ll i_ = (s_); i_ >= (t_); --i_)

typedef long long ll;

const ll P = 998244353, N = 1e6 + 5;

ll fac[N];

ll ans;

ll qpow(ll x, ll t = P - 2) {

	ll res = 1;

	for (; t; t >>= 1, x = 1LL * x * x % P)

		if (t & 1)

			res = 1LL * res * x % P;

	return res;

}

ll C(ll m, ll n) { return 1LL * fac[m] * qpow(fac[m - n]) % P * qpow(fac[n]) % P; }

int main() {

	ll n, m;

	scanf("%lld%lld", &n, &m);

	if (n > m)

		swap(n, m);

	fac[0] = fac[1] = 1;

	rep (i, 2, n + m)

		fac[i] = 1ll * fac[i - 1] * i % P;

	rep (i, 1, n)

		ans = (ans + C(n + m - 2 * i, n - i) * C(2 * i, i) % P) % P;

	ans = ans * fac[n] % P * fac[m] % P * qpow(fac[n + m]) % P * qpow(2) % P;

	printf("%lld\n", (m + ans) % P);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.191869240495687x):
#include<cstdio>



const int mod=998244353,N=1000005;



int fexp(int a,int b)

{

	int x=1;

	for(;b;b>>=1,a=1LL*a*a%mod)

		if(b&1)x=1LL*x*a%mod;

	return x;

}



int n,m,ans,fac[N],ifac[N];



int main()

{

	scanf("%d%d",&n,&m);

	n+=m;

	fac[0]=1;

	for(int i=1; i<=n; ++i)fac[i]=1LL*i*fac[i-1]%mod;

	ifac[n]=fexp(fac[n],mod-2);

	for(int i=n-1; ~i; --i)ifac[i]=1LL*(i+1)*ifac[i+1]%mod;

	n-=m;

	if(n<m){int k=n;n=m;m=k;}

	for(int x=1; x<=m; ++x)

		ans=(ans+1LL*fac[x+x]*ifac[x]%mod*ifac[x]%mod*fac[n-x+m-x]%mod*ifac[n-x]%mod*ifac[m-x])%mod;

	ans=1LL*ans*ifac[2]%mod*ifac[n+m]%mod*fac[n]%mod*fac[m]%mod;

	printf("%d",(ans+n)%mod);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<vector>

#include<set>

#include<map>

#include<unordered_map>

using namespace std;

#define ri register int

#define il inline

#define pb emplace_back

#define solid const auto &

#define enter putchar('\n')

#define Size(x) ((int)x.size())

#define mem(x,y) memset(x,y,sizeof(x))

#define gm int mid((l+r)>>1)

#define mp make_pair

#define fi first

#define se second

typedef long long LL;

typedef unsigned long long ull;

typedef pair<int,int> pii;

template<class T>il void in(T &x)

{

	x=0; char c=getchar(); bool f=0;

	while(!isdigit(c)) f|=(c=='-'),c=getchar();

	while(isdigit(c)) x=x*10+(c^'0'),c=getchar();

	f?x=-x:0;

}

template<class T>il void out(T x,const char c='\n')

{

	static short st[30]; short tp=0;

	if(x<0) putchar('-'),x=-x;

	do st[++tp]=x%10,x/=10; while(x);

	while(tp) putchar('0'|st[tp--]);

	putchar(c);

}

template<class T>il void err(const T &x,const char c='\n') {cerr<<x<<c;}

template<class T,class ...Args>il void err(const T &x,const Args &...args) {err(x,' '),err(args...);}

const int md=998244353;

il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=(LL)a*a%md) if(b&1) r=(LL)r*a%md; return r;}

il int fit(const int x) {return x>=md?x-md:x;}

namespace i207M

{

const int N=1000005;

int fac[N],ifac[N];

void prework(int n)

{

	fac[0]=1;

	for(ri i=1;i<=n;++i) fac[i]=(LL)fac[i-1]*i%md;

	ifac[n]=qpow(fac[n],md-2);

	for(ri i=n;i>=1;--i) ifac[i-1]=(LL)ifac[i]*i%md;

}

il int C(int n,int m) {return (LL)fac[n]*ifac[m]%md*ifac[n-m]%md;}

int n,m;

signed main()

{

#ifdef M207

	freopen("in.in","r",stdin);

#endif

	in(n),in(m);

	if(n>m) swap(n,m);

	prework(n+m);

	int ans=0;

	for(ri i=1;i<=n;++i)

		ans=(ans+(LL)C(2*i,i)*C(n-i+m-i,n-i))%md;

	ans=(LL)ans*qpow(C(n+m,n),md-2)%md*(md+1)/2%md;

	ans=fit(ans+m);

	out(ans);

	return 0;

}

}

signed main()

{

	i207M::main();

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.17742966104007x):
#include<cstdio>



const int mod=998244353,N=1000005;



int fexp(int a,int b)

{

	int x=1;

	for(;b;b>>=1,a=1LL*a*a%mod)

		if(b&1)x=1LL*x*a%mod;

	return x;

}



int n,m,ans,fac[N],ifac[N];



int main()

{

	scanf("%d%d",&n,&m);

	n+=m;

	fac[0]=1;

	for(int i=1; i<=n; ++i)fac[i]=1LL*i*fac[i-1]%mod;

	ifac[n]=fexp(fac[n],mod-2);

	for(int i=n-1; ~i; --i)ifac[i]=1LL*(i+1)*ifac[i+1]%mod;

	n-=m;

	if(n<m){int k=n;n=m;m=k;}

	for(int x=1; x<=m; ++x)

		ans=(ans+1LL*fac[x+x]*ifac[x]%mod*ifac[x]%mod*fac[n-x+m-x]%mod*ifac[n-x]%mod*ifac[m-x])%mod;

	ans=1LL*ans*ifac[2]%mod*ifac[n+m]%mod*fac[n]%mod*fac[m]%mod;

	printf("%d",(ans+n)%mod);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<cstring>

using namespace std;

#define MAXN 1000000

#define MOD 998244353

#define LL long long

int n,m;

int inv[MAXN+5],fac[MAXN+5];

int ans;

int fst_pow(int a,int b)

{

	int res=1;

	while(b)

	{

		if(b&1)res=(1LL*res*a)%MOD;

		a=(1LL*a*a)%MOD;

		b>>=1;

	}

	return res;

}

void prepare()

{

	fac[0]=1;

	for(int i=1;i<=n+m;i++)

	fac[i]=(1LL*fac[i-1]*i)%MOD;

	inv[n+m]=fst_pow(fac[n+m],MOD-2);

	for(int i=n+m-1;i>=0;i--)

	inv[i]=(1LL*inv[i+1]*(i+1))%MOD;

}

int Comb(int a,int b)

{

	return 1LL*(1LL*fac[a]*inv[a-b]%MOD)*inv[b]%MOD;

}

int main()

{

	scanf("%d%d",&n,&m);

	if(n<m)swap(n,m);

	prepare();

	for(int i=1;i<=m;i++)

		ans=(ans+1LL*Comb(2*i,i)*Comb(n+m-2*i,n-i)%MOD)%MOD;

	ans=1LL*ans*fst_pow(Comb(m+n,n),MOD-2)%MOD;

	ans=1LL*ans*fst_pow(2,MOD-2)%MOD;

	printf("%d",ans+n);

}


// Faster C++ solution for the same problem (measured speedup: 5.143561312725926x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1000005,md=998244353;

int n,m,ans;

int nyc[N],fac[N],facn[N];

inline int exgcd(int a,int b,int &x,int &y)

{

	if(b==0)

	{

		x=1;

		y=0;

		return a;

	}

	int t=exgcd(b,a%b,y,x);

	y-=a/b*x;

	return t;

}

inline int inv(int a)

{

	int x=0,y=0;

	exgcd(a,md,x,y);

	return (x+md)%md;

}

inline int C(int n,int m)

{

	return (ll)fac[n]*facn[m]%md*facn[n-m]%md;

}

inline int Cn(int n,int m)

{

	return (ll)facn[n]*fac[m]%md*fac[n-m]%md;

}

int main()

{

	scanf("%d%d",&n,&m);

	inv(1);

	nyc[1]=1;

	fac[0]=facn[0]=fac[1]=facn[1]=1;

	for(int i=2;i<=n+m;i++)

	{

		nyc[i]=(ll)(md-md/i)*nyc[md%i]%md;

		fac[i]=(ll)fac[i-1]*i%md;

		facn[i]=(ll)facn[i-1]*nyc[i]%md;

	}

	for(int i=1;i<=n&&i<=m;i++)

		ans=(ans+(ll)C(n+m-2*i,n-i)*C(2*i,i)%md)%md;

	ans=(ll)ans*nyc[2]%md*Cn(n+m,n)%md;

	ans=(ans+max(n,m))%md;

	printf("%d\n",ans);

	return 0;

}
// Slower C++ solution:
/* Your prologue will be the story. */

/* Copyright by HenryLi */

#include<iostream>

#include<algorithm>

#include<queue>

#include<string>

#include<map>

#include<vector>

#include<set>

#include<sstream>

#include<stack>

#include<ctime>

#include<cmath>

#include<cctype>

#include<climits>

#include<cstring>

#include<cstdio>

#include<cstdlib>

#include<iomanip>

#include<bitset>

#include<complex>

using namespace std;

template <class _T> inline void read(_T &_x) {

	int _t; bool _flag=false;

	while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;

	if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';

	while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';

	if(_flag) _x=-_x;

}

typedef long long LL;

const int maxn = 200010;

int n, a[maxn];

set<int> s;

int main() {

	//freopen("C.in","r",stdin);

	//freopen("C.out","w",stdout);

	read(n);

	for (int i = 1; i <= n; ++i) {

		read(a[i]);

		if (a[i] >= i || a[i] - a[i - 1] > 1) {

			puts("-1");

			return 0;

		}

	}

	LL ans = 0;

	for (int i = n; i >= 1; --i) {

		if (s.find(a[i] - i) != s.end()) continue;

		s.insert(a[i] - i);

		ans += a[i];

	}

	cout << ans << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.246730652862683x):
#include<cstdio>

int a[200005],n;

long long ans;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)scanf("%d",a+i);

	if(a[1]){puts("-1");return 0;}

	for(int i=2;i<=n;++i)if(a[i]<=a[i-1])ans+=a[i];

	else if(a[i]==a[i-1]+1)ans++;

	else {puts("-1");return 0;}

	printf("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int n,arr[200009];



int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",&arr[i]);

    if(arr[1]>0)

    {

        printf("-1\n");

        return 0;

    }

    long long ans=0;

    for(int i=1;i<=n;i++)

    {

        if(arr[i]-arr[i-1]>1)

        {

            printf("-1\n");

            return 0;

        }

        if(arr[i]-arr[i-1]==1)continue;

        ans+=arr[i-1];

    }

    ans+=arr[n];

    printf("%lld\n",ans);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.221118769190711x):
#include<cstdio>

int a[200005],n;

long long ans;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)scanf("%d",a+i);

	if(a[1]){puts("-1");return 0;}

	for(int i=2;i<=n;++i)if(a[i]<=a[i-1])ans+=a[i];

	else if(a[i]==a[i-1]+1)ans++;

	else {puts("-1");return 0;}

	printf("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

inline long long read(){

	long long x=0,f=1;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}

	return x*f;

}

#define MN 200005

long long n,a[MN];

long long ans;

int main(){

	n=read();bool ok=0;

	a[1]=read();if(a[1]>0) ok=1;

	register int i,j;

	for(i=2;i<=n;i++){

		a[i]=read();

		if(a[i]-a[i-1]>1) ok=1;

	}

	if(ok){

		puts("-1");

		return 0;

	}

	i=j=2;

	while(i<=n){

		for(;a[j+1]==a[j]+1;j++);

		ans+=a[j];i=j+1;j++;

	}

	printf("%lld\n",ans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.207072759841867x):
#include<cstdio>

int n,a[200001];

long long ans=0;

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	if(a[1]!=0){

		puts("-1");return 0;

	}

	for(int i=1;i<n;i++){

		if(a[i+1]-a[i]>1){

			puts("-1");return 0;

		}

		if(a[i+1]-a[i]==1) ans++;

		else ans+=1ll*a[i+1];

	}

	printf("%lld",ans);

	return 0;

}