Under construction

Still being built. Things may change

Kagisys

Interview

Time limit2sMemory limit512 MB

Summary
Simulate a door lock: for each scanned card ID, print whether it opens, closes, or is unknown, toggling the door state on known IDs.
Level

Easy3 of 10

Topics
Hash map, Simulation, Implementation, String
Solved
No attempts yet

Problem

A room uses an electronic lock system that opens and closes a door with IC cards. The system works as follows.

When a user holds their IC card over the door, the ID of that IC card is passed to the system. If the ID is registered, the system unlocks the door when it is locked and locks it otherwise, printing a message in each case. If the ID is not registered, the system prints a message saying it is not registered, and neither unlocks nor locks the door.

Currently, N IDs (U1, U2, ..., UN) are registered in the system, and the door is locked. An IC card is held over the door M times, and the IDs are T1, T2, ..., TM in that order. Determine what messages the system prints.

Input

The input is given in the following format.

N
U1
U2
……
UN
M
T1
T2
……
TM

Output

For each of T1, T2, ..., TM, print on one line:

  • "Opened by " followed by the ID when the door is unlocked,

  • "Closed by " followed by the ID when the door is locked,

  • "Unknown " followed by the ID when the ID is not registered.

The door is locked in the initial state.

Constraints

  • N and M are integers

  • 1 ≤ N ≤ 256

  • Ui is a string of 1 to 10 lowercase English letters

  • Ui are unique (Ui ≠ Uj if i ≠ j)

  • 1 ≤ M ≤ 256

  • Ti is a string of 1 to 10 lowercase English letters

Examples3

  1. Example 1

    Input
    4
    abcd
    efgh
    ijkl
    mnop
    5
    abcd
    abcc
    efgh
    abcd
    mnop
    
    Expected output
    Opened by abcd
    Unknown abcc
    Closed by efgh
    Opened by abcd
    Closed by mnop
    
  2. Example 2

    Input
    2
    a
    abcdefghij
    9
    c
    bcdefghijk
    abcdefghij
    b
    a
    b
    a
    bcdefghijk
    c
    
    Expected output
    Unknown c
    Unknown bcdefghijk
    Opened by abcdefghij
    Unknown b
    Closed by a
    Unknown b
    Opened by a
    Unknown bcdefghijk
    Unknown c
    
  3. Example 3

    Input
    2
    z
    x
    2
    z
    x
    
    Expected output
    Opened by z
    Closed by x