#include <iostream>
#include<bits/stdc++.h>
using namespace std;

#define REDL(a ,n) ll a[n];for(ll i=0;i<n;i++) cin>>a[i];
#define pb push_back
#define fi first
#define se second
typedef  long long ll;

typedef pair<ll,ll> pairll;

void coordinate_compress(ll a[], ll n)
{
    ll b[n];
    for(ll i=0; i<n; i++)
        b[i]=a[i];
    sort(b, b+n);
    // ll c[n];
    //  memset(c, 0, sizeof(c));
    for(ll i=0; i<n; i++)
    {
        a[i]=lower_bound(b, b+n, a[i])-b;//+c[a[i]];
        // c[a[i]]++;
    }
}
/*
struct sorte
{
    bool operator()(pairll a, pairll b)
    {
        if(a.second<b.second)
            return true;
        else if(a.second==b.second)
            if(a.first<b.first)
                return true;
        return false;
    }
};
*/
/*
const ll MAXN=1e5+10;
ll tree[MAXN], lazy[MAXN];
void updateRange(ll node, ll start, ll end, ll l, ll r, ll val)
{
    if(lazy[node] != 0)
    {
        // This node needs to be updated
        tree[node] += (end - start + 1) * lazy[node];    // Update it
        if(start != end)
        {
            lazy[node*2] += lazy[node];                  // Mark child as lazy
            lazy[node*2+1] += lazy[node];                // Mark child as lazy
        }
        lazy[node] = 0;                                  // Reset it
    }
    if(start > end or start > r or end < l)              // Current segment is not within range [l, r]
        return;
    if(start >= l and end <= r)
    {
        // Segment is fully within range
        tree[node] += (end - start + 1) * val;
        if(start != end)
        {
            // Not leaf node
            lazy[node*2] += val;
            lazy[node*2+1] += val;
        }
        return;
    }
    ll mid = (start + end) / 2;
    updateRange(node*2, start, mid, l, r, val);        // Updating left child
    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child
    tree[node] = tree[node*2] + tree[node*2+1];        // Updating root with max value
}

ll queryRange(ll node, ll start, ll end, ll l, ll r)
{
    if(start > end or start > r or end < l)
        return 0;         // Out of range
    if(lazy[node] != 0)
    {
        // This node needs to be updated
        tree[node] += (end - start + 1) * lazy[node];            // Update it
        if(start != end)
        {
            lazy[node*2] += lazy[node];         // Mark child as lazy
            lazy[node*2+1] += lazy[node];    // Mark child as lazy
        }
        lazy[node] = 0;                 // Reset it
    }
    if(start >= l and end <= r)             // Current segment is totally within range [l, r]
        return tree[node];
    ll mid = (start + end) / 2;
    ll p1 = queryRange(node*2, start, mid, l, r);         // Query left child
    ll p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
    return (p1 + p2);
}
vector<ll> path;
vector<ll>children[MAXN];
pairll segments[MAXN];
ll timer;
bool visited[MAXN];
void EulerPath(ll start)
{
    visited[start]=true;
    ll start_time=timer;

    path.push_back(start);
    for(auto i:children[start])
    {
        if(!visited[i])
        {
        timer++;
        EulerPath(i);
        }
    }
    ll end_time=timer;
    segments[start]= {start_time, end_time};
}
*/

/*
const ll MAXN=6e5+10;

ll BITarray[MAXN];
ll BITget(ll i, ll n)
{
    i++;
    ll sum=0;
    for(;i>0;i-=(i&(-i)))
        sum+=BITarray[i];
    return sum;
}
void BITupd(ll i ,ll val, ll n)
{
        i++;
    ll sum=0;
    for(;i<=n;i+=(i&(-i)))
        BITarray[i]+=val;

}

/*
const int maxn=1e6+10;
vector<int> adj[maxn];
ll hashes[maxn];
const ll mod=1000000009;
const ll prime=1000033;
ll powers[maxn];
void generate_powers()
{
    powers[0]=1;
    for(int i=1;i<=maxn;i++)
    {
        powers[i]=(powers[i-1]*prime)%mod;
    }
}
void hashout(ll n)
{
    for(int i=1;i<=n;i++)
    {
        for(auto j:adj[i])
        {
            hases[i]=(hashes[i]+powers[j])%mod;
        }
    }
}*/

int main()
{

    ios_base::sync_with_stdio(false);
    int a,ta;
    int b, tb;
    cin>>a>>ta;
    cin>>b>>tb;
    vector<int> buses;
    for(int i=5*60;i<24*60;i+=b)
        buses.pb(i);
    int h,m;
    char _;
    cin>>h>>_>>m;
    int time=h*60+m;
    auto aa=upper_bound(buses.begin() , buses.end() , time-tb);
    auto bb=upper_bound(buses.begin() , buses.end() , time+ta-1)-1;
    cout<<bb-aa+1<<endl;

}

#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}//continue break
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int a,ta,b,tb;cin>>a>>ta>>b>>tb;
        string s;cin>>s;
        int c=0;
        c=(s[3]-'0')*10+(s[4]-'0')+60*((s[0]-'0')*10+(s[1]-'0'));
        int i=300;
        int ans=0;
        int d=c+ta;
        while(1){
            int j=i;
            int k=j+tb;
            if(k<=c||j>=d){

            }
            else{
                ans++;
            }
            // dbg(j,k);
            i+=b;
            if(i>=1440)break;
        }
        cout<<ans;
    }
    timecalculater();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int>start , end;
    int a , fa;
    int b , fb;
    char h1   , h2  , m1 , m2;
    char c;
    cin >> a >> fa;
    cin >> b >> fb;
    cin >> h1 >> h2 >> c >> m1 >> m2;
    for(int i = 300 ; i <= 1439 ; i+=b)
    {
        start.push_back(i);
        end.push_back(i+fb);

    }

    int t1 = ((h1-48)*10+(h2-48))*60 + (m1-48)*10+(m2-48);
    int t2 = t1+fa;
   // cout << t1 << " " << t2 << "\n";
    int pos1 = upper_bound(end.begin() , end.end() , t1)-end.begin();
    int pos2 = upper_bound(start.begin()+pos1 , start.end() , t2-1)-start.begin();

    //cout << start.size() << " " << end.size() << '\n';
    cout << pos2-pos1;

}

#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
int a, ta, b, tb, h, m, L, R;

