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 oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100010;
struct trie {
  vector<vector<int>> tree;
  vector<vector<int>> go;
  vector<vector<int>> ENDS;
  trie() { new_node(); }
  int new_node() {
    int id = tree.size();
    tree.push_back(vector<int>(26));
    go.push_back(vector<int>(26));
    ENDS.push_back(vector<int>());
    return id;
  }
  void push(string s, int idx) {
    int cur = 0;
    for (auto x : s) {
      int v = x - 'a';
      if (!tree[cur][v]) {
        int id = new_node();
        tree[cur][v] = id;
      }
      cur = tree[cur][v];
    }
    ENDS[cur].push_back(idx);
  }
  void build() {
    queue<pair<int, int>> q;
    q.push({0, 0});
    while (!q.empty()) {
      pair<int, int> c = q.front();
      q.pop();
      int u = c.first;
      int f = c.second;
      for (auto i : ENDS[f]) ENDS[u].push_back(i);
      for (int i = 0; i < 26; ++i) {
        if (tree[u][i]) {
          q.push({tree[u][i], go[f][i]});
          go[u][i] = tree[u][i];
        } else
          go[u][i] = go[f][i];
      }
    }
  }
};
template <typename T, typename C = T>
struct min_cost_flow {
  struct edge {
    int src, dst;
    T cap, flow;
    C cost;
    int rev;
  };
  int n;
  vector<vector<edge>> adj;
  min_cost_flow(int n) : n(n), adj(n) {}
  void add_edge(int src, int dst, T cap, C cost) {
    adj[src].push_back({src, dst, cap, 0, cost, (int)adj[dst].size()});
    if (src == dst) adj[src].back().rev++;
    adj[dst].push_back({dst, src, 0, 0, -cost, (int)adj[src].size() - 1});
  }
  const C oo = numeric_limits<C>::max();
  vector<C> dist;
  vector<edge *> prev;
  vector<T> curflow;
  bool bellman_ford(int s, int t) {
    dist.assign(n, oo);
    prev.assign(n, nullptr);
    curflow.assign(n, 0);
    dist[s] = 0;
    curflow[s] = numeric_limits<T>::max();
    for (int it = 0, change = true; it < n && change; ++it) {
      change = false;
      for (int u = 0; u < n; ++u)
        if (dist[u] != oo) {
          for (auto &e : adj[u])
            if (e.flow < e.cap && dist[e.dst] > dist[u] + e.cost) {
              dist[e.dst] = dist[u] + e.cost;
              prev[e.dst] = &e;
              curflow[e.dst] = min(curflow[u], e.cap - e.flow);
              change = true;
            }
        }
    }
    return dist[t] < oo;
  }
  pair<T, C> max_flow(int s, int t) {
    T flow = 0;
    C cost = 0;
    while (bellman_ford(s, t)) {
      T delta = curflow[t];
      flow += delta;
      cost += delta * dist[t];
      for (edge *e = prev[t]; e != nullptr; e = prev[e->src]) {
        e->flow += delta;
        adj[e->dst][e->rev].flow -= delta;
      }
    }
    return {flow, cost};
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  trie T;
  int k;
  cin >> k;
  vector<int> values(k);
  vector<int> length(k);
  for (int i = 0; i < k; ++i) {
    string a;
    cin >> a >> values[i];
    length[i] = a.length();
    T.push(a, i);
  }
  T.build();
  int x;
  cin >> x;
  min_cost_flow<int> mcf(n + 2);
  mcf.add_edge(0, 1, x, 0);
  for (int i = 0, u = 0; i < n; ++i) {
    mcf.add_edge(i + 1, i + 2, x, 0);
    int v = s[i] - 'a';
    u = T.go[u][v];
    for (auto e : T.ENDS[u]) {
      int l = length[e];
      int f = i - l;
      mcf.add_edge(f + 1, i + 1, 1, -values[e]);
    }
  }
  pair<int, int> ans = mcf.max_flow(0, n + 1);
  cout << -ans.second << endl;
  return 0;
}