You are given boxes numbered from to . Box contains two balls whose colors are given by a two-character string . The letters R and B denote red and blue.
In one move, choose two distinct boxes and swap one ball from each box.
Find the minimum number of moves needed to make the two balls in every box have the same color. Different boxes may have different colors. You may make zero moves. If this is impossible, output -1.
R and B.Swap a red ball from box with a blue ball from box , and do the same for boxes and . The boxes become BB, RR, BB, RR in two moves.