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;
uint64_t rnd_data = 0xDEADBEEFDULL;
inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; }
inline int my_rand() {
  rnd_data = rnd_data * 0x5DEECE66DULL + 0xB;
  return (rnd_data >> 17) & 0x7FFFFFFF;
}
template <class _T>
inline _T sqr(const _T &x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-11;
const int INF = 0x3f3f3f3f;
struct te {
  int v1, v2;
  int a, f;
  int c;
};
int n, m, k;
char s[1024];
char a[1024][1024];
int b[1024];
int c[1024];
int d[1024];
int pa[1024];
te e[202400];
void add_edge(int v1, int v2, int w, int c) {
  e[k++] = {v1, v2, w, 0, c};
  e[k++] = {v2, v1, 0, 0, -c};
}
int find(int st, int en) {
  memset(d, 0x3f, sizeof(d));
  d[st] = 0;
  for (int tt = 0; tt < (int)(n + 1); tt++) {
    bool bb = true;
    for (int i = 0; i < (int)(k); i++) {
      int v1 = e[i].v1;
      int v2 = e[i].v2;
      if (d[v1] >= INF || e[i].f >= e[i].a) continue;
      if (d[v2] > d[v1] + e[i].c) {
        d[v2] = d[v1] + e[i].c;
        pa[v2] = i;
        bb = false;
      }
    }
    if (bb) break;
  }
  return d[en];
}
long long flow(int st, int en, int x) {
  long long ans = 0;
  for (int tt = 0; tt < (int)(x); tt++) {
    int j = find(st, en);
    if (j >= 0) break;
    int k = en;
    while (k != st) {
      int ee = pa[k];
      ans += e[ee].c;
      e[ee].f++;
      e[ee ^ 1].f--;
      k = e[ee].v1;
    }
  }
  return ans;
}
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  k = 0;
  scanf("%d", &n);
  scanf("%s", s);
  scanf("%d", &m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%s%d", a[i], &c[i]);
    b[i] = strlen(a[i]);
    for (int j = 0; j < (int)(n - b[i] + 1); j++) {
      if (!strncmp(s + j, a[i], b[i])) add_edge(j, j + b[i], 1, -c[i]);
    }
  }
  int x;
  scanf("%d", &x);
  for (int i = 0; i < (int)(n); i++) {
    add_edge(i, i + 1, x, 0);
  }
  long long ans = -flow(0, n, x);
  printf("%lld\n", ans);
  return 0;
}