3930.LLPS

Time Limit: 1s Memory Limit: 256MB

This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.

You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.

We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 \le p1 \lt p2 \lt ... \lt pk \le |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| \gt |y| and x1=y1, x2=y2, ...,x|y|=y|y|, or there exists such number r (r \lt |x|, r \lt |y|) that x1=y1, x2=y2, ..., xr=yr and xr+1 \gt yr+1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".

String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s|-1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

Input Format(From the terminal/stdin)

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Output Format(To the terminal/stdout)

Print the lexicographically largest palindromic subsequence of string s.

Sample Input 1

Copy
radar
     \n

Sample Output 1

Copy
rr
  \n

Sample Input 2

Copy
bowwowwow
         \n

Sample Output 2

Copy
wwwww
     \n

Sample Input 3

Copy
codeforces
          \n

Sample Output 3

Copy
s
 \n

Sample Input 4

Copy
mississipp
          \n

Sample Output 4

Copy
ssss
    \n

Hints

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

Submit

请先 登录

© 2025 FAQs