cswork / OAOpen practice workspace

UberOA #20

Bus Time

Estimated EasyJudge-ready

Topics (AI-labelled)StringsSimulation

Given the day's departure times and the current time, find how many minutes have passed since the most recent bus that has already departed. A bus departing exactly at the current time does not count as departed; if no bus has departed yet that day, return −1, without wrapping around to the previous day.

This site's standard input/output is stated explicitly.

Input

The first line contains n, followed by n lines of departure times in HH:MM format, and the last line contains the current time. This site uses 0≤n≤100000 and times in 00:00..23:59. The list is given in non-decreasing time order and may contain duplicates.

Output

Output one integer answer.

Example 1

Input:

3
12:30
14:00
19:55
14:30

Output:

30

Example 2

Input:

2
12:30
14:00
14:00

Output:

90

Example 3

Input:

1
00:00
00:00

Output:

-1

Example notes

Example 1: the most recent departure was at 14:00, 30 minutes ago. Example 2: the 14:00 bus does not count as departed yet, so only 12:30 counts, 90 minutes ago. Example 3: the bus at exactly 00:00 does not count as departed, and there is no earlier bus that day, so the output is −1.

Editorial

Loading solution…