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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class G {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static class Age {
		int id, c, u, f, id_to;
		public Age(int to, int c, int u, int f, int id_to) {
			this.id = to;
			this.c = c;
			this.u = u;
			this.f = f;
			this.id_to = id_to;
		}
	}
	static ArrayList<Age>[]ages;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		String s = next();
		int source = 0, target = n+1;
		int m = nextInt();
		ages = new ArrayList[target+1];
		for (int i = 0; i <= target; i++) {
			ages[i] = new ArrayList<Age>();
		}
		for (int i = 0; i < m; i++) {
			String t = next();
			int cost = nextInt();
			for (int j = 0; j <= s.length()-t.length(); j++) {
				if (s.substring(j, j+t.length()).equals(t)) {
					addAge(j+1, j+t.length()+1, 1, -cost);
				}
			}
		}
		int x = nextInt();
		int INF = (int) 1e4;
		addAge(source, 1, x, 0);
		for (int i = 1; i <= n; i++) {
			addAge(i, i+1, INF, 0);
		}
		System.out.println(-minCostFlow(source, target));
		pw.close();
	}
	private static int minCostFlow(int source, int target) {
		int res = 0;
		int[]d = new int[target+1];
		int INF = (int) 1e9;
		Deque<Integer> dq = new LinkedList<>();
		int[]id = new int[target+1];
		int[]p = new int[target+1];
		int[]p_age = new int[target+1];
		while (true) {
			dq.add(source);
			Arrays.fill(id, 2);
			Arrays.fill(p, -1);
			id[source] = 1;
			Arrays.fill(d, INF);
			d[source] = 0;
			while (!dq.isEmpty()) {
				int v = dq.pollFirst();
				id[v] = 0;
				int id_age = 0;
				for (Age to : ages[v]) {
					if (d[v] + to.c < d[to.id] && to.u-to.f > 0) {
						d[to.id] = d[v] + to.c;
						p[to.id] = v;
						p_age[to.id] = id_age;
						if (id[to.id]==0)
							dq.addFirst(to.id);
						else if (id[to.id]==2)
							dq.addLast(to.id);
						id[to.id] = 1;
					}
					id_age++;
				}
			}
			if (d[target]==INF)
				break;
			int cur = target;
			int addFlow = INF;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				addFlow = Math.min(addFlow, ages[prev].get(id_age).u-ages[prev].get(id_age).f);
				if (prev==source)
					break;
				cur = prev;
			}
			cur = target;
			int cost = 0;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				Age age = ages[prev].get(id_age);
				age.f += addFlow;
				cost += addFlow * age.c;
				ages[prev].set(id_age, age);
				id_age = age.id_to;
				age = ages[cur].get(id_age);
				age.f -= addFlow;
				ages[cur].set(id_age, age);
				if (prev==source)
					break;
				cur = prev;
			}
			res += cost;
		}
		return res;
	}
	private static void addAge(int i, int j, int flow, int cost) {
		ages[i].add(new Age(j, cost, flow, 0, ages[j].size()));
		ages[j].add(new Age(i, -cost, 0, 0, ages[i].size()-1));
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}