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>
const long double EPS = 1e-10;
const long long int MOD = 1000000007ll;
const long long int mod1 = 1000000009ll;
const long long int mod2 = 1100000009ll;
int INF = (int)1e9;
long long int INFINF = (long long int)1e18;
int debug = 0;
using namespace std;
void print(int a[], int s, int e) {
  for (int i = s; i <= e; i++) cout << a[i] << " ";
  cout << "\n";
}
void print(vector<int> &v, int s, int e) {
  for (int i = s; i <= e; i++) cout << v[i] << " ";
  cout << "\n";
}
void print(vector<int> &v) {
  for (int x : v) cout << x << " ";
  cout << "\n";
}
long long int bit_count(long long int _x) {
  long long int _ret = 0;
  while (_x) {
    if (_x % 2 == 1) _ret++;
    _x /= 2;
  }
  return _ret;
}
long long int bit(long long int _mask, long long int _i) {
  return (_mask & (1 << _i)) == 0 ? 0 : 1;
}
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long int add(long long int a, long long int b, long long int m = MOD) {
  long long int x = a + b;
  while (x >= m) x -= m;
  return x;
}
long long int sub(long long int a, long long int b, long long int m = MOD) {
  long long int x = a - b;
  while (x < 0) x += m;
  return x;
}
long long int mul(long long int a, long long int b, long long int m = MOD) {
  long long int x = a * b;
  x %= m;
  return x;
}
struct Edge {
  long long int b, c, u, f, back;
};
class MCMF {
 private:
  long long int s, t, n;
  vector<vector<Edge> > g;
  long long int inf;

 public:
  MCMF(long long int _s, long long int _t, long long int _n) {
    inf = (long long int)1e18;
    s = _s;
    t = _t;
    n = _n;
    g.resize(n);
  }
  void addEdge(long long int from, long long int to, long long int cost,
               long long int cap) {
    Edge e1 = {to, cost, cap, 0, (long long int)g[to].size()};
    Edge e2 = {from, -cost, 0, 0, (long long int)g[from].size()};
    g[from].push_back(e1);
    g[to].push_back(e2);
  }
  long long int minCostMaxFlow() {
    long long int flow = 0;
    long long int cost = 0;
    long long int *state = new long long int[n];
    long long int *from = new long long int[n];
    long long int *from_edge = new long long int[n];
    long long int *d = new long long int[n];
    long long int *q = new long long int[n];
    long long int qh, qt;
    qh = 0, qt = 0;
    while (true) {
      for (long long int i = 0; i < n; i++) state[i] = 2, d[i] = inf;
      fill(from, from + n, -1);
      state[s] = 1;
      q[qh++] = s;
      d[s] = 0;
      while (qh != qt) {
        long long int v = q[qt++];
        qt %= n;
        state[v] = 0;
        for (long long int i = 0; i < g[v].size(); i++)
          if (g[v][i].f < g[v][i].u && d[g[v][i].b] > d[v] + g[v][i].c) {
            long long int to = g[v][i].b;
            d[to] = d[v] + g[v][i].c;
            from[to] = v;
            from_edge[to] = i;
            if (state[to] == 1) continue;
            if (!state[to]) {
              qt--;
              if (qt == -1) qt = n - 1;
              q[qt] = to;
              state[to] = 1;
            } else {
              state[to] = 1;
              q[qh++] = to;
              qh %= n;
            }
          }
      }
      if (d[t] == inf) break;
      long long int it = t;
      long long int addflow = inf;
      while (it != s) {
        addflow = min(addflow, g[from[it]][from_edge[it]].u -
                                   g[from[it]][from_edge[it]].f);
        it = from[it];
      }
      it = t;
      while (it != s) {
        g[from[it]][from_edge[it]].f += addflow;
        g[it][g[from[it]][from_edge[it]].back].f -= addflow;
        cost += g[from[it]][from_edge[it]].c * addflow;
        it = from[it];
      }
      flow += addflow;
    }
    return cost;
  }
};
int N, M, X;
string second;
int main() {
  if (0) {
    freopen("input.txt", "r", stdin);
    debug = 1;
  }
  srand(time(NULL));
  cin >> N;
  MCMF mcmf(0, N + 1, N + 2);
  cin >> second;
  second = ' ' + second;
  cin >> M;
  for (int i = 1; i <= M; i++) {
    string t;
    int p;
    cin >> t >> p;
    int l = t.size();
    t = ' ' + t;
    for (int j = 1; j <= N - l + 1; j++) {
      if (second.substr(j, l) == t.substr(1, l)) {
        mcmf.addEdge(j, j + l, -p, 1);
      }
    }
  }
  cin >> X;
  for (int i = 1; i <= N + 1; i++) mcmf.addEdge(i - 1, i, 0, X);
  cout << (-mcmf.minCostMaxFlow());
  return 0;
}