Solution for 1st three problems