Codeforces Round 123 (Div. 2)
C
Try and Catch
Codeforces
1800
原题
← BD →
翻译中…

Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.

翻译中…

The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks:

翻译中…
  1. The try operator. It opens a new try-catch-block.
  2. The catch(<exception_type>, <message>) operator. It closes the try-catch-block that was started last and haven't yet been closed. This block can be activated only via exception of type . When we activate this block, the screen displays the . If at the given moment there is no open try-catch-block, then we can't use the catch operator.
翻译中…

The exceptions can occur in the program in only one case: when we use the throw operator. The throw(<exception_type>) operator creates the exception of the given type.

翻译中…

Let's suggest that as a result of using some throw operator the program created an exception of type $*a*$. In this case a try-catch-block is activated, such that this block's try operator was described in the program earlier than the used throw operator. Also, this block's catch operator was given an exception type $*a*$ as a parameter and this block's catch operator is described later that the used throw operator. If there are several such try-catch-blocks, then the system activates the block whose catch operator occurs earlier than others. If no try-catch-block was activated, then the screen displays message "Unhandled Exception".

翻译中…

To test the system, Vasya wrote a program that contains only try, catch and throw operators, one line contains no more than one operator, the whole program contains exactly one throw operator.

翻译中…

Your task is: given a program in VPL, determine, what message will be displayed on the screen.

翻译中…

Input

翻译中…

The first line contains a single integer: $*n*$ $(1 ≤ *n* ≤ 10^{5})$ the number of lines in the program. Next $*n*$ lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces.

翻译中…

The program contains only operators try, catch and throw. It is guaranteed that the program is correct. It means that each started try-catch-block was closed, the catch operators aren't used unless there is an open try-catch-block. The program has exactly one throw operator. The program may have spaces at the beginning of a line, at the end of a line, before and after a bracket, a comma or a quote mark.

翻译中…

The exception type is a nonempty string, that consists only of upper and lower case english letters. The length of the string does not exceed 20 symbols. Message is a nonempty string, that consists only of upper and lower case english letters, digits and spaces. Message is surrounded with quote marks. Quote marks shouldn't be printed. The length of the string does not exceed 20 symbols.

翻译中…

Length of any line in the input file does not exceed 50 symbols.

翻译中…

Output

翻译中…

Print the message the screen will show after the given program is executed.

翻译中…

Note

翻译中…

In the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(AE,"AE somewhere") has exception type AE as parameter and operator catch(BE,"BE in line 3") has exception type BE.

翻译中…

In the second sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(AE,"AE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so both blocks can be activated, but only the first one will be activated, because operator catch(AE,"AE in line 3") is described earlier than catch(AE,"AE somewhere")

翻译中…

In the third sample there is no blocks that can be activated by an exception of type CE.

翻译中…

样例

Input #1
8
try
    try
        throw ( AE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")
Output #1
AE somewhere
InputCopy OutputCopy
Input #2
8
try
    try
        throw ( AE )
    catch ( AE, "AE in line 3")

    try
    catch(BE, "BE in line 5")
catch(AE,"AE somewhere")
Output #2
AE in line 3
InputCopy OutputCopy
Input #3
8
try
    try
        throw ( CE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")
Output #3
Unhandled Exception
InputCopy OutputCopy
题目信息
题号
195C
时间限制
2 s
内存限制
256 MB
标签
表达式解析
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。