Python sol by balance. [w/ Explanation]
Explanation & Abstract model:\n\nThink of balance.\n\nInput array is in the form\n\n1, 3, 5, ..., n, ..., 2n-5, 2n -3, 2n-1\n\nWe can view this problem by balan
**Explanation** & **Abstract model**:\n\nThink of **balance**.\n\nInput array is in the form\n\n1, 3, 5, ..., **n**, ..., 2n-5, 2n -3, 2n-1\n\nWe can view this problem by balance procedure\n\n![image](https://assets.leetcode.com/users/images/14f4c594-2ec6-4845-9786-99ad80840331_1597672703.3123982.png)\n\n\n1 gram, 3 gram, 5 gram, ...,**n** gram, ..., 2n-5 gram, 2n -3 gram, 2n-1 gram\n\nBy description, with one operation, we can **+1 gram** on one position on the **left-hand side**, and **-1 gram** on another position on the **right-hand side**.\n\nAfter k times of operation( a pair of +1 and -1 on balance), final state would be\n\nn gram, n gram, n gram, ..., **n** gram, ..., n gram, n gram, n gram\n\nTherefore, combined the property of symmetirc, we can derive **k** from the weight **difference accumulation to balance point n**\n\nk \n= weight **difference accumulation** of **left hand-side** to balance point n\n= weight **difference accumulation** of **right hand-side** to balance point n\n= ( n - 1 ) + ( n - 3 ) + ( n - 5 ) + ...\n\n--- \n\nFor example with **n** = **5**\n\narr = [1, 3, **5**, 7, 9]\n\n**balance point** = **n** = **5**\n\nweight difference accumulation on left hand side\n= ( 5 - 1 ) + ( 5 - 3 )\n= 4 + 2\n= 6\n\nTherefore, we need 6 times operation to make array equal\n\n---\n\n**Implementation** by balance procedure:\n\n```\nclass Solution:\n    def minOperations(self, n: int) -> int:\n        \n        # balance point is n\n        # left hand side is lighter\n        # right hand side is heavier\n        balance_point = n\n        \n        \n        diff_accumulation = 0\n        \n        odd = 1\n        \n        # accumulate all the differnce between small odds to balance point\n        while odd < n:\n            \n            diff_accumulation += (balance_point - odd)\n            \n            # move to next odd number\n            odd += 2\n        \n        # each operation contribute one pair of +1 on left hand side / -1 on right hand side\n        # so the accumulation of difference is the answer\n        return diff_accumulation\n```\n\n---\n\n**Implementation** by math formula derived from balance procedure:\n\n```\nclass Solution:\n    def minOperations(self, n: int) -> int:\n\n        # only cosinder left-hand side is enough, due to symmetric property of balance procedure\n        first_odd = 1\n        last_odd = n-2 if (n % 2 == 1) else n-1\n        \n        first_diff = n - first_odd\n        last_diff = n - last_odd\n        terms = 1 + (first_diff - last_diff) // 2\n        \n        diff_accumulation = (first_diff + last_diff) * terms // 2\n        return diff_accumulation\n```\n\n
['Math', 'Python', 'Python3']