This post is all about the solution of the A2. Gardener and the Capybaras (hard version) Codeforces Round #843 (Div. 2) Problem solution.

A2. Gardener and the Capybaras (hard version) Codeforces Round #843 (Div. 2) Problem solution

Codeforces



Problem Statement :

Kazimir Kazimirovich works as a gardener on Mars. He has a massive apple orchard full of binary balanced apple trees.

Casimir recently decided to get himself three capybaras. The gardener even came up with their names and scribbled them down on paper. Each capybara's name is a non-empty line with the letters "a" and "b" in it.

The lines a, b, and c represent the names of the capybaras. Casimir then wrote the nonempty lines a, b, and c without spaces in a row. For example, if the capybara's name was "aba", "ab", and "bb", the gardener's string would be "abaabbb".

The gardener remembered an intriguing property: either the string b is not smaller lexicographically than the strings a and


Format of Input :

Each test contains a number of test cases. The first line contains the number t (1t500) of test cases. The test cases are described below.

A test case's only line contains the string s (3|s|100) — the capybaras' names written together. The string only contains the English letters 'a' and 'b'.

The sum of string lengths across all test cases is guaranteed not to exceed 500.


Format of the Output :

For every test case, print three strings a, b, and c separated by spaces on a single line — capybara names, such that writing them without spaces results in a line s. ab and cb, or ba and bc, must be satisfied.

If you have several options for restoring the names, print any of them. If the names are unable to be recovered, print ":(" (without quotes)


New Upcoming OnePlus 11 Specifications

New Upcoming OnePlus 11 Specifications, Click Here

Also Check this out:-

A1. Gardener and the Capybaras (easy version) Codeforces Round #843 (Div. 2) Problem solution, Click Here
A2. Gardener and the Capybaras (hard version) Codeforces Round #843 (Div. 2) Problem solution, Click Here
B. Gardener and the Array Codeforces Round #843 (Div. 2) Problem solution, Click Here
C. Interesting Sequence Codeforces Round #843 (Div. 2) Problem solution, Click Here
D. Friendly Spiders Codeforces Round #843 (Div. 2) Problem solution, Click Here
Solution of the Problem: Click Here