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>
static const long long INF64 = (1LL << 61);
static const int INF32 = 0x7fffffff;
static const int MAXN = 504;
static const int MAXM = 104;
static const int MAXX = 104;
namespace mcf {
static const int MAXN = ::MAXN + 10;
static const int MAXM = ::MAXN * 5;
int n, m = 0, source, sink;
int dest[MAXM], cap[MAXM], cost[MAXM];
int head[MAXN], next[MAXM];
inline void initialize() { memset(head, -1, sizeof head); }
inline void add_edge(int u, int v, int _cap, int _cost) {
  dest[m] = v;
  cap[m] = _cap;
  cost[m] = _cost;
  next[m] = head[u];
  head[u] = m++;
  dest[m] = u;
  cap[m] = 0;
  cost[m] = -_cost;
  next[m] = head[v];
  head[v] = m++;
}
std::pair<long long, long long> deluge() {
  long long ans = 0, flow = 0;
  static long long d[MAXN];
  static int pv[MAXN], pe[MAXN];
  while (true) {
    std::fill(d, d + n, INF64);
    d[source] = 0;
    bool updated;
    do {
      updated = false;
      for (int i = 0; i < n; ++i)
        if (d[i] != INF64) {
          for (int w = head[i]; w != -1; w = next[w])
            if (cap[w] > 0 && d[dest[w]] > d[i] + cost[w]) {
              d[dest[w]] = d[i] + cost[w];
              pv[dest[w]] = i;
              pe[dest[w]] = w;
              updated = true;
            }
        }
    } while (updated);
    if (d[sink] == INF64) break;
    int aug = INF32;
    for (int i = sink; i != source; i = pv[i]) aug = std::min(aug, cap[pe[i]]);
    flow += aug;
    ans += d[sink] * aug;
    for (int i = sink; i != source; i = pv[i]) {
      cap[pe[i]] -= aug;
      cap[pe[i] ^ 1] += aug;
    }
  }
  return std::make_pair(flow, ans);
}
}  // namespace mcf
int n, m, x;
char s[MAXN];
char w[MAXM][MAXN];
int len[MAXN], q[MAXM];
int ct = 0;
int u[MAXM * MAXN], v[MAXM * MAXN], p[MAXM * MAXN];
bool used[MAXM * MAXN];
inline bool substr_equal(int sstart, int wlen, char *word) {
  for (int i = 0; i < wlen; ++i)
    if (s[sstart + i] != word[i]) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  getchar();
  for (int i = 0; i < n; ++i) s[i] = getchar();
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf("%s%d", w[i], &q[i]);
  scanf("%d", &x);
  for (int i = 0; i < m; ++i) {
    len[i] = strlen(w[i]);
    for (int j = 0; j <= n - len[i]; ++j)
      if (substr_equal(j, len[i], w[i])) {
        u[ct] = j;
        v[ct] = j + len[i];
        p[ct++] = q[i];
      }
  }
  mcf::n = (n + 1) + 2;
  mcf::source = mcf::n - 2;
  mcf::sink = mcf::n - 1;
  mcf::initialize();
  static const int OvO = 1000;
  for (int i = 0; i < ct; ++i) mcf::add_edge(v[i], u[i], 1, -p[i]);
  mcf::add_edge(mcf::source, n, x, 0);
  mcf::add_edge(0, mcf::sink, x, 0);
  for (int i = 0; i < n; ++i) mcf::add_edge(i + 1, i, INF32, 0);
  std::pair<long long, long long> flow = mcf::deluge();
  printf("%I64d\n", -flow.second);
  return 0;
}