puts (1..A+B*10).find{|n| (0..A).any?{|i| (0..B).any?{|j| next if i + j * 10 < n z = A - i + B - j + f((i + j * 10) - n) z == C } } } || :Impossible