Under construction

Still being built. Things may change

Orderly Class

Interview

Time limit2sMemory limit512 MB

Summary
Given two equal-length strings A and B, count the intervals in A such that reversing that interval turns A into B.
Level

Medium6 of 10

Topics
String, Two pointers, Implementation, Brute force
Solved
No attempts yet

Problem

Ms. Thomas is managing her class of nn students. She placed all of them in a line and gave the ii-th student from the left a card with the letter aia_i written on it.

She would now like to rearrange the students so that the ii-th student from the left holds a card with the letter bib_i written on it. She has one way to do it. She chooses a group of consecutive students and reverses the order of that group. Every student keeps the original card while the group is reversed.

Count the ways to do this. Two ways are different when the first position or the last position of the chosen group differs. If no single reversal turns AA into BB, the answer is 0.

For AA equal to abba and BB equal to aabb, the only group is a(bba). For AA equal to caxcab and BB equal to cacxab, there are two groups, ca(xc)ab and c(axca)b. For AA equal to a and BB equal to z, there is no group to choose.

Input

The first line holds the string AA and the second line holds the string BB. Both strings consist of lowercase English letters only. The ii-th character of AA is aia_i and the ii-th character of BB is bib_i. The two strings have the same length nn with 1≤n≤1000001 \le n \le 100000, and AA and BB are not identical.

Output

Print one integer, the number of ways to reverse a single consecutive group of AA so that the result is BB.

Examples3

  1. Example 1

    Input
    abba
    aabb
    
    Expected output
    1
    
  2. Example 2

    Input
    caxcab
    cacxab
    
    Expected output
    2
    
  3. Example 3

    Input
    a
    z
    
    Expected output
    0