Mirror IIOT 2022-2023, Final Round | ssr

This was the problem page during the contest. Access the current page here.
Time limit: 0.75s
Memory limit: 256MB
Input:
Output:

Task

El Bandito Inofensivo gives a set of words SS and a stack, you are asked to perform the following operations:

  • operation of type 00: add the character cc on top of the stack
  • operation of type 11: pop the character from the top of the stack
  • operation of type 22: insert the word WW in SS
  • operation of type 33: erase the word WW from SS

We say that a word SS of length NN is on top of the stack if the suffix (we see the stack as a string, where the last element of the string is the top of the stack) of length NN of the stack is equal to the string SS.
If there is a word from the set SS at the top of the stack, it is removed instantly.

Initially, both the stack and the set of words are empty. You are given QQ operations of the types above and you are asked to print the character on top of the stack after each of the QQ operations. The character on top of the empty stack is considered to be the character ?'?'.

Input

First line of the input contains the number QQ (1Q1.51051 \le Q \le 1.5 * 10^5). The next QQ lines describe the QQ operations. Each of the lines contain a number opop, representing the type of operation we have to perform:

  • op=0op = 0, then the line also contains the character cc. This line describes an operation of type 00.
  • if op=1op = 1, the line describes an operation on type 11. This operation will never show up when the stack is empty.
  • if op=2op = 2, then the line also contains the string WW. This line describes an operation of type 22.
  • if op=3op = 3, then the line also contains the string WW. This line describes an operation of type 33. This operation will never involve a word which is not in SS.

For tests worth 1313 points, 1Q1001 \le Q \le 100.

For tests worth 3838 more points, there is no operation of type 11 and all the operations of type 00 are performed after all the operations of type 22 and 33.

The sum of lengths of all words inserted in SS is at most 10510^5.

The number of operations of type 00 is at most 10510^5.

It is guaranteed that, at any moment of time, SS does not contain two words such that one is a suffix of the other.

Output

The only line of the output will contain a string SS of length QQ, where the ithi-th character from SS represents the character on top of the stack after the ithi-th operation. If after the ithi-th operation the stack is empty, then the ithi-th character in SS will be the character ?'?'.

Example 1

stdin

10
0 a
0 b
2 bbd
0 b
0 b
1
2 ab
0 d
3 ab
0 b

stdout

abbbbbbaab

Explanation

The evolution of the stack and the set of string after each operation:

After step 11: "a""a"

After step 22: "ab""ab"

After step 33: "ab""ab", ["bbd"]["bbd"]

After step 44: "abb""abb", ["bbd"]["bbd"]

After step 55: "abbb""abbb", ["bbd"]["bbd"]

After step 66: "abb""abb", ["bbd"]["bbd"]

After step 77: "abb""abb", ["bbd","ab"]["bbd", "ab"]

After step 88: "abbd""abbd" -> "a""a", ["bbd","ab"]["bbd", "ab"]

After step 99: "a""a", ["bbd"]["bbd"]

After step 1010: "ab""ab", ["bbd"]["bbd"]

Contest info

Official contest

Start time: 1677902400000

Total duration: 209h59m0s

Status: Ended

Individual duration: 3h0m0s

Log in or sign up to be able to send submissions!