LogiQuest

236. Minimum Insertions for Palindrome

MediumDynamic Programming

Print the minimum number of characters to insert anywhere to make s a palindrome.

Input format

A single line.

Output format

The minimum insertions.

Example 1

Input

zzazz

Output

0

Example 2

Input

mbadm

Output

2

Constraints

1 ≤ |s| ≤ 1000

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

Loading the MyLoginn IDE…