Under construction

Still being built. Things may change

Mock Grading

Time limit8sMemory limit1024 MB

Summary
Find the first question after which the summed bonuses of remembered strings matching the read answer suffix reach A, or report Fail.
Level

Medium7 of 10

Topics
String matching, Trie, Prefix sum, Binary search
Solved
No attempts yet

Statement

The POSTECH multiple-choice exam has NN questions, and each question has 26 choices labeled with the uppercase letters A through Z. Writing the correct letters in order from question 1 to question NN gives the answer string SS of length NN.

MM students took the exam and submitted answers to every question. They do not remember every answer they submitted. Student ii remembers LiL_i consecutive answers, and writing them in order gives the string TiT_i.

After the exam, students compare their remembered strings TiT_i with the published answer string SS to grade themselves. The letters of SS are read one by one from the front, and the confidence of the students rises by the following rules.

  1. Every student starts with confidence 0.
  2. If the last LiL_i correct letters read so far match TiT_i in order, the confidence of student ii rises by a positive integer BiB_i. In other words, the suffix of length LiL_i of the string read so far must match TiT_i in order.
  3. While fewer than LiL_i correct letters have been read, the confidence of student ii neither rises nor falls. Increases are independent of each other. So TiT_i triggers a rise whenever the most recent LiL_i letters match it, regardless of whether TiT_i also appears earlier in SS or matches some other TjT_j.

When the confidence of any of the MM students reaches AA or more, the self-grading is considered valid. Find the number of the question after which a student first has confidence AA or more.

Input

The first line contains NN, the number of questions in this year's quiz, MM, the number of students who took the exam, and the integer AA. (1≤N≤10000001 \leq N \leq 1000000, 1≤M≤1000001 \leq M \leq 100000, 1≤A≤10151 \leq A \leq 10^{15})

The next line contains the answer string SS of this year's exam. SS consists only of uppercase letters.

Each of the next MM lines contains LiL_i, BiB_i, and TiT_i, separated by spaces. (1≤Li≤N1 \leq L_i \leq N, 1≤Bi≤1091 \leq B_i \leq 10^9) TiT_i consists only of uppercase letters. The sum of all LiL_i is at most 1000000. Different students may have the same TiT_i.

Output

Print the number of the question at which the confidence of some student first reaches AA or more. If no student reaches AA or more after all NN answers are read, print Fail.

Examples2

  1. Example 1

    Input
    17 2 13
    COCOCOCOCOCOCOCOA
    4 3 COCO
    3 2 OCO
    
    Expected output
    12
    
  2. Example 2

    Input
    13 2 100
    FAILEDTHEEXAM
    13 998244353 SLEEPEVERYDAY
    9 100000007 IDONTCARE
    
    Expected output
    Fail