#include #include using namespace atcoder; using namespace std; using ll= long long; ll mod=998244353; int main(){ ll n,m; cin >> n >> m; vectora(n),b(m); ll x=0; for (ll i = 0; i < n; i++) { cin >> a[i]; x^=a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; x^=b[i]; } if (x!=0) { cout << 0 << endl; return 0; } vectortwo(30,1); for (ll i = 0; i < 20; i++) { two[i+1]=two[i]*2; } ll ans=1; for (ll i = 0; i < (n-1)*(m-1)*20; i++) { ans*=2; ans%=mod; } cout << ans << endl; }