Modified for POJ AND WE GET OUT OF MEMORY HAHAHAHA