//~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){
        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);
        }
    }
    cout << result << endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string a,b;
int cosa[27],cosb[27],ami;
int main (void)
{
    int i,j,k;
    char aux;
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        a+=aux;
    }
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        b+=aux;
    }
    for(i=0;i<b.size();i++)
        cosb[b[i]-'a']++;
    for(i=0;i<b.size();i++)
    {
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    int diff=0,sol=0;
    for(i=b.size();i<=a.size();i++)
    {
        diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
        if(i==a.size())
            break;
        if(a[i-b.size()]=='?')
            ami--;
        else
            cosa[a[i-b.size()]-'a']--;
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    cout<<sol<<endl;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
char a[100007],b[100007];
int cosa[27],cosb[27],ami;
int main (void)
{
    int i,j,k;
    //freopen("input.txt","r",stdin);
    char aux;
    for(i=0;1;i++)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        a[i]=aux;
    }
    //a+='@';
    for(i=0;1;i++)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        b[i]+=aux;
    }
    //b+='@';
    for(i=0;i<strlen(b);i++)
        cosb[b[i]-'a']++;
    for(i=0;i<strlen(b);i++)
    {
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    int diff=0,sol=0;
    diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    for(i=strlen(b);i<strlen(a);i++)
    {
        /*if(i==81000)
        printf("%d %d ",i,a.size());*/

        if(a[i-strlen(b)]=='?')
            ami--;
        else
            cosa[a[i-strlen(b)]-'a']--;
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
        diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    }
  //  cout<<"OK"<<endl;
    cout<<sol<<endl;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string a,b;
int cosa[27],cosb[27],ami;
int main (void)
{
    int i,j,k;
    cin>>a>>b;
    for(i=0;i<b.size();i++)
        cosb[b[i]-'a']++;
    for(i=0;i<b.size();i++)
    {
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    int diff=0,sol=0;
    for(i=b.size();i<=a.size();i++)
    {
        diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
        if(i==a.size())
            break;
        if(a[i-b.size()]=='?')
            ami--;
        else
            cosa[a[i-b.size()]-'a']--;
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    cout<<sol<<endl;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string a,b;
int cosa[27],cosb[27],ami;
int main (void)
{
    int i,j,k;
    freopen("input.txt","r",stdin);
    char aux;
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        a+=aux;
    }
    //a+='@';
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        b+=aux;
    }
    //b+='@';
    for(i=0;i<b.size();i++)
        cosb[b[i]-'a']++;
    for(i=0;i<b.size();i++)
    {
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    int diff=0,sol=0;
    diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    for(i=b.size();i<a.size();i++)
    {
        /*if(i==81000)
        printf("%d %d ",i,a.size());*/

        if(a[i-b.size()]=='?')
            ami--;
        else
            cosa[a[i-b.size()]-'a']--;
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
        diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    }
  //  cout<<"OK"<<endl;
    cout<<sol<<endl;
}


    #include<stdio.h>
    #include<iostream>
    #include<vector>
   #include<string>
    using namespace std;
    string a,b;
    int cosa[27],cosb[27],ami;
    int main (void)
    {
       int i,j,k;
       cin>>a>>b;
       if(b.size()>a.size())
    {
       cout<<"0\n";
            return 0;
    }
       for(i=0;i<b.size();i++)
           cosb[b[i]-'a']++;
       for(i=0;i<b.size();i++)
       {
           if(a[i]=='?')
               ami++;
           else
               cosa[a[i]-'a']++;
       }
       int diff=0,sol=0;
       for(i=b.size();i<=a.size();i++)
       {
           diff=0;
           for(j=0;j<26;j++)
          {
               if(cosa[j]>cosb[j])
              {
                   diff=1000000;
                   break;
               }
               diff+=cosb[j]-cosa[j];
           }
           if(diff<=ami)
               sol++;
           if(i==a.size())
               break;
           if(a[i-b.size()]=='?')
               ami--;
           else
               cosa[a[i-b.size()]-'a']--;
           if(a[i]=='?')
               ami++;
           else
               cosa[a[i]-'a']++;
       }
       cout<<sol<<endl;
   }


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string a,b;
int cosa[27],cosb[27],ami;
int main (void)
{
    int i,j,k;
    //freopen("input.txt","r",stdin);
    char aux;
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        a+=aux;
    }
    //a+='@';
    while(1)
    {
        scanf("%c",&aux);
        if(aux=='\n')
            break;
        b+=aux;
    }
    //b+='@';
    for(i=0;i<b.size();i++)
        cosb[b[i]-'a']++;
    for(i=0;i<b.size();i++)
    {
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
    }
    int diff=0,sol=0;
    diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    for(i=b.size();i<a.size();i++)
    {
        /*if(i==81000)
        printf("%d %d ",i,a.size());*/

        if(a[i-b.size()]=='?')
            ami--;
        else
            cosa[a[i-b.size()]-'a']--;
        if(a[i]=='?')
            ami++;
        else
            cosa[a[i]-'a']++;
        diff=0;
        for(j=0;j<26;j++)
        {
            if(cosa[j]>cosb[j])
            {
                diff=1000000;
                break;
            }
            diff+=cosb[j]-cosa[j];
        }
        if(diff<=ami)
            sol++;
    }
  //  cout<<"OK"<<endl;
    cout<<sol<<endl;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<sstream>
#include<set>
#include<cmath>

using namespace std;

string s,p;
int uses[130],usep[130],temp[130],shott[130];

vector<char>v;

int find_it(){
    int shot=0,i;
    for(i='a';i<='z';i++){
        if(uses[i]==usep[i])continue;
        if(uses[i]<usep[i]){
            shott[i]=usep[i]-uses[i];
            shot+=shott[i];;
        }
    }
    return shot;
}

int main()
{
//  freopen("sam.txt","r",stdin);
    int i,j,k,total=0,rep=0;
    cin>>s>>p;
    if(s.length()<p.length()){
        cout<<'0'<<endl;
        return 0;
    }
    for(i=0;i<p.length();i++){
        ++uses[s[i]];
        ++usep[p[i]];
        if(s[i]=='?')rep++;
    }
    int shot=find_it();
    if(shot==0)total++;
    else if(shot==rep)total++;
    for(i=1;i<=s.length()-p.length();i++){
        if(s[i-1]=='?'){
            rep--;
        }
        if(s[i+p.length()-1]=='?'){
            rep++;
        }
        uses[s[i+p.length()-1]]++;
        uses[s[i-1]]--;
        shot=find_it();
        if(shot==rep)total++;
        else if(shot==0)total++;
    }
    cout<<total<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;
int uses[130],usep[130];
string s,p;

int make_use(){
    int i,rep=0;
    for(i=0;i<p.length();i++){
        usep[p[i]]++;
        uses[s[i]]++;
        if(s[i]=='?')++rep;
    }
    return rep;
}

int make_shot(){
    int i,shot=0;
    for(i='a';i<='z';i++){
        if(uses[i]==usep[i])continue;
        if(usep[i]>uses[i])shot+=usep[i]-uses[i];
    }
    return shot;
}

int main()
{
    freopen("sam.txt","r",stdin);
    cin>>s>>p;
    if(s.length()<p.length()){
        cout<<'0'<<endl;
        return 0;
    }
    int rep=make_use();
    int shot=make_shot();
    int total=0;
    if(shot==0)total++;
    else if(shot==rep)total++;
    for(int i=1;i<=s.length()-p.length();i++){
        if(s[i-1]=='?')--rep;
        if(s[i-1+p.length()]=='?')++rep;
        ++uses[s[i-1+p.length()]];
        --uses[s[i-1]];
        shot=make_shot();
        if(shot==0)total++;
        else if(shot==rep)total++;
    }
    cout<<total<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;
int uses[130],usep[130];
string s,p;

int make_use(){
    int i,rep=0;
    for(i=0;i<p.length();i++){
        usep[p[i]]++;
        uses[s[i]]++;
        if(s[i]=='?')++rep;
    }
    return rep;
}

int make_shot(){
    int i,shot=0;
    for(i='a';i<='z';i++){
        if(uses[i]==usep[i])continue;
        if(usep[i]>uses[i])shot+=usep[i]-uses[i];
    }
    return shot;
}

int main()
{
//  freopen("sam.txt","r",stdin);
    cin>>s>>p;
    int rep=make_use();
    int shot=make_shot();
    int total=0;
    if(shot==0)total++;
    else if(shot==rep)total++;
    for(int i=1;i<=s.length()-p.length();i++){
        if(s[i-1]=='?')--rep;
        if(s[i-1+p.length()]=='?')++rep;
        ++uses[s[i-1+p.length()]];
        --uses[s[i-1]];
        shot=make_shot();
        if(shot==0)total++;
        else if(shot==rep)total++;
    }
    cout<<total<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<sstream>
#include<set>
#include<cmath>

using namespace std;

string s,p;
int uses[130],usep[130],temp[130],shott[130];

vector<char>v;

int find_it(){
    int shot=0,i;
    for(i='a';i<='z';i++){
        if(uses[i]==usep[i])continue;
        if(uses[i]<usep[i]){
            shott[i]=usep[i]-uses[i];
            shot+=shott[i];;
        }
    }
    return shot;
}

int main()
{
//  freopen("sam.txt","r",stdin);
    int i,j,k,total=0,rep=0;
    cin>>s>>p;
    if(s.length()<p.length()){
        cout<<'0'<<endl;
        return 0;
    }
    for(i=0;i<p.length();i++){
        ++uses[s[i]];
        ++usep[p[i]];
        if(s[i]=='?')rep++;
    }
    int shot=find_it();
    if(shot==0)total++;
    else if(shot==rep)total++;
    for(i=1;i<s.length();i++){
        if(s[i-1]=='?'){
            rep--;
        }
        if(s[i+p.length()-1]=='?'){
            rep++;
        }
        uses[s[i+p.length()-1]]++;
        uses[s[i-1]]--;
        shot=find_it();
        if(shot==rep)total++;
        else if(shot==0)total++;
    }
    cout<<total<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;
int uses[130],usep[130];
string s,p;

int make_use(){
    int i,rep=0;
    for(i=0;i<p.length();i++){
        usep[p[i]]++;
        uses[s[i]]++;
        if(s[i]=='?')++rep;
    }
    return rep;
}

int make_shot(){
    int i,shot=0;
    for(i='a';i<='z';i++){
        if(uses[i]==usep[i])continue;
        if(usep[i]>uses[i])shot+=usep[i]-uses[i];
    }
    return shot;
}

int main()
{
//  freopen("sam.txt","r",stdin);
    cin>>s>>p;
    if(s.length()<p.length()){
        cout<<'0'<<endl;
        return 0;
    }
    int rep=make_use();
    int shot=make_shot();
    int total=0;
    if(shot==0)total++;
    else if(shot==rep)total++;
    for(int i=1;i<=s.length()-p.length();i++){
        if(s[i-1]=='?')--rep;
        if(s[i-1+p.length()]=='?')++rep;
        ++uses[s[i-1+p.length()]];
        --uses[s[i-1]];
        shot=make_shot();
        if(shot==0)total++;
        else if(shot==rep)total++;
    }
    cout<<total<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define rep1(i,n) for(int i=1; i<=(int)n; i++)
#define rep1v(i,n) for(int i=n; i>=1; i--)
#define repc(i,a,b) for(int i=a;i<=b;i++)
#define dbg(x) printf("Problem is here %d\n",x)

#define refINF 100000
#define INF 0x7FFFFFFF
#define PI 3.1415926535897932384626433832795
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define pis pair<int,string>
#define psi pair<string,int>
#define pss pair<string,string>
#define pmp make_pair
#define MII map<int,int>::iterator
#define MCI map<char,int>::iterator
#define MIC map<int,char>::iterator
#define MIS map<int,string>::iterator
#define MSI map<string,int>::iterator

#define sqr(x) ((x)*(x))
#define sdi(x) scanf("%d",&x)
#define sli(x) scanf("%I64d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define slii(x,y) scanf("%I64d%I64d",&x,&y)
#define ssi(x) scanf("%s",x)
#define uu first
#define vv second
#define ll long long
#define ld long double
#define ull unsigned long long
/// moves
//int dr[]={-1,-1,-1,0,0,1,1,1}; int dc[]={-1,0,1,-1,1,-1,0,1}; // 8 direction
//int dr[]={-1,1,0,0}; int dc[]={0,0,-1,1}; // 4 direction
//int dr[] = {-1,-1,0,0,1,1}; int dc[] = {-1,0,-1,1,0,1}; // hexagonal direction
//int dr[]={2,1,-1,-2,-2,-1,1,2};int dc[]={1,2,2,1,-1,-2,-2,-1}; // Knight Direction
//int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
//int lcm(int a, int b){return (int)a*(b/gcd(a,b));}
#define MAX
#define MOD
using namespace std;

int cns1[300][100000+100];
int cns2[300];

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    if(s2.size()>s1.size())return cout<<0<<endl,0;
    for(int i=0;i<s1.size();i++){
        if(i==0)cns1[s1[i]][i]++;
        else cns1[s1[i]][i]=cns1[s1[i]][i-1]+1;
        for(int d='a';d<='z';d++){
            if(s1[i]!=d)
            cns1[d][i]=cns1[d][i-1];
        }
        if(s1[i]!='?')cns1['?'][i]=cns1['?'][i-1];
    }
    /*for(int i=0;i<s1.size();i++){
        cout<<cns1['?'][i]<<" ";
    }*/
    for(int i=0;i<s2.size();i++)cns2[s2[i]]++;
    int cnt=0;
    int lt=s2.size()-1;
    for(int i=0;i<s1.size()-s2.size()+1;i++){
        int wtf;
        if(i==0)wtf=cns1['?'][i+lt];
        else wtf=cns1['?'][i+lt]-cns1['?'][i-1];

        int ok=1;
        for(int k='a';k<='z';k++){
            int d=cns2[k];
            int tt;
            if(i==0){
                tt=cns1[k][i+lt];
            }
            else tt=cns1[k][i+lt]-cns1[k][i-1];
            if(tt>d){ok=0;break;}
            else if(d>tt+wtf){ok=0;break;}
            else if(d==tt)continue;
            else{
                wtf-=abs(d-tt);
            }
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;

return 0;

}


#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define rep1(i,n) for(int i=1; i<=(int)n; i++)
#define rep1v(i,n) for(int i=n; i>=1; i--)
#define repc(i,a,b) for(int i=a;i<=b;i++)
#define dbg(x) printf("Problem is here %d\n",x)

#define refINF 100000
#define INF 0x7FFFFFFF
#define PI 3.1415926535897932384626433832795
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define pis pair<int,string>
#define psi pair<string,int>
#define pss pair<string,string>
#define pmp make_pair
#define MII map<int,int>::iterator
#define MCI map<char,int>::iterator
#define MIC map<int,char>::iterator
#define MIS map<int,string>::iterator
#define MSI map<string,int>::iterator

#define sqr(x) ((x)*(x))
#define sdi(x) scanf("%d",&x)
#define sli(x) scanf("%I64d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define slii(x,y) scanf("%I64d%I64d",&x,&y)
#define ssi(x) scanf("%s",x)
#define uu first
#define vv second
#define ll long long
#define ld long double
#define ull unsigned long long
/// moves
//int dr[]={-1,-1,-1,0,0,1,1,1}; int dc[]={-1,0,1,-1,1,-1,0,1}; // 8 direction
//int dr[]={-1,1,0,0}; int dc[]={0,0,-1,1}; // 4 direction
//int dr[] = {-1,-1,0,0,1,1}; int dc[] = {-1,0,-1,1,0,1}; // hexagonal direction
//int dr[]={2,1,-1,-2,-2,-1,1,2};int dc[]={1,2,2,1,-1,-2,-2,-1}; // Knight Direction
//int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
//int lcm(int a, int b){return (int)a*(b/gcd(a,b));}
#define MAX
#define MOD
using namespace std;

int cns1[300][100000+100];
int cns2[300];

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(int i=0;i<s1.size();i++){
        if(i==0)cns1[s1[i]][i]++;
        else cns1[s1[i]][i]=cns1[s1[i]][i-1]+1;
        for(int d='a';d<='z';d++){
            if(s1[i]!=d)
            cns1[d][i]=cns1[d][i-1];
        }
        if(s1[i]!='?')cns1['?'][i]=cns1['?'][i-1];
    }
    /*for(int i=0;i<s1.size();i++){
        cout<<cns1['?'][i]<<" ";
    }*/
    for(int i=0;i<s2.size();i++)cns2[s2[i]]++;
    int cnt=0;
    int lt=s2.size()-1;
    for(int i=0;i<s1.size()-s2.size()+1;i++){
        int wtf;
        if(i==0)wtf=cns1['?'][i+lt];
        else wtf=cns1['?'][i+lt]-cns1['?'][i-1];

        int ok=1;
        for(int k='a';k<='z';k++){
            int d=cns2[k];
            int tt;
            if(i==0){
                tt=cns1[k][i+lt];
            }
            else tt=cns1[k][i+lt]-cns1[k][i-1];
            if(tt>d){ok=0;break;}
            else if(d>tt+wtf){ok=0;break;}
            else if(d==tt)continue;
            else{
                wtf-=abs(d-tt);
            }
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;

return 0;

}


#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define rep1(i,n) for(int i=1; i<=(int)n; i++)
#define rep1v(i,n) for(int i=n; i>=1; i--)
#define repc(i,a,b) for(int i=a;i<=b;i++)
#define dbg(x) printf("Problem is here %d\n",x)

#define refINF 100000
#define INF 0x7FFFFFFF
#define PI 3.1415926535897932384626433832795
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define pis pair<int,string>
#define psi pair<string,int>
#define pss pair<string,string>
#define pmp make_pair
#define MII map<int,int>::iterator
#define MCI map<char,int>::iterator
#define MIC map<int,char>::iterator
#define MIS map<int,string>::iterator
#define MSI map<string,int>::iterator

#define sqr(x) ((x)*(x))
#define sdi(x) scanf("%d",&x)
#define sli(x) scanf("%I64d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define slii(x,y) scanf("%I64d%I64d",&x,&y)
#define ssi(x) scanf("%s",x)
#define uu first
#define vv second
#define ll long long
#define ld long double
#define ull unsigned long long
/// moves
//int dr[]={-1,-1,-1,0,0,1,1,1}; int dc[]={-1,0,1,-1,1,-1,0,1}; // 8 direction
//int dr[]={-1,1,0,0}; int dc[]={0,0,-1,1}; // 4 direction
//int dr[] = {-1,-1,0,0,1,1}; int dc[] = {-1,0,-1,1,0,1}; // hexagonal direction
//int dr[]={2,1,-1,-2,-2,-1,1,2};int dc[]={1,2,2,1,-1,-2,-2,-1}; // Knight Direction
//int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
//int lcm(int a, int b){return (int)a*(b/gcd(a,b));}
#define MAX
#define MOD
using namespace std;

int cns1[300][1000000];
int cns2[300];

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(int i=0;i<s1.size();i++){
        if(i==0)cns1[s1[i]][i]++;
        else cns1[s1[i]][i]=cns1[s1[i]][i-1]+1;
        for(int d='a';d<='z';d++){
            if(s1[i]!=d)
            cns1[d][i]=cns1[d][i-1];
        }
        if(s1[i]!='?')cns1['?'][i]=cns1['?'][i-1];
    }
    /*for(int i=0;i<s1.size();i++){
        cout<<cns1['?'][i]<<" ";
    }*/
    for(int i=0;i<s2.size();i++)cns2[s2[i]]++;
    int cnt=0;
    int lt=s2.size()-1;
    for(int i=0;i<s1.size()-s2.size()+1;i++){
        int wtf;
        if(i==0)wtf=cns1['?'][i+lt];
        else wtf=cns1['?'][i+lt]-cns1['?'][i-1];

        int ok=1;
        for(int k='a';k<='z';k++){
            int d=cns2[k];
            int tt;
            if(i==0){
                tt=cns1[k][i+lt];
            }
            else tt=cns1[k][i+lt]-cns1[k][i-1];
            if(tt>d){ok=0;break;}
            else if(d>tt+wtf){ok=0;break;}
            else if(d==tt)continue;
            else{
                wtf-=abs(d-tt);
            }
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;

return 0;

}


#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define rep1(i,n) for(int i=1; i<=(int)n; i++)
#define rep1v(i,n) for(int i=n; i>=1; i--)
#define repc(i,a,b) for(int i=a;i<=b;i++)
#define dbg(x) printf("Problem is here %d\n",x)

#define refINF 100000
#define INF 0x7FFFFFFF
#define PI 3.1415926535897932384626433832795
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define pis pair<int,string>
#define psi pair<string,int>
#define pss pair<string,string>
#define pmp make_pair
#define MII map<int,int>::iterator
#define MCI map<char,int>::iterator
#define MIC map<int,char>::iterator
#define MIS map<int,string>::iterator
#define MSI map<string,int>::iterator

#define sqr(x) ((x)*(x))
#define sdi(x) scanf("%d",&x)
#define sli(x) scanf("%I64d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define slii(x,y) scanf("%I64d%I64d",&x,&y)
#define ssi(x) scanf("%s",x)
#define uu first
#define vv second
#define ll long long
#define ld long double
#define ull unsigned long long
/// moves
//int dr[]={-1,-1,-1,0,0,1,1,1}; int dc[]={-1,0,1,-1,1,-1,0,1}; // 8 direction
//int dr[]={-1,1,0,0}; int dc[]={0,0,-1,1}; // 4 direction
//int dr[] = {-1,-1,0,0,1,1}; int dc[] = {-1,0,-1,1,0,1}; // hexagonal direction
//int dr[]={2,1,-1,-2,-2,-1,1,2};int dc[]={1,2,2,1,-1,-2,-2,-1}; // Knight Direction
//int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
//int lcm(int a, int b){return (int)a*(b/gcd(a,b));}
#define MAX
#define MOD
using namespace std;

int cns1[255][100000+60];
int cns2[255];

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(int i=0;i<s1.size();i++){
        if(i==0)cns1[s1[i]][i]++;
        else cns1[s1[i]][i]=cns1[s1[i]][i-1]+1;
        for(int d='a';d<='z';d++){
            if(s1[i]!=d)
            cns1[d][i]=cns1[d][i-1];
        }
        if(s1[i]!='?')cns1['?'][i]=cns1['?'][i-1];
    }
    /*for(int i=0;i<s1.size();i++){
        cout<<cns1['?'][i]<<" ";
    }*/
    for(int i=0;i<s2.size();i++)cns2[s2[i]]++;
    int cnt=0;
    int lt=s2.size()-1;
    for(int i=0;i<s1.size()-s2.size()+1;i++){
        int wtf;
        if(i==0)wtf=cns1['?'][i+lt];
        else wtf=cns1['?'][i+lt]-cns1['?'][i-1];

        int ok=1;
        for(int k='a';k<='z';k++){
            int d=cns2[k];
            int tt;
            if(i==0){
                tt=cns1[k][i+lt];
            }
            else tt=cns1[k][i+lt]-cns1[k][i-1];
            if(tt>d){ok=0;break;}
            else if(d>tt+wtf){ok=0;break;}
            else if(d==tt)continue;
            else{
                wtf-=abs(d-tt);
            }
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;

return 0;

}


#include <bits/stdc++.h>

#define stream istringstream
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define repv(i,n) for(int i=n-1; i>=0; i--)
#define rep1(i,n) for(int i=1; i<=(int)n; i++)
#define rep1v(i,n) for(int i=n; i>=1; i--)
#define repc(i,a,b) for(int i=a;i<=b;i++)
#define dbg(x) printf("Problem is here %d\n",x)

#define refINF 100000
#define INF 0x7FFFFFFF
#define PI 3.1415926535897932384626433832795
#define pb(x) push_back(x)
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define pis pair<int,string>
#define psi pair<string,int>
#define pss pair<string,string>
#define pmp make_pair
#define MII map<int,int>::iterator
#define MCI map<char,int>::iterator
#define MIC map<int,char>::iterator
#define MIS map<int,string>::iterator
#define MSI map<string,int>::iterator

#define sqr(x) ((x)*(x))
#define sdi(x) scanf("%d",&x)
#define sli(x) scanf("%I64d",&x)
#define sdii(x,y) scanf("%d%d",&x,&y)
#define slii(x,y) scanf("%I64d%I64d",&x,&y)
#define ssi(x) scanf("%s",x)
#define uu first
#define vv second
#define ll long long
#define ld long double
#define ull unsigned long long
/// moves
//int dr[]={-1,-1,-1,0,0,1,1,1}; int dc[]={-1,0,1,-1,1,-1,0,1}; // 8 direction
//int dr[]={-1,1,0,0}; int dc[]={0,0,-1,1}; // 4 direction
//int dr[] = {-1,-1,0,0,1,1}; int dc[] = {-1,0,-1,1,0,1}; // hexagonal direction
//int dr[]={2,1,-1,-2,-2,-1,1,2};int dc[]={1,2,2,1,-1,-2,-2,-1}; // Knight Direction
//int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
//int lcm(int a, int b){return (int)a*(b/gcd(a,b));}
#define MAX
#define MOD
using namespace std;

int cns1[100000+60][255];
int cns2[255];

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(int i=0;i<s1.size();i++){
        if(i==0)cns1[s1[i]][i]++;
        else cns1[s1[i]][i]=cns1[s1[i]][i-1]+1;
        for(int d='a';d<='z';d++){
            if(s1[i]!=d)
            cns1[d][i]=cns1[d][i-1];
        }
        if(s1[i]!='?')cns1['?'][i]=cns1['?'][i-1];
    }
    /*for(int i=0;i<s1.size();i++){
        cout<<cns1['?'][i]<<" ";
    }*/
    for(int i=0;i<s2.size();i++)cns2[s2[i]]++;
    int cnt=0;
    int lt=s2.size()-1;
    for(int i=0;i<s1.size()-s2.size()+1;i++){
        int wtf;
        if(i==0)wtf=cns1['?'][i+lt];
        else wtf=cns1['?'][i+lt]-cns1['?'][i-1];

        int ok=1;
        for(int k='a';k<='z';k++){
            int d=cns2[k];
            int tt;
            if(i==0){
                tt=cns1[k][i+lt];
            }
            else tt=cns1[k][i+lt]-cns1[k][i-1];
            if(tt>d){ok=0;break;}
            else if(d>tt+wtf){ok=0;break;}
            else if(d==tt)continue;
            else{
                wtf-=abs(d-tt);
            }
        }
        if(ok)cnt++;
    }
    cout<<cnt<<endl;

return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define test int t;scanf("%d", &t);while(t--)
#define sd(n) scanf("%d", &n)
#define pd(n) printf("%d", n)
#define fl(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007
int fact[5001];
int invfact[5001];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<5001;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[5000] = inv(fact[5000], MOD-2);
    for(int i=5000;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}
void solve(){
    string s, p;
    cin>>s>>p;
    int l = p.length();
    int le = s.length();
    string alph = "abcdefghijklmnopqrstuvwxyz";
    map<char, int> mp;
    map<char, int> pm;
    for(int i=0;i<l;i++){
        mp[s[i]]++;
    }
    for(int i=0;i<l;i++){
        pm[p[i]]++;
    }
    int ans = 0;
    bool flag = false;
    for(int i=0;i<=le-l;i++){
        flag = false;
        if(i!=0){
            mp[s[i+l-1]]++;
        }
        for(int j=i;j<i+l;j++){
            if(s[j]=='?')   continue;
            if(mp[s[j]]>pm[s[j]]){
                flag = true;
                break;
            }
        }
        mp[s[i]]--;
        if(!flag)   ans++;
    }
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("B-small-attempt1.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("B-small.out", "w", stdout);*/
	ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define test int t;scanf("%d", &t);while(t--)
#define sd(n) scanf("%d", &n)
#define pd(n) printf("%d", n)
#define fl(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007
int fact[5001];
int invfact[5001];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<5001;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[5000] = inv(fact[5000], MOD-2);
    for(int i=5000;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}
void solve(){
    string s, p;
    cin>>s>>p;
    int l = p.length();
    int le = s.length();
    string alph = "abcdefghijklmnopqrstuvwxyz";
    map<char, int> mp;
    map<char, int> pm;
    for(int i=0;i<l;i++){
        mp[s[i]]++;
    }
    for(int i=0;i<l;i++){
        pm[p[i]]++;
    }
    int ans = 0;
    bool flag = false;
    for(int i=0;i<=le-l;i++){
        flag = false;
        if(i!=0){
            mp[s[i+l-1]]++;
        }
        for(int j=0;j<26;j++){
            if(mp[alph[j]]>pm[alph[j]]){
                flag = true;
                break;
            }
        }
        mp[s[i]]--;
        if(!flag)   ans++;
    }
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("B-small-attempt1.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("B-small.out", "w", stdout);*/
	ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define test int t;scanf("%d", &t);while(t--)
#define sd(n) scanf("%d", &n)
#define pd(n) printf("%d", n)
#define fl(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007
int fact[5001];
int invfact[5001];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<5001;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[5000] = inv(fact[5000], MOD-2);
    for(int i=5000;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}
void solve(){
    string s, p;
    scanf("%s", s);
    scanf("%s", p);
    int l = p.length();
    int le = s.length();
    string alph = "abcdefghijklmnopqrstuvwxyz";
    map<char, int> mp;
    map<char, int> pm;
    for(int i=0;i<l;i++){
        mp[s[i]]++;
    }
    for(int i=0;i<l;i++){
        pm[p[i]]++;
    }
    int ans = 0;
    bool flag = false;
    for(int i=0;i<=le-l;i++){
        flag = false;
        if(i!=0){
            mp[s[i+l-1]]++;
        }
        for(int j=i;j<i+l;j++){
            if(s[j]=='?')   continue;
            if(mp[s[j]]>pm[s[j]]){
                flag = true;
                break;
            }
        }
        mp[s[i]]--;
        if(!flag)   ans++;
    }
    printf("%d", ans);
}
int main(){
    /*FILE *fin = freopen("B-small-attempt1.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("B-small.out", "w", stdout);*/
	/*ios_base::sync_with_stdio(false);*/
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define test int t;scanf("%d", &t);while(t--)
#define sd(n) scanf("%d", &n)
#define pd(n) printf("%d", n)
#define fl(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007
int fact[5001];
int invfact[5001];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<5001;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[5000] = inv(fact[5000], MOD-2);
    for(int i=5000;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}
void solve(){
    string s, p;
    cin>>s>>p;
    int l = p.length();
    int le = s.length();
    string alph = "abcdefghijklmnopqrstuvwxyz";
    int mp[80];
    int pm[80];
    memset(mp, 0, sizeof(mp));
    memset(pm, 0, sizeof(pm));
    for(int i=0;i<l;i++){
        mp[int(s[i] - '0')]++;
    }
    for(int i=0;i<l;i++){
        pm[int(p[i] - '0')]++;
    }
    int ans = 0;
    bool flag = false;
    for(int i=0;i<=le-l;i++){
        flag = false;
        if(i!=0){
            mp[int(s[i+l-1] - '0')]++;
        }
        for(int j=0;j<26;j++){
            if(mp[int(alph[j] - '0')]>pm[int(alph[j] - '0')]){
                flag = true;
                break;
            }
        }
        mp[int(s[i] - '0')]--;
        if(!flag)   ans++;
    }
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("B-small-attempt1.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("B-small.out", "w", stdout);*/
	ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define test int t;scanf("%d", &t);while(t--)
#define sd(n) scanf("%d", &n)
#define pd(n) printf("%d", n)
#define fl(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007
int fact[5001];
int invfact[5001];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<5001;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[5000] = inv(fact[5000], MOD-2);
    for(int i=5000;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}
void solve(){
    string s, p;
    cin>>s>>p;
    int l = p.length();
    int le = s.length();
    string alph = "abcdefghijklmnopqrstuvwxyz";
    int mp[80];
    int pm[80];
    memset(mp, 0, sizeof(mp));
    memset(pm, 0, sizeof(pm));
    for(int i=0;i<l;i++){
        mp[int(s[i] - '0')]++;
    }
    for(int i=0;i<l;i++){
        pm[int(p[i] - '0')]++;
    }
    int ans = 0;
    bool flag = false;
    for(int i=0;i<=le-l;i++){
        flag = false;
        if(i!=0){
            mp[int(s[i+l-1] - '0')]++;
        }
        for(int j=i;j<i+l;j++){
            if(s[j]=='?')   continue;
            if(mp[int(s[j] - '0')]>pm[int(s[j] - '0')]){
                flag = true;
                break;
            }
        }
        mp[int(s[i] - '0')]--;
        if(!flag)   ans++;
    }
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("B-small-attempt1.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("B-small.out", "w", stdout);*/
	ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char str[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  scanf("%s", str);
  scanf("%s", p);
  n = (int) strlen(str);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    ++need[p[i] - 'a'];
    if (str[i] != '?') {
    	++cnt[str[i] - 'a'];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (str[i] != '?') {
        --cnt[str[i] - 'a'];
      }
      if (i +  m >= n) break;
      if (str[i + m] != '?') {
    	  ++cnt[str[i + m] - 'a'];
      }
  }
  printf("%d\n", ans);
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  gets(s);
  gets(p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
    if (s[i] != '?') {
    	cnt[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i - m  + 1] != '?') {
        cnt[s[i - m + 1] - 'a']--;
      }
      if (i +  m >= n) break;
      if (i < n - 1 && s[i + 1] != '?') {
    	  cnt[s[i + 1] - 'a']++;
      }
  }
  cout << ans << endl;
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  scanf("%s", s);
  scanf("%s", p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    ++need[p[i] - 'a'];
    if (s[i] != '?') {
    	++cnt[s[i] - 'a'];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i] != '?') {
        --cnt[s[i] - 'a'];
      }
      if (i +  m >= n) break;
      if (s[i + m] != '?') {
    	  ++cnt[s[i + m] - 'a'];
      }
  }
  printf("%d\n", ans);
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
 // gets(s);
 // gets(p);
  scanf("%s", s);
  scanf("%s", p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
  }
  int ans = 0;
  int qm = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != '?') {
      cnt[s[i] - 'a']++;
    }
    if (i >= m - 1) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i - m  + 1] != '?') {
        cnt[s[i - m + 1] - 'a']--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  gets(s);
  gets(p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
    if (s[i] != '?') {
    	cnt[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i] != '?') {
        cnt[s[i] - 'a']--;
      }
      if (i +  m >= n) break;
      if (s[i + m] != '?') {
    	  cnt[s[i + m] - 'a']++;
      }
  }
  cout << ans << endl;
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  gets(s);
  gets(p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
  }
  int ans = 0;
  int qm = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != '?') {
      cnt[s[i] - 'a']++;
    }
    if (i >= m - 1) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i - m  + 1] != '?') {
        cnt[s[i - m + 1] - 'a']--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char str[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  scanf("%s", str);
  scanf("%s", p);
  n = (int) strlen(str);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    ++need[p[i] - 'a'];
    if (str[i] != '?') {
    	++cnt[str[i] - 'a'];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (str[i] != '?') {
        --cnt[str[i] - 'a'];
      }
      if (i +  m >= n) break;
      if (str[i + m] != '?') {
    	  ++cnt[str[i + m] - 'a'];
      }
  }
  printf("%d\n", ans);
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  scanf("%s", s);
  scanf("%s", p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
    if (s[i] != '?') {
    	cnt[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i] != '?') {
        cnt[s[i] - 'a']--;
      }
      if (i +  m >= n) break;
      if (s[i + m] != '?') {
    	  cnt[s[i + m] - 'a']++;
      }
  }
  cout << ans << endl;
  return 0;
}


//#define _CRT_SECURE_NO_DEPRECATE
//#include <ctime>
//#include <float.h>
//#include <algorithm>
//#include <string>
//#include <vector>
//#include <queue>
//#include <iostream>
//#include <cmath>
//#include <sstream>
//#include <map>
//#include <set>
//#include <cstring>
//#include <cstdio>
//using namespace std;
//#define pb push_back
//#define inf 1000000000
//#define L(s) (int)(s).size()
//#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
//#define C(a) memset((a),0,sizeof(a))
//#define ll long long
//#define all(c) (c).begin(), (c).end()
//#define VI vector<int>
//#define mp make_pair
//#define pii pair<int,int>
//#define x first
//#define y second
//#define uint unsigned int
//#define ull unsigned ll
//#define eps 1e-12
//#define b(x) (1<<(x))
//char str[111111], p[111111], n, m;
//int cnt[26], need[26];
//int main() {
//  scanf("%s", str);
//  scanf("%s", p);
//  n = (int) strlen(str);
//  m = (int) strlen(p);
//  if (m > n) {
//	  cout << "0\n";
//	  return 0;
//  }
//  for (int i = 0; i < m; ++i) {
//    ++need[p[i] - 'a'];
//    if (str[i] != '?') {
//    	++cnt[str[i] - 'a'];
//    }
//  }
//  int ans = 0;
//  for (int i = 0; i < n; ++i) {
//      bool ok = 1;
//      for (int j = 0; j < 26; ++j) {
//        if (cnt[j] > need[j]) {
//          ok = 0;
//          break;
//        }
//      }
//      if (ok) {
//        ++ans;
//      }
//      if (str[i] != '?') {
//        --cnt[str[i] - 'a'];
//      }
//      if (i +  m >= n) break;
//      if (str[i + m] != '?') {
//    	  ++cnt[str[i + m] - 'a'];
//      }
//  }
//  printf("%d\n", ans);
//  return 0;
//}
#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
#define pb push_back
#define ppb pop_back
#define pi 3.1415926535897932384626433832795028841971
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pdd pair<double,double>
#define INF 1000000000
#define FOR(i,a,b) for (int _n(b), i(a); i <= _n; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define VI vector <int>
#define ll long long

int a,b,c,d,i,j,n,m,k;
char str[100002], p[100002];
int cnt[26], need[26];
int main() {
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        scanf("%s", str);
        scanf("%s", p);
        n = (int)strlen(str);
        m = (int)strlen(p);
        if (m > n) {
                printf("0\n");
                exit(0);
        }

        c = 0;
        rept(i, m) {
                if (str[i] != '?') ++cnt[str[i] - 'a'];
                ++need[p[i] - 'a'];
        }

        rept(i, n) {
                bool ok = 1;
                rept(j, 26) {
                        if (cnt[j] > need[j]) {
                                ok = 0;
                                break;
                        }
                }
                if (ok) ++c;
                if (str[i] != '?') --cnt[str[i] - 'a'];
                if (i + m >= n) break;
                if (str[i + m] != '?') ++cnt[str[i + m] - 'a'];
        }
        printf("%d\n", c);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  scanf("%s", s);
  scanf("%s", p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
    if (s[i] != '?') {
    	cnt[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i] != '?') {
        cnt[s[i] - 'a']--;
      }
      if (i +  m >= n) break;
      if (s[i + m] != '?') {
    	  cnt[s[i + m] - 'a']++;
      }
  }
  printf("%d\n", ans);
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define uint unsigned int
#define ull unsigned ll
#define eps 1e-12
#define b(x) (1<<(x))
char s[111111], p[111111], n, m;
int cnt[26], need[26];
int main() {
  gets(s);
  gets(p);
  n = (int) strlen(s);
  m = (int) strlen(p);
  if (m > n) {
	  cout << "0\n";
	  return 0;
  }
  for (int i = 0; i < m; ++i) {
    need[p[i] - 'a']++;
    if (s[i] != '?') {
    	cnt[s[i] - 'a']++;
    }
  }
  int ans = 0;
  for (int i = m - 1; i < n; ++i) {
      bool ok = 1;
      for (int j = 0; j < 26; ++j) {
        if (cnt[j] > need[j]) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        ++ans;
      }
      if (s[i - m  + 1] != '?') {
        cnt[s[i - m + 1] - 'a']--;
      }
      if (i < n - 1 && s[i + 1] != '?') {
    	  cnt[s[i + 1] - 'a']++;
      }
  }
  cout << ans << endl;
  return 0;
}


//============================================================================
// Name        : Code103.cpp
// Author      : Vlade087
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#define mp make_pair
#define pb push_back
using namespace std;
string c,c1;
char CC[100005],C1[100005];
int A[27][100005],B[28],C[28];
int main() {
 gets(CC);
 gets(C1);
 c = CC;
 c1 = C1;
 for(int i=0;i<c1.length();i++)
         B[c1[i]-'a']++;
 int len = c.length();
 for(int i=1;i<=len;i++)
 {
         for(int j=0;j<=26;j++)
                 A[i][j] = A[i-1][j];
         if(c[i-1]!='?')
          A[i][c[i-1]-'a']++;
         else
          A[i][26]++;
 }
 if(c.length() < c1.length())
 {
   cout<<"0";
   return 0;
 }
 int ini = 1;
 int fin = c1.length();
 int res = 0;
 bool ok;
 while(fin <= c.length())
 {
     memset(C,0,sizeof(C));
     for(int i=0;i<=26;i++)
         C[i] = A[fin][i] - A[ini-1][i];
      ok = 1;
      int sum = 0;
     for(int i=0;i<26;i++)
         if(B[i] >= C[i])
         {
                 sum+=B[i]-C[i];
         }else
                 ok = 0;
     if(ok)
     {
     if(sum==C[26])
         res++;
     }
    ini++;
    fin++;
 }
 cout<<res;
        return 0;
}


//============================================================================
// Name        : Code103.cpp
// Author      : Vlade087
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#define mp make_pair
#define pb push_back
using namespace std;
string c,c1;
int A[30][100005],B[30],C[30];
int main() {
 cin>>c>>c1;
  for(int i=0;i<c1.length();i++)
         B[c1[i]-'a']++;
 int ini = 0;
 int fin = c1.length()-1;
 for(int i=0;i<c.length();i++)
 {
  if(c[i]=='?')
   c[i] = 'z'+1;
 }
 for(int i=ini;i<=fin;i++)
  C[c[i]-'a']++;
   int sum = 0;
   int res = 0;
 while(fin < c.length())
 {
    bool ok = 0;
    sum = 0;
    for(int i=0;i<26;i++)
      if(B[i] < C[i])
      {
        ok = 1;
        break;
      }else
      {
         sum += B[i]-C[i];
      }
     if(ok==0)
     {
       if(sum==C[26])
       res++;
     }
   ini++;
   fin++;
   C[c[ini-1]-'a']--;
   if(fin < c.length())
    C[c[fin]-'a']++;
 }
 cout<<res;
        return 0;
}


//============================================================================
    // Name        : Code103.cpp
    // Author      : Vlade087
    // Version     :
    // Copyright   : Your copyright notice
    // Description : Hello World in C++, Ansi-style
    //============================================================================

    #include <iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<algorithm>
    #include<string.h>
    #include<ctype.h>
    #include<stdio.h>
    #define mp make_pair
    #define pb push_back
    using namespace std;
   // string c,c1;
    char c[1000005],c1[1000005];
    int A[27][1000005],B[28],C[28];
    int main() {
     cin>>c>>c1;
     for(int i=0;i<strlen(c1);i++)
             B[c1[i]-'a']++;
     int len = strlen(c);
     for(int i=1;i<=len;i++)
     {
             for(int j=0;j<=26;j++)
                     A[i][j] = A[i-1][j];
             if(c[i-1]!='?')
              A[i][c[i-1]-'a']++;
             else
              A[i][26]++;
     }
     int ini = 1;
     int fin = strlen(c1);
     int res = 0;
     bool ok;
     int sum;
     while(fin <= strlen(c))
     {
        // memset(C,0,sizeof(C));
         for(int i=0;i<=26;i++)
             C[i] = A[fin][i] - A[ini-1][i];
          ok = 1;
          sum = 0;
         for(int i=0;i<26;i++)
             if(B[i] >= C[i])
             {
                     sum+=B[i]-C[i];
             }else
                     ok = 0;
         if(ok)
         {
         if(sum==C[26])
             res++;
         }
        ini++;
        fin++;
     }
     cout<<res;
            return 0;
    }


//============================================================================
// Name        : Code103.cpp
// Author      : Vlade087
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#define mp make_pair
#define pb push_back
using namespace std;
string c,c1;
int A[30][100005],B[30],C[30];
int main() {
 cin>>c>>c1;
 if(c1.length() > c.length())
 {
  cout<<0;
  return 0;
 }
  for(int i=0;i<c1.length();i++)
         B[c1[i]-'a']++;
 int ini = 0;
 int fin = c1.length()-1;
 for(int i=0;i<c.length();i++)
 {
  if(c[i]=='?')
   c[i] = 'z'+1;
 }
 for(int i=ini;i<=fin;i++)
  C[c[i]-'a']++;
   int sum = 0;
   int res = 0;
 while(fin < c.length())
 {
    bool ok = 0;
    sum = 0;
    for(int i=0;i<26;i++)
      if(B[i] < C[i])
      {
        ok = 1;
        break;
      }else
      {
         sum += B[i]-C[i];
      }
     if(ok==0)
     {
       if(sum==C[26])
       res++;
     }
   ini++;
   fin++;
   C[c[ini-1]-'a']--;
   if(fin < c.length())
    C[c[fin]-'a']++;
 }
 cout<<res;
        return 0;
}


    //============================================================================
        // Name        : Code103.cpp
        // Author      : Vlade087
        // Version     :
        // Copyright   : Your copyright notice
        // Description : Hello World in C++, Ansi-style
        //============================================================================

        #include <iostream>
        #include<map>
        #include<queue>
        #include<stack>
        #include<vector>
        #include<algorithm>
        #include<string.h>
        #include<ctype.h>
        #include<stdio.h>
        #define mp make_pair
        #define pb push_back
        using namespace std;
       // string c,c1;
        char c[1000005],c1[1000005];
        int A[28][1000005],B[28],C[28];
        int main() {
        scanf("%s",c);
        scanf("%s",c1);
         for(int i=0;i<strlen(c1);i++)
                 B[c1[i]-'a']++;
         int len = strlen(c);
         for(int i=1;i<=len;i++)
         {
                 for(int j=0;j<=26;j++)
                         A[i][j] = A[i-1][j];
                 if(c[i-1]!='?')
                  A[i][c[i-1]-'a']++;
                 else
                  A[i][26]++;
         }
         int ini = 1;
         int fin = strlen(c1);
         int res = 0;
         bool ok;
         int sum;
         while(fin <= strlen(c))
         {
            // memset(C,0,sizeof(C));
             for(int i=0;i<=26;i++)
                 C[i] = A[fin][i] - A[ini-1][i];
              ok = 1;
              sum = 0;
             for(int i=0;i<26;i++)
                 if(B[i] >= C[i])
                 {
                         sum+=B[i]-C[i];
                 }else
                         ok = 0;
             if(ok)
             {
             if(sum==C[26])
                 res++;
             }
            ini++;
            fin++;
         }
         cout<<res;
                return 0;
        }


//============================================================================
// Name        : Code103.cpp
// Author      : Vlade087
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#define mp make_pair
#define pb push_back
using namespace std;
string c,c1;
char CC[100005],C1[100005];
int A[27][100005],B[28],C[28];
int main() {
 gets(CC);
 gets(C1);
 c = CC;
 c1 = C1;
 for(int i=0;i<c1.length();i++)
         B[c1[i]-'a']++;
 int len = c.length();
 for(int i=1;i<=len;i++)
 {
         for(int j=0;j<=26;j++)
                 A[i][j] = A[i-1][j];
         if(c[i-1]!='?')
          A[i][c[i-1]-'a']++;
         else
          A[i][26]++;
 }
 int ini = 1;
 int fin = c1.length();
 int res = 0;
 bool ok;
 while(fin <= c.length())
 {
     memset(C,0,sizeof(C));
     for(int i=0;i<=26;i++)
         C[i] = A[fin][i] - A[ini-1][i];
      ok = 1;
      int sum = 0;
     for(int i=0;i<26;i++)
         if(B[i] >= C[i])
         {
                 sum+=B[i]-C[i];
         }else
                 ok = 0;
     if(ok)
     {
     if(sum==C[26])
         res++;
     }
    ini++;
    fin++;
 }
 cout<<res;
        return 0;
}


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

int main()
{
	long long int sl,pl,no,h,count=0,g;
	bool f;
	string s,p;
	cin>>s>>p;
	sl=s.length();
	pl=p.length();
	no=sl-pl+1;
	long long int sa[27],sba[27];

	if(pl>sl)
		cout<<0;
	else
	{
		for(int i=0;i<27;i++)
		{
			sa[i]=0;
			sba[i]=0;
		}
	for(int i=0;i<pl;i++)
	{
		h=int(p[i])-97;
		sa[h]++;
	}
	for(int i=0;i<no;i++)
	{	f=true;
		if(i==0)
		{
			for(int j=i;j<i+pl;j++)
			{
			h=int(s[j])-97;
			if(s[j]!='?')
				sba[h]++;
			}
		}
		else
		{
			g=int(s[i-1])-97;
			sba[g]--;
			h=int(s[i+pl-1])-97;
			if(s[i+pl-1]!='?')
				sba[h]++;
		}
		for(int k=0;k<27;k++)
		{
			if(sa[k]<sba[k])
				f=false;
		}
		if(f==true)
			count++;
	}
	cout<<count;
	//coiuyftfghj
	}

	return 0;

}


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

int main()
{
	long long int sl,pl,no,h,count=0,g;
	bool f;
	string s,p;
	cin>>s>>p;
	sl=s.length();
	pl=p.length();
	no=sl-pl+1;
	long long int sa[27],sba[27];

	if(pl>sl)
		cout<<0;
	else
	{
		for(int i=0;i<27;i++)
		{
			sa[i]=0;
			sba[i]=0;
		}
	for(int i=0;i<pl;i++)
	{
		h=int(p[i])-97;
		sa[h]++;
	}
	for(int i=0;i<no;i++)
	{	f=true;
		if(i==0)
		{
			for(int j=i;j<i+pl;j++)
			{
			h=int(s[j])-97;
			if(s[j]!='?')
				sba[h]++;
			}
		}
		else
		{
			g=int(s[i-1])-97;
			sba[g]--;
			h=int(s[i+pl-1])-97;
			if(s[i+pl-1]!='?')
				sba[h]++;
		}
		for(int k=0;k<27;k++)
		{
			if(sa[k]<sba[k])
				f=false;
		}
		if(f==true)
			count++;
	}
	cout<<count;
	}

	return 0;

}


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

int main()
{
	long long int sl,pl,no,h,count=0,g;
	bool f;
	string s,p;
	cin>>s>>p;
	sl=s.length();
	pl=p.length();
	no=sl-pl+1;
	long long int sa[27],sba[27];

	if(pl>sl)
		cout<<0;
	else
	{
		for(int i=0;i<27;i++)
		{
			sa[i]=0;
			sba[i]=0;
		}
	for(int i=0;i<pl;i++)
	{
		h=int(p[i])-97;
		sa[h]++;
	}
	for(int i=0;i<no;i++)
	{	f=true;
		if(i==0)
		{
			for(int j=i;j<i+pl;j++)
			{
			h=int(s[j])-97;
			if(s[j]!='?')
				sba[h]++;
			}
		}
		else
		{
			g=int(s[i-1])-97;
			sba[g]--;
			h=int(s[i+pl-1])-97;
			if(s[i+pl-1]!='?')
				sba[h]++;
		}
		for(int k=0;k<27;k++)
		{
			if(sa[k]<sba[k])
				f=false;
		}
		if(f==true)
			count++;
	}
	cout<<count;
	//coiuyftfghjnb
	}

	return 0;

}


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

int main()
{
	long long int sl,pl,no,h,count=0,g;
	bool f;
	string s,p;
	cin>>s>>p;
	sl=s.length();
	pl=p.length();
	no=sl-pl+1;
	long long int sa[27],sba[27];

	if(pl>sl)
		cout<<0;
	else
	{
		for(int i=0;i<27;i++)
		{
			sa[i]=0;
			sba[i]=0;
		}
	for(int i=0;i<pl;i++)
	{
		h=int(p[i])-97;
		sa[h]++;
	}
	for(int i=0;i<no;i++)
	{	f=true;
		if(i==0)
		{
			for(int j=i;j<i+pl;j++)
			{
			h=int(s[j])-97;
			if(s[j]!='?')
				sba[h]++;
			}
		}
		else
		{
			g=int(s[i-1])-97;
			sba[g]--;
			h=int(s[i+pl-1])-97;
			if(s[i+pl-1]!='?')
				sba[h]++;
		}
		for(int k=0;k<27;k++)
		{
			if(sa[k]<sba[k])
				f=false;
		}
		if(f==true)
			count++;
	}
	cout<<count;//dfghj
	}

	return 0;

}


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

int main()
{
	long long int sl,pl,no,h,count=0;
	bool f;
	string s,p;
	cin>>s>>p;
	sl=s.length();
	pl=p.length();
	no=sl-pl+1;
	long long int sa[27],sba[no+3][27];

	if(pl>sl)
		cout<<0;
	else
	{
		for(int i=0;i<27;i++)
		sa[i]=0;
	for(int i=0;i<pl;i++)
	{
		h=int(p[i])-97;
		sa[h]++;
	}
	for(int i=0;i<no;i++)
		for(int j=0;j<27;j++)
			sba[i][j]=0;
	for(int i=0;i<no;i++)
	{	f=true;
		for(int j=i;j<i+pl;j++)
		{
			h=int(s[j])-97;
			if(s[j]!='?')
				sba[i][h]++;
		}
		for(int k=0;k<27;k++)
		{
			if(sa[k]<sba[i][k])
				f=false;
		}
		if(f==true)
			count++;
	}
	cout<<count;
	}

	return 0;

}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

int ch_p[26];
string s, p;

bool check(string s){
    int ch_s[26];
    int i, ok = 0, k = 0;
    memset(ch_s, 0, sizeof(ch_s));
    for(i = 0; i < s.size(); ++i){
        if(s[i] == '?') k++;
        else ch_s[s[i] - 'a']++;
    }
    if(k == p.size()) return true;
    for(i = 0; i < 26; ++i){
        if(ch_s[i] - ch_p[i] < 0){
            k += ch_s[i] - ch_p[i];
            if(k < 0) return false;
        }
        ok++;
    }
    if(ok  == 26){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    // freopen("input.txt", "r", stdin);
    int i, c = 0;
    cin >> s >> p;
    if(s.size() < p.size()){
        cout << 0;
        return 0;
    }
    memset(ch_p, 0, sizeof(ch_p));
    for(i = 0; i < p.size(); ++i){
        ch_p[p[i] - 'a']++;
    }
    for(i = 0; i < s.size(); ++i){
        if(i + p.size() > s.size()) break;
        if(check(s.substr(i, p.size()))) c++;
    }
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

int pch[26], sch[26];

bool check(){
    int i;
    for(i = 0; i < 26; ++i)
        if(sch[i] > pch[i]) return 0;
    return 1;
}

int main(){
    string s, p;
    int i, ls, lp, c = 0;
    cin >> s >> p;
    ls = s.size();
    lp = p.size();
    if(ls < lp){
        cout << 0;
        return 0;
    }
    for(i = 0; i < lp; ++i){
        pch[p[i]-'a']++;
        if(s[i] != '?') sch[s[i]-'a']++;
    }
    if(check()) c++;
    for(; i < ls; ++i){
        if(s[i - lp] != '?') sch[s[i-lp]-'a']--;
        if(s[i] != '?') sch[s[i]-'a']++;
        if(check()) c++;
    }
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int pch[26], sch[26];
bool ok(){
    int i;
    for(i = 0; i < 26; ++i)
        if(sch[i] > pch[i]) return 0;
    return 1;
}
int main(){
    string s, p;
    int i, ls, lp, c = 0;
    cin >> s >> p;
    ls = s.size();
    lp = p.size();
    if(ls < lp){
        cout << 0;
        return 0;
    }
    for(i = 0; i < lp; ++i){
        pch[p[i]-'a']++;
        if(s[i] != '?') sch[s[i]-'a']++;
    }
    if(ok()) c++;
    for(; i < ls; ++i){
        if(s[i - lp] != '?') sch[s[i-lp]-'a']--;
        if(s[i] != '?') sch[s[i]-'a']++;
        if(ok()) c++;
    }
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

int ch_p[26];
string s, p;

bool check(string s){
    int ch_s[26];
    int i;
    bool ok = true;
    memset(ch_s, 0, sizeof(ch_s));
    for(i = 0; i < s.size(); ++i){
        if(s[i] != '?') ch_s[s[i] - 'a']++;
    }
    for(i = 0; i < 26; ++i){
        if(ch_s[i] > ch_p[i]){
            ok = false;
            break;
        }
    }
    if(ok) return true;
    else return false;
}

int main(){
    // freopen("input.txt", "r", stdin);
    int i, c = 0;
    cin >> s >> p;
    if(s.size() < p.size()){
        cout << 0;
        return 0;
    }
    memset(ch_p, 0, sizeof(ch_p));
    for(i = 0; i < p.size(); ++i){
        ch_p[p[i] - 'a']++;
    }
    for(i = 0; i < s.size(); ++i){
        if(i + p.size() > s.size()) break;
        if(check(s.substr(i, p.size()))) c++;
    }
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

int ch_p[26];

bool check(string s){
    int ch_s[26];
    int i, ok = 0, k = 0;
    memset(ch_s, 0, sizeof(ch_s));
    for(i = 0; i < s.size(); ++i){
        if(s[i] == '?') k++;
        else ch_s[s[i] - 'a']++;
    }
    for(i = 0; i < 26; ++i){
        if(ch_s[i] - ch_p[i] < 0){
            k += ch_s[i] - ch_p[i];
            if(k < 0) return false;
        }
        ok++;
    }
    if(ok  == 26){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    // freopen("input.txt", "r", stdin);
    int i, c = 0;
    string s, p;
    cin >> s >> p;
    if(s.size() < p.size()){
        cout << 0;
        return 0;
    }
    memset(ch_p, 0, sizeof(ch_p));
    for(i = 0; i < p.size(); ++i){
        ch_p[p[i] - 'a']++;
    }
    for(i = 0; i < s.size(); ++i){
        if(i + p.size() > s.size()) break;
        if(check(s.substr(i, p.size()))) c++;
    }
    cout << c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl "\n"
#define D(x) cout << #x << " : " << x << "  "
#define l cout << endl
#define in freopen("in","r",stdin)

#define For(i,a)    for(int i=0; i<a; i++)
#define Fori(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define all(x)  x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long int llint;

int main() { IO;
    int n;
    string s,p;
    cin>>s>>p;
    int ss = s.size(), sp = p.size();
    bool first = true;
    if(ss<sp) cout<<"0"<<endl;
    else {
        int ssub = 1;
        int comodin=0, times=0;
        int a[26]={0};
        int b[26]={0};
        For(i,sp) a[p[i]-'a']++;
        For(i,ss) {
            if(s[i]=='?') comodin++;
            else b[s[i]-'a']++;
            if(ssub >= sp) {
                int dif=0;
                For(j,26) {
                    if(b[j]<a[j]) dif+= a[j]-b[j];
                }
                if(dif==0 or comodin>=dif) times++;
                if(s[i-sp+1]=='?') comodin--;
                else b[s[i-sp+1]-'a']--;
            }
            ssub++;
        }
        cout<<times<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl "\n"
#define D(x) cout << #x << " : " << x << "  "
#define l cout << endl
#define in freopen("in","r",stdin)

#define For(i,a)    for(int i=0; i<a; i++)
#define Fori(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define all(x)  x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long int llint;

int main() { IO;
    int n;
    string s,p;
    cin>>s>>p;
    int ssub = 1;
    int ss = s.size(), sp = p.size();

    //bool first = true;

    if(ss<sp) cout<<"0"<<endl;
    else {
        int comodin=0, times=0;
        int a[26]={0};
        int b[26]={0};
        For(i,26) a[p[i]-'a']++;
        For(i,ss) {
            if(s[i]=='?') comodin++;
            else b[s[i]-'a']++;
            if(ssub >= sp) {
                int dif=0;
                For(j,26) {
                    if(b[j]<a[j]) dif+= a[j]-b[j];
                }
                if(dif==0 or comodin>=dif) times++;
                //--
                //if(first) first=false;
                //else{
                    if(s[i-sp+1]=='?') comodin--;
                    else b[s[i-sp+1]-'a']--;
                //D(s[i-sp+1]);l;
                //}
            }
            ssub++;
        }
        cout<<times<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl "\n"
#define D(x) cout << #x << " : " << x << "  "
#define l cout << endl
#define in freopen("in","r",stdin)

#define For(i,a)    for(int i=0; i<a; i++)
#define Fori(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define all(x)  x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long int llint;

int main() { IO;
    int n;
    string s,p;
    cin>>s>>p;
    int ssub = 1;
    int ss = s.size(), sp = p.size();

    if(ss<sp) cout<<"0"<<endl;
    else {
        int comodin=0, times=0;
        int a[26]={0};
        int b[26]={0};
        For(i,26) a[p[i]-'a']++;
        For(i,ss) {
            if(s[i]=='?') comodin++;
            else b[s[i]-'a']++;
            if(ssub >= sp) {
                int dif=0;
                For(j,26) {
                    if(b[j]<a[j]) dif+= a[j]-b[j];
                }
                if(dif==0 or comodin>=dif) times++;
                //--
                if(s[i-sp+1]=='?') comodin--;
                else b[s[i-sp+1]-'a']--;
            }
            ssub++;
        }
        cout<<times<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl "\n"
#define D(x) cout << #x << " : " << x << "  "
#define l cout << endl
#define in freopen("in","r",stdin)

#define For(i,a)    for(int i=0; i<a; i++)
#define Fori(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define all(x)  x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long int llint;

bool isAnagram(string cad1, string cad2) {
    int letras[26] = {0};
    int comodin=0;
    For(i,cad1.size()) {
        if(cad1[i]=='?') {
            comodin++;
        }
        else {
            letras[cad1[i]-'a']++;
        }
    }

    For(i,cad2.size()) {
        if(letras[cad2[i]-'a']>0) {
            letras[cad2[i]-'a']--;
        }
        else if(comodin>0) comodin--;
        else return false;
    }
    return true;
}

int main() { IO;
    int n;
    string s,p;
    cin>>s>>p;

    int ss = s.size(), sp = p.size(), times=0;
    if(ss<sp) cout<<"0"<<endl;
    else {
        for(int i=0; i <= ss-sp; i++){
            if(isAnagram(s.substr(i,sp),p)) times++;
        }
        cout<<times<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl "\n"
#define D(x) cout << #x << " : " << x << "  "
#define l cout << endl

#define For(i,a)    for(int i=0; i<a; i++)
#define Fori(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define all(x)  x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long int llint;

int main() { IO;
    int n;
    string s,p;
    cin>>s>>p;
    int ss = s.size(), sp = p.size();
    bool first = true;
    if(ss<sp) cout<<"0"<<endl;
    else {
        int ssub = 1;
        int comodin=0, times=0;
        int a[26]={0};
        int b[26]={0};
        For(i,sp) a[p[i]-'a']++;
        For(i,ss) {
            if(s[i]=='?') comodin++;
            else b[s[i]-'a']++;
            if(ssub >= sp) {
                int dif=0;
                For(j,26) {
                    if(b[j]<a[j]) dif+= a[j]-b[j];
                }
                if(dif==0 or comodin>=dif) times++;
                if(s[i-sp+1]=='?') comodin--;
                else b[s[i-sp+1]-'a']--;
            }
            ssub++;
        }
        cout<<times<<endl;
    }
}


#include <iostream>
#include <string.h>
using namespace std;

char s[100005];
char p[100005];

void init()
{
    cin >> s >> p;
}

int calc()
{
    int slen = strlen(s);
    int plen = strlen(p);
    if (slen < plen)
        return 0;
    int i, j;
    int gap = slen - plen;
    int cnt = 0;
    int pc[26] = {0};
    for (i = 0; i < plen; i++)
    {
        pc[p[i] - 'a']++;
    }
    for (i = 0; i < gap + 1; i++)
    {
        int sc[26] = {0};
        for (j = 0; j < plen; j++)
        {
            if (s[i + j] == '?')
                continue;
            int tt = s[i + j] - 'a';
            sc[tt]++;
            if (sc[tt] > pc[tt])
                break;
        }
        if (j == plen)
            cnt++;
    }
    return cnt;
}

int main()
{
    init();
    cout << calc() << endl;
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

char s[100001];
char p[100001];

void init()
{
    cin >> s >> p;
}

int calc()
{
    int slen = strlen(s);
    int plen = strlen(p);
    if (slen < plen)
        return 0;
    int i, j;
    int gap = slen - plen;
    int cnt = 0;
    int pc[26] = {0};
    for (i = 0; i < plen; i++)
    {
        pc[p[i] - 'a']++;
    }
    for (i = 0; i < gap + 1; i++)
    {
        int sc[26] = {0};
        for (j = 0; j < plen; j++)
        {
            sc[s[i + j] - 'a']++;
        }
        for (j = 0; j < 26; j++)
        {
            if (sc[j] > pc[j])
                break;
        }
        if (j == 26)
            cnt++;
    }
    return cnt;
}

int main()
{
    init();
    cout << calc() << endl;
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

char s[100001];
char p[100001];

void init()
{
    cin >> s >> p;
}

int calc()
{
    int slen = strlen(s);
    int plen = strlen(p);
    if (slen < plen)
        return 0;
    int i, j;
    int gap = slen - plen;
    int cnt = 0;
    int pc[26] = {0};
    for (i = 0; i < plen; i++)
    {
        pc[p[i] - 'a']++;
    }
    for (i = 0; i < gap + 1; i++)
    {
        int sc[26] = {0};
        for (j = 0; j < plen; j++)
        {
            int tt = s[i + j] - 'a';
            sc[tt]++;
            if (sc[tt] > pc[tt])
                break;
        }
        if (j == plen)
            cnt++;
    }
    return cnt;
}

int main()
{
    init();
    cout << calc() << endl;
    return 0;
}


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

string s, p;

void init()
{
    cin >> s >> p;
}

int calc()
{
    int slen = s.length();
    int plen = p.length();
    if (slen < plen)
        return 0;
    int i, j;
    int gap = slen - plen;
    int cnt = 0;
    int pc[26] = {0};
    for (i = 0; i < plen; i++)
    {
        pc[p[i] - 'a']++;
    }
    for (i = 0; i < gap + 1; i++)
    {
        int sc[26] = {0};
        string t = s.substr(i, plen);
        for (j = 0; j < plen; j++)
        {
            sc[t[j] - 'a']++;
        }
        for (j = 0; j < 26; j++)
        {
            if (sc[j] > pc[j])
                break;
        }
        if (j == 26)
            cnt++;
    }
    return cnt;
}

int main()
{
    init();
    cout << calc() << endl;
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

char s[100005];
char p[100005];

void init()
{
    cin >> s >> p;
}

int calc()
{
    int slen = strlen(s);
    int plen = strlen(p);
    if (slen < plen)
        return 0;
    int i, j;
    int gap = slen - plen;
    int cnt = 0;
    int pc[26] = {0};
    int sc[26] = {0};
    for (i = 0; i < plen; i++)
    {
        pc[p[i] - 'a']++;
        if (s[i] != '?')
            sc[s[i] - 'a']++;
    }
    for (i = 0; i < gap + 1; i++)
    {
        for (j = 0; j < 26; j++)
        {
            if (sc[j] > pc[j])
                break;
        }
        if (j == 26)
            cnt++;
        if (s[i] != '?')
            sc[s[i] - 'a']--;
        if (s[i + plen] != '?')
            sc[s[i + plen] - 'a']++;
    }
    return cnt;
}

int main()
{
    init();
    cout << calc() << endl;
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 1000000
using namespace std;
char a[100001],b[100001];
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<iostream>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	string s,p;
    getline(cin,s);

		getline(cin,p);
		int ans=0;
		for(int i=0;i<=s.length()-p.length();i++)
		{
			string x=p;
			int sum=0;
			for(int j=0;j<p.length();j++)
			{
				if(s[i+j]=='?')
					sum++;
				else
				{
					if(x.find(s[i+j])!=-1)
					{
						sum++;
						x[x.find(s[i+j])]='*';
					}
					else
					{
						break;
					}
				}
				if(sum==p.length())
					ans++;
			}
		}
		cout<<ans<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int counts[288];
int countp[288];
char p[100006];
char s[100006];
int plen,slen;
bool check(){
	for(int i='a' ;i <='z';i++){
		//cout<<(char)i<<" "<<counts[i]<<" "<<countp[i]<<endl;
		if(counts[i]>countp[i])
			return false;
	}
	return true;
}
int main(){
	scanf("%s%s",s,p);
	plen=strlen(p);
	slen=strlen(s);
	//printf("%s\n%s\n",s,p);
	int ans=0;
	for(int i=0;i!=plen;i++){
		countp[p[i]]++;
	}
	for(int i=0;i!=plen;i++){
		counts[s[i]]++;
	}
	if(check()){
		ans++;
		//cout<<plen-1<<endl;
	}
	for(int i=plen;s[i]!=0;i++){
		counts[s[i]]++;
		counts[s[i-plen]]--;
		if(check()){
			ans++;
			//cout<<i<<endl;
		}
	}
	printf("%d\n",ans);
}


#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++) 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<iomanip>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[500],b[500];
int lens,lenp;
string s,p;
void count()
{
  for(int i='a';i<='z';i++){

    a[i]=0;
    b[i]=0;
  }

  for (int i=0;i<lenp;i++){

    a[(int)p[i]]++;

  }
}

int main()
{
  int isok;
  long long int sum;
  cin>>s;

    lens=s.length();
    cin>>p;
    lenp=p.length();
    sum=0;
    if (lenp>lens) cout<<sum<<endl;
    else {
      count();
      for (int i=0;i<=lens-lenp;i++){
        isok=0;

        for(int j=0;j<lenp;j++){
    //cout<<s[i+j]<<' '<<b[(int)s[i+j]]<<' '<<a[(int)s[i+j]]<<endl;
         if (s[i+j]!='?'){
            b[(int)s[i+j]]++;

            if (b[(int)s[i+j]]>a[(int)s[i+j]]){

               isok=1;
               break;
             }
          }
        }
        if (isok==0) sum++;
        for(int i='a';i<='z';i++)
           b[i]=0;
      }
      cout<<sum<<endl;
    }
  //system("pause");
  return 0;

}


#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
   string s,t;
   int p[30],q[30];
   while(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<string>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
   string s,t;
   int p[30],q[30],sum,ss;
   while(cin>>s>>t)
   {
	   sum=0;
	   //getline(cin,t);
	   for(int i=1;i<=26;i++)
	   {
		   p[i]=0;
		   q[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;

        ss=0;
       for(int i=0;i<=lt-1;i++)
		   if(s[i]=='?') sum++;
		   else q[s[i]-96]++;
		    for(int j=1;j<=26;j++)
		  {
			  if(p[j]-q[j]>0) ss+=p[j]-q[j];
		  }
		  if(sum>=ss) ans++;

	   for(int i=1;i<=ls-lt;i++)
	   {

          ss=0;
		  if(s[i-1]=='?') sum--;
		  else q[s[i-1]-96]--;
		  if(s[i+lt-2]=='?') sum++;
		  else q[s[i+lt-2]]++;

		  for(int j=1;j<=26;j++)
		  {
			  if(p[j]-q[j]>0) ss+=p[j]-q[j];
		  }
		  if(sum>=ss) ans++;
	   }
    cout<<ans<<endl;

   }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	string s,p;
	while(getline(cin,s))
	{
		getline(cin,p);
		int ans=0;
		for(int i=0;i<=s.length()-p.length();i++)
		{
			string x=p;
			int sum=0;
			for(int j=0;j<p.length();j++)
			{
				if(s[i+j]=='?')
					sum++;
				else
				{
					if(x.find(s[i+j])>0)
					{
						sum++;
						x[x.find(s[i+j])]='*';
					}
					else
					{
						break;
					}
				}
				if(sum==p.length())
					ans++;
			}
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int counts[288];
int countp[288];
char p[100006];
char s[100006];
int plen,slen;
bool check(){
	for(int i='a' ;i <='z';i++){
		//cout<<(char)i<<" "<<counts[i]<<" "<<countp[i]<<endl;
		if(counts[i]>countp[i])
			return false;
	}
	return true;
}
int main(){
	scanf("%s%s",s,p);
	plen=strlen(p);
	slen=strlen(s);
	//printf("%s\n%s\n",s,p);
	if(slen<plen){
		printf("0\n");
		return 0;
	}
	int ans=0;
	for(int i=0;i!=plen;i++){
		countp[p[i]]++;
	}
	for(int i=0;i!=plen;i++){
		counts[s[i]]++;
	}
	if(check()){
		ans++;
		//cout<<plen-1<<endl;
	}
	for(int i=plen;s[i]!=0;i++){
		counts[s[i]]++;
		counts[s[i-plen]]--;
		if(check()){
			ans++;
			//cout<<i<<endl;
		}
	}
	printf("%d\n",ans);
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <string.h>
using namespace std;

typedef long long ll;
const double pi=acos(-1.0);
const double eps=1e-11;
const int inf=0x7FFFFFFF;
#define zero(a) memset(a, 0, sizeof(a))
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define srep(i,n) REP(i,1,n+1)

struct sy{
	int c[27];
}k,x;

int check(){
	int i,z=0;
	REP(i,1,27){
		z += abs(k.c[i] - x.c[i]);
	}
	if( z <= k.c[0]) return 1;
	return 0;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt","r",stdin);
#endif

	string a,b;
	cin>>a>>b;
	zero(k.c);
	zero(x.c);
	int len = b.length(),len2 = a.length();
	if( len > len2){
		cout<<"0\n";
		return 0;
	}
	int i,j;
	rep(i,len){
		if(a[i] == '?')
			k.c[0]++;
		else
			k.c[a[i]-'a'+1]++;
		x.c[b[i]-'a'+1]++;
	}
	int ans = 0;

	ans += check();

	REP(i,len,len2){
		if(a[i] == '?')
			k.c[0]++;
		else
			k.c[a[i]-'a'+1]++;
		if(a[i-len] == '?')
			k.c[0]--;
		else
			k.c[a[i-len]-'a'+1]--;
		ans += check();
	}
	cout<<ans<<endl;

return 0;
}


#include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,a[maxn],cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1,j=2;i<=j&&j<=n;i++,j++)
		for(;j<=n;j++)
			if(a[j]>a[i])
			{
				cnt++;break;
			}
	printf("%d\n",cnt);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

int n;
int a[100100];
int c[100100];

int judge(int l,int r,int x){
	int mid=(l+r)>>1;
	if(l==r&&a[r]<x&&!c[r]) return l;
	else if(l+1==r&&a[r]<x&&!c[r])return r;
	else if(l+1==r&&a[l]<x&&!c[l])return l;
	else if(l+1==r) return -1;
	else if(l==r) return -1;
	if(a[mid]==x||c[mid]) return judge(l,mid-1,x);
	else return judge(mid,r,x);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int ans=0;
	sort(a+1,a+1+n);/*
	for(int i=1;i<=n;i++){
		printf("%d ",a[i]);
	}*/
	for(int i=n;i>=2;i--){
		int tmp=judge(1,i-1,a[i]);
		if(tmp==-1) break;
		c[tmp]=1;ans++;
		//printf("du:%d & %d\n",i,tmp);
	}
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a[100005];

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
		}
		sort(a, a+n);
		int res = 0;
		for(int i = 1; i < n; i++)
		{
			if(a[i] > a[res])
				res ++;
		}
		printf("%d\n", res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a[100005];
int ans[100005];

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i = 0; i < n; i++)
			scanf("%d", &a[i]);
		sort(a, a+n);
		int Min = a[0];
		int mark = 0;
		int res = 0;
		for(int i = 1; i < n; i++)
		{
			if(a[i] > Min)
			{
				mark = i;break;
			}
		}
		for(int i = 0; i < n; i++)
		{
			ans[i] = a[mark++];
			if(mark == n)
				mark = 0;
		}
		for(int i = 0; i < n; i++)
		{
			if(ans[i] > a[i])
				res ++;
		}
		printf("%d\n", res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a[100005];
int ans[100005];

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i = 0; i < n; i++)
			scanf("%d", &a[i]);
		sort(a, a+n);
		int Min = a[0];
		int mark = 0;
		int res = 0;
		int cnt = 0;
		for(int i = 1; i < n; i++)
		{
			if(a[i] > Min)
			{
				mark = i;break;
			}
		}
		for(int j = mark; j < n; j++)
		{
			int t = j;
			for(int i = 0; i < n; i++)
			{
				ans[i] = a[t++];
				if(t == n)
					t = 0;
				if(ans[i] > a[i])
					res ++;
			}
			if(cnt < res)
				cnt = res;
			if(cnt > res)
				break;
			res = 0;
		}
		printf("%d\n", cnt);
	}
	return 0;
}


/*=================================
# Created time: 2018-07-13 22:33
# Filename: a.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
 int cnt = 1;
 int c[maxn], a[maxn];
int main(){
	int n; read(n);
	FORP(i, 1, n) read(a[i]);
	sort(a + 1, a + 1 + n);
	c[1] = 1;
	FORP(i, 2, n) {
		if (a[i] != a[i - 1]) cnt++;
		c[cnt]++;
	}
	//FORP(i, 1, cnt) write(c[i],' ');
	a[1] = c[1]; int ans = 0;
	FORP(i, 2, cnt) a[i] = a[i - 1] + c[i];
	if (cnt == 1) {puts("0"); return 0;}
	int head = 1;
	FORM(i, cnt, 1){
		if (head >= i) break;
		while (c[i] && head != i) {
			if (c[i] >= c[head]) ans += c[head], c[i] -= c[head], head++;
			else ans += c[i], c[head] -= c[i];
		}
	}
	write(ans,'\n');
}


/*=================================
# Created time: 2018-07-13 22:33
# Filename: a.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
 int cnt = 1;
 int c[maxn], a[maxn];
int main(){
	int n; read(n);
	FORP(i, 1, n) read(a[i]);
	sort(a + 1, a + 1 + n);
	c[1] = 1;
	FORP(i, 2, n) {
		if (a[i] != a[i - 1]) cnt++;
		c[cnt]++;
	}
	//FORP(i, 1, cnt) write(c[i],' ');
	a[1] = c[1]; int ans = 0;
	FORP(i, 2, cnt) a[i] = c[i];
	if (cnt == 1) {puts("0"); return 0;}
	int tail = cnt - 1;
	FORM(i, cnt, 1){
		if (tail == i) tail --;
		while (tail && c[i]){
			if (c[i] >= a[tail]) ans += a[tail], c[i] -= a[tail], tail--;
			else ans += c[i], a[tail] -= c[i], c[i] = 0;
		}
	}
	write(ans,'\n');
}