import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine()
  val w = StdIn.readLine().split(" ").map(_.toInt)
  var l: Array[Int]  = Array.empty

  w.foreach { i =>
    if (l.isEmpty) {
      l = l :+ i
    } else {
      l = l :+ (i + l.last)
    }
  }

  println(l.dropRight(1).map{i => Math.abs(l.last - 2 * i)}.min)
}
  

