#include <bits/stdc++.h>
using namespace std;
long long computeHash(int left, int right, const vector<long long> &hashes, const vector<long long> &powers, long long base) {
return hashes[right] - hashes[left - 1] * powers[right - left + 1];
}
bool isMatchingFrequency(const vector<int> &freqS, const vector<int> &freqT) {
for (int i = 0; i < 26; i++) {
if (freqS[i] != freqT[i]) return false;
}
return true;
}
int main() {
string s, t;
cin >> s >> t;
int lenS = s.length();
int lenT = t.length();
const long long base = 131;
vector<int> freqS(26, 0);
vector<int> freqT(26, 0);
for (char ch : s) {
freqS[ch - 'a']++;
}
vector<long long> hashes(lenT + 1, 0);
vector<long long> powers(lenT + 1, 1);
for (int i = 1; i <= lenT; i++) {
hashes[i] = hashes[i - 1] * base + t[i - 1];
powers[i] = powers[i - 1] * base;
}
set<long long> uniqueHashes;
for (int i = 0; i < lenT; i++) {
freqT[t[i] - 'a']++;
if (i >= lenS) {
freqT[t[i - lenS] - 'a']--;
}
if (i >= lenS - 1 && isMatchingFrequency(freqS, freqT)) {
int windowStart = i - lenS + 1;
int windowEnd = i + 1;
uniqueHashes.insert(computeHash(windowStart + 1, windowEnd, hashes, powers, base));
}
}
cout << uniqueHashes.size() << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgY29tcHV0ZUhhc2goaW50IGxlZnQsIGludCByaWdodCwgY29uc3QgdmVjdG9yPGxvbmcgbG9uZz4gJmhhc2hlcywgY29uc3QgdmVjdG9yPGxvbmcgbG9uZz4gJnBvd2VycywgbG9uZyBsb25nIGJhc2UpIHsKICAgIHJldHVybiBoYXNoZXNbcmlnaHRdIC0gaGFzaGVzW2xlZnQgLSAxXSAqIHBvd2Vyc1tyaWdodCAtIGxlZnQgKyAxXTsKfQoKYm9vbCBpc01hdGNoaW5nRnJlcXVlbmN5KGNvbnN0IHZlY3RvcjxpbnQ+ICZmcmVxUywgY29uc3QgdmVjdG9yPGludD4gJmZyZXFUKSB7CiA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