import io.StdIn._
object Main extends App {
  val n = readInt
  val ws = readLine.split(" ").map(_.toInt)

  def rec(separator_index: Int, min: Int): Int = {
    val r_sum = ws.take(separator_index).sum
    val l_sum = ws.drop(separator_index).sum
    val diff = (r_sum - l_sum).abs

    if (diff == min) min
    else if (r_sum < l_sum) rec(separator_index+1, math.min(diff, min))
    else rec(separator_index-1, math.min(diff, min))
  }
  val result = rec(n/2, ws.max)
  println(result)
}