Color Changing Sofa

滴答滴答---题目链接 

Statements

Piva has recently bought a wonderful beach house at Praia do Forte.

After deciding that his house would be as colorful as a rainbow, Piva painted his living room in tiles of different colors. More specifically, Piva's living room can be seen as a row of nn tiles such that the ii-th of them has color sisi, where ss is a string composed of lowercase English characters.

Piva now wants to put his brand-new color changing sofa in his room. The sofa is mm (m≤nm≤n) tiles long and should be put in the room in a way that it fits entirely on mm consecutive tiles. Moreover, Piva wants the colors of the sofa and of the floor to match. We say that their colors match if the color of a sofa tile matches with the color of the floor tile right below it. To accomplish that, Piva may change the colors of the sofa according to its specification.

The sofa can be described by a string tt of zeroes and ones of length mm, where each character in the string represents a tile of the sofa. Piva can pick the zero-tiles and change them all to the same color. The same can be done for one-tiles. Therefore, notice that it is impossible for two zero-tiles (same for one-tiles) to have different colors. Also, that means that the tiles of the sofa will have at mosttwo different colors. For instance, suppose the string is 101. That means we can color the sofa aba or aaa, but not abc.

Given the descriptions of Piva's living room and of his sofa, determine on how many positions his sofa can be placed. Notice that for each possible placement, the sofa colors can be chosen independently. Also, notice that the sofa can be put in any direction (left to right or right to left), but a position where it can be put in both directions should be counted only once.

Input

The first line contains the string ss (|s|=n≤2000|s|=n≤2000) – the living room description.

The second line contains the string of zeroes and ones tt (|t|=m≤n|t|=m≤n) – the sofa description.

Output

Print a single integer – the number of positions the sofa can be placed.

Examples

Input

aba
10

Output

2

Input

aba
111

Output

0

Input

aaa
101

Output

1

Input

abada
101

Output

2

Input

aab
100

Output

1

Note

In the first example, we can put the sofa in two positions.

  1. Position [1,2][1,2], color mapping (0→a,1→b)(0→a,1→b), left to right.
  2. Position [2,3][2,3], color mapping (0→b,1→a)(0→b,1→a), left to right.

Notice there are other correct direction and color mapping configurations for each of these positions. The ones shown above are just examples.

In the second example, there is no way to place the sofa and to choose its colors such that there is a color match.

In the third example, we can put the sofa in [1,3][1,3], color mapping (0→a,1→a)(0→a,1→a), left to right.

In the fourth example, we can put the sofa in two positions:

  1. Position [1,3][1,3], color mapping (0→a,1→b)(0→a,1→b), left to right.
  2. Position [3,5][3,5], color mapping (0→a,1→d)(0→a,1→d), left to right.

In the fifth example, we can put the sofa in [1,3][1,3], color mapping (0→a,1→b)(0→a,1→b), right to left.

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
const int N=2001;
int main()
{
    char b[N];
    char a[N];
    scanf("%s",a);
    scanf("%s",b);
    int n=strlen(a);
    int m=strlen(b);
    int ans=0;
    set<char>p,q;
    for(int i=0; i<=n-m; i++)
    {
        p.clear();
        q.clear();
        for(int j=0; j<m; j++)
        {
            if(b[j]=='0')
                p.insert(a[i+j]);
            else q.insert(a[i+j]);
        }
        if(p.size()>1||q.size()>1)
        {
            p.clear();
            q.clear();

            for(int j=0; j<m; j++)
            {
                if(b[j]=='0')
                    p.insert(a[i+m-1-j]);
                else q.insert(a[i+m-1-j]);
            }
            if(p.size()>1||q.size()>1);
                else ans++;
        }
        else ans++;
    }

    printf("%d\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/83629056