#include<bits/stdc++.h>
using namespace std;
#define N 710
#define mod 1000000007
int dp[2][N][N];
int all[2][N][N];
int pos[2],pre[2][N];
int cnt[2];
int main()
{
string s1,s2;
cin >> s1 >> s2;
pos[0]=pos[1]=-1;
for(int i=0; i<s1.size(); i++)
{
pre[0][i]=pos[0];
pre[1][i]=pos[1];
pos[s1[i]-'0']=i;
}
for(int i=0; i<s2.size(); i++) cnt[s2[i]-'0']++;
int ans=0;
for(int p=0; p<s1.size(); p++)
{
int nw=s1[p]-'0';
if(nw==0)
{
if(pre[nw][p]==-1)
{
dp[0][1][0]=1;
all[0][1][0]=1;
for(int i=1; i<=cnt[1]; i++)
{
dp[0][1][i]=all[1][0][i];
all[0][1][i]=all[1][0][i];
}
}
else
{
for(int i=cnt[0]; i>=0; i--)
{
for(int j=cnt[1]; j>=0; j--)
{
if(i>0) dp[0][i][j]=dp[0][i-1][j];
else dp[0][i][j]=0;
if(i>0) dp[0][i][j]+=all[1][i-1][j];
dp[0][i][j]%=mod;
all[0][i][j]+=dp[0][i][j];
all[0][i][j]%=mod;
}
}
}
memset(all[1],0,sizeof (all[1]));
ans+=dp[0][cnt[0]][cnt[1]];
ans%=mod;
}
else
{
if(pre[nw][p]==-1)
{
dp[1][0][1]=1;
all[1][0][1]=1;
for(int i=1; i<=cnt[0]; i++)
{
dp[1][i][1]=all[0][i][0];
all[1][i][1]=all[0][i][0];
}
}
else
{
for(int i=cnt[0]; i>=0; i--)
{
for(int j=cnt[1]; j>=0; j--)
{
if(j>0) dp[1][i][j]=dp[1][i][j-1];
else dp[1][i][j]=0;
if(j>0) dp[1][i][j]+=all[0][i][j-1];
dp[1][i][j]%=mod;
all[1][i][j]+=dp[1][i][j];
all[1][i][j]%=mod;
}
}
}
memset(all[0],0,sizeof (all[0]));
ans+=dp[1][cnt[0]][cnt[1]];
ans%=mod;
}
}
cout<<ans<<endl;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgTiA3MTAKI2RlZmluZSBtb2QgMTAwMDAwMDAwNwoKaW50IGRwWzJdW05dW05dOwppbnQgYWxsWzJdW05dW05dOwppbnQgcG9zWzJdLHByZVsyXVtOXTsKaW50IGNudFsyXTsKCmludCBtYWluKCkKewogICAgCiAgICBzdHJpbmcgczEsczI7CiAgICBjaW4gPj4gczEgPj4gczI7CiAgICBwb3NbMF09cG9zWzFdPS0xOwogICAgZm9yKGludCBpPTA7IGk8czEuc2l6ZSgpOyBpKyspCiAgICB7CiAgICAgICAgcHJlWzBdW2ldPXBvc1swXTsKICAgICAgICBwcmVbMV1baV09cG9zWzFdOwogICAgICAgIHBvc1tzMVtpXS0nMCddPWk7CiAgICB9CiAgICBmb3IoaW50IGk9MDsgaTxzMi5zaXplKCk7IGkrKykgY250W3MyW2ldLScwJ10rKzsKICAgIGludCBhbnM9MDsKICAgIGZvcihpbnQgcD0wOyBwPHMxLnNpemUoKTsgcCsrKQogICAgewogICAgICAgIGludCBudz1zMVtwXS0nMCc7CiAgICAgICAgaWYobnc9PTApCiAgICAgICAgewogICAgICAgICAgICBpZihwcmVbbnddW3BdPT0tMSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZHBbMF1bMV1bMF09MTsKICAgICAgICAgICAgICAgIGFsbFswXVsxXVswXT0xOwogICAgICAgICAgICAgICAgZm9yKGludCBpPTE7IGk8PWNudFsxXTsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGRwWzBdWzFdW2ldPWFsbFsxXVswXVtpXTsKICAgICAgICAgICAgICAgICAgICBhbGxbMF1bMV1baV09YWxsWzFdWzBdW2ldOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZm9yKGludCBpPWNudFswXTsgaT49MDsgaS0tKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGZvcihpbnQgaj1jbnRbMV07IGo+PTA7IGotLSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGk+MCkgZHBbMF1baV1bal09ZHBbMF1baS0xXVtqXTsKICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBkcFswXVtpXVtqXT0wOwogICAgICAgICAgICAgICAgICAgICAgICBpZihpPjApIGRwWzBdW2ldW2pdKz1hbGxbMV1baS0xXVtqXTsKICAgICAgICAgICAgICAgICAgICAgICAgZHBbMF1baV1bal0lPW1vZDsKICAgICAgICAgICAgICAgICAgICAgICAgYWxsWzBdW2ldW2pdKz1kcFswXVtpXVtqXTsKICAgICAgICAgICAgICAgICAgICAgICAgYWxsWzBdW2ldW2pdJT1tb2Q7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIG1lbXNldChhbGxbMV0sMCxzaXplb2YgKGFsbFsxXSkpOwogICAgICAgICAgICBhbnMrPWRwWzBdW2NudFswXV1bY250WzFdXTsKICAgICAgICAgICAgYW5zJT1tb2Q7CgogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZihwcmVbbnddW3BdPT0tMSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZHBbMV1bMF1bMV09MTsKICAgICAgICAgICAgICAgIGFsbFsxXVswXVsxXT0xOwogICAgICAgICAgICAgICAgZm9yKGludCBpPTE7IGk8PWNudFswXTsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGRwWzFdW2ldWzFdPWFsbFswXVtpXVswXTsKICAgICAgICAgICAgICAgICAgICBhbGxbMV1baV1bMV09YWxsWzBdW2ldWzBdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZm9yKGludCBpPWNudFswXTsgaT49MDsgaS0tKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGZvcihpbnQgaj1jbnRbMV07IGo+PTA7IGotLSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGo+MCkgZHBbMV1baV1bal09ZHBbMV1baV1bai0xXTsKICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBkcFsxXVtpXVtqXT0wOwogICAgICAgICAgICAgICAgICAgICAgICBpZihqPjApIGRwWzFdW2ldW2pdKz1hbGxbMF1baV1bai0xXTsKICAgICAgICAgICAgICAgICAgICAgICAgZHBbMV1baV1bal0lPW1vZDsKICAgICAgICAgICAgICAgICAgICAgICAgYWxsWzFdW2ldW2pdKz1kcFsxXVtpXVtqXTsKICAgICAgICAgICAgICAgICAgICAgICAgYWxsWzFdW2ldW2pdJT1tb2Q7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIG1lbXNldChhbGxbMF0sMCxzaXplb2YgKGFsbFswXSkpOwogICAgICAgICAgICBhbnMrPWRwWzFdW2NudFswXV1bY250WzFdXTsKICAgICAgICAgICAgYW5zJT1tb2Q7CiAgICAgICAgfQogICAgfQogICAgY291dDw8YW5zPDxlbmRsOwoKCn0KCg==