class String def palindrome? self == self.reverse end end s = gets.chomp n, m = s.size, s.size / 2 pos = (0...m).find { s[_1] != s[~_1] } if pos t = s[pos..~pos] if x = [t + t[0], t[-1] + t].find(&:palindrome?) s[pos..~pos] = x puts s else puts 'NA' end else if n.even? puts s[...m] + 'a' + s[m..] else puts s[...m] + s[m] + s[m..] end end