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>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
typedef double LD;
const int N = 500 + 5;
int E;
char S[N];
const int M = 100 + 5;
char c[M][N];
int m;
int p[N];
int x;
const int INF = 100000000, T = 100;
struct mincostflow {
  struct edge {
    int v, to, u, f, c;
    edge(int _v = 0, int _to = 0, int _u = 0, int _c = 0, int _f = 0)
        : v(_v), to(_to), u(_u), f(_f), c(_c) {}
  };
  int n;
  int tope;
  vector<edge> e;
  vector<std::vector<int> > graph;
  const LD ep;
  mincostflow() : ep(1e-9) { graph.resize(N); }
  void add_edge(int v, int to, int u, int c) {
    e.push_back(edge(v, to, u, c));
    graph[v].push_back(tope++);
    e.push_back(edge(to, v, 0, -c));
    graph[to].push_back(tope++);
  }
  int ex[N];
  int po[N];
  LD p[N];
  inline LD Cp(int in) { return p[e[in].v] - p[e[in].to] + e[in].c; }
  bool discharge(int v, LD E) {
    bool st = false;
    while (ex[v] > 0) {
      if (po[v] == ((int)((graph[v]).size()))) {
        st = true;
        LD pa = -1.0 * INF;
        for (int j = 0; j < (int)(((int)((graph[v]).size()))); ++j) {
          int in = graph[v][j];
          if (e[in].u > e[in].f) pa = max(pa, p[e[in].to] - e[in].c - E);
        }
        p[v] = pa;
        po[v] = 0;
      }
      int in = graph[v][po[v]];
      if (e[in].u > e[in].f && Cp(in) < -ep) {
        int pu = min(ex[v], e[in].u - e[in].f);
        e[in].f += pu;
        e[in ^ 1].f -= pu;
        ex[e[in].to] += pu;
        ex[e[in].v] -= pu;
      }
      if (ex[v] > 0) ++po[v];
    }
    return st;
  }
  void make_e_optimal(LD E) {
    list<int> L;
    for (int i = 0; i < (int)(tope); ++i)
      if (e[i].u > e[i].f && Cp(i) < -ep) {
        e[i].f = e[i].u;
        e[i ^ 1].f = -e[i].f;
      }
    for (int i = 0; i < (int)(n); ++i) {
      L.push_back(i);
      ex[i] = 0;
      po[i] = 0;
    }
    for (int i = 0; i < (int)(tope); ++i) ex[e[i].to] += e[i].f;
    list<int>::iterator H = L.begin();
    while (H != L.end()) {
      if (discharge(*H, E)) {
        L.push_front(*H);
        L.erase(H);
        H = L.begin();
      }
      ++H;
    }
  }
  int flow() {
    LD E = 1.0 * T;
    while (E > 1.0 / n - ep) {
      E = E / 2.0;
      make_e_optimal(E);
    }
    int res = 0;
    for (int i = 0; i < (int)(tope); ++i) {
      res += e[i].f * e[i].c;
    }
    return -res / 2;
  }
} F;
vector<int> z_function(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    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;
  }
  return z;
}
int L[N];
int e[N];
int qa[N];
void solve() {
  scanf("%d", &E);
  scanf("%s", S);
  scanf("%d", &m);
  for (int i = 1; i <= (int)(m); ++i) scanf("%s %d", c[i], &p[i]);
  scanf("%d", &x);
  for (int i = 0; i < (int)(E); ++i) {
    L[i] = F.tope;
    F.add_edge(i, i + 1, x, 0);
  }
  F.n = E + 1;
  for (int i = 1; i <= (int)(m); ++i) {
    string u;
    e[i] = strlen(c[i]);
    for (int j = 0; j < (int)(e[i]); ++j) u += c[i][j];
    for (int j = 0; j < (int)(E); ++j) u += S[j];
    std::vector<int> ans = z_function(u);
    for (int j = e[i]; j < ((int)((ans).size())); ++j) {
      if (ans[j] >= e[i]) {
        int in = F.tope;
        F.add_edge(j - e[i] + e[i], j - e[i], 1, -p[i]);
      }
    }
  }
  cout << F.flow() << endl;
}
char t[N];
char tu[N];
void testgen() {
  FILE* f = fopen("input.txt", "w");
  int n = 500, m = 100;
  fprintf(f, "%d\n", n);
  for (int i = 0; i < (int)(n); ++i) t[i] = 'a' + rand() % 1;
  fprintf(f, "%s\n", t);
  fprintf(f, "%d\n", m);
  for (int i = 0; i < (int)(m); ++i) {
    int l = rand() % n;
    int r = rand() % n;
    if (l > r) swap(l, r);
    for (int j = l; j <= r; ++j) {
      fprintf(f, "%c", t[j]);
    }
    fprintf(f, " %d\n", rand() % 100 + 1);
  }
  fprintf(f, "%d\n", rand() % m + 1);
  fclose(f);
}
int main() {
  std::cout << std::fixed;
  std::cout.precision(8);
  std::cerr << std::fixed;
  std::cerr.precision(3);
  solve();
  return 0;
}