Advanced Algorithm Q.27