The first and last term of an A.P are 5 and 45 respectively. If the sum of all the terms is 400, find the common difference.