#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,T; cin >> N >> T; vector R(N); vector> big,small; for(auto &r : R) cin >> r; for(int i=0; i> a >> b; if(a <= b) big.push_back({a,b,R.at(i)}); else small.push_back({a,b,R.at(i)}); } sort(big.begin(),big.end()); long long t1 = 0,t2 = 0; for(auto [a,b,r] : big){ if(t1) t1 += T; if(t2) t2 += T; t2 = max(t2,t1+a)+b*r,t1 += a*r; t2 = max(t2,t1+b); } for(auto [a,b,r] : small){ if(t1) t1 += T; if(t2) t2 += T; t2 = max(t2,t1+a)+b*r,t1 += a*r; t2 = max(t2,t1+b); } long long answer = t2; cout << answer/(24*60) << " " << answer%(24*60)/60 << " " << answer%60 << endl; }