#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lint = long long; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector& vec, const V& val, int len) { vec.assign(len, val); } template void ndarray(vector& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); } template bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } template bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; } #include using mint = atcoder::modint998244353; int main() { int N, M, K; cin >> N >> M >> K; vector S(N), A(M), B(M); for (auto &x : S) cin >> x, --x; for (auto &x : A) cin >> x; for (auto &x : B) cin >> x; vector dpall(K + 1), dpsnxt(K + 1); dpall.at(0) = 1; vector dp(M, vector(K + 1)); for (const int s : S) { const int a = A.at(s), b = B.at(s); for (int k = 0; k <= K; ++k) { if (k + a <= K) dpsnxt.at(k + a) += dpall.at(k) + dp.at(s).at(k); if (k + b <= K) dpsnxt.at(k + b) += dpall.at(k) + dp.at(s).at(k); dp.at(s).at(k) = -dpall.at(k); dpall.at(k) += dpsnxt.at(k); dpsnxt.at(k) = 0; } } cout << dpall.back().val() << '\n'; }