[Solution] Palindrome Pain solution codechef

Palindrome Pain solution codechef – You are given two integers XX and YY. You need to construct two different strings S1S1 and S2S2 consisting of only the characters a‘a′ and b‘b′, such that the following conditions are satisfied:

[Solution] Palindrome Pain solution codechef

  1. Both S1S1 and S2S2 are palindromes.
  2. Both S1S1 and S2S2 should contain exactly XX occurrences of 𝚊a and YY occurrences of 𝚋b.

If there are multiple possible answers, you may print any of them. If it is not possible to construct two distinct strings satisfying the conditions, print 1−1 instead.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing two space-separated integers X,YX,Y.

Output Format

For each test case:

  • If it is not possible to construct two distinct strings satisfying the conditions, print 1−1
  • Otherwise, print two lines — the first should contain the string S1S1 and the second should contain S2S2
  • If there are multiple possible answers, you may print any of them.

[Solution] Palindrome Pain solution codechef

  • 1T10001≤T≤1000
  • 1X,Y1031≤X,Y≤103

Sample Input 1 

2
2 4
3 3

Sample Output 1 

abbbba
babbab
-1

Palindrome Pain solution Explanation

Test case 11: The three palindromes containing 22 𝚊a-s and 44 𝚋b-s are 𝚊𝚋𝚋𝚋𝚋𝚊,𝚋𝚊𝚋𝚋𝚊𝚋,abbbba,babbab, and 𝚋𝚋𝚊𝚊𝚋𝚋bbaabb. Printing any two of these is a valid answer.

Test case 22: There are no palindromes containing 33 each of 𝚊a and 𝚋b.

Leave a Comment