#include using namespace std; using ll=long long; using ld=double; #define FOR(i,a,b) for(ll i=a;i<(ll)b;++i) #define F(n) FOR(i,0,n) #define FF(n) FOR(j,0,n) #define aa first #define bb second #define PB push_back #define EQ(a,b) (fabs(a-b)<=(fabs(a+b)*EPS)) #define INF (1 << 25) ll g = 0; string fix(const string & a) { string res; F(a.size()) { if (a[i] >= '0' && a[i] <= '9') { FF(a[i] - '0') res.PB('#'); g ++; } else res.PB(a[i]); } return res; } #define ROW 12007 #define COL 3007 int dp[ROW][COL]; int main(){ ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); string a, b; cin >> a; cin >> b; a = fix(a); b = fix(b); //cout << a << endl << b << endl; F(ROW)FF(COL) dp[i][j] = INF; F(ROW) dp[i][0] = i; F(COL) dp[0][i] = i; for (int i = 1; i < a.size() + 1; ++ i) { for (int j = 1; j < b.size() + 1; ++ j) { dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1); dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1); if (a[i - 1] == '#' || b[j - 1] == '#') dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]); if (a[i - 1] == b[j - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]); } } /*F(a.size() + 1) { FF(b.size() + 1) { cout << dp[i][j] << ' '; } cout << endl; }*/ cout << g + dp[ a.size() ][ b.size() ] << endl; return 0; }