If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.

<image>

However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.

<image>

You have met a cat. Can you figure out whether it's normal or grumpy?

Interaction

This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. 

In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase.

Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out.

Note

Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.

Difficulty: HARD
Tags: Complete search
Skill types: Complete search

Starter code:

Solutions:
print('grumpy' if input('9\n')[-2:] in ['s?', 'le', 'se', 'ay', 'en'] else 'normal')


for i in range(10):
	print(i)
	t = input().strip()
	if t == 'no':
		continue
	if t in {"don't even", 'are you serious', 'worse', 'terrible', 'go die in a hole', 'no way'}:
		print('grumpy')
	else:
		print('normal')
	break


normal = ['no'] * 5 + ['cool', 'not bad', 'great!', "don't touch me!", "don't think so"]
grumpy = ['no'] * 3 + ['no way'] * 2 + ['terrible', 'worse', 'go die in a hole', "don't even", 'are you serious?']
import sys
import re
sys.stdout.flush()
normal = [re.sub("('|!|\\?| )", '', x).lower() for x in normal]
grumpy = [re.sub("('|!|\\?| )", '', x).lower() for x in grumpy]
cat = None
counter = 0
while cat is None:
	print(counter)
	sys.stdout.flush()
	text = re.sub("('|!|\\?| )", '', input()).lower()
	if text in normal:
		normal.remove(text)
	else:
		cat = 'grumpy'
	if text in grumpy:
		grumpy.remove(text)
	else:
		cat = 'normal'
	counter += 1
print(cat)


grum = ["don't even", 'are you serious', 'go die in a hole', 'worse', 'terrible', 'no way']
for i in range(10):
	print(i)
	s = str(input()).lower()
	if s != 'no':
		print('grumpy' if s in grum else 'normal')
		break


import sys
normal_only = ['not bad\n', 'great\n', "don't touch me\n", "don't think so\n", 'cool\n']
grumpy_only = ["don't even\n", 'terrible\n', 'worse\n', 'no way\n', 'go die in a hole\n', 'are you serious\n']

def query(a):
	print(str(a), flush=True)
	res = sys.stdin.readline()
	return res
for i in range(0, 10):
	res = query(i)
	if res in normal_only:
		print('normal', flush=True)
		sys.exit()
	elif res in grumpy_only:
		print('grumpy', flush=True)
		sys.exit()


print('grumpy' if input('9\n') in ['go die in a hole', 'are you serious?', 'terrible', 'worse', 'no way', "don't even"] else 'normal')


import sys
i = 0
while i < 10:
	print(i)
	sys.stdout.flush()
	ans = sys.stdin.readline().strip().lower()
	if ans == 'no':
		i += 1
		continue
	if ans[:3] in ['gre', 'not', 'coo', 'don'] and ans[-4:] != 'even':
		print('normal')
	else:
		print('grumpy')
	sys.stdout.flush()
	break


print(9)
print(['normal', 'grumpy'][input()[-2:] in 'lenuseay'])


normal = dict()
normal['no'] = 5
normal["don't think so"] = 1
normal["don't touch me"] = 1
normal['great'] = 1
normal['not bad'] = 1
normal['cool'] = 1
print(9, flush=True)
res = input().strip()
if res not in normal:
	print('grumpy', flush=True)
else:
	print('normal', flush=True)


from sys import exit
import sys
a = ['no', 'no', 'no', 'no', 'no', "don'", 'grea', "don'", 'not ', 'cool']
b = ['no', 'no', 'no', 'no w', 'no w', 'go d', 'wors', 'terr', "don'", 'are ']
for i in range(9):
	sys.stdout.write(str(i))
	sys.stdout.write('\n')
	sys.stdout.flush()
	inp = input()
	if inp.__len__() > 4:
		inp = inp[:4]
	if inp in a:
		a.remove(inp)
	else:
		print('grumpy')
		exit()
	if inp in b:
		b.remove(inp)
	else:
		print('normal')
		exit()
sys.stdout.write('normal')
sys.stdout.flush()
exit()
for i in range(10):
	print(i)
	a = input()
	if a.__len__() > 2:
		if a[-2:] == 'en':
			print('grumpy')
			exit()
print('normal')


