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;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
  return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <typename T>
string NumberToString(T Number) {
  ostringstream second;
  second << Number;
  return second.str();
}
inline int nxt() {
  int aaa;
  scanf("%d", &aaa);
  return aaa;
}
inline long long int lxt() {
  long long int aaa;
  scanf("%lld", &aaa);
  return aaa;
}
inline double dxt() {
  double aaa;
  scanf("%lf", &aaa);
  return aaa;
}
template <class T>
inline T bigmod(T p, T e, T m) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
  }
  return (T)ret;
}
int ar[505 * 2];
string s, t;
int p;
int n;
const long long int INF = (long long int)1 << 60;
struct Edge {
  long long int from, to, cap, flow, cost;
  Edge(int from, int to, int cap, int flow, int cost)
      : from(from), to(to), cap(cap), flow(flow), cost(cost) {}
};
namespace mcmf {
int n, m, s, t;
vector<Edge> edges;
vector<long long int> G[505 * 2];
bool inq[505 * 2];
long long int d[505 * 2], p[505 * 2], a[505 * 2];
void init(int src, int sink, int node) {
  n = node;
  s = src;
  t = sink;
  edges.clear();
  for (int i = 0; i <= n; ++i) G[i].clear();
}
void addEdge(int from, int to, long long int cap, long long int cost) {
  edges.push_back(Edge(from, to, cap, 0, cost));
  edges.push_back(Edge(to, from, 0, 0, -cost));
  m = edges.size();
  G[from].push_back(m - 2);
  G[to].push_back(m - 1);
}
bool spfa(long long int& flow, long long int& cost) {
  for (int i = 0; i <= n; ++i) d[i] = INF, inq[i] = 0;
  queue<int> que;
  que.push(s);
  inq[s] = 1;
  d[s] = 0;
  p[s] = 0;
  a[s] = INF;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    inq[x] = 0;
    for (int i = 0; i < G[x].size(); ++i) {
      Edge& e = edges[G[x][i]];
      if (e.cap > e.flow && d[e.to] > d[x] + e.cost) {
        d[e.to] = d[x] + e.cost;
        p[e.to] = G[x][i];
        a[e.to] = min(a[x], e.cap - e.flow);
        if (!inq[e.to]) inq[e.to] = 1, que.push(e.to);
      }
    }
  }
  if (d[t] == INF) return 0;
  flow += a[t];
  cost += d[t];
  int u = t;
  while (u != s) {
    edges[p[u]].flow += a[t];
    edges[p[u] ^ 1].flow -= a[t];
    u = edges[p[u]].from;
  }
  return 1;
}
pair<long long int, long long int> solve() {
  long long int flow = 0, cost = 0;
  while (spfa(flow, cost))
    ;
  return make_pair(cost, flow);
}
}  // namespace mcmf
void make() {
  for (int i = 0; i + t.size() - 1 < n; i++) {
    if (s.substr(i, t.size()) == t) {
      ;
      mcmf::addEdge(i, i + t.size(), 1, -p);
    }
  }
}
int main() {
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  mcmf::init(n + 1, n + 2, n + 3);
  for (int i = 0; i < q; i++) {
    cin >> t >> p;
    make();
  }
  int x = nxt();
  for (int i = 0; i < n; i++) {
    mcmf::addEdge(i, i + 1, x, 0);
  }
  mcmf::addEdge(n + 1, 0, x, 0);
  mcmf::addEdge(n, n + 2, x, 0);
  printf("%lld\n", -mcmf::solve().first);
  return 0;
}