Palindromic Subsequence

Given a string and marked positions, find a palindromic subsequence covering the most marked positions, and report the length of the longest such one.

Medium7Dynamic programmingStringNo attempts yetTime limit1sMemory limit512 MB

Problem

A palindrome is a string that reads the same backward as forward. For example, BANANAB is a palindrome and BANANAS is not.

A subsequence is a string obtained by deleting zero or more characters from the original string. For example, ANNA is a subsequence of BANANAS.

You are given a string SS and several distinct positions of SS, called the special positions. Among the subsequences of SS, find one that is a palindrome and contains as many special positions as possible. If several palindromic subsequences contain that maximum number of special positions, take the longest one among them and report its length.

Input

The first line contains a string SS of uppercase letters. The length of SS is between 1 and 2000.

The second line contains an integer NN (0NS0 \le N \le |S|), followed by NN distinct integers separated by spaces that give the special positions. Each integer is between 1 and S|S|, and they are not necessarily sorted. The first character of SS is at position 1.

Output

Print a single integer, the length of the palindromic subsequence described above.