private IEnumerable<string> TakeByThree(string input)
{
var remains = input;
while (!string.IsNullOrEmpty(remains) && remains.Length >= 3)
{
yield return remains.Substring(0, 3);
remains = remains.Substring(3);
}
}
public string Contract(string input) =>
new string(TakeByThree(input).Select(t => t[0] == t[1] || t[0] == t[2] ? t[0] : t[1]).ToArray());