CF1775A1.Gardener and the Capybaras (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an easy version of the problem. The difference between the versions is that the string can be longer than in the easy version. You can only do hacks if both versions of the problem are passed.

Kazimir Kazimirovich is a Martian gardener. He has a huge orchard of binary balanced apple trees.

Recently Casimir decided to get himself three capybaras. The gardener even came up with their names and wrote them down on a piece of paper. The name of each capybara is a non-empty line consisting of letters "a" and "b".

Denote the names of the capybaras by the lines aa , bb , and cc . Then Casimir wrote the nonempty lines aa , bb , and cc in a row without spaces. For example, if the capybara's name was "aba", "ab", and "bb", then the string the gardener wrote down would look like "abaabbb".

The gardener remembered an interesting property: either the string bb is lexicographically not smaller than the strings aa and cc at the same time, or the string bb is lexicographically not greater than the strings aa and cc at the same time. In other words, either aba \le b and cbc \le b are satisfied, or bab \le a and bcb \le c are satisfied (or possibly both conditions simultaneously). Here \le denotes the lexicographic "less than or equal to" for strings. Thus, aba \le b means that the strings must either be equal, or the string aa must stand earlier in the dictionary than the string bb . For a more detailed explanation of this operation, see "Notes" section.

Today the gardener looked at his notes and realized that he cannot recover the names because they are written without spaces. He is no longer sure if he can recover the original strings aa , bb , and cc , so he wants to find any triplet of names that satisfy the above property.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t5001 \le t \le 500 ). The description of the test cases follows.

The only line of a test case contains the string ss ( 3s1003 \le |s| \le 100 ) — the names of the capybaras, written together. The string consists of English letters 'a' and 'b' only.

It is guaranteed that the sum of string lengths over all test cases does not exceed 500500 .

输出格式

For each test case, print three strings aa , bb and cc on a single line, separated by spaces — names of capybaras, such that writing them without spaces results in a line ss . Either aba \le b and cbc \le b , or bab \le a and bcb \le c must be satisfied.

If there are several ways to restore the names, print any of them. If the names cannot be recovered, print ":(" (without quotes).

输入输出样例

  • 输入#1

    5
    bbba
    aba
    aaa
    abba
    abbb

    输出#1

    b bb a
    a b a
    a a a
    ab b a
    a bb b

说明/提示

A string xx is lexicographically smaller than a string yy if and only if one of the following holds:

  • xx is a prefix of yy , but xyx \ne y ;
  • in the first position where xx and yy differ, the string xx has the letter 'a', and the string yy has the letter 'b'.

Now let's move on to the examples.

In the first test case, one of the possible ways to split the line ss into three lines — "b", "bb", "a".

In the third test case, we can see that the split satisfies two conditions at once (i. e., aba \le b , cbc \le b , bab \le a , and bcb \le c are true simultaneously).

首页