Simple C++ code
\n\n    void earliestAndLatest_(int a, int b, int& first, int& second, int n, vector<vector<vector<bool>>>& m, int curr) {\n        \n        if (a + b == n + 1
```\n\n    void earliestAndLatest_(int a, int b, int& first, int& second, int n, vector<vector<vector<bool>>>& m, int curr) {\n        \n        if (a + b == n + 1) {\n            first = min(curr, first);\n            second = max(curr, second);\n            return;\n        }\n        \n        if (m[a][b][curr]) return;\n        \n        for (int i = 0; i < (1 << ((n + 1) / 2)); ++i) {\n            \n            int newa = 1, newb = 2;\n            \n            for (int j = 0; j < ((n + 1) / 2); ++j) {\n                \n                int pos = j + 1;\n                \n                if (pos == a || pos == b || pos == n - a + 1 || pos == n - b + 1) continue;\n                \n                if (i & (1 << j)) pos = n - pos + 1;\n                \n                if (pos < a) ++newa;\n                if (pos < b) ++newb;\n                \n            }\n            \n            earliestAndLatest_(newa, newb, first, second, (n + 1) / 2, m, curr + 1);\n            \n        }\n        \n        m[a][b][curr] = true;\n        return;\n    }\n    \n    vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n        int first = INT_MAX, second = INT_MIN;\n        \n        vector<vector<vector<bool>>> m(29, vector<vector<bool>>(29, vector<bool>(5, false)));\n        \n        earliestAndLatest_(firstPlayer, secondPlayer, first, second, n, m, 1);\n        \n        return vector<int> {first, second};\n    }\n```
[]