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;
struct edge {
  int a, b, w, c, f;
};
struct edd {
  int a, b, w, n;
  edd(int A, int B, int W, int N) { a = A, b = B, w = W, n = N; }
};
const int MAXN = 510;
vector<int> eds[MAXN];
int was[MAXN];
vector<edge> ed;
int n;
string s;
int m;
string t[MAXN];
pair<int, string> tt[MAXN];
int cs[MAXN];
int go[MAXN];
int dd[MAXN];
int gg[MAXN];
void make_edge(int a, int b, int w, int fl) {
  edge x;
  x.a = a;
  x.b = b;
  x.c = 1;
  x.w = w;
  if (!fl)
    x.f = 0;
  else
    x.f = x.c;
  eds[a].push_back(ed.size());
  ed.push_back(x);
  swap(x.a, x.b);
  x.c = 0;
  x.f = -x.f;
  x.w = -x.w;
  eds[b].push_back(ed.size());
  ed.push_back(x);
}
vector<edd> vv;
int main() {
  long long ans = 0;
  cin >> n;
  cin >> s;
  cin >> m;
  for (int i = 0; i < m; ++i) cin >> tt[i].second >> tt[i].first;
  sort(tt, tt + m);
  reverse(tt, tt + m);
  int x;
  cin >> x;
  for (int j = 0; j < n; ++j) go[j] = x;
  for (int i = 0; i < m; ++i) {
    t[i] = tt[i].second;
    cs[i] = tt[i].first;
    for (int j = 0; j <= (int)(s.size() - t[i].size()); ++j) {
      int fl = 0;
      for (int k = 0; k < (int)t[i].size(); ++k)
        if (s[j + k] != t[i][k]) {
          fl = 1;
          break;
        }
      if (fl) continue;
      for (int k = j; k < j + (int)t[i].size(); ++k)
        if (go[k] == 0) fl = 1;
      if (!fl) {
        for (int k = j; k < j + (int)t[i].size(); ++k) --go[k];
        make_edge(j + t[i].size(), j, -cs[i], 1);
        ans -= cs[i];
      } else {
        make_edge(j + t[i].size(), j, -cs[i], 0);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    edge xx;
    xx.a = i;
    xx.b = i + 1;
    xx.c = x;
    xx.w = 0;
    xx.f = x - go[i];
    eds[i].push_back(ed.size());
    ed.push_back(xx);
    swap(xx.a, xx.b);
    xx.c = 0;
    xx.f = -xx.f;
    eds[i + 1].push_back(ed.size());
    ed.push_back(xx);
  }
  vector<int> way;
  while (true) {
    for (int i = 0; i < n + 1; ++i) dd[i] = 0, gg[i] = -1;
    vv.clear();
    for (int i = 0; i < (int)ed.size(); ++i) {
      if (ed[i].f != ed[i].c) vv.push_back(edd(ed[i].a, ed[i].b, ed[i].w, i));
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < (int)vv.size(); ++j)
        if (dd[vv[j].b] > dd[vv[j].a] + vv[j].w) {
          dd[vv[j].b] = dd[vv[j].a] + vv[j].w;
          gg[vv[j].b] = j;
        }
    }
    int fl = 0;
    fill(was, was + n + 1, -1);
    way.clear();
    for (int j = 0; j < (int)vv.size(); ++j)
      if (dd[vv[j].b] > dd[vv[j].a] + vv[j].w) {
        dd[vv[j].b] = dd[vv[j].a] + vv[j].w;
        gg[vv[j].b] = j;
        int now = vv[j].b;
        fl = 1;
        while (was[now] == -1) {
          was[now] = way.size();
          way.push_back(vv[gg[now]].n);
          now = vv[gg[now]].a;
        }
        for (int i = was[now]; i < (int)way.size(); ++i) {
          int e = way[i];
          ans += ed[e].w;
          ed[e].f += 1;
          ed[e ^ 1].f -= 1;
        }
        break;
      }
    if (!fl) break;
  }
  cout << -ans << "\n";
  return 0;
}