Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 1777
Data, Data, Everywhere

Time Limit: 5 Seconds      Memory Limit: 32768 KB

You've been asked to make a simple text-based database that can store any number of fields associated with records. IDs can contain letters, numbers, dashes (-), and slashes (/), and are case-sensitive. The standard data format for input and output is:

record-id
field-id
some data here
terminated with
a single period
.

There are NO blank lines between entries.

Some commands have lists of record IDs or field IDs. These are comma-separated lists of IDs (no spaces) that specify the order of the output. * can be specified instead of a list of IDs. If * is specified for the record IDs, treat it as a comma-separated lexicographically sorted list of all the record IDs with at least one field in the database. If * is specified for the field IDs, treat it as a comma-separated lexicographically sorted list of all the field IDs defined by at least one record in the database.

The list of commands and their parameters follows:

Command Description
show <record-list> <field-list> For the specified records, display the values of the specified fields. This command takes two parameters, a list of record IDs and a list of field names. Both are comma-separated lists (no spaces) which specify which entries to display and in what order to display them. Output should follow the standard entry format and should be terminated by a line containing a single asterisk.

If a record does not have data for a field, then display the following entry for that record:

record-id
field-name
NO DATA
.

rem <text> The program should ignore the text.
append <record-list> <field-list> Read in text and add it to the end of the specified entry, creating the entry if necessary. Input is terminated with a single period.

delete <record-list> <field-list> For the specified records, delete the values of the specified fields. This command takes two parameters, a list of record IDs and a list of field names.
done Stop processing this list of commands.


Input

Read commands from the input, one command per line. There will be at most 50,000 lines in the input (including any read files), a mix of commands and data. IDs will be at most 64 characters long. There will be at most 10,000 field IDs and 10,000 record IDs defined at any given time, although more may be defined after the old IDs have been deleted. Each line will be at most 255 characters long. Record field data will be at most 2,000 lines long.


Output


Only the show command produces output. Print the output in the standard data format to the standard output stream.

The program should finish the given input within 60 seconds.


Sample Input

append team-bar prob-b
1400 Accepted.
.
append team-foo prob-a
1305 Wrong answer.
.
show team-foo,team-bar *
append team-foo prob-a
1402 Accepted.
.
rem Hmm...
delete team-bar *
.
show * *
done


Sample Output

team-foo
prob-a
1305 Wrong answer.
.
team-foo
prob-b
NO DATA
.
team-bar
prob-a
NO DATA
.
team-bar
prob-b
1400 Accepted.
.
*
team-foo
prob-a
1305 Wrong answer.
1402 Accepted.
.
*


Source: Asia 2003, Manila (Philippine)
Submit    Status