def solve(vs, mat) used = Array.new(5, false) ps = [] 5.times do |i| pivot = -1 5.times do |j| next if used[j] next if mat[j][i].abs < 1e-8 if pivot == -1 || mat[pivot][i].abs > mat[j][i].abs pivot = j end end return 0 if pivot == -1 (i + 1).upto(5) do |j| mat[pivot][j] /= mat[pivot][i] end mat[pivot][i] = 1.0 5.times do |j| next if j == pivot next if mat[j][i] == 0 (i + 1).upto(5) do |k| mat[j][k] -= mat[j][i] * mat[pivot][k] end mat[j][i] = 0 end used[pivot] = true ps << pivot end 5.times do |i| return 0 if mat[i][5] < -1e-8 end cs = 5.times.map { |i| mat[ps[i]][5].to_i } ret = 0 [0, cs[0] - 2].max.upto(cs[0] + 2) do |c0| [0, cs[1] - 2].max.upto(cs[1] + 2) do |c1| [0, cs[2] - 2].max.upto(cs[2] + 2) do |c2| [0, cs[3] - 2].max.upto(cs[3] + 2) do |c3| [0, cs[4] - 2].max.upto(cs[4] + 2) do |c4| next if c4 + c0 + c1 > vs[0] next if c0 + c1 + c2 > vs[1] next if c1 + c2 + c3 > vs[2] next if c2 + c3 + c4 > vs[3] next if c3 + c4 + c0 > vs[4] ret = [ret, c0 + c1 + c2 + c3 + c4].max end end end end end return ret end vs = readline.split.map(&:to_i) es = [] 5.times do |i| e = [0.0] * 6 e[5] = vs[i].to_f e[(i + 4) % 5] = e[i] = e[(i + 1) % 5] = 1 es << e e = [0.0] * 6 e[i] = 1 es << e end ans = 0 (1 << 10).times do |i| next if i.to_s(2).count("1") != 5 mat = [] 10.times do |j| if (i & (1 << j)) != 0 mat << es[j].clone end end ans = [ans, solve(vs, mat)].max end puts ans