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 MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
struct MincostFlow {
  static const long long oo = (long long)1e18;
  static const int MAXV = 1000 + 10;
  static const int MAXE = 1000000 + 10;
  int n, s, t, E, adj[MAXE], next[MAXE], last[MAXV], which[MAXV];
  long long totalCost, totalFlow, cap[MAXE], flow[MAXE], cost[MAXE], pot[MAXE],
      dist[MAXV];
  void init(int _n, int _s, int _t) {
    n = _n;
    s = _s;
    t = _t;
    memset(last, -1, sizeof(last));
    E = 0;
  }
  void add(int u, int v, long long ca, long long co) {
    adj[E] = v;
    cap[E] = ca;
    flow[E] = 0;
    cost[E] = +co;
    next[E] = last[u];
    last[u] = E++;
    adj[E] = u;
    cap[E] = 0;
    flow[E] = 0;
    cost[E] = -co;
    next[E] = last[v];
    last[v] = E++;
  }
  void bellman() {
    int stop = 0;
    fill_n(pot, n, 0);
    while (!stop) {
      stop = 1;
      for (int u = 0; u < n; u++)
        for (int e = last[u]; e != -1; e = next[e])
          if (flow[e] < cap[e]) {
            int v = adj[e];
            if (pot[v] > pot[u] + cost[e]) {
              pot[v] = pot[u] + cost[e];
              stop = 0;
            }
          }
    }
  }
  int dijkstra() {
    priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                   greater<pair<long long, int> > >
        que;
    for (int u = 0; u < n; u++) dist[u] = oo;
    dist[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
      long long dnow = que.top().first;
      int u = que.top().second;
      que.pop();
      if (dnow > dist[u]) continue;
      for (int e = last[u]; e != -1; e = next[e])
        if (flow[e] < cap[e]) {
          int v = adj[e];
          long long dnext = dnow + cost[e] + pot[u] - pot[v];
          if (dist[v] > dnext) {
            dist[v] = dnext;
            which[v] = e;
            que.push(make_pair(dnext, v));
          }
        }
    }
    return dist[t] < oo;
  }
  int maxflow(long long desireFlow = oo) {
    totalCost = totalFlow = 0;
    bellman();
    while (totalFlow < desireFlow) {
      if (!dijkstra()) return 0;
      long long delta = desireFlow - totalFlow;
      for (int v = t, e = which[v]; v != s; v = adj[e ^ 1], e = which[v])
        delta = min(delta, cap[e] - flow[e]);
      for (int v = t, e = which[v]; v != s; v = adj[e ^ 1], e = which[v]) {
        flow[e] += delta;
        flow[e ^ 1] -= delta;
      }
      totalFlow += delta;
      totalCost += delta * (dist[t] - pot[s] + pot[t]);
      for (int u = 0; u < n; u++) pot[u] += dist[u];
    }
    return 1;
  }
} mcf;
const int maxn = 500 + 10;
int n, m;
string s;
void solve() {
  cin >> n >> s;
  cin >> m;
  mcf.init(n + 2, n + 1, n);
  for (int i = (0); i < (m); i++) {
    string t;
    int p;
    cin >> t >> p;
    for (int i = (0); i < (n - int((t).size()) + 1); i++) {
      int found = 0;
      for (int j = (0); j < (int((t).size())); j++) {
        if (s[i + j] != t[j]) {
          found = 1;
          break;
        }
      }
      if (!found) {
        mcf.add(i, i + int((t).size()), 1, -p);
      }
    }
  }
  int x;
  cin >> x;
  for (int i = (0); i < (n); i++) mcf.add(i, i + 1, x, 0);
  mcf.add(n + 1, 0, x, 0);
  mcf.maxflow();
  cout << -mcf.totalCost << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}