[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let ds = reads int
    let mutable ans = 0
    for i in [0..N-2] do
        let es = Seq.skip i ds
        let f = Seq.head es
        let gs = Seq.tail es
        let h = Seq.fold (fun s x -> s + x * f) 0 gs
        ans <- ans + h
    printfn "%i" ans
    0