n=gets.size-1;p (n...n*n).map{|x|t=$_.chop[x%n,x/n];t!=t.reverse ? 0:x/n}.max