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;
int field[11][11];
int main() {
    while(true) {
        int H, W;
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                cin >> field[h][w];
            }
        }
        int ans = 0;
        for(int h1 = 1; h1 <= H; h1++) {
            for(int h2 = h1 + 2; h2 <= H; h2++) {
                for(int w1 = 1; w1 <= W; w1++) {
                    for(int w2 = w1 + 2; w2 <= W; w2++) {
                        int innermaxi = 0;
                        int outermini = 15;
                        for(int h = h1; h <= h2; h++) {
                            outermini = min(outermini, field[h][w1]);
                            outermini = min(outermini, field[h][w2]);
                        }
                        for(int w = w1; w <= w2; w++) {
                            outermini = min(outermini, field[h1][w]);
                            outermini = min(outermini, field[h2][w]);
                        }
                        int now = 0;
                        for(int w = w1 + 1; w < w2; w++) {
                            for(int h = h1 + 1; h < h2; h++) {
                                innermaxi = max(innermaxi, field[h][w]); 
                                now += outermini - field[h][w];
                            }
                        }
                        if(innermaxi >= outermini) continue;
                        ans = max(ans, now);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int h, w;
int a[15][15];

int check(int sx, int sy, int tx, int ty) {
  int bd = 1e9;
  for (int y = sy; y <= ty; y++) {
    bd = min({bd, a[y][sx], a[y][tx]});
  }
  for (int x = sx; x <= tx; x++) {
    bd = min({bd, a[sy][x], a[ty][x]});
  }
  return bd;
}

int calc(int sx, int sy, int tx, int ty, int bd) {
  int ans = 0;
  for (int y = sy; y <= ty; y++) {
    for (int x = sx; x <= tx; x++) {
      if (bd <= a[y][x]) return 0;
      ans += bd - a[y][x];
    }
  }
  return ans;
}

int main() {
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    rep(y, h) rep(x, w) cin >> a[y][x];

    int ans = 0, bd;
    for (int sy = 0; sy < h - 2; sy++) {
      for (int sx = 0; sx < w - 2; sx++) {
        for (int ty = sy + 2; ty < h; ty++) {
          for (int tx = sx + 2; tx < w; tx++) {
            //池の境界の高さの最小値を求める
            bd = check(sx, sy, tx, ty);

            //容量を求める
            ans = max(ans, calc(sx + 1, sy + 1, tx - 1, ty - 1, bd));
          }
        }
      }
    }
    cout << ans << "\n";
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;
int e[15][15];
int main() {
	while (1) {
		int d, w; cin >> d >> w;
		if (d == 0 && w == 0)break;
		for (int i = 0; i < d; i++) {
			for (int j = 0; j < w; j++) {
				cin >> e[i][j];
			}
		}
		int Max = 0;
		for (int i = 1; i < d - 1; i++) {
			for (int j = 1; j < w - 1; j++) {
				for (int k = i; k < d - 1; k++) {
					for (int l = j; l < w - 1; l++) {
						int Min = 100;
						for (int a = i - 1; a <= k + 1; a++) {
							Min = min(Min, e[a][j - 1]);
							Min = min(Min, e[a][l + 1]);
						}
						for (int b = j - 1; b <= l + 1; b++) {
							Min = min(Min, e[i - 1][b]);
							Min = min(Min, e[k + 1][b]);
						}
						int cnt = 0;
						bool flag = true;
						for (int c = i; c <= k; c++) {
							for (int d = j; d <= l; d++) {
								cnt += (Min - e[c][d]);
								if (e[c][d] >= Min) {
									flag = false;
									break;
								}
							}
						}
						if (flag == true)Max = max(Max, cnt);
					}
				}
			}
		}
		cout << Max << endl;
	}
}