#C5475. String Query Operations

    ID: 49128 Type: Default 1000ms 256MiB

String Query Operations

String Query Operations

You are given an initially empty string S and will be asked to perform a series of queries on it. The queries are of three types:

  • 1 c: Append character c to the end of S.
  • 2: Remove the last character of S (if S is not empty).
  • 3 k: Print the k-th character of S (1-indexed). If k is out of bounds, print -1.

In mathematical notation, for a query of type 3, if \(1 \leq k \leq |S|\), output \(S[k]\); otherwise, output \(-1\). Process each query sequentially and output the result for each type 3 query in the order they occur.

inputFormat

The first line contains an integer \(Q\) --- the number of queries. Each of the next \(Q\) lines contains one query in one of the following formats:

  • 1 c: Append character c to the string.
  • 2: Remove the last character from the string (if any).
  • 3 k: Print the k-th character of the string (1-indexed) or print -1 if it does not exist.

outputFormat

For each type 3 query, output the result on a separate line. There is no output for type 1 and type 2 queries.

## sample
5
1 a
1 b
1 c
3 2
2
b

</p>