Cookies

@s-panferov I think this handles everything.

cc @reem 
Only with a large number of cookies. With a few (1, 2, 3ish), it would remove the branch in the for loop, but add in 2 bounds checks, and make the code much more complicated to boot.

How many cookies is the common case? I'm think 0-2.