static void prep(){
        colUp = new int[n][m];
        colDown = new int[n][m];
        rowLeft = new int[n][m];
        rowRight = new int[n][m];

        for(int i=1; i<n; i++){
            for(int j=0; j<m; j++){
                colDown[i][j] = colDown[i-1][j] + value(a[i-1][j], a[i][j]);
            }
        }
        for(int i=n-2; i>=0; i--){
            for(int j=0; j<m; j++){
                colUp[i][j] = colUp[i+1][j] + value(a[i+1][j], a[i][j]);
            }
        }
        for(int j=1; j<m; j++){
            for(int i=0; i<n; i++){
                rowRight[i][j] = rowRight[i][j-1] + value(a[i][j-1], a[i][j]);
            }
        }
        for(int j=m-2; j>=0; j--){
            for(int i=0; i<n; i++){
                rowLeft[i][j] = rowLeft[i][j+1] + value(a[i][j+1], a[i][j]);
            }
        }
    }