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;
struct MinCostMaxFlow {
  static const int INF = 1e9;
  int n, s, t;
  struct edge {
    int u, v, c, f, cost;
  };
  vector<edge> E;
  vector<vector<int> > graph;
  vector<int> dist, head;
  vector<bool> inq;
  MinCostMaxFlow(int n = 0, int s = 0, int t = 0) : n(n), s(s), t(t) {
    E.clear();
    graph.assign(n + 1, vector<int>());
  }
  void addEdge(int u, int v, int c, int cost) {
    graph[u].push_back(E.size());
    E.push_back({u, v, c, 0, cost});
    graph[v].push_back(E.size());
    E.push_back({v, u, 0, 0, -cost});
  }
  bool SPFA() {
    head.assign(n + 1, -1);
    dist.assign(n + 1, 1e9);
    dist[s] = 0;
    queue<pair<int, int> > wl;
    wl.push({0, s});
    while (not wl.empty()) {
      int d = wl.front().first, u = wl.front().second;
      wl.pop();
      if (d > dist[u]) continue;
      for (int i : graph[u]) {
        if (dist[E[i].v] > d + E[i].cost && E[i].f < E[i].c) {
          dist[E[i].v] = d + E[i].cost, head[E[i].v] = i;
          wl.push({dist[E[i].v], E[i].v});
        }
      }
    }
    return (head[t] != -1);
  }
  int dfs() {
    int delta = INF;
    for (int u = t; u != s; u = E[head[u]].u) {
      int i = head[u];
      delta = min(delta, E[i].c - E[i].f);
    }
    for (int u = t; u != s; u = E[head[u]].u) {
      int i = head[u];
      E[i].f += delta, E[i ^ 1].f -= delta;
    }
    return delta;
  }
  int maxFlow() {
    int ans = 0, flow = 0;
    while (SPFA()) {
      int det = dfs();
      ans += dist[t] * det;
      flow += det;
    }
    return ans;
  }
} mcmf;
int m, p, A, B, C, z[610], MAX_CAPACITY, sum = 0;
vector<int> capacity[510];
char c[610];
string a, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> a >> m;
  mcmf = MinCostMaxFlow(A + 3, A + 2, A + 3);
  for (int x = 1; x <= m; x++) {
    cin >> b >> p;
    B = b.length(), C = B + A;
    for (int i = 0; i < B; i++) c[i] = b[i], z[i] = 0;
    for (int i = B; i < C; i++) c[i] = a[i - B], z[i] = 0;
    int L = 0, R = 0;
    for (int i = 1; i < C; i++) {
      if (R < i) {
        L = R = i;
        while (R < C && c[R] == c[R - L]) 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 < C && c[R] == c[R - L]) R++;
          z[i] = R - L, R--;
        }
      }
    }
    for (int i = 0; i < A; i++) {
      if (z[i + B] >= B) mcmf.addEdge(i + 1, i + B + 1, 1, -p);
    }
  }
  cin >> MAX_CAPACITY;
  mcmf.addEdge(A + 2, 1, MAX_CAPACITY, 0);
  mcmf.addEdge(A + 1, A + 3, MAX_CAPACITY, 0);
  for (int i = 1; i <= A; i++) mcmf.addEdge(i, i + 1, MAX_CAPACITY, 0);
  printf("%d", -mcmf.maxFlow());
}