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;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long long first, second;
  pt() {}
  pt(long long first, long long second) : first(first), second(second) {}
  inline pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second);
  }
  inline pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second);
  }
  inline pt operator*(const long double &r) const {
    return pt(first * r, second * r);
  }
  inline long long sqlen() const {
    return abs(first * first + second * second);
  }
  inline bool operator<(const pt &r) const {
    if (first != r.first) return first < r.first;
    return second < r.second;
  }
  inline bool operator==(const pt &r) const {
    return first == r.first && second == r.second;
  }
};
ostream &operator<<(ostream &os, const pt &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
inline long long cross(const pt &l, const pt &r) {
  return l.first * r.second - l.second * r.first;
}
inline long long dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
template <typename T>
inline T sqr(T first) {
  return first * first;
}
const long long INF = LLONG_MAX;
struct Edge {
  int fr, to;
  long long c, cost, f;
  Edge() {}
  Edge(int fr, int to, long long c, long long cost)
      : fr(fr), to(to), c(c), cost(cost), f(0) {}
};
const int N = 510;
struct G {
  vector<Edge> e;
  vector<int> g[N];
  char u[N];
  long long d[N];
  int q[N];
  int p[N];
  int n, s, t;
  void addEdge(int fr, int to, long long c, long long cost) {
    g[fr].push_back(int(e.size()));
    e.push_back(Edge(fr, to, c, cost));
    g[to].push_back(int(e.size()));
    e.push_back(Edge(to, fr, 0, -cost));
  }
  bool fb() {
    memset(p, -1, n * sizeof(int));
    memset(d, 0x3f, n * sizeof(long long));
    memset(u, 0, n * sizeof(char));
    d[s] = 0;
    u[s] = 1;
    int q1 = 0, q2 = 0;
    q[q2++] = s;
    while (q1 != q2) {
      int v = q[q1++];
      if (q1 == N) q1 = 0;
      u[v] = 0;
      for (int id : g[v]) {
        if (e[id].f == e[id].c) continue;
        int to = e[id].to;
        long long len = e[id].cost;
        if (d[to] > d[v] + len) {
          d[to] = d[v] + len;
          p[to] = id;
          if (!u[to]) {
            q[q2++] = to;
            if (q2 == N) q2 = 0;
            u[to] = 1;
          }
        }
      }
    }
    return p[t] != -1;
  }
  long long push(long long pushed = INF) {
    int v = t;
    while (v != s) {
      pushed = min(pushed, e[p[v]].c - e[p[v]].f);
      v = e[p[v]].fr;
    }
    v = t;
    while (v != s) {
      e[p[v]].f += pushed;
      e[p[v] ^ 1].f -= pushed;
      v = e[p[v]].fr;
    }
    return pushed;
  }
  pair<long long, long long> minCostFlow(int S, int T, long long need) {
    s = S, t = T;
    long long flow = 0;
    long long cost = 0;
    while (fb() && need > 0) {
      long long add = push(need);
      cost += add * d[t];
      flow += add;
    }
    return make_pair(flow, cost);
  }
};
char buf[10000];
inline void solve() {
  int n = nxt();
  scanf("%s", buf);
  string s = buf;
  int m = nxt();
  vector<pair<string, int> > a(m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%s", buf);
    string t = buf;
    int c = nxt();
    a[i].first = t;
    a[i].second = c;
  }
  int first = nxt();
  G g;
  g.n = n + 2;
  for (int i = 0; i < (int)(n + 1); i++) {
    g.addEdge(i, i + 1, first, 0);
  }
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(max(0, int(n - a[i].first.length() + 1))); j++) {
      if (s.substr(j, a[i].first.length()) == a[i].first) {
        g.addEdge(j + 1, j + a[i].first.length() + 1, 1, -a[i].second);
      }
    }
  }
  auto res = g.minCostFlow(0, n + 1, first);
  cout << -res.second << "\n";
}
void prepare() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  prepare();
  int t = 1;
  for (int i = 0; i < (int)(t); i++) {
    solve();
  }
  return 0;
}