def kaibun_parse(str,l) str1 = str[0..l-1] l.times{|i| tmp = str1[i..l-1] if tmp == tmp.reverse && tmp != str return tmp end } end def kaibun_max(str,n) if n == 0 return "" else return [kaibun_max(str,n-1),kaibun_parse(str,n)].max{|a,b|a.size <=> b.size} end end s = gets puts kaibun_max(s,s.size).size