Under construction

Still being built. Things may change

Spilled Ink

Time limit1sMemory limit512 MB

Summary
Given a string with hidden letters (#) and its Z-array, restore a string that matches both, or report that no such string exists.
Level

Medium7 of 10

Topics
String, Union-find, String matching
Solved
No attempts yet

문제

Didi defines ZiZ_i for a string SS of uppercase letters (A-Z) as the length of the longest common prefix of S[1∼N]S[1 \sim N] and the suffix S[i∼N]S[i \sim N] of SS. Didi built the array ZZ from these values using an algorithm found after long study. While dancing with joy, Didi spilled ink on part of the string SS, so Didi cannot check whether the array ZZ is correct.

The kind ryute wants to help the desperate Didi. Using the partially hidden string S′S' and the array ZZ that Didi wrote, ryute will restore the original string SS. ryute will also check whether Didi's array ZZ is correct. If at least one possible original string SS exists, the array ZZ is considered correct. Otherwise, it is considered incorrect. Help ryute and Didi.

입력

The first line contains the length NN of the string SS (1≤N≤1051 \le N \le 10^5).

The second line contains the string S′S'. S′S' consists of uppercase letters (A-Z) and #. A # means the letter at that position is hidden by ink. There are at most 20 # characters.

The third line contains the elements ZiZ_i (0≤Zi≤N−i+10 \le Z_i \le N-i+1) of the array ZZ that Didi wrote, separated by spaces, in order.

출력

If the array ZZ that Didi wrote is incorrect, print THINKINGFACE. Otherwise, print YES on the first line and the original string SS on the second line. If several strings are possible for SS, print any one of them.

Examples3

  1. Example 1

    Input
    7
    ABAB#CD
    7 0 3 0 1 0 0
    
    Expected output
    YES
    ABABACD
    
  2. Example 2

    Input
    7
    ABAB#CD
    7 0 3 0 0 0 0
    
    Expected output
    THINKINGFACE
    
  3. Example 3

    Input
    27
    #ABCDEFGHIJKLMNOPQRSTUVWXYZ
    27 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    
    Expected output
    THINKINGFACE