Problem: You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz and P’pairus, who decided to accompany you and give you some puzzles for seemingly unknown reasons.

One day, Sanz has created a crossword for you. Not any kind of crossword, but a 1D crossword! You are given m words and a string of length n. You are also given an array p, which designates how much each word is worth — the i-th word is worth pi points. Whenever you find one of the m words in the string, you are given the corresponding number of points. Each position in the crossword can be used at most x times. A certain word can be counted at different places, but you cannot count the same appearance of a word multiple times. If a word is a substring of another word, you can count them both (presuming you haven’t used the positions more than x times).

In order to solve the puzzle, you need to tell Sanz what’s the maximum achievable number of points in the crossword. There is no need to cover all postions, just get the maximal score! Crossword and words contain only lowercase English letters.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the length of the crossword. The second line contains the crossword string. The third line contains a single integer m (1 ≤ m ≤ 100) — the number of given words, and next m lines contain description of words: each line will have a string representing a non-empty word (its length doesn't exceed the length of the crossword) and integer pi (0 ≤ pi ≤ 100). Last line of the input will contain x (1 ≤ x ≤ 100) — maximum number of times a position in crossword can be used.

Output

Output single integer — maximum number of points you can get.

Example

Input

6
abacba
2
aba 6
ba 3
3


Output

12

Note

For example, with the string "abacba", words "aba" (6 points) and "ba" (3 points), and x = 3, you can get at most 12 points - the word "aba" appears once ("abacba"), while "ba" appears two times ("abacba"). Note that for x = 1, you could get at most 9 points, since you wouldn’t be able to count both "aba" and the first appearance of "ba".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m;
char S[555], ch[555][555];
int X[555], V[555];
int Head[400010], Next[400010], Go[400010], Fl[400010], Cost[400010], H[400010],
    Cnt = 1;
void addedge(int x, int y, int z, int w) {
  Go[++Cnt] = y;
  Next[Cnt] = Head[x];
  Head[x] = Cnt;
  Fl[Cnt] = z;
  Cost[Cnt] = w;
  Go[++Cnt] = x;
  Next[Cnt] = Head[y];
  Head[y] = Cnt;
  Fl[Cnt] = 0;
  Cost[Cnt] = -w;
}
void cmin(int &x, int y) {
  if (x > y) x = y;
}
void precalc() {
  static int Deg[400010];
  for (int i = 1; i <= n + 3; i++)
    for (int T = Head[i]; T; T = Next[T])
      if (Fl[T]) Deg[Go[T]]++;
  memset(H, 63, sizeof H);
  H[n + 2] = 0;
  vector<int> V(1, n + 2);
  for (int i = 0; i < V.size(); i++) {
    int x = V[i];
    for (int T = Head[x]; T; T = Next[T])
      if (Fl[T]) {
        cmin(H[Go[T]], H[x] + Cost[T]);
        if (!--Deg[Go[T]]) V.push_back(Go[T]);
      }
  }
}
int Dis[555], vis[555], FF[555], Pr[555];
void Dij() {
  memset(Dis, 63, sizeof Dis);
  memset(vis, 0, sizeof vis);
  memset(FF, 0, sizeof FF);
  Dis[n + 2] = 0;
  FF[n + 2] = 1000000000;
  for (int o = 1; o <= n + 3; o++) {
    int mn = 1e9, x;
    for (int i = 1; i <= n + 3; i++)
      if (!vis[i] && mn > Dis[i]) mn = Dis[i], x = i;
    vis[x] = 1;
    for (int T = Head[x]; T; T = Next[T])
      if (Fl[T]) {
        int v = Cost[T] + H[x] - H[Go[T]];
        if (Dis[Go[T]] > Dis[x] + v) {
          Dis[Go[T]] = Dis[x] + v;
          Pr[Go[T]] = T ^ 1;
          FF[Go[T]] = min(FF[x], Fl[T]);
        }
      }
  }
}
int inst[555];
int multiaug(int x, int fl) {
  inst[x] = 1;
  if (x == n + 3) {
    inst[x] = 0;
    return fl;
  }
  int tot = 0;
  for (int T = Head[x]; T; T = Next[T])
    if (Fl[T] && !inst[Go[T]]) {
      int v = Cost[T] + H[x] - H[Go[T]];
      if (Dis[Go[T]] == Dis[x] + v) {
        int v = multiaug(Go[T], min(fl, Fl[T]));
        Fl[T] -= v;
        Fl[T ^ 1] += v;
        if ((tot += v) == fl) break;
        if (v) break;
      }
    }
  inst[x] = 0;
  return tot;
}
int Flow() {
  precalc();
  int ans = 0;
  for (;;) {
    Dij();
    if (Dis[n + 3] >= 1000000000) return ans;
    ans += multiaug(n + 2, 1000000000) * (Dis[n + 3] + H[n + 3]);
    for (int i = 1; i <= n + 3; i++) H[i] += Dis[i];
  }
}
int main() {
  scanf("%d", &n);
  scanf("%s", S + 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", ch[i] + 1);
    scanf("%d", &V[i]);
    int s = strlen(ch[i] + 1);
    for (int j = 1; j + s - 1 <= n; j++) {
      int flag = 1;
      for (int k = 1; k <= s; k++)
        if (S[j + k - 1] != ch[i][k]) {
          flag = 0;
          break;
        }
      if (flag == 1) {
        addedge(j, j + s, 1, -V[i]);
      }
    }
  }
  scanf("%d", &X[1]);
  for (int i = 2; i <= n; i++) X[i] = X[i - 1];
  for (int i = 1; i <= n + 1; i++)
    if (X[i] > X[i - 1])
      addedge(n + 2, i, X[i] - X[i - 1], 0);
    else if (X[i] < X[i - 1])
      addedge(i, n + 3, X[i - 1] - X[i], 0);
  for (int i = 1; i <= n; i++) addedge(i, i + 1, X[i], 0);
  printf("%d\n", -Flow());
  return 0;
}