ABCD - Colours A, B, C, D

no tags 

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
ahmed ashry: 2013-03-28 16:49:36

nice one !!

Ouditchya Sinha: 2013-03-27 14:20:23

@Viktor Fonic My AC solution gives CDBDCB for your input :)

dirty: 2013-03-17 11:52:49

WA at case 18. I dont know why .. Test Case is messy :(

Viktor Fonic: 2013-03-13 19:41:51

Here's an interesting case:
3
ABACAD

Output:
BCDBDC

Vitalis Salis: 2013-03-11 14:36:03

@Shubham Dude don't give the algorithm. Some may want to think about it themselves.

Last edit: 2013-03-11 14:36:15
Curiosa: 2013-02-17 01: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.

Shivam Agrawal: 2013-02-14 16:08:49

WA at test case 18...any1 please help

Last edit: 2013-02-14 16:11:44
Khoi Tran: 2013-01-30 02:36:14

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?

ginnipkj: 2013-01-14 21:12:50

Sometimes u need to be greedy....:)

Shubham Somani: 2013-01-11 11:48:09

simple DFS! :P


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