#K48692. Generate Palindromic Strings

    ID: 28477 Type: Default 1000ms 256MiB

Generate Palindromic Strings

Generate Palindromic Strings

You are given a single integer (n). Your task is to generate all distinct palindromic strings of length (n) using lowercase English letters.

A palindromic string is defined as a string that reads the same backward as forward. Note that:

  • If (n = 0), output nothing (i.e. an empty list).
  • If (n = 1), output all 26 single-letter strings from 'a' to 'z'.
  • If (n > 1) and (n) is odd, output nothing.
  • If (n > 1) and even, construct palindromes by generating a half string of length (\frac{n}{2}) and then appending its reverse.

The answer should be printed to standard output, where each palindromic string is printed on a separate line. If there is no valid palindrome, print nothing.

inputFormat

The input consists of a single integer (n) given on standard input. (n) can be 0, 1, or any non-negative integer. For the purpose of this problem, note that generating palindromes for odd (n > 1) is not possible except for (n = 1).

outputFormat

Print each valid palindromic string on a new line to standard output. If there are no palindromic strings (for example, when (n = 0) or when (n) is odd and greater than 1), output nothing.## sample

0