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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T, class U>
inline void Max(T &a, U b) {
  if (a < b) a = b;
}
template <class T, class U>
inline void Min(T &a, U b) {
  if (a > b) a = b;
}
inline void add(int &a, int b) {
  a += b;
  while (a >= 1000000007) a -= 1000000007;
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = ans * (long long)a % 1000000007;
    a = (long long)a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
char b[505];
const int M = 1000000;
int q[505], h[505], cnt, head[600], d[600], p[600], vis[600];
int cal(int i, int j) {
  return (h[j] - 1LL * h[i] * q[j - i] % 1000000007 + 1000000007) % 1000000007;
}
struct node {
  int v, c, w, _next;
} g[200010];
void add(int a, int b, int c, int w) {
  g[cnt] = {b, c, w, head[a]};
  head[a] = cnt++;
  g[cnt] = {a, 0, -w, head[b]};
  head[b] = cnt++;
}
bool bfs(int s, int t) {
  for (int i = 0; i < t + 1; i++) d[i] = -1000000007, vis[i] = 0;
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; ~i; i = g[i]._next) {
      int j = g[i].v, k = g[i].w;
      if (g[i].c && d[j] < d[u] + k) {
        d[j] = d[u] + k;
        p[j] = i;
        if (!vis[j]) vis[j] = 1, q.push(j);
      }
    }
  }
  return d[t] > -1000000007;
}
int max_flow(int s, int t) {
  int ans = 0;
  while (bfs(s, t)) {
    int first = t, f = 1000000007;
    while (first != s) {
      Min(f, g[p[first]].c), first = g[p[first] ^ 1].v;
    }
    ans += d[t] * f;
    first = t;
    while (first != s) {
      g[p[first]].c -= f, g[p[first] ^ 1].c += f, first = g[p[first] ^ 1].v;
    }
  }
  return ans;
}
int main() {
  int i, j, k = 0, ca = 0, T, K, m = 0, n;
  scanf("%d%s%d", &n, b, &m);
  q[0] = 1;
  for (int i = 0; i < n; i++)
    h[i + 1] = (h[i] * 29LL + b[i]) % 1000000007,
          q[i + 1] = q[i] * 29LL % 1000000007;
  memset(head, -1, sizeof(head));
  int s = 0, t = n + 1;
  for (int i = 0; i < m; i++) {
    scanf("%s%d", b, &k);
    int len = strlen(b);
    long long st = 0;
    for (int j = 0; j < len; j++) st = (st * 29LL + b[j]) % 1000000007;
    for (int j = 0; j < n - len + 1; j++) {
      if (cal(j, j + len) == st) add(j + 1, j + len + 1, 1, k);
    }
  }
  scanf("%d", &k);
  for (int i = 0; i < n + 1; i++) add(i, i + 1, k, 0);
  int ans = max_flow(s, t);
  printf("%d\n", ans);
  return 0;
}