How to handle edge cases of stack

join shbcf.ru