h = {
  ?I => 1,
  ?V => 5,
  ?X => 10,
  ?L => 50,
  ?C => 100,
  ?D => 500,
  ?M => 1000
}
$<.map{|x|
  a=x.chop.split("").map{|c|h[c]}
  i,p,s=a.size-1,0,0
  while i>=0 do
    n=a[i]
    if n<p
      n=-n
    else
      p=n
    end
    s+=n
    i-=1
  end
  p s
}
  