moji = "abcdefghi".split("")
numbers = gets.chomp.split.map(&:to_i)
missing = (1..9).to_a
h = {}
unknown = []
moji.zip(numbers){|m, n|
    if n != -1
        h[m] = n
        missing.delete n
    else
        unknown << m
    end
}
answer = 0
missing.permutation(missing.length){|arr|
    unknown.zip(arr){|m, n| h[m] = n}
    answer += 1 if h["a"] + h["c"] + h["f"] + 10 * (h["b"] + h["e"]) + 100 * h["d"] == 100 * h["g"] + 10 * h["h"] + h["i"]
}
puts answer

