careercup 5.7: method borrowed from the std answer