Problem B added. Not working for large input though