Title: Patrol

In the year 1862, the lord of Aizu was appointed as the guardian of Kyoto. The role of the guardian of Kyoto is crucial in maintaining law and order during the turbulent end of the Edo period. They are required to patrol the city in collaboration with the shogunate and other feudal domains. However, when it came time to decide the patrol routes, a renowned stubborn elder among the retainers made the following demands.

It became a serious matter. Even though he was the lord, he could not ignore the retainer's demands. Depending on the choice of patrol routes, it could lead to a loss of "samurai honor."

Therefore, a program needs to be created to determine whether the given start point, end point, and intersection information meet the three conditions mentioned above. This program will be presented to the lord.

The start point is represented by 1, the end point by 2, and other intersections by integers greater than 3. Each road is represented by a pair of intersection numbers it connects. The number of intersections is less than or equal to 100, and there is at least one route from each intersection to the start and end points.

Input:
Multiple datasets are provided. Each dataset is given in the following format:
a1 b1
a2 b2
...
0 0

Each line with two integers indicates the existence of a road connecting intersection ai and bi. When both ai and bi are 0, it indicates the end of the intersection information input.

The number of datasets does not exceed 50.

Output:
For each dataset, output "OK" if the samurai honor is maintained (if the three conditions are met), otherwise output "NG" on a single line.

Sample Input:
1 3
3 4
3 5
3 6
4 6
4 7
4 7
5 6
6 7
5 8
5 8
6 8
6 9
7 9
8 9
9 2
0 0
1 3
3 4
3 4
4 2
0 0

Output for the Sample Input:
OK
NG

# Buggy version:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        for i in ab:
            v[i] += 1
        print(v)
        odd = 0
        for i in v:
            if i % 2 == 1:
                odd += 1
        if odd == 0 or (odd == 2 and ((v[1] % 2) == (v[2] % 2) == 1)):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp



# Fixed version:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        for i in ab:
            v[i] += 1
        odd = 0
        for i in v:
            if i % 2 == 1:
                odd += 1
        if odd == 2 and ((v[1] % 2) == (v[2] % 2) == 1):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp

# Buggy version:
import sys
v=[0]*101
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['OK','NG'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)-2])
  v=[0]*101


# Fixed version:
import sys
v=[0]*100
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2])
  v=[0]*100

# Buggy version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
for line in stdin:
    start, end = (int(s) for s in line.split())
    if start or end:
        cnt[start] += 1
        cnt[end] += 1
    else:
        semi_eulerian = sum(i % 2 for i in cnt.values()) == 2
        if semi_eulerian and cnt[1] % 2 and cnt[2] % 2:
            print('OK')
        else:
            print('NO')
        cnt.clear()

# Fixed version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
for line in stdin:
    start, end = (int(s) for s in line.split())
    if start or end:
        cnt[start] += 1
        cnt[end] += 1
    else:
        semi_eulerian = sum(i % 2 for i in cnt.values()) == 2
        if semi_eulerian and cnt[1] % 2 and cnt[2] % 2:
            print('OK')
        else:
            print('NG')
        cnt.clear()