Acm algorithm - and check the detailed solution