A solution to ineger allocation problem described on SO