package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// Priority Queue
type Item struct {
	priority, from, to, index int
}

type PQ []*Item

func (pq PQ) Len() int {
	return len(pq)
}

func (pq PQ) Less(i, j int) bool {
	return pq[i].priority > pq[j].priority
}

func (pq PQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PQ) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1
	*pq = old[0 : n-1]
	return item
}

// End Priority Queue

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)

	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	pq := make(PQ, 0)
	heap.Init(&pq)
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			v := a[i] * asub(i, j)
			heap.Push(&pq, &Item{v, i, j, 0})
		}
	}

	used0 := make([]bool, N)
	used1 := make([]bool, N)
	ans := 0
	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		if used0[item.from] || used1[item.to] {
			continue
		}
		ans += item.priority
		used0[item.from] = true
		used1[item.to] = true
		// out(item.from, item.to, item.priority)
	}
	out(ans)
}
