A string is said to contain a value that is known as its beauty.
You are given M pairings where the ith pairing is {(ai,bi):ki}. Here, ai and bi are lowercase English letters and ki is a positive integer.
There exists a string S of length L. For the ith pairing, let the number of indices j∈[1,L−1] such that Sj=ai and Sj+1=bi be counti. The beauty of S is the sum of counti∗ki for each i∈[1,M].
You are given a string A of length N consisting of lowercase English letters. A string can be formed from a subsequence of a string by concatenating the characters of the subsequence in order of occurrence. You are required to find the maximum beauty that can be obtained by selecting any strings that can be formed by a subsequence of A.
Input format
Output format
Print a single line containing the maximum beauty that can be obtained from a string formed by a subsequence of A.
Constraints
1≤N≤2⋅1051≤M≤1051≤ki≤106
Sj, ai, bi are lowercase English letters.
The subsequence A1,A2,A5 forms the string abc. The beauty of this string is 15, which is the maximum that can be obtained. Note that this is not the only subsequence that forms a string with the maximum beauty.