Advanced Algorithm Q.24