You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 396. Rotate Function.go
    path of file: ./repos/LeetCode-Go/leetcode/0396.Rotate-Function
    
    the code of the file until where you have to start completion: package leetcode

func maxRotateFunction(nums []int) int {
	n := len(nums)
	var sum, f int
	for i, num := range nums {
		sum += num
		f += i * num // F(0)
	}
	ans := f
	for i := 1; i < n; i++ {
		f += sum - n*nums[n-i] // F(i) = F(i-1) + sum - n*nums[n-
    
func maxRotateFunction(nums []int) int {
	n := len(nums)
	var sum, f int
	for i, num := range nums {
		sum += num
		f += i * num // F(0)
	}
	ans := f
	for i := 1; i < n; i++ {
		f += sum - n*nums[n-i] // F(i) = F(i-1) + sum - n*nums[n-i]
		if f > ans {
			ans = f
		}
	}
	return ans
}