There is a secret string of length , consisting of lowercase English letters. However, the full string is unknown to you.
Instead, you are provided with hints of the string. Each hint contains information about a partial piece of the string:
- An integer : the starting position (-based index) of the piece.
- An integer : the length of the piece.
- A substring of length : the partial piece.
Each hint indicates that the string , or its reversed version, appears at position in the secret string.
Your task is to determine whether there exists a string of length that is consistent with all the given hints
If such a string exists, output any valid string. Otherwise, report that the hints are inconsistent.
Input data
The first line of the input contains two integers and - the length of the unknown string and the number of hints, respectively.
Each of the next lines contains the integers and , and the string of length , describing a hint.
No pair of hints correspond to the exact same substring of the hidden string, that is for all , either or .
Output data
Print NO
in a single line if there is no string that satisfies the given conditions. Otherwise, print YES
on the first line, followed by one such valid string on the next line.
Constraints and clarifications
- .
- .
- , and for each .
- or for all .
- for each .
- Each consists of lowercase English letters.
# | Score | Restrictions |
---|---|---|
0 | 0 | Examples |
1 | 10 | Each partial piece is palindromic. That is, for all , , for all . |
2 | 10 | , . |
3 | 10 | Each piece overlays at most other piece. |
4 | 20 | For all , there exists at most one such that and . |
5 | 20 | , . |
6 | 30 | No additional limitations. |
Example 1
stdin
11 5
0 2 ii
7 4 yrag
1 3 toi
6 4 ngar
3 4 thun
stdout
YES
iiothungary
Example 2
stdin
7 3
0 5 cabac
1 3 aba
4 3 dbd
stdout
NO