using System;
using System.Linq;
public class Test
{
public static void Main()
{
string input = " aa aaa aaaa bb bbb bbbb cc ccc cccc cccc ";
var words = input.Split((char[])null, StringSplitOptions.RemoveEmptyEntries).Distinct();
var lookup = words.ToLookup(s => s.Length);
foreach (var group in lookup)
{
Console.WriteLine(string.Join(", ", group.ToArray()));
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlzdHJpbmcgaW5wdXQgPSAiIGFhIGFhYSBhYWFhICBiYiBiYmIgYmJiYiBjYyBjY2MgY2NjYyBjY2NjICI7CiAJCXZhciB3b3JkcyA9IGlucHV0LlNwbGl0KChjaGFyW10pbnVsbCwgU3RyaW5nU3BsaXRPcHRpb25zLlJlbW92ZUVtcHR5RW50cmllcykuRGlzdGluY3QoKTsKIAkJdmFyIGxvb2t1cCA9IHdvcmRzLlRvTG9va3VwKHMgPT4gcy5MZW5ndGgpOwogCQlmb3JlYWNoICh2YXIgZ3JvdXAgaW4gbG9va3VwKQogCQl7CiAJCQlDb25zb2xlLldyaXRlTGluZShzdHJpbmcuSm9pbigiLCAiLCBncm91cC5Ub0FycmF5KCkpKTsKIAkJfQoJfQp9