using System.Text.RegularExpressions;
using System.Collections.Generic;
public static void Main()
var s1 = "my&friend&Paul has heavy hats! &";
var s2 = "my friend John has many many friends &";
s1 = Regex.Replace(s1, @"[^a-z]", "");
s2 = Regex.Replace(s2, @"[^a-z]", "");
var freq1 = StringCharFrequency(s1);
var freq2 = StringCharFrequency(s2);
var keySet = new HashSet<char>(freq1.Keys);
keySet.UnionWith(freq2.Keys);
var strings = new List<string>();
foreach (var key in keySet)
if (!freq1.TryGetValue(key, out count1))
if (!freq2.TryGetValue(key, out count2))
if (count1 <= 1 && count2 <= 1) continue;
if (count1 > count2) tempS += $"1:{new string(key, count1)}";
else if (count2 > count1) tempS += $"2:{new string(key, count2)}";
else tempS += $"=:{new string(key, count1)}";
var sortedStrings = strings.OrderByDescending(x => x.Length)
Console.WriteLine(string.Join('/', sortedStrings));
private static Dictionary<char, int> StringCharFrequency(string s)
var freq = new Dictionary<char, int>();
if (freq.ContainsKey(ch))