459B

codeforces problem solution 
written in python 2.7