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 T>
inline bool isLeap(T y) {
  return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);
}
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <class T>
inline T BigMod(T Base, T power, T M = 1000000007) {
  if (power == 0) return 1;
  if (power & 1)
    return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;
  else {
    T y = BigMod(Base, power / 2, M) % M;
    return (y * y) % M;
  }
}
template <class T>
inline T ModInv(T A, T M = 1000000007) {
  return BigMod(A, M - 2, M);
}
int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};
int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int pt[100005];
vector<int> v[100005];
string ptt[100005];
int ans, dtt[100005], non[505][505], fl[505], pos1[505], pos2[505], cl[505];
const int N = 505 * 2;
const long long INF = (long long)1 << 60;
struct Edge {
  long long from, to, cap, flow, cost;
  Edge(int from, int to, int cap, int flow, int cost)
      : from(from), to(to), cap(cap), flow(flow), cost(cost) {}
};
namespace mcmf {
int n, m, s, t;
vector<Edge> edges;
vector<long long> G[N];
bool inq[N];
long long d[N], p[N], a[N];
void init(int src, int sink, int node) {
  n = node;
  s = src;
  t = sink;
  edges.clear();
  for (int i = 0; i <= n; ++i) G[i].clear();
}
void addEdge(int from, int to, long long cap, long long cost) {
  edges.push_back(Edge(from, to, cap, 0, cost));
  edges.push_back(Edge(to, from, 0, 0, -cost));
  m = edges.size();
  G[from].push_back(m - 2);
  G[to].push_back(m - 1);
}
bool spfa(long long &flow, long long &cost) {
  for (int i = 0; i <= n; ++i) d[i] = INF, inq[i] = 0;
  queue<int> que;
  que.push(s);
  inq[s] = 1;
  d[s] = 0;
  p[s] = 0;
  a[s] = INF;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    inq[x] = 0;
    for (int i = 0; i < G[x].size(); ++i) {
      Edge &e = edges[G[x][i]];
      if (e.cap > e.flow && d[e.to] > d[x] + e.cost) {
        d[e.to] = d[x] + e.cost;
        p[e.to] = G[x][i];
        a[e.to] = min(a[x], e.cap - e.flow);
        if (!inq[e.to]) inq[e.to] = 1, que.push(e.to);
      }
    }
  }
  if (d[t] == INF) return 0;
  flow += a[t];
  cost += d[t];
  int u = t;
  while (u != s) {
    edges[p[u]].flow += a[t];
    edges[p[u] ^ 1].flow -= a[t];
    u = edges[p[u]].from;
  }
  return 1;
}
pair<long long, long long> solve() {
  long long flow = 0, cost = 0;
  while (spfa(flow, cost))
    ;
  return make_pair(cost, flow);
}
}  // namespace mcmf
int sor;
int occ(string s, string second, int indx) {
  int z[1005];
  memset(z, 0, sizeof(z));
  int n = s.length();
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (z[i] == second.length()) {
      mcmf::addEdge(i - second.length() - 1, i - 1, 1, -dtt[indx]);
    }
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int n;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    pos1[i] = cnt++;
    pos2[i] = cnt++;
  }
  sor = cnt;
  mcmf::init(n + 1, n + 2, n + 3);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> ptt[i] >> dtt[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < n; i++) mcmf::addEdge(i, i + 1, q, 0);
  for (int i = 0; i < m; i++) {
    string second = ptt[i] + '#' + s;
    occ(second, ptt[i], i);
  }
  mcmf::addEdge(n + 1, 0, q, 0);
  mcmf::addEdge(n, n + 2, q, 0);
  pair<long long, long long> x = mcmf::solve();
  cout << -x.first;
  return 0;
}