ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила

1561. Winnie the Pooh

Ограничение времени: 2.0 секунды
Ограничение памяти: 64 МБ
Winnie the Pooh likes honey a lot. But many sorts of honey exist in the world. Winnie eats a barrel of honey in an integral number of days. Two barrels of honey of the same sort need the same number of days to be eaten. Any event that corresponds to the problem is one of the following:
  1. New sort of honey appears. It is assigned the smallest non-negative number not assigned yet. No other information about this sort is provided.
  2. Winnie investigated (empirically maybe…), that if he has to eat A0 barrels of honey of 0th sort, A1 of the 1st, …, Ak of the k-th sort, starting at weekday S, the first weekday after eating will be E (0, …, k — sorts that are already known to exist; Ai are integers, 0 ≤ Ai ≤ 106).
  3. Winnie plans to eat A0 barrels of honey of the 0th sort, A1 of the 1st, … Ak of the k-th sort, starting at weekday S, where 0, …, k are sorts that are already known to exist. You have to find the first day after eating according to the information from preceding queries.

Исходные данные

The first line contains N — number of queries (0 ≤ N ≤ 1000). Events of type 1, 2, 3 are given as follows respectively:
  • Add
  • Learn A0 A1 A2 … Ak S E
  • Eat A0 A1 A2 … Ak S
The queries are given one per line.

Результат

If you can determine the weekday output it. If there is more than one possibility output "Don't know" without quotes. If you determined some contradiction before this Eat query, output "Already crazy" without quotes.

Пример

исходные данныерезультат
9
Add
Add
Learn 5 2 Saturday Monday
Eat 3 3 Tuesday
Add
Learn 0 9 4 Friday Thursday
Eat 3 0 6 Sunday
Learn 3 2 10 Saturday Friday
Eat 3 4 11 Monday
Don't know
Saturday
Already crazy
Источник задачи: Novosibirsk SU Contest. Petrozavodsk training camp, September 2007