Barbarian tribes

In a lost land two primitive tribes coexist: Gareds and Kekas. Every
summer solstice they meet and compete to decide which tribe will be the
favorite of the gods for the rest of the year, following an old ritual:

First, a local guru chooses three numbers at random: n, m and k.
Afterwards, n Gared maids (in the positions 1, …, n) and m Keka maids
(in the positions n + 1, …, n + m) are placed in a circle looking
inwards. Then the guru begins to count 1, …, k starting at the first
Gared maid. When the k-th maid is reached, she is immediately sacrificed
to the gods. The guru then counts again 1, …, k starting at the maid
following the one just sacrificed. Again, the k-th maid reached this way
is sacrificed. After every two sacrifices, the second sacrificed maid is
replaced by a new maid. In order to decide the tribe of the new maid,
the guru looks at the heads of the two maids just killed (nothing else
remains of them). If both heads are of the same tribe, the guru calls a
Gared maid. If the heads are from different tribes, the guru calls a
Keka maid. The process then begins again (counting and sacrificing twice
and replacing once) starting to count at the maid following the new maid
just added to the circle. Since the number of maids is reduced by one
after every step (of two sacrifices and one replacement), after
n + m − 1 steps only one maid remains.

According to the tradition, the tribe of the last maid will be the
favorite of the gods. (What the guru does to the last maid is something
you don’t want to know.) Anyway, write a program such that, given n, m
and k, writes the name of the fortunate tribe.

For example, this is what happens for n = m = 3 and k = 2 (a “G” denotes
a Gared maid and a “K” denotes a Keka maid; the subindexes mark the
order the maids enter the circle):

1.  Initial content of the circle: G₁ G₂ G₃ K₄ K₅ K₆
    Starting to count at G₁. First sacrifice: G₂. Second sacrifice: K₄
    (replaced by K₇).

2.  Content of the circle: G₁ G₃ K₇ K₅ K₆
    Starting to count at K₅. First sacrifice: K₆. Second sacrifice: G₃
    (replaced by K₈).

3.  Content of the circle: G₁ K₈ K₇ K₅
    Starting to count at K₇. First sacrifice: K₅. Second sacrifice: K₈
    (replaced by G₉).

4.  Content of the circle: G₁ G₉ K₇
    Starting to count at K₇. First sacrifice: G₁. Second sacrifice: K₇
    (replaced by K₁₀).

5.  Content of the circle: G₉ K₁₀
    Starting to count at G₉. First sacrifice: K₁₀. Second sacrifice: G₉
    (replaced by K₁₁).

6.  Final content of the circle: K₁₁

Input

Input consists of several cases, each with three natural numbers n, m
and k. You can assume 1 ≤ n + m ≤ 2000 and 1 ≤ k ≤ 1000. A special case
with n = m = k = 0 ends the input.

Output

For every case, print either "Gared" or "Keka" as convenient.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:35:26.404Z

© Jutge.org, 2006–2026.
https://jutge.org
