#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool isMatch(string s, string p) {
int m = s.length(), n = p.length();
vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false));
// Base case: both strings are empty
dp[0][0] = true;
// Initialize dp for patterns with '*' that can match an empty string
for (int j = 2; j <= n; j++) {
if (p[j - 1] == '*') {
dp[0][j] = dp[0][j - 2];
}
}
// Fill the dp table
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (p[j - 1] == '.' || p[j - 1] == s[i - 1]) {
// Current characters match or pattern has '.'
dp[i][j] = dp[i - 1][j - 1];
} else if (p[j - 1] == '*') {
// Handle '*'
dp[i][j] = dp[i][j - 2];
// Treat '*' as matching zero of the preceding character
if (p[j - 2] == '.' || p[j - 2] == s[i - 1]) {
dp[i][j] = dp[i][j] || dp[i - 1][j];
// Match one or more of the preceding character
}
}
}
}
return dp[m][n];
}
int main() {
string s;
string p;
cin >> s >> p;
cout << boolalpha << isMatch(s, p) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBpc01hdGNoKHN0cmluZyBzLCBzdHJpbmcgcCkgewogICAgaW50IG0gPSBzLmxlbmd0aCgpLCBuID0gcC5sZW5ndGgoKTsKICAgIHZlY3Rvcjx2ZWN0b3I8Ym9vbD4+IGRwKG0gKyAxLCB2ZWN0b3I8Ym9vbD4obiArIDEsIGZhbHNlKSk7CgogICAgLy8gQmFzZSBjYXNlOiBib3RoIHN0cmluZ3MgYXJlIGVtcHR5CiAgICBkcFswXVswXSA9IHRydWU7CgogICAgLy8gSW5pdGlhbGl6ZSBkcCBmb3IgcGF0dGVybnMgd2l0aCAnKicgdGhhdCBjYW4gbWF0Y2ggYW4gZW1wdHkgc3RyaW5nCiAgICBmb3IgKGludCBqID0gMjsgaiA8PSBuOyBqKyspIHsKICAgICAgICBpZiAocFtqIC0gMV0gPT0gJyonKSB7CiAgICAgICAgICAgIGRwWzBdW2pdID0gZHBbMF1baiAtIDJdOwogICAgICAgIH0KICAgIH0KCiAgICAvLyBGaWxsIHRoZSBkcCB0YWJsZQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gbjsgaisrKSB7CiAgICAgICAgICAgIGlmIChwW2ogLSAxXSA9PSAnLicgfHwgcFtqIC0gMV0gPT0gc1tpIC0gMV0pIHsKICAgICAgICAgICAgICAgIC8vIEN1cnJlbnQgY2hhcmFjdGVycyBtYXRjaCBvciBwYXR0ZXJuIGhhcyAnLicKICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gZHBbaSAtIDFdW2ogLSAxXTsKICAgICAgICAgICAgfSBlbHNlIGlmIChwW2ogLSAxXSA9PSAnKicpIHsKICAgICAgICAgICAgICAgIC8vIEhhbmRsZSAnKicKICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gZHBbaV1baiAtIDJdOyAKICAgICAgICAgICAgICAgIC8vIFRyZWF0ICcqJyBhcyBtYXRjaGluZyB6ZXJvIG9mIHRoZSBwcmVjZWRpbmcgY2hhcmFjdGVyCiAgICAgICAgICAgICAgICBpZiAocFtqIC0gMl0gPT0gJy4nIHx8IHBbaiAtIDJdID09IHNbaSAtIDFdKSB7CiAgICAgICAgICAgICAgICAgICAgZHBbaV1bal0gPSBkcFtpXVtqXSB8fCBkcFtpIC0gMV1bal07IAogICAgICAgICAgICAgICAgICAgIC8vIE1hdGNoIG9uZSBvciBtb3JlIG9mIHRoZSBwcmVjZWRpbmcgY2hhcmFjdGVyCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIGRwW21dW25dOwp9CgppbnQgbWFpbigpIHsKICAgIHN0cmluZyBzOwogICAgc3RyaW5nIHA7CgoJY2luID4+IHMgPj4gcDsKCiAgICBjb3V0IDw8IGJvb2xhbHBoYSA8PCBpc01hdGNoKHMsIHApIDw8IGVuZGw7IAoKICAgIHJldHVybiAwOwp9