//Ishan Bansal
//handle:ishan.nitj at codeforces ,ishan_nitj at codechef
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128
#define mag 1000000
#define inf 1000000000000000000
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define mset(x,v) memset(x, v, sizeof(x))
#define print_array(a,n) for(i=0;i<n;i++) printf("%lld ",a[i]);
#define dbg1(x) cout<<#x<<" "<<x<<endl;
#define dbg2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define dbg4(x,y,z,k) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<" "<<#k<<" "<<k<<endl;
#define pb push_back
#define fe first
#define se second
ll dp[15][1<<15];
string g,f;
ll n;
ll count_one(ll n){// to count no of ones in a binary form of a number
ll count=0;
while(n){
n=n&(n-1);
count++;
}
return count;
}
ll func(ll last,ll mask){
if(dp[last][mask]!=-1)
return dp[last][mask];
ll pos=count_one(mask)-1;
ll ans=0;
if(count_one(mask)==1){
if(mask&(1<<last))
ans=1;
}
else{
set<char>s;
mask=mask&~(1<<last);
for(ll k=0;k<n;k++){
if(mask&(1<<k)){
if(g[k]!=g[last] && s.find(g[k])==s.end() && f[count_one(mask)-1]!=g[k]){
s.insert(g[k]);
ans+=func(k,mask);
}
}
}
}
dp[last][mask]=ans;
return ans;
}
int main(){
mset(dp,-1);
cin>>g>>f;
n=g.size();
ll ans=0;
set<char>s;
for(ll i=0;i<n;i++){
if(s.find(g[i])==s.end()){
ans+=func(i,(1<<n)-1);
s.insert(g[i]);
}
}
cout<<(ans);
}
Ly9Jc2hhbiBCYW5zYWwKLy9oYW5kbGU6aXNoYW4ubml0aiBhdCBjb2RlZm9yY2VzICxpc2hhbl9uaXRqIGF0IGNvZGVjaGVmCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW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