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;
struct MCMF {
  struct Edge {
    int v1, v2, w, f, c;
  };
  int N;
  vector<Edge> E;
  vector<vector<int>> ed;
  vector<int> dist;
  vector<int> prev;
  vector<bool> inq;
  MCMF(int n = 0) : N(n), ed(N), dist(N), prev(N), inq(N) {}
  void add_edge(int a, int b, int w, int c) {
    ed[a].push_back(E.size());
    E.push_back({a, b, w, c, c});
    ed[b].push_back(E.size());
    E.push_back({b, a, -w, 0, c});
  }
  bool Bfs(int s, int t) {
    fill(dist.begin(), dist.end(), 0x3f3f3f3f);
    fill(prev.begin(), prev.end(), -1);
    fill(inq.begin(), inq.end(), false);
    queue<int> q;
    dist[s] = 0;
    inq[s] = true;
    q.push(s);
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      inq[now] = false;
      for (int i = 0; i < (int)ed[now].size(); i++) {
        const Edge &e = E[ed[now][i]];
        if (e.f > 0 && dist[e.v2] > dist[e.v1] + e.w) {
          dist[e.v2] = dist[e.v1] + e.w;
          prev[e.v2] = ed[now][i];
          if (!inq[e.v2]) {
            q.push(e.v2);
            inq[e.v2] = true;
          }
        }
      }
    }
    return dist[t] != 0x3f3f3f3f;
  }
  pair<int, int> Solve(int s, int t) {
    pair<int, int> res = {0, 0};
    while (Bfs(s, t)) {
      int now = t;
      int f = INT_MAX, c = 0;
      while (now != s) {
        f = min(f, E[prev[now]].f);
        c += E[prev[now]].w;
        now = E[prev[now]].v1;
      }
      now = t;
      while (now != s) {
        E[prev[now]].f -= f;
        E[prev[now] ^ 1].f += f;
        now = E[prev[now]].v1;
      }
      res.first += f;
      res.second += f * c;
    }
    return res;
  }
};
struct AC {
  struct Node {
    Node *ch[26], *fail;
    vector<int> indexes;
    Node() {
      memset(ch, 0, sizeof(ch));
      fail = NULL;
    }
  };
  Node *root;
  AC() { root = new Node(); }
  void Insert(const string &s, int index) {
    Node *tr = root;
    for (char c : s) {
      if (!tr->ch[c - 'a']) {
        tr->ch[c - 'a'] = new Node();
      }
      tr = tr->ch[c - 'a'];
    }
    tr->indexes.push_back(index);
  }
  void Build() {
    queue<Node *> q;
    q.push(root);
    while (!q.empty()) {
      Node *now = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (now->ch[i]) {
          Node *ptr = now->fail;
          while (ptr && !ptr->ch[i]) ptr = ptr->fail;
          if (!ptr)
            now->ch[i]->fail = root;
          else
            now->ch[i]->fail = ptr->ch[i];
          q.push(now->ch[i]);
        }
      }
    }
  }
  vector<pair<int, int>> Match(const string &s) {
    vector<pair<int, int>> res;
    Node *tr = root;
    for (int i = 0; i < (int)s.size(); i++) {
      char c = s[i];
      while (tr && !tr->ch[c - 'a']) tr = tr->fail;
      if (tr)
        tr = tr->ch[c - 'a'];
      else
        tr = root;
      Node *ptr = tr;
      while (ptr) {
        for (int index : ptr->indexes) res.push_back({index, i});
        ptr = ptr->fail;
      }
    }
    return res;
  }
};
char s[510];
char p[110][510], len[110];
int w[110];
int main() {
  int N, M, X;
  scanf("%d", &N);
  scanf("%s", s);
  scanf("%d", &M);
  AC ac;
  for (int i = 0; i < M; i++) {
    scanf("%s%d", p[i], &w[i]);
    len[i] = strlen(p[i]);
    ac.Insert(p[i], i);
  }
  ac.Build();
  auto res = ac.Match(s);
  scanf("%d", &X);
  MCMF mcmf(N + 3);
  int source = N + 1, target = source + 1;
  for (int i = 0; i < N; i++) mcmf.add_edge(i, i + 1, 0, X);
  mcmf.add_edge(source, 0, 0, X);
  mcmf.add_edge(N, target, 0, X);
  for (auto m : res) {
    mcmf.add_edge(m.second - len[m.first] + 1, m.second + 1, -w[m.first], 1);
  }
  auto ans = mcmf.Solve(source, target);
  printf("%d\n", -ans.second);
  return 0;
}