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 flow_type, typename cost_type>
struct min_cost_max_flow {
  struct edge {
    size_t src, dst, rev;
    flow_type flow, cap;
    cost_type cost;
  };
  int n;
  vector<vector<edge>> adj;
  min_cost_max_flow(int n) : n(n), adj(n), potential(n), dist(n), back(n) {}
  void add_edge(size_t src, size_t dst, flow_type cap, cost_type cost) {
    adj[src].push_back({src, dst, adj[dst].size(), 0, cap, cost});
    if (src == dst) adj[src].back().rev++;
    adj[dst].push_back({dst, src, adj[src].size() - 1, 0, 0, -cost});
  }
  vector<cost_type> potential;
  inline cost_type rcost(const edge &e) {
    return e.cost + potential[e.src] - potential[e.dst];
  }
  void bellman_ford(int source) {
    for (int k = 0; k < n; ++k)
      for (int u = 0; u < n; ++u)
        for (edge &e : adj[u])
          if (e.cap > 0 && rcost(e) < 0) potential[e.dst] += rcost(e);
  }
  const cost_type oo = numeric_limits<cost_type>::max();
  vector<cost_type> dist;
  vector<edge *> back;
  cost_type dijkstra(int source, int sink) {
    fill(dist.begin(), dist.end(), oo);
    priority_queue<pair<cost_type, int>, vector<pair<cost_type, int>>,
                   greater<pair<cost_type, int>>>
        pq;
    for (pq.push({dist[source] = 0, source}); !pq.empty();) {
      pair<cost_type, int> p = pq.top();
      pq.pop();
      if (dist[p.second] < p.first) continue;
      if (p.second == sink) break;
      for (edge &e : adj[p.second])
        if (e.flow < e.cap && dist[e.dst] > dist[e.src] + rcost(e)) {
          back[e.dst] = &e;
          pq.push({dist[e.dst] = dist[e.src] + rcost(e), e.dst});
        }
    }
    return dist[sink];
  }
  pair<flow_type, cost_type> max_flow(int source, int sink) {
    flow_type flow = 0;
    cost_type cost = 0;
    for (int u = 0; u < n; ++u)
      for (edge &e : adj[u]) e.flow = 0;
    potential.assign(n, 0);
    dist.assign(n, 0);
    back.assign(n, nullptr);
    bellman_ford(source);
    while (dijkstra(source, sink) < oo) {
      for (int u = 0; u < n; ++u)
        if (dist[u] < dist[sink]) potential[u] += dist[u] - dist[sink];
      flow_type f = numeric_limits<flow_type>::max();
      for (edge *e = back[sink]; e; e = back[e->src])
        f = min(f, e->cap - e->flow);
      for (edge *e = back[sink]; e; e = back[e->src])
        e->flow += f, adj[e->dst][e->rev].flow -= f;
      flow += f;
      cost += f * (potential[sink] - potential[source]);
    }
    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_max_flow<int, 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;
}