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
hide comments
rayofhopee:
20160520 16:34:58
If stuck at testcase 9.....try this..


comp0zr:
20160508 04:52:11
Two compilation errors because I forgot to remove a few isolated references to a debugging macro I added, but after I did that I got and AC on my first scored submission (which at this point in my development as a programmer is quite an accomplishment!). Like usual, I spent all night coming up with a convoluted algorithm that included multidimensional arrays and random number generation, but eventually gave up and realized while I was out for the day how simple the solution for this actually is! Completely trashed my original approach and ended up finishing it in about 2 hours... like welldesigned algorithms so often seem to be, the best approaches are often much simpler than they first appear. In any case, this site is great, I can see an immense improvement in my understanding of many concepts since I've been here. Cheers! 

poojan :
20160309 14:36:18
2 WA ans But Finally Got It Awsome Que! One wa bcs Not terminate string '\0':


enigmus:
20160224 15:19:52
Hint: Try building up your solution from smaller pieces 

Ankit:
20160218 17:23:42
My program runs for a O(n) but still it gives Time Limit Exceeded. Stuck badly. !! 

Ankit:
20160217 13:13:54
TLE after 18. The numbers in the bracket, any idea what it means ?


minhthai:
20160115 12:53:12
try to think super simply :) 

naruto09:
20151216 20:15:07
WA at 18th test case...can anyone help please..? 

darkhire21:
20151018 11:00:37
read carefully statement 1 ..!!!! 

(Tjandra Satria Gunawan)(æ›¾æ¯…æ˜†):
20150802 04:25:08
Finally AC, it's hard to think the solution but very easy to implement :) 
Added by:  Adrian Satja Kurdija 
Date:  20110313 
Time limit:  0.190s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  inspired by a math puzzle 