import java.util.Scanner

object Main extends App {

  val n = scala.io.StdIn.readInt()
  val arr = scala.io.StdIn.readLine().split(" ").map(_.toInt)


  def solve() = {
    val totalWeight = arr.sum
    val sumArr = Array.fill(n)(0)
    for(i <- 0 until n) {
      if(i == 0) sumArr(i) = arr(i)
      else sumArr(i) = sumArr(i-1) + arr(i)
    }

    sumArr.map { v =>
      (v - (totalWeight - v)).abs
    }.min
  }

  println(solve)

}
