problem

There is a light bulb at the grid point $ (x, y) $ that meets $ 1 \ leq x \ leq h, 1 \ leq y \ leq w $.

The power supply is installed at coordinates $ (i + 0.5, j + 0.5) (1 \ leq i <h, 1 \ leq j <w, i + j $ is even) (corrected at 14:21). Coordinates $ When the power supply installed at (i + 0.5, j + 0.5) $ is turned on, the coordinates $ (i, j), (i + 1, j), (i, j + 1), (i + 1) , j + 1) $ 4 $ light bulbs in $ glow.

If you have more than $ 1 $ connected to a power supply with a light bulb on $ (i, j) $, you get $ B_ {i, j} $ cleanliness. You have the total cleanliness. Also, if you turn on each power supply, it costs $ W $ for electricity per $ 1 $.

Turn on some power to maximize "total income-total electricity bill".



output

Output the maximum value of "total income-total electricity bill". Also, output a line break at the end.

Example

Input

4 4 10
100 100 100 100
100 100 100 100
1 100 100 1
1 1 1 1


Output

970
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e16;
struct edge {int to; long long int cap; int rev;} ;
 
vector<edge> G[2510];
int level[2510];
int iter[2510];
 
void add_edge(int from, int to, long long int cap){
	edge e;
	e.to=to, e.cap=cap, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=0, e.rev=G[from].size()-1;
	G[to].push_back(e);
}
 
void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0; i<G[v].size(); i++){
			edge e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
 
long long int dfs(int v, int t, long long int f){
	if(v==t) return f;
	for(int &i=iter[v]; i<G[v].size(); i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			long long int d=dfs(e.to, t, min(f, e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
 
long long int max_flow(int s, int t){
	long long int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter, 0, sizeof(iter));
		long long int f;
		while((f=dfs(s, t, INF))>0){
			flow+=f;
		}
	}
}

int main()
{
    int h, w; ll W;
    cin>>h>>w>>W;
    int s=(h-1)*(w-1), t=(h-1)*(w-1)+1;
    for(int i=0; i<h-1; i++){
        for(int j=0; j<w-1; j++){
            if((i+j)&1) continue;
            if(i&1) add_edge(i*(w-1)+j, t, W);
            else add_edge(s, i*(w-1)+j, W);
        }
    }
    ll b[51][51];
    ll sum=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>b[i][j];
            sum+=b[i][j];
            if(i==0) add_edge(j-j%2, t, b[i][j]);
            else if(j==0) add_edge((i-i%2)*(w-1), t, b[i][j]);
            else if(i==h-1) add_edge((h-2)*(w-1)+j-j%2, t, b[i][j]);
            else if(j==w-1) add_edge((i-i%2)*(w-1)+w-2, t, b[i][j]);
            else if((i&1) && !(j&1)) add_edge((i-1)*(w-1)+j, i*(w-1)+j-1, b[i][j]);
            else if(!(i&1) && (j&1)) add_edge(i*(w-1)+j-1, (i-1)*(w-1)+j, b[i][j]);
            else if((i&1) && (j&1)) add_edge((i-1)*(w-1)+j-1, i*(w-1)+j, b[i][j]);
            else add_edge(i*(w-1)+j, (i-1)*(w-1)+j-1, b[i][j]);
        }
    }
    cout<<sum-max_flow(s, t)<<endl;
    return 0;
}
