#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn = 5e5+7;
int n;
long long p[maxn];
char s[maxn];
long long sum1[maxn];
long long sum2[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&p[i]);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        sum1[i]=sum1[i-1];
        sum2[i]=sum2[i-1];
        if(s[i]=='A')
            sum1[i]+=p[i];
        else
            sum2[i]+=p[i];
    }
    long long ans = max(sum2[n],sum1[n]);
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,sum2[n]-sum2[i]+sum1[i]);
        ans = max(ans,sum2[i]+sum1[n]-sum1[i]);
    }
    printf("%d\n",ans);
}


#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
const int maxn=5e5+10;
#define LL long long
int cas=1,T;
int n;
LL p[maxn];
char s[maxn];
LL sum1[maxn],sum2[maxn];
int main()
{
    scanf("%d",&n);
    for (int i = 1;i<=n;i++)
        scanf("%d",&p[i]);
    scanf("%s",s+1);
    for (int i = 1;i<=n;i++)
    {
        sum1[i]=sum1[i-1];
        sum2[i]=sum2[i-1];
        if (s[i]=='A')
            sum1[i]+=p[i];
        else
            sum2[i]+=p[i];
    }
    LL ans = max(sum1[n],sum2[n]);
    for (int i = 1;i<=n;i++)
    {
        ans = max(ans,sum2[n]-sum2[i]+sum1[i]);
        ans = max(ans,sum2[i]+sum1[n]-sum1[i]);
    }
    cout << ans << endl;
    //freopen("in","r",stdin);
    //scanf("%d",&T);
    //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli maxi=0,ans=0,ans1=0,init=0,alpha=0;
lli p[n];
char s[500002]={'\0'};
for(lli i=0;i<n;i++){
	slli(p[i]);
}
ss(s);
for( lli i=0;i<n;i++){
		if(s[i]=='B')
			init+=p[i]%mod;
		init%=mod;
		}
maxi=init;
for( lli i=0;i<n;i++){
	if(s[i]=='A')
		ans+=p[i]%mod;
	else
		ans1+=p[i]%mod;
	ans%=mod;
	ans1%=mod;
	if(ans>=ans1){
	ans-=ans1;
	ans%=mod;
	alpha = init + ans;
	alpha%=mod;
	if(alpha>maxi)
		maxi=alpha%mod;
	}
}
ans=0;
ans1=0;
alpha=0;
for( lli i=n-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i]%mod;
	else
		ans1+=p[i]%mod;
	ans%=mod;
	ans1%=mod;
	if(ans>=ans1){
	ans-=ans1;
	ans%=mod;
	alpha = init + ans;
	alpha%=mod;
	if(alpha>maxi)
		maxi=alpha%mod;
	}
}
printf("%lli",maxi);
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli maxi=0,ans=0,init=0,alpha=0;
lli p[n];
char s[500002]={'\0'};
for(lli i=0;i<n;i++){
	slli(p[i]);
}
ss(s);
for( lli i=0;i<n;i++){
		if(s[i]=='B')
			init+=p[i]%mod;
		init%=mod;
		}
maxi=init;
for( lli i=0;i<n;i++){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	if(ans>0)
		ans%=mod;
	alpha = init + ans;
	if(alpha>0)
		alpha%=mod;
	if(alpha>maxi)
		maxi=alpha%mod;
}
ans=0;
alpha=0;
for( lli i=n-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	if(ans>0)
		ans%=mod;
	alpha = init + ans;
	if(alpha>0)
		alpha%=mod;
	if(alpha>maxi)
		maxi=alpha%mod;
}
printf("%lli",maxi);
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli maxi=0,ans=0,init=0;
lli p[n];
string s;
for(lli i=0;i<n;i++){
	slli(p[i]);
}
cin>>s;
int l=s.length();
for( lli i=0;i<l;i++){
	if(s[i]=='A')
		ans+=p[i];
	else{
		init+=p[i];
		ans-=p[i];
	}
	if(ans>maxi)
		maxi=ans;
}
ans=0;
for( lli i=l-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	if(ans>maxi)
		maxi=ans;
}
printf("%lli",maxi+init);
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli maxi=0,ans=0,init=0,alpha=0;
lli p[n];
char s[500002]={'\0'};
for(lli i=0;i<n;i++){
	slli(p[i]);
}
ss(s);
for( lli i=0;i<n;i++){
		if(s[i]=='B')
			init+=p[i];
		}
for( lli i=0;i<n;i++){
	if(s[i]=='A')
		ans+=p[i];
	else{
		ans-=p[i];
	}
	alpha = init + ans;
	if(alpha>maxi)
		maxi=alpha;
}
ans=0;
alpha=0;
for( lli i=n-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
		alpha = init + ans;
	if(alpha>maxi)
		maxi=alpha;
}
printf("%lli",maxi);
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli maxi=0,ans=0,init=0,alpha=0;
lli p[n];
char s[500002]={'\0'};
for(lli i=0;i<n;i++){
	slli(p[i]);
}
ss(s);
for( lli i=0;i<n;i++){
		if(s[i]=='B')
			init+=p[i];
		}
