Splitology
InterviewTime limit1sMemory limit1024 MB
Given a lowercase string of length up to 500, find a split into two non-empty palindromes, or report NO if none exists.
- Level
Easy2 of 10
- Topics
- String, Brute force
- Solved
- No attempts yet
Problem
Yosef is a peculiar fellow. He introduced the idea to study a string by splitting it into two, and he called it Splitology. Why split a string? We do not know. Didn't we say that Yosef is a weird one?
Yosef is interested in one particular type of string, a palindrome. A palindrome is a string that reads the same forwards and backwards. For example, "ada", "taat", and "radar" are palindromes. On the other hand, "taman" is not a palindrome, since reading it backwards gives "namat".
The idea of Splitology is still new, so Yosef is checking whether a string can be split into two non-empty strings where each string is a palindrome.
For example, "malamini" can be split into "malam" and "ini", and both are palindromes. "ababab" can be split into "aba" and "bab", and both are palindromes. "ababab" can also be split into "ababa" and "b", or into "a" and "babab".
Gunawan, a friend of Yosef, is also peculiar. When he learned about Splitology, he asked Yosef whether "irvinganteng" can be split into two palindromes. The answer is no, and it can be proven that such a split does not exist.
Input
The input is a single line containing a string S. S contains only lowercase letters (a-z), and its length is between 2 and 500, inclusive.
Output
If S cannot be split into two palindromes, print "NO" on a line. Otherwise, print two palindromes A and B on one line, separated by a single space, such that S = A + B. If there is more than one valid split, print any one of them.