str = gets.chomp
spell = gets.chomp
t = Array.new(spell.size+1, 0)
t[0] = 1
str.each_char do |c|
    new_t = Array.new(spell.size+1, 0)
    (0..spell.size).each do |i|
        if i < spell.size && c == spell[i]
            new_t[i+1] += t[i]
        end
        new_t[i] += t[i]
    end
    t = new_t.map {|k| k % 1_000_000_007}
end
p t[-1]
