using System.Collections.Generic;
public static void Main()
TimeSpan[] hours = new[] {
var query = hours.Aggregate(new List<(int group, TimeSpan ts)>(), (acc,curr) => {
var (lastGroup,lastTs) = acc.Last();
if(curr.Subtract(lastTs).TotalMinutes <= 5)
acc.Add((lastGroup,curr));
acc.Add((lastGroup+1,curr));
}).GroupBy(x => x.group, y => y.ts);
foreach(var item in query)
Console.WriteLine(String.Join(", ", item));