Sphere Online Judge

SPOJ Problem Set (classical)

8551. Colours A, B, C, D

Problem code: ABCD

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:1s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All
Resource:originated from a mathematical problem

hide comments
2013-04-10 13:33:54 pranav gupta
will any solution do or it has to be smallest one in lexicographical order? Could you please provide me a test case where my solution is going wrong. I've tried too long to debug this now without knowing what exactly to debug.
2013-03-28 17:49:36 ahmed ashry
nice one !!
2013-03-27 15:20:23 Ouditchya Sinha
@Viktor Fonic My AC solution gives CDBDCB for your input :)
2013-03-17 12:52:49 dirty
WA at case 18. I dont know why .. Test Case is messy :(
2013-03-13 20:41:51 Viktor Fonic
Here's an interesting case:
3
ABACAD

Output:
BCDBDC
2013-03-11 15:36:03 Vitalis Salis
@Shubham Dude don't give the algorithm. Some may want to think about it themselves.

Last edit: 2013-03-11 15:36:15
2013-02-17 02:47:59 თორნიკე
Pls check my solution, what's wrong with it. It seems that it works, but gives me WA. I've checked it on every provided cases.
2013-02-14 17:08:49 Shivam Agrawal
WA at test case 18...any1 please help

Last edit: 2013-02-14 17:11:44
2013-01-30 03:36:14 Khoi Tran
Can anyone take a look at my solution? Why does it exceed time limit?
It's O(n) and I tried my best to optimize everything. Is it just a Python limitation?
2013-01-14 22:12:50 ginnipkj
Sometimes u need to be greedy....:)
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.