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 T1, class T2>
std::ostream& operator<<(std::ostream& os, const pair<T1, T2>& p) {
  os << "[" << p.first << ", " << p.second << "]";
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  bool first = true;
  for (typename std::vector<T>::const_iterator it = v.begin(); it != v.end();
       ++it) {
    if (!first) os << ", ";
    first = false;
    os << *it;
  }
  os << "]";
  return os;
}
vector<string> _split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return v;
}
void _print(vector<string>::iterator) {}
template <typename T, typename... Args>
void _print(vector<string>::iterator it, T a, Args... args) {
  string name = it->substr((*it)[0] == ' ', it->length());
  if (isalpha(name[0]))
    cerr << name << " = " << a << " ";
  else
    cerr << name << " ";
  _print(++it, args...);
}
struct Edge {
  int v, to, flow, cap, cost;
  Edge() : v(), to(), flow(), cap(), cost() {}
  Edge(int _v, int _to, int _cap, int _cost)
      : v(_v), to(_to), flow(0), cap(_cap), cost(_cost) {}
};
const int V = 600;
const int E = (int)1e6;
const int M = 150;
const int INF = (int)1e9;
vector<int> g[V];
int e_cnt;
Edge e_list[E];
int s, t;
int n;
string str;
int m;
string pat[M];
int p[M];
int x;
bool in_q[V];
int dist[V];
int par_v[V];
int par_e[V];
void add_edge(int v, int to, int cap, int cost) {
  {
    if (0) {
      _print(_split("v, to, cap, cost", ',').begin(), v, to, cap, cost);
      cerr << endl;
    } else {
      void(0);
    }
  };
  e_list[e_cnt] = Edge(v, to, cap, cost);
  g[v].push_back(e_cnt);
  e_cnt++;
  e_list[e_cnt] = Edge(to, v, 0, -cost);
  g[to].push_back(e_cnt);
  e_cnt++;
}
string read_string() {
  string ss;
  cin >> ss;
  return ss;
}
int main() {
  scanf("%d", &n);
  str = read_string();
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    pat[i] = read_string();
    scanf("%d", &p[i]);
  }
  scanf("%d", &x);
  s = 0;
  t = n + 1;
  {
    if (0) {
      _print(_split("s, t", ',').begin(), s, t);
      cerr << endl;
    } else {
      void(0);
    }
  };
  for (int i = 0; i <= n; i++) add_edge(i, i + 1, x, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str.substr(i, (int)pat[j].length()) != pat[j]) continue;
      add_edge(i + 1, (i + 1) + (int)pat[j].length(), 1, p[j]);
    }
  }
  int ans = 0;
  queue<int> q;
  while (true) {
    fill(dist, dist + V, -INF);
    dist[s] = 0;
    q.push(s);
    in_q[s] = true;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      in_q[v] = false;
      for (int e_id : g[v]) {
        int to = e_list[e_id].to;
        int can = e_list[e_id].cap - e_list[e_id].flow;
        if (can > 0 && dist[to] < dist[v] + e_list[e_id].cost) {
          dist[to] = dist[v] + e_list[e_id].cost;
          par_v[to] = v;
          par_e[to] = e_id;
          if (!in_q[to]) {
            in_q[to] = true;
            q.push(to);
          }
        }
      }
    }
    if (dist[t] == -INF) break;
    int push = INF;
    for (int i = t; i != s; i = par_v[i]) {
      int e_id = par_e[i];
      push = min(push, e_list[e_id].cap - e_list[e_id].flow);
    }
    for (int i = t; i != s; i = par_v[i]) {
      int e_id = par_e[i];
      ans += e_list[e_id].cost * push;
      e_list[e_id].flow += push;
      e_list[e_id ^ 1].flow -= push;
    }
  }
  printf("%d\n", ans);
  return 0;
}