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;
const int N = 5555, maxm = 1000000, L = 131071, inf = 0x3f000000;
int n, m, K;
int head[N], adj[maxm], f[maxm], c[maxm], next_[maxm], tol = 1;
int q[L + 1], qh, qt, d[N], cost;
bool inq[N], vis[N];
int S, T, dn;
inline void addedge(int u, int v, int flow, int cost) {
  tol++;
  adj[tol] = v;
  f[tol] = flow;
  c[tol] = cost;
  next_[tol] = head[u];
  head[u] = tol;
  tol++;
  adj[tol] = u;
  f[tol] = 0;
  c[tol] = -cost;
  next_[tol] = head[v];
  head[v] = tol;
}
bool spfa() {
  memset(d, -20, dn + 1 << 2);
  d[S] = 0, q[qh = 0, qt = 1] = S;
  for (int u, v, i; qh != qt;) {
    u = q[qh = qh + 1 & L];
    inq[u] = 0;
    for (i = head[u]; i; i = next_[i])
      if (f[i] > 0 && d[v = adj[i]] < d[u] + c[i]) {
        d[v] = d[u] + c[i];
        if (!inq[v]) {
          inq[v] = 1;
          q[qt = qt + 1 & L] = v;
        }
      }
  }
  return d[T] > 0;
}
int aug(int u, int flow) {
  if (u == T) {
    cost += flow * d[T];
    return flow;
  }
  vis[u] = 1;
  int left = flow;
  for (int v, t, i = head[u]; i && left; i = next_[i])
    if (!vis[v = adj[i]] && f[i] > 0 && d[v] == d[u] + c[i]) {
      t = aug(v, min(f[i], left));
      left -= t;
      f[i] -= t, f[i ^ 1] += t;
    }
  return flow - left;
}
void solve() {
  int mf = 0;
  while (spfa()) {
    memset(vis, 0, dn + 1);
    mf += aug(S, inf);
  }
}
char s[N], str[N];
void init() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  S = n + 2;
  T = n + 1;
  dn = n + 2;
  for (int i = 1; i <= n; i++) addedge(i, i + 1, inf, 0);
  scanf("%d", &m);
  for (int i = 1, p; i <= m; i++) {
    scanf("%s %d", str, &p);
    int l = strlen(str);
    for (int j = 1; j + l - 1 <= n; j++) {
      int flag = 1;
      for (int k = 0; k < l && flag; k++) flag &= str[k] == s[j + k];
      if (flag) addedge(j, j + l, 1, p);
    }
  }
  scanf("%d", &K);
  addedge(S, 1, K, 0);
}
int main() {
  init();
  solve();
  printf("%d\n", cost);
  return 0;
}