1
 2
 3
 4
 5
 6
 7
 8
 9
10
def leap(x, d=400):
    return (
        not d and [d]
        or
        x == 0 and [[1, 0, 1][d >> 6 & 3]]
        or
        x < d and [leap(x, [0, 4, 100][d >> 6 & 3])]
        or
        [leap(x - d, d)]
    )[0]