#K76712. Train Coach Reservation Management

    ID: 34704 Type: Default 1000ms 256MiB

Train Coach Reservation Management

Train Coach Reservation Management

You are given a train coach consisting of n rows. Each row has two seats: one on the left and one on the right. Initially, all seats are unreserved.

You will receive m reservation requests. Each reservation request is specified by a row number and a seat selection which can be one of the following strings: left, right, or both. The rules for handling requests are as follows:

  • If the request is for left, reserve the left seat of that row if it is not already reserved. Otherwise, the request fails.
  • If the request is for right, reserve the right seat of that row if it is not already reserved. Otherwise, the request fails.
  • If the request is for both, reserve both left and right seats of that row only if both seats are free. Otherwise, the request fails.

Process the requests in the order they are given. For each request, print Success if the reservation is completed, or Failure otherwise.

The condition for a successful reservation for a 'both' request can be mathematically represented in \(\LaTeX\) as:

\[ \text{Success if } (L_i = 0 \text{ and } R_i = 0) \quad \text{, else Failure} \]

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains two space-separated integers n and m, where n is the number of rows in the train coach and m is the number of reservation requests.
  2. Each of the next m lines contains an integer and a string separated by a space. The integer represents the row number (1-indexed) and the string represents the seat request (either "left", "right", or "both").

outputFormat

The output is written to standard output (stdout) and consists of m lines. Each line contains either Success or Failure corresponding to the outcome of each reservation request in order.

## sample
5 6
1 left
1 right
2 both
1 both
3 right
5 left
Success

Success Success Failure Success Success

</p>