Problem: Takahashi has decided to give a string to his mother.

The value of a string T is the length of the longest common subsequence of T and T', where T' is the string obtained by reversing T. That is, the value is the longest length of the following two strings that are equal: a subsequence of T (possibly non-contiguous), and a subsequence of T' (possibly non-contiguous).

Takahashi has a string S. He wants to give her mother a string of the highest possible value, so he would like to change at most K characters in S to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable.

Constraints

* 1 \leq |S| \leq 300
* 0 \leq K \leq |S|
* S consists of lowercase English letters.
* K is an integer.

Input

Input is given from Standard Input in the following format:


S
K


Output

Print the highest possible value achievable.

Examples

Input

abcabcabc
1


Output

7


Input

atcodergrandcontest
3


Output

15

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;


    void solve() {
        char[] s = in.next().toCharArray();
        int n = s.length;
        int maxChange = in.nextInt();
        int[][][] dp = new int[maxChange + 2][n][n];
        for (int i = 0; i < n; i++) {
            dp[0][i][i] = 1;
            if (i + 1 < n) {
                if (s[i] == s[i + 1]) {
                    dp[0][i][i + 1] = 2;
                } else {
                    dp[1][i][i + 1] = 2;
                }
            }
        }
        for (int len = 1; len <= n; len++) {
            for (int fr = 0; fr + len <= n; fr++) {
                int to = fr + len - 1;
                for (int ch = 0; ch <= maxChange; ch++) {
                    int cur = dp[ch][fr][to];
                    if (fr > 0) {
                        dp[ch][fr - 1][to] = Math.max(dp[ch][fr - 1][to], cur);
                    }
                    if (to + 1 < n) {
                        dp[ch][fr][to + 1] = Math.max(dp[ch][fr][to + 1], cur);
                    }
                    if (fr > 0 && to + 1 < n) {
                        if (s[fr - 1] == s[to + 1]) {
                            dp[ch][fr - 1][to + 1] = Math.max(dp[ch][fr - 1][to + 1], cur + 2);
                        } else {
                            dp[ch + 1][fr - 1][to + 1] = Math.max(dp[ch + 1][fr - 1][to + 1], cur + 2);
                        }
                    }
                }
            }
        }
        int res = 0;
        for (int ch = 0; ch <= maxChange; ch++) {
            res = Math.max(res, dp[ch][0][n - 1]);
        }
        out.println(res);
    }


    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}