#include using namespace std; #define repd(i,a,b) for (ll i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; typedef pair P; typedef vector vec; using Graph = vector>; const long long INF = 1LL<<60; const long long MOD = 1000000007; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int nxt[2005][2005]; mint dp[2005][2005]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,m,k; cin>>n>>m>>k; vec s(n); rep(i,n){ cin>>s[i]; s[i]--; } vec a(m),b(m); rep(i,m)cin>>a[i]; rep(i,m)cin>>b[i]; for(ll i=n;i>=1;i--){ for(ll j=i-1;j>=0;j--){ nxt[j][s[i-1]]=i; if(j==0)continue; if(s[i-1]==s[j-1])break; } } dp[0][0]=1; rep(i,n){ rep(j,m){ if(nxt[i][j]==0)continue; rep(l,k+1){ if(l+a[j]>k&&l+b[j]>k)break; if(l+a[j]<=k)dp[nxt[i][j]][l+a[j]]+=dp[i][l]; if(l+b[j]<=k)dp[nxt[i][j]][l+b[j]]+=dp[i][l]; } } } mint ans=0; rep(i,2005)ans+=dp[i][k]; cout<