#coordinate geometry algorithm