grumpy = ['no way', 'die', 'worse', 'terrible', 'even', 'are']
for i in range(10):
	print(i)
	answer = input()
	if answer != 'no':
		for elem in grumpy:
			if elem in answer:
				print('grumpy')
				break
		else:
			print('normal')
		break


print(9)
print('ngorrummaply'[input()[-2:] in 'lenuseay'::2])


flag = False
for i in range(10):
	print(i)
	j = input().strip()
	if j == 'cool' or j == 'not bad' or j == 'great' or (j == "don't think so") or (j == "don't touch me"):
		flag = True
		break
	if j != 'no':
		break
if flag:
	print('normal')
else:
	print('grumpy')


for i in range(10):
	print(i, flush=True)
	s = input()
	if s != 'no':
		if s in ['great', "don't think so", "don't touch me", 'not bad', 'cool']:
			print('normal', flush=True)
		else:
			print('grumpy', flush=True)
		break


for i in range(10):
	print(i)
	b = input()
	if "don't even" in b or 'terrible' in b or 'serious' in b or ('worse' in b) or ('go die' in b) or ('way' in b):
		print('grumpy')
		break
	elif b != 'no':
		print('normal')
		break
	elif i > 2:
		print('normal')
		break


import sys
normal = False
nos = 0
for i in range(10):
	print(i)
	sys.stdout.flush()
	s = input()
	if s in ['cool', 'great', "don't think so", 'not bad', "don't touch me"]:
		normal = True
		break
	elif s != 'no':
		break
	else:
		nos += 1
		if nos > 3:
			normal = True
			break
print('normal' if normal else 'grumpy')


import sys
normal = ['cool', 'not bad', "don't touch me", "don't think so", 'great']
for i in range(10):
	print(i)
	sys.stdout.flush()
	react = input()
	if react == 'no':
		continue
	for t in normal:
		if react.startswith(t):
			print('normal')
			exit(0)
	print('grumpy')
	exit(0)


import sys

def check(s):
	if s == 'no':
		return 'dn'
	elif s in ['great', "don't think so", "don't touch me", 'not bad', 'cool']:
		return 'n'
	else:
		return 'g'
print(0)
sys.stdout.flush()
t = check(input())
for i in range(1, 10):
	if t == 'dn':
		print(i)
		sys.stdout.flush()
		t = check(input())
	elif t == 'n':
		print('normal')
		sys.stdout.flush()
		sys.exit(0)
	else:
		print('grumpy')
		sys.stdout.flush()
		sys.exit(0)


import re
import math
import decimal
import bisect

def read():
	return input().strip()
grumpy = ["don't even", 'are you serious?', 'go die in a hole', 'worse', 'terrible', 'no way']
print(9, flush=True)
resp = read()
if resp in grumpy:
	print('grumpy', flush=True)
else:
	print('normal', flush=True)


print(9, flush=True)
print(['normal', 'grumpy'][input()[-2:] in 'lenuseay'], flush=True)


import sys
(i, ans) = (0, 'no')
while ans == 'no':
	print(i)
	i += 1
	sys.stdout.flush()
	ans = input()
if ans[:3] in ('gre', 'don', 'not', 'coo') and (not ans.endswith('even')):
	print('normal')
else:
	print('grumpy')


def main():
	grumpy = ["don't even", 'are you serious?', 'worse', 'terrible', 'no way', 'go die in a hole']
	print(9)
	res = input()
	if res in grumpy:
		print('grumpy')
		return
	else:
		print('normal')
		return
main()


import sys
grum = ["don't even", 'are you serious', 'go die in a hole', 'worse', 'terrible', 'no way']
for i in range(10):
	print(i)
	sys.stdout.flush()
	s = sys.stdin.readline().strip().lower()
	if s != 'no':
		print('grumpy' if s in grum else 'normal')
		sys.exit()


i = 0
exec("print(i,flush=1);i+=1;x=input()\nif x!='no':print('grumpy'if x[-2:]in'lenuseay'else'normal');quit()\n" * 7)


i = 0
while 1:
	print(i)
	i += 1
	x = input()[-2:]
	if x != 'no':
		print(['normal', 'grumpy'][x in 'lenuseay'])
		break


