Orderly Class | 프로그래밍의 벗 PivotOJ
PivotOJ

Orderly Class

시간 제한: 2000ms메모리 제한: 512MB출처: ICPC Mid-Central Regional 2017BOJ 15100

문제

Ms. Thomas is managing her class of n students.

She placed all her students in a line, and gave the i-th student from the left a card with the letter ai written on it.

She would now like to rearrange the students so that the i-th student from the left has a card with the letter bi written on it.

To do this, she will choose some consecutive group of students, and reverse their order. Students will hold on to their original cards during this process.

She’s now wondering, what is the number of valid ways to do this? (It may be impossible, in which case, the answer is zero). With sequences abba and aabb, Ms. Thomas can choose the group a(bba).

With sequences caxcab and cacxab, Ms. Thomas can choose ca(xc)ab or c(axca)b. With sequences a and z, there are clearly no solutions.

입력

The input is two lines of lowercase letters, A and B. The i-th character of A and B represent ai and bi respectively. It is guaranteed that A and B have the same positive length, and A and B are not identical. The common length is allowed to be as large as 100 000.

출력

For each test case, output a single integer, the number of ways Ms. Thomas can reverse some consecutive group of A to form the line specified by string B.

예제

예제 1

입력
abba
aabb
출력
1

예제 2

입력
caxcab
cacxab
출력
2

예제 3

입력
a
z
출력
0
코드를 제출하려면 로그인하세요.