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++: import java.util.*;
class C {
	public static void main(String arg[]){
		while(true){
			Scanner cs=new Scanner(System.in);
			int ans=0;
			int n=cs.nextInt();
			int m=cs.nextInt();
			if (n==0)break;
			int a[][]=new int[n+1][m+1];
			int s[][]=new int[n+1][m+1];
			for (int i=1;i<=n;i++)
				for(int j=1;j<=m;j++){
					a[i][j]=cs.nextInt();
				}
			for (int i=0;i<n;i++)
				for (int j=0;j<m;j++){
					s[i][j]=0;
				}
			for (int i=1;i<n;i++)
				for (int j=1;j<m;j++){
					s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+a[i][j];
				}
			for (int st1=1;st1<n;st1++)
				for (int st2=1;st2<m;st2++)
					for (int en1=st1+2;en1<=n;en1++)
						for (int en2=st2+2;en2<=m;en2++){
							int min=a[st1][st2];
							for(int i=st1;i<=en1;i++){
								if (min>a[i][st2])min=a[i][st2];
								if (min>a[i][en2])min=a[i][en2];
							}
							for(int i=st2;i<=en2;i++){
								if (min>a[st1][i])min=a[st1][i];
								if (min>a[en1][i])min=a[en1][i];
							}
							int max=a[st1+1][st2+1];				
							for (int i=st1+1;i<en1;i++)
								for (int j=st2+1;j<en2;j++)
									if (max<a[i][j])max=a[i][j];
							if (max<min&& ans<min*(en1-st1-1)*(en2-st2-1)-(s[en1-1][en2-1]-s[st1][en2-1]-s[en1-1][st2]+s[st1][st2]))
								ans=min*(en1-st1-1)*(en2-st2-1)-(s[en1-1][en2-1]-s[st1][en2-1]-s[en1-1][st2]+s[st1][st2]);
						}
			System.out.println(ans);
		}
	}
}

C++: #include<iostream>

int e[100][100]={0};
int min=10;

int Pond(int a,int b,int c,int d){
  int x=0;
  for(int i=a+1;i<c+a-1;i++){
    for(int j=b+1;j<d+b-1;j++){
      int f=e[j][i];
      x+=(min-f);
    }
  }
  return f;
}

int area(int a,int b,int c,int d){
  int max=0;
  min=10;
  for(int i=b;i<d+b;i+;){
    int x1=e[i][a];
    int x2=e[i][a+c-1];
    if(x1>x2) x1=x2;
    if(min>x1) min=x1;
  }
  for(int i=a;i<a+c;i++){
    int x1=e[b][i];
    int x2=e[b+d-1][i];
    if(x1>x2) x1=x2;
    if(min>x1) min=x1;
  }
  for(int i=a+1;i<c+a-1;i++){
    for(int j=b+1;j<b+d-1;j++){
      int y=e[j][i];
      if(max<y) max=y;
    }
  }
	if(min>max) retrun 1;
	else return 0;
}

int main()
{
  int d,w;
  int in=0;
  int x=0;
  int ans;
  int tmp;

  while(d>0 && w>0){
    int max=0;
    std::cin>>d>>w;
    if(d==0 && w==0) break;
    for(int i=0;i<d;i++){
      for(int j=0;j<w;j++){
	std::cin>>e[i][j];
      }
    }
    for(int i=d;i>2;i--){
      for(int k=w;k>w;k--){
	for(int j=0;j<i-d+1;j++){
	  for(int l=0;l<k-w+1;l++){
	    if(Pond(l,j,k,i)==1){
	      tmp=area(l,j,k,i);
	      if(tmp>max){
		max=tmp;
	      }
	    }
	  }
	}
      }
      std::cout<<max<<'\n';
    }
    return 0;
  }