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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Map;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            in.nextInt();
            String s = in.next();
            int m = in.nextInt();
            Map<String, Integer> all = new HashMap<>();
            for (int i = 0; i < m; i++) {
                String p = in.next();
                int c = in.nextInt();
                Integer got = all.get(p);
                if (got == null || got < c) {
                    got = c;
                }
                all.put(p, got);
            }
            final int X = in.nextInt();
            int n = s.length();
            TaskG.MinCostMaxFlowGraph g = new TaskG.MinCostMaxFlowGraph(n + 1);
            for (int i = 0; i < n; i++) {
                g.addEdge(i, i + 1, X, 0);
            }
            TaskG.Edge[] lastEdge = new TaskG.Edge[n + 1];
            long[] d = new long[n + 1];
            int[] q = new int[n + 2];
            boolean[] inQueue = new boolean[n + 1];
            long ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    String sub = s.substring(i, j);
                    if (!all.containsKey(sub)) continue;
                    int c = all.get(sub);
                    Arrays.fill(d, Long.MAX_VALUE);
                    d[i] = 0;
                    int head = 0;
                    int tail = 0;
                    q[tail++] = i;
                    inQueue[i] = true;
                    while (head != tail) {
                        int v = q[head++];
                        if (head == n + 2) {
                            head = 0;
                        }
                        inQueue[v] = false;
                        for (TaskG.Edge e : g.edges[v]) {
                            if (e.flow < e.cap && d[e.from] != Long.MAX_VALUE && d[e.to] > d[e.from] + e.cost) {
                                d[e.to] = d[e.from] + e.cost;
                                lastEdge[e.to] = e;
                                if (!inQueue[e.to]) {
                                    q[tail++] = e.to;
                                    inQueue[e.to] = true;
                                    if (tail == n + 2) tail = 0;
                                }
                            }
                        }
                    }
                    if (d[j] == Long.MAX_VALUE) continue;
                    long pathLen = -c + d[j];
                    if (pathLen >= 0) {
                        g.addEdge(j, i, 1, -c);
                        continue;
                    }
                    ans += pathLen;
                    for (int v = j; v != i; v = lastEdge[v].from) {
                        lastEdge[v].flow++;
                        lastEdge[v].rev.flow--;
                    }
                    g.addEdge(j, i, 1, 1, -c);
//                for (int v = 0; v <= n; v++) {
//                    for (Edge e : g.edges[v]) {
//                        System.out.println(e.from + " " + e.to + " " + e.flow + " " + e.cap + " " + e.cost);
//                    }
//                }
//                System.out.println("==========================");
                }
            }
            out.println(-ans);
        }

        public static class Edge {
            int from;
            int to;
            public int flow;
            int cap;
            long cost;
            TaskG.Edge rev;

            public Edge(int from, int to, int flow, int cap, long cost) {
                this.from = from;
                this.to = to;
                this.flow = flow;
                this.cap = cap;
                this.cost = cost;
            }


            public String toString() {
                return "Edge [from=" + from + ", to=" + to + ", flow=" + flow
                        + ", cap=" + cap + ", cost=" + cost + "]";
            }

        }

        static class MinCostMaxFlowGraph {
            int n;
            ArrayList<TaskG.Edge>[] edges;

            public MinCostMaxFlowGraph(int n) {
                this.n = n;
                edges = new ArrayList[n];
                for (int i = 0; i < edges.length; i++) {
                    edges[i] = new ArrayList<TaskG.Edge>();
                }
            }

            public TaskG.Edge addEdge(int from, int to, int cap, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, 0, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, 0, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            public TaskG.Edge addEdge(int from, int to, int cap, int flow, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, flow, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, -flow, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }


        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            if (c < 0) {
                return null;
            }
            while (c >= 0 && !isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}