#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<long long, int>;
using pii = pair<int, int>;
const int N = 500 + 7, M = 107, N2 = 1e3 + 7;
const ll mod = 1e9 + 5, base1 = 311, base2 = 331;
int n, m, x;
string s, w[N];
int p[N], dp[N], res;
int Max[N];
ll power1[N], power2[N];
ll hashs1[N], hashs2[N];
ll hashw1[M], hashw2[M];
bool _check(int r, int j) {
  int l = r - w[j].size() + 1;
  return l >= 1 &&
         hashw1[j] ==
             (hashs1[r] - hashs1[l - 1] * power1[r - l + 1] + mod * mod) %
                 mod &&
         hashw2[j] ==
             (hashs2[r] - hashs2[l - 1] * power2[r - l + 1] + mod * mod) % mod;
}
void _hashcal() {
  power1[0] = power2[0] = 1;
  for (int i = 1; i <= n; ++i) {
    power1[i] = power1[i - 1] * base1 % mod;
    power2[i] = power2[i - 1] * base2 % mod;
  }
  for (int i = 1; i <= n; ++i) {
    hashs1[i] = (hashs1[i - 1] * base1 + s[i]) % mod;
    hashs2[i] = (hashs2[i - 1] * base2 + s[i]) % mod;
  }
  for (int i = 1; i <= m; ++i) {
    int l = w[i].size();
    for (int j = 0; j < l; ++j) {
      hashw1[i] = (hashw1[i] * base1 + w[i][j]) % mod;
      hashw2[i] = (hashw2[i] * base2 + w[i][j]) % mod;
    }
  }
}
void _sub1() {
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    for (int j = 1; j <= m; ++j)
      if (_check(i, j)) dp[i] = max(dp[i], dp[i - w[j].size()] + p[j]);
  }
  res = dp[n];
}
int c[N2][N2], f[N2][N2];
int cost[N2][N2];
int cnt[N2];
int pre[N2], d[N2];
bool inq[N2];
int _find() {
  queue<int> q;
  q.push(1);
  fill(d, d + N2, 1e9);
  d[1] = 0;
  fill(pre, pre + N2, 0);
  fill(cnt, cnt + N2, 0);
  fill(inq, inq + N2, false);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = false;
    for (int v = 1; v <= n * 2 + 1; ++v)
      if (f[u][v] < c[u][v]) {
        int curcost = ((f[u][v] >= 0) ? 1 : -1) * cost[u][v];
        if (d[u] + curcost < d[v]) {
          d[v] = d[u] + curcost;
          pre[v] = u;
          if (!inq[v]) {
            inq[v] = true;
            q.push(v);
          }
        }
      }
  }
  return d[n + 1];
}
void _inc(int Min) {
  for (int u, v = n + 1; v; v = u) {
    u = pre[v];
    ++f[u][v];
    --f[v][u];
  }
  res -= Min;
}
void _full() {
  for (int i = 1; i <= n; ++i) c[i][i + n + 1] = c[i + n + 1][i + 1] = 100;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (_check(i, j)) {
        int l = i - w[j].size() + 1;
        c[l][i + 1] = 1;
        cost[l][i + 1] = cost[i + 1][l] = -p[j];
      }
  for (int i = 1; i <= x; ++i) {
    int Min = _find();
    if (Min == 0) break;
    _inc(Min);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> s >> m;
  s = ' ' + s;
  for (int i = 1; i <= m; ++i) cin >> w[i] >> p[i];
  cin >> x;
  _hashcal();
  if (x == 1)
    _sub1();
  else
    _full();
  cout << res;
  return 0;
}
