← Home
```go
package main

import (
	"fmt"
)

func main() {
	var a, ta int
	var b, tb int
	var timeStr string

	fmt.Scan(&a, &ta)
	fmt.Scan(&b, &tb)
	fmt.Scan(&timeStr)

	var h, m int
	fmt.Sscanf(timeStr, "%d:%d", &h, &m)

	simionStart := h*60 + m
	simionEnd := simionStart + ta

	busStart := 5 * 60        // 05:00 AM in minutes
	busEndLimit := 23*60 + 59 // 11:59 PM in minutes

	count := 0

	// Iterate through all buses departing from city B
	for depB := busStart; depB <= busEndLimit; depB += b {
		arrA := depB + tb

		// Check if the bus from B overlaps with Simion's journey on the road
		// 1. The bus from B must arrive at A after Simion has left A (arrA > simionStart)
		//    If arrA <= simionStart, the bus arrived before or exactly when Simion left (missed or met at start).
		// 2. The bus from B must depart B before Simion arrives at B (depB < simionEnd)
		//    If depB >= simionEnd, the bus leaves after or exactly when Simion arrives (missed or met at finish).
		if arrA > simionStart && depB < simionEnd {
			count++
		}
	}

	fmt.Println(count)
}
```