[Python] Top-Down Dynamic Programming with Memorization
\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        from functools import lru_cache\n        
```\nclass Solution:\n    def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n        from functools import lru_cache\n        earliest, latest = float(\'inf\'), -1\n        \n        cur = n\n        d = {n: 1}\n        round = 2\n        while cur > 2:\n            cur = (cur + 1) // 2\n            d[cur] = round\n            round += 1\n            \n        def getGroup(l, m, r, seat):\n            if seat < l:  # Group l\n                return 0\n            if seat < l + 1 + m:  # Group m\n                return 1\n            return 2  # Group r\n            \n        @lru_cache(None)\n        def helper(l, m, r):\n            """\n            l: number of players before firstPlayer\n            m: number of players between firstPlayer and secondPlayer\n            r; number of players after secondPlayer\n            """\n            nonlocal earliest, latest\n            t = l + m + r + 2  # Total number of players\n            if l == r:\n                earliest = min(earliest, d[t])\n                latest = max(latest, d[t])\n                return\n            \n            lm = mr = lr = 0  # lm: number of games between players in l and players in m\n            ll = mm = rr = 0  # ll: number of games between players within l\n            winner = (l, l + m + 1)\n            for i in range((t + 1) // 2):\n                j = t - i - 1\n                \n                if i in winner or j in winner:\n                    continue\n                groupi = getGroup(l, m, r, i)\n                groupj = getGroup(l, m, r, j)\n                \n                if groupi == groupj:\n                    if groupi == 0:\n                        ll += 1\n                    elif groupi == 1:\n                        mm += 1\n                    elif groupi == 2:\n                        rr += 1\n                        \n                elif groupi == 0:\n                    if groupj == 1:\n                        lm += 1\n                    elif groupj == 2:\n                        lr += 1\n                        \n                elif groupi == 1:\n                    mr += 1\n                                        \n            for i in range(lm + 1):\n                for j in range(mr + 1):\n                    for k in range(lr + 1):\n                        helper(i + k + ll, mm + lm - i + j, rr + lr - k + mr - j)\n                        \n        helper(firstPlayer - 1, secondPlayer - firstPlayer - 1, n - secondPlayer)\n        \n        return [earliest, latest]\n```
[]