AlgoUniversity
  • Go Back
Discussion
Construct String :

Author

Shikhar Mehrotra

Difficulty Level : Medium

Submissions : 1039

Asked In : American-Express

Marks :20

: 13 | : 1

Given a string $$$S$$$ with combinations of $$$a,b,?$$$ where $$$?$$$ can be replaced with either $$$a$$$ or $$$b$$$.

Your task is to construct a lexicographically smallest valid string if it is possible by replacing all $$$?$$$ with either $$$a$$$ or $$$b$$$ such that the string should not have substring of length $$$3$$$ which has all same characters.

For example $$$aaabb$$$ is invalid because $$$aaa$$$ is a substring of length $$$3$$$ which has all same characters, but $$$aabaaba$$$ is valid because there is no substring of length $$$3$$$ with all same characters .

Input

The input consists of a string $$$S$$$ of length $$$1 \le N \le 10^{5}$$$ consisting of $$$a,b,?$$$

Output

Print the valid string as stated above if possible or print "-1" (without quotes) if it is not possible to create a valid string.

Examples

Input
a?b?aa
Output
aabbaa
Input
?
Output
a
Input
aaaaa??aa
Output
-1

Note

For second test case following are valid answers $$$a,b$$$ but you have to report lexicographically smallest, therefore $$$a$$$

For third test case it can be shown no valid answer exists. Hence -1.

Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: si ≠ ti. If there is no such position (i. e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters si and ti according to their order in alphabet

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.