maxi=init;
for( lli i=0;i<n;i++){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	alpha = init + ans;
	if(alpha>maxi)
		maxi=alpha;
}
ans=0;
alpha=0;
for( lli i=n-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	alpha = init + ans;
	if(alpha>maxi)
		maxi=alpha;
}
printf("%lli",maxi);
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
const double PI = 3.14159265359;
int INF = 2147483645;
lli INFINF = 9223372036854775807;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
lli n;
slli(n);
lli max=0,ans=0,init=0;
lli p[n];
string s;
for(int i=0;i<n;i++){
	slli(p[i]);
}
cin>>s;
int l=s.length();
forn(i,l){
	if(s[i]=='A')
		ans+=p[i];
	else{
		init+=p[i];
		ans-=p[i];
	}
	if(ans>max)
		max=ans;
}
ans=0;
for( int i=l-1;i>=0;i--){
	if(s[i]=='A')
		ans+=p[i];
	else
		ans-=p[i];
	if(ans>max)
		max=ans;
}
cout<<max+init;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
const ll N=5e5;

ll p[N],pre[N],suf[N];
int main()
{
   // cout<<N<<endl;
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll n,i,val2=0;

    cin>>n;

    fr(i,0,n-1)
    {
        scanf("%d",&p[i]);

    }

    string s;
    cin>>s;

    ll val=0,l;

    fr(i,0,n-1)
    if(s[i]=='B')
    {
        if(i<=n-2)
            val+=p[i],suf[i+1]=val;

        val2+=p[i];
    }

    val=0;

    frn(i,n-1,1)
    if(s[i]=='B')
        val+=p[i],pre[i-1]=val;

    /*fr(i,0,n-1)
    cout<<pr[i]<<" ";

    cout<<endl;

    fr(i,0,n-1)
    cout<<su[i]<<" ";

    cout<<endl;
    */

    //cout<<s<<endl;

    ll mx1=-100;

    val=0;
    mx1=max(mx1,val2);

    fr(i,0,n-1)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+pre[i]);
    }
    else
        mx1=max(mx1,val+pre[i]);

    val=0;

    frn(i,n-1,0)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+suf[i]);
    }
    else
        mx1=max(mx1,val+suf[i]);

    cout<<mx1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
const ll N=5e5;

ll p[N],pre[N],suf[N];
ll main()
{
   // cout<<N<<endl;
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll n,i,val2=0;

    cin>>n;

    fr(i,0,n-1)
    {
        scanf("%d",&p[i]);

    }

    string s;
    cin>>s;

    ll val=0,l;

    fr(i,0,n-1)
    if(s[i]=='B')
    {
        if(i<=n-2)
            val+=p[i],suf[i+1]=val;

        val2+=p[i];
    }

    val=0;

    frn(i,n-1,1)
    if(s[i]=='B')
        val+=p[i],pre[i-1]=val;

    /*fr(i,0,n-1)
    cout<<pr[i]<<" ";

    cout<<endl;

    fr(i,0,n-1)
    cout<<su[i]<<" ";

    cout<<endl;
    */

    //cout<<s<<endl;

    ll mx1=-100;

    val=0;
    mx1=max(mx1,val2);

    fr(i,0,n-1)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+pre[i]);
    }
    else
        mx1=max(mx1,val+pre[i]);

    val=0;

    frn(i,n-1,0)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+suf[i]);
    }
    else
        mx1=max(mx1,val+suf[i]);

    cout<<mx1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
const ll N=5e5;

ll p[N],pre[N],suf[N];
int main()
{
    // cout<<N<<endl;
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll n,i,val2=0;

    cin>>n;

    fr(i,0,n-1)
    scanf("%d",&p[i]);

    string s;
    cin>>s;

    ll val=0,l;

    fr(i,0,n-1)
    if(s[i]=='B')
    {
        if(i<=n-2)
            val+=p[i],suf[i+1]=val;

        val2+=p[i];
    }

    val=0;

    frn(i,n-1,1)
    if(s[i]=='B')
        val+=p[i],pre[i-1]=val;

    ll mx1=-100;

    val=0;
    mx1=max(mx1,val2);

    fr(i,0,n-1)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+pre[i]);
    }
    else
        mx1=max(mx1,val+pre[i]);

    val=0;

    frn(i,n-1,0)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+suf[i]);
    }
    else
        mx1=max(mx1,val+suf[i]);

    cout<<mx1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
const int N=5e5;

