Under construction

Still being built. Things may change

Multithreaded Program

Interview

Time limit2sMemory limit512 MB

Summary
Given per-thread assignment sequences and final variable values, decide whether a valid interleaving exists and, if so, output one execution.
Level

Medium6 of 10

Topics
Greedy, Topological sort
Solved
No attempts yet

Problem

Maurice is debugging a multithreaded program on his old machine. The program has several threads operating on a set of shared variables. Each thread executes its own sequence of assignments in a predefined program order. Each assignment sets one variable to an integer value.

When the program runs, assignments from different threads can execute in any order. The only guarantee is that each thread executes all of its assignments in program order.

For example, suppose the program has three threads with 22, 22, and 11 assignments in their sequences. One valid execution is:

  • thread 11 executes the first assignment in its sequence;
  • thread 22 executes the first assignment in its sequence;
  • thread 22 executes the second assignment in its sequence;
  • thread 11 executes the second assignment in its sequence;
  • thread 33 executes the only assignment in its sequence.

This execution can be described as 1,2,2,1,31, 2, 2, 1, 3, where the numbers give the thread that performs each assignment, in order. Many other valid executions are also possible.

Maurice suspects that his machine is broken and may work incorrectly. He ran the program and recorded the values of all variables at the end.

Find an execution that performs all assignments and leads to the recorded values of all variables, or report that the machine is broken and no such execution exists.

Input

The first line contains a single integer tt, the number of threads (1≤t≤1001 \leq t \leq 100). The threads are numbered from 11 to tt. The following lines describe tt sequences of assignments, one per thread.

The first line of the ii-th description contains an integer lil_i, the length of the sequence of assignments of the ii-th thread (1≤li≤1001 \leq l_i \leq 100). Each of the following lil_i lines contains an assignment in the form <variable>=<value>. The assignments are listed in program order. Variable names consist of up to 1010 lowercase English letters, and values are positive integers not exceeding 10910^9.

The first of the remaining lines contains an integer kk, the number of variables (1≤k≤10 0001 \le k \le 10\,000). Each of the following kk lines contains a variable name and its recorded value, which is a positive integer not exceeding 10910^9. Each variable used in the program is listed exactly once, and each listed variable is used in at least one assignment.

Output

Print Yes if an execution producing the recorded values exists, and No otherwise.

If an execution exists, print a line containing s=l1+l2+⋯+lts = l_1 + l_2 + \dotsb + l_t integers c1,c2,…,csc_1, c_2, \ldots, c_s, describing such an execution (1≤ci≤t1 \le c_i \le t). This specifies that the first assignment is performed by thread c1c_1, the second one by thread c2c_2, and so on. Each thread performs its assignments in program order. After the ss-th assignment, each variable must have the recorded value. The ii-th thread must appear in the description exactly lil_i times.

Examples2

  1. Example 1

    Input
    2
    2
    a=1
    b=2
    2
    b=1
    a=2
    2
    a 1
    b 1
    
    Expected output
    No
    
  2. Example 2

    Input
    3
    5
    start=1
    counter=1111
    counter=10
    counter=3333
    finish=1
    4
    start=2
    counter=20
    counter=10
    finish=2
    3
    start=3
    qwerty=787788
    finish=3
    4
    counter 10
    start 1
    finish 1
    qwerty 787788
    
    Expected output
    Yes
    2 3 3 2 1 1 3 1 1 2 2 1