Problem:
Score : 100 points

Problem Statement

A programming competition site AtCode regularly holds programming contests.

The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.

The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.

The contest after the ARC is called AGC, which is rated for all contestants.

Takahashi's rating on AtCode is R. What is the next contest rated for him?

Constraints

0 ≤ R ≤ 4208

R is an integer.

Input

Input is given from Standard Input in the following format:

R

Output

Print the name of the next contest rated for Takahashi (ABC, ARC or AGC).

Sample Input 1

1199

Sample Output 1

ABC

1199 is less than 1200, so ABC will be rated.

Sample Input 2

1200

Sample Output 2

ARC

1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.

Sample Input 3

4208

Sample Output 3

AGC

Solution in Scala (2.11.7) (judge verdict: Runtime Error)

import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D, G = in.next().toInt
  val p = new Array[Int](D+1)
  val c = new Array[Int](D+1)

  for(i <- 1 to D) {
    val a, b = in.next().toInt
    p(i) = a; c(i) = b / 100
  }


  //
  val MAX = 100000
  val IM = Int.MaxValue
  val dp = Array.fill[Int](MAX+1)(IM)
  dp(0) = 0
  for(k <- 1 to D) {
    val np = p(k); val nc = c(k)

    for(i <- (1 to MAX).reverse) {
      for (j <- 1 until np) {
        val now = i - (k * j)
        if(now >= 0)
          if(dp(now) != IM) {
            dp(i) = dp(i) min (dp(now) + j)
          }
      }

      val clear = i - (k * np) - nc
      if(clear >= 0)
        if(dp(clear) != IM) {
          dp(i) = dp(i) min (dp(clear) + np)
        }
    }
  }

  var ans = IM
  for (i <- G/100 to MAX)
    ans = ans min dp(i)
  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}