import scala.io.StdIn.readLine

object Main extends App {
  val MOD = 1000000007
  val n = readLine.toInt
  val a = readLine.split(" ").map(_.toLong).sorted

  val s = a.sum
  val half = s  / 2

  def calc(id: Int, curVal: Long, count: Int): Long = {
    if(id >= n - 1 || half < curVal || count == n - 1) math.abs(s - 2 * curVal)
    else {
      val a1 = calc(id + 1, curVal, count)
      val a2 = calc(id + 1, curVal + a(id + 1), count + 1)
      math.min(a1, a2)
    }
  }

  val ans = (for(i <- 0 until n) yield calc(i, a(i), 1)).min
  println(ans)
}
