#include using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cerr; using std::cin; using std::cout; using std::endl; #if defined(DONLINE_JUDGE) #define NDEBUG #elif defined(ONLINE_JUDGE) #define NDEBUG #endif template std::vector make_v(size_t a) { return std::vector(a); } template auto make_v(size_t a, Ts... ts) { return std::vector(ts...))>(a, make_v(ts...)); } int main() { int n, k; scanf("%d%d", &n, &k); std::vector c(n), d(n); for (auto& v : c) scanf("%d", &v); for (auto& v : d) scanf("%d", &v); std::vector max(1001, -1); for (int i = 0; i < n; ++i) max[c[i]] = std::max(max[c[i]], d[i]); std::vector cnt(1001, 0); for (int i = 0; i < n; ++i) if (max[c[i]] == d[i]) cnt[c[i]] += 1; std::vector dp(k + 1); for (int i = 0; i < k; ++i) { for (int j = 0; j < 1001 and i + j <= k; ++j) { if (max[j] == -1) continue; dp[i + j] = std::max(dp[i + j], dp[i] + max[j]); } } for (int i = 0; i < k; ++i) dp[i + 1] = std::max(dp[i + 1], dp[i]); const int MOD = 998244353; std::vector ans(k + 1); ans[0] = 1; for (int i = 0; i < k; ++i) { for (int j = 0; j < 1001 and i + j <= k; ++j) { if (cnt[j] == 0) continue; if (dp[i] + max[j] + dp[k - (i + j)] != dp[k]) continue; ans[i + j] += ans[i] * cnt[j] % MOD; ans[i + j] %= MOD; } } i64 sum = 0; for (int i = 0; i <= k; ++i) { if (dp[i] != dp[k]) continue; sum = (sum + ans[i]) % MOD; } printf("%d\n%lld\n", dp[k], sum); return 0; }