Double Permutation Inc

Polycarp recently became an employee of the company “Double Permutation Inc.” Now he is a fan of permutations and is looking for them everywhere!

A permutation in this problem is a sequence of integers p1,p2,,pkp1,p2,,pk such that every integer from 11 to kk occurs exactly once in it. For example, the following sequences are permutations of [3,1,4,2][3,1,4,2], [1][1] and [6,1,2,3,5,4][6,1,2,3,5,4]. The following sequences are not permutations: [0,1][0,1], [1,2,2][1,2,2], [1,2,4][1,2,4] and [2,3][2,3].

In the lobby of the company’s headquarter statistics on visits to the company’s website for the last nn days are published — the sequence a1,a2,,ana1,a2,,an. Polycarp wants to color all the elements of this sequence in one of three colors (red, green or blue) so that:

  • all red numbers, being written out of a1,a2,,ana1,a2,,an from left to right (that is, without changing their relative order), must form some permutation (let’s call it PP);
  • all green numbers, being written out of a1,a2,,ana1,a2,,an from left to right (that is, without changing their relative order), must form the same permutation PP;
  • among blue numbers there should not be elements that are equal to some element of the permutation PP.

Help Polycarp to color all nn numbers so that the total number of red and green elements is maximum.

Input

The first line contains an integer nn (1n21051n2105) — the length of the sequence aa. The second line contains nn integers a1,a2,,ana1,a2,,an (1ai21051ai2105).

Output

Print a string ss of length nn such that:

  • sisi=’R’, if the element aiai must be colored in red;
  • sisi=’G’, if the element aiai must be colored in green;
  • sisi=’B’, if the element aiai must be colored in blue.

The string ss should maximize the total number of red and green elements when fulfilling the requirements from the main part of the problem statement. If there are several optimal answers, print any of them.

Examples

input

5
1 2 3 2 1

output

RBBBG

input

3
1 1 1

output

BBB

input

10
3 3 2 2 5 4 1 5 4 1

output

RGRGRRRGGG

input

10
3 9 3 1 2 1 2 4 4 4

output

RBGRRGGBBB

Solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
 
fun main(args: Array<String>) {
var n = readInt()
var a = readInts()
val MAX = 200010
var cnt = IntArray(MAX)
for (x in a) cnt[x]++
var low = 0
var high = n
while (low < high) {
        var mid = (low + high + 1) / 2
        var ok = true
        for (i in 1..mid) {
            if (cnt[i] != 2) {
                ok = false
                break
            }
        }
        if (ok) {
            var x = ArrayList<Int>()
var y = 0
var cc = IntArray(mid + 1)
for (v in a) {
if (v <= mid) {
                    if (cc[v] == 0) {
                        x.add(v)
                    } else {
                        if (x[y] != v) {
                            ok = false
                            break
                        }
                        y += 1
                    }
                    cc[v] += 1
                }
            }
        }
        if (ok) {
            low = mid
        } else {
            high = mid-1
        }
    }
    var res = CharArray(n)
    var mid = low
        var x = ArrayList<Int>()
var y = 0
var cc = IntArray(mid + 1)
for (it in 0..n-1) {
var v = a[it]
if (v <= mid) {
                if (cc[v] == 0) {
                    res[it] = 'R'
                } else {
                    res[it] = 'G'
                }
                cc[v] += 1
            } else {
                res[it] = 'B'
            }
        }
    println(res.joinToString(""))
}