Finding x and y and sum of terms