code:
#include <bits/stdc++.h> #define ll long long #define mod 998244353 #define N 1000006 #define setIO(s) freopen(s".in","r",stdin) using namespace std; namespace IO { char *p1, *p2, buf[100000]; #define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ ) int rd() { int x = 0;char c = nc();while (c < 48) {c = nc();}while (c > 47) {x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();}return x;} }; ll qpow(ll base,ll k) { ll tmp=1; for(;k;k>>=1,base=base*base%mod) if(k&1) tmp=tmp*base%mod; return tmp; } int a[N]; int main() { using namespace IO; // setIO("input"); int n=rd(),m=rd(),k=rd(),i,j,ans=1; for(i=1;i<=n;++i) { int x=rd(); ans=(ll)ans*(k-x)%mod; } int mdl=1; for(i=0;i<=m;++i) { int x=rd(); (ans+=(ll)mdl*x%mod)%=mod; mdl=(ll)mdl*k%mod; } printf("%d\n",ans); return 0; }