a=[1000,900,500,400,100,90,50,40,10,9,5,4,1] r=%w(M CM D CD C XC L XL X IX V IV I) b=[] gets gets.split.map{|n| x=0 j=0 loop{ if n.start_with?(r[j]) x+=a[j] n=n[r[j].size..n.size-1] break if n=="" else j+=1 end } b<3999?"ERROR":d