import scala.math.abs

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val as = List.fill(n)(sc.nextInt)

    var absMin = as.sum
    for(k <- 1 until (n - 2))
      for(l <- (k + 1) until (n - 1))
        for(m <- (l + 1) until n) {
        	val ps = List(
        	  as.slice(0, k),
        	  as.slice(k, l),
        	  as.slice(l, m),
        	  as.slice(m, n)
        	).map(_.sum)
	val absCur = abs(ps.max - ps.min)
	if(absCur < absMin)
	  absMin = absCur
        }

    println(absMin)
  }
}
