Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		d, w := io.NextInt(), io.NextInt()
		if d == 0 {
			break
		}
		e := make([][]int, d)
		for i := 0; i < d; i++ {
			e[i] = make([]int, w)
			for j := 0; j < w; j++ {
				e[i][j] = io.NextInt()
			}
		}
		ans := 0
		for i := 0; i < d-2; i++ {
			for j := 0; j < w-2; j++ {
				for k := i + 2; k < d; k++ {
					for l := j + 2; l < w; l++ {
						ans = intMax(vol(e, i, j, k, l), ans)
					}
				}
			}
		}
		io.Println(ans)
	}
}

func vol(e [][]int, a, b, c, d int) int {
	outer := 10
	for i := a; i <= c; i++ {
		outer = intMin(e[i][b], outer)
		outer = intMin(e[i][d], outer)
	}
	for j := b; j <= d; j++ {
		outer = intMin(e[a][j], outer)
		outer = intMin(e[c][j], outer)
	}
	a++
	b++
	vol := 0
	for i := a; i < c; i++ {
		for j := b; j < d; j++ {
			if e[i][j] >= outer {
				return 0
			}
			vol += outer - e[i][j]
		}
	}
	return vol
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func intMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)

int main(void){
    int Y,X;
    while(cin>>Y>>X, Y|X){
        int e[10][10] = {};
        rep(y,Y)rep(x,X) cin>>e[y][x];
        int res = 0;
        rep(y2,Y)rep(y1,y2-1)rep(x2,X)rep(x1,x2-1){
            int mn = 9, sum = 0, mx = 0;
            for(int y = y1; y<=y2; y++)for(int x = x1; x<=x2; x++){
                if(x==x1 || x==x2 || y==y1 || y==y2){
                    mn = min(mn,e[y][x]);
                }else{
                    mx = max(mx,e[y][x]);
                    sum += e[y][x];
                }
            }
            if(mn > mx){
                res = max(res, mn*(y2-y1-1)*(x2-x1-1) - sum);
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int highest=100;

int gerden[11][11];

int main(){
    int d, w;
    while(cin >> d >> w){
        if(d==0 && w==0) break;
        for(int i=0; i<d; i++){
            for(int j=0; j<w; j++){
                cin >> gerden[i][j];
            }
        }

        int ans=0;
        for(int i=3; i<=d; i++){
            for(int j=3; j<=w; j++){    // 縦i横jの池候補
                for(int k=0; k<=d-i; k++){
                    for(int l=0; l<=w-j; l++){   // 池候補を縦横に動かす

                        int min_out=100, max_in=-1, capacity=0;
                        for(int m=k; m<i+k; m++){
                            for(int n=l; n<j+l; n++){   // 池かどうかを調べる(ついでに容量)
                                if(m==k || n==l || m==k+i-1 || n==l+j-1){
                                    if(gerden[m][n]<min_out){
                                        min_out = gerden[m][n];
                                    }
                                }else{
                                    capacity += highest - gerden[m][n];
                                    if(gerden[m][n]>max_in){
                                        max_in = gerden[m][n];
                                    }
                                }
                            }
                        }
                        if(max_in < min_out){
                            if(capacity-((100-min_out)*(i-2)*(j-2)) > ans ){
                                ans = capacity - ((100-min_out)*(i-2)*(j-2));
                            }
                        }

                    }
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = (a); i <= (b); ++i)

main() {
    while(1) {
        int h, w;
        cin >> h >> w;
        if(!h) return 0;
        vector<vector<int>> a(h, vector<int>(w));
        rep(i, h) rep(j, w) cin >> a[i][j];
        int ans = 0;
        rep(i, h) rep2(ii, i, h - 1) rep(j, w) rep2(jj, j, w - 1) {
            int d = 0;
            if(i + 1 >= ii or j + 1 >= jj) continue;
            rep2(iii, i + 1, ii - 1) {
                rep2(jjj, j + 1, jj - 1) { d = max(d, a[iii][jjj]); }
            }
            int D = INT_MAX;
            rep2(jjj, j, jj) D = min({D, a[i][jjj], a[ii][jjj]});
            rep2(iii, i, ii) D = min({a[iii][j], a[iii][jj], D});
            if(D <= d) continue;
            int now = 0;
            rep2(iii, i + 1, ii - 1) rep2(jjj, j + 1, jj - 1) now += D - a[iii][jjj];
            ans = max(ans, now);
        }
        cout << ans << endl;
    }
}