// seekworser さんの提出コード #include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; #define rep(i, n) for (int i=0; i> n >> m >> k; vector s(n), a(m), b(m); rep(i, n) { cin >> s[i]; s[i]--; } rep(i, m) cin >> a[i]; rep(i, m) cin >> b[i]; vector br(n+1, vector(m, 0)); for (int i = 1; i <= n; i++) { rep(j, m) br[i][j] = br[i-1][j]; br[i][s[i-1]] = i; } vector dp(n+2, vector(k+1, 0)); dp[1][0] = 1; for (int i=2; i < n+2; i++) rep(j, k+1) { ll si = s[i-2]; ll bpos = br[i-2][si]; if (j - a[si] >= 0) dp[i][j] += dp[i-1][j-a[si]] - dp[bpos][j-a[si]]; if (j - b[si] >= 0) dp[i][j] += dp[i-1][j-b[si]] - dp[bpos][j-b[si]]; dp[i][j] += dp[i-1][j]; } cout << dp[n+1][k].val() << '\n'; }