int p[N],pre[N],suf[N];
int main()
{
   // cout<<N<<endl;
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    int n,i,val2=0;

    cin>>n;

    fr(i,0,n-1)
    {
        scanf("%d",&p[i]);

    }

    string s;
    cin>>s;

    int val=0,l;

    fr(i,0,n-1)
    if(s[i]=='B')
    {
        if(i<=n-2)
            val+=p[i],suf[i+1]=val;

        val2+=p[i];
    }

    val=0;

    frn(i,n-1,1)
    if(s[i]=='B')
        val+=p[i],pre[i-1]=val;

    /*fr(i,0,n-1)
    cout<<pr[i]<<" ";

    cout<<endl;

    fr(i,0,n-1)
    cout<<su[i]<<" ";

    cout<<endl;
    */

    //cout<<s<<endl;

    int mx1=-100;

    val=0;
    mx1=max(mx1,val2);

    fr(i,0,n-1)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+pre[i]);
    }
    else
        mx1=max(mx1,val+pre[i]);

    val=0;

    frn(i,n-1,0)
    if(s[i]=='A')
    {
        val+=p[i];
        mx1=max(mx1,val+suf[i]);
    }
    else
        mx1=max(mx1,val+suf[i]);

    cout<<mx1<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cmath>
#include<fstream>
#include<conio.h>
using namespace std;
int main()
{
    int n,p[100002];
    char s[100002];
    int a[100002];
    long long ans=0,res=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i];
    for(int i=0;i<n;i++)
        cin>>s[i];
    if(s[0]=='B')
        a[0]=p[0];
    else
        a[0]=0;
    ans=a[0];
    for(int i=1;i<n;i++)
    {
        a[i]=a[i-1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i-1]+res);
        }
    }
    if(s[n-1]=='B')
        a[n-1]=p[n-1];
    else
        a[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        a[i]=a[i+1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    res=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i+1]+res);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cmath>
#include<fstream>
#include<conio.h>
using namespace std;
int n,p[500002];
char s[500002];
int a[500002];
int main()
{
    long long ans=0,res=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i];
    for(int i=0;i<n;i++)
        cin>>s[i];
    if(s[0]=='B')
        a[0]=p[0];
    else
        a[0]=0;
    for(int i=1;i<n;i++)
    {
        a[i]=a[i-1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    ans=a[n-1];
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i-1]+res);
        }
    }
    if(s[n-1]=='B')
        a[n-1]=p[n-1];
    else
        a[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        a[i]=a[i+1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    res=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i+1]+res);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cmath>
