Fixed bugs in second solution
Second solution won't work