/* #include void self::main(){ LL(N,T); VV(N,a,b); ll M=zip(a).size(); vec>g(M); fo(i,N)g[a[i]].eb(b[i]); vecv2,v1; fo(x,M){ sort(g[x]); v2.eb(g[x][0]); g[x].pop_front(); v1^=g[x]; } sort(v2); sort(v1); zeta(v2); zeta(v1); ll ans=0; fo(k,v2.size()){ ll t2=v2.segment_sum(0,k); if(t2>T)break; ll t1=T-t2; ll l=binary_search_last_true(0,v1.size()+1,[&](ll l){ return v1.segment_sum(0,l)<=t1; }); amax(ans,k*2+l); } pp(ans); } */ #include using namespace std; namespace self{void main();void sub();void pp(auto&&...a);void ppe(auto&&...a);} int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);vin(__VA_ARGS__) #define VV(n,...) RDVV(ll,n,__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);iconstexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);} constexpr auto abs(auto x){return x<0?-x:x;} bool amax(auto&a,const auto&b){return a1)(f((o+x)/2)?o:x)=(o+x)/2;return o;} template>decltype(auto)sort(auto&&a,F f={}){ranges::sort(a,f);return a;} templateusing pack_back_t=tuple_element_t>; } namespace self{ templateconcept vectorial=is_base_of_v::value_type>,remove_cvref_t>; templateconstexpr int depth=0; templateconstexpr int depth =depth+1; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else { } } auto&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} ll size()const{return vector::size();} auto&emplace_back(auto&&...a){vector::emplace_back(std::forward(a)...);return*this;} auto pop_front(){auto r=*this->begin();this->erase(this->begin());return r;} auto segment_sum(ll a,ll b)const{assert(0<=a&&a<=b&&b<=size());C res=0;if(b)res+=(*this)[b-1];if(a)res-=(*this)[a-1];return res;} template>vec stable_sort(F f={})const{vec v=*this;ranges::stable_sort(v,f);return v;} template>auto sort_from(F f={})const{ veco(size()); std::iota(o.begin(),o.end(),0); return o.stable_sort([&](ll i,ll j){return f((*this)[i],(*this)[j]);}); } }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; templateauto zip_by(F f,A&...a){ auto v=(a^...); auto o=v.sort_from(f); vecz(v.size()); decltype(v)u; fe(o,i){ if(u.empty()||f(u.back(),v[i]))u.push_back(v[i]); z[i]=u.size()-1; } ll i=0; ([&](auto&x){fe(x,e)e=z[i++];}(a),...); return u; } auto zip(auto&...a){return zip_by(less<>{},a...);} templatevoid zeta(V&&v){if constexpr(depth>>1){ }fo(i,v.size()-1)v[i+1]+=v[i];} } void self::pp(auto&&...a){const char*c="";((cout<>g(M); fo(i,N)g[a[i]].eb(b[i]); vecv2,v1; fo(x,M){ sort(g[x]); v2.eb(g[x][0]); g[x].pop_front(); v1^=g[x]; } sort(v2); sort(v1); zeta(v2); zeta(v1); ll ans=0; fo(k,v2.size()){ ll t2=v2.segment_sum(0,k); if(t2>T)break; ll t1=T-t2; ll l=binary_search_last_true(0,v1.size()+1,[&](ll l){ return v1.segment_sum(0,l)<=t1; }); amax(ans,k*2+l); } pp(ans); }