Greater Average Submatrix Objective

Write a program in any language that reads a matrix from stdin in which all columns are space delimited and all rows are newline delimited. The program must output a sub matrix so as that there is no other sub matrix with greater average, this sub matrix' average value, as well as the starting and ending coordinates. Each sub matrix must be at least 2x2. The initial matrix can be an m x n matrix where 2 &lt; m &lt; 256 and 2 &lt; n &lt; 512. For each element e, you know that -1000000 &lt; e &lt; 1000000

Example Inputs

A)

1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18


B)

1 1 1
1 1 1
1 1 1


Example Output

A)

Sub Matrix:
11 12
17 18
Average of all values:
14.5
Starting Coordinates:
[4,0]
Ending Coordinates:
[5,1]


B)

Sub Matrix:
1 1
1 1
Average of all values:
1
Starting Coordinates:
[0,0]
Ending Coordinates:
[1,1]


Rules

You may not use any matrix related library provided for your language but you may use lists, arrays, tables, dictionaries and all the operations that can be performed without including / importing anything in your language.

Scoring


You get one point for every additional byte of code.
You get one point for every variable you use (even if it's a list).
You get one point for every function / method (including lambda / anonymous) you use.
The winner is the solution with the fewest points.
MATLAB, 332 + 9 + 7 = 348
The code:
v=str2num(input(''));s=size(v);d=[];e={};for m=1:s(1)-1 for n=1:s(2)-1 for o=1:s(1)-m for p=1:s(2)-n q=v(o:m+o,p:n+p);e=[e {q}];d=[d;mean(q(:)) o p o+m p+n];end;end;end;end;[~,m]=max(d(:,1));disp('Sub Matrix:');disp(e{m});fprintf('Average of all values:\n%f\nStarting Coordinates:\n[%d,%d]\nEnding Coordinates:\n[%d,%d]\n',d(m,1:5))

And an explanation
%Functions used (7):
%    input str2num size mean max disp fprintf
%Variables used (9):
%    v s d e m n o p q

v=str2num(input('')); %Convert to matrix (new lines and spaces are correctly handled by str2num to form dimensions)
s=size(v); %Dimensions of n.
d=[];
e={};
for m=1:s(1)-1
    %Loop through all widths from 2 up to the width of the matrix (-1 to save doing that later)
    for n=1:s(2)-1
        %Loop through all heights from 2 up the the width of the matrix (-1 to save doing that later)
        for o=1:s(1)-m
            for p=1:s(2)-n
                %Extract the sub array
                q=v(o:m+o,p:n+p);
                %Store the sub array in a cell array so we don't have to extract it later.
                e=[e {q}];
                %Append to the list the details (mean and indicies) of this sub array.
                d=[d;mean(q(:)) o p o+m p+n];
            end
        end
    end
end
%Find the index of the sub array with the largest mean
[~,m]=max(d(:,1));
%And print the output
disp('Sub Matrix:');
disp(e{m});
fprintf('Average of all values:\n%f\nStarting Coordinates:\n[%d,%d]\nEnding Coordinates:\n[%d,%d]\n',d(m,1:5))

input asks for you to enter the matrix. Because MATLAB struggles with new lines, you need to type something like ['1 2 3 4' 10 '5 6 7 8'] Note that the 10 is the new line character. This basically just forms the array exactly as your string would be (the ' and [] are not passed in to the code)