def main():
	for i in range(10):
		print(i)
		result = str(input())
		if result == 'no':
			continue
		if result == 'cool' or result == 'great' or result == "don't think so" or (result == "don't touch me") or (result == 'not bad'):
			print('normal')
			break
		else:
			print('grumpy')
			break
main()


import sys
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in a:
	sys.stdout.flush()
	print(i, flush=True)
	sys.stdout.flush()
	s = str(input())
	sys.stdout.flush()
	if s == 'no':
		sys.stdout.flush()
		continue
	if s == 'great' or s == 'cool' or s == 'not bad' or (s == "don't touch me") or (s == "don't think so"):
		print('normal', flush=True)
		break
	else:
		print('grumpy', flush=True)
		break


import re

def main():
	ptn = 'cool|bad|great|think|touch'
	for i in range(10):
		print(i)
		res = input()
		if res == 'no':
			continue
		if re.search(ptn, res) is not None:
			print('normal')
			break
		else:
			print('grumpy')
			break
main()


import sys
for i in range(10):
	print(i)
	sys.stdout.flush()
	a = sys.stdin.readline().strip().lower()
	if 'cool' in a or 'great' in a or 'not bad' in a or ('think' in a):
		print('normal')
		sys.exit(0)
	if 'die' in a or 'serious' in a or 'way' in a or ('worse' in a) or ('terrible' in a) or ('even' in a):
		print('grumpy')
		sys.exit(0)


for i in range(10):
	print(i)
	inp = input()
	kaj = ['great', "don't think so", 'cool', 'not bad', "don't touch me"]
	if inp == 'no':
		continue
	if inp in kaj:
		print('normal')
		break
	if inp not in kaj:
		print('grumpy')
		break


import sys
seen_cool = False
no_counter = 0
normal = ['great', 'bad', 'think', 'touch', 'cool']
for i in range(10):
	print(i)
	sys.stdout.flush()
	s = input()
	if s == 'no':
		no_counter += 1
		if no_counter > 3:
			print('normal')
			break
	else:
		found = False
		for f in normal:
			if f in s:
				found = True
		if found:
			print('normal')
		else:
			print('grumpy')
		break


for i in range(10):
	print(i)
	t = input()
	if t in ['no way', 'go die in a hole', 'are you serious', 'worse', 'terrible', "don't even"]:
		print('grumpy')
		exit(0)
	elif t != 'no':
		print('normal')
		exit(0)


grumpy = ['are you serious', "don't even", 'go die in a hole', 'terrible', 'worse', 'no way']
grumpyFlag = False
for i in range(10):
	print(i)
	response = input()
	if response == 'no':
		continue
	elif response in grumpy:
		grumpyFlag = True
		break
	else:
		break
if grumpyFlag:
	print('grumpy')
else:
	print('normal')


G = {'no.': 3, 'eve': 1, 'are': 1, 'wor': 1, 'ter': 1, 'god': 1, 'now': 2}
N = {'no.': 5, 'gre': 1, 'coo': 1, 'thi': 1, 'not': 1, 'tou': 1}
from collections import defaultdict as dd, deque
C = dd(int)
S = set()
for i in range(10):
	print(i)
	s = input() + '........'
	s = s.replace(' ', '').replace("don't", '')
	s = s[:3]
	C[s] += 1
	if s not in G or C[s] > G[s]:
		print('normal')
		break
	if s not in N or C[s] > N[s]:
		print('grumpy')
		break


normal = ['great', "don't think so", "don't touch me", 'not bad', 'cool']
response = 'no'
x = 0
while response == 'no':
	print(x, flush=True)
	response = input()
	x += 1
print('normal') if response in normal else print('grumpy')


for i in range(0, 10):
	print(i, flush=True)
	s = input()
	if s != 'no':
		print(['normal', 'grumpy'][s[-2:] in 'lenuseay'], flush=True)
		break


import sys
flag = 0
q = set()
for i in range(10):
	print(i)
	sys.stdout.flush()
	s = input()
	if s != 'no':
		if s in 'great!' or s in "don't think so" or s in 'not bad' or (s in 'cool') or (s in "don't touch me!"):
			print('normal')
		else:
			print('grumpy')
		break


no = 0
for i in range(10):
	print(i)
	inp = input()
	if inp == 'no':
		no += 1
		if no == 4:
			exit(print('normal'))
		continue
	if inp == 'cool' or inp == "don't think so" or inp == 'not bad' or (inp == "don't touch me") or (inp == 'great'):
		exit(print('normal'))
	exit(print('grumpy'))


