#include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll INF = 1e18, MX = 20020; void solve() { ll n, W; cin >> n >> W; vector> wv(n); rep(i, n) cin >> wv[i].second >> wv[i].first; sort(wv.begin(), wv.end()); vector> dp(MX + 10, {-INF, -INF}); dp[MX / 2] = {0, 1}; for (const auto [w, v] : wv) { vector> nex = dp; rep(pw, MX) { ll nw = pw + w; if (0 <= nw && nw <= MX) { if (nex[nw].first < dp[pw].first + v) { nex[nw] = {dp[pw].first + v, dp[pw].second}; } else if (nex[nw].first == dp[pw].first + v) { nex[nw].second += dp[pw].second; } } } swap(dp, nex); } ll maxv = -INF; mint ans = 0; for (ll i = 0; i <= W + MX / 2; i++) { if (maxv < dp[i].first) { maxv = dp[i].first; ans = dp[i].second; } else if (maxv == dp[i].first) { ans += dp[i].second; } } cout << maxv << ' ' << ans.val() << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }