a=gets.to_i
n=a.times.map { gets.to_i  }
@size = n.inject(:+)
a = 0
b = 0
c = 0
@dp = {}

def f(n,a,b,c)
  abc = [a,b,c].sort
  return @dp[abc[0]][abc[1]][abc[2]] if @dp.dig(abc[0],abc[1],abc[2])
  i = 0
  if @size / 2.0 <= [a,b,c].max - n.inject(:+).to_i
    @dp.merge!({ abc[0] => { abc[1] => { abc[2] => 3 ** n.size } } })
    return 3 ** n.size
  end
  if n==[]
    @dp.merge!({ abc[0] => { abc[1] => { abc[2] => 0 } } })
    return 0
  end
  i += f(n[1..-1],a + n[0],b,c)
  i += f(n[1..-1],a,b + n[0],c)
  i += f(n[1..-1],a,b,c + n[0])
  @dp.merge!({ abc[0] => { abc[1] => { abc[2] => i } } })
  return i
end

puts 3**n.size - f(n,a,b,c)
