Longest Palindromic Subsequence


Given a string ss, find the length of the longest subsequence of ss that is a palindrome.

A subsequence is formed by deleting zero or more characters without changing the order of the remaining characters. A palindrome reads the same forwards and backwards.

Input

The first line contains an integer nn, the length of the string.

The second line contains the string ss.

Output

Output one integer: the length of the longest palindromic subsequence of ss.

Constraints

  • 1n50001 \le n \le 5000
  • ss consists only of lowercase English letters.
Subtasks
  • For 20 points, n20n \le 20.
  • For 30 points, n500n \le 500.
  • For 50 points, no additional constraints.

Example 1

Input 1
5
bbbab
Output 1
4
Explanation

One longest palindromic subsequence is bbbb.

Example 2

Input 2
4
cbbd
Output 2
2
Explanation

One longest palindromic subsequence is bb.

Example 3

Input 3
6
agbdba
Output 3
5
Explanation

One longest palindromic subsequence is abdba.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.