You are given a string
sss of length
nnn, and there are some fixed positions in the string. You need to find a palindrome subsequence of
sss which contains all fixed positions and has the largest lexicographical order.
Formally, let the string
s=c1c2...cns=c_1c_2...c_ns=c1c2...cn, and the fixed positions
F={a1, a2, ..., am} (1≤ai≤n)F=\{a_1,\ a_2,\ ...,\ a_m\}\ \ (1\le a_i\le n)F={a1, a2, ..., am} (1≤ai≤n). You should find a sequence
P=(p1, p2, ..., pt)P=(p_1,\ p_2,\ ...,\ p_t)P=(p1, p2, ..., pt) (1≤pi≤n, pi<pi+1)(1\le p_i\le n,~\ p_i<p_{i+1})(1≤pi≤n, pi<pi+1) satisfying:
-
∀1≤i≤m, ai\forall 1\le i\le m, ~\ a_i∀1≤i≤m, ai appears in PPP.
-
cp1cp2...cptc_{p_1}c_{p_2}...c_{p_t}cp1cp2...cpt is a palindrome and its lexicographical order is the largest.
A string is a palindrome if it reads the same backwards as forwards.