def min(a,b); a < b ? a : b; end def max(a,b); a > b ? a : b; end def kadomatsu?(a) a.uniq.size == 3 && (a[1] < min(a[0], a[2])) || (a[1] > max(a[0], a[2])) end A = gets.split.map(&:to_i) puts kadomatsu?(A) ? :INF : (1 .. 1000).count{|p_| kadomatsu?(A.map{|v| v % p_ }) }