Skip to content

Instantly share code, notes, and snippets.

@danielevans
Created February 26, 2013 18:56
Show Gist options
  • Save danielevans/5041045 to your computer and use it in GitHub Desktop.
Save danielevans/5041045 to your computer and use it in GitHub Desktop.
lines = $stdin.read.lines.map &:strip
lines = $stdin.read.lines.map do |line|
line.strip
end
while true
c,n = lines.shift.split.map &:to_i
break if c == 0 && n == 0
v = lines.shift.split.map(&:to_i)
v.shift
v.pop
if v == []
v = [0]
end
puts c * ( n - 1 ) * 2 + v.reduce(&:+)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment