def is_kadomatsu(a, b, c) return false if [a, b, c].uniq.size != 3 if [a, b, c].min == b || [a, b, c].max == b return true else return false end end d, *h = $<.map(&:to_i) INF = 10000000000 ans = INF if d == 0 p is_kadomatsu(*h) ? 0 : -1 exit end tmp = h[1] - [h[0], h[2]].min ans1 = tmp < 0 ? 0 : [tmp, 0].max / d + 1 ans = [ans, ans1].min if is_kadomatsu(h[0], [h[1] - d * ans1, 0].max, h[2]) tmp = h[0] - h[1] tmp1 = tmp < 0 ? 0 : [tmp, 0].max / d + 1 tmp = h[2] - h[1] tmp2 = tmp < 0 ? 0 : [tmp, 0].max / d + 1 ans2 = tmp1 + tmp2 ans = [ans, ans2].min if is_kadomatsu([h[0] - tmp1 * d, 0].max, h[1], [h[2] - tmp2 * d, 0].max) p ans == INF ? -1 : ans