public class MonthlyStats
public DateTime Date { get; set; }
public ulong FriendCount { get; set; }
public ulong ScoreCount { get; set; }
public sealed class Person
public Person(int id, string name, DateTime registrationDate, ulong friendCount, ulong scoreCount)
RegistrationDate = registrationDate;
FriendCount = friendCount;
public int Id { get; init; }
public string Name { get; set; }
public DateTime RegistrationDate { get; set; }
public ulong FriendCount { get; set; }
public ulong ScoreCount { get; set; }
public static void Main()
new(1, "A", new DateTime(2022, 1, 4), 9, 23),
new(2, "B", new DateTime(2021, 4, 8), 7, 29),
new(3, "C", new DateTime(2021, 9, 11), 4, 13),
new(4, "D", new DateTime(2021, 11, 1), 10, 14),
new(5, "E", new DateTime(2021, 4, 17), 12, 17),
new(6, "F", new DateTime(2022, 1, 27), 5, 11),
new(7, "G", new DateTime(2021, 9, 2), 13, 31),
MonthlyStats[] monthlyStats = persons
.GroupBy(p => new DateTime(p.RegistrationDate.Year, p.RegistrationDate.Month, 1),
( firstDayOfMonth, personsInMonth ) => new MonthlyStats
FriendCount = (ulong)personsInMonth.Sum(p => (decimal)p.FriendCount),
ScoreCount = (ulong)personsInMonth.Sum(p => (decimal)p.ScoreCount)
.OrderBy(stat => stat.Date)
foreach (var stat in monthlyStats)
Console.WriteLine($"{stat.Date:dd/MM/yyyy} | {stat.FriendCount} | {stat.ScoreCount}");