object Main extends App {
  val sc = new java.util.Scanner(System.in)
  println(
    List
      .fill(sc.nextInt())(sc.nextInt())
      .tails
      .toList
      .init
      .map { case x :: xs => x * xs.sum }
      .sum
  )
}
