part 1 realy easy part 2 made with a trick, got from reddit megathread else naive approach would have taken 40 day of computation