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>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
struct edge {
  int u, v, cost, cap;
  edge() {}
  edge(int _u, int _v, int _c, int _cap) : u(_u), v(_v), cost(_c), cap(_cap) {}
  int get(int t) { return t ^ u ^ v; }
};
const int inf = 1e9;
template <class edge, int inf>
class edkarp {
 public:
  vector<edge> edges;
  vector<vector<int>> adj;
  int n;
  void init(int _n) {
    n = _n;
    adj.assign(n, vector<int>(0));
  }
  inline int comp(int i) { return i ^ 1; }
  inline int par(int i, int edge_num) { return edges[edge_num].get(i); }
  void add(int u, int v, int co, int capac) {
    adj[u].emplace_back(edges.size());
    edges.emplace_back(u, v, co, capac);
    adj[v].emplace_back(edges.size());
    edges.emplace_back(v, u, -co, 0);
  }
  void shortest_path(int v, vector<int> &d, vector<int> &p) {
    p.assign(n, -1);
    d.assign(n, inf);
    d[v] = 0;
    bool change = false;
    for (int i = 0; i < n - 1; i++) {
      change = false;
      for (int j = 0; j < edges.size(); j++) {
        if (d[edges[j].u] == inf || edges[j].cap == 0) continue;
        if (d[edges[j].v] > d[edges[j].u] + edges[j].cost) {
          d[edges[j].v] = d[edges[j].u] + edges[j].cost;
          p[edges[j].v] = j;
          change = true;
        }
      }
      if (!change) break;
    }
  }
  int mincost(int st, int tar, int k = inf) {
    vector<int> p, d;
    int flow = 0, cost = 0;
    int nf;
    while (flow < k) {
      shortest_path(st, d, p);
      if (d[tar] == inf) break;
      nf = k - flow;
      int cr = tar;
      while (cr != st) {
        nf = min(nf, edges[p[cr]].cap);
        cr = par(cr, p[cr]);
      }
      flow += nf;
      cost += nf * d[tar];
      cr = tar;
      while (cr != st) {
        edges[p[cr]].cap -= nf;
        edges[comp(p[cr])].cap += nf;
        cr = par(cr, p[cr]);
      }
    }
    return cost;
  }
};
void prefix_func(string &s, vector<int> &v) {
  int n = s.size();
  v.assign(n, 0);
  for (int i = 1; i < n; i++) {
    int j = v[i - 1];
    while (j >= 0 && s[j] != s[i]) {
      j = j == 0 ? -1 : v[j - 1];
    }
    v[i] = j + 1;
  }
}
int n, m, p[104], x, cr;
string s, w[104];
vector<int> v;
edkarp<edge, inf> fo;
void solve() {
  cin >> n >> s;
  cin >> m;
  fo.init(n + 2);
  fo.add(0, 1, 0, 100);
  for (int i = 1; i <= n; i++) {
    fo.add(i, i + 1, 0, 100);
  }
  for (int i = 0; i < m; i++) {
    cin >> w[i] >> p[i];
    prefix_func(w[i], v);
    cr = 0;
    for (int j = 0; j < n; j++) {
      while (cr >= 0 && s[j] != w[i][cr]) {
        cr = cr == 0 ? -1 : v[cr - 1];
      }
      cr++;
      if (cr == (int)w[i].size()) {
        cr = v[cr - 1];
        fo.add(j - (int)w[i].size() + 2, j + 2, -p[i], 1);
      }
    }
  }
  cin >> x;
  cout << -fo.mincost(0, n + 1, x) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}