cost of having cam sensor replaced & possibly timing chain? on 2007 Hyundai Sonata

the check engine light came on, code said timing advanced & cam sensor, car began idling rougher, reset check engine light & it came back on in about 400 miles then check engine light went out in about 100 miles...then this repeats

Asked by for the 2007 Hyundai Sonata