ABCD - Colours A, B, C, D

Consider a table with 2 rows and 2N columns (a total of 4N cells). Each cell of the first row is coloured by one of the colours A, B, C, D such that there are no two adjacent cells of the same colour. You have to colour the second row using colours A, B, C, D such that:

  • There are exactly N cells of each colour (A, B, C and D) in the table.
  • There are no two adjacent cells of the same colour. (Adjacent cells share a vertical or a horizontal side.)

It is guaranteed that the solution, not necessarily unique, will always exist.

Input

[a natural number N ≤ 50000]

[a string of 2N letters from the set {A, B, C, D}, representing the first row of the table]

Output

[a string of 2N letters from the set {A, B, C, D}, representing the second row of the table]

Example

Input:
1
CB

Output:
AD
Input:
2
ABAD

Output:
BCDC

Added by:Adrian Satja Kurdija
Date:2011-03-13
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU
Resource:inspired by a math puzzle

hide comments
2014-03-05 18:51:10 Kushagra Sinha
Finally AC ... not "simple" by any means ... it is an NP-complete problem ... do not waste time trying to find a "simple" closed-form solution ...
2014-01-31 13:43:49 newbie
@author...i am getting wa many times...can you plz check submission no. 10976986
2014-01-30 09:21:56 :)
no need of backtracking.
think in simple way :)
AC in 1st attempt
2014-01-05 15:47:33 Vipul Pandey
good one! normal bracktracking will give tle. think little differently.
2013-12-15 06:24:55 Mitch Schwartz
I believe a custom judge is being used that allows any correct solution to pass. My AC code prints a different result for the second example case. It could be checked more thoroughly, if someone were motivated to do so.

Last edit: 2013-12-15 06:32:08
2013-12-15 04:20:12 cegprakash
nowhere in the question it's mentioned lexicographical order. Why? All possible solutions will be accepted?
2013-10-31 17:56:18 Avaneesh Rastogi
Seems like a lot of people don't read the problem-statement carefully.
"There are exactly N cells of each colour (A, B, C and D) in the table."
Its clearly written.
2013-10-17 20:12:30 Anurag Pratik
Watch out for the input format!
2013-09-25 09:50:48 californiagurl
@ouditchya:ur answer is just the reverse of victor's ....
2013-09-05 02:34:38 Yanzhe Chen
Backtracing is TLE :-(
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.