#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 205;
const int M = 205;
bool vis[N][M];
int map[N][M], f[N][M];
int n, m;
int dp(int x, int y) {
if (x == 1)
return f[x][y] = map[x][y];
if (vis[x][y])
return f[x][y];
int res = -214748;
res = max(res, dp(x-1, y));
if (x - 1 >= 1 && y - 1 >= 1)
res = max(res, dp(x-1, y-1));
if (x - 1 >= 1 && y + 1 <= m)
res = max(res, dp(x-1, y+1));
res += map[x][y];
f[x][y] = res;
vis[x][y] = true;
return res;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j= 1; j <= m; j++)
scanf("%d", &map[i][j]);
printf("%d\n", dp(n, m / 2 + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
printf("%d ", f[i][j]);
printf("\n");
}
return 0;
}