Krypton Stadiums

Time limit10sMemory limit512 MB

Summary
Given n intervals where interval i contains point i, classify the layout as Great, Acceptable, or Bad based on whether pairs of cities are co-hosted by a nesting or shared stadium.
Level

Hard8 of 10

Topics
Intervals, Greedy, Sorting, Array
Solved
No attempts yet

Problem

The planet Krypton has nn cities. They sit at distinct points on one straight line running west to east, and they are labelled 0,1,2,…,n−10, 1, 2, \dots, n-1 from west to east. Each city has one team and one stadium.

Stadium ii carries two integers aia_i and bib_i. The team from city xx plays at stadium ii only when ai≤x≤bia_i \le x \le b_i. Every team can play at its home stadium, so ai≤i≤bia_i \le i \le b_i is guaranteed.

Before the season schedule is written, the layout of the cities and stadiums gets one of three verdicts.

  • The layout is Great if for every pair of cities c1c_1 and c2c_2 some stadium ii with min⁡(c1,c2)≤i≤max⁡(c1,c2)\min(c_1, c_2) \le i \le \max(c_1, c_2) can host the teams from both cities.
  • The layout is Acceptable if it is not Great but for every pair of cities c1c_1 and c2c_2 some stadium can host the teams from both cities.
  • The layout is Bad if there is a pair of cities that no stadium can host together.

Input

The input holds several test cases and ends at end of file.

The first line of each test case has the number of cities nn (2≤n≤200 0002 \le n \le 200\,000). The next nn lines give the intervals of stadiums 00 through n−1n-1 in order. Each line has exactly six characters: the first three give aia_i and the last three give bib_i. Each group of three characters is a three digit base 62 number that uses 0-9A-Za-z as the digits with values 00 through 6161. For example, cities 00, 11, 99, 1010, 3535, 3636, 6161, 6262 and 199 999199\,999 are written 000, 001, 009, 00A, 00Z, 00a, 00z, 010 and q1n. Always 0≤ai≤i≤bi≤n−10 \le a_i \le i \le b_i \le n-1.

There are at most 1 0001\,000 test cases and at most 2 000 0002\,000\,000 stadiums over all test cases.

Output

For each test case print one of Great, Acceptable or Bad on its own line.

Examples2

  1. Example 1

    Input
    4
    000001
    000003
    002002
    002003
    4
    000000
    001001
    002002
    003003
    4
    000001
    000003
    002002
    003003
    
    Expected output
    Great
    Bad
    Acceptable
    
  2. Example 2

    Input
    2
    000001
    000001
    2
    000001
    001001
    2
    000000
    000001
    2
    000000
    001001
    
    Expected output
    Great
    Great
    Great
    Bad