/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int a[2000][2000];
int n,m;
LL w;
LL an;
bool out(int x ,int y){
    return x < 0 || y < 0 || x >= n || y >= m || a[x][y] == -1;
}
PII bfs[4000000];
int bn;
bool u[2000][2000];
int dis[2000][2000];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
LL go(int x1,int y1,int x2,int y2){
    bfs[0]=MP(x1,y1);
    dis[x1][y1]=0;
    MS0(u);
    u[x1][y1]=1;
    bn=1;
    LL ret=1e18;
    REP(i,bn){
        auto x=bfs[i];
        if(a[x.F][x.S])ret=min(ret,a[x.F][x.S]+dis[x.F][x.S]*w);
        if(x.F==x2&&x.S==y2){
            an=min(an,dis[x.F][x.S]*w);
            break;
        }
        REP(j,4){
            int nx=x.F+dx[j];
            int ny=x.S+dy[j];
            if(out(nx,ny)){continue;}
            if(u[nx][ny]){continue;}
            u[nx][ny]=1;
            dis[nx][ny]=dis[x.F][x.S]+1;
            bfs[bn++]=MP(nx,ny);
        }
    }
    return ret;
}
void solve() {
    an=1e18;
    LL v1 = go(0,0,n-1,m-1);
    LL v2 = go(n-1,m-1,0,0);
    an=min(an,v1+v2);
    if(an>1e17)W(-1);
    else W(an);
}
void input() {
    R(n,m,w);
    REP(i,n)REP(j,m){
        R(a[i][j]);
    }
}
int main(){
    input();
    solve();
    return 0;
}


### Prompt

Your challenge is to write a Cpp solution to the following problem:

Dima overslept the alarm clock, which was supposed to raise him to school.

Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school.

The city where Dima lives is a rectangular field of n × m size. Each cell (i, j) on this field is denoted by one number a_{ij}:

  * The number -1 means that the passage through the cell is prohibited; 
  * The number 0 means that the cell is free and Dima can walk though it. 
  * The number x (1 ≤ x ≤ 10^9) means that the cell contains a portal with a cost of x. A cell with a portal is also considered free. 



From any portal, Dima can go to any other portal, while the time of moving from the portal (i, j) to the portal (x, y) corresponds to the sum of their costs a_{ij} + a_{xy}.

In addition to moving between portals, Dima can also move between unoccupied cells adjacent to one side in time w. In particular, he can enter a cell with a portal and not use it.

Initially, Dima is in the upper-left cell (1, 1), and the school is in the lower right cell (n, m).

Input

The first line contains three integers n, m and w (2 ≤ n, m ≤ 2 ⋅ 10^3, 1 ≤ w ≤ 10^9), where n and m are city size, w is time during which Dima moves between unoccupied cells.

The next n lines each contain m numbers (-1 ≤ a_{ij} ≤ 10^9) — descriptions of cells.

It is guaranteed that the cells (1, 1) and (n, m) are free.

Output

Output the minimum time it will take for Dima to get to school. If he cannot get to school at all, then output "-1".

Example

Input


5 5 1
0 -1 0 1 -1
0 20 0 0 -1
-1 -1 -1 -1 -1
3 0 0 0 0
-1 0 0 0 0


Output


14

Note

Explanation for the first sample: 

<image>

### Response

```cpp
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int a[2000][2000];
int n,m;
LL w;
LL an;
bool out(int x ,int y){
    return x < 0 || y < 0 || x >= n || y >= m || a[x][y] == -1;
}
PII bfs[4000000];
int bn;
bool u[2000][2000];
int dis[2000][2000];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
LL go(int x1,int y1,int x2,int y2){
    bfs[0]=MP(x1,y1);
    dis[x1][y1]=0;
    MS0(u);
    u[x1][y1]=1;
    bn=1;
    LL ret=1e18;
    REP(i,bn){
        auto x=bfs[i];
        if(a[x.F][x.S])ret=min(ret,a[x.F][x.S]+dis[x.F][x.S]*w);
        if(x.F==x2&&x.S==y2){
            an=min(an,dis[x.F][x.S]*w);
            break;
        }
        REP(j,4){
            int nx=x.F+dx[j];
            int ny=x.S+dy[j];
            if(out(nx,ny)){continue;}
            if(u[nx][ny]){continue;}
            u[nx][ny]=1;
            dis[nx][ny]=dis[x.F][x.S]+1;
            bfs[bn++]=MP(nx,ny);
        }
    }
    return ret;
}
void solve() {
    an=1e18;
    LL v1 = go(0,0,n-1,m-1);
    LL v2 = go(n-1,m-1,0,0);
    an=min(an,v1+v2);
    if(an>1e17)W(-1);
    else W(an);
}
void input() {
    R(n,m,w);
    REP(i,n)REP(j,m){
        R(a[i][j]);
    }
}
int main(){
    input();
    solve();
    return 0;
}


```