Text Pieces

Time limit: 0.5s Memory limit: 512MB Input: Output:

There is a secret string of length NN, consisting of lowercase English letters. However, the full string is unknown to you.

Instead, you are provided with QQ hints of the string. Each hint contains information about a partial piece of the string:

  • An integer BiB_i: the starting position (00-based index) of the piece.
  • An integer KiK_i: the length of the piece.
  • A substring SiS_i of length KiK_i: the partial piece.

Each hint indicates that the string SiS_i, or its reversed version, appears at position BiB_i in the secret string.

Your task is to determine whether there exists a string of length NN 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 NN and QQ - the length of the unknown string and the number of hints, respectively.

Each of the next QQ lines contains the integers BiB_i and KiK_i, and the string SiS_i of length KiK_i, describing a hint.
No pair of hints correspond to the exact same substring of the hidden string, that is for all iji \ne j, either BiBjB_i \ne B_j or KiKjK_i \ne K_j.

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

  • 1N20 0001 \le N \le 20 \ 000.
  • 1Q20 0001 \le Q \le 20 \ 000.
  • 0BiN10 \le B_i \le N-1, and Bi+KiNB_i + K_i \le N for each i=0,,Q1i=0,\ldots,Q-1.
  • BiBjB_i \ne B_j or KiKjK_i \ne K_j for all iji \ne j.
  • 1Ki1501 \le K_i \le 150 for each i=0,,Q1i=0,\ldots,Q-1.
  • Each KiK_i consists of lowercase English letters.
# Score Restrictions
0 0 Examples
1 10 Each partial piece is palindromic. That is, for all i=0Q1i = 0 \ldots Q-1, Si,j=Si,Kij1S_{i,j} = S_{i,K_i - j - 1}, for all j=0Ki1j = 0 \ldots K_i-1.
2 10 N,Q15N, Q \leq 15, Ki10K_i \leq 10.
3 10 Each piece overlays at most 11 other piece.
4 20 For all i=0Q1i = 0 \ldots Q-1, there exists at most one jj such that iji \ne j and BiBjBi+Ki1B_i \leq B_j \leq B_i + K_i - 1.
5 20 N,Q10 000N, Q \leq 10 \ 000, Ki100K_i \leq 100.
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

Log in or sign up to be able to send submissions!