#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) template bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; using mint=atcoder::modint998244353; int main(){ int n,w; cin>>n>>w; vector> vw(n); for(auto&[a,b]:vw) cin>>b>>a; int sz=1e4+10; vector> dpm(sz,{-1e18,0}),dp2(sz+w,{-1e18,0}); dpm.at(0)={0,1}; dp2.at(0)={0,1}; for(auto[a,b]:vw){ if(a<0){ auto ndp=dpm; rep(i,0,sz){ if(i-a>=sz) break; if(chmax(ndp.at(i-a).first,dpm.at(i).first+b)){ ndp.at(i-a).second=dpm.at(i).second; }else if(ndp.at(i-a).first==dpm.at(i).first+b){ ndp.at(i-a).second+=dpm.at(i).second; } } swap(dpm,ndp); }else{ auto ndp=dp2; rep(i,0,sz+w){ if(i+a>=sz+w) break; if(chmax(ndp.at(i+a).first,dp2.at(i).first+b)){ ndp.at(i+a).second=dp2.at(i).second; }else if(ndp.at(i+a).first==dp2.at(i).first+b){ ndp.at(i+a).second+=dp2.at(i).second; } } swap(dp2,ndp); } } ll a=-1e18; mint b=0; rep(i,0,sz) rep(j,0,sz+w){ if(j-i>w) break; if(dpm.at(i).first+dp2.at(j).first>a){ a=dpm.at(i).first+dp2.at(j).first; b=dpm.at(i).second*dp2.at(j).second; }else if(dpm.at(i).first+dp2.at(j).first==a){ b+=dpm.at(i).second*dp2.at(j).second; } } cout<