import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val n: Int = StdIn.readLine().toInt
    val ws: List[Int] = StdIn.readLine().split(' ').toList.map(_.toInt)

    val sums: List[Int] = ws.foldLeft(Nil: List[Int])((acc, w) =>
      acc match {
        case Nil => List(w)
        case sum :: tail => sum + w :: acc
      })
    val sum = sums.head
    val diffs = sums.map(s => (sum - s * 2).abs)
    val ans = diffs.foldLeft(sum)((min, d) => if (min < d) min else d)
    println(ans)

  }

}

