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;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
struct kra {
  int cel;
  int* prze1;
  int* prze2;
  long long koszt;
};
int n1;
const int nax = 1007;
const long long inf = 1000000007;
const long long infinf = inf * inf;
vector<kra> graf[nax];
void add_edge(int v, int u, int prze, long long koszt) {
  kra ret1{u, new int, new int, koszt};
  kra ret2{v, ret1.prze2, ret1.prze1, -koszt};
  (*ret1.prze1) = prze;
  (*ret1.prze2) = 0;
  graf[v].push_back(ret1);
  graf[u].push_back(ret2);
}
int aktu[nax];
long long odl[nax];
int bylo[nax];
queue<int> bfs;
vector<int> drzewo[nax];
int ojc[nax];
long long wyn;
void tnij(int v) {
  debug() << "tne " << v;
  ojc[v] = 0;
  for (int i = 0; i < drzewo[v].size(); i++)
    if (ojc[drzewo[v][i]] == v) tnij(drzewo[v][i]);
  drzewo[v].clear();
  aktu[v] = 1;
}
void spfa() {
  for (int i = 1; i <= n1; i++) {
    aktu[i] = 1;
    odl[i] = infinf;
    drzewo[i].clear();
    ojc[i] = 0;
  }
  aktu[1] = 0;
  odl[1] = 0;
  bfs.push(1);
  while (!bfs.empty()) {
    int v = bfs.front();
    bfs.pop();
    if (aktu[v]) continue;
    aktu[v] = 1;
    for (int i = 0; i < graf[v].size(); i++) {
      if ((*graf[v][i].prze1) &&
          odl[v] + graf[v][i].koszt < odl[graf[v][i].cel]) {
        debug() << "ciecie";
        tnij(graf[v][i].cel);
        ojc[graf[v][i].cel] = v;
        drzewo[v].push_back(graf[v][i].cel);
        odl[graf[v][i].cel] = odl[v] + graf[v][i].koszt;
        aktu[graf[v][i].cel] = 0;
        bfs.push(graf[v][i].cel);
      }
    }
  }
  debug() << range(odl + 1, odl + 1 + n1);
}
int dfs(int v) {
  debug() << "["
          << "v"
             ": "
          << (v) << "] ";
  if (v == n1) return 1;
  bylo[v] = 1;
  for (int i = 0; i < graf[v].size(); i++) {
    debug() << "z " << v << " na " << graf[v][i].cel;
    if (!bylo[graf[v][i].cel] && (*graf[v][i].prze1) &&
        odl[v] + graf[v][i].koszt == odl[graf[v][i].cel] &&
        dfs(graf[v][i].cel)) {
      wyn += graf[v][i].koszt;
      (*graf[v][i].prze1)--;
      (*graf[v][i].prze2)++;
      return 1;
    }
  }
  return 0;
}
int flow() {
  spfa();
  for (int i = 1; i <= n1; i++) bylo[i] = 0;
  debug() << "jade";
  return dfs(1);
}
int n, m, x;
char tek[nax];
char slo[nax];
int dlu[nax];
int tab[nax][nax];
int main() {
  scanf("%d", &n);
  scanf("%s", tek + 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", slo + 1);
    int p1;
    scanf("%d", &p1);
    dlu[i] = strlen(slo + 1);
    for (int j = 1; j + dlu[i] - 1 <= n; j++) {
      tab[j][i] = p1;
      for (int l = dlu[i]; l; l--)
        if (slo[l] != tek[j - 1 + l]) tab[j][i] = 0;
    }
  }
  scanf("%d", &x);
  for (int i = 1; i <= n; i++) debug() << range(tab[i] + 1, tab[i] + 1 + n);
  n1 = n + 1;
  for (int i = 1; i <= n; i++) {
    add_edge(i, i + 1, x, 0);
    for (int j = 1; j <= m; j++) add_edge(i, i + dlu[j], 1, -tab[i][j]);
  }
  for (int i = 1; i <= x; i++) flow();
  printf("%lld\n", -wyn);
  return 0;
}