← 返回 amazon 的题目列表From logs, find the most frequent event sequence
类型:online_judge
You are given time-ordered logs. Each log has user_id and event. For each user, build the event stream in chronological order (events may repeat). Define a length-3 event sequence as any consecutive triple (e1,e2,e3).
Count all length-3 sequences generated by all users and output the most frequent sequence and its count. Break ties by lexicographically smallest triple.
Input
First line: integer n
Next n lines: user_id event
Logs are globally time-sorted; ties follow input order.
Output
One line: e1 e2 e3 count
Constraints
1 <= n <= 2e5
user_id and event are whitespace-free strings
Example Input:
7
u1 a
u1 b
u1 c
u1 a
u2 a
u2 b
u2 c
Output:
a b c 2
Example
Input
7
u1 a
u1 b
u1 c
u1 a
u2 a
u2 b
u2 c
Output
a b c 2