#P16104. [ICPC 2019 NAIPC] Subsequences in Substrings
[ICPC 2019 NAIPC] Subsequences in Substrings
Problem Description
You are given two strings , and . Count the number of substrings of that contain as a subsequence at least once.
Note that a substring and a subsequence both consist of characters from the original string, in order. In a substring, the characters must be contiguous in the original string, but in a subsequence, they are not required to be contiguous. In the string abcde, ace is a subsequence but not a substring.
If is aa and is a, then the answer is 3: [a]a, [aa], and a[a].
Input Format
Each test case will consist of exactly two lines.
The first line will contain string (, ), with no other characters.
The second line will contain string (, , ), with no other characters.
Output Format
Output a single integer, which is the number of substrings of that contain as a subsequence at least once.
abcdefghijklmnopqrstuvwxyz
a
26
abcdefghijklmnopqrstuvwxyz
m
182
penpineappleapplepen
ppap
68