#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "< pii; typedef vector vi; typedef vector vvi; typedef vector vpii; typedef set si; typedef pair pll; typedef vector vl; typedef vector vvl; typedef vector vpll; typedef set sl; typedef __int128_t lll; typedef pair plll; typedef vector vlll; templatestring join(vector&v) {stringstream s;FOR(i,0,sz(v))s<<' '<b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; int n, m; pii DP[1201][1201][3]; string s, t; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> s >> t; pii imp = mp(iinf, -1); fill(DP[0][0], DP[1021][0], imp); DP[0][0][0] = mp(0, -1); int c; FOR(i, 0, n+1)FOR(j, 0, m+1){ if((i==0)&&(j==0)) continue; if((i > 0) && (j > 0)){ c = s[i-1] == t[j-1] ? 0 : 5; mins(DP[i][j][0], mp(DP[i-1][j-1][0].fi + c, 0)); mins(DP[i][j][0], mp(DP[i-1][j-1][1].fi + c, 1)); mins(DP[i][j][0], mp(DP[i-1][j-1][2].fi + c, 2)); } if(i > 0){ mins(DP[i][j][1], mp(DP[i-1][j][0].fi + 9, 0)); mins(DP[i][j][1], mp(DP[i-1][j][1].fi + 2, 1)); mins(DP[i][j][1], mp(DP[i-1][j][2].fi + 9, 2)); } if(j > 0){ mins(DP[i][j][2], mp(DP[i][j-1][0].fi + 9, 0)); mins(DP[i][j][2], mp(DP[i][j-1][1].fi + 9, 1)); mins(DP[i][j][2], mp(DP[i][j-1][2].fi + 2, 2)); } } int ans = iinf, idx; FOR(i, 0, 3)if(ans > DP[n][m][i].fi){ ans = DP[n][m][i].fi; idx = i; } cout << ans << endl; int _n = n, _m = m, _idx; vector vs, vt; while(idx != -1){ _idx = DP[_n][_m][idx].se; switch(idx){ case 0: vs.pb(s[_n-1]); vt.pb(t[_m-1]); _n--; _m--; break; case 1: vs.pb(s[_n-1]); vt.pb('-'); _n--; break; case 2: vs.pb('-'); vt.pb(t[_m-1]); _m--; break; default: break; } idx = _idx; } reverse(rng(vs)); reverse(rng(vt)); each(itr, vs)cout << *itr; cout << endl; each(itr, vt)cout << *itr; cout << endl; return 0; }