If the sum of first 7 terms of an AP is 49 and that of 17 terms is 289, find the sum of first n terms.