bit mask + simulation + memorization
Unfortunately, I didn\'t solve this problem in the contest. I was struggling to solve a bug. \n\nAt first sight, this problem can be solved by search algorithm,
Unfortunately, I didn\'t solve this problem in the contest. I was struggling to solve a bug. \n\nAt first sight, this problem can be solved by search algorithm, either by dfs or backtracking. The input size is <= 28. At each step, half of the player will be eliminated. So the height of the recursion tree will be O(log(28)). Actually, the height will nevel greater than 4.  Then we need to estimate how many nodes in each level. Each node has at most 2 ^ (len(payler) / 2 - 2) children (firstPlayer and secondPlayer will always will and the middle player wins as well, sometimes, middle player could be first or second player)\n\nIn the worst case, n = 28. The amount of the nodes will be 2 ^ 12 + 2 ^ 12 * 2 ^ 4 + 2 ^ 12 * 2 ^ 4 * 2 = O(2 ^ 17) = 131072. We will also prun the tree during fanout process.\n\nWe can use bit mask to represent the players in each round of match. Then we need to covert the mask to player array by lowbit function x & -x. And then, we will arrange players into pairs and generate all possible mask of winers. To bo noticed that firstPlayer, secondPlayer and the middle player if exists will always win.\n\n**Python**\n```python\nclass Solution:\n    def earliestAndLatest(self, n: int, f: int, s: int) -> List[int]:\n                        \n            f = 1 << (f - 1)\n            s = 1 << (s - 1)\n            \n            def toA(x):\n                A = []\n                while x:\n                    A.append(x & -x)\n                    x -= x & -x\n                return A\n            \n            @functools.lru_cache(None)\n            def dfs(mask, depth):\n                A = toA(mask)\n                i, j = 0, len(A) - 1\n                pairs = []\n                while i < j:\n                    if A[i] == f and A[j] == s:\n                        return [depth, depth]\n                    if A[i] not in [f, s] and A[j] not in [f, s]:\n                        pairs.append((A[i], A[j]))\n                    i += 1\n                    j -= 1\n                winners = sum(set([f, s, A[len(A) // 2] if len(A) & 1 else 0]))\n                res = [math.inf, 0]\n                for com in itertools.product(*pairs):\n                    a, b = dfs(sum(com) + winners, depth + 1)\n                    res[0] = min(res[0], a)\n                    res[1] = max(res[1], b)\n                return res\n            mask = (1 << n) - 1\n            res = dfs(mask, 1)\n            return res\n```\n
[]