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;
using ll = long long;
using pli = pair<long long, int>;
using pii = pair<int, int>;
const int N = 500 + 7, M = 107, N2 = 1e3 + 7;
const ll mod = 1e9 + 5, base1 = 311, base2 = 331;
int n, m, x;
string s, w[N];
int p[N], dp[N], res;
int Max[N];
ll power1[N], power2[N];
ll hashs1[N], hashs2[N];
ll hashw1[M], hashw2[M];
bool _check(int r, int j) {
  int l = r - w[j].size() + 1;
  return l >= 1 &&
         hashw1[j] ==
             (hashs1[r] - hashs1[l - 1] * power1[r - l + 1] + mod * mod) %
                 mod &&
         hashw2[j] ==
             (hashs2[r] - hashs2[l - 1] * power2[r - l + 1] + mod * mod) % mod;
}
void _hashcal() {
  power1[0] = power2[0] = 1;
  for (int i = 1; i <= n; ++i) {
    power1[i] = power1[i - 1] * base1 % mod;
    power2[i] = power2[i - 1] * base2 % mod;
  }
  for (int i = 1; i <= n; ++i) {
    hashs1[i] = (hashs1[i - 1] * base1 + s[i]) % mod;
    hashs2[i] = (hashs2[i - 1] * base2 + s[i]) % mod;
  }
  for (int i = 1; i <= m; ++i) {
    int l = w[i].size();
    for (int j = 0; j < l; ++j) {
      hashw1[i] = (hashw1[i] * base1 + w[i][j]) % mod;
      hashw2[i] = (hashw2[i] * base2 + w[i][j]) % mod;
    }
  }
}
void _sub1() {
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    for (int j = 1; j <= m; ++j)
      if (_check(i, j)) dp[i] = max(dp[i], dp[i - w[j].size()] + p[j]);
  }
  res = dp[n];
}
int c[N2][N2], f[N2][N2];
int cost[N2][N2];
int cnt[N2];
int pre[N2], d[N2];
bool inq[N2];
int _find() {
  queue<int> q;
  q.push(1);
  fill(d, d + N2, 1e9);
  d[1] = 0;
  fill(pre, pre + N2, 0);
  fill(cnt, cnt + N2, 0);
  fill(inq, inq + N2, false);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = false;
    for (int v = 1; v <= n * 2 + 1; ++v)
      if (f[u][v] < c[u][v]) {
        int curcost = ((f[u][v] >= 0) ? 1 : -1) * cost[u][v];
        if (d[u] + curcost < d[v]) {
          d[v] = d[u] + curcost;
          pre[v] = u;
          if (!inq[v]) {
            inq[v] = true;
            q.push(v);
          }
        }
      }
  }
  return d[n + 1];
}
void _inc(int Min) {
  for (int u, v = n + 1; v; v = u) {
    u = pre[v];
    ++f[u][v];
    --f[v][u];
  }
  res -= Min;
}
void _full() {
  for (int i = 1; i <= n; ++i) c[i][i + n + 1] = c[i + n + 1][i + 1] = 100;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (_check(i, j)) {
        int l = i - w[j].size() + 1;
        c[l][i + 1] = 1;
        cost[l][i + 1] = cost[i + 1][l] = -p[j];
      }
  for (int i = 1; i <= x; ++i) {
    int Min = _find();
    if (Min == 0) break;
    _inc(Min);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> s >> m;
  s = ' ' + s;
  for (int i = 1; i <= m; ++i) cin >> w[i] >> p[i];
  cin >> x;
  _hashcal();
  if (x == 1)
    _sub1();
  else
    _full();
  cout << res;
  return 0;
}