.bills as $bills | [ $bills[].alloc[] ] | group_by(.ower.name) | [ .[] | .[0].ower.name as $ower | { $ower: [ .[].amount, ($bills[] | select(.payed_by.name == $ower) | -.amount) ] | add } ] | add