import Foundation
 
let number = Int(readLine()!)!

//標準入力二行目以降
var weights = [Int]()
let input_line = readLine()! 

for i in 0..<number {
    let splits = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	weights.append(Int(splits[i])!)
}

let sumOfWeights = weights.reduce(0, combine: { $0 + $1 }) //重しの総和
var position = 1
var lhsWeight = weights[position - 1]

while sumOfWeights / 2 > lhsWeight {
    position += 1
    lhsWeight += weights[position - 1]
}

if abs(sumOfWeights - (lhsWeight * 2)) <= abs(sumOfWeights - (lhsWeight * 2 - weights[position - 1])) {
  print(abs(sumOfWeights - (lhsWeight * 2)))
} else {
  print(abs(sumOfWeights - (lhsWeight * 2 - weights[position - 1])))
}