Implemented new algorithm. Failed UVA online judge