Solution
C++ []\nint cnt[100000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nu
```C++ []\nint cnt[100000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = size(nums);\n        memset(cnt, 0, sizeof(int) * n);\n        for (int i = 0; i < n; ++i) {\n            int v = nums[i], i2 = i-v;\n            if (v > i) i2 += n;\n            ++cnt[i]; --cnt[i2];\n        }\n        int best = -1, s = 0, bs = 0;\n        for (int i = 0; i < n; ++i) if ((s += cnt[i]) > bs) bs = s, best = i;\n        return best+1;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def bestRotation(self, nums: List[int]) -> int:\n        N = len(nums)\n        change = [1] * N\n        for i in range(N): change[(i - nums[i] + 1) % N] -= 1\n        change = list(itertools.accumulate(change))\n        return change.index(max(change))\n```\n\n```Java []\nclass Solution {\n    public int bestRotation(int[] nums) {\n        final int size = nums.length;\n        int[] rsc = new int[size];\n        for(int i = 0; i < size - 1; i++) {\n            int value = nums[i];\n            int downPos = (i + 1 + size - value) % size;\n            rsc[downPos]--;\n        }\n        int value = nums[size-1];\n        if( value != 0 ) rsc[size - value]--;\n        int bestk = 0;\n        int bestscore = rsc[0];\n        int score = rsc[0];\n        for(int i = 1; i < nums.length; i++) {\n            score += rsc[i] + 1;\n            if( score > bestscore ) {\n                bestk = i;\n                bestscore = score;\n            }\n        }\n        return bestk;\n    }\n}\n```\n
['C++', 'Java', 'Python3']