The city of Poughkeepsie celebrates Halloween every year. Geographically, the city is a rectangle that is 30 miles long and 45 miles wide. On a map, it looks like a grid, with its east-west roads horizontally dividing the city into 1-mile-long rectangles and its north-south roads vertically dividing the city likewise. There is one house at each road intersection.
The city's residents tend to be more generous with their candy as one moves toward the center of the rectangle. The resident at the lower-left corner of the city - whom we'll call Bob - gives out 10 candies per child. If a child starts at Bob's house and proceeds eastward, each resident they come across will give them 5 more candies than the last one (In other words, Bob's nearest eastern neighbor will give 15 candies. If a child walks another mile to the next eastern neighbor, they get another 20 candies.) After they reach the horizontal center street, that number decreases by 5. If that same child instead proceeds northward of Bob's house - which is located at (0,0) - each resident they meet will give them 10 more candies than the previous resident. After they reach the relevant center street, each resident they meet will give 10 less.
The number of candies given out by residents who do not live on the edges of the city is the sum of the number of candies given out by the two neighbors who live on the nearest borders of the city. So, a resident who lives at (44,29) will give out the number of candies given by the resident at (45,29) + the number of candies given by the resident at (30,44).
Important note: The only way to access each house is by walking along roads or adjacent paths. One is not allowed to, for example, bee-line from Bob's house to (1,1) - s/he must first either walk along the y-axis for 1 mile, turn right and walk for another mile; or walk along the x-axis for 1 mile, turn left and walk for another mile. Also, once a child has received candy from a house, they will receive no more candy from that same house.
Objective: Your program is to figure out how much candy a child can receive if s/he starts at Bob's house and is to walk no more than a given distance "d".
Scoring Programs will be scored based on the size (in bytes) of the source code.