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;
const int maxn = 500 + 123;
string s;
int n;
int x;
struct edge {
  int u, v, cap, flow, cost;
};
bool minimize(int &a, const int &b) {
  if (a > b) return a = b, true;
  return false;
}
class minCostFlow {
 public:
  int source, sink;
  const int INF = 1e9 + 123;
  vector<edge> e;
  vector<int> V[maxn];
  int prevEdge[maxn], d[maxn];
  void initFlow(int _source, int _sink) {
    source = _source;
    sink = _sink;
  }
  void addEdge(int u, int v, int cap, int cost) {
    e.push_back((edge){u, v, cap, 0, cost});
    e.push_back((edge){v, u, 0, 0, -cost});
    V[u].push_back(((int)e.size()) - 2);
    V[v].push_back(((int)e.size()) - 1);
  }
  bool findPath() {
    for (int i = (0), _b = (n + 1); i <= _b; i++) d[i] = INF, prevEdge[i] = 0;
    d[source] = 0;
    while (true) {
      bool ok = false;
      for (int i = (0), _b = (n + 1); i <= _b; i++) {
        for (int id : V[i])
          if (e[id].cap - e[id].flow > 0) {
            if (minimize(d[e[id].v], d[i] + e[id].cost)) {
              prevEdge[e[id].v] = id;
              ok = true;
            }
          }
      }
      if (!ok) break;
    }
    return d[sink] < INF;
  }
  int minCost() {
    int res = 0;
    while (findPath()) {
      int u = sink;
      int push = INF;
      while (u != source) {
        int id = prevEdge[u];
        push = min(push, e[id].cap - e[id].flow);
        u = e[id].u;
      }
      u = sink;
      while (u != source) {
        int id = prevEdge[u];
        e[id].flow += push;
        e[id ^ 1].flow -= push;
        res += push * (e[id].cost);
        u = e[id].u;
      }
    }
    return res;
  }
} mcf;
struct Node {
  int chil[26];
  vector<int> val;
  Node() {
    val = vector<int>(0);
    for (int i = 0, _n = 26; i < _n; ++i) chil[i] = -1;
  }
};
vector<Node> trie;
void addWord(string t, int cost) {
  int cur = 0;
  for (int i = 0, _n = ((int)t.size()); i < _n; ++i) {
    int k = t[i] - 'a';
    if (trie[cur].chil[k] == -1) {
      trie.push_back(*new Node);
      trie[cur].chil[k] = (int)trie.size() - 1;
    }
    cur = trie[cur].chil[k];
  }
  trie[cur].val.push_back(cost);
}
void initTrie() { trie.push_back(*new Node); }
void ReadData() {
  initTrie();
  cin >> n >> s;
  int m;
  cin >> m;
  while (m--) {
    string t;
    cin >> t;
    int cost;
    cin >> cost;
    addWord(t, cost);
  }
  cin >> x;
}
void Process() {
  mcf.initFlow(0, n + 1);
  for (int i = (0), _b = (n); i <= _b; i++) mcf.addEdge(i, i + 1, x, 0);
  for (int i = (0), _b = (n - 1); i <= _b; i++) {
    int cur = 0;
    for (int j = (i), _b = (n - 1); j <= _b; j++) {
      if (trie[cur].chil[s[j] - 'a'] == -1) break;
      cur = trie[cur].chil[s[j] - 'a'];
      for (auto cost : trie[cur].val) mcf.addEdge(i, j + 1, 1, -cost);
    }
  }
  cout << -mcf.minCost() << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ReadData();
  Process();
  return 0;
}