using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Number = System.Int64;
namespace Program
{
///
/// 経路復元パートとかいう無駄な面倒要素
///
public class Solver
{
public void Solve()
{
var n = sc.Integer();
var m = sc.Integer();
var s = sc.Scan();
var t = sc.Scan();
var dp = new int[n + 2, m + 2, 3];
var prev = new Triplet[n + 2, m + 2, 3];
for (int i = 0; i <= n + 1; i++)
for (int j = 0; j <= m + 1; j++)
for (int k = 0; k < 3; k++)
dp[i, j, k] = 1145141919;
dp[0, 0, 0] = 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++)
for (int k = 0; k < 3; k++)
{
if (i < n && j < m)
{
var x = s[i] == t[j] ? 0 : 5;
if (dp[i + 1, j + 1, 0] > dp[i, j, k] + x)
{
dp[i + 1, j + 1, 0] = dp[i, j, k] + x;
prev[i + 1, j + 1, 0] = new Triplet(i, j, k);
}
}
if (j < m)
{
var x = k == 1 ? 2 : 9;
if (dp[i, j + 1, 1] > dp[i, j, k] + x)
{
dp[i, j + 1, 1] = dp[i, j, k] + x;
prev[i, j + 1, 1] = new Triplet(i, j, k);
}
}
if (i < n)
{
var x = k == 2 ? 2 : 9;
if (dp[i + 1, j, 2] > dp[i, j, k] + x)
{
dp[i + 1, j, 2] = dp[i, j, k] + x;
prev[i + 1, j, 2] = new Triplet(i, j, k);
}
}
}
var min = int.MaxValue;
for (int k = 0; k < 3; k++)
min = Math.Min(min, dp[n, m, k]);
var ss = new List();
var tt = new List();
var p = new Triplet(n, m, -1);
for (int k = 0; k < 3; k++)
if (dp[n, m, k] == min) p.K = k;
while (p.I > 0 || p.J > 0)
{
var pre = prev[p.I, p.J, p.K];
if (pre.K == 0)
{
ss.Add(s[pre.I]);
tt.Add(t[pre.J]);
}
else if (pre.K == 1)
ss.Add('-');
else tt.Add('-');
p = pre;
}
IO.Printer.Out.WriteLine(min);
ss.Reverse(); tt.Reverse();
IO.Printer.Out.WriteLine(ss.AsString());
IO.Printer.Out.WriteLine(tt.AsString());
}
public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
}
}
#region main
static class Ex
{
static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
static public string AsJoinedString(this IEnumerable ie, string st = " ") { return string.Join(st, ie); }
static public void Main()
{
var solver = new Program.Solver();
solver.Solve();
Program.IO.Printer.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO
{
using System.IO;
using System.Text;
using System.Globalization;
public class Printer: StreamWriter
{
static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
public void Write(string format, T[] source) { base.Write(format, source.OfType