using System.Collections.Generic;
public string Name { get; set; }
public double Debt { get; set; }
public int Apt { get; set; }
override public string ToString() {
return string.Format("{0} {1} {2}", this.Name, this.Debt, this.Apt);
public static void Main()
var data = new List<Debtor> {
new Debtor { Name = "Name1", Debt = 123.123, Apt = 123 },
new Debtor { Name = "Name2", Debt = 321.321, Apt = 87 },
new Debtor { Name = "Name3", Debt = 231.231, Apt = 36 }
var res = data.GroupBy(x => Math.Ceiling((double)(x.Apt % 36) / 4), x => x,
(key, value) => string.Format("{0}, {1}", key, value.Where(x => x.Debt == value.Min(y => y.Debt)).First()));
foreach (var str in res) {