#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
mt19937 ggen;
const int MAXN = 100100;
struct edge {
  int fr;
  int to;
  int w;
  int c;
  int back;
  edge() {}
  edge(int fr, int to, int w, int c, int back)
      : fr(fr), to(to), w(w), c(c), back(back) {}
};
int n, m, x;
string s;
string a[110];
int w[110];
vector<vector<edge> > g;
int d[510];
edge *pre[510];
bool u[510];
void conn(int a, int b, int c, int w = 0) {
  int sa = g[a].size();
  int sb = g[b].size();
  g[a].push_back(edge(a, b, w, c, sb));
  g[b].push_back(edge(b, a, -w, 0, sa));
}
vector<int> q;
int ql;
void levit(int v) {
  q.clear();
  ql = 0;
  q.push_back(v);
  memset(d, 0x7f, sizeof(int) * (n + 1));
  memset(pre, 0, sizeof(edge *) * (n + 1));
  d[v] = 0;
  u[v] = 1;
  while (ql != q.size()) {
    v = q[ql];
    ql++;
    u[v] = 0;
    for (int i = 0; i < (int)g[v].size(); i++) {
      edge *e = &g[v][i];
      if (!e->c) continue;
      if (d[e->to] > d[v] + e->w) {
        d[e->to] = d[v] + e->w;
        pre[e->to] = e;
        if (!u[e->to]) {
          u[e->to] = 1;
          q.push_back(e->to);
        }
      }
    }
  }
}
void push(int a, int b, int w) {
  levit(a);
  int cc = 1;
  if (d[b] <= w) {
    cc = 0;
    edge *e = pre[b];
    while (e) {
      e->c--;
      g[e->to][e->back].c++;
      e = pre[e->fr];
    }
  }
  int sb = g[b].size();
  int sa = g[a].size();
  g[b].push_back(edge(b, a, -w, cc, sa));
  g[a].push_back(edge(a, b, w, 1 - cc, sb));
}
void solve() {
  cin >> n;
  g.resize(n + 1);
  cin >> s;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> w[i];
  }
  cin >> x;
  for (int i = 1; i <= n; i++) {
    conn(i - 1, i, x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int len = n - i;
    for (int j = 0; j < m; j++) {
      int wlen = a[j].size();
      if (wlen > len) continue;
      bool was = false;
      for (int k = i; k < i + wlen && !was; k++)
        if (s[k] != a[j][k - i]) was = true;
      if (!was) push(i, i + wlen, w[j]);
    }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < (int)g[i].size(); j++)
      if (g[i][j].w < 0) ans += (1 - g[i][j].c) * g[i][j].w;
  cout << -ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ggen = mt19937(13);
  solve();
  return 0;
}
