some algorithm solution