LogiQuest

235. Longest Palindromic Subsequence

MediumDynamic Programming

Print the length of the longest subsequence of s that is a palindrome.

Input format

A single line.

Output format

The length.

Example 1

Input

bbbab

Output

4

Example 2

Input

cbbd

Output

2

Constraints

1 ≤ |s| ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…