#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string A, B; //--------------------------------------------------------------------------------------------------- enum { NORMAL, QUESTION, STAR }; //--------------------------------------------------------------------------------------------------- vector> parse(string s) { int n = s.length(); vector> res; rep(i, 0, n) { if(i + 1 < n and s[i + 1] == '?') { res.push_back({QUESTION, s[i]}); i++; } else if(i + 1 < n and s[i + 1] == '*') { res.push_back({STAR, s[i]}); i++; } else res.push_back({NORMAL, s[i]}); } return res; } //--------------------------------------------------------------------------------------------------- int dp[2010][2010]; void _main() { cin >> A >> B; auto AA = parse(A); auto BB = parse(B); int NA = AA.size(); int NB = BB.size(); rep(a, 0, NA + 1) rep(b, 0, NB + 1) dp[a][b] = inf; dp[0][0] = 0; rep(a, 0, NA) rep(b, 0, NB) { if (AA[a].first == NORMAL) chmin(dp[a + 1][b], dp[a][b] + 1); else chmin(dp[a + 1][b], dp[a][b]); if (BB[b].first == NORMAL) chmin(dp[a][b + 1], dp[a][b] + 1); else chmin(dp[a][b + 1], dp[a][b]); if(AA[a].first == NORMAL and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == NORMAL and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == NORMAL and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == QUESTION and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == NORMAL) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == QUESTION) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } if(AA[a].first == STAR and BB[b].first == STAR) { chmin(dp[a + 1][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a + 1][b], dp[a][b] + (AA[a].second != BB[b].second)); chmin(dp[a][b + 1], dp[a][b] + (AA[a].second != BB[b].second)); } } rep(a, 0, NA) { if (AA[a].first == NORMAL) chmin(dp[a + 1][NB], dp[a][NB] + 1); else chmin(dp[a + 1][NB], dp[a][NB]); } rep(b, 0, NB) { if (BB[b].first == NORMAL) chmin(dp[NA][b + 1], dp[NA][b] + 1); else chmin(dp[NA][b + 1], dp[NA][b]); } cout << dp[NA][NB] << endl; }