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 MAXN = 500 + 10;
const int MAXE = 1e5;
const int INF = 1e9;
int z[MAXN];
void z_function(string s) {
  int n = (int)s.length();
  for (int i = 1, l = 0, r = 0; i < n; i++) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
    } else {
      z[i] = 0;
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      z[i]++;
    }
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
  }
}
string t[MAXN];
int p[MAXN];
int has[MAXN][MAXN];
struct edge {
  int v, to, cn, cs, f, p;
  edge(int v, int to, int cn, int cs, int f, int p)
      : v(v), to(to), cn(cn), cs(cs), f(f), p(p){};
  edge(){};
};
vector<int> g[MAXN];
edge ee[MAXE];
int cnt;
int d[MAXN];
int phi[MAXE];
int prv[MAXN];
void add_edge(int v, int to, int cn, int cs) {
  ee[cnt] = edge(v, to, cn, cs, 0, cnt + 1);
  g[v].push_back(cnt++);
  ee[cnt] = edge(to, v, 0, -cs, 0, cnt - 1);
  g[to].push_back(cnt++);
}
void max_flow(int sr, int sk, int n) {
  int v, num, to, cs, cn;
  for (int i = 0; i < n; i++) {
    d[i] = INF;
  }
  d[sr] = 0;
  bool was;
  for (int i = 0; i < n; i++) {
    was = 0;
    for (int j = 0; j < cnt; j++) {
      v = ee[j].v, to = ee[j].to;
      cn = ee[j].cn, cs = ee[j].cs;
      if (d[v] < INF) {
        if (cn - ee[j].f > 0) {
          if (d[to] > d[v] + cs) {
            was = 1;
            d[to] = d[v] + cs;
          }
        }
      }
    }
    if (!was) break;
  }
  for (int i = 0; i < n; i++) {
    phi[i] = d[i];
    if (0) cout << "PHI " << i << " " << phi[i] << endl;
  }
  prv[sr] = -1;
  for (;;) {
    for (int i = 0; i < n; i++) d[i] = INF;
    d[sr] = 0;
    set<pair<int, int> > st;
    st.insert(make_pair(0, sr));
    while (!st.empty()) {
      v = st.begin()->second;
      st.erase(st.begin());
      for (int i = 0; i < (int)g[v].size(); i++) {
        num = g[v][i];
        to = ee[num].to;
        cs = ee[num].cs + phi[v] - phi[to];
        cn = ee[num].cn;
        if (cn > ee[num].f && d[to] > d[v] + cs) {
          st.erase(make_pair(d[to], to));
          d[to] = d[v] + cs;
          prv[to] = num;
          st.insert(make_pair(d[to], to));
        }
      }
    }
    if (d[sk] == INF) break;
    int ds = INF;
    v = sk;
    while (prv[v] != -1) {
      num = prv[v];
      ds = min(ds, ee[num].cn - ee[num].f);
      v = ee[num].v;
    }
    v = sk;
    while (prv[v] != -1) {
      num = prv[v];
      ee[num].f += ds;
      ee[ee[num].p].f -= ds;
      v = ee[num].v;
    }
  }
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int m;
  cin >> m;
  int mx = 0;
  for (int i = 0; i < m; i++) {
    cin >> t[i];
    cin >> p[i];
    mx = max(p[i], mx);
    string tt = t[i] + "$" + s;
    z_function(tt);
    for (int j = 0, k = t[i].length() + 1; j < s.length(); j++, k++) {
      if (z[k] == t[i].length()) {
        has[i][j] = 1;
        if (0) cout << "(" << i << " " << j << ") ";
      }
    }
    if (0) cout << endl;
  }
  int x;
  cin >> x;
  int sr = n + 1;
  int sk = n + 2;
  int n2 = sk + 1;
  mx = 0;
  add_edge(sr, 0, x, mx);
  for (int i = 0; i < n; i++) {
    add_edge(i, i + 1, x, mx);
  }
  add_edge(n, sk, x, mx);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (has[j][i]) {
        add_edge(i, i + (int)t[j].length(), 1, mx - p[j]);
      }
    }
  }
  max_flow(sr, sk, n2);
  long long ans = 0;
  for (int i = 0; i < cnt; i++) {
    if (ee[i].f > 0) {
      ans += ee[i].cs - mx;
    }
  }
  cout << -ans;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}