solving the probelm of bangladesh it talent contest 2014. example problem => http://itcontest.diit.info/mod/resource/view.php?id=10