Editorial for Wave Painting


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
import math
import sys
sys.setrecursionlimit(15000)

tiles = {}

def mex(d, n):
    for i in range(n):
        if i not in d:
            return i

def tile(n):
    if n in tiles:
        return tiles[n]

    d = {}
    nn = n - k
    for i in range(0, nn + 1):
        d[tile(i) ^ tile(nn - i)] = True
    tiles[n] = mex(d, n + 1)
    return tiles[n]

def solve(n, k_input):
    global k, tiles
    k = k_input
    for i in range(k):
        tiles[i] = 0
    tiles[k] = 1
    return "Aro" if tile(n) != 0 else "Deuo"

n, k = map(int, input().split(" "))
print(solve(n, k))