Completed the ACM-ICPC team question from hackerrank.