The sum of n terms of an AP whose first term is 6 and common difference is 40 is equal to the sum of 2n terms is 40 and common difference is 6. Find the value of n.