#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define debug(...) ((void)0)

#include <atcoder/modint.hpp>
using mint = atcoder::modint998244353;
namespace atcoder {
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
std::ostream& operator<<(std::ostream& os, const static_modint<m>& x) {
    return os << x.val();
}
}  // namespace atcoder

using namespace std;
using ll = long long;
using ld = long double;

void solve(int) {
    int N, W;
    cin >> N >> W;

    unordered_map<int, pair<int, mint>> dp;
    dp[0] = {0, 1};

    for (int i = 0; i < N; i++) {
        int v, w;
        cin >> v >> w;
        auto next_dp = dp;
        for (auto [weight, value] : dp) {
            if (!next_dp.contains(weight + w) || next_dp[weight + w].first < value.first + v) {
                next_dp[weight + w] = {value.first + v, value.second};
            } else if (next_dp[weight + w].first == value.first + v) {
                next_dp[weight + w].second += value.second;
            }
        }
        swap(dp, next_dp);
        debug(dp);
    }

    int ans = numeric_limits<int>::min();
    for (auto&& [weight, value] : dp) {
        if (weight <= W) {
            ans = max(ans, value.first);
        }
    }
    int cnt = 0;
    for (auto&& [weight, value] : dp) {
        if (weight <= W && value.first == ans) {
            cnt += value.second.val();
        }
    }
    cout << ans << ' ' << cnt << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve(0);
}