DWITE '11 R1 #5 - Tattarrattat

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE, October 2011, Problem 5

A palindrome is a word that is the same backwards as it is forwards (e.g. tattarrattat). Even though most words aren't palindromes, you can always remove letters from the word to make it a palindrome (remember that all words of length 0 or 1 are palindromes). For example, "farmer" is not a palindrome, but removing a few letters yields "rer", which is a palindrome.

Your task is to determine the length of the longest palindrome you can get from a word by removing zero or more letters.

The input will contain 5 test cases, each a line with a string S consisting of no more than 255 alphanumeric characters (a-z, A-Z, 0-9). There are no spaces.

For each test case, print one line, each a number — the length of the longest palindrome you can get by removing zero or more letters from the corresponding string.

Sample Input


Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.