# Arup Guha
# Maria Mauco
# 6/12/2023

import random

def main():

    cookies = int(input("Enter a starting number of cookies.\n"))

    player = 1

    # Game goes until there are 0 cookies.
    while cookies > 0:

        print("There are", cookies, "cookies left.")
        take = int(input("Player #"+str(player)+", how many cookies to take?\n"))

        # Must take at least one cookie, can't take more than 5, and can't
        # take more than are there.
        if take <= 0 or take > 5 or take > cookies:
            print("Invalid # of cookies, you forfeit your turn.")
            player = 3 - player
            continue

        # Update # of cookies, and player.
        cookies -= take

        # Don't update if last cookies was taken.
        if cookies > 0:
            player = 3 - player

    print("The winner was player #",player,".", sep="")

main()
