#C4769. Optimizing Actions Sequence

    ID: 48343 Type: Default 1000ms 256MiB

Optimizing Actions Sequence

Optimizing Actions Sequence

You are given an integer \(n\) and a sequence of \(n\) actions. Each action is one of the following strings: "start", "stop", or "restart".

Your task is to optimize the sequence by applying the following rules in order:

  • If two consecutive actions are both "start", only the first one should be kept.
  • If two consecutive actions are both "stop", only the first one should be kept.
  • If an action "restart" is immediately followed by a "start", remove the "restart" and keep the "start".
  • All other actions will be retained in the order they appear.

Output the optimized sequence as space-separated actions.

inputFormat

The first line contains a single integer \(n\) (\(0 \le n \le 10^5\)) which indicates the number of actions.

The second line contains \(n\) space-separated strings, each being "start", "stop", or "restart". If \(n\) is 0, the second line will be empty.

outputFormat

Output a single line containing the optimized sequence of actions as space-separated words. If there are no actions, output nothing.

## sample
7
start start stop stop restart start stop
start stop start stop