#include<fstream>
#include<conio.h>
using namespace std;
int n,p[500002];
char s[500002];
long long a[500002];
int main()
{
    long long ans=0,res=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i];
    for(int i=0;i<n;i++)
        cin>>s[i];
    if(s[0]=='B')
        a[0]=p[0];
    else
        a[0]=0;
    for(int i=1;i<n;i++)
    {
        a[i]=a[i-1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    ans=a[n-1];
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i-1]+res);
        }
    }
    if(s[n-1]=='B')
        a[n-1]=p[n-1];
    else
        a[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        a[i]=a[i+1];
        if(s[i]=='B')
            a[i]+=p[i];
    }
    res=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A')
        {
            res+=p[i];
            ans=max(ans,a[i+1]+res);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
   string s,t;
   int p[30],q[30];
   while(cin)
   {
	   getline(cin,s);
	   getline(cin,t);
	   for(int i=1;i<=30;i++)
		   p[i]=0;
	   int ls=s.length();
	   int lt=t.length();

	   for(int i=0;i<=lt-1;i++)
		   p[t[i]-96]++;
       int ans=0;

	   for(int i=0;i<=ls-lt;i++)
	   {
          for(int j=1;j<=26;j++)
			  q[j]=0;
          int sum=0,ss=0;
		  for(int j=i;j<=i+lt-1;j++)
		  {
			  if(s[j]=='?') sum++;
			  else q[s[j]-96]++;
		  }
		  for(int j=1;j<=26;j++)
		  {
			  if(p[j]-q[j]>0) ss+=p[j]-q[j];
		  }
		  if(sum>=ss) ans++;
	   }
      printf("%d\n",ans);

   }

    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 1000000
using namespace std;
char a[10001],b[10001];
int c2[31],c1[31];
int pd(int *c1,int *c2)
{
	int i;
	for(i=0;i<=25;i++){
		if(c1[i]>c2[i]) return 0;
	}
	return 1;
}
int main()
{
	    int i;
	while(scanf("%s %s",a,b)!=EOF){
		int len2=strlen(b);
		int len1=strlen(a);
		if(len2>len1) {cout<<0<<endl;continue;}
	    for(i=0;i<=30;i++) c1[i]=c2[i]=0;
		for(i=0;i<len2;i++) {
			c2[b[i]-'a']++;
			if(a[i]!='?') c1[a[i]-'a']++;
		}
		int cou=pd(c1,c2);
		for(i=len2;i<len1;i++){
			if(a[i-len2]!='?')
			  c1[a[i-len2]-'a']--;
			if(a[i]!='?') c1[a[i]-'a']++;
			cou+=pd(c1,c2);
		}
		cout<<cou<<endl;
	}
}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

string str1,str2;
long a[30],b[30];
long ans=0;
long len;
long flag=0;

int main(){
	getline(cin,str1);
	getline(cin,str2);
	len=str2.length();;
	for (int i=0;i<len;i++)
		if (b[str2[i]-97]!='?')
			b[str2[i]-97]++;
	for (int i=0;i<=str1.length();i++){
		if (i>=len){
			if (flag==0) ans++;
			if (str1[i-len]!='?'){
			       	a[str1[i-len]-97]--;
				if (a[str1[i-len]-97]==b[str1[i-len]-97])
					flag--;
			}
		}
		if (i<str1.length())
		if (str1[i]!='?'){
			if (a[str1[i]-97]==b[str1[i]-97]) flag++;
		       	a[str1[i]-97]++;
		}
	}
	printf("%d\n",ans);
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;
string s1, s2;
int main(){
	int i;
	for(; cin >> s1 >> s2;){
		int num1[26], num2[26];
		memset(num1, 0, sizeof(num1));
		memset(num2, 0, sizeof(num2));
		for( i = 0; i < s2.length(); i++){
			num2[s2[i]-'a']++;
		}
		int num = 0, ans = 0;
		if(s2.length() > s1.length())
			cout << ans <<endl;
		else{
			for(i = 0; i < s2.length() - 1; i++){
				if(s1[i] == '?')
					num++;
				else
					num1[s1[i]-'a']++;
			}
			while(i < s1.length()){
				if(i >= s2.length()){
					if(s1[i-s2.length()]=='?')
						num--;
					else
						num1[s1[i-s2.length()]-'a']--;
				}
				if(s1[i]=='?')
					num++;
				else
					num1[s1[i]-'a']++;
				bool flag = true;
				for(int j = 0; j < 26; j++){
					if(num1[j] > num2[j]){
						flag = false;
					}
				}
				if(flag)
					ans++;
				i++;
			}
			cout << ans <<endl;
		}
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[100005],b[100005];
struct pp{
	int p[26];
	pp()
	{
		memset(p,0,sizeof(p));
		memset(p,0,sizeof(p));
	}
};
int main()
{
	scanf("%s%s",&a,&b);
	int ans=0;
	int lb=strlen(b);
	int la=strlen(a);
	if(la<lb) printf("0\n");
	else
	{
		pp aa,bb;
		for(int i=0;i<lb;i++) bb.p[b[i]-'a']++;
		for(int i=0;i<lb;i++) aa.p[a[i]-'a']++;
		//for(int i=0;i<26;i++) cout<<bb.p[i]<<" "<<aa.p[i]<<endl;
		for(int i=lb-1;i<la;i++)
		{
			bool f=true;
			for(int j=0;j<26;j++) {
				if(aa.p[j]>bb.p[j]) {f=false;break;}
			}
			if(f) ans++;
			if(i!=la-1) {
				aa.p[a[i+1]-'a']++;
				aa.p[a[i+1-lb]-'a']--;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
   // if(S=="v") {cout<<"0"<<endl;return 0;}
    REP(i,szp) p[P[i]]++;
    for(i=0;i<szp-1 && i<szs;i++)s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=szp) s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
    REP(i,szp) p[P[i]]++;REP(i,szp-1) s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=szp)
             s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
   // if(S=="v") {cout<<"0"<<endl;return 0;}
    REP(i,szp) p[P[i]]++;
    REP(i,szp-1) s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=szp) s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
    if(S=="v") {cout<<"0"<<endl;return 0;}
    REP(i,szp) p[P[i]]++;
    REP(i,szp-1) s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=szp) s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[50000],p[50000];
int main()
{
    int n,i,res=0;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
    REP(i,szp) p[P[i]]++;REP(i,szp-1) s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=szp)
             s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[256],p[256];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    if(S=="v") {cout<<"0"<<endl; return 0;}
    int szs=S.size(),szp=P.size();
   for(i=0;P[i];i++)p[P[i]]++; l=i;
   for(i=0;i<l-1;i++)s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=l) s[S[i-l]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
   for(i=0;P[i];i++)p[P[i]]++; l=i;
   for(i=0;i<l-1;i++)s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=l) s[S[i-l]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[256],p[256];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
   for(i=0;P[i];i++)p[P[i]]++; l=i;
   for(i=0;i<l-1;i++)s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=l) s[S[i-l]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
    REP(i,szp) p[P[i]]++;
    REP(i,szp-1) s[S[i]]++;
    for(;i<szs;i++)
    {
        s[S[i]]++;
        if(i>=szp)
        s[S[i-szp]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


/*  In The Name of GOD
    Site: Codeforces
    Round:
    Problem:
    Language: C++;
    Author: ASU(SUST)
*/
using namespace std;
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}
int sdigit(int num){int re=0;while(num){re+=num%10; num/=10;} return re;}
//bool Valid(int r,int c){if(r>=row || r<0 || c>=col || c<0) return 0; return 1;}
//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int s[500],p[500];
int main()
{
    int n,i,res=0,l;
    string S="",P="";
    cin>>S>>P;
    int szs=S.size(),szp=P.size();
    REP(i,szp) p[P[i]]++; l=i;
    REP(i,l-1) s[S[i]]++;
    for(;S[i];i++)
    {
        s[S[i]]++;
        if(i>=l) s[S[i-l]]--;
            for(char ch='a';ch<='z';ch++)
            {
                if(s[ch]>p[ch])
                {
                    res--;
                    break;
                }
            }
        res++;
    }
    cout<<res<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char ch[100001],p[100001],m[27],n[27];
int main()
{

    //freopen("input.txt","r",stdin);
    cin>>ch;
    cin>>p;
    int x=strlen(p),y=strlen(ch);
    for(int i=0;i<x;i++)
    {
        m[p[i]-'a']++;
    }
    int ans=0;
    for(int i=x-1;i<y;i++)
    {
        int q=0;
        for(int j=i;j>i-x;j--)
        {
            if(ch[j]!='?')
            {
                n[ch[j]-'a']++;
                if(m[ch[j]-'a']-n[ch[j]-'a']<0)
                {
                    q=1;
                    break;
                }
            }
        }
        for(int k=0;k<27;k++)n[k]=0;
        if(q==0)ans++;
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char ch[100001],p[100001],m[27],n[27];
int main()
{

    //freopen("input.txt","r",stdin);
    cin>>ch;
    cin>>p;
    int x=strlen(p),y=strlen(ch);
    for(int i=0;i<x;i++)
    {
        m[p[i]-'a']++;
    }
    int ans=0;
    for(int i=0;i<y-x;i++)
    {
        int q=0;
        for(int j=i;j<i+x;j++)
        {
            if(ch[j]!='?')
            {
                n[ch[j]-'a']++;
                if(m[ch[j]-'a']-n[ch[j]-'a']<0)
                {
                    q=1;
                    break;
                }
            }
        }
        for(int k=0;k<27;k++)n[k]=0;
        if(q==0)ans++;
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char ch[100001],p[100001],m[27],n[27];
int main()
{

    //freopen("input.txt","r",stdin);
    cin>>ch;
    cin>>p;
    int x=strlen(p),y=strlen(ch);
    for(int i=0;i<x;i++)
    {
        m[p[i]-'a']++;
    }
    int ans=0;
    for(int i=0;i<=y-x;i++)
    {
        int q=0;
        for(int j=i;j<i+x;j++)
        {
            if(ch[j]!='?')
            {
                n[ch[j]-'a']++;
                if(m[ch[j]-'a']-n[ch[j]-'a']<0)
                {
                    q=1;
                    break;
                }
            }
        }
        for(int k=0;k<27;k++)n[k]=0;
        if(q==0)ans++;
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char ch[100001],p[100001],m[27],n[27];
int main()
{

    //freopen("input.txt","r",stdin);
    cin>>ch;
    cin>>p;
    int x=strlen(p),y=strlen(ch);
    for(int i=0;i<x;i++)
    {
        m[p[i]-'a']++;
    }
    int ans=0;
    for(int i=0;i<=y-x;i++)
    {
        int q=0;
        for(int j=i;j<i+x;j++)
        {
            if(ch[j]!='?')
            {
                n[ch[j]-'a']++;
                /*if(m[ch[j]-'a']-n[ch[j]-'a']<0)
                {
                    q=1;
                    break;
                }*/
            }
        }
        for(int k=0;k<27;k++)
        {
        	if(m[k]<n[k])
        	{
        		q=1;
        		break;
        	}
        }
        for(int k=0;k<27;k++)n[k]=0;
        if(q==0)ans++;
    }
    cout<<ans;
    return 0;
}


//~In The Name Of Allah~//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;

#define all(S) S.begin(), S.end()
#define sortb(S) sort(S.rbegin(), S.rend())
#define sorta(S) sort(all(S))
#define cinp(N) cin>>N.first>>N.second
#define coutp(N) cout<<N.first<<" "<<N.second<<endl
#define mem(C, V) memset(C, V, sizeof C)
#define clr(S, V) fill(all(S), V)
#define ssum(N) (ll)N*(N+1)/2
#define gt(S) getline(cin, S)
#define sp(N) setprecision(N)<<fixed
#define siz(S) S.size()
#define mk make_pair
#define go continue
#define rep(i, j) for (ll i = 0; i < j; i++)
#define rrep(i, j) for (ll i = j - 1; i > -1; i--)
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define Rep(i, j, k) for (ll i = j; i < k; i++)
#define RRep(i, j, k) for (ll i = k; i >= j; i--)
#define srep(C) for (decltype(C.begin()) it = C.begin(); it != C.end(); it++)
#define pi 3.1415926535897932384626433832795
#define ex 2.7182818284
#define mod 1000000007
#define oo (ll) 1e18+1

typedef stringstream ss;
typedef string s;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<s> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef map<s, ll> msi;

int main(){
    //freopen("input.txt", "r", stdin)
    //freopen("output.txt", "w", stdout)
    s str, sub, now = "";
    mci base, tmp;
    int size, len, have, need, x, y, ans = 0;
    cin >> str >> sub, size = siz(str), len = siz(sub);
    rep(i, len) base[sub[i]]++;
    rep(i, size){
        now += str[i], tmp[str[i]]++;
        if ((i + 1) >= len){
            have = tmp['?'], need = 0;
            for (mci::iterator it = base.begin(); it != base.end(); it++)
                x = tmp[it->first], y = it->second, (x != y) ? need += abs(x - y) : 0;
            ans += have == need, tmp[now[0]]--, now.erase(0, 1);
        }
    }
    printf("%d\n", ans);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;
#define sorta(STL) sort(STL.begin(), STL.end())
#define sortb(STL) sort(STL.begin(), STL.end(), g<int>())
#define all(STL) (STL.begin(), STL.end())
#define mk make_pair
#define ssum(Length) ull(Length*(Length+1)/2)
#define np next_permutation
#define gt(Str) getline(cin, Str)
#define g greater
#define re reverse
#define cinp(number) cin>>number.first>>number.second
#define coutp(number) cout<<number.first<<" "<<number.second<<endl;
#define sp(number) setprecision(number)<<fixed
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define rep(i, j) for (int i = 0; i < j; i++)
#define rep_(i, j, k) for (int i = j; i < k; i++)
#define rrep(i, size) for (int i = size - 1; i > -1; i--)
#define mrep(def, mapa) for (def::iterator it = mapa.begin(); it != mapa.end(); it++)
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define oo (int) 1e9
typedef stringstream ss;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<string, string> mss;
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string str1, str2, tmp = "";
    cin >> str1 >> str2;
    int result = 0, size = str1.size(), size_ = str2.size();
    rep(i, size){
        tmp += str1[i];
        if (tmp.size() == size_){
            int _ = 0, __ = 0;
            mci tt;
            rep(j, size_) tmp[j] == '?' ? _++ : 0, tt[tmp[j]]++;
            rep(j, size_) if (tt[str2[j]]) tt[str2[j]]--;
            else if (str2[j] != '?') __++;
            if (__ == _) result++;
            tmp.erase(0, 1);
        }
    }
    cout << result << endl;
    return 0;
}


//~In The Name Of Allah~//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;

#define all(S) S.begin(), S.end()
#define sortb(S) sort(S.rbegin(), S.rend())
#define sorta(S) sort(all(S))
#define cinp(N) cin>>N.first>>N.second
#define coutp(N) cout<<N.first<<" "<<N.second<<endl
#define mem(C, V) memset(C, V, sizeof C)
#define clr(S, V) fill(all(S), V)
#define ssum(N) (ll)N*(N+1)/2
#define gt(S) getline(cin, S)
#define sp(N) setprecision(N)<<fixed
#define siz(S) S.size()
#define mk make_pair
#define go continue
#define rep(i, j) for (ll i = 0; i < j; i++)
#define rrep(i, j) for (ll i = j - 1; i > -1; i--)
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define Rep(i, j, k) for (ll i = j; i < k; i++)
#define RRep(i, j, k) for (ll i = k; i >= j; i--)
#define srep(C) for (decltype(C.begin()) it = C.begin(); it != C.end(); it++)
#define pi 3.1415926535897932384626433832795
#define ex 2.7182818284
#define mod 1000000007
#define oo (ll) 1e18+1

typedef stringstream ss;
typedef string s;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<s> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef map<s, ll> msi;

char str[(int)1e5 + 1], sub[(int)1e5 + 1];
s now = "";
int base[26], tmp[27], size, len, have, need, x, y, ans = 0;

int main(){
    //freopen("input.txt", "r", stdin)
    //freopen("output.txt", "w", stdout)
    scanf("%s%s", &str, &sub), size = strlen(str), len = strlen(sub);
    rep(i, len) base[sub[i] - 'a']++;
    rep(i, size){
        now += str[i], str[i] == '?' ? tmp[26]++ : tmp[str[i] - 'a']++;
        if (i >= len - 1){
            have = tmp[26], need = 0;
            rep(j, 26) (base[j] && tmp[j] != base[j]) ? need += abs(tmp[j] - base[j]) : 0;
            ans += have == need, now[0] != '?' ? tmp[now[0] - 'a']-- : tmp[26]--, now.erase(0, 1);
        }
    }
    printf("%d\n", ans);
    return 0;
}


//~In The Name Of Allah~//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;
#define sorta(STL) sort(STL.begin(), STL.end())
#define sortb(STL) sort(STL.begin(), STL.end(), g<int>())
#define all(STL) STL.begin(), STL.end()
#define mk make_pair
#define ssum(Length) ull(Length*(Length+1)/2)
#define np next_permutation
#define gt(Str) getline(cin, Str)
#define g greater
#define re reverse
#define cinp(number) cin>>number.first>>number.second
#define coutp(number) cout<<number.first<<" "<<number.second<<endl;
#define sp(number) setprecision(number)<<fixed
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define rep(i, j) for (int i = 0; i < j; i++)
#define rep_(i, j, k) for (int i = j; i < k; i++)
#define rrep(i, size) for (int i = size - 1; i > -1; i--)
#define mrep(def, mapa) for (def::iterator it = mapa.begin(); it != mapa.end(); it++)
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define oo (int) 1e9
typedef stringstream ss;
typedef string s;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector< vector<int> > vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef multimap<int, int> mlii;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<string, string> mss;
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string str1, str2, tmp = "";
    cin >> str1 >> str2;
    mci array, base;
    int size = str1.size(), size_ = str2.size(), result = 0, need = 0;
    bool ys = 0;
    rep(i, size_) base[str2[i]]++;
    rep(i, size)
    if (str1[i] == '?' || base[str1[i]]){
        tmp += str1[i], array[str1[i]]++;
        if (tmp.size() == size_){
            mrep(mci, base) if (array[it->first] < it->second) need += it->second - array[it->first];
            else if (array[it->first] > it->second){ ys = 1; break; }
            if (array['?'] == need && !ys) result++;
            ys = need = 0, array[str1[i - size_ + 1]]--, tmp.erase(0, 1);
        }
    }
    else ys = need = 0, array.clear(), tmp = "";
    cout << result << endl;
    return 0;
}


//~In The Name Of Allah~//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;

#define all(S) S.begin(), S.end()
#define sortb(S) sort(S.rbegin(), S.rend())
#define sorta(S) sort(all(S))
#define cinp(N) cin>>N.first>>N.second
#define coutp(N) cout<<N.first<<" "<<N.second<<endl
#define mem(C, V) memset(C, V, sizeof C)
#define clr(S, V) fill(all(S), V)
#define ssum(N) (ll)N*(N+1)/2
#define gt(S) getline(cin, S)
#define sp(N) setprecision(N)<<fixed
#define siz(S) S.size()
#define mk make_pair
#define go continue
#define rep(i, j) for (ll i = 0; i < j; i++)
#define rrep(i, j) for (ll i = j - 1; i > -1; i--)
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define Rep(i, j, k) for (ll i = j; i < k; i++)
#define RRep(i, j, k) for (ll i = k; i >= j; i--)
#define srep(C) for (decltype(C.begin()) it = C.begin(); it != C.end(); it++)
#define pi 3.1415926535897932384626433832795
#define ex 2.7182818284
#define mod 1000000007
#define oo (ll) 1e18+1

typedef stringstream ss;
typedef string s;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<s> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef map<s, ll> msi;

char str[(int)1e5 + 1], sub[(int)1e5 + 1];
s now = "";
mci base, tmp;
int size, len, have, need, x, y, ans = 0;

int main(){
    //freopen("input.txt", "r", stdin)
    //freopen("output.txt", "w", stdout)
    scanf("%s%s", &str, &sub), size = strlen(str), len = strlen(sub);
    rep(i, len) base[sub[i]]++;
    rep(i, size){
        now += str[i], tmp[str[i]]++;
        if ((i + 1) >= len){
            have = tmp['?'], need = 0;
            for (mci::iterator it = base.begin(); it != base.end(); it++)
                x = tmp[it->first], y = it->second, (x != y) ? need += abs(x - y) : 0;
            ans += have == need, tmp[now[0]]--, now.erase(0, 1);
        }
    }
    printf("%d\n", ans);
    return 0;
}


//~In The Name Of Allah~//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;
#define sorta(STL) sort(STL.begin(), STL.end())
#define sortb(STL) sort(STL.begin(), STL.end(), g<int>())
#define all(STL) STL.begin(), STL.end()
#define mk make_pair
#define ssum(Length) ull(Length*(Length+1)/2)
#define np next_permutation
#define gt(Str) getline(cin, Str)
#define g greater
#define re reverse
#define cinp(number) cin>>number.first>>number.second
#define coutp(number) cout<<number.first<<" "<<number.second<<endl;
#define sp(number) setprecision(number)<<fixed
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define rep(i, j) for (int i = 0; i < j; i++)
#define rep_(i, j, k) for (int i = j; i < k; i++)
#define rrep(i, size) for (int i = size - 1; i > -1; i--)
#define mrep(def, mapa) for (def::iterator it = mapa.begin(); it != mapa.end(); it++)
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define oo (int) 1e9
typedef stringstream ss;
typedef string s;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector< vector<int> > vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef multimap<int, int> mlii;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<string, string> mss;
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string str1, str2, tmp = "";
    cin >> str1 >> str2;
    if (str2.size() > str1.size()){
        cout << 0 << endl;
        return 0;
    }
    mci array, base;
    int size = str1.size(), size_ = str2.size(), result = 0, need = 0;
    bool ys = 0;
    rep(i, size_) base[str2[i]]++;
    rep(i, size)
    if (str1[i] == '?' || base[str1[i]]){
        tmp += str1[i], array[str1[i]]++;
        if (tmp.size() == size_){
            mrep(mci, base) if (array[it->first] < it->second) need += it->second - array[it->first];
            else if (array[it->first] > it->second){ ys = 1; break; }
            if (array['?'] == need && !ys) result++;
            ys = need = 0, array[str1[i - size_ + 1]]--, tmp.erase(0, 1);
        }
    }
    else ys = need = 0, array.clear(), tmp = "";
    cout << result << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;
#define sorta(STL) sort(STL.begin(), STL.end())
#define sortb(STL) sort(STL.begin(), STL.end(), g<int>())
#define all(STL) (STL.begin(), STL.end())
#define mk make_pair
#define ssum(Length) ull(Length*(Length+1)/2)
#define np next_permutation
#define gt(Str) getline(cin, Str)
#define g greater
#define re reverse
#define cinp(number) cin>>number.first>>number.second
#define coutp(number) cout<<number.first<<" "<<number.second<<endl;
#define sp(number) setprecision(number)<<fixed
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define rep(i, j) for (int i = 0; i < j; i++)
#define rep_(i, j, k) for (int i = j; i < k; i++)
#define rrep(i, size) for (int i = size - 1; i > -1; i--)
#define mrep(def, mapa) for (def::iterator it = mapa.begin(); it != mapa.end(); it++)
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define oo (int) 1e9
typedef stringstream ss;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<string, string> mss;
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string str, str2;
    cin >> str >> str2;
    int size = str.size(), size2 = str2.size(), result = 0, tmp = 0;
    mci array, rtmp, with;
    rep(i, size2) array[str2[i]]++, with[str2[i]] = 1;
    rtmp = array;
    rep(i, size){
        if (!with[str[i]] && str[i] != '?') rtmp = array, tmp = 0;
        else if (!rtmp[str[i]] && with[str[i]] && tmp == size2 - 1) tmp++;
        if (rtmp[str[i]] || str[i] == '?') tmp++, rtmp[str[i]]--;
        if (tmp == size2) result++, tmp--;
    }
    cout << result << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <sstream>
#include <cstring>
#include <fstream>
#include <functional>
#include <cstdio>
#include <stack>
#include <utility>
#include <set>
#include <list>
#include <queue>
#include <bitset>
using namespace std;
#define sorta(STL) sort(STL.begin(), STL.end())
#define sortb(STL) sort(STL.begin(), STL.end(), g<int>())
#define all(STL) (STL.begin(), STL.end())
#define mk make_pair
#define ssum(Length) ull(Length*(Length+1)/2)
#define np next_permutation
#define gt(Str) getline(cin, Str)
#define g greater
#define re reverse
#define cinp(number) cin>>number.first>>number.second
#define coutp(number) cout<<number.first<<" "<<number.second<<endl;
#define sp(number) setprecision(number)<<fixed
#define getdis(x1, y1, x2, y2) double(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define rep(i, j) for (int i = 0; i < j; i++)
#define rep_(i, j, k) for (int i = j; i < k; i++)
#define rrep(i, size) for (int i = size - 1; i > -1; i--)
#define mrep(def, mapa) for (def::iterator it = mapa.begin(); it != mapa.end(); it++)
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define oo (int) 1e9
typedef stringstream ss;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<string, string> mss;
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string str, str2;
    cin >> str >> str2;
    int size = str.size(), size2 = str2.size(), result = 0, tmp = 0;
    mci array, rtmp, with;
    rep(i, size2) array[str2[i]]++, with[str2[i]] = 1;
    rtmp = array;
    rep(i, size){
        if ((!rtmp[str[i]] && with[str[i]]) || (!with[str[i]] && str[i] != '?')) rtmp = array, tmp = 0;
        if (rtmp[str[i]] || str[i] == '?') tmp++, rtmp[str[i]]--;
        if (tmp == size2) result++, tmp--;
    }
    cout << result << endl;
    return 0;
}