Totalling Troublesome T's Given a "T" shape on an x * y number grid, with length W on the top bar and H on the stem of the T, with the bottom of the T on the square numbered n: calculate the total of all of the numbers in the T shape. W must be an odd number and all must be positive integers.

Here are some examples of valid T's on a 9*9 grid:



Looking at the T where n=32, W=3 &amp; H=4, you can see that the total is:4 + 5 + 6 + 14 + 23 + 32 = 84.

The Challenge

Your challenge is to create a program which, when given five positive integers, x, y, W, H and n, output the total of the T with those values (W must be odd, given an even number the program can output anything or even crash). The numbers may be inputted in any reasonable format. If the T does not fit on the given grid, then any output is acceptable.

Example Code (Python 3.6.2)

x = int(input())
y = int(input())
W = int(input())
H = int(input())
n = int(input())

total = 0

#"Stem" of the T
for i in range(H - 1):
    total += n - (x * i) #Decrease increment by length of row each time

#Top of the T 
for i in range(-W//2 + 1, W//2 + 1): #Iterate over the width offset so that the center is zero
    total += (n - (x * (H - 1))) + i #Add the top squares on the T, one less to the left and one more to the right

print(total)


As with most challenges here this is code-golf, so the answer with the shortest code in bytes wins.
JavaScript (ES6), 32 30 bytes

Saved 2 bytes thanks to @Shaggy

(w,h,x)=&gt;Q=n=&gt;--h?n+Q(n-x):n*w


Takes input in a curried format: f(W,H,x,y)(n)



let f =
(w,h,x)=&gt;Q=n=&gt;--h?n+Q(n-x):n*w;

console.log(
  f(3, 4, 9, 9)(32)
);




How?

First we note that the sum of the T starting at n with height H can be broken down into two sums:


n
The sum of the T starting one row higher with height H - 1


By repeatedly adding n to the total, moving one row up, and subtracting 1 from H until it reaches 1, we end up summing the vertical stem of the T. Moving one row up is accomplished by subtracting x from n, since it can be observed that the difference between any cell and the one above is x.

When H reaches 1, we now have only the crossbar of width W left to sum. At this point n represents the center of the crossbar. We could sum the crossbar recursively as we did with the stem, but instead we take advantage of a fairly simple formula:

sum(n - a : n + a) = (n - a) + (n - (a-1)) + ... + n + ... + (n + (a-1)) + (n + a)
                   = (n - a) + (n + a) + (n - (a-1)) + (n + (a-1)) + ... + n
                   = 2n + 2n + ... + n
                   = n * (2a + 1)


In this case, our a is (W - 1) / 2, which makes

n * (2a + 1) = n * (((W - 1) / 2) * 2 + 1)
             = n * ((W - 1) + 1)
             = n * W


which is the sum of the crossbar.