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;
using cd = complex<double>;
using ll = long long;
const double PI = acos(-1);
void fft(vector<cd> &a, bool invert) {
  int n = a.size();
  for (int i = 1, j = 0; i < n; i++) {
    int bit = n >> 1;
    for (; j & bit; bit >>= 1) j ^= bit;
    j ^= bit;
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    double ang = 2 * PI / len * (invert ? -1 : 1);
    cd wlen(cos(ang), sin(ang));
    for (int i = 0; i < n; i += len) {
      cd w(1);
      for (int j = 0; j < len / 2; j++) {
        cd u = a[i + j], v = a[i + j + len / 2] * w;
        a[i + j] = u + v;
        a[i + j + len / 2] = u - v;
        w *= wlen;
      }
    }
  }
  if (invert) {
    for (cd &x : a) x /= n;
  }
}
vector<ll> multiply(vector<ll> const &a, vector<ll> const &b) {
  vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
  int n = 1;
  while (n < a.size() + b.size()) n <<= 1;
  fa.resize(n);
  fb.resize(n);
  fft(fa, false);
  fft(fb, false);
  for (int i = 0; i < n; i++) fa[i] *= fb[i];
  fft(fa, true);
  vector<ll> result(n);
  for (int i = 0; i < n; i++) result[i] = round(fa[i].real());
  result.resize(a.size() + b.size());
  return result;
}
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int &cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
template <class TF, class TC, TF Foo, TC Coo>
struct MinCostMaxFlow {
  int n, s, t, E;
  vector<int> adj, nxt, lst, frm, vis;
  vector<TF> cap, flw;
  TF totalFlow;
  vector<TC> cst, dst;
  TC totalCost;
  void init(int n, int s, int t) {
    this->n = n, this->s = s, this->t = t;
    lst.resize(n, -1), E = 0;
    frm.resize(n);
    vis.resize(n);
  }
  void add(int u, int v, TF ca, TC co) {
    adj.push_back(v);
    cap.push_back(ca), flw.push_back(0), cst.push_back(+co),
        nxt.push_back(lst[u]), lst[u] = E++;
    adj.push_back(u), cap.push_back(0), flw.push_back(0), cst.push_back(-co),
        nxt.push_back(lst[v]), lst[v] = E++;
  }
  int spfa() {
    dst.clear();
    dst.resize(n, Coo);
    dst[s] = 0;
    queue<int> que;
    que.push(s);
    while (que.size()) {
      int u = que.front();
      que.pop();
      for (int e = lst[u]; e != -1; e = nxt[e])
        if (flw[e] < cap[e]) {
          int v = adj[e];
          if (dst[v] > dst[u] + cst[e]) {
            dst[v] = dst[u] + cst[e];
            frm[v] = e;
            if (!vis[v]) {
              vis[v] = 1;
              que.push(v);
            }
          }
        }
      vis[u] = 0;
    }
    return dst[t] < Coo;
  }
  pair<TC, TF> mincost() {
    totalCost = 0, totalFlow = 0;
    while (1) {
      if (!spfa()) break;
      TF mn = Foo;
      for (int v = t, e = frm[v]; v != s; v = adj[e ^ 1], e = frm[v])
        mn = min(mn, cap[e] - flw[e]);
      for (int v = t, e = frm[v]; v != s; v = adj[e ^ 1], e = frm[v]) {
        flw[e] += mn;
        flw[e ^ 1] -= mn;
      }
      totalFlow += mn;
      totalCost += mn * dst[t];
    }
    return pair<TC, TF>(totalCost, totalFlow);
  }
};
using namespace std;
class GUnderfail {
 public:
  void solve(std::istream &cin, std::ostream &cout) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m;
    cin >> m;
    vector<string> v;
    vector<ll> b;
    for (int i = 0; i < m; i++) {
      string h;
      cin >> h;
      v.push_back(h);
      ll o;
      cin >> o;
      b.push_back(o);
    }
    ll x;
    cin >> x;
    MinCostMaxFlow<ll, ll, LONG_LONG_MAX / 5, LONG_LONG_MAX / 5> maxFlow;
    maxFlow.init(n + 2, n + 1, n);
    for (int i = 0; i < n; i++) maxFlow.add(i, i + 1, x, 0);
    maxFlow.add(n + 1, 0, x, 0);
    for (int i = 0; i < v.size(); i++) {
      for (int j = 0; j <= n - v[i].length(); j++) {
        bool match = true;
        for (int k = 0; k < v[i].length(); k++) {
          if (s[j + k] != v[i][k]) {
            match = false;
            break;
          }
        }
        if (match) maxFlow.add(j, j + v[i].length(), 1, -b[i]);
      }
    }
    cout << -maxFlow.mincost().first << endl;
  }
};
int main() {
  GUnderfail solver;
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}