@n = gets.to_i
@c = @n.times.map {gets.to_i}
M = 10 ** 9 + 7
@memo = Array.new(@n)

def calc(i, f)
    return f == 0 ? 1 : 0 if i == @n

    if f == 0
        @memo[i] ? @memo[i] : @memo[i] = (calc(i+1, @c[i]) + calc(i+1, 0)) % M
    elsif @c[i] != f
        calc(i+1, f)
    elsif @c[i-1] == f
        0
    else
        @memo[i]
    end
end

@n.times {|i| calc(@n-i-1, 0)}
p @memo[0]