using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
static IEnumerable<string> Filter(IEnumerable<string> files, string query) {
var lowerQuery = query.ToLower();
var hasNew = lowerQuery.StartsWith("new");
return files
.Where(f =>
f.ToLower().Contains(lowerQuery)
&& (hasNew || !f.ToLower().StartsWith("new"))
);
}
public static void Main()
{
var data = new[] {"NewFile1", "NewFile2", "File1", "File2", "Newfoundland"};
foreach (var s in Filter(data, "file")) {
Console.Write("{0} ", s);
}
Console.WriteLine();
foreach (var s in Filter(data, "newf")) {
Console.Write("{0} ", s);
}
Console.WriteLine();
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CiAgICBzdGF0aWMgSUVudW1lcmFibGU8c3RyaW5nPiBGaWx0ZXIoSUVudW1lcmFibGU8c3RyaW5nPiBmaWxlcywgc3RyaW5nIHF1ZXJ5KSB7CiAgICAgICAgdmFyIGxvd2VyUXVlcnkgPSBxdWVyeS5Ub0xvd2VyKCk7CiAgICAgICAgdmFyIGhhc05ldyA9IGxvd2VyUXVlcnkuU3RhcnRzV2l0aCgibmV3Iik7CiAgICAgICAgcmV0dXJuIGZpbGVzCiAgICAgICAgICAgIC5XaGVyZShmID0+CiAgICAgICAgICAgICAgICBmLlRvTG93ZXIoKS5Db250YWlucyhsb3dlclF1ZXJ5KQogICAgICAgICAgICAmJiAgKGhhc05ldyB8fCAhZi5Ub0xvd2VyKCkuU3RhcnRzV2l0aCgibmV3IikpCiAgICAgICAgICAgICk7Cgl9CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIGRhdGEgPSBuZXdbXSB7Ik5ld0ZpbGUxIiwgIk5ld0ZpbGUyIiwgIkZpbGUxIiwgIkZpbGUyIiwgIk5ld2ZvdW5kbGFuZCJ9OwoJCWZvcmVhY2ggKHZhciBzIGluIEZpbH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