num_players = 419 num_marbles = 71052 * 100 class Node: def __init__(self, val): self.val = val self.prev = None self.next = None def insert(self, val): new = Node(val) new.prev = self new.next = self.next if self.next is not None: self.next.prev = new self.next = new return new def remove(self): if self.prev is not None: self.prev.next = self.next if self.next is not None: self.next.prev = self.prev self.next = None self.prev = None cur_node = Node(0) cur_node.next = cur_node cur_node.prev = cur_node score = {x: 0 for x in range(1, num_players + 1)} cur_marble = 1 while cur_marble <= num_marbles: cur_player = (cur_marble - 1) % num_players + 1 if cur_marble % 23 == 0: tmp = cur_node.prev.prev.prev.prev.prev.prev.prev cur_node = tmp.next tmp.remove() score[cur_player] += cur_marble + tmp.val else: cur_node = cur_node.next.insert(cur_marble) cur_marble += 1 print(max(score.values()))