#include<iostream> #include<climits> #include<vector> #include<algorithm> #include<numeric> #include <string> using namespace std; class Solution{ public: }; int main(){ int n; cin>>n; vector<vector<int>> clocks(n,vector<int>(2)); for(int i=0;i<n;i++){ cin>>clocks[i][0]>>clocks[i][1]; } sort(clocks.begin(),clocks.end(),[](vector<int>&a,vector<int>&b){ if(a[0]==b[0]) return a[1]<b[1]; else return a[0]<b[0]; }); int X; cin>>X; int A,B; cin>>A>>B; vector<int> res; for(vector<int>& clock:clocks){ int h=clock[0]; int m=clock[1]+X; h+=m/60; m%=60; if(h<A||(h==A&&m<=B)){ res=clock; } } cout<<res[0]<<' '<<res[1]; system("pause"); return 0; }