require 'set' require 'rational' $buf = [] def fill_buf; (s = gets) ? $buf = s.chomp.split : break while $buf.empty? end def has_next; fill_buf; !$buf.empty? end def get; fill_buf; $buf.shift end def geti; get.to_i end def getf; get.to_f end def getss(n = nil); n ? Array.new(n) { get } : begin fill_buf; $buf.shift(1e9) end; end def getis(n = nil); getss(n).map(&:to_i) end def getfs(n = nil); getss(n).map(&:to_f) end while has_next b1, b2, b3 = getis r = Rational(b3 - b2, b2 - b1) d = b2 - r*b1 # p [r, d] w p (b3*r + d).to_i end