#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; int main() { constexpr ll MOD = 998244353; int n, m, k; cin >> n >> m >> k; vector s(n), a(m), b(m); for(int i = 0; i < n; i++) { cin >> s[i]; s[i]--; } for(int i = 0; i < m; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; vector> dp(k+1, vector(n+1)); // 総和がi、j-1終わり dp[0][0] = 1; vector last_appeared(m, -1); for(int i = 0; i < n; i++) { for(int j = 0; j <= k; j++) { for(int c : {a[s[i]], b[s[i]]}) { if(j+c <= k) { for(int l = last_appeared[s[i]]+1; l <= i; l++) { dp[j+c][i+1] += dp[j][l]; } dp[j+c][i+1] %= MOD; } } } last_appeared[s[i]] = i; } ll ans = accumulate(dp[k].begin(), dp[k].end(), 0LL) % MOD; if(ans < 0) ans += MOD; cout << ans << endl; }