First solution

so unbelievably slow