Peculiar Paints

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 32M
PyPy 2 64M
PyPy 3 64M

Author:
Problem type

You've bought some peculiar paints from the shady arts store down the corner! These paints seem completely normal at first, but they start doing some interesting things when combined. The paints come in 6 colours: red, orange, yellow, green, blue, and purple.

Like regular paints, mixing two of the same colour will result in that colour, and mixing two different primary colours will result in a secondary colour. For example, mixing red and yellow will result in orange. Things do get more interesting when mixing other colours. Mixing two different secondary colours will result in the closest primary colour to the two on the basic colour wheel. For example, mixing orange and purple will result in red. Finally, if a primary colour and secondary colour are mixed, the resulting colour is white. For example, green and red will mix to make white, and blue and purple will mix to make white. Combining any colour with white will result in that colour. For this problem, the primary colours are red, yellow, and blue, and the secondary colours are orange, green, and purple. White is neither a primary nor secondary colour.

The box of peculiar paints contains a fun activity! A configuration of cells is put together row by row to form an upside-down triangle, with each row containing one cell less than the row above. The top row P has a capital letter in each cell representing the first letter of the colour that you should fill it in with. You then start combining paint colours after filling the top row in. Each of the cells in the next rows is populated with some colour by mixing the colours in the two cells above. Given a string of the letters on the sheet with the top row containing N cells, output the first letter of the colour in the bottom cell as an uppercase letter.

It is recommended that Python users use PyPy instead.

Constraints

1 \le N \le 10^4

P only consists of the following characters: R, O, Y, G, B, or P.

Input Specification

The first line will contain an integer N.

The next line will contain N characters representing the colours in P.

Output Specification

Output a single capital character representing the colour of the bottom cell (R, O, Y, G, B, P, or W).

Sample Input 1

5
PRYPP

Sample Output 1

W

Explanation for Sample Output 1

Combining the top row results in the next row having colours WOWP.

The next row will have colours OOP.

The next will have OR.

Finally, orange and red make white.

Sample Input 2

10
YBYBBBBYOR

Sample Output 2

B

Comments

There are no comments at the moment.