#K10116. Longest Increasing Timestamp Subsequence

    ID: 23176 Type: Default 1000ms 256MiB

Longest Increasing Timestamp Subsequence

Longest Increasing Timestamp Subsequence

You are given a sequence of timestamps in the format HH:MM:SS. Your task is to determine the length of the longest subsequence (not necessarily contiguous) in which each timestamp is strictly greater than the preceding one.

Formally, given a sequence of timestamps \(t_1, t_2, \dots, t_n\), find the maximum length \(L\) of a subsequence \(t_{i_1}, t_{i_2}, \dots, t_{i_L}\) such that for every \(1 \leq j < L\), the following holds: \[ t_{i_j} < t_{i_{j+1}} \]

Note that the comparison of timestamps is based on their chronological order on the same day. For example, 00:00:00 is considered less than 12:00:00, and so on.

inputFormat

The input is given via stdin and has the following format:

 n
 t1
 t2
 ...
 tn

Here, the first line contains an integer n — the number of timestamps. The following n lines each contain a timestamp string in the format HH:MM:SS.

outputFormat

Output the length of the longest strictly increasing subsequence of timestamps to stdout.

 L

Where L is the length of the longest subsequence.

## sample
5
12:05:30
12:05:31
12:05:32
12:05:30
12:05:33
4

</p>