Under construction

Still being built. Things may change

2024

Interview

Time limit1sMemory limit1024 MB

Summary
Decide whether a digit string can be built from English digit words, where each word is either a digit or a repeat count for the next word's digit.
Level

Medium5 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

Pierluigi has just opened the million-dollar question on the most famous quiz show. The question is a sequence of NN English words, and each word stands for one of the digits zero through nine. The first offered answer is a sequence of MM digits. An answer makes sense if it can be obtained from the word sequence. In that process, a word either represents a digit, or it gives the number of consecutive times the digit represented by the next word appears.

The example in the picture has all answers making sense. For instance, 2024 makes sense if "Two" represents 2, "Zero" represents 0, "Two" represents 2, and "Four" represents 4. The answer 0044 also makes sense: "Two" says that the digit 0, represented by "Zero", appears twice, and then "Two" says that the digit 4, represented by "Four", appears twice. The answer 24 also makes sense. "Two" represents 2, then "Zero" says that the digit represented by the next word appears zero times, and "Four" represents 4 once. The answer 02024 does not make sense, because a count can only affect the digit represented by the next word, so the digits "02" cannot be repeated twice.

Pierluigi is not sure whether the first offered answer makes sense. Luckily, you are his lifeline.

Input

The first line contains a natural number NN (1≤N≤10001 \le N \le 1000), the number from the problem statement.

The second line contains NN English words, each digit word. Each word is one of "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", and "Nine".

The third line contains a natural number MM (1≤M≤10001 \le M \le 1000), the number from the problem statement.

The fourth line contains an MM-digit number, which may have leading zeros.

Output

If the answer makes sense, print "DA". Otherwise, print "NE".

Examples3

  1. Example 1

    Input
    4
    Two Zero Two Four
    4
    2024
    
    Expected output
    DA
    
  2. Example 2

    Input
    4
    Two Zero Two Four
    5
    02024
    
    Expected output
    NE
    
  3. Example 3

    Input
    5
    One Two Three Four Five
    5
    24445
    
    Expected output
    DA