Title: Dangerous Bridge

In Aizuwakamatsu City, located much further north from Aizukomatsumura, there is a bridge called "Yabashi" which serves as the only means of transportation to the surrounding villages. Despite heavy foot traffic, the bridge has deteriorated to the point of imminent collapse.

Yabashi can withstand a maximum weight of 150 [kg]. For instance, an 80 [kg] person and a 50 [kg] person can cross simultaneously, but if a 90 [kg] person starts crossing while an 80 [kg] person is already on the bridge, the bridge will break.

If the bridge collapses, the people of Aizukomatsumura will lose their means of transportation to the surrounding villages. As the village's sole programmer, you have decided to create a program to determine the bridge's structural integrity and the method of crossing to protect the villagers' livelihood.

The program should take as input the number of people crossing the bridge <var>n> (1 ≤ <var>n> ≤ 100), the weight of each person crossing <var>m<sub>i></sub> (1 ≤ <var>m<sub>i></sub> ≤ 100), the time they start crossing <var>a<sub>i></sub>, and the time they finish crossing <var>b<sub>i></sub> (0 ≤ <var>a<sub>i></sub>, <var>b<sub>i></sub> < 2^31). It should output "OK" if the bridge remains intact and "NG" if it breaks. The total weight of people on the bridge exceeding 150 [kg] will cause the bridge to collapse. Additionally, at time <var>a<sub>i></sub>, people are on the bridge, but at time <var>b<sub>i></sub>, they are not.

Input:
Multiple datasets are provided as input, ending with a single line containing zero. Each dataset is in the following format:
<var>n>
<var>m<sub>1></sub> <var>a<sub>1></sub> <var>b<sub>1></sub>
<var>m<sub>2></sub> <var>a<sub>2></sub> <var>b<sub>2></sub>
...
<var>m<sub>n></sub> <var>a<sub>n></sub> <var>b<sub>n></sub>

The number of datasets does not exceed 1200.

Output:
For each input dataset, output whether the bridge will break or not in a single line.

Sample Input:
3
80 0 30
50 5 25
90 27 50
3
80 0 30
70 5 25
71 30 50
0

Output for the Sample Input:
NG
OK

# Buggy version:
while True:
    N = int(input())
    if not N:
        break
    e = []
    for i in range(N):
        m, a, b = map(int, input().split())
        e.append((a, m))
        e.append((b, -m))

    M = 0
    ot = -1
    for t, m in sorted(e):
        M += m
        if M >= 150 and ot != t:
            print('NG')
            break
        ot = t
    else:
        print('OK')

# Fixed version:
while True:
    N = int(input())
    if not N:
        break
    e = []
    for i in range(N):
        m, a, b = map(int, input().split())
        e.append((a, m))
        e.append((b, -m))

    M = 0
    ot = 0
    for t, m in sorted(e):
        if M > 150 and ot != t:
            print('NG')
            break
        M += m
        ot = t
    else:
        print('OK')

# Buggy version:

from operator import itemgetter

while 1:
    n = int(input())
    if n == 0:
        break
    t_w = []
    for _ in range(n):
        m, a, b = map(int, input().split())
        t_w.append((a, m, 5))
        t_w.append((b, -m, 3))
        t_w.sort(key=itemgetter(0, 2))
        ans, cur = 'OK', 0
        for t, w, pri in t_w:
            cur += w
            # print('t', t, 'w', w, 'cur', cur)
            if cur > 150:
                ans = 'NG'
                break
        print(ans)


# Fixed version:
from operator import itemgetter

while 1:
    n = int(input())
    if n == 0:
        break
    t_w = []
    for _ in range(n):
        m, a, b = map(int, input().split())
        t_w.append((a, m, 5))
        t_w.append((b, -m, 3))
        t_w.sort(key=itemgetter(0, 2))
        ans, cur = 'OK', 0
        for t, w, pri in t_w:
            cur += w
            # print('t', t, 'w', w, 'cur', cur)
            if cur > 150:
                ans = 'NG'
                break
    print(ans)