import sys
good = {'great', 'not bad', 'cool', "don't touch me", "don't think so"}
for i in range(10):
	print(i)
	sys.stdout.flush()
	s = input()
	if s == 'no way' or (s != 'no' and s not in good):
		print('grumpy')
		exit(0)
	elif s in good:
		print('normal')
		exit(0)


import sys
for i in range(0, 10):
	print(i)
	sys.stdout.flush()
	res = input()
	if res != 'no':
		if res in ['great', "don't think so", "don't touch me", 'not bad', 'cool', 'great']:
			print('normal')
		else:
			print('grumpy')
		sys.stdout.flush()
		exit()


for i in range(10):
	print(i)
	reaction = input()
	if reaction != 'no':
		for part in ('no way', 'die', 'worse', 'terrible', 'even', 'are'):
			if part in reaction:
				print('grumpy')
				break
		else:
			print('normal')
		break


n = ['no', 'great', 'dontthinkso', 'donttouchme', 'notbad', 'cool', 'no', 'no', 'no', 'no']
g = ['no', 'donteven', 'areyouserious', 'godieinahole', 'worse', 'terrible', 'noway', 'noway', 'no', 'no']
for i in range(10):
	print(i, flush=True)
	v = ''.join((c for c in input().lower() if 'a' <= c <= 'z'))
	if v in n and v in g:
		n.remove(v)
		g.remove(v)
		continue
	print('grumpy' if v in g else 'normal')
	break


ans = ''
i = 0
while not ans:
	print(i, flush=1)
	s = input()
	if s != 'no':
		if s in ['great', 'great!', "don't think so", 'not bad', 'cool', "don't touch me", "don't touch me!"]:
			ans = 'normal'
		else:
			ans = 'grumpy'
	i += 1
print(ans)


import sys, random
normal = "no,great!,don't think so,not bad,cool,don't touch me,great".split(',')
grumpy = "no,no way,are you serious?,don't even,terrible,go die in a hole,worse,are you serious,are you serius".split(',')
p = [i for i in range(10)]
random.shuffle(p)
for i in p:
	print(i)
	sys.stdout.flush()
	s = input()
	if s in normal and s in grumpy:
		continue
	if s in normal:
		print('normal')
		break
	else:
		print('grumpy')
		break
sys.stdout.flush()


from random import randint
n = randint(0, 9)
print(n)
s = str(input())
if s == "don't think so" or s == "don't touch me" or s == 'not bad' or (s == 'great') or (s == 'cool'):
	print('normal')
elif s == 'are you serious?' or s == 'go die in a hole' or s == 'worse' or (s == 'terrible') or (s == 'no way') or (s == "don't even"):
	print('grumpy')
elif s == 'no':
	z = 0
	while z == 0:
		n = randint(0, 9)
		print(n)
		s = str(input())
		if s == "don't think so" or s == "don't touch me" or s == 'not bad' or (s == 'great') or (s == 'cool'):
			print('normal')
			z = 1
		elif s == 'are you serious?' or s == 'go die in a hole' or s == 'worse' or (s == 'terrible') or (s == 'no way') or (s == "don't even"):
			print('grumpy')
			z = 1
		elif s == 'no':
			pass


import sys
sys.stdout.flush()
for i in range(6):
	print(i)
	a = input()
	if not a == 'no':
		break
if a == "don't think so" or a == "don't touch me" or a == 'not bad' or (a == 'cool') or (a == 'great'):
	print('normal')
else:
	print('grumpy')


a = ['great', "don't think so", 'not bad', "don't touch me", 'cool']
for i in range(10):
	print(i)
	ans = input()
	if ans != 'no':
		if ans in a:
			print('normal')
			exit()
		else:
			print('grumpy')
			exit()


i = 0
print(i)
ch = input()
if ch == 'no':
	i = i + 1
	while ch == 'no':
		print(i)
		ch = input()
		i = i + 1
if ch == "don't even" or ch == 'terrible' or ch == 'worse' or (ch == 'are you serious') or (ch == 'go die in a hole') or (ch == 'no way'):
	print('grumpy')
else:
	print('normal')