class SkewHeap
  def initialize(rev = nil)
    @rev = rev
  end
  def push(k, x, y)
    @root = meld(@root, Node.new(k, x, y))
  end
  def top
    @root.key
  end
  def empty?
    @root.nil?
  end
  def pop
    key, x, y = @root.key, @root.x, @root.y
    @root = meld(@root.lchild, @root.rchild)
    [key, x, y]
  end
  def meld(lhs, rhs)
    return lhs unless rhs
    return rhs unless lhs
    lhs, rhs = rhs, lhs unless lhs < rhs
    lhs, rhs = rhs, lhs if @rev
    lhs.rchild = meld(lhs.rchild, rhs)
    lhs.lchild, lhs.rchild = lhs.lchild, lhs.rchild
    lhs
  end
  class Node
    include Comparable
    attr_accessor :key, :x, :y, :lchild, :rchild
    def initialize(k, x, y)
      @key, @x, @y = k, x, y
    end
    def <=>(other)
      (@key != other.key) ? (@key <=> other.key) : ((@x - @y).abs <=> (other.x - other.y).abs)
    end
  end
end

N=gets.to_i
A=gets.split.map(&:to_i)
q=SkewHeap.new(true)
N.times do |x|
  N.times do |y|
    q.push(A[x]*(x-y).abs,x,y)
  end
end
ans=0
used=Array.new(2){Array.new(N)}
until q.empty?
  w,x,y = *q.pop
  next if used[0][x]
  next if used[1][y]
  used[0][x] = used[1][y] = true
  ans+=w
end
p ans