Same solution implemented again for the new online judge but with two cases incorporated into same logic.