bool get(int l, int r) {
  if(r<=L || l>=R) return 0;
  return 1;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("A.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  scanf("%d %d %d %d %d:%d", &a, &ta, &b, &tb, &h, &m);
  L = h*60+m;
  R = h*60+m+ta;
  int st = 5*60, ed = 23*60+59;
  int ans=0;
  for(int i=st; i<=ed; i+=b) {
    if(get(i, i+tb)) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <set>
#include <bitset>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long> vl;

#define endl '\n'
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()

void conan()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main()
{
	//conan();

	int a, ta, b, tb, h, m;

	cin >> a >> ta >> b >> tb;
	scanf("%d:%d", &h, &m);

	int start = h * 60 + m;
	int enda = start+ ta;
	int cnt = 0;

	for (int i = 300; i < min(1440, enda); i += b)
	{
		if (i + tb > start)
			cnt++;
	}

	cout << cnt << endl;

}

#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) ;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

struct node
{
	int len,l,r;
};

struct comp
{
      bool operator()(node n1,node n2)
	  {
	     if(n1.len!=n2.len)
		  return n1.len<n2.len;
		 else
		 {
		    if(n1.l>n2.l)
			 return true;
			else
			 return false;
		 }
	  }
};
int minprime[10000000];

void makemodified()
{
	for(int i=2;i*i<10000000;i++)
	{
		if(minprime[i]==0)
		{
			for(int j=i*i;j<10000000;j+=i)
				if(minprime[j]==0)
					minprime[j]=i;
		}
	}

	for(int i=0;i<10000000;i++)
		if(minprime[i]==0)
			minprime[i]=i;
}

//multiple factorise
map< int,int >factorise(int n)
{
map<int, int> salman;
	while(n!=1)
	{
		salman[minprime[n]]++;
		n/=minprime[n];
	}

return salman;
}

bool checkleap(int y)
{
	return ((y%400==0) || ((y%4==0) && (y%100!=0)));
}

bool isintersect(int a,int b,int c,int d)
{

	for(int i=a;i<=b;i++)
	  if(i>c and i<d)
	   return true;

	return false;
}

bool isintersect1(int a,int b,int c,int d)
{

	  if(c>=a and d<=b)
	   return true;

	return false;
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   int a,ta;
   cin>>a>>ta;

   int b,tb;
   cin>>b>>tb;

   string s;
   cin>>s;

   int stmin=((s[0]-'0')*10+(s[1]-'0')-5)*60+((s[3]-'0')*10+(s[4]-'0'));
   int endmin=stmin+ta;

   if(ta==1 && b<=tb)
   {
   	 cout<<1 ;
   	 return 0;
   }
   else if(ta==1)
   {
   	   int ans=0;
	   for(int i=0;i<=1139;i+=b)
	   {
	   	   if(isintersect1(i,i+tb,stmin,endmin))
	   	    ans++;
	   }

	   cout<<ans;
	   return 0;
   }

   //cout<<stmin<<" "<<endmin<<endl;
   int ans=0;
   for(int i=0;i<=1139;i+=b)
   {
   	   if(isintersect(i,i+tb,stmin,endmin))
   	    ans++;
   }

   cout<<ans;

   return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define forn(i, x, n) for(int i=x; i<=n; ++i)
#define rofn(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sze(x) (int) x.size()

int main() {

    int a, b, ta, tb;
    sc("%d %d %d %d", &a, &ta, &b, &tb);

    string s;
    cin>>s;

    int h = stoi(s.substr(0, 2));
    int m = stoi(s.substr(3, 2));

    int st = (h * 60) + m;
    int en = st + ta;

    int ans = 0, x = 300;

    while(1) {

        if((x >= st && x < en) || (x+tb > st)) {
            ans++;
        }
        x += b;

        if(x >= en || x >= 1440) break;
    }

    printf("%d\n", ans);
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int a, ta, b, tb,h,m;
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%d:%d", &h, &m);
	m += h * 60;
	m -= 300;
	printf("%d", (min(m + ta - 1,18*60+59) / b+1) - ((m - tb>=0)?(m-tb)/b+1:0));
	getchar(); getchar();
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,ta,tb,h,m;
    cin>>a>>ta>>b>>tb>>h;
    getchar();
    cin>>m;
    int depart=(h*60)+m-300;
    int start=depart-tb;
    if(start<0)
    {
        start=0;
    }
    start=(start/b)*b;
    if(start<(depart-tb))
    {
        start+=b;
    }
    if(start+tb==depart)
    {
        start+=b;
    }
    int finish=depart+ta;

   //cout<<start<<" "<<finish<<endl;
    if(finish%b==0)
    {
        finish-=b;
    }
     if(finish>1139)
    {
        finish=1139;
    }
    int result;
    if(start>finish)
    {
        result=0;
    }
    else
    {
        result=((finish-start)/b)+1;
    }

    cout<<result<<endl;

}

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define F first
#define S second

#ifndef LOCAL
#define cerr if(0)cerr
#endif // LOCAL

using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const long double ldINF = 1e+018;
const long double EPS = 0.000000001;
const int base = INF;
const int sdx[4] = {0, 1, 0, -1};
const int sdy[4] = {1, 0, -1, 0};

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    string t;
    cin >> t;
    int h = (t[0] - '0') * 10 + (t[1] - '0');
    int m = (t[3] - '0') * 10 + (t[4] - '0');
    //cout << h << ' ' << m << endl;
    int s = h * 60 + m;
    int f = h * 60 + m + b;
    int cur = 5 * 60;
    int ans = 0;
    while (true) {
        if (cur > 23 * 60 + 59)
            break;
        if (cur >= s && cur < f)
            ans++;
        else
            if (cur + y > s && cur + y <= f)
                ans++;
            else
                if (cur <= s && cur + y >= f)
                    ans++;
//        cout << cur / 60 << ' ' << cur % 60 << endl;
//        cout << ans << endl;
//        cout << cur << ' ' << s << ' ' << f << endl;
        cur += x;
    }
    cout << ans << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
#include<deque>
#include<queue>
#include<cmath>
#include<vector>
#include<math.h>
#include<set>
#include<map>
using namespace std;
void mansour()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
long long x[200005];
int main()
{
	mansour();
	/*The First*/
	long long a,b,ta,tb,h,m,mas,mae,mbs,mbe,c=0;
	char x;
	cin>>a>>ta>>b>>tb>>h>>x>>m;
	mas=m+(h*60);
	mae=mas+ta;
	mbs=5*60;
	mbe=mbs+tb;
	while(true)
	{

		if(mbs>=24*60)
			break;
		if(mbs<mae && mbe>mas)
			c++;

		mbs+=b;
		mbe=mbs+tb;
	}
	cout <<c<<"\n";
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=24*60;
int main()
{
   int a,b,ta,tb,h,m,cnt;
   char c;
   cin>>a>>ta;
   cin>>b>>tb;
   cin>>h>>c>>m;
   int st=h*60+m;
   int ed=h*60+m+ta;
   int s=5*60;
   cnt=0;
   while(s<60*24)
   {
       if(((s+tb)>st&&s<ed)||(s<ed&&s>st) )cnt++;
       s+=b;
   }
   cout<<cnt;
}

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
    int a,ta,b,tb,totalTime,z;
    string startTime;
    cin>>a>>ta>>b>>tb>>startTime;
    int hours = atoi(startTime.substr(0,2).data())-5;
    int mins = atoi(startTime.substr(3,2).data());
    totalTime = hours*60 + mins;
    z = 0;
    int timeCount = 0;
    while ((totalTime + ta)> timeCount && (timeCount) < (19 * 60)){
        if ((timeCount) < (totalTime+ta) && (timeCount+tb) > totalTime){
            z++;
        }
        timeCount+=b;
    }
    cout<<z;
    return 0;
}

#include <cstdio>
#include <string>
using namespace std;

int a, ta, b, tb;

int amount(int ti)
{
	if (ti == -1) return 0;
	return ti / b + 1;
}

int main()
{
	string s;
	char buf[6];
	scanf("%d%d%d%d%s", &a, &ta, &b, &tb, buf);
	s = buf;
	int t = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3, 2)) - 300;
	printf("%d\n", amount(min(t + ta - 1, 1139)) - amount(max(t - tb, -1)));
	return 0;
}

#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;
int a[16], b[16];
int main() {
	int a, ta, b, tb;
	cin >> a >> ta >> b >> tb;
	string st;
	cin >> st;
	int ans = 0, z = b;
	b = 300;
	int time = stoi(st.substr(0, 2))*60 + stoi(st.substr(3)), end = time + ta;
	while (b < 1440) {
		if (b <= time && b + tb>time ||  b < end && b+tb >= end || b>=time && b+tb<=end) {
			ans++;
		}
		b += z;
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main ()
{
    int _, ta, b, tb;
    int hh, mm;
    char __;
    cin >> _ >> ta >> b >> tb >> hh >> __ >> mm;
    //cout << hh << " " << mm << endl;
    int l1 = hh * 60 + mm, r1 = l1 + ta;
    int cunt = 0;
    for (int i = (5 * 60); i < 24 * 60; i += b)
    {
        int l2 = i;
        int r2 = i + tb;
        int l3 = max(l1, l2), r3 = min(r1, r2);
        if (l3 < r3)
        {
            cunt++;
        }
    }
    cout << cunt << endl;
}

#include <iostream>

using namespace std;

int main()
{
    int a,ta;
    cin >> a >> ta;
    int b,tb,h=0,m=0,num=0;
    int totmin;
    cin >> b >> tb;
    string s;
    cin >> s;
    for(int i =0; i<2; i++){
        h=h*10+(s[i]-'0');
    }
    for(int i =3; i<5; i++){
        m=m*10+(s[i]-'0');
    }
    totmin=h*60+m;
    for(int i = 5*60; i<=1439; i+=b){
        if((i<=totmin&&i+tb>totmin)||(i>=totmin&&i<totmin+ta))
            num++;
    }
    cout << num;
}

#include <iostream>
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
int main()
{
    int h,m;
    int a,ta,b,tb;
    scanf("%d%d",&a,&ta);
    scanf("%d%d",&b,&tb);
    scanf("%d:%d",&h,&m);
    m=m+h*60;
    int now=5*60;
    int ans=0;
    while(now+tb<=m)
    {
        now+=b;
    }
    while(now<ta+m&&now<24*60)
    {
        ans++;
        now+=b;
    }
    printf("%d\n",ans);
}

#include <iostream>
#include <cstdio>

using namespace std;

static const int LO = 5 * 60;
static const int HI = 23 * 60 + 59;

int main() {
	int a, ta, b, tb, hh, mm;
	scanf("%d%d", &a, &ta);
	scanf("%d%d", &b, &tb);
	scanf("%d:%d", &hh, &mm);

	int lu = hh * 60 + mm;
	int ru = lu + ta;

	int lhs = LO, rhs = LO + tb;
	int res = 0;
	while (lhs <= HI) {
		if (lu < rhs && ru > lhs) {
			++res;
		}
		lhs += b;
		rhs += b;
	}

	//cout << lhs << endl;
	//cout << rhs << endl;

	printf("%d\n", res);
	return 0;
}

#include <iostream>
#include<string>
#include<bits/stdc++.h>
#include<set>
#include<stack>
using namespace std;
int fre[100005];
int arr[100005];
int a[100005];
int main()
{
std::ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int a,b,r,c,d,q=0;
cin>>a>>b;
cin>>c>>d;
int l=d;
string s;
cin>>s;
r=((((s[0]-'0')*10)+(s[1]-'0'))*60)+(((s[3]-'0')*10)+(s[4]-'0'));
int h=b+r;
for(int i=300; i<h; i+=c){
   int f=i+l;
    if(i>(24*60)-1)
    break;
    if(f>r)
    q++;
}
cout<<q<<endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
int main()
{

	int a,ta,b,tb,count=0;
	cin>>a>>ta;
	cin>>b>>tb;
	int diff=b-a;
	if(diff<0) diff=0;

	struct bus
	{
		int start,finish;

	};
	string input;
	cin>>input;
	string hr=input.substr(0,2),min=input.substr(3,2);
	int hour=stoi(hr),minute=stoi(min);
	int simitime=hour*60+minute;
	bus simion;
	simion.start=simitime;
	simion.finish=simitime+ta;
	for (int i=300;i<1440;i+=b)
	{
		bus X;
		X.start=i;
		X.finish=i+tb;
		if((X.start>=simion.start&&X.start<simion.finish)||(X.finish>simion.start&&X.finish<simion.finish))
			count++;
		else if(X.start<simion.start)
		{
			int travel=X.start+1;
			for(;;travel++)
			{
				if(travel==simion.start&&travel<X.finish)
				{
					count++;
					break;
				}
				else if(travel==X.finish) break;
			}
		}

	}
	cout<<count<<endl;

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FI(i,L,R) int i; for(i = L;i<R;i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FEI(i,L,R) int i;for(i = L;i <= R;i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFI(i,L,R) int i;for (i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define FFEI(i,L,R) int i;for (i = L; i >=R; i--)

#define getI(a) cin>>a
#define getII(a,b) cin>>a>>b
#define getIII(a,b,c) cin>>a>>b>>c
#define wez(n) int (n); cin>>n //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); cin>>n>>m
#define wez3(n,m,k) int (n),(m),(k); cin>>n>>m>>k
#define TESTS wez(testow);while(testow--) //for multilple cases problems
#define arrayIn(a,L,R) FE(i,L,R) cin>>a[i]
#define VectorIn(V,n) FE(i,0,n-1){wez(xscd);V.pb(xscd);}  // remember to not use ;
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define fi first
#define se second
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define pb push_back
#define MAXN 100001       // 1e5
#define Q 1000000007

typedef pair<int,int> pi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int fA,tA,fB,tB,hr,min;
    cin>>fA>>tA;
    cin>>fB>>tB;
    string s;
    cin>>s;
    stringstream ss(s);
    char col;
    ss>>hr>>col>>min;
    int finish[1500];
    int star[1500];
    FE(i,0,1499)
    {
        finish[i] = 0; star[i] = 0;
    }
    int i;
    for(i = 0;i<1140;i+=fB)
    {
    	finish[i+tB] = 1;
    	star[i] = 1;
    }
    int curr = (hr-5)*60+min;
    int end = curr+tA;
    int Onroad = 0,Gen = 0;
    F(i,curr,end)

    {
        if(star[i] == 1)
        Gen += star[i];
    }
    int startcnt = 0, finishcnt = 0;
    F(i,0,curr)
    {
    	startcnt += star[i];
    	finishcnt += finish[i];
    }
    finishcnt += finish[curr];

    Onroad = (startcnt - finishcnt);
    cout<<Onroad+Gen;

	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <unordered_set>

typedef unsigned long long ull;
typedef long long ll;
using std::vector;

int main() {
#ifndef ONLINE_JUDGE
	freopen("A.txt", "rt", stdin);
#endif

	const int start = 300;
	const int end = 1439;

	int a, ta, b, tb;
	std::cin >> a >> ta >> b >> tb;

	int hh, mm;
	char c;
	std::cin >> hh >> c >> mm;

	int s = hh * 60 + mm;
	int first = std::max(start, s - tb);
	int last = std::min(end, s + ta);

	int result = 0;
	for (int time = start; time <= end; time += b)
	{
		if (time >= first && time <= last)
		{
			if (time + tb == s) continue;
			if (time == s + ta) continue;
			++result;
		}
	}

	std::cout << result;

	return 0;
}

#include "bits\stdc++.h"
using namespace std;

#define STARTTIME (5*60)
#define ENDTIME (24*60)

int main() {
	int a,ta,b,tb,t0;
	int h, m;
	int ans = 0;
	int i,limit;

	cin >> a >> ta >> b >> tb;
	scanf("%02d:%02d",&h,&m);
	t0 = h * 60 + m;
	limit = t0 + ta;

	for (i = STARTTIME; i < limit && i < ENDTIME; i += b)
	{
		if (i + tb <= t0) continue;
		ans++;
	}

	cout << ans;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int a,ta,b,tb;
	int h,m,t;
	scanf("%d %d %d %d",&a,&ta,&b,&tb);
	scanf("%d:%d",&h,&m);
	t=(h-5)*60+m;
	int ans=0;
	set<int> ss;
	int en=(11+12-5)*60+59;
	for(int x=0;x<=en;x+=b)
	{
		int y=x+tb;
		int mn=max(x,t),mx=min(y,t+ta);
		if(mn<=mx) {
			if(mn==mx&&(mn==t||mx==t+ta));
			else ss.insert(x);
		}
	}
	cout << ss.size() << endl;
}

#include <stdio.h>

int main() {

	int a, ta, b, tb;
	scanf("%d %d %d %d", &a, &ta, &b, &tb);

	int h, m;
	scanf("%d:%d", &h, &m);

	int start = h * 60 + m;
	int end = start+ ta;

	int cnt = 0;
	for (int i = 300 ; i < 1440; i+=b) {
		if (i + tb <= start)
			continue;
		if (i >= end)
			break;
		cnt++;
	}
	printf("%d", cnt);
}

#include<bits/stdc++.h>

using namespace std;
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define ff first.first
#define fs first.second
typedef long long ll;
typedef unsigned long long ull;

const ll mod = 1e16+371;
//const ll mod = 1e12+193;

const double PI = acos(-1);
const ll INF = 1e18;
const ll MAX=1e5+10, N=1e6;
//const int lim=1<<18;
//const ll mod = 100000000 ;

int main(){
	ios_base::sync_with_stdio(0);
//	cin.tie(0);
//	srand(time(0));

	int a,ta,b,tb;
	while(cin>>a>>ta>>b>>tb){
		int hr; cin>>hr;
		char c; cin>>c;
		int mi; cin>>mi;
		int strt=hr*60+mi;
		int lst=strt+ta;
		int ans=0;
		for(int x=300;x<24*60;x+=b){
			if(strt>=x+tb || lst<=x)
				continue;
			ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

#include <cstdio>
#include <algorithm>
#include<cmath>
#include<string.h>
#include<memory.h>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <stdio.h>
#include <stack>
#include <set>
#define MOd 0x7FFFFFFF;
#define mod 65537;
using namespace std;
typedef  long long LL;
const int N=1e9+7;
int a,ta,b,tb,t1,t2;
char c;
int main(){
//freopen("in.txt","r",stdin);
cin>>a>>ta>>b>>tb;
cin>>t1>>c>>t2;
int nt1=t1*60+t2;
int met2=nt1+ta;
int met1=nt1-tb;
int fg1=0,fg2=0;
if(met1<300){
    met1=300;
fg1=1;
}
if(met2>23*60+59){
    met2=23*60+59;
fg2=1;
}
int num=0;
for(int i=300;i<=23*60+59;i+=b){
    if(i>met1&&i<met2)
        num++;
    else if(i==met1){
        if(fg1==1)
        num++;
    }
    else if(i==met2){
        if(fg2==1)
        num++;
    }

}
cout<<num<<endl;
return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <set>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <ctime>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef pair<bl, bl> pbl;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define ft first
#define sd second
#define forn(i, y, x) for(int i = y; i < x; i++)
#define ford(i, y, x) for(int i = y; i >= x; i--)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define error exit(1)
#define DEBUG
const int mod = (int)1e9;
const int inf = (int)1e9;
const int base = 1000 * 1000 * 1000;
const int maxn = 2005;
const ld pi = acosl(-1.0);
const ld eps = 1e-9;

void solve()
{
	int a, ta, b, tb;
	scanf("%d %d %d %d", &a, &ta, &b, &tb);
	int h, m;
	scanf("%d:%d", &h, &m);
	int ot = h * 60 + m;
	int t = h * 60 + m + ta;
	int ans = 0;
	for (int i = 5 * 60; i < 24 * 60; i += b){
		if (i + tb > ot && i < t) ans++;
	}
	printf("%d", ans);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <iostream>
#define m 60*24-1
using namespace std;

int main()
{
   int a,b;
   int c,d;
   int e,f;
   cin>>a>>b>>c>>d;
   scanf("%d:%d",&e,&f);
   int q=e*60+f-d;
   int w=e*60+f+b;
if(w>m) w=m;
if(q<300) q=300;

int lze=300;
int ans=0;
//cout<<q<<' '<<w<<endl;
while(lze<=m)
{

    if(lze>=q&&lze<=w) {
            if(lze+d==e*60+f) ans--;
            if(lze==e*60+f+b) ans--;
            ans++;

  //cout<<lze<<' ';
    }
        lze+=c;
}

cout<<ans;

	return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;
struct node
{
    int h,m;
};
node p[320000];
int main()
{
    int A,ta,B,tb;
    cin>>A>>ta>>B>>tb;
    char s[5];
    cin>>s;
    int begh,begm;
    begh=(s[0]-'0')*10+s[1]-'0';
    begm=(s[3]-'0')*10+s[4]-'0';
    int i;
    int bgh=5,bgm=0;
    for(i=0;i<=300000;i++)
    {
        p[i].h=bgh;
        p[i].m=bgm;
        bgm+=B;
        bgh+=bgm/60;
        bgm%=60;
        if(bgh>=25)break ;
    }
    int finm=begm+ta;
    int finh=begh+finm/60;
   // cout<<finm<<endl;
    finm%=60;
    begm-=tb;
    begh+=(begm-59)/60;
    while(begm<0)begm+=60;
    int ans=0;
    //cout<<begh<<":"<<begm<<endl;
    //cout<<finh<<":"<<finm<<endl;
    if(begh<5){begh=4;begm=59;}
    if(finh>=24){finh=24;finm=0;}
    for(i=0;i<=200000;i++)
    {
        if(p[i].h==begh&&p[i].m==begm)continue ;
        if(p[i].h==finh&&p[i].m==finm)continue ;
        if(finh==begh&&p[i].h==finh)
        {
            if(p[i].m>begm&&p[i].m<finm){ans++;}
            continue ;
        }
        else
        {
        if(p[i].h==begh&&p[i].m>begm)ans++;
        if(p[i].h==finh&&p[i].m<finm)ans++;
        if(p[i].h<finh&&p[i].h>begh)ans++;}
        if(p[i].h>=24)break ;
       // cout<<p[i].h<<":"<<p[i].m<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,ta,b,tb;
    int h,m;
    char ch;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d%c%d",&h,&ch,&m);
    int k=(h-5)*60+m;
    int s=k-tb,e=k+ta;
//    cout<<k<<' '<<s<<endl;
    if(e>1140)
        e=1140;
    int i=1;
    int n,ans=0;
    if(s>=0)
    {
        while(1)
        {
            n=i*b;
            if(n==s)
                break;
            else if(n>s)
            {
                if(n<=e)
                    ans++;
                break;
            }
            i++;
        }
    }
    else
    {
        n=0;
        if(n!=k)
            ans++;
    }
//    cout<<i<<endl;
//    cout<<s<<' '<<n<<' '<<e<<endl;
    ans+=(e-n)/b;
    while(1)
    {
        n=i*b;
        if(n==e)
        {
            ans--;
            break;
        }
        else if(n>e)
            break;
        i++;
    }
    printf("%d\n",ans);
    return 0;
}

//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<memory.h>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<int>             VI;
typedef vector<bool>            VB;
typedef vector<VI>              VVI;
typedef vector<string>          VS;
typedef pair<int, int>           PII;
typedef map<string, int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int, int>            MII;
typedef pair<double, double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

void solve(int t) {
	int a, ta, b, tb;
	cin >> a >> ta >> b >> tb;

	string time;
	cin >> time;
	int sT = ((time[0] - '0') * 10 + (time[1] - '0')) * 60 + (time[3] - '0') * 10 + time[4] - '0';
	//cout << sT << endl;
	int ans = 0;

	int startTime = 5 * 60;
	//cout << sT << " " << sT + ta << endl;
	while (startTime < 24 * 60) {
		//cout << startTime << " " << startTime + tb << endl;
		if (max(sT, startTime) < min(sT+ta, startTime+tb)) {
			ans++;
		}
		startTime += b;
	}

	cout << ans << endl;
}

int main() {
	//freopen("in.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
	solve(0);
	return 0;
}

# include <iostream>
# include <cstdio>
# include <vector>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <algorithm>
# include <string>

using namespace std;

int main()
{
    int a, ta, b, tb;
    cin >> a >> ta >> b >> tb;
    string s;
    cin >> s;
    int timein = 60 * (10 * (s[0] - '0') + s[1] - '0') + 10 * (s[3] - '0') + s[4] - '0';
    int timeout = timein + ta;
    //cout << timein << endl;
    int kol = 0;
    int i;
    for (i = 0; 300 + b * i < 1440; i++)
    {
        if (((300 + b * i > timein) && (300 + b * i < timeout)) || ((300 + b * i <= timein) && (300 + b * i + tb > timein)))
        {
            kol++;
        }
    }

    cout << kol << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

int a, ta, b, tb;
string hour;

int main() {
    cin >> a >> ta;
    cin >> b >> tb;
    cin >> hour;
    int num = 0;
    int num2 = 0;
    int i;
    int last = 1139;
    for (i = 0; i < hour.length(); i++) {
        if ('0' <= hour[i] && hour[i] <= '9') {
            num = num * 10 + hour[i] - '0';
        }
        else if (hour[i] == ':') {
            num -= 5;
            break;
        }
    }
    for (; i < hour.length(); i++) {
        if ('0' <= hour[i] && hour[i] <= '9') {
            num2 = num2 * 10 + hour[i] - '0';
        }
    }
    num *= 60;
    num += num2;
    num2 = num + ta;
    int ans = 0;
    int start = 0;
    while (start < num2 && start <= last) {
        if (start + tb > num) ans++;
        start += b;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a, ta, b, tb;

    cin >> a >> ta >> b >> tb;

    int h, m;
    scanf("%d:%d", &h, &m);

    int st = (h*60) + m, last = st + ta, cnt = 0;

    for(int i = 300; i < last; i += b){
        if(i > 1439) break;
        if((i >= st && i < last) || (i < st && (i+tb) > st)) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,ta;
    int b,tb;
    int h,m;
    char input[10],trans[10];
    scanf("%d%d",&a,&ta);
    scanf("%d%d",&b,&tb);
    scanf("%s",input);
    strncpy(trans,input,2);
    trans[2]=='0';
    h=atoi(trans);
    strncpy(trans,input+3,2);
    trans[2]=='0';
    m=atoi(trans);
    int totalMin = 5*60+ 0;
    int dep = 23*60+59;
    int goTime[2000],depTime[2000];
    for(int i=0;i<2000;i++){
        goTime[i]=totalMin;
        depTime[i]=totalMin+tb;
        if(goTime[i]>dep){
            goTime[i]=-1;
            depTime[i]=-1;
            break;
        }
        totalMin+=b;
    }
    totalMin=h*60+m;
    dep = totalMin+ta;
    int sum=0;
    for(int i=0;i<2000;i++){
        if(goTime[i]==-1)break;
        if(goTime[i]==totalMin) sum++;
        else if(goTime[i]<totalMin && depTime[i]>totalMin)sum++;
        else if(goTime[i]>totalMin && goTime[i] < dep) sum++;
    }
    cout << sum << endl;

}

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
#include <assert.h>

using namespace std;

int main()
{
#ifdef TEST
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin.sync_with_stdio(0);

	int a, ta, b, tb;
	cin >> a >> ta >> b >> tb;

	string s;
	cin >> s;

	int sh = int(s[0] - '0') * 10 + int(s[1] - '0');
	int sm = int(s[3] - '0') * 10 + int(s[4] - '0');
	int stime = sh * 60 + sm;

	int mintime = 5 * 60;
	int maxtime = 24 * 60 - 1;

	int timeFrom = stime - tb;
	int timeTo = stime + ta;

	int count = 0;
	int time = mintime;
	while (time <= maxtime)
	{
		if (time > timeFrom && time < timeTo)
		{
			count++;
		}

		time += b;
	}

	cout << count << endl;
	return 0;
}

#include <bits/stdc++.h>

#define int long long
#define ld long double
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int a, ta;
    cin >> a >> ta;
    int b, tb;
    cin >> b >> tb;

    string start;
    cin >> start;

    int hh = stoll(start.substr(0,2));
    int mm = stoll(start.substr(3,2));

    int m = hh*60 + mm;

    int left = m;
    int right = m + ta;

    // cout << left << ' ' << right << endl;

    int cnt = 0;

    for(int time = 300; time < 1440; time+=b)
    {
        int start = time;
        int end = time + tb;

        // cout << start << ' ' << end << ' ';

        if(start >= right)
        {
            break;
        }

        if(left < end && start < right)
        {
            cnt++;
            // cout<<"yes\n";
            continue;
        }

        if(start > left && start < right)
        {
            cnt++;
            // cout << "yes\n";
            continue;
        }

        if(end > left && end < right)
        {
            cnt++;
            // cout << "yes\n";
            continue;
        }

        // cout << endl;
    }

    cout << cnt;

    return 0;
}

#if 1
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <fstream>
#include <chrono>
using namespace std;
using namespace std::chrono;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ull> vull;
typedef vector<vull> vvull;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

#define fs first
#define sc second
#define pb push_back
// forward strict for, most common
#define fors(i, a, n) for (int i = (int) (a); i < (int) (n); ++i)
// forward inclusive for
#define fori(i, a, n) for (int i = (int) (a); i <= (int) (n); ++i)
// backward for, inclusive
#define forb(i, n, a) for (int i = (int) (n); i >= (a); --i)

template <typename T>
void print(string name, vector<T>& v) {
    if (name.size()) cout << name << ": ";
    int s = (int) v.size();
    fors(i, 0, s) cout << v[i] << " ";
    cout << endl;
}
template<typename T> void print(vector<T>& v) { print("", v); }
#endif

int main() {
#ifdef LOCAL_CODE
    stringstream ss(R"(
10 30
10 35
05:20

60 120
24 100
13:00

30 60
10 60
23:30
)");
    cin.rdbuf(ss.rdbuf());
    int test_cases = 3;
#else
    int test_cases = 1;
    ios::sync_with_stdio(false); // faster cin/cout, do not mix with scanf, printf!!!
#endif

    fors(test_case, 0, test_cases) {
//    	cout << "test case " << test_case << endl;

        int a, ta, b, tb;
        string shm;
        cin >> a >> ta >> b >> tb >> shm;
        int h, m;
        h = (shm[0] - '0') * 10 + shm[1] - '0';
        m = (shm[3] - '0') * 10 + shm[4] - '0';

        int res = 0;

        int hm = h * 60 + m;
        int hm2 = hm + ta;
//        cout << "Start and end " << hm << " " << hm2 << endl;
        fors(i, 0, 24 * 60) {
        	int hmb = 5 * 60 + i * b;
        	if (hmb >= 24 * 60) break;

        	int hmb2 = hmb + tb;

        	if (hmb2 <= hm || hm2 <= hmb) continue;
        	else {
//				cout << hmb << " " << hmb2 << endl;
        		res++;
        	}
        }

        cout << res << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long long x,y,a ,ta , b , tb ,t, ans = 0     ;
    char z;
    cin>>a>>ta>>b>>tb;
    cin>>x>>z>>y;
    t = x*60+y;
    for( long long  i = 5*60 ; i < 24*60 ; i+=b ){
        if(t+ta>i && t<=i)  ans++;
      else
        if(t>i && i+tb>t) ans++;
    }
    cout<<ans;
    return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;

int a, ta;
int b, tb;
int h, m;
inline int max(int a, int b)
{
	return a < b ? b : a;
}
inline int min(int a, int b)
{
	return a < b ? a : b;
}

bool read() {
	if (!(cin >> a >> ta)) return false;
	cin >> b >> tb;
	char c;
	cin>>h>>c>>m;
	return true;
}

int main() {
	read();
	int x1 = h * 60 + m;
	int y1 = x1 + ta;

	int ans = 0;
	for (int x2 = 5 * 60 + 0; x2 < 24 * 60; x2 += b) {
		int y2 = x2 + tb;
		int x = max(x1, x2), y = min(y1, y2);
		if (x < y)
			ans++;
	}
	cout << ans << endl;
}

#include<iostream>
using namespace std;
int main(void)
{
	int x1,y1,x2,y2;
	cin>>x1>>y1;
	cin>>x2>>y2;
	char a[10];
	cin>>a;
	int time,time1,c1,c2;
	time=((a[0]-'0')*10+(a[1]-'0')-5)*60+(a[3]-'0')*10+(a[4]-'0');
	time1=time+y1;
    int judge=time1;
	if(time1>=1140)
	time1=1139;
	if(time<y2)
	c1=0;
	else c1=(time-y2)/x2+1;
	if(time1%x2==0)
	{
	if(judge>time1)
	c2=time1/x2+1;
	else c2=time1/x2;
	}
	else c2=time1/x2+1;
	cout<<c2-c1<<endl;
	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<set>
#include<stack>
#include<fstream>
using namespace std;
int a,ta,b,tb,t,ans,now;
string x;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>ta>>b>>tb;
    cin>>x;
    t=((x[0]-'0')*10+x[1]-'0')*60+((x[3]-'0')*10+x[4]-'0');
    for(int nt=300;nt<t+ta;nt++){
        if(nt<=1439&&(nt-300)%b==0){
            now++;
            if(nt>t){ans++;}
        }
        if((nt-300-tb)%b==0&&nt>=300+tb) now--;
        if(nt==t)ans+=now;
    }
    cout<<ans<<endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <list>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

//#define _LOCAL_DEBUG_
#ifdef _LOCAL_DEBUG_
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

int a, ta, b, tb;

void clear() {
}

void solve() {
	int h, m;
	scanf("%d:%d", &h, &m);
	m += h * 60;
	int r = 0;
	for (int depTime = 5 * 60; depTime <= 23 * 60 + 59; depTime += b)
		if (depTime > m - tb && depTime < m + ta)
			r++;

	printf("%d\n", r);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d%d%d%d", &a, &ta, &b, &tb) == 4) {
		clear();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

/***************************************
    codeforces = topcoder = sahedsohel
    IIT,Jahangirnagar University(42)
****************************************/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define inf (INT_MAX/10)
#define linf (LLONG_MAX/10LL)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define fl(c,i,n) for(i=c;i<n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define memn(a) memset(a,-1,sizeof(a))
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
#define mpr make_pair
#define PI (2.0*acos(0.0)) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pii pair< int , int >
#define pll pair< ll , ll >
#define pcs(a) printf("Case %d: ", a)
#define nl puts("")
#define endl '\n'
#define dbg(x) cout<<#x<<" : "<<x<<endl

template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}

int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}

///int mnth[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
///int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
///int kdx[]={2,1,-1,-2,-2,-1,1,2};int kdy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
///int dx[]={-1,+1,0,1,0,-1}; // Hexagonal Direction   **
///int dy[]={-1,+1,1,0,-1,0}; //                       *#*
///                                                     **
const double eps=1e-9;

/*****************************************************************/
/// ////////////////////   GET SET GO    ////////////////////// ///
/*****************************************************************/

#define intx(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(a[k]-a[l])-(a[i]-a[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define inty(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
#define area(i,j,k) ((ll)x[i]*y[j]+(ll)x[j]*y[k]+(ll)x[k]*y[i]-(ll)y[i]*x[j]-(ll)y[j]*x[k]-(ll)y[k]*x[i])

int ts,kk=1;

#define M 200005
#define MD 1000000007LL
#define MX 10005

int a,b,ta,tb;
vector< int >v;
char s[10];

int main()
{
    int t,i,j,k;

    sc2(b,tb);
    sc2(a,ta);
    k=0;
    for(i=300;i<1440;i+=a)
    {
        v.pb(i);
    }
    scanf(" %s",s);

    j=s[0]*10-480+s[1]-48;
    k=s[3]*10-480+s[4]-48;

    int rs=0;
    j=j*60+k;
    for(i=0;i<v.size();i++)
    {
        if( j+tb==v[i] )continue;
        if( v[i]+ta==j )continue;
        pii x,y;
        x=pii(j,j+tb);
        y=pii(v[i],v[i]+ta);
        if(x>y)swap(x,y);
        if( x.xx<=y.xx&&y.xx<=x.yy )
        {
            rs++;
            continue;
        }
        if( y.xx<=x.yy&&x.yy<=y.yy )
        {
            rs++;
            continue;
        }
    }
    cout<<rs<<endl;

    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

bool doesIntersect(ii x, ii y)
{
    if(x > y)
        swap(x, y);
    if(x.second <= y.first)
        return 0;
    return 1;
}

int main()
{
    int a, ta, b, tb;
    int depHour, depMin;
    char ch;
    vector<ii>v;
    int curTime = 0;
    while(cin >> a >> ta >> b >> tb >> depHour >> ch >> depMin)
    {
        v.clear();
        depHour -= 5;
        int depTime = depHour * 60 + depMin;
        int res = 0;
        for(curTime = max(0, depTime - tb); curTime < min(depTime + ta, 1140); curTime ++)
        {
            if(curTime % b == 0 && doesIntersect(mp(depTime, depTime + ta), mp(curTime, curTime + tb)))
                res++;
        }

        cout << res << nl;

    }

    return 0;
}

#include <iostream>
#include <stdio.h>
#include <numeric>
#include <queue>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <iomanip>
#include <set>
#include <queue>
#include <bitset>
#include <iomanip>
#include <map>
#include <string.h>
#include <stack>
#include <algorithm>

#include <unordered_map>
#include <unordered_set>

using namespace std;

char come_time[100];

int get_minutes()
{
	int hour = (come_time[0] - '0') * 10 + (come_time[1] - '0');
	int minute = (come_time[3] - '0') * 10 + (come_time[4] - '0');
	return hour * 60 + minute;
}

int main()
{
	// 坐上车前发车的有多少辆，坐上车到达之前的时间能够发车多少辆
	int a , ta , b , tb;
	while (scanf("%d%d%d%d" , &a , &ta , &b , &tb) != EOF)
	{
		scanf("%s" , come_time);
		int come = get_minutes();
		// 第一辆发车的时间和最后一辆发车的时间
		int ans = 0;
		// 判断每一分钟
		for (int i = 5 * 60;i < 24 * 60;i ++)
		{
			if ((i - 5 * 60) % b == 0)
			{
				// 判断跑在路上的
				if (i + tb > come && i < come)
					ans ++;
				// 判断碰面的
				if (i >= come && i < come + ta)
					ans ++;
			}
		}
		printf("%d\n" , ans);
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

long long t1a, t2a, t1b, t2b, tl, tr, start, ans, hours, minuts;
char x;
main(){
    cin >> t1a >> t2a;
    cin >> t1b >> t2b;
    cin >> hours >> x >> minuts;
    tl = hours * 60 + minuts;
    tr = tl + t2a;
    start = 5 * 60;
    for (int i = 0; start + i * t1b <= 23 * 60 + 59; i++){
        long long cl =start +  i * t1b;
        long long cr = cl + t2b;
        if (cr < cl) cl = cr;
        if (min(tr,cr) > max(cl, tl)) ans++;
    }
    cout << ans;
}

#include <bits/stdc++.h>
#define fr first
#define pb push_back
#define skip continue
#define sc second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define vi vector<ll>
#define MAX 1e9 + 1234
#define PI 2.00*acos(0)
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<char, int> pci;

int const INF = 1e8 + 100;
const int MOD = 998244353;
const int N = 310500;
const ld EPS = 3e-16;

void faster(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int simple( int n ) {
    int i, sq;
    if ( n%2 == 0 ) { return 0; }
    sq= (int)sqrt( n );
    for ( i= 3; i<=sq; i++ ) {
    if ( (n%i) == 0 ) { return 0; }
    }
    return 1;
}
ll gcd(ll a, ll b){
    if(a > b)	swap(a, b);
    if(!a)	return b;
    return gcd(b % a, a);

}

ll lcm (ll a, ll b) {
	return a / gcd (a, b) * b;
}

bool ok(int a, pii& b)
{
    return a >= b.fr && a <= b.sc;
}

bool check(pii& a, pii& b)
{
    return ok(a.fr, b) || ok(a.sc, b) || ok(b.fr, a) || ok(b.sc, a);
}

void solve(){
    int a , ta;
    cin >> a >> ta;
    int b , tb;
    cin >> b >> tb;
    string s;
    cin >> s;
    int h , m , t;
    h = (s[0] - '0') * 10 + (s[1] - '0');
    m = (s[3] - '0') * 10 + (s[4] - '0');
    int t1 = h * 60 + m;
    int t2 = h * 60 + m + ta;

    int t3 = 300, ans = 0;
    while (t3 <= min(t2, 23 * 60 + 59))
    {
        int t4 = t3 + tb;
        int l = max(t1, t3);
        int r = min(t2, t4);
        if (l < r) ans++;
        t3 += b;
    }

    cout << ans << endl;
}
int main(){

    faster();
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	ll a,ta;
	cin>>a>>ta;
	ll b,tb;
	cin>>b>>tb;
	string s;
	cin>>s;
	ll min=(10*(s[0]-'0')+s[1]-'0')*60+10*(s[3]-'0')+s[4]-'0';
//	cout<<min<<" "<<min+ta<<endl;
	ll x=300;
	ll c=0;
	while(x<1440)
	{
		double w=(double)x;

		for(double i=w;i<=w+(double)tb;i+=0.5)
		{
			if(i>min&&i<min+ta)
			{
				//cout<<w<<endl;
				c++;
				break;
			}
		}
		x=x+b;
	}
	cout<<c;

}

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2e5 + 5;
const int oo = 1e9 + 5;

int intersect (int l, int r, int l2, int r2) {
	int lm = max(l, l2);
	int rm = min(r, r2);
	return (rm - lm + 1);
}

void solve() {
	int a, ta, b, tb;
	string s;
	cin >> a >> ta;
	cin >> b >> tb;
	cin >> s;
	int l = (s[0]-'0')*600+(s[1]-'0')*60 + (s[3]-'0')*10+(s[4]-'0');
	int r = l + ta;
	int ans = 0;
	for (int l2 = 300; l2 <= 1439; l2 += b) {
		int r2 = l2 + tb;
		if (intersect(l+1, r-1, l2+1, r2-1) >= 0) {
			++ans;
		}
	}
	cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a, ta, b, tb;
    int h,m, start, lim = 23*(60)+59 - 5*60, end;

    cin >> a >> ta;
    cin >> b >> tb;

    scanf("%d:%d",&h,&m);

    start = h*60+m - 5*60;
    end = min(start+(ta-1),lim);
    start = max(start-(tb-1),0);

    cout << end/b-start/b + (start%b==0) << '\n';
    //cout << start << " " << end << '\n';
    return 0;
}

#include <iostream>

using namespace std;

struct time
{
    int stat;
    int endt;
}Time[2000];

int main()
{
    int H,M;
    int i,a,ta,b,tb;
    int st,ed,sum;
    char op;
    cin>>a>>ta>>b>>tb>>H>>op>>M;
    st=H*60+M;
    ed=st+ta;
    Time[0].stat=5*60;
    Time[0].endt=Time[0].stat+tb;
    i=1;
    while(Time[i-1].stat+b<=24*60-1)
    {
        Time[i].stat=Time[i-1].stat+b;
        Time[i].endt=Time[i].stat+tb;
        i++;
    }
    i--;
    sum=0;
    for(;i>=0;i--)
    {
        if(st<Time[i].endt&&ed>Time[i].stat)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}

#include <cstdio>

int main(){
    int a, ta, b, tb;
    while(scanf("%d%d%d%d", &a, &ta, &b, &tb) > 0){

        char str[6];
        scanf("%s", str);

        int depa = ((str[0]-'0')*10 + str[1]-'0')*60 + (str[3]-'0')*10 + str[4]-'0';
        int depb = 5*60;

        while(depb < 24*60 and depb+tb <= depa){
            depb += b;
        }

        int z = 0;
        while(depb < 24*60 and depb < depa+ta){
            depb += b; z++;
        }

        printf("%d\n", z);
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f(a,b,c) for(int a=b;a<c;a++)
#define read(t) ll t; cin>>t;
#define readarr(arr,n) ll arr[n]; f(i,0,n) cin>>arr[i];
#define forstl(i,v) for(auto &i: v)
#define ln endl
#define dbg(x) cout<<#x<<" = "<<x<<ln;
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it<<ln;} cout<<ln;
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cout<<ln;
#define dbgarr(v,s,e) cout<<#v<<" = "; f(i,s,e) cout<<v[i]<<", "; cout<<ln;
#define addEdge(tr,k) f(i,0,k) { ll x,y; cin>>x>>y, tr[x].push_back(y), tr[y].push_back(x);}
#define findd(a,b)   a.find(b)!=a.end()

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }

//														GLOBAL VARS
ll INF =LLONG_MAX;
const ll M= 1000000007;

//														USEFUL FUNCTIONS
ll powm(ll , ll ) ;

// 														MAIN
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    //It gets easier day by day, but the hard part is to........
    read(a) read(ta)
    read(b) read(tb)
    string s;
    cin>>s;
    ll t=s[4]-'0';
    t+=10*(s[3]-'0');
    t+=60*(s[1]-'0');
    t+=600*(s[0]-'0');
    ll bus_see=0;
    ll tmp=t+ta;
    tmp=min(tmp,(ll)1440);
    tmp--;
    tmp-=300;
    // dbg(tmp)
    tmp/=b;
    // dbg(tmp)
    tmp++;
    // dbg(tmp)
    t-=tb;
    // dbg(t)
    if(t<300) t=0;
    // t=max(t,(ll)240);
    // dbg(t)
    t-=300;
    // dbg(t)

    t/=b;
    if(t<0) t=-1;
    // dbg(t)
    t++;
    t=max((ll)0,t);
    // dbg2(t,tmp)
    cout<<tmp-t<<endl;

}

//													FUNCTIONS DECLARATIONS
ll powm(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%M;
		a=(a*a)%M;
		b>>=1;
	}
	return res;
}

#include <bits/stdc++.h>

#define pb push_back
#define mk make_pair
#define ll long long
#define db double
#define ld long double
#define M_PI 3.1415926535897931

using namespace std;

void solve()
{
    ios::sync_with_stdio(0);
    int a,b,c,d,h,m;
    char x;
    cin >> a >> b >> c >> d;
    cin >> h >> x >> m;
    h = h * 60 + m - 300;
    int g = h;
    int s = h - d;
    int e = min(h + b,24 * 60 - 300);
    int ans = 0;
    for(int i = max(s + 1,0); i < e; i ++)
    {
        if(i % c == 0)
        {
                ans ++;
        }
    }
    cout << ans;
}

main()
{
    int t = 1;
    //cin >> t;
    while(t --)
    {
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,ta,b,tb;
    string S;
    cin >> a >> ta >> b >> tb;
    cin >> S;
    int h = stoi(S.substr(0,2)),m = stoi(S.substr(3,2));
    int mi = max(60*h+m-tb,50*6-1);
    int ma = min(60*h+m+ta,24*60)-1;
    cout << (ma-300)/b+1-(mi<300? 0:(mi-300)/b+1) << "\n";
}

#include <bits/stdc++.h>
#define maxn 2005

using namespace std;
typedef long long ll;

int main(){

//	freopen("in.txt", "r", stdin);
	int n1, m1, n2, m2;

	while(cin >> n1 >> m1 >> n2 >> m2){

		int a, b;

		scanf("%d:%d", &a, &b);
		int s = a * 60 + b - 300;
		int k1 = s - m2, k2 = s + m1;
		k2 = min(k2, 1139);
		k1 = max(k1, 0);
		int p = k2 / n2 - k1 / n2;
		if(k1 % n2 == 0)
		 p++;
		if(k2 == s + m1 && k2 % n2 == 0)
		 p--;
		if(k1 % n2 == 0 && k1 + m2 == s)
		 p--;
		cout << p << endl;
	}
	return 0;
}

#include<iostream>

using namespace std;

int main()
{
	int a,b,ta,tb,k=0;
	char Sim[6];
	cin>>a>>ta;
	cin>>b>>tb;
	cin>>Sim;
	int c=60*(10*(Sim[0]-'0')+(Sim[1]-'0'))+10*(Sim[3]-'0')+(Sim[4]-'0');
	for(int i=300; i<(c+ta); i+=b)
	{
		if(i>(c-tb) && i<=1439 )
			k++;
	}
	cout<<k<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

main ()
{
    int a, b, c, d, e, f, i, j = 0, ta, tb, sh = 5, sm = 0, th = 5, tm = 0;
    char ch;
    cin >> a >> ta;
    cin >> b >> tb;
    cin >> c >> ch >> d;
    sm += tb;
    while ((sh < c && sm <= d) || (sh <= c))
    {
         if ((sh >= c && sm > d) || (sh > c)) {
            break;
        }
        sm += b;
        while (sm >= 60) {
            sh++;
            sm -= 60;
        }
         if ((sh >= c && sm > d) || (sh > c)) {
            break;
        }
    }

    sm -= tb;
    while (sm < 0) {
        sh--;
        sm += 60;
    }

    d += ta;
    while (d >= 60) {
        c++;
        d -= 60;
    }

    while (sh < c || sm < d)
    {
        if (sh > c || sh >= 24) break;
        else if (sh == c && sm > d) break;
        sm += b;
        while (sm >=60) {
            sh++;
            sm -= 60;
        }
        j++;
    }
    if (j == 140) j++;
    cout << j;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <utility>
#include <memory.h>
#include <cassert>
#include <iterator>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
#include <ctime>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
//  freopen("input.txt","r",stdin);
//	 freopen("output.txt","w",stdout);
  int a, ta;
  int b, tb;
  scanf("%d%d%d%d", &a, &ta, &b, &tb);
  int h, m;
  scanf("%d:%d", &h, &m);
  m = m + h * 60;
  int start = 5 * 60;
  int le = m;
  int ri = m + ta;
  int cur = start;
  int ans = 0;
  for (int i = 0; i <= 1000000; i++) {
  	int l = cur;
  	int r = l + tb;
  	if (l < ri && r > le) ++ans;
  		else {
  			if (r > le && r <= ri) ans++;
  		}
  	cur += b;
  	if (cur > 23 * 60 + 59) break;
  }
  cout << ans << endl;
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;
#include<queue>
char a[200005];
int main()
{

    int a,ta,b,tb;
    int h;
    int m;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d:%d",&h,&m);
    int left=h*60+m-tb;
    int right=h*60+m+ta;

    // cout<<right<<" "<<left<<endl;
    int ans=300;
    int count=0;
    while(ans<=23*60+59)
    {
        if(ans>left&&ans<right)
        {
            count++;

        }
        ans+=b;
        if(ans>right)
            break;
    }
    cout<<count<<endl;

}

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    int a, ta, b, tb, hs, ms;
    scanf("%d %d", &a, &ta);
    scanf("%d %d", &b, &tb);
    scanf("%d:%d", &hs, &ms);

    int cincohoras = 60 * 5;
    int meianoite = 60 * 24;
    int inicioviagem = hs*60 + ms;
    int fimviagem = inicioviagem + ta;

    int part_bus, cheg_bus, cont=0;

    part_bus=cincohoras;
    cheg_bus=part_bus+tb;

    while(part_bus<meianoite){
        if(((inicioviagem>=part_bus && inicioviagem < cheg_bus) || (fimviagem<cheg_bus && fimviagem>part_bus))||(inicioviagem<=part_bus&&fimviagem>=cheg_bus)){
            cont++;
        }
        part_bus+=b;
        cheg_bus = part_bus+tb;
    }

    printf("%d\n", cont);

    return 0;
}

#include<bits/stdc++.h>

#define X  first
#define Y  second
typedef long long ll;

#define FOR(i,a,b) for(ll i = a;i<=b;i++)
#define FOD(i,a,b) for(ll i = a;i>=b;i--)
#define pb push_back
#define mp make_pair

using namespace std;

typedef pair<ll,ll>ii;
const ll maxN = 1e6+5;
const ll inf = 1e10;
const ll mod = 1e9+7;

ll a,ta;
ll b,tb;
string s;
int main()
{
    ios_base::sync_with_stdio(0);
	cin>>a>>ta;
	cin>>b>>tb;
	cin>>s;
	ll start = 5*60;
	ll finish = 24 * 60 - 1;
	ll tam = 60 *((s[0]-'0') * 10 + (s[1]-'0')) +((s[3]-'0') * 10 + (s[4]-'0'));

	ll xe = (min((tam + ta-1),finish)- start)/b;
	xe++;
//	cout<<xe;
	ll res = 0;
	while(1)
	{
		if(res * b + tb + start <= tam)res++;
		else break;
	}
	cout<<xe-res;
	return 0;
}

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
	int a,ta,b,tb;
	int starth,startm;

	cin>>a>>ta>>b>>tb;
	scanf("%d:%d",&starth,&startm);

    int n;
    if((starth-5)*60+startm+ta<19*60)
        n = ((starth-5)*60+startm+ta)/b+1;
    else
        n = 19*60/b+1;
	if(((starth-5)*60+startm+ta)%b==0)
	{
		n--;
	}

	int x;
	int arriveT = 0;
	int t = (starth-5)*60+startm;
	for(x=1;x<=n;x++)
	{
	    if(x==1)
            arriveT += tb;
		else
            arriveT+=b;
		if(arriveT > t)
		{
			break;
		}
	}

	int ret = n-x+1;
	cout<<ret<<endl;

    return 0;
}

#include <bits/stdc++.h>

#define lli long long int
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin freopen( "balancing.in", "r", stdin );
#define fout freopen( "balancing.out", "w", stdout );

using namespace std;

int a, ta, b, tb, c, d, ans;

int main ()
{
    cin >> a >> ta >> b >> tb;
    sc( "%d:%d", &c, &d );
    int sec = (c*60 + d) + ta;
    for ( int i = 5*60; i <= 23 * 60 + 59; i += b )
    {
        if( max ( sec - ta, i ) < min( sec, i + tb ) )
        {
            ans++;
        }
    }
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;

long long a,ta,b,tb,h,m,ans,i;

int main(){
	cin>>a>>ta>>b>>tb;
	scanf("%d:%d",&h,&m);
	for( i=0;i<max((long long)0,h*60+m-tb-299);i+=b){}
	while(i<h*60+m+ta-300&&i<1140){ans++;i+=b;}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>L;X--)
#define DEP2(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)

int main(){
	int a,ta,b,tb,h,m;
	cin>>a>>ta>>b>>tb;
	scanf("%d:%d",&h,&m);
	int l=h*60+m;
	for(int i=5*60;i<=23*60+59;i+=a){
		if(i>=l) {
			l=i;break;
		}
	}

	int r=l+ta,cnt=0;
//	cout<<l<<' '<<r<<endl;
	for(int i=5*60;i<=23*60+59;i+=b){
//		cout<<i<<' '<<i+tb<<endl;
		if(i+tb>l && i<r) cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a, ta, b, tb;

int main(){
    //freopen("input.txt", "r", stdin);
    vector<int> pos;
    scanf("%d%d%d%d", &a, &ta, &b, &tb);
    int hh, mm;
    scanf("%d:%d", &hh, &mm);
    int stmin = (hh - 5) * 60 + mm;
    int stval = ta * tb;
    int aspeed = stval / ta;
    int bspeed = stval / tb;
    //cout << aspeed << " " << bspeed << "\n";
    for(int i = 0; i <= stmin; i++){
        for(auto& it: pos ){
            it -= bspeed;
        }
        if(i % b == 0 && i < 1140){
            pos.push_back(stval);
        }

    }
//    for(auto it: pos){
//        printf("%d\n", it);
//    }
    int cnt = 0;
    int x = 0;
    for(int i = stmin + 1; i <= (stmin + ta) ; i++){
//        printf("=>%d, %d\n", i, cnt);
//        for(auto it: pos){
//            if(it >0) printf("%d\n", it);
//        }
        for(auto& it: pos){
            if((x < it && (it - bspeed) < (x + aspeed)) || (x != 0 && it != stval && x == it)){
                cnt += 1;
                //printf("%d\n", i - 1106);
            }
            it -= bspeed;
        }
        x += aspeed;
        if(i % b == 0 && i < 1140){
            //printf("%d\n", i);
            pos.push_back(stval);
        }

    }
    printf("%d\n", cnt);
}

/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

void solve()
{
    int a,ta,b,tb;
    cin >> a >> ta >> b >> tb;
    int hh,mm;
    cin >> hh ;
    char c;
    cin >> c ;
    cin >> mm ;
    int curtim = hh*60 + mm;
    int ans = 0;
    for(int i = max(300ll,curtim - tb + 1) ; i < min(24*60ll ,curtim + ta) ; ++i){
        if( (i-300)%b == 0)  ans++;
    }
    cout << ans;
}

int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define fi first
#define sc second
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define pb push_back
#define mp make_pair
#define ll long long
#define dl double
#define ison(a,b) (a&(1<<b))
#define bitcnt __builtin_popcount
#define MOD 1000000007
#define INF 1000000000

typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> wadj;

int main(int argc, char const *argv[])
{
//freopen("inp.txt","r",stdin);
 int fa,ta;
 cin>>fa>>ta;
 int fb,tb;
 cin>>fb>>tb;
 int h,m;
 scanf("%d:%d",&h,&m);
 int st = h*60+m;
 int ed = st+ta;
 int cnt=0;
 for(int i=5*60;i<24*60;i+=fb)
 {
  int ds=i+tb;
  if(ds>st&&i<ed)
    cnt++;
 }
 cout<<cnt;

    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int a, ta, b, tb;

  cin >> a >> ta >> b >> tb;

  int h, m; char t;

  cin >> h >> t >> m;

  int bega = h * 60 + m;
  int enda = bega + ta;

  int ans = 0;

  for(int ct = 5 * 60; ct < 24 * 60; ct += b) {
    int ct2 = ct + tb;
    if(max(bega, ct) < min(enda, ct2)) ans++;
  }

  cout << ans;

  return 0;
}
/*

*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
  int a,ta;
  int b,tb;
  cin>>a>>ta>>b>>tb;
  char ch;
  int hh,mm;
  cin>>hh;
  cin.get(ch);
  cin>>mm;
  int start=300;
  int simon=hh*60+mm;
  int cnt=0;
  for(int i=300;i<simon+ta;i+=b)
    if(((i<=simon&&i+tb>simon)||i>=simon)&&(i<=23*60+59)) cnt++;
    cout<<cnt<<endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int sbit(int x) {
	int sum = 0;
	while (x) {
		if (x & 1)sum++;
		x >>= 1;
	}
	return sum;
}
void printNumber(int n, int len) {
	if (!len)return;
	printNumber(n >> 1, len - 1);
	cout << (n & 1);
}
bool getBit(int x, int idx) { return x & (x >> idx - 1); }

int setBit1(int x, int idx) {
	return x | (1 << idx);
}
int countNumBits2(int mask) {// O(bits Count)
	int ret = 0;
	while (mask) {
		mask&=(mask)-1;
		ret++;
	}
	return ret;
}
void printAllSubsets(int len) {
	for (int i = 0; i < (1 << len); i++) {
		printNumber(i,len);
		cout << endl;
	}
}
using namespace std;
int main()
{
	file();
	fast();

	int a, ta, b, tb, sa, sb;
	char c;
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%d%c%d", &sa, &c, &sb);
	int start = sa * 60 + sb;
	int end = start + ta, show = 0;
	for (int i = 300; i < min(end, 1440); i += b) {
		if (i<start){
			if (i+tb>start)show++;
		}
		else if (i>=start){
			show++;
		}
	}
	printf("%d\n", show);

}

#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 111111
#define M 1000000
#define ll long long
using namespace std;
struct node
{
    int l,r;
} zz[1000];
int main()
{
    int a,ta,b,tb,hh,mm;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d:%d",&hh,&mm);
    int num=0;
    int st=5*60;
    int ed=23*60+59;

    while(st<=ed)
    {
        zz[num].l=st;
        zz[num].r=zz[num].l+tb;
        st+=b;
        num++;
    }
    int a_st=hh*60+mm;
    int a_ed=a_st+ta;
    int ans=0;
    for(int i=0; i<num; i++)
    {
        if(a_st<zz[i].r&&zz[i].l<a_ed)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int a,b,ta,tb;
    cin>>a>>ta>>b>>tb;
    int h,m;
    char ch;
    cin>>h>>ch>>m;
    int sum;
    int count,ans=0;
    sum=h*60+m;
    count=sum+ta;
    for(int i=5*60;i<=23*60+59;i+=b)
    {
        if(i<count&&i+tb>sum)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
#define MOD 1000000007
#define MAX 1000010

int N,K,Q;
int freq[MAX];

typedef long long int ll;
int main()
{

// freopen("data.in.txt","r",stdin);
    int a,t1,b,t2,h,m;
    char op;
    cin>>a>>t1;
    cin>>b>>t2;
    cin>>h>>op>>m;
    int lstart =h*60+m;
    int cnt1=300,cnt2=24*60-1,cnt=0;

    while(cnt1<=cnt2)
    {
        if(cnt1+t2>lstart&&cnt1<lstart+t1) cnt++;
        cnt1+=b;
    }
    cout<<cnt<<endl;

    return 0;
}

#include<stdio.h>
using namespace std;

int main()
{
    int a,ta,b,tb;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    int h,m;
    scanf("%d:%d",&h,&m);
    m+=h*60;
    m-=300;
    int l=m-tb+1;
    int r=m+ta-1;
    if(l<0) l=0;
    if(r>1139) r=1139;
    int rez=r/b-(l-1)/b;
    if(l==0 && b>1) rez++;
    printf("%d\n",rez);
    return 0;
}

#include<bits/stdc++.h>
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
#define all(x) x.begin(),x.end()
#define szz(s) ll(s.size())
typedef long long ll;
#define endl '\n'
using namespace std;

void file(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);// freopen("out.txt", "w", stdout);
#endif
}

int main(){
    file();

    int a , ta , b , tb , m , h ,ans = 0 , m1 , m2 ,m3 , x , y , xx , yy ,c=0 ;
    char cc ;
    cin >> a >> ta >> b >> tb >> h >> cc >> m ;

    x = h*60+m;
    y = x+ta;
    vector < int > st;

    for(int i = 5*60 ; i < 24*60;i+=b)
        for(int k = i ; k <= i+tb ; k++)
            if(k>=x&&k<=y&&i!=y&&i+tb!=x){c++;break;}
    cout << c << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi(v)   vector <int> v
#define loop(n)	for(int i=0;i<n;i++)
bool is_prime(int n)
{
    if(n==2)
        return true;
    if(n%2==0||n<2)
        return false;
    for(int i=3; i<=sqrt(n); i+=2)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll comb(ll a,ll b)
{
    ll res=1;
    if(a==0||b==0)
        return 1;
    int cnt[31]= {},x=a-b;
    for(int j=2; j<=a; j++)
    {
        int h=j;
        for(int i=2; i<=h; i++)
        {
            while(h%i==0)
            {
                h/=i;
                cnt[i]++;
            }
        }
    }
    for(int j=2; j<=b; j++)
    {
        int h=j;
        for(int i=2; i<=h; i++)
        {
            while(h%i==0)
            {
                h/=i;
                cnt[i]--;
            }
        }
    }
    for(int j=2; j<=x; j++)
    {
        int h=j;
        for(int i=2; i<=h; i++)
        {
            while(h%i==0)
            {
                h/=i;
                cnt[i]--;
            }
        }
    }
    for(int i=1; i<=30; i++)
    {
        if(cnt[i]>0)
        {
            while(cnt[i]>0)
            {
                cnt[i]--;
                res*=i;
            }
        }
    }
    return res;
}
//freopen("input.txt" ,"r",stdin );
//freopen("output.txt","w",stdout);

int main()
{
    int cnt[200000]={},res=0;
    int a,ta,b,tb,h,m;
    char c;
    cin>>a>>ta>>b>>tb>>h>>c>>m;
    int x=300*60;

    for(int i=h*60*60+m*60+1;i<h*60*60+m*60+ta*60;i++)
    {
        cnt[i%(1440*60)]++;
    }
    while(x<=1439*60)
    {
        int z=0;
        for(int i=x;i<=x+tb*60;i++)
        {
            if(cnt[i%(1440*60)]>0)
                z=1;

        }
        if(z==1)
            res++;
        x+=b*60;
    }
    cout<<res;
}

#include <iostream>
#include<cstdio>
using namespace std;
struct time{
    int hour;
    int minute;
    time(int a=0,int b=0):hour(a),minute(b){}
    int operator -(const time &b){
        return (hour-b.hour)*60+(minute-b.minute);
    }
    int gettime(){
        return hour*60+minute;
    }

};
int main()
{
    int ta,la;
    int tb,lb;
    int ans;
    time start;
    while(cin>>ta>>la>>tb>>lb){
    scanf("%d:%d",&start.hour,&start.minute);
    int starttime,laststarttime;
    starttime=start.gettime()-time(5,0).gettime()-min(start-time(5,0),lb);
    laststarttime=start.gettime()-time(5,0).gettime()+min(time(23,59)-start,la);
    ans=(laststarttime)/tb-(starttime)/tb;
    if((laststarttime)%tb==0&&laststarttime!=1139)ans--;
    if(starttime==0&&start-time(5,0)!=lb)ans++;
    //if((starttime-time(5,0).gettime())%tb==0)ans++;

      cout<<ans<<endl;
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#define N 100005
#define lson l,m,rt*2
#define rson m+1,r,rt*2+1
using namespace std;
int main()
{
    int a,tb,b,ta,n,t,ans=0,k,h,m;
    char d[100];
    cin>>a>>ta;
    cin>>b>>tb;
    scanf("%d:%d",&h,&m);
    h=h*60+m;
    k=5*60;
    for(int i=k;i<24*60;i+=b)
    {
        if(i+tb<=h||i>=h+ta)
        {
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,ta,b,tb;
    int h,m;
    char ch;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d%c%d",&h,&ch,&m);
    int k=(h-5)*60+m;
    int s=k-tb,e=k+ta;
//    cout<<k<<' '<<s<<endl;
    if(e>1140)
        e=1140;
    int i=1;
    int n,ans=0;
    if(s>=0)
    {
        while(1)
        {
            n=i*b;
            if(n==s)
                break;
            else if(n>s)
            {
                if(n<=e)
                    ans++;
                break;
            }
            i++;
        }
    }
    else
    {
        n=0;
        if(n!=k)
            ans++;
    }
//    cout<<i<<endl;
//    cout<<s<<' '<<n<<' '<<e<<endl;
    ans+=(e-n)/b;
    while(1)
    {
        n=i*b;
        if(n==e)
        {
            ans--;
            break;
        }
        else if(n>e)
            break;
        i++;
    }
    printf("%d\n",ans);
    return 0;
}

//Template

// By Gaurav :)
//Includes
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility> //Pair
#include <algorithm>
#include <sstream> // istringstream>> ostring stream<<
#include <iostream>
#include <iomanip>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
using namespace std;

//M lazy ;)
typedef long long ll;
typedef vector <int> vi;
typedef pair< int ,int > pii;
typedef istringstream iss;
typedef ostringstream oss;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define ln length()
#define rep(i,n) for(int i=0;i<n;i++)
#define fu(i,a,n) for(int i=a;i<=n;i++)
#define fd(i,n,a) for(int i=n;i>=a;i--)
#define all(a)  a.begin(),a.end()
#define ESP (1e-9)

#define gi(n) scanf("%d",&n)
#define gl(n) cin >> n
#define pi(n) printf("%d",n)
#define pl(n) cout << n
#define ps printf(" ")
#define pn printf("\n")
#define dg(n,s); printf("%s %d",s,n)
#define imax numeric_limits<int>::max()
#define imin numeric_limits<int>::min()
#define lmax numeric_limits<ll>::max()
#define lmin numeric_limits<ll>::min()

#define mod 1000000007
#define NK 1100000

int a,t1,b,t2;
string s;
int main(){
	cin>>a>>t1>>b>>t2;
    cin>>s;
    int x = (s[0] - '0')*10 + s[1] - '0' ;
    int y = (s[3] - '0')*10 + s[4] - '0';
    int total = min(24*60 , (x-5)*60 + y );
    /*int ans = 0;
    for(int i = 5*60 ; i < 24*60 ; i += b){
    	if(i + t2 > total &&  total + t1 > i )   ans++;
	}
	cout<<ans<<endl;  */
  //  cout<<tot<<endl;
	int t = min(19*60 - 1 ,(total + t1 - 1))/b + 1;
	int t3;
	if(total <  t2 )       t3 = 0 ;
	else                   t3 =  (total - t2 )/b + 1;
	cout<<(t - t3);
	return 0;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

int a, ta;
int b, tb;
int t;

bool read () {
	if (scanf("%d%d", &a, &ta) != 2)
		return false;
	scanf("%d%d", &b, &tb);
	static char buf[10];
	scanf("%s", buf);
	string s = buf;
	t = atoi(s.substr(0, 2).c_str()) * 60 + atoi(s.substr(3, 2).c_str());
	return true;
}

void solve() {
	int A = t;
	int B = t + ta;
	int ans = 0;
	forn(i, 2000){
		int C = i * b + 300;
		if (C >= 24 * 60) break;
		int D = i * b + tb + 300;
		int l = max(A, C);
		int r = min(B, D);
		ans += l < r;
	}
	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();
#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {
#else
	if(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<list>
#include<vector>
#include<cstring>
#include<queue>
#define mod 1000000007
#define ll long long
using namespace std;

int main()
{

    string str;
	int a,ta,b,tb,x,y,z,w,s1,s2,t1,t2;
	cin>>a>>ta;
	cin>>b>>tb;

	cin>>str;

	x=str[0]-'0';
	y=str[1]-'0';

	z=str[3]-'0';
	w=str[4]-'0';

	t1=10*x+y;
	t2=10*z+w;

	s1=t1-5;

	s1=s1*60;
	s1=s1+t2;

//	cout<<"s1="<<s1<<"\n";

	int var=s1-tb;
	int counti=0;

	if(var>=0)
	{
	 counti=1;
	counti+=var/b;
   }
	else
	counti=0;

//	cout<<"var="<<var<<"\n";
	s1=s1+ta;

   // cout<<"s1="<<s1<<"\n";

	//cout<<"s1="<<s1;

	s1=min(1140,s1);
	t1=(s1-1)/b;

	t1=t1+1;

	//cout<<"t1="<<t1<<"\n";

	/*if(s1!=0)
	{
		if(s1%tb==0)
		t1=t1-1;
	}*/

	t1=t1-counti;
	cout<<t1;

	return 0;
}

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int a,tA,b,tB,h,m,starting,ending,totalBus=0;

    cin>>a>>tA>>b>>tB;
    scanf("%d:%d",&h,&m);

    starting=(h-5)*60+m;
    ending=starting+tA;

    for(int i=0;i<=1139;i=i+b)
    {

        if(i+tB>starting && i<ending)
        {
            totalBus++;
        }
        if(i>ending)
            break;
    }
    cout<<totalBus;

    return 0;
}

// Not sure :'(

#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, ta;
  int b, tb;
  cin >> a >> ta >> b >> tb;
  string s;
  cin >> s;
  int hh = (s[0] - '0') * 10 + (s[1] - '0');
  int mm = (s[3] - '0') * 10 + (s[4] - '0');
  mm = 60 * hh + mm;
  int from = mm;
  int to = from + ta;
  int ans = 0;
  for (int x = 5 * 60; x < 24 * 60; x += b) {
    int y = x + tb;
    int xx = max (from, x);
    int yy = min (to, y);
    if (xx < yy) ans++;
  }
  cout << ans << '\n';
  return (0);
}

#include <bits/stdc++.h>

using namespace std;
int flag = 0;
int main()
{
    int a,ta,b,tb; scanf("%d%d%d%d",&a,&ta,&b,&tb);
    int h,m; scanf("%d:%d",&h,&m);
    m = h*60+m,h = 0 , h = m + ta;
    for(int i = 300; i < 1440;i+=b)
        if(i < h&& i+tb > m)
        flag++;
    return!printf("%d",flag);
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
int main()
{
    ARB
    char c;
    int a,ta,b,tb,h,m,t,ans=0;
	cin>>a>>ta;
	cin>>b>>tb;
	cin>>h>>c>>m;
	t=60*h+m;
	for(int i=5*60;i<24*60;i+=b)
	{
		if(i > t-tb && i<t+ta)
            ans++;
	}
	cout<<ans;
}

#include <iostream>
using namespace std;
long long int a,ta,b,ba,Va[50000],Vb[500000],nr,tb,h,ha,j,pd,pl;
string ora;
int main()
{
   cin>>a>>ta>>b>>tb>>ora;
   h=(ora[0]-'0')*1000+(ora[1]-'0')*100+(ora[3]-'0')*10+(ora[4]-'0');
  // cout<<h;
   h-=500;
   pd=tb/b;
   pl=ta/b;
   if (h%b==0) pd--;
   if (h+ta%b==0) pl--;
   cout<<pd+pl;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int a, ta, b, tb;

  cin >> a >> ta >> b >> tb;

  int h, m; char t;

  cin >> h >> t >> m;

  int endt = min(23 * 60 + 59, h * 60 + m + ta);

  int begt = max(5 * 60, h * 60 + m - tb);

  int tott = endt - begt;

  cout << tott / b;

  return 0;
}
/*

*/

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
   int a,ta,b,tb,hh,mm;
   cin>>a>>ta>>b>>tb;
   scanf("%d:%d",&hh,&mm);
   int tem=(hh-5)*60+mm;
   int ans=0;
   if(tem%a!=0)
   {
       tem=(tem/a)*a+a;
   }
   int l=tem-tb,r=tem+ta;
   if((tem-tb)<=0)l=0;
   if(tem+ta>(18*60+59))r=18*60+59;
   ans+=(r-l)/b;
   if((tem-tb)%b==0) ans--;
   cout<<ans<<endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int a, ta, b, tb,w,q=0,u, g=0;
	long long s, ms;
	float l;
	cin >> a >> ta >> b >> tb;
	string x, r = "", e = "";
		cin >> x;
	for (int j = 0; j<x.size(); j++)
	{
		if (x[j] == ':')
		{
			r = e;
			e = "";
		}
		else
			e += x[j];
	}
	s = stol(r) * 60 + stol(e);
	q = 300;
	while (s >= q)
	{
if(s==q)
g=1;
		q += b;
	}
	q -= b;
	u = ta+(s-q) ;
	if (q + ta > 1439)
		u -= b;
	if (u%b == 0 ||g==1)
		cout << u / b;
	else
		cout << u / b + 1;
	return 0;
}

#include <iostream>
typedef long long ll;
#include <utility>

using namespace std;
int a,ta,b,tb;

pair <int,int> tt;
int time;

int main(){
//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	cin>>a>>ta>>b>>tb;
	scanf("%d:%d", &tt.first, &tt.second);
	time = (tt.first - 5) * 60 + tt.second;

	int timeFirst = max(time - tb, 0);
	int timeLast = min(time + ta - 1, 1139);

	cout<<(timeLast - timeFirst)/b;
	return 0;
}

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

inline void file()
{
    freopen("D:\\go.txt", "r", stdin);
    freopen("D:\\leave.txt", "w", stdout);
}

int main()
{
   // file();
    int a, ta;
    int b, tb;
    int h, m;
    scanf("%d%d", &a, &ta);
    scanf("%d%d", &b, &tb);
    scanf("%d:%d", &h, &m);
    int leave_time_b = 300;
    int leave_time_a = h * 60 + m;
    int arrive_time_a = leave_time_a + ta;
    int res = 0;
    for (int i = leave_time_b; ;i += b)
    {
        if ((i != arrive_time_a && i != leave_time_a) && (i + tb < arrive_time_a && i + tb > leave_time_a) || i > leave_time_a)
        {
            //cout << "i = " << i << endl;
            res++;
        }
        if (i >= arrive_time_a)
            break;
    }
    printf("%d\n", res);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sn scanf
#define pt printf
#define wl while
#define fi(a,b,c) for(int(a)=(b);(a)<=(c);(a)++)
int a,ta,b,tb,m,j;
int mu,ak,te;
char c;
int main(){
 sn("%d%d",&a,&ta);
 sn("%d%d",&b,&tb);
 sn("%d%c%d",&j,&c,&m);
 //pt("%d %d m ",j,m);
 m+=(j*60);
 //pt("%d m ",m);
 mu=300;
 ak=(23*60)+59;
 //pt("%d ak ",ak);
 wl(mu<=(m-tb))mu+=b;
 //pt("%d mu ",mu);
 te=mu;
 wl((te<=(m+ta))&&((te+b)<=ak))te+=b;
 if(te>=(m+ta))te-=b;
 te=te-mu;
 pt("%d\n",(te/b));
}

#include <iostream>
#include <string>

using namespace std;

int main() {
	int a, ta, b, tb, h, m;
	cin >> a >> ta >> b >> tb;
	string l;
	cin >> l;
	h = (l[0] - 48) * 10 + (l[1] - 48);
	m = (l[3] - 48) * 10 + (l[4] - 48) + h * 60;
	int start, end = m + ta - 300;
	if (end > 23 * 60 + 59 - 300)
		end = 23 * 60 + 59 - 300;
	if (end % b == 0)
		end -= b;
	else
		end -= end % b;
	start = m - tb - 300;
	if (start < 0)
		start = 0;
	else
		start += b - (start % b);
	if (end - start > 0)
		cout << (end - start) / b + 1;
	else
		cout << 0;

	return 0;
}

//  https://codeforces.com/contest/665/problem/A
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main(){
    int a,ta,b,tb;
    string time;

    cin >> a>> ta>> b >> tb >> time;
    int hour = stoi(time.substr(0, 2));
    int mins = stoi(time.substr(3, 2));
    int start_time = hour*60 +mins;
    int end_time = start_time+ta;
    vector<pair<int,int>> b_buses;
    int answer=0;
    for(int i = 300 ; i < 1440 ; i++){
        if(i%b==0){
            b_buses.push_back(make_pair(i,i+tb));
        }

    }

    for(int i = 0 ; i<b_buses.size();i++){
        if (
            b_buses[i].first >= start_time && b_buses[i].first < end_time
            ||
            b_buses[i].second > start_time && b_buses[i].second < end_time
        ){
            answer++;
            // cout << start_time << " " << end_time << " " << b_buses[i].first << " " << b_buses[i].second << endl;

        }

    }

    cout << answer;
}

#include<bits/stdc++.h>

using namespace std;
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define ff first.first
#define fs first.second
typedef long long ll;
typedef unsigned long long ull;

const ll mod = 1e16+371;
//const ll mod = 1e12+193;

const double PI = acos(-1);
const ll INF = 1e18;
const ll MAX=1e5+10, N=1e6;
//const int lim=1<<18;
//const ll mod = 100000000 ;

bool intersect(int a,int b,int c,int d){
	return (a>=c&&a<=d) || (b>=c&&b<=d);
}
int main(){
	ios_base::sync_with_stdio(0);
//	cin.tie(0);
//	srand(time(0));

	int a,ta,b,tb;
	while(cin>>a>>ta>>b>>tb){
		int hr; cin>>hr;
		char c; cin>>c;
		int mi; cin>>mi;
		int strt=hr*60+mi;
		int lst=strt+ta;
		int x=300;
		int ans=0;
		for(int i=0;i<24*60*2;x+=b,i++){
			if(strt>=x+tb || lst<=x)
				continue;
			ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int a, ta, b, tb, h, m, tmp, help, ans;

	scanf("%d%d", &a, &ta);
	scanf("%d%d", &b, &tb);
	scanf("%d:%d", &h, &m);

	tmp = h * 60 + m;
	help = tmp + ta;
	tmp -= tb;
	tmp++;
	ans = 0;

	while((tmp % b != 0) || (tmp < 300))
		tmp++;

	for(int i = tmp; i < help; i += b)
	{
		ans++;
	}

	printf("%d\n", ans);
}

#include "bits\stdc++.h"
using namespace std;

int main() {
	int i, j;
	int a, b, ta, tb, t0;
	char doph1, doph2, dopm1, dopm2, dop;
	int ans, x;

	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%c", &dop);
	scanf("%c%c%c%c%c", &doph1, &doph2, &dop, &dopm1, &dopm2);
	t0 = ((doph1 - '0') * 10 + (doph2 - '0')) * 60 + ((dopm1 - '0') * 10 + (dopm2 - '0')) - 5 * 60;

	x = t0 % b;
	ans = (ta - (b - x)) / b + 1;

	if (t0 > b)
	{
		if (t0 > tb) t0 = tb;
		ans += (t0 - x) / b;
	}

	printf("%d", ans);
	return 0;
}

#include <iostream>
using namespace std;
const int S=5*60;
const int T=24*60-1;
int main()
{
	//freopen("in.txt","r",stdin);
	int a,b,ta,tb,i,h,m,t,to;
	while(cin>>a>>ta>>b>>tb)
	{
		int ans = 0;
		scanf("%d:%d",&h,&m);
	//	t = h*60+m;
		cout<<t<<endl;
	//	to = t+ta;
		cout<<T<<endl;
		if(t>T)
			to=T;
		for( i = S ; i < to ; i+=b)
		{
			if((i+tb>t)||(i>t))
			{
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

/*
ID: marik_k1
PROG:
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");

#define forn(i,n) for(int i = 0; i < n; ++i)
#define mp make_pair
#define pb push_back
#define all(t) t.begin(),t.end()
#define gcd(x,y) __gcd(x,y)

typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N = 200000;
const LL INF = (LL)10e15;
const double eps = 1e-6;
const long long MOD = 1000000007;
const double PI = M_PI;
int h,m,a,ta,b,tb;
int ans;

int main(){
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

     cin >> a >> ta >> b >> tb;
    scanf("%d:%d",&h,&m);

   int l1 = h * 60 + m;
	int r1 = l1 + ta;

//	int ans = 0;
	for (int l2 = 5 * 60 + 0; l2 < 24 * 60; l2 += b) {
		int r2 = l2 + tb;
		int L = max(l1, l2), R = min(r1, r2);
		if (L < R)
			ans++;
	}
	cout << ans;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int a,ta,b,tb,h,m,timeTO,numTO,ans;
    int arr[6];
    string str;
    cin>>a>>ta>>b>>tb;
    cin>>str;
    arr[0]=str[0]-'0';
    arr[1]=str[1]-'0';
   // cout<<arr[0]<<" "<<arr[1]<<endl;
    h=arr[0]*10+arr[1];

    arr[2]=str[3]-'0';
    arr[3]=str[4]-'0';
   // cout<<arr[2]<<" "<<arr[3]<<endl;
    m=arr[2]*10+arr[3];
    //cout<<h<<m;

    timeTO=(h-5)*60+m+ta;
    numTO=(timeTO/b)+1;

    //cout<<numTO<<endl;

    ans=((numTO*b)/a)-1;

    cout<<ans;

}

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main ()
{
	int p1,g1;
	int p2,g2;
	int hour,minute;
	int sum1,sum2,sum3=300;
	int num=0;
	char ch;
	cin>>p1>>g1;
	cin>>p2>>g2;
	cin>>hour>>ch>>minute;
	sum1=hour*60+minute;
	sum2=sum1+g1;
	while(sum3<sum2)
	{
		if(sum3+g2>=sum1)
		{
			num++;
		}
		sum3+=p2;
	}
	cout<<num<<endl;
	return 0;

}

#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0);
	cout.tie(0);
	int Af, At, bf, bt, hd, md;
	scanf("%d %d\n%d %d\n%d:%d", &Af, &At, &bf, &bt, &hd, &md);
	md += hd * 60;
	int done = md + At;
	int meet = (md - 300)/bf + 1;
	meet -= floor((md - 300 - bt)/bf) + 1;
	//int meet = floor(bt/bf);
	while(++md < done){
        //cout << md - 300 << ' ' << meet << ' ';
        if(md < 1440 && (md - 300)%bf == 0) meet++;
        //cout << meet << endl;
	}
	cout << meet << '\n';
}

#if 1
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <fstream>
#include <chrono>
using namespace std;
using namespace std::chrono;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ull> vull;
typedef vector<vull> vvull;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

#define fs first
#define sc second
#define pb push_back
// forward strict for, most common
#define fors(i, a, n) for (int i = (int) (a); i < (int) (n); ++i)
// forward inclusive for
#define fori(i, a, n) for (int i = (int) (a); i <= (int) (n); ++i)
// backward for, inclusive
#define forb(i, n, a) for (int i = (int) (n); i >= (a); --i)

template <typename T>
void print(string name, vector<T>& v) {
    if (name.size()) cout << name << ": ";
    int s = (int) v.size();
    fors(i, 0, s) cout << v[i] << " ";
    cout << endl;
}
template<typename T> void print(vector<T>& v) { print("", v); }
#endif

int main() {
#ifdef LOCAL_CODE
    stringstream ss(R"(
10 30
10 35
05:20

60 120
24 100
13:00
)");
    cin.rdbuf(ss.rdbuf());
    int test_cases = 2;
#else
    int test_cases = 1;
    ios::sync_with_stdio(false); // faster cin/cout, do not mix with scanf, printf!!!
#endif

    fors(test_case, 0, test_cases) {
//    	cout << "test case " << test_case << endl;

        int a, ta, b, tb;
        string shm;
        cin >> a >> ta >> b >> tb >> shm;
        int h, m;
        h = (shm[0] - '0') * 10 + shm[1] - '0';
        m = (shm[3] - '0') * 10 + shm[4] - '0';

        int res = 0;

        int hm = h * 60 + m;
        int hm2 = hm + ta;
//        cout << "Start and end " << hm << " " << hm2 << endl;
        fors(i, 0, 24 * 60 / b + 1) {
        	int hmb = 5 * 60 + i * b;
        	int hmb2 = hmb + tb;

        	if (hmb2 <= hm || hm2 <= hmb) continue;
        	else res++;
        	if (hmb > 24 * 60) break;
        }

        cout << res << endl;
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,ta;
    int b,tb;
    int h,m;
    char input[10],trans[10];
    scanf("%d%d",&a,&ta);
    scanf("%d%d",&b,&tb);
    scanf("%s",input);
    strncpy(trans,input,2);
    trans[2]=='0';
    h=atoi(trans);
    strncpy(trans,input+3,2);
    trans[2]=='0';
    m=atoi(trans);
    int totalMin = 5*60+ 0;
    int dep = 23*60+59;
    int goTime[2000],depTime[2000];
    for(int i=0;i<2000;i++){
        goTime[i]=totalMin;
        depTime[i]=totalMin+tb;
        if(depTime[i]>dep){
            goTime[i]=-1;
            depTime[i]=-1;
            break;
        }
        totalMin+=b;
    }
    totalMin=h*60+m;
    dep = totalMin+ta;
    int sum=0;
    for(int i=0;i<2000;i++){
        if(goTime[i]==-1)break;
        if(goTime[i]==totalMin) sum++;
        else if(goTime[i]<totalMin && depTime[i]>totalMin)sum++;
        else if(goTime[i]>totalMin && goTime[i] < dep) sum++;
    }
    cout << sum << endl;

}

//http://codeforces.com/contest/665/problem/A

#include <stdio.h>
#include <math.h>
int up,d;

void set_up(int min, int need1, int diff2)
{
min=min-300;
up=min+need1;
if(up % diff2 == 0) up=up-diff2;
else up=up-(up % diff2);

if(up>1139) { up=1139/diff2; up=up*diff2; }
}

void set_do(int min, int need2, int diff2)
{
min=min-300;
d=min-need2;
if(d % diff2 == 0) d=d+diff2;
else d=d+diff2 - (d % diff2);

if(d<0) d=0;
}

int main()
{
//freopen("input.txt","r",stdin);

int m,diff1,diff2,need1,need2,strt_h,strt_m;
scanf("%d %d",&diff1,&need1);
scanf("%d %d",&diff2,&need2);
scanf("%d:%d",&strt_h,&strt_m);

m=strt_h * 60 + strt_m;

set_up(m,need1,diff2);
set_do(m,need2,diff2);

int ans;
//printf("%d %d %d\n",m,d,up);

if(up % diff2 == 0) ans=1;
ans=ans+(up/diff2)-(d/diff2);
printf("%d\n",ans);

return 0;
}

/*
	Nikhil Daliya
	nik1234
	IIIT Hyderabad
*/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define sz size()
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define SET(a,b) memset(a,b,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define SL(n) scanf("%lld",&n)
#define PL(n) printf("%lld",n)
#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d",n);
#define _ ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
typedef long long int LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<VL> VVL;
typedef pair<LL,LL> PLL;
typedef pair<int ,int> II;
typedef vector<II> VII;
void FastIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main()
{
	LL a,b,ta,tb,i;
	cin >> a >> ta;
	cin >> b >> tb;
	string s;
	cin >> s;
	string z= "";
	for(i=0;i<s.length();i++){
		if(s[i] == ':')
			break;
		z+=s[i];
	}
	long hr = atol(z.c_str());
	z= "";
	//cout << hr << endl;
	for(i=i+1;i<s.length();i++)
		z+=s[i];
	long mi = atol(z.c_str());
	LL net = (hr-5)*60 + mi;
	mi = net + ta;
	hr = max(0ll,net - tb+1ll);
	LL maxi = 11*60 + 59;
	LL fin = min((LL)mi - 1 , maxi );
	//cout << hr << " " << fin << endl;
	cout << (fin - hr)/b + (hr%b==0?1:0) << endl;
 	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
typedef long double ld;
typedef long double uld;
typedef short sh;
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
}
int main() {
	//cout << setprecision(9) << fixed;
	Fast
	srand(time(NULL));
	file();
	int a,ta,b,tb,th,tm,bus=0;char ch;cin>>a>>ta>>b>>tb>>th>>ch>>tm;
    int ia=(th*60)+tm,fa=(th*60)+tm+ta;
    for(int i=300;i<=1439;i+=b){
        int f=i+tb;
        if(((i>=ia)&&(i<fa))||((f>ia)&&(f<fa))||((ia>i)&&(fa<f)))bus++;
    }
    cout<<bus;
}

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define NN
#define esp 1e-7
#define inf 1e9
#define LL long long
#define rep(i,s,t) for (int i=s;i<=t;i++)
#define red(i,t,s) for (int i=t;i>=s;i--)
#define vtson(k,x) for (int k=o[x];k;k=nex[k])
using namespace std;
inline int read()
{
    int t=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9')f=(ch=='-')?-1:f,ch=getchar();
    while(ch>='0'&&ch<='9')t=t*10+ch-'0',ch=getchar();
    return t*f;
}

/*
int cc=0,to[NN<<1],nex[NN<<1],o[NN];
inline void add(int x,int y)
{
    to[++cc]=y,nex[cc]=o[x],o[x]=cc;
    to[++cc]=x,nex[cc]=o[y],o[y]=cc;
}
*/
int main()
{
  //  freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
    int a=read(),ta=read(),b=read(),tb=read(),h=read(),min=read();
    h-=5;
    int now=h*60+min;
    int num1=(now+ta-1+b)/b,num2=max(0,(now-tb+b))/b;
    int ans=num1-num2;
    printf("%d\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define DB(x)cout<<#x<<"="<<x<<endl;
typedef long long ll;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);

	int ta, tb, va, vb, answer = 0;

	scanf("%d %d", &ta, &va);
	scanf("%d %d", &tb, &vb);

	int sh, sm;
	scanf("%d:%d", &sh, &sm);

	sm += sh * 60;
	sh = sm + va;
	int i = 300;
	while(i < sh)
	{
		if(i > sm || i + vb > sm)
			answer++;
		i += tb;
	}

	printf("%d\n", answer);

	return 0;
}

//
// Created by cxworks on 16-4-20.
//
#include <iostream>
#include <cstring>
using  namespace std;

int main(){
    int a,ta,b,tb;
    cin>>a>>ta>>b>>tb;
    string time;
    cin>>time;
    int h,m;
    h=(time[0]-'0')*10+time[1]-'0';
    m=(time[3]-'0')*10+time[4]-'0';
    int min=(h-5)*60+m;
    int nowB=(min-tb);
    if (nowB%b==0){
        nowB+=b;
    }
    if (nowB<0)
        nowB=0;
    int temp1=min/b;
    //
    int endB;
    if (h==23&&m+ta>59){
        endB=18*60+59;
    }
    else{
        endB=min+ta;
    }
    int total=endB-nowB;

    int ans=total/b;
    if (endB%b!=0)
        ans--;
    cout<<ans<<endl;
}

#include <iostream>
#include <string>
#include <cctype>
#include <vector>

using namespace std;

int main(){
	int a,b,ta,tb,ts;
	string s;
	cin>>a>>ta>>b>>tb>>s;
	ts = ((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+s[4]-'0'-300;
	int x = max(0,ts-tb+1),y = min(1139,ts+ta);
	cout<<y/b-x/b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define si set<int>
#define eps 1e-18L
#define sit set<int> iterator
#define srit set<int> :: reverse_iterator
#define vi vector<int>
#define vit vector<int>::iterator
#define vrit vector<int>::reverse_iterator
#define pb push_back
#define pf push_front
#define beg begin
#define e end
#define rb rbegin
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define yes cout<<"YES"
#define no cout<<"NO"
#define f first
#define s second
#define mp make_pair
#define PI 3.14159265
const long long MAXN=2e5+5;
const long double EPS = 3e-16;
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

typedef  long long ll;
typedef  unsigned long long ull;

void solve(){
  int a,ta;
  cin>>a>>ta;
  int b,tb;
  cin>>b>>tb;
  string str;
  cin>>str;
  string sag = "",minut="";
  sag+=str[0];
  sag+=str[1];
  minut+=str[3];
  minut+=str[4];
  stringstream tt;
  tt<<sag;
  int s ,m;
  tt>>s;
  tt.clear();
  tt<<minut;
  tt>>m;
  s+=m/60;
  m%=60;
  int s1 = s,m1 = m;
  int s2 = s,m2=m+ta;
  s2+=m2/60;
  m2%=60;
  int res=0;
  //cout<<s1<<" : "<<m1<<"\t"<<s2<<" : "<<m2<<endl;
  for(int sagi=5,mini=0;sagi<=23;mini+=b){
        sagi+=mini/60;
        mini%=60;
        //int dolgo=0;
        int sd=sagi,md=mini;
        //cout<<sd<<" : "<<md<<"\t";
        for(int dolgo=1;dolgo<tb;dolgo++){
            //cout<<sd<<" : "<<md<<endl;
            md++;
            sd+=(md)/60;
            md%=60;
            if(s1==sd&&m1<md&&(m2>md||s2>sd)){
                   // cout<<"YES\t";
                    res++;
                    break;
            }
            else if(s1<sd&&s2>sd){
                //cout<<"YES\t";
                    res++;
                    break;
            }else if(s2==sd&&m2>md&&(m1<md||s1<sd)){
              //  cout<<"YES\t";
                    res++;
                    break;
            }
        }
        //cout<<sd<<" : "<<md<<endl;
  }
  cout<<res;

}

int main()
{
    faster();
  int tt=1;
  //cin>>tt;
  while(tt--){
    solve();
    cout<<endl;
  }
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define INF 1000000007
int main()
{
    #ifdef local
    freopen("data.txt","r",stdin);
    #endif
    int a,b,c,d;
    char get1[10];
    while(scanf("%d%d%d%d%s",&a,&b,&c,&d,get1)!=EOF)
    {
        int a = 0;
        int minn = 300;
        int maxn = 18*60+60;
        a = (get1[0]-'0')*10+(get1[1]-'0');
        a*=60;
        a+=(((get1[3]-'0')*10+(get1[4]-'0')));
        int p = a;
        a -= d;
        a = max(a,minn);
        p += b;
        p = min(p,maxn);
        p -= a;

        printf("%d\n",p/c);
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

int a1,b1;
int a2,b2;
int c,d;
const int init = 300;
const int man = 23*60+59;

int main() {
    cin >> a1 >> b1;
    cin >> a2 >> b2;
    scanf("%d:%d",&c,&d);
    c = c*60+d;
    if(c+b1 <= man) {
        int sum  = b1/a2;
        int gg = min(c-300,b1);
        gg = min(gg,b2);
        sum += gg/a2;
        cout << sum << endl;
    } else {
        int sum  = (man-c)/a2;
        int gg = min(c-300,b1);
        gg = min(gg,b2);
        sum += gg/a2;
        cout << sum << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int a, ta, b, tb;

int main(){
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	int x, y; scanf("%d:%d", &x, &y);
	int t1 = 60*x + y - 300;
	int t2 = min(t1 + ta, 18*60 + 59);
	int tot = t2 / b + 1;
	int arr = (t1 - tb) / b;
	if(t1 > tb) arr++;
//printf("%d %d %d %d\n", t1, t2, tot, arr);
	int ans = tot - arr;
	if(t2 % b == 0) ans--;
	cout << ans << endl;
	return 0;
}

#include <iostream>
typedef long long ll;
#include <utility>
#include<algorithm>

using namespace std;
int a, ta, b, tb;

pair <int, int> tt;
int time;

int main() {
	//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	cin >> a >> ta >> b >> tb;
	scanf("%d:%d", &tt.first, &tt.second);
	time = (tt.first - 5) * 60 + tt.second;

	int timeFirst = max(time - tb, 0);
	int timeLast = min(time + ta, 1139);

	cout << (timeLast - timeFirst) / max(b,2);
	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int a, ta, b, tb, sh, st, s, e;
void input() {
    scanf("%d%d%d%d%d:%d",&a,&ta,&b,&tb,&sh,&st);
    s = sh*60+st;
    e = s + ta;
}
void solve() {
    int ans = 0;
    for (int i = 0; i < 500; ++ i) {
        int xs = 300 + i * b;
        int xe = xs + tb;
        if (max(xs, s) < min(xe, e)) {
            ans ++;
        }
    }
    printf("%d\n", ans);
}
int main() {
    input();
    solve();
}

//  https://codeforces.com/contest/665/problem/A
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main()
{
    int a, ta, b, tb;
    string time;

    cin >> a >> ta >> b >> tb >> time;
    int hour = stoi(time.substr(0, 2));
    int mins = stoi(time.substr(3, 2));
    int start_time = hour * 60 + mins;
    int end_time = start_time + ta;
    vector<pair<int, int>> b_buses;
    int answer = 0;
    for (int i = 300; i < 1440; i++)
    {
        if (i % b == 0)
        {
            b_buses.push_back(make_pair(i, i + tb));
        }
    }

    for (int i = 0; i < b_buses.size(); i++)
    {
        if (
            b_buses[i].first >= start_time && b_buses[i].first < end_time ||
            b_buses[i].second > start_time && b_buses[i].second < end_time ||
            start_time >= b_buses[i].first && start_time < b_buses[i].second ||
            end_time > b_buses[i].first && end_time < b_buses[i].second

        )
        {
            answer++;
        }
        // cout << start_time << " " << end_time << " " << b_buses[i].first << " " << b_buses[i].second << endl;
    }

    cout << answer;
}

#include<bits/stdc++.h>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eb emplace_back
#define pb push_back
#define ll long long
#define mp make_pair
#define x first
#define y second
#define mod 1000000007
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std;
int main()
{
   int a,ta;
   cin >> a >> ta;
   int b,tb;
   cin >> b >> tb;
   int hr,min;
   scanf("%d:%d",&hr,&min);
    int st,fi;
    st=((hr*60)-300)+min;
    fi=st+ta;int j;
    //cout << st << " " << fi << "\n";
    int i;int ans=0;
    for(i=0;i<1140;i=i+b)
    {
        if(i>=fi)
            continue;
        if(i+tb<=st)
            continue;
        for(j=i;j<=i+tb;j++){
            if(st<j && j<fi)
            {
                //cout << i << "\n";
                ans++;
                break;
            }
        }

    }
    cout << ans << "\n";
   return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define fi first
#define se second
#define mp make_pair

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	int a, ta, b, tb;
	cin >> a >> ta;
	cin >> b >> tb;

	char c1, c2, c, c3, c4;
	cin >> c1 >> c2 >> c >> c3 >> c4;
	int hour = (c1 - '0') * 10 + (c2 - '0');
	int minute = (c3 - '0') * 10 + (c4 - '0');
	int departure = hour * 60 + minute;
	int lastime = 23 * 60 + 59;

	int arrival = departure + ta;
	int ans = 0;
	int startb = 5 * 60;
	for(int i = 0; i < 1000; i++){
		if(startb + i * b < lastime && startb + i * b < arrival && (startb + i * b) + tb > departure){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int a, t_a, b, t_b, h, m, sum = 0;
	int time_s, time1, time2;
	char x;
	cin >> a >> t_a >> b >> t_b >> h >> x >> m;
	time_s = h * 60 + m;
	time1 = time_s - t_b;
	time2 = time_s + t_a;

	int max = time_s + t_a;
	if (max > 23 * 60 + 59)
		max = 23 * 60 + 59;
	for (int t = 5 * 60; t < max; t += b)
	{
		if (t > time1 && t < time2)
			sum++;
	}
	cout << sum << endl;
	return 0;
}

#include <iostream>
#include<cstdio>
using namespace std;
struct time{
    int hour;
    int minute;
    time(int a=0,int b=0):hour(a),minute(b){}
    int operator -(const time &b){
        return (hour-b.hour)*60+(minute-b.minute);
    }

};
int main()
{
    int ta,la;
    int tb,lb;
    time start;
    cin>>ta>>la>>tb>>lb;
    scanf("%d:%d",&start.hour,&start.minute);
    int runtime=0;
    runtime+=min(lb,(start-time(5,0)));
    runtime+=min(la,(time(23,0)-start));
    cout<<runtime/tb<<endl;

    return 0;
}

#include<bits/stdc++.h>
#include<cstdio>

int main()
{
    int a,ta,b,tb,hh,mm;
    char ch;
    scanf("%d %d",&a,&ta);
    scanf("%d %d",&b,&tb);
    scanf("%d %c %d",&hh,&ch,&mm);

    int rem=(mm+ta)/60;
    mm=(mm+ta)%60;
    hh+=rem;

    int tshh,tsmm;
    tshh=5;
    tsmm=00;
    int cnt=0;
    while(1)
    {
        if(tshh > hh || (tshh==23 && tsmm==59))
            break;
        else if(tshh==hh && tsmm>=mm)
            break;

        tsmm+=b;
        rem=tsmm/60;
        tshh+=rem;
        tsmm%=60;
        cnt++;

    }
    printf("%d",cnt);

    return 0;
}

#include "bits\stdc++.h"
using namespace std;

#define STARTTIME (5*60)
#define ENDTIME (24*60-1)

int main() {
	int a,ta,b,tb,t0;
	int h, m;
	int ans = 0;
	int i,limit;

	cin >> a >> ta >> b >> tb;
	scanf("%02d:%02d",&h,&m);
	t0 = h * 60 + m;
	limit = t0 + ta;

	for (i = STARTTIME; i < limit && i < ENDTIME; i += b)
	{
		if (i + tb < t0) continue;
		ans++;
	}

	cout << ans;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int sbit(int x) {
	int sum = 0;
	while (x) {
		if (x & 1)sum++;
		x >>= 1;
	}
	return sum;
}
void printNumber(int n, int len) {
	if (!len)return;
	printNumber(n >> 1, len - 1);
	cout << (n & 1);
}
bool getBit(int x, int idx) { return x & (x >> idx - 1); }

int setBit1(int x, int idx) {
	return x | (1 << idx);
}
int countNumBits2(int mask) {// O(bits Count)
	int ret = 0;
	while (mask) {
		mask&=(mask)-1;
		ret++;
	}
	return ret;
}
void printAllSubsets(int len) {
	for (int i = 0; i < (1 << len); i++) {
		printNumber(i,len);
		cout << endl;
	}
}
using namespace std;
int main()
{
	file();
	fast();

	int a, ta, b, tb, sa, sb;
	char c;
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%d%c%d", &sa, &c, &sb);
	int start = sa * 60 + sb;
	int end = start + ta, show = 0;
	for (int i = 300; i < min(end, 1440); i += b) {
		if (i + tb > start&&i+tb!=end)show++;
	}
	printf("%d\n", show);

}

#include<stdio.h>

int main() {
	int a, ta;
	int b, tb;
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	int h, m;
	scanf("%d:%d", &h, &m);
	m = h * 60+m;
	m = (m + a - 1) / a*a;
	int em = m + ta;
	int cnt = 0;
	for (int i = 5 * 60; i < 24 * 60; i+=b) {
		if (i < m && m < i + tb) {
			cnt++;
		}
		else if (i < em && em < i + tb) {
			cnt++;
		}
		else if (m < i && i < em) {
			cnt++;
		}
		else if (m < i + tb && i + tb < em) {
			cnt++;
		}
		else if (i < m && em < i + tb) {
			cnt++;
		}
		else if (m < i && i + tb < em) {
			cnt++;
		}
	}
	printf("%d", cnt);
}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
typedef vector<vi>		vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6+13, M = N;
//=======================
int n, m, k;
int i,j,t;
//=======================
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a,ta;
    int b,tb;
    int h,m;
    cin>>a>>ta;
    cin>>b>>tb;
    scanf("%d:%d", &h, &m);
    int x1 = h*60 + m;
    int y1 = x1 + ta;
    int ans=0;
    int x,y,x2,y2;
    for(x2 = 60*5;x2 < 24*60 ;x2 +=b )
    {
        y2 = x2 + tb;
        x = max(x1,x2);
        y = min(y1,y2);
        if(x<y){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int a,ta,b,tb;
	int h,m,t;
	scanf("%d %d %d %d",&a,&ta,&b,&tb);
	scanf("%d:%d",&h,&m);
	t=(h-5)*60+m;
	int ans=0;
	set<int> ss;
	int en=(11+12)*60+59;
	for(int i=t+1;i<t+ta;i++)
	{
		for(int x=0;x<=min(i,en);x+=b)
		{
			int y=x+tb;
			if(x<i&&i<y)
				ss.insert(x);
		}
	}
	cout << ss.size() << endl;
}

#include<bits/stdc++.h>

using namespace std;
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define ff first.first
#define fs first.second
typedef long long ll;
typedef unsigned long long ull;

const ll mod = 1e16+371;
//const ll mod = 1e12+193;

const double PI = acos(-1);
const ll INF = 1e18;
const ll MAX=1e5+10, N=1e6;
//const int lim=1<<18;
//const ll mod = 100000000 ;

int main(){
	ios_base::sync_with_stdio(0);
//	cin.tie(0);
//	srand(time(0));

	int a,ta,b,tb;
	while(cin>>a>>ta>>b>>tb){
		int hr; cin>>hr;
		char c; cin>>c;
		int mi; cin>>mi;
		int strt=hr*60+mi;
		int lst=strt+ta;
		int ans=0;
		for(int x=300;x<24*60*2;x+=b){
			if(strt>=x+tb || lst<=x)
				continue;
			ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	long a, ta;  cin>>a>>ta;
	long b, tb;  cin>>b>>tb;

	long h, m;  char s;  cin>>h>>s>>m;
	m+=60*h;

	long count=0;
	for(long i=300; i<m+ta; i+=b)
	{
		if(i+tb>m)
		count++;
	}

	cout<<count;
}

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    int a,ta,b,tb;
    cin>>a>>ta>>b>>tb;
    int c,d;
    scanf("%d:%d",&c,&d);
    int tol=c*60+d;
    int ans=0;
    if(24*60-1-tol<ta){
        ans=tb/b+(24*60-1-tol)/b;
    }
    else if(tol-300>tb){
        ans=ta/b+tb/b;
    }
    else{
        ans=ta/b+(tol-300)/b;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main() {
	int a, ta, b, tb;
	cin >> a >> ta >> b >> tb;
	string s; cin >> s;

	int hour = (s[0]-'0')*10 + s[1]-'0';
	int minute = (s[3]-'0')*10 + s[4]-'0';
	int start = (hour - 5) * 60 + minute;
	int ans = start / b - (start - tb) / b;
	ta = min(ta, (23 - hour) * 60 + 60 - minute);
	int next = 0;
	if (start % b) next = ta + start % b;
	else next = ta;
	ans += (next - 1) / b;

	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int a,ta,b,tb,i,j,hour,minu;
char s;
int main()
{
	int tomin,forbu,tobus=0,c=0,d;
	cin>>a>>ta>>b>>tb;
	cin>>hour>>s>>minu;
	c=minu+(hour-5)*60;
	tomin=c+ta;
	forbu=tomin/b;
	int car[2][2000];
	for(i=0;i<=forbu;i++)
	{
		if (b*i>=1140)
			break;
		car[0][i]=b*i;
		car[1][i]=b*i+tb;
	}
	for (j=0;j<=i;j++)
	{
		if((car[1][j]>c && car[1][j]<tomin)||(car[0][j]>=c && car[0][j]<tomin)) tobus++;
	}
	cout<<tobus<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long double ld;
typedef short sh;
typedef long long ll;
typedef unsigned long long ull;
const double pi=acos(-1.0);
void file(){
#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);//freopen("out.txt","w",stdout);
#endif
}
int main(){
	//cout<<setprecision(9)<<fixed;
	fast
	file();
	int a,ta,b,tb,h,m,bus=0;cin>>a>>ta>>b>>tb;
	scanf("%d:%d",&h,&m);
	int ia=(h*60)+m,fa=(h*60)+m+ta;
    for(int i=300;i<min(fa,1439);i+=b){
        int f=i+tb;
        if(f>ia)
            bus++;
    }
    cout<<bus;
}

// Problem : A. Buses Between Cities
// Contest : Codeforces - Educational Codeforces Round 12
// URL : https://codeforces.com/group/tDxsgaTGTK/contest/665/problem/A
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//look at my code
//my code is amazing
#include<bits/stdc++.h>
using namespace std;
#define ll long long
// #define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// const int N=;

int32_t main()
{
    int a,ta,b,tb,h,m;
	scanf("%d %d %d %d",&a,&ta,&b,&tb);
	scanf("%d:%d",&h,&m);

	int st=h*60+m;
	int et=st+ta;

	ll ans=0;
	for(int i=5*60;i<=24*60;i+=b){
		int x=i+tb;
		//-----            -----
		//   ------       ---
		if((x>st and i<et)||( i>x and i<et )||( st==i and 1 ))
		ans++;

	}

	cout<<ans;

	return 0;

}

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);

	int a, ta, b, tb;
	char s[8];
	scanf("%d%d%d%d%s", &a, &ta, &b, &tb, s);
	int simon = ((int)(s[0] - '0') * 10 + (int)(s[1] - '0')) * 60 + (int)(s[3] - '0') * 10 + (s[4] - '0');
	int begin = max(300, simon - tb + 1);
	int end = min(1440-1, simon + ta - 1);
	//printf("%d %d %d\n", simon, begin, end);
	int ans = (end - begin) / b;
	if ((begin - 300) % b == 0) ++ans;
	printf("%d\n", ans);
}

#include <iostream>
#include<algorithm>
using namespace std;
#include<cmath>
#include<stdio.h>
#define  PI acos(-1.0)
typedef struct
{
    int h;
    int m;
} node;
int suanq(int hh,int mm,int h,int m)
{
    if(h<hh||(h==hh&&m<=mm))
        return -1;
    int count=0;
    for(int i=hh; i<=h; i++)
    {
        for(int j=mm; j<=60; j++)
        {

            if(i==h&&j==m)
                return count;
            count++;
        }
    }
}
int suanh(int hh,int mm,int h,int m)
{
    if(h>=23&&m>=59)
        return -1;
    if(h>=24)
        return -1;
    int count=0;
    for(int i=h; i<=hh; i++)
    {
        for(int j=m; j<=60; j++)
        {

            if(i==hh&&j==mm)
                return count;
            count++;
        }
    }

}
int  main()
{
    int a,b,aa,bb,h,m;
    while(cin>>a>>b>>aa>>bb)
    {
        scanf("%d:%d",&h,&m);
        int qian=suanq(5,00,h,m);
        int hou=suanh(23,59,h,m);
        int qiant,hout;
        if(qian==-1||qian<=bb)
        {
            qiant=suanq(5,00,h,m);
        }
        else
        {
            qiant=bb;
        }
        if(hou==-1||hou<=b)
        {

            hout=suanh(23,59,h,m);
        }
        else
        {
            hout=b;
        }
//        cout<<qian<<" "<<hou<<endl;
    //    cout<<qiant<<" "<<hout<<endl;
int ans=0;
        int st=h*60+m-qiant;
        int ed=h*60+m+hout;
        int st1=h*60+m;
       // cout<<st<<" "<<ed<<endl;
        for(int i=5*60;i<=11*60+59;i+=aa)
        {
            if(i+bb>st1&&i<ed)
            {
                 ans++;
            }

            continue;
            if(i>st1&&i<ed)
            {
                 ans++;

            }
        }
        cout<<ans<<endl;

    }
}
/*
1 1
1 1
05:20
*/

#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int a,ta,b,tb,mm,ss,t;
const int maxt = 18 * 60 + 59;
int main(int argc, char** argv) {
    scanf("%d%d%d%d%d:%d", &a, &ta, &b, &tb, &mm, &ss);
    t = (mm - 5) * 60 + ss;
    int y = (t - tb) / b;
    int x = min(t + ta - 1, maxt)/b;
    printf("%d\n", x -y );

    return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int a, b, tA, tB, hour, min;;
	cin >> a >> tA >> b >> tB >> hour;
	cin.get();
	cin >> min;
	int daytimeRemain = (23 - 5) * 60 + (59 - 0); //5:00 - 23:59
	int busTimeRemain = tA, count = 0, timeFromStart = (hour - 5) * 60 + min;
	int tempL = 0;
	while (tempL * b + tB <= timeFromStart)
	{
		tempL++;
	}
	int tempH = tempL;
	while (tempH * b < timeFromStart + tA && tempH * b < daytimeRemain)
	{
		tempH++;
	}
	cout << tempH - tempL << endl;
	return 0;
}

/* sjsakib  */
#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define repl(i,n) for(int i=1; i<=(int)n; i++)
#define replv(i,n) for(int i=n; i>=1; i--)

#define INF (1<<28)
#define PI 3.141592653589793238462643383279502
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define vi vector<int>
#define pmp make_pair

#define sdi(x) scanf("%d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define sdc(x) scanf("%c",&x)
#define SDs(x) scanf("%s",x)
#define uu first
#define vv second
using namespace std;

template<class T> inline T gcd(T a,T b) {if(a<0)return
gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b) {if(a<0)return
lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> inline T sqr(T x){return x*x;}
template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1); }

typedef long long i64;
typedef unsigned long long ui64;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

//bool operator < ( const node& p ) const {      return dist > p.dist;   }

#define cl list<char>

#define OUT(x,y) (x>7 || y>7 || x<0 || y<0)

int fx[]={0,0,-1,+1,-1,-1,+1,+1};
int fy[]={-1,+1,0,0,-1,+1,-1,+1};
int bx[]={1,-1,1,-1};
int by[]={1,-1,-1,1};
int rx[]={0,0,1,-1};
int ry[]={1,-1,0,0};
int nx[]={1,2,1,2,-1,-2,-1,-2};
int ny[]={2,1,-2,-1,2,1,-2,-1};

int board[8][8];

int main() {
    //ios::sync_with_stdio(false);
    int a,ta,b,tb,dtime,atime,hh,mm;
    sdii(a,ta);
    sdii(b,tb);
    scanf("%d:%d",&hh,&mm);
    dtime = (hh-5)*60+mm;
    atime = min(dtime+ta,1139)-1;
    int cnt = (atime/b)-((dtime-tb)>0?(dtime-tb)/b+1:0)+1;
    cnt-=(atime%b==0?1:0);
    cout<<cnt<<endl;
    return 0;

}

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
#define MOD 1000000007
#define MAX 1000010

int N,K,Q;
int freq[MAX];

typedef long long int ll;
int main(){

// freopen("data.in.txt","r",stdin);
   int a,t1,b,t2;
   cin>>a>>t1>>b>>t2;
   int h,m;
   char op;
   cin>>h>>op>>m;
   int l=h*60+m;
   int l1=l+t1;
  // if(l1>23*60+59) l1=23*60+59;//arrive
   int l2=l-t2;
//   if(l2<5*60) l2=5*60;
int cnt1=l2,cnt2=24*60-1,cnt=0;
while(cnt1<=cnt2)
{
    if(cnt1+t2>cnt2) break;
    if(cnt1+t2>l&&cnt1<l1) cnt++;
    cnt1+=b;

}
cout<<cnt<<endl;
   return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	int a, ta, b, tb;
	cin >> a >> ta >> b >> tb;
	cin >> s;
	int h = (s[0] - '0') * 10 + s[1] - '0';
	int m = (s[3] - '0') * 10 + s[4] - '0';
	int t1 = 60 * h + m;
	int t2 = t1 + ta;
	int ans = 0;
	int t3 = 5 * 60,t4=t3+tb;
	for (int i = 0; i < 100; i++)
	{
		if (max(t1, t3) <= min(t2, t4)) ans++;
		//if ((t3<=t1&&t4>t1)||(t3>=t1&&t4<=t2)||(t3<t2&&t4>=t2)) ans++;
		t3 += b;
		t4 = t3 + tb;
	}
	cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
#define re register
#define gcd __gcd
#define ft first
#define sd second
#define mr make_pair
#define lowbit(x) ((x)&-(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
const int N = 2e6+7;
const int M = 2e6+7;
const int lim = 2e5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int main()
{
    int a,ta,b,tb,aa,bb;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d:%d",&aa,&bb);
    int st = 60*aa+bb, ed = 60*aa+bb+ta;
    int ans=0,t=0;
    while( 1 )
    {
    	int k = 60*5+b*t,kk = k+tb;
    	if( k >= 24*60 || k > ed )
			break;
		if( ( k >= st && k < ed ) || ( kk > st && kk <= ed ) )
			ans++;
		t++;
	}
	printf("%d\n",ans);
    return 0;
}

#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
   int a,ta,b,tb,hh,mm;
   cin>>a>>ta>>b>>tb;
   scanf("%d:%d",&hh,&mm);
   int tem=(hh-5)*60+mm;
   int ans=0;
   int l=tem,r=tem+ta;int n=((23-5)*60+59);
   for(int i=0;i<=n;i+=b)
   {
      if(i==r) continue;
      if((i>=l&&i<=r)||((i+tb)>=l&&(i+tb)<=r)) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(void) {

	int a, ta, b, tb;
	cin>>a>>ta>>b>>tb;
	string s;
	cin>>s;
	int start = 60*((s[0]-'0')*10 + (s[1]-'0')) + (s[3]-'0')*10 + (s[4]-'0');
	int finish = ta + start;
	//cout<<start<<" "<<finish<<endl;
	int ans = 0;
	for(int st = 300; st < 24*60; st += b) {
		int x = max(st, start);
		int y = max(finish, st+tb);
		if(x < y)	ans++;
	}

	cout<<ans;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,x,y,p,q,i,j,m,h,t,ans;
    string str;
    cin >> a >> x;
    cin >> b >> y;
    cin >> str;
    i=str[0]-48,j=str[1]-48;
    h=j+10*i;
    i=str[3]-48,j=str[4]-48;
    m=j+10*i;
    t=m+(h-5)*60;
    p=min(t,y);
    t=59-m+(23-h)*60;
    q=min(t,x);
    ans=(p+q)/b;
    t=m+(h-5)*60;
    if(t%p==0 && t%q==0 && t%a==0 && t%b==0 && a%b==0)
        ans=ans-1;
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

inline void file()
{
    freopen("D:\\go.txt", "r", stdin);
    freopen("D:\\leave.txt", "w", stdout);
}

int main()
{
    //file();
    int a, ta;
    int b, tb;
    int h, m;
    scanf("%d%d", &a, &ta);
    scanf("%d%d", &b, &tb);
    scanf("%d:%d", &h, &m);
    int leave_time_b = 300;
    int leave_time_a = h * 60 + m;
    int arrive_time_a = leave_time_a + ta;
    int res = 0;
    for (int i = leave_time_b; i < 1440;i += b)
    {
        if ((i != arrive_time_a && i != leave_time_a) && (i + tb < arrive_time_a && i + tb > leave_time_a) || i > leave_time_a)
        {
            //cout << "i = " << i << endl;
            res++;
        }
        if (i >= arrive_time_a)
            break;
    }
    printf("%d\n", res);

    return 0;
}

#include <iostream>
#include <string>

int main()
{
    int aFreq, aTime, bFreq, bTime;
    std::cin >> aFreq >> aTime >> bFreq >> bTime;

    std::string stringTime;
    std::cin >> stringTime;

    int startTime = ( stringTime[0] - '0' ) * 600 + ( stringTime[1] - '0' ) * 60 - 60 * 5 + ( stringTime[3] - '0' ) * 10 + stringTime[4] - '0';

    int periodStart, periodFinish;
    if( startTime - bTime >= 0 )
        periodStart = startTime - bTime + bFreq - (( startTime - bTime ) % bFreq );
    else
        periodStart = 0;

    if( startTime + aTime <= 23 * 60 + 59 )
        periodFinish = startTime + aTime - 1;
    else
        periodFinish = 23 * 60 + 59;

    if( periodStart <= periodFinish )
        std::cout << ( periodFinish - periodStart ) / bFreq + 1;
    else
        std::cout << 0;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a, ta, b, tb;

int main(){
    //freopen("input.txt", "r", stdin);
    vector<int> pos;
    scanf("%d%d%d%d", &a, &ta, &b, &tb);
    int hh, mm;
    scanf("%d:%d", &hh, &mm);
    int stmin = (hh - 5) * 60 + mm;
    int stval = ta * tb;
    int aspeed = stval / ta;
    int bspeed = stval / tb;
    //cout << aspeed << " " << bspeed << "\n";
    for(int i = 0; i <= stmin; i++){
        for(auto& it: pos){
            it -= bspeed;
        }
        if(i % b == 0){
            pos.push_back(stval);
        }

    }
    int cnt = 0;
    int x = 0;
    for(int i = stmin + 1; i < stmin + ta; i++){
        for(auto& it: pos){
            if(x <= it && it - bspeed <= x + aspeed){
                cnt += 1;
            }
            it -= bspeed;
        }
        x += aspeed;
        if(i % b == 0){
            pos.push_back(stval);
        }

    }
    printf("%d\n", cnt);
}

#include <cstdio>
#include <iostream>
using namespace std;
struct node
{
    int h,m;
};
node p[320000];
int main()
{
    int A,ta,B,tb;
    cin>>A>>ta>>B>>tb;
    char s[5];
    cin>>s;
    int begh,begm;
    begh=(s[0]-'0')*10+s[1]-'0';
    begm=(s[3]-'0')*10+s[4]-'0';
    int i;
    int bgh=5,bgm=0;
    for(i=0;i<=300000;i++)
    {
        p[i].h=bgh;
        p[i].m=bgm;
        bgm+=B;
        bgh+=bgm/60;
        bgm%=60;
        if(bgh>=25)break ;
    }
    int finm=begm+ta;
    int finh=begh+finm/60;
    //cout<<finm<<endl;
    finm%=60;
    begm-=tb;
    begh+=(begm-60)/60;
    while(begm<0)begm+=60;
    int ans=0;
    //cout<<begh<<":"<<begm<<endl;
    //cout<<finh<<":"<<finm<<endl;
    for(i=0;i<=200000;i++)
    {
        if(finh==begh&&p[i].h==finh)
        {
            if(p[i].m>begm&&p[i].m<finm)ans++;
            continue ;
        }
        else
        {
        if(p[i].h==begh&&p[i].m>begm)ans++;
        if(p[i].h==finh&&p[i].m<finm)ans++;
        if(p[i].h<finh&&p[i].h>begh)ans++;}
        if(p[i].h>=24)break ;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
   int a,ta,b,tb,hh,mm;
   cin>>a>>ta>>b>>tb;
   char ch[10];
   scanf("%s",ch);
   hh= (ch[0]-'0')*10+(ch[1]-'0');
   mm=(ch[3]-'0')*10+(ch[4]-'0');
   int tem=(hh-5)*60+mm;
   int ans=0;
   int l=tem,r=tem+ta;int n=((23-5)*60+59);
   for(int i=0;i<=n;i+=b)
   {
      if((i>=l&&i<r)||((i+tb)>l&&(i+tb)<=r)) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

char s[10];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int a,ta,b,tb;
	cin>>a>>ta>>b>>tb;
	cin>>s;

	int t=((s[0]-'0')*10+s[1]-'5')*60+(s[3]-'0')*10+s[4]-'0';
	int st=max(0,t-tb+1);
	int ed=min(1139,t+ta-1);

	cout<<st<<" "<<ed<<endl;
	int ans=0;
	for(int i=st;i<=ed;i++){
		if(i%b==0)ans++;
	}
	cout<<ans<<endl;

	return 0;
}

#include <cstdio>
#include <string>
using namespace std;

int a, ta, b, tb;

int amount(int ti)
{
	if (ti == -1) return 0;
	return (ti - 1) / b + 1;
}

int main()
{
	string s;
	char buf[6];
	scanf("%d%d%d%d%s", &a, &ta, &b, &tb, buf);
	s = buf;
	int t = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3, 2)) - 300;
	printf("%d\n", amount(min(t + ta - 1, 1139)) - amount(max(t - tb, -1)));
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sn scanf
#define pt printf
#define wl while
#define fi(a,b,c) for(int(a)=(b);(a)<=(c);(a)++)
int a,ta,b,tb,m,j;
int mu,ak,te;
char c;
int main(){
 sn("%d%d",&a,&ta);
 sn("%d%d",&b,&tb);
 sn("%d%c%d",&j,&c,&m);
 //pt("%d %d m ",j,m);
 m+=(j*60);
 //pt("%d m ",m);
 mu=300;
 ak=(23*60)+59;
 //pt("%d ak ",ak);
 wl(mu<(m-tb))mu+=b;
 //pt("%d mu ",mu);
 te=mu;
 wl((te<(m+ta))&&((te+b)<ak))te+=b;
 if(te>(m+ta))te-=b;
 te=te-mu;
 pt("%d\n",(te/b));
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <utility>
#include <memory.h>
#include <cassert>
#include <iterator>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
#include <ctime>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
//  freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  int a, ta;
  int b, tb;
  scanf("%d%d%d%d", &a, &ta, &b, &tb);
  int h, m;
  scanf("%d:%d", &h, &m);
  m = m + h * 60;
  int start = 5 * 60;
  int le = m;
  int ri = m + ta;
  int cur = start;
  int ans = 0;
  for (int i = 0; i <= 1000000; i++) {
  	int l = cur;
  	int r = cur + tb;
  	l = max(l, le + 1);
  	r = min(r, ri - 1);
  	if (l < r) ++ans;
  	cur += b;
  	if (cur > 23 * 60 + 59) break;
  }
  cout << ans << endl;
	return 0;
}

#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
   int a,ta,b,tb,hh,mm;
   cin>>a>>ta>>b>>tb;
   scanf("%d:%d",&hh,&mm);
   int tem=(hh-5)*60+mm;
   int ans=0;
   int l=tem,r=tem+ta;int n=((23-5)*60+59);
   for(int i=0;i<=n;i+=b)
   {
      if(i==r||l==(i+tb)) continue;
      if((i>l&&i<r)||((i+tb)>l&&(i+tb)<r)) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

#include "bits\stdc++.h"
using namespace std;

int main() {
	int i, j;
	int a, b, ta, tb, t0;
	char doph1, doph2, dopm1, dopm2, dop;
	int ans, x;

	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	scanf("%c", &dop);
	scanf("%c%c%c%c%c", &doph1, &doph2, &dop, &dopm1, &dopm2);
	t0 = ((doph1 - '0') * 10 + (doph2 - '0')) * 60 + ((dopm1 - '0') * 10 + (dopm2 - '0')) - 5 * 60;

	x = t0 % b;
	ans = (ta - (b - x)) / b;
	if (x == 0) ans++;

	if (t0 > b)
	{
		if (t0 > tb) t0 = tb-x;
		ans += t0 / b;
	}
	else
	{
		if(t0 != 0 ) ans++;
	}

	printf("%d", ans);
	return 0;
}

#include<stdio.h>
int main()
{
    int a,b,c,d;
    int h,s;
    scanf("%d%d",&a,&b);
    scanf("%d%d",&c,&d);
    scanf("%d:%d",&h,&s);
    int time=(h*60)+s+b;
    int x,y;
    int m=d-b;
    if(time<=1439 && b>=d )
        {
            x=b/c;
            int z=d/c;
            y=x+z;
            printf("%d\n",y);
        }

       else if(time<=1439 && b<d&& a<m)
        {
            x=b/c;
            int z=d/c;
            y=x+z;
            printf("%d\n",y);
        }
         else if(time<=1439 && b<d&& a>m)
        {
            x=b/c;
            int z=d/c;
            y=x+z-1;
            printf("%d\n",y);
        }

        else if(time>1439)
        {
            x=b/c;
            int z1=time-1439;
            int z2=z1/c;
            y=x+z2-1;
             printf("%d\n",y);
        }
        return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
const ll mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll N=1e5+8;
int main(){
 ll a,ta,b,tb,t1,t2,ans=0,t3,t4;
 cin>>a>>ta;
 cin>>b>>tb;
string s;
cin>>s;
ll x=((s[0]-'0')*10+(s[1]-'0'))*60;
ll y=(s[3]-'0')*10+(s[4]-'0');
t1=x+y;
cout<<t1<<endl;
t2=t1+ta;
cout<<t2<<endl;
t3=5*60;
t4=5*60+tb;
while(t3<24*60&&t4<(24*60+tb)){
  if(t3>=t1&&t3<t2){
    ans++;
   // cout<<ans<<endl;
    t3=t3+b;
    t4=t4+b;
   // cout<<t3<<' '<<t4<<endl;

  }
  else
  if(t4>=t1&&t4<t2){
    ans++;
    //cout<<ans<<endl;
    t3=t3+b;
    t4=t4+b;
    //cout<<t3<<' '<<t4<<endl;
  }
  else {
    t3+=b;
    t4+=b;
    //cout<<t3<<' '<<t4<<endl;
  }
}
cout<<ans<<endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <utility>
#include <numeric>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<valarray>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define MP                  make_pair
#define lpv(i, v)           for(int i=0;i<sz(v);++i)
#define lpn(i, n)           for(int i=0;i<(int)(n);++i)
#define ss	                second
#define ff	                first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;
typedef vector<int>                 vi;
typedef vector<ll>                  vl;

int main(){
	int a, ta, b, tb,mn,hou;
	char x;
	cin >> a >> ta >> b >> tb >> hou >> x >> mn;
	int st = 5*60;
	int end =59+23*60+tb;
	int r = max(st, hou * 60 + mn - tb+1), u = min(end, hou * 60 + mn + ta);
	int c = 0;
	while (r+b <= u)c++, r += b;
	cout << c << endl;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 155
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"Possible" : "Impossible");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
}
void et() {
    puts("-1"); exit(0);
}

void fmain() {
    int a,b,ta,tb;
    cin>>a>>ta>>b>>tb;
    int h,m;
    scanf("%d:%d", &h, &m);
    int st = h*60 + m;
    int ed = st + ta;
    for(int i=300;i<ed;i+=b) {
        int j=i+tb;
        if (j<=st) continue;
        k++;
    }
    cout<<k<<endl;;
}
int main() {
    fmain();
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
#define LANCER_SHARK { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
using namespace std;

//int a[200007], b[200007];
int main(){
	LANCER_SHARK;
	ll a, ta, b, tb, h, m,enh,enm ,hd = 5, md = 0, arh, arm, res = 0;
	char c;
	//string st1, st2, en1, en2;
	cin >> a >> ta >> b >> tb;
	cin >> h >> c >> m;
	enh = h + (ta / 60);
	enm = m + (ta % 60);
	if (enm > 59){
		enh++;
		enm -= 60;
	}
	// h :m   enh:enm
	// hd:md  arh:arm
	while (1)
	{
		arh = hd + (tb / 60);
		arm = md + (tb % 60);
		if (arm > 59){
			arh++;
			arm -= 60;
		}
		if (enh > hd &&arh > h)
			res++;
		else if (enh == hd && enm > md && (arh > h || (arh == h && arm > m)))
			res++;
		else if ((arh == h && arm > m) && (enh > hd || (enh == hd&&enm > md)))
			res++;
		else if (hd > enh || h > 23 || enh > 23 || hd > 23 || arh > 23)
			break;
		hd += (b / 60);
		md += (b % 60);
		if (md > 59){
			hd++;
			md -= 60;
		}
	}
	cout << res;
	cout <<  endl;
	return 0;
}

#include<iostream>
#include<string>

using namespace std;

int conv(int hour,int minu)
{
    int tmin=hour*60+minu;
    return tmin;
}

int time(int t,int b)
{
    int i;
    for(i=300;i<t;i+=b);
    return i;
}

int main()
{
    int a,b,ta,tb,z,i;
    z=0;
    cin>>a>>ta>>b>>tb;
    int h,m;
    string s;
    cin>>s;
    h=((int)s[0]-48)*10+(int)s[1]-48;
    m=((int)(s[3])-48)*10+(int)s[4]-48;
    h=conv(h,m);
    if(h-tb<=300)
    {
        for(i=300;i<h+ta;i=i+b)
        {
            z++;
        }
    }
    else if(h+ta>=1440)
    {
        int x=time(h-tb,b);
        if(x+tb==h)
        {
            x=x+b;
        }
        for(i=x+1;i<1440;i=i+b)
        {
            z++;

        }
    }
    else
    {
        int x=time(h-tb,b);
        if(x+tb==h)
        {
            x=x+b;
        }
        for(i=x;i<h+ta;i=i+b)
        {
            z++;
        }
    }
   if(a==ta&&b==tb&&b==a&&h==1439)
   {
       z=0;
   }
    cout<<z;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define N (1000005)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(v) ((int)(v).size())
#define ed(v) v.end()
#define contains(v,i) (v.find(i)!=v.end())
#define forn(i,a,b) for(ll i = a; i < b; i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(v) ((a)*(a))
#define cb(v) ((a)*(a)*(a))

typedef long long int ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef vector<ll> vi;
typedef map<ll,ll> mll;

bool has_overlap(ll a1, ll a2, ll b1, ll b2){
  forn(i, a1+1, a2){
    if(b1 <= i && i <= b2){
      return true;
    }
  }
  return false;
}

int main(){

    fast

    ll a, ta, b, tb;
    string start;
    cin >> a >> ta >> b >> tb;
    cin >> start;

    ll start_hr = (start[0] - '0') * 10 + (start[1] - '0');
    ll start_minute = (start[3] - '0') * 10 + (start[4] - '0');

    ll start_ts = start_hr * 60 + start_minute - 5 * 60;
    ll end_ts = start_ts + ta;

    // cout << start_ts << " " << end_ts << endl;

    ll count = 0;
    forn(i, 0, 60 * 24){
      ll start_ts_b = i * b;
      ll end_ts_b = start_ts_b + tb;

      if(has_overlap(start_ts, end_ts, start_ts_b, end_ts_b)){
        // cout << start_ts_b << " " << end_ts_b << endl;
        count++;
      }
    }
    cout << count << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int a, ta, b, tb;

int main(){
	scanf("%d%d%d%d", &a, &ta, &b, &tb);
	int x, y; scanf("%d:%d", &x, &y);
	int t1 = 60*x + y - 300;
	int t2 = min(t1 + ta, 18*60 + 59);
	int tot = t2 / b + 1;
	int arr = (t1 - tb) / b;
	if(t1 >= tb) arr++;
//printf("%d %d %d %d\n", t1, t2, tot, arr);
	int ans = tot - arr;
	if(t2 % b == 0) ans--;
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef  long long ll;

int main()
{
    int en=60*24;
    int a,ta,b,tb;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    int h,m;
    scanf("%d:%d",&h,&m);
    int C_start=m+60*h;
    int C_end=C_start+ta;
    int start=5*60;
    while(start+tb<C_start)
    {
        start+=b;
    }
    int ans=0;
    while(start<C_end)
    {
        if(start+tb>C_start||start<C_end)ans++;
        start+=b;
    }
    printf("%d\n",ans);

}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 100, mod = 1e9 + 7, inf = 0x3f3f3f3f;
typedef long long ll;
const ll INF = (1ll<<50);
int main()
{
    int a,ta,b,tb,hh,mm;
    int ts,te,s=60*5,e=23*60+59;
    int l=0,r=0;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d:%d",&hh,&mm);
    ts=hh*60+mm;
    l=ts-tb;
    if(l<s) l=s;
    if((l-s-tb)&&(l-s-tb)%b==0) l++;  //判断从B到A的车是否到达B
    te=ts+ta;
    r=te;
    if(r>e) r=e;
    int ans=0;
    while(s<e)
    {
        if(s>=l&&s<r) ans++;
        s+=b;
        if(s>r) break;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int start=300;
int a,b,ta,tb;
char depart[6];
int main()
{
    cin>>a>>ta>>b>>tb;
    scanf("%s",depart);
    int time=((depart[0]-'0')*10+(depart[1]-'0'))*60;
    time+=(depart[3]-'0')*10+(depart[4]-'0');
    int num=0;
    int dt=time-start;
    if(time<1440)
    {
        num+=dt/b+1;
        if(dt-tb>=0)
        num-=((dt-tb)/b+1);
        if(ta+time<1440)
        {
            if((ta-(time-start)%b)%b==0) num+=(ta-(time-start)%b)/b-1;
            else num+=(ta-(time-start)%b)/b;
        }
        else
        {
            if((1440-time-(time-start)%b)%b==0) num+=((1440-time-(time-start)%b)/b-1);
            else num+=(1440-time-(time-start)%b)/b;
        }
    }
    else
    {
        if((1440-start)%b==0) num+=(1440-start)/b+1;
        else num+=(1440-start)/b;
        if(time-start-tb>0)
        num-=(time-start-tb)/b;
    }
    cout<<num<<endl;
    return 0;
}

#include <iostream>
#include<algorithm>
using namespace std;
#include<cmath>
#include<stdio.h>
#define  PI acos(-1.0)
typedef struct
{
    int h;
    int m;
} node;
int suanq(int hh,int mm,int h,int m)
{
    if(h<hh||(h==hh&&m<=mm))
        return -1;
    int count=0;
    for(int i=hh; i<=h; i++)
    {
        for(int j=mm; j<=60; j++)
        {

            if(i==h&&j==m)
                return count;
            count++;
        }
    }
}
int suanh(int hh,int mm,int h,int m)
{
    if(h>=23&&m>=59)
        return -1;
    if(h>=24)
        return -1;
    int count=0;
    for(int i=h; i<=hh; i++)
    {
        for(int j=m; j<=60; j++)
        {

            if(i==hh&&j==mm)
                return count;
            count++;
        }
    }

}
int  main()
{
    int a,b,aa,bb,h,m;
    while(cin>>a>>b>>aa>>bb)
    {
        scanf("%d:%d",&h,&m);
        int qian=suanq(5,00,h,m);
        int hou=suanh(23,59,h,m);
        int qiant,hout;
        if(qian==-1||qian<=bb)
        {
            qiant=suanq(5,00,h,m);
        }
        else
        {
            qiant=bb;
        }
        if(hou==-1||hou<=b)
        {

            hout=suanh(23,59,h,m);
        }
        else
        {
            hout=b;
        }
//        cout<<qian<<" "<<hou<<endl;
    //    cout<<qiant<<" "<<hout<<endl;
int ans=0;
        int st=h*60+m-qiant;
        int ed=h*60+m+hout;
        int st1=h*60+m;
       // cout<<st<<" "<<ed<<endl;
        for(int i=5*60;i<60*24;i+=aa)
        {
            if(i+bb>st1&&i<ed)
            {
                 ans++;
            }

            continue;
            if(i>st1&&i<ed)
            {
                 ans++;

            }
        }
        cout<<ans<<endl;

    }
}
/*
1 1
1 1
05:20
*/

#include <bits/stdc++.h>
#define fr first
#define pb push_back
#define skip continue
#define sc second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define vi vector<ll>
#define MAX 1e9 + 1234
#define PI 2.00*acos(0)
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<char, int> pci;

int const INF = 1e8 + 100;
const int MOD = 998244353;
const int N = 310500;
const ld EPS = 3e-16;

void faster(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int simple( int n ) {
    int i, sq;
    if ( n%2 == 0 ) { return 0; }
    sq= (int)sqrt( n );
    for ( i= 3; i<=sq; i++ ) {
    if ( (n%i) == 0 ) { return 0; }
    }
    return 1;
}
ll gcd(ll a, ll b){
    if(a > b)	swap(a, b);
    if(!a)	return b;
    return gcd(b % a, a);

}

ll lcm (ll a, ll b) {
	return a / gcd (a, b) * b;
}

bool ok(int a, pii& b)
{
    return a > b.fr && a < b.sc;
}

bool check(pii& a, pii& b){
    for (int x = a.fr; x <= a.sc; ++x) {
        if (ok(x, b)) {
            return true;
        }
    }
    return false;
}

void solve(){
    int a , ta;
    cin >> a >> ta;
    int b , tb;
    cin >> b >> tb;
    string s;
    cin >> s;
    int h , m , t;
    h = (s[0] - '0') * 10 + (s[1] - '0');
    m = (s[3] - '0') * 10 + (s[4] - '0');
    t = h * 60 + m;

    int ans = 0;
    for (int i = 5 * 60; i < 24 * 60; i += b) {
        pii p1 = mp(t, t + ta);
        pii p2 = mp(i, i + tb);
        if (check(p1, p2)) {
            ++ans;
        }
    }

    cout << ans << "\n";
}
int main(){

    faster();
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define NN
#define esp 1e-7
#define inf 1e9
#define LL long long
#define rep(i,s,t) for (int i=s;i<=t;i++)
#define red(i,t,s) for (int i=t;i>=s;i--)
#define vtson(k,x) for (int k=o[x];k;k=nex[k])
using namespace std;
inline int read()
{
    int t=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9')f=(ch=='-')?-1:f,ch=getchar();
    while(ch>='0'&&ch<='9')t=t*10+ch-'0',ch=getchar();
    return t*f;
}

/*
int cc=0,to[NN<<1],nex[NN<<1],o[NN];
inline void add(int x,int y)
{
    to[++cc]=y,nex[cc]=o[x],o[x]=cc;
    to[++cc]=x,nex[cc]=o[y],o[y]=cc;
}
*/
int main()
{
  //  freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
    int a=read(),ta=read(),b=read(),tb=read(),h=read(),mn=read();
    h-=5;
    int now=h*60+mn;
    int num1=min(419,(now+ta-1))/b+1,num2=max(0,min(419,(now-tb+b))/b);
    int ans=num1-num2;
    printf("%d\n",ans);
    return 0;
}

#include<iostream>
using namespace std;
int a,ta,b,tb;
char time[10];
int hour,minute,count2;
#define mm 1139
int main()
{
	//freopen("input.txt","r",stdin);
    scanf("%d %d %d %d",&a,&ta,&b,&tb);
    scanf("%s",time);
    hour=(time[0]-'0')*10+(time[1]-'0');
    minute=(time[3]-'0')*10+(time[4]-'0');
    int sum=(hour-5)*60+minute;
    int sum1;
    if(sum-tb>0)
		sum1=sum-tb;
	else
		sum1=0;
	int count1;
	if(sum1==0)
		count1=0;
	else
		count1=sum1/b+1;
    int sum2=sum+ta;
    if(sum2>mm)
    {
    	sum2=mm;
    	count2=sum2/b+1;
	}
    else
    {
    	count2=sum2/b;
    	if(sum2%b>0)
    		count2++;
	}
    cout<<count2-count1<<endl;
    //printf("%d %d %d %d %d\n",sum,sum1,sum2,count1,count2);
    return 0;
}

#include <stdio.h>

using namespace std;

int main()
{
    int a,b,ta,tb,sh,sm;
    scanf("%d %d",&a,&ta);
    scanf("%d %d",&b,&tb);
    scanf("%d:%d",&sh,&sm);
    int st=sh*60+sm;
    int ans=0;
    for (int t=300;t<=st+ta;t+=b)
    {
        int t1=t,t2=t1+tb;
        if ((t1>=st && t1<st+ta)||(t2>st && t2<=st+ta)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int a, Ta, b, Tb, currHour, currMin, lastHour,lastMin;
int z;

int main(){

    cin >> a >> Ta >> b >> Tb >> currHour >> currMin;

    int baseTime = 5 * 60;
    int finalTime = baseTime + (24 - 5) * 60;
    int depart = currHour * 60 + currMin;
    int arrival = depart + Ta;

    int first_bus = baseTime;

    while(first_bus + Tb < depart && first_bus < finalTime)
        first_bus += b;

    int bus = first_bus;
    z = 0;
    while(bus < arrival && bus < finalTime){

        z = z + 1;
        bus += b;
    }

    cout << z << endl;

    return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <set>
#include <bitset>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long> vl;

#define endl '\n'
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()

void conan()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main()
{
	conan();

	int a, ta, b, tb, h, m;

	cin >> a >> ta >> b >> tb;
	scanf("%d:%d", &h, &m);

	int start = h * 60 + m;
	int enda = start+ ta;
	int cnt = 0;

	for (int i = 300; i < min(1440, enda); i += b)
	{
		if (i + tb > start)
			cnt++;
	}

	cout << cnt << endl;

}

#include <iostream>

using namespace std;

int main()
{

int x ,y ,a,b;
cin >> x >> y >> a >> b;
string s;
cin >> s;
string g=s.substr(3);
int r=g[1]-'0'+10*(g[0]-'0');
g=s.substr(0,2);
int f=g[1]-'0'+10*(g[0]-'0');

f=f*60+r;
int j=1439-f;
f-=5*60;
//cout << f <<endl;
if (f<b)
{
    int k=y+f;
    cout << k/a<<endl;
}
else if(j<y)
{
    int k=j+b;
    cout << k/a<<endl;
}else
{
    if (a==b&&x==y)
    {
        cout << y<<endl;
        return 0;
    }
   int k= y+b;
   if (a==1)
   cout <<k/a-1<<endl;
   else
    cout << k/a<<endl;
}

    return 0;
}

/***************************************
    codeforces = topcoder = sahedsohel
    IIT,Jahangirnagar University(42)
****************************************/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define inf (INT_MAX/10)
#define linf (LLONG_MAX/10LL)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define fl(c,i,n) for(i=c;i<n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define memn(a) memset(a,-1,sizeof(a))
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
#define mpr make_pair
#define PI (2.0*acos(0.0)) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pii pair< int , int >
#define pll pair< ll , ll >
#define pcs(a) printf("Case %d: ", a)
#define nl puts("")
#define endl '\n'
#define dbg(x) cout<<#x<<" : "<<x<<endl

template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}

int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}

///int mnth[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
///int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
///int kdx[]={2,1,-1,-2,-2,-1,1,2};int kdy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
///int dx[]={-1,+1,0,1,0,-1}; // Hexagonal Direction   **
///int dy[]={-1,+1,1,0,-1,0}; //                       *#*
///                                                     **
const double eps=1e-9;

/*****************************************************************/
/// ////////////////////   GET SET GO    ////////////////////// ///
/*****************************************************************/

#define intx(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(a[k]-a[l])-(a[i]-a[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define inty(i,j,k,l) ((a[i]*b[j]-b[i]*a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]*b[l]-b[k]*a[l]))/((a[i]-a[j])*(b[k]-b[l])-(b[i]-b[j])*(a[k]-a[l]))
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
#define area(i,j,k) ((ll)x[i]*y[j]+(ll)x[j]*y[k]+(ll)x[k]*y[i]-(ll)y[i]*x[j]-(ll)y[j]*x[k]-(ll)y[k]*x[i])

int ts,kk=1;

#define M 100005
#define MD 1000000007LL
#define MX 10005

int a,b,ta,tb;
vector< int >al[2060];
bool vs[2060];

int main()
{
    int t,i,j,k;

    sc2(b,tb);
    sc2(a,ta);
    k=0;
    for(i=300;i<1440;i+=a)
    {
        for(j=1;j<ta-1;j++)al[i+j].pb( k );
        k++;
    }
    scanf(" %d:%d",&j,&k);

    set< int >st;
    j=j*60+k;
    for(i=1;i<tb-1;i++)
    {
        j++;
        for(k=0;k<al[j].size();k++)st.insert( al[j][k] );
    }
    cout<<st.size()<<endl;

    return 0;
}