3969 AC

sovled as nim game with Bouton's Theorem