#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
            cin >> Ar[i][j];

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e12);
            for (int j = M; j >= 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e12);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    for (int j = 1; j <= M; ++j)
        Max = max(Rez[N][j], Max);
    if (Max <= 0)
        Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            cin >> Ar[i][j];
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    if (N%2)
        for (int j = 3; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 2; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            scanf("%I64d",&Ar[i][j]);
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            long long Max = -(1e13);

            for (int j = M; j > 1; --j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
                Max = max(Max, Rez[i][j]);
                Rez[i][j] = Max;
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
                Max = max(Max, Rez[i][j]);
                Rez[i][j] = Max;
            }
        }

    }

    long long Max = -(1e13);
    if (N%2)
        for (int j = 2; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 1; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            cin >> Ar[i][j];

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    for (int j = 1; j <= M; ++j)
        Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            scanf("%I64d",Ar[i][j]);
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = -(1e13);
    if (N%2)
        for (int j = 2; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 1; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            cin >> Ar[i][j];

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    for (int j = 1; j <= M; ++j)
        Max = max(Rez[N][j], Max);
    if (Max <= 0)
        Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            scanf("%I64d",Ar[i][j]);
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = -(1e13);
    if (N%2)
        for (int j = 2; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 1; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}

[close]


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            cin >> Ar[i][j];
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = -(1e13);
    if (N%2)
        for (int j = 2; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 1; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            cin >> Ar[i][j];
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    for (int j = 1; j <= M; ++j)
        Max = max(Rez[N][j], Max);
    if (Max <= 0)
        Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= N; ++j)
            cin >> Ar[i][j];

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e12);
            for (int j = M; j >= 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e12);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = 0;
    for (int j = 1; j <= M; ++j)
        Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <utility>
#include <time.h>
using namespace std;

#define sz(v) ((int)v.size())
#define pb push_back
#define mp make_pair

inline void PrintIVect(vector <int>& V) {
    for (int i = 0; i < sz(V); ++i)
        cout << V[i] << " ";
    cout << endl;
}

long long Ar[1500+10][1500+10];
long long Rez[1500+10][1500+10];

int N,M;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> N >> M;
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            scanf("%I64d",&Ar[i][j]);
    for (int i = 1; i <= N; ++i)
        for (int j = 1; j <= M; ++j)
            Rez[i][j] = -(1e13);

    for (int i = 1; i <= N; ++i) {
        if (i%2) {//ci > ci-1
            long long Sum = Ar[i][1];
            for (int j = 2; j <= M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j-1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = M; j > 1; --j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }
        else {//ci < ci-1
            long long Sum = 0;
            for (int j = 1; j < M; ++j) {
                Sum += Ar[i][j];
                Rez[i][j] = Rez[i-1][j+1] + Sum;
            }
            long long Max = -(1e13);
            for (int j = 1; j < M; ++j) {
                Rez[i][j] = max(Rez[i][j], Max);
                Max = max(Max, Rez[i][j]);
            }
        }

    }

    long long Max = -(1e13);
    if (N%2)
        for (int j = 2; j <= M; ++j)
            Max = max(Rez[N][j], Max);
    else
        for (int j = 1; j < M; ++j)
            Max = max(Rez[N][j], Max);
    //if (Max <= 0)
    //    Max = 0;
    cout << Max;
    return 0;

}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        long long ma1 = -inf;
        long long *ma2 = new long long[m];
        ma2[m - 1] = b[i - 1][m - 1];
        for (long long j = m - 2; j >= 0; j--)
            ma2[j] = max(ma2[j + 1], b[i -1][j]);
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  if (j != m - 1)
                     b[i][j] = max(b[i][j], ma2[j + 1] + sum[i][j]);
            }
            else
            {
                if (j != 0)
                {
                      ma1 = max(ma1, b[i - 1][j - 1]);
                      b[i][j] = max(b[i][j], ma1 + sum[i][j]);
                }
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long inf = 999999999;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  for (long long q = j + 1; q < m; q++)
                      b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
            else
            {
                for (long long q = 0; q < j; q++)
                    b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
        }
    }
    long long ans = 0;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        long long ma1 = -inf;
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  for (long long q = j + 1; q < m; q++)
                      b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
            else
            {
                if (j != 0)
                {
                      ma1 = max(ma1, b[i - 1][j - 1]);
                      b[i][j] = max(b[i][j], ma1 + sum[i][j]);
                }
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
        {
            int temp;
            scanf("%d", &temp);
            a[i][j] = (long long)temp;
        }
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  for (long long q = j + 1; q < m; q++)
                      b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
            else
            {
                for (long long q = 0; q < j; q++)
                    b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long ans = 0;
    long long prev = 0;
    long long b[2000];
    for (long long i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
              long long cur = 0;
              for (long long j = 0; j <= prev; j++)
                  cur += a[i][j];
              b[prev] = cur;
              for (long long j = prev + 1; j < m; j++)
                  b[j] = b[j - 1] + a[i][j];
              long long ind = prev;
              for (long long j = prev + 1; j < m; j++)
                  if (b[j] >= b[ind])
                     ind = j;
              ans += b[ind];
              prev = ind;
        }
        else
        {
            long long cur = a[i][0];
            b[0] = cur;
            for (long long j = 1; j < prev; j++)
                b[j] = b[j - 1] + a[i][j];
            long long ind = 0;
            for (long long j = 1; j < prev; j++)
                if (b[j] > b[ind])
                   ind = j;
            ans += b[ind];
            prev = ind;
        }
    }
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int **a = new int*[n];
    for (int i = 0; i < n; i++)
    {
        a[i] = new int[m];
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    }
    int ans = 0;
    int prev = 0;
    int b[2000];
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
              int cur = 0;
              for (int j = 0; j <= prev; j++)
                  cur += a[i][j];
              b[prev] = cur;
              for (int j = prev + 1; j < m; j++)
                  b[j] = b[j - 1] + a[i][j];
              int ind = prev;
              for (int j = prev + 1; j < m; j++)
                  if (b[j] >= b[ind])
                     ind = j;
              ans += b[ind];
              prev = ind;
        }
        else
        {
            int cur = a[i][0];
            b[0] = cur;
            for (int j = 1; j < prev; j++)
                b[j] = b[j - 1] + a[i][j];
            int ind = 0;
            for (int j = 1; j < prev; j++)
                if (b[j] > b[ind])
                   ind = j;
            ans += b[ind];
            prev = ind;
        }
    }
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  for (long long q = j + 1; q < m; q++)
                      b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
            else
            {
                for (long long q = 0; q < j; q++)
                    b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
        {
            int temp;
            scanf("%d", &temp);
            a[i][j] = (long long)temp;
        }
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        long long ma1 = -inf;
        long long *ma2 = new long long[m];
        ma2[m - 1] = b[i - 1][m - 1];
        for (long long j = m - 2; j >= 0; j--)
            ma2[j] = max(ma2[j + 1], b[i -1][j]);
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  if (j != m - 1)
                     b[i][j] = max(b[i][j], ma2[j + 1] + sum[i][j]);
            }
            else
            {
                if (j != 0)
                {
                      ma1 = max(ma1, b[i - 1][j - 1]);
                      b[i][j] = max(b[i][j], ma1 + sum[i][j]);
                }
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  for (long long q = j + 1; q < m; q++)
                      b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
            else
            {
                for (long long q = 0; q < j; q++)
                    b[i][j] = max(b[i][j], b[i - 1][q] + sum[i][j]);
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    system("pause");
    return 0;
}


# include <iostream>
# include <string>
# include <vector>
# include <math.h>
# include <algorithm>
# include <string.h>
# include <stack>
# include <queue>
# include <sstream>
# include <set>
# include <map>
# include <stdio.h>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long **a = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        a[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            scanf("%lld", &a[i][j]);
    }
    long long inf = 999999999;
    inf *= inf;
    long long **b = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        b[i] = new long long[m];
        for (long long j = 0; j < m; j++)
             b[i][j] = -inf;
    }
    long long **sum = new long long*[n];
    for (long long i = 0; i < n; i++)
    {
        sum[i] = new long long[m];
        for (long long j = 0; j < m; j++)
            sum[i][j] = 0;
    }
    for (long long i = 0; i < n; i++)
        sum[i][0] = a[i][0];
    for (long long i = 0; i < n; i++)
        for (long long j = 1; j < m; j++)
            sum[i][j] = sum[i][j - 1] + a[i][j];
    b[0][0] = a[0][0];
    for (long long i = 1; i < m; i++)
        b[0][i] = b[0][i - 1] + a[0][i];
    for (long long i = 1; i < n; i++)
    {
        long long ma1 = -inf;
        long long *ma2 = new long long[m];
        ma2[m - 1] = b[i - 1][m - 1];
        for (long long j = m - 2; j >= 0; j--)
            ma2[j] = max(ma2[j + 1], b[i -1][j]);
        for (long long j = 0; j < m; j++)
        {
            if (i % 2 == 1)
            {
                  if (j != m - 1)
                     b[i][j] = max(b[i][j], ma2[j + 1] + sum[i][j]);
            }
            else
            {
                if (j != 0)
                {
                      ma1 = max(ma1, b[i - 1][j - 1]);
                      b[i][j] = max(b[i][j], ma1 + sum[i][j]);
                }
            }
        }
    }
    long long ans = -inf;
    for (long long i = 0; i < m; i++)
        ans = max(ans, b[n - 1][i]);
    cout << ans;
    //system("pause");
    return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
    if (nst == nen) {
        tree[ind] = arr[nst];
        return;
    }
    build(ind * 2 + 1, nst, (nst + nen) / 2);
    build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
    tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
    if (nst > qen || nen < qst)
        return -oo;
    if (nst >= qst && nen <= qen)
        return tree[ind];
    ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
    ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
    return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("a.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    //scanf("%d%d", &I, &J);
    cin>>I>>J;
    rep(i,I) rep(j,J) {
            //scanf("%d", &x);
            cin>>x;
            nums[i][j] = x;
        }
    arr[0] = nums[I - 1][0];
    rep2(i,1,J)
        arr[i] = arr[i - 1] + nums[I - 1][i];
    build(0, 0, J - 1);
    for (int i = I - 2; i >= 0; i--) {
        int st = 0, en = J - 1;
        if (i % 2) {
            arr[en] = -oo;
            en--;
        } else {
            arr[st] = -oo;
            st++;
        }
        ll acc = 0;
        if (st)
            acc = nums[i][0];
        for (int j = st; j <= en; j++) {
            acc += nums[i][j];
            if (i % 2)
                arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
            else
                arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
        }
        build(0, 0, J - 1);
    }
    ll mx = -oo;
    rep(i,J)
        mx = max(mx, arr[i]);
    cout << mx << endl;
    return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
	if (nst == nen) {
		tree[ind] = arr[nst];
		return;
	}
	build(ind * 2 + 1, nst, (nst + nen) / 2);
	build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
	tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
	if (nst > qen || nen < qst)
		return -oo;
	if (nst >= qst && nen <= qen)
		return tree[ind];
	ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
	ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
	return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.txt", "rt", stdin);
#endif
	scanf("%d%d", &I, &J);
	rep(i,I) rep(j,J) {
			scanf("%d", &x);
			nums[i][j] = x;
		}
	arr[0] = nums[I - 1][0];
	rep2(i,1,J)
		arr[i] = arr[i - 1] + nums[I - 1][i];
	build(0, 0, J - 1);
	for (int i = I - 2; i >= 0; i--) {
		int st = 0, en = J - 1;
		if (i % 2) {
			arr[en] = -oo;
			en--;
		} else {
			arr[st] = -oo;
			st++;
		}
		ll acc = 0;
		if (st)
			acc = nums[i][0];
		for (int j = st; j <= en; j++) {
			acc += nums[i][j];
			if (i % 2)
				arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
			else
				arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
		}
		build(0, 0, J - 1);
	}
	ll mx = -oo;
	rep(i,J)
		mx = max(mx, arr[i]);
	cout << mx << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

long long arr[1500][1500];
long long dp[1500][1500];
int X;
int Y;

int main()
{
    cin>>Y>>X;

    for(int n=0;n<Y;n++)
    {
        for(int m=0;m<X;m++)
        {
            cin>>arr[n][m];
        }
    }

    // do dp
    dp[Y-1][0]=arr[Y-1][0];

    for(int n=1;n<X;n++)
    {
        dp[Y-1][n]=dp[Y-1][n-1]+arr[Y-1][n];
    }

    for(int n=Y-2;n>=0;n--)
    {
        long long help[X];

        if(n%2==0)
        {
            help[0]=dp[n+1][0];

            for(int m=1;m<X-1;m++)
            {
                help[m]=max(help[m-1],dp[n+1][m]);
            }
            //greater
            dp[n][1]=arr[n][0]+arr[n][1]+help[0];

            for(int m=2;m<X;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m-2]+arr[n][m]+help[m-1];
            }
        }
        else
        {
            help[X-1]=dp[n+1][X-1];

            for(int m=X-2;m>0;m--)
            {
                help[m]=max(help[m+1],dp[n+1][m]);
            }

            dp[n][0]=arr[n][0]+help[1];

            for(int m=1;m<X-1;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m]+arr[n][m]+help[m+1];
            }
        }
    }

    long long res = dp[0][1];

    for(int n=2;n<X;n++)
    {
        res = max(res,dp[0][n]);
    }

    cout<<res<<endl;

}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
    if (nst == nen) {
        tree[ind] = arr[nst];
        return;
    }
    build(ind * 2 + 1, nst, (nst + nen) / 2);
    build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
    tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
    if (nst > qen || nen < qst)
        return -oo;
    if (nst >= qst && nen <= qen)
        return tree[ind];
    ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
    ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
    return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("a.txt", "rt", stdin);
#endif
    //ios_base::sync_with_stdio(false);
    scanf("%d%d", &I, &J);
    //cin>>I>>J;
    rep(i,I) rep(j,J) {
            scanf("%d", &x);
            //cin>>x;
            nums[i][j] = x;
        }
    arr[0] = nums[I - 1][0];
    rep2(i,1,J)
        arr[i] = arr[i - 1] + nums[I - 1][i];
    build(0, 0, J - 1);
    for (int i = I - 2; i >= 0; i--) {
        int st = 0, en = J - 1;
        if (i % 2) {
            arr[en] = -oo;
            en--;
        } else {
            arr[st] = -oo;
            st++;
        }
        ll acc = 0;
        if (st)
            acc = nums[i][0];
        for (int j = st; j <= en; j++) {
            acc += nums[i][j];
            if (i % 2)
                arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
            else
                arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
        }
        build(0, 0, J - 1);
    }
    ll mx = -oo;
    rep(i,J)
        mx = max(mx, arr[i]);
    cout << mx << endl;
    return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
    if (nst == nen) {
        tree[ind] = arr[nst];
        return;
    }
    build(ind * 2 + 1, nst, (nst + nen) / 2);
    build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
    tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
    if (nst > qen || nen < qst)
        return -oo;
    if (nst >= qst && nen <= qen)
        return tree[ind];
    ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
    ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
    return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("a.txt", "rt", stdin);
#endif
    //scanf("%d%d", &I, &J);
    cin>>I>>J;
    rep(i,I) rep(j,J) {
            //scanf("%d", &x);
            cin>>x;
            nums[i][j] = x;
        }
    arr[0] = nums[I - 1][0];
    rep2(i,1,J)
        arr[i] = arr[i - 1] + nums[I - 1][i];
    build(0, 0, J - 1);
    for (int i = I - 2; i >= 0; i--) {
        int st = 0, en = J - 1;
        if (i % 2) {
            arr[en] = -oo;
            en--;
        } else {
            arr[st] = -oo;
            st++;
        }
        ll acc = 0;
        if (st)
            acc = nums[i][0];
        for (int j = st; j <= en; j++) {
            acc += nums[i][j];
            if (i % 2)
                arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
            else
                arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
        }
        build(0, 0, J - 1);
    }
    ll mx = -oo;
    rep(i,J)
        mx = max(mx, arr[i]);
    cout << mx << endl;
    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

long long arr[1500][1500];
long long dp[1500][1500];
int X;
int Y;

int main()
{
    scanf("%d %d",&Y,&X);

    for(int n=0;n<Y;n++)
    {
        for(int m=0;m<X;m++)
        {
            scanf("%lld",&arr[n][m]);
        }
    }

    // do dp
    dp[Y-1][0]=arr[Y-1][0];

    for(int n=1;n<X;n++)
    {
        dp[Y-1][n]=dp[Y-1][n-1]+arr[Y-1][n];
    }

    for(int n=Y-2;n>=0;n--)
    {
        long long help[X];

        if(n%2==0)
        {
            help[0]=dp[n+1][0];

            for(int m=1;m<X-1;m++)
            {
                help[m]=max(help[m-1],dp[n+1][m]);
            }
            //greater
            dp[n][1]=arr[n][0]+arr[n][1]+help[0];

            for(int m=2;m<X;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m-2]+arr[n][m]+help[m-1];
            }
        }
        else
        {
            help[X-1]=dp[n+1][X-1];

            for(int m=X-2;m>0;m--)
            {
                help[m]=max(help[m+1],dp[n+1][m]);
            }

            dp[n][0]=arr[n][0]+help[1];

            for(int m=1;m<X-1;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m]+arr[n][m]+help[m+1];
            }
        }
    }

    long long res = dp[0][1];

    for(int n=2;n<X;n++)
    {
        res = max(res,dp[0][n]);
    }

    cout<<res<<endl;

}


#include <iostream>
#include <stdio.h>

using namespace std;

long long arr[1500][1500];
long long dp[1500][1500];
int X;
int Y;
int Z;

int main()
{
    scanf("%d%d",&Y,&X);

    for(int n=0;n<Y;n++)
    {
        for(int m=0;m<X;m++)
        {
            scanf("%d",&Z);
            arr[n][m]=Z;
        }
    }

    // do dp
    dp[Y-1][0]=arr[Y-1][0];

    for(int n=1;n<X;n++)
    {
        dp[Y-1][n]=dp[Y-1][n-1]+arr[Y-1][n];
    }

    for(int n=Y-2;n>=0;n--)
    {
        long long help[X];

        if(n%2==0)
        {
            help[0]=dp[n+1][0];

            for(int m=1;m<X-1;m++)
            {
                help[m]=max(help[m-1],dp[n+1][m]);
            }
            //greater
            dp[n][1]=arr[n][0]+arr[n][1]+help[0];

            for(int m=2;m<X;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m-2]+arr[n][m]+help[m-1];
            }
        }
        else
        {
            help[X-1]=dp[n+1][X-1];

            for(int m=X-2;m>0;m--)
            {
                help[m]=max(help[m+1],dp[n+1][m]);
            }

            dp[n][0]=arr[n][0]+help[1];

            for(int m=1;m<X-1;m++)
            {
                dp[n][m]=dp[n][m-1]-help[m]+arr[n][m]+help[m+1];
            }
        }
    }

    long long res = dp[0][1];

    for(int n=2;n<X;n++)
    {
        res = max(res,dp[0][n]);
    }

    cout<<res<<endl;

}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
    if (nst == nen) {
        tree[ind] = arr[nst];
        return;
    }
    build(ind * 2 + 1, nst, (nst + nen) / 2);
    build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
    tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
    if (nst > qen || nen < qst)
        return -oo;
    if (nst >= qst && nen <= qen)
        return tree[ind];
    ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
    ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
    return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("a.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    scanf("%d%d", &I, &J);
    //cin>>I>>J;
    rep(i,I) rep(j,J) {
            scanf("%d", &x);
            //cin>>x;
            nums[i][j] = x;
        }
    arr[0] = nums[I - 1][0];
    rep2(i,1,J)
        arr[i] = arr[i - 1] + nums[I - 1][i];
    build(0, 0, J - 1);
    for (int i = I - 2; i >= 0; i--) {
        int st = 0, en = J - 1;
        if (i % 2) {
            arr[en] = -oo;
            en--;
        } else {
            arr[st] = -oo;
            st++;
        }
        ll acc = 0;
        if (st)
            acc = nums[i][0];
        for (int j = st; j <= en; j++) {
            acc += nums[i][j];
            if (i % 2)
                arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
            else
                arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
        }
        build(0, 0, J - 1);
    }
    ll mx = -oo;
    rep(i,J)
        mx = max(mx, arr[i]);
    cout << mx << endl;
    return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const int oo = (int) 1e9;
const double PI = 2 * acos(0);
const double eps = 1e-9;

inline int comp(const double &a, const double &b) {
	if (fabs(a - b) < eps)
		return 0;
	return a > b ? 1 : -1;
}

int di[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dj[] = { 0, 0, 1, -1, 1, -1, -1, 1 };
int diK[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int djK[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

int I, J;

inline bool val(const int &i, const int &j) {
	if (i < 0 || j < 0 || i >= I || j >= J)
		return false;
	return true;
}

int N;
int n;

int main() {
    #ifndef ONLINE_JUDGE
    freopen("a.txt","rt",stdin);
    #endif
	return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>

using namespace std;

#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;

#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz size()
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define rep2(i,n,m) for(int i=n;i<(int)(m);i++)
#define For(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();++it)
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define dot(a,b) ((conj(a)*(b)).X)
#define X real()
#define Y imag()
#define length(V) (hypot((V).X,(V).Y))
#define vect(a,b) ((b)-(a))
#define cross(a,b) ((conj(a)*(b)).imag())
#define normalize(v) ((v)/length(v))
#define rotate(p,about,theta) ((p-about)*exp(point(0,theta))+about)
#define pointEqu(a,b) (comp(a.X,b.X)==0 && comp(a.Y,b.Y)==0)

typedef stringstream ss;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const ll oo = (ll) 1e18;
const double PI = 2 * acos(0);
const double eps = 1e-9;

int I, J, x;
ll nums[1500][1500];

ll arr[1500];
ll tree[1 << 12];

void build(int ind, int nst, int nen) {
    if (nst == nen) {
        tree[ind] = arr[nst];
        return;
    }
    build(ind * 2 + 1, nst, (nst + nen) / 2);
    build(ind * 2 + 2, (nst + nen) / 2 + 1, nen);
    tree[ind] = max(tree[ind * 2 + 1], tree[ind * 2 + 2]);
}

ll get(int ind, int nst, int nen, int qst, int qen) {
    if (nst > qen || nen < qst)
        return -oo;
    if (nst >= qst && nen <= qen)
        return tree[ind];
    ll r1 = get(ind * 2 + 1, nst, (nst + nen) / 2, qst, qen);
    ll r2 = get(ind * 2 + 2, (nst + nen) / 2 + 1, nen, qst, qen);
    return max(r1, r2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("a.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(true);
    //scanf("%d%d", &I, &J);
    cin>>I>>J;
    rep(i,I) rep(j,J) {
            //scanf("%d", &x);
            cin>>x;
            nums[i][j] = x;
        }
    arr[0] = nums[I - 1][0];
    rep2(i,1,J)
        arr[i] = arr[i - 1] + nums[I - 1][i];
    build(0, 0, J - 1);
    for (int i = I - 2; i >= 0; i--) {
        int st = 0, en = J - 1;
        if (i % 2) {
            arr[en] = -oo;
            en--;
        } else {
            arr[st] = -oo;
            st++;
        }
        ll acc = 0;
        if (st)
            acc = nums[i][0];
        for (int j = st; j <= en; j++) {
            acc += nums[i][j];
            if (i % 2)
                arr[j] = acc + get(0, 0, J - 1, j + 1, J - 1);
            else
                arr[j] = acc + get(0, 0, J - 1, 0, j - 1);
        }
        build(0, 0, J - 1);
    }
    ll mx = -oo;
    rep(i,J)
        mx = max(mx, arr[i]);
    cout << mx << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p);	}

long long M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						scanf("%lld",A+i);
						A[i] += A[i-1];
				}
				if(h)
						for(t=M[i=n]; --i ;)  D
				else
						for(t=M[i=1]; ++i<=n;) D
		}

		cout << t;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p); }

long long M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						scanf("%lld",A+i);
						A[i] += A[i-1];
				}
				t = -100000000011LL;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p);	}

int M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						cin >> A[i];
						A[i] += A[i-1];
				}
				t = -10004;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
		return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p); }

int M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						scanf("%d",A+i);
						A[i] += A[i-1];
				}
				t = -100005;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p);	}

int M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						cin >> A[i];
						A[i] += A[i-1];
				}
				t = -10004;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p);	}

long long M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						scanf("%d",A+i);
						A[i] += A[i-1];
				}
				t = -100000000011LL;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
}


#include<bits/stdc++.h>

using namespace std;

#define D { p = M[i];  M[i] = t + A[i];  t = max(t , p);	}

int M[1502],A[1502],m,n,i,t,p,h;

int main(){

		cin >> m >> n;

		for(m++;m--;h=!h){
				for(i=1;i<=n;i++){
						scanf("%d",A+i);
						A[i] += A[i-1];
				}
				t = -10004;
				if(h)
						for(i=n; i ;i--)  D
				else
						for(i=1;i<=n;i++) D
		}

		cout << t;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <numeric>
#include <memory>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <functional>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <bitset>

#define X first
#define Y second
#define MAX(x, y) x = x > (y) ? x : (y)
#define MIN(x, y) x = x > (y) ? (y) : x
#define LOW(x) ((x) & -(x))
#define SQR(x) ((x) * (x))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rFOR(i, b, a) for (int i = (b); i > (a); --i)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x, p) memset(x, p, sizeof(x))
#define COPY(x, y) memcpy(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<string> VS;

const int INF = 0x3fffffff;
const ll _INF = 0x7ffffffffffffffll;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template<class T, class INT>
inline T pow(T x, INT y)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res *= tt;
		tt *= tt;
	}
	return res;
}

template<class T, class INT>
inline T pow(T x, INT y, T p)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res = res * tt % p;
		tt = tt * tt % p;
	}
	return res;
}

int toInt(string s)
{
	int x = 0;
	istringstream sin(s);
	sin >> x;
	return x;
}

template<class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

template<class INT>
inline INT gcd(INT x, INT y)
{
	return y ? gcd(y, x % y) : x;
}

template<class INT>
inline int calc_bits(INT x)
{
	return x ? (x & 1) + calc_bits(x >> 1) : 0;
}

const int MAXN = 1500 + 10;

int a[MAXN], f[MAXN], n, m, p, tmp;

inline void opt(int x)
{
	tmp = f[x], f[x] = p + a[x], MAX(p, tmp);
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &n, &m);
	REP(i, n)
	{
		REP(j, m) scanf("%d", a + j);
		partial_sum(a, a + m, a);
		p = -INF;
		if (i & 1)
			rFOR(j, m - 1, -1) opt(j);
		else
			REP(j, m) opt(j);
	}
	cout << *max_element(f, f + m) << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <numeric>
#include <memory>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <functional>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <bitset>

#define X first
#define Y second
#define MAX(x, y) x = x > (y) ? x : (y)
#define MIN(x, y) x = x > (y) ? (y) : x
#define LOW(x) ((x) & -(x))
#define SQR(x) ((x) * (x))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rFOR(i, b, a) for (int i = (b); i > (a); --i)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x, p) memset(x, p, sizeof(x))
#define COPY(x, y) memcpy(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<string> VS;

const int INF = 0x3fffffff;
const ll _INF = 0x7ffffffffffffffll;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template<class T, class INT>
inline T pow(T x, INT y)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res *= tt;
		tt *= tt;
	}
	return res;
}

template<class T, class INT>
inline T pow(T x, INT y, T p)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res = res * tt % p;
		tt = tt * tt % p;
	}
	return res;
}

int toInt(string s)
{
	int x = 0;
	istringstream sin(s);
	sin >> x;
	return x;
}

template<class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

template<class INT>
inline INT gcd(INT x, INT y)
{
	return y ? gcd(y, x % y) : x;
}

template<class INT>
inline int calc_bits(INT x)
{
	return x ? (x & 1) + calc_bits(x >> 1) : 0;
}

const int MAXN = 1500 + 10;

int a[MAXN], n, m;
ll f[MAXN], tmp, p;

inline void opt(int x)
{
	tmp = f[x], f[x] = p + a[x], MAX(p, tmp);
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &n, &m);
	REP(i, n)
	{
		REP(j, m) scanf("%d", a + j);
		partial_sum(a, a + m, a);
		p = -_INF;
		if (i & 1)
			rFOR(j, m - 1, -1) opt(j);
		else
			REP(j, m) opt(j);
	}
	cout << *max_element(f, f + m) << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <numeric>
#include <memory>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <functional>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <bitset>

#define X first
#define Y second
#define MAX(x, y) x = x > (y) ? x : (y)
#define MIN(x, y) x = x > (y) ? (y) : x
#define LOW(x) ((x) & -(x))
#define SQR(x) ((x) * (x))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rFOR(i, b, a) for (int i = (b); i > (a); --i)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x, p) memset(x, p, sizeof(x))
#define COPY(x, y) memcpy(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<string> VS;

const int INF = 0x7fffffff;
const ll _INF = 0x7ffffffffffffffll;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template<class T, class INT>
inline T pow(T x, INT y)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res *= tt;
		tt *= tt;
	}
	return res;
}

template<class T, class INT>
inline T pow(T x, INT y, T p)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res = res * tt % p;
		tt = tt * tt % p;
	}
	return res;
}

int toInt(string s)
{
	int x = 0;
	istringstream sin(s);
	sin >> x;
	return x;
}

template<class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

template<class INT>
inline INT gcd(INT x, INT y)
{
	return y ? gcd(y, x % y) : x;
}

template<class INT>
inline int calc_bits(INT x)
{
	return x ? (x & 1) + calc_bits(x >> 1) : 0;
}

const int MAXN = 1500 + 10;

int a[MAXN], f[MAXN], n, m, p, tmp;

inline void opt(int x)
{
	tmp = f[x], f[x] = p + a[x], MAX(p, tmp);
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &n, &m);
	REP(i, n)
	{
		REP(j, m) scanf("%d", a + j);
		partial_sum(a, a + m, a);
		p = -INF;
		if (i & 1)
			rFOR(j, m - 1, -1) opt(j);
		else
			REP(j, m) opt(j);
	}
	cout << *max_element(f, f + m) << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <numeric>
#include <memory>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <functional>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <bitset>

#define X first
#define Y second
#define MAX(x, y) x = x > (y) ? x : (y)
#define MIN(x, y) x = x > (y) ? (y) : x
#define LOW(x) ((x) & -(x))
#define SQR(x) ((x) * (x))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rFOR(i, b, a) for (int i = (b); i > (a); --i)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x, p) memset(x, p, sizeof(x))
#define COPY(x, y) memcpy(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<string> VS;

const int INF = 0x3fffffff;
const ll _INF = 0x7ffffffffffffffll;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template<class T, class INT>
inline T pow(T x, INT y)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res *= tt;
		tt *= tt;
	}
	return res;
}

template<class T, class INT>
inline T pow(T x, INT y, T p)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res = res * tt % p;
		tt = tt * tt % p;
	}
	return res;
}

int toInt(string s)
{
	int x = 0;
	istringstream sin(s);
	sin >> x;
	return x;
}

template<class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

template<class INT>
inline INT gcd(INT x, INT y)
{
	return y ? gcd(y, x % y) : x;
}

template<class INT>
inline int calc_bits(INT x)
{
	return x ? (x & 1) + calc_bits(x >> 1) : 0;
}

const int MAXN = 1500 + 10;

int a[MAXN][MAXN], f[MAXN], b[MAXN], n, m, p, tmp;

inline void opt(int x)
{
	tmp = f[x], f[x] = p + b[x], MAX(p, tmp);
}

int main(int argc, char* argv[])
{
	cin >> n >> m;
	REP(i, n)
		REP(j, m) cin >> a[i][j];
	REP(i, n)
	{
		partial_sum(a[i], a[i] + m, b);
		p = -INF;
		if (i & 1)
			rFOR(j, m - 1, -1) opt(j);
		else
			REP(j, m) opt(j);
	}
	cout << *max_element(f, f + m) << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <numeric>
#include <memory>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <functional>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <bitset>

#define X first
#define Y second
#define MAX(x, y) x = x > (y) ? x : (y)
#define MIN(x, y) x = x > (y) ? (y) : x
#define LOW(x) ((x) & -(x))
#define SQR(x) ((x) * (x))
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rFOR(i, b, a) for (int i = (b); i > (a); --i)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x, p) memset(x, p, sizeof(x))
#define COPY(x, y) memcpy(x, y, sizeof(x))
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<string> VS;

const int INF = 0x3fffffff;
const ll _INF = 0x7ffffffffffffffll;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template<class T, class INT>
inline T pow(T x, INT y)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res *= tt;
		tt *= tt;
	}
	return res;
}

template<class T, class INT>
inline T pow(T x, INT y, T p)
{
	T res(1);
	for (T tt(x); y; y /= 2)
	{
		if (y & 1) res = res * tt % p;
		tt = tt * tt % p;
	}
	return res;
}

int toInt(string s)
{
	int x = 0;
	istringstream sin(s);
	sin >> x;
	return x;
}

template<class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

template<class INT>
inline INT gcd(INT x, INT y)
{
	return y ? gcd(y, x % y) : x;
}

template<class INT>
inline int calc_bits(INT x)
{
	return x ? (x & 1) + calc_bits(x >> 1) : 0;
}

const int MAXN = 1500 + 10;

int a[MAXN], f[MAXN], n, m, p, tmp;

inline void opt(int x)
{
	tmp = f[x], f[x] = p + a[x], MAX(p, tmp);
}

int main(int argc, char* argv[])
{
	cin >> n >> m;
	REP(i, n)
	{
		REP(j, m) cin >> a[j];
		partial_sum(a, a + m, a);
		p = -INF;
		if (i & 1)
			rFOR(j, m - 1, -1) opt(j);
		else
			REP(j, m) opt(j);
	}
	cout << *max_element(f, f + m) << endl;
}


#include <iostream>

long long int a[1500][1500];
//long long int b[1500][1500];

using namespace std;

int main()
{
    int n,m;

    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    //b[n-1][0]=a[n-1][0];
    for(int i=1;i<m;i++)
        a[n-1][i]=a[n-1][i-1]+a[n-1][i];
    bool sign=n%2;
    const long long int bad=-1000000000000;
    for(int i=n-2;i>=0;i--)
    {
    int base=0;
    for(int j=0;j<m;j++)
    {
        base+=a[i][j];
        int start,end;
        a[i][j]=bad;

        if(sign)
        {
            start=j+1;
            end=m;
        }
        else
        {
            start=0;
            end=j;
        }
        for(int k=start;k<end;k++)
            if(a[i+1][k]+base>a[i][j])a[i][j]=a[i+1][k]+base;

    }
    sign=!sign;
    }
    long long int max=a[0][0];
    for(int i=0;i<m;i++)
        if(a[0][i]>max)max=a[0][i];
    cout<<max;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long n;
    long long l;
    cin>>n>>l;
    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    long long a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }

    /*for(int i=0;i<n-1;i++) {
        for(int j=0;j<n-i-1;j++) {
            if(a[j] > a[j+1]) {
                long long temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }*/

    sort(a,a+n);

    /*for(int i=0;i<n;i++)
        cout<<a[i]<<endl;*/

    float max1 = a[0];
    //float max2 = 0;
    for(int i=1;i<n;i++) {
        if(a[i]-a[i-1] > max1) {
            max1 = (float)abs(a[i] - a[i-1]);
            //cout<<"here2\t"<<a[i]<<"\t"<<a[i-1]<<"\n"<<max1<<"\n";
        }
    }

    if(l-a[n-1] > max1){
        //cout<<"here1\n";
        max1 = l - a[n-1];
    }

    float ans1 = (float)max1/(float)2;

  //cout<<max1;
    cout<<ans1;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>l>>n;
    int l_arr[l];
    for(int i=0; i<l; i++){
        cin>>l_arr[i];
    }
    sort(l_arr,l_arr+l);
    float max_diff = (float)l_arr[0];

    for(int i=1; i<l-1; i++){
        if((abs(l_arr[i]-l_arr[i+1]))/2 > max_diff){
            max_diff = (float)abs(l_arr[i]-l_arr[i+1])/2;
        }
    }

    if(abs(l_arr[l-1]-n) > max_diff){
        max_diff = (float)abs(l_arr[l-1]-n);
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    cout<<max_diff;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long n;
    long long l;
    cin>>n>>l;
    long long a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }

    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    sort(a,a+n);

    /*for(int i=0;i<n;i++)
        cout<<a[i]<<endl;*/

    float max1 = a[0];
    float max2 = 0;
    for(int i=1;i<n;i++) {
        if(a[i]-a[i-1] > max2) {
            max2 = a[i] - a[i-1];
        }
    }
    if(l-a[n-1] > max1){
        max1 = l - a[n-1];
    }
    float ans1 = max1;
    float ans2 = max2/2;
    if(ans1 > ans2)
        cout<<ans1;
    else
        cout<<ans2;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>l>>n;
    int l_arr[l];
    for(int i=0; i<l; i++){
        cin>>l_arr[i];
    }
    sort(l_arr,l_arr+l);
    float max_diff = (float)l_arr[0];

    for(int i=0; i<l-1; i++){
        if((float)(abs(l_arr[i]-l_arr[i+1]))/(float)2 > max_diff){
            max_diff = (float)abs(l_arr[i]-l_arr[i+1])/(float)2;
        }
    }

    if(abs(l_arr[l-1]-n) > max_diff){
        max_diff = (float)abs(l_arr[l-1]-n);
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    cout<<max_diff;
}


#include <iostream>
using namespace std;

int main()
{
    long long n;
    long long l;
    cin>>n>>l;
    long long a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }

    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    for(int i=0;i<n-1;i++) {
        for(int j=0;j<n-i-1;j++) {
            if(a[j] > a[j+1]) {
                long long temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }

    /*for(int i=0;i<n;i++)
        cout<<a[i]<<endl;*/

    float max1 = a[0];
    float max2 = 0;
    for(int i=1;i<n-1;i++) {
        if(a[i]-a[i-1] > max2) {
            max2 = a[i] - a[i-1];
        }
    }
    if(l-a[n-1] > max1){
        max1 = l - a[n-1];
    }
    float ans1 = max1;
    float ans2 = max2/2;
    if(ans1 > ans2)
        cout<<ans1;
    else
        cout<<ans2;
}


#include <iostream>
using namespace std;

int main()
{
    long long n;
    long long l;
    cin>>n>>l;
    long long a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }

    for(int i=0;i<n-1;i++) {
        for(int j=0;j<n-i-1;j++) {
            if(a[j] > a[j+1]) {
                long long temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }

    /*for(int i=0;i<n;i++)
        cout<<a[i]<<endl;*/

    float max1 = a[0];
    float max2 = 0;
    for(int i=1;i<n-1;i++) {
        if(a[i]-a[i-1] > max2) {
            max2 = a[i] - a[i-1];
        }
    }
    if(l-a[n-1] > max1){
        max1 = l - a[n-1];
    }
    float ans1 = max1;
    float ans2 = max2/2;
    if(ans1 > ans2)
        cout<<ans1;
    else
        cout<<ans2;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,l;
    cin>>l>>n;
    int l_arr[l];
    for(int i=0; i<l; i++){
        cin>>l_arr[i];
    }
    sort(l_arr,l_arr+l);
    float max_diff = (float)l_arr[0];

    for(int i=0; i<l-1; i++){
        if((float)(abs(l_arr[i]-l_arr[i+1]))/(float)2 > max_diff){
            max_diff = (float)abs(l_arr[i]-l_arr[i+1])/(float)2;
        }
    }

    if(abs(l_arr[l-1]-n) > max_diff){
        max_diff = (float)abs(l_arr[l-1]-n);
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    cout<<max_diff;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>l>>n;
    int l_arr[l];
    for(int i=0; i<l; i++){
        cin>>l_arr[i];
    }
    sort(l_arr,l_arr+l);
    float max_diff = (float)l_arr[0];

    for(int i=1; i<l-1; i++){
        if((float)(abs(l_arr[i]-l_arr[i+1]))/(float)2 > max_diff){
            max_diff = (float)abs(l_arr[i]-l_arr[i+1])/(float)2;
        }
    }

    if(abs(l_arr[l-1]-n) > max_diff){
        max_diff = (float)abs(l_arr[l-1]-n);
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    cout<<max_diff;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>l>>n;
    int l_arr[l];
    for(int i=0; i<l; i++){
        cin>>l_arr[i];
    }
    sort(l_arr,l_arr+l);
    float max_diff = (float)l_arr[0];

    for(int i=0; i<l-1; i++){
        if((float)(abs(l_arr[i]-l_arr[i+1]))/(float)2 > max_diff){
            max_diff = (float)abs(l_arr[i]-l_arr[i+1])/(float)2;
            //cout<<"here..\t"<<l_arr[i]<<"\t"<<l_arr[i+1]<<"\n";
        }
    }

    if(abs(l_arr[l-1]-n) > max_diff){
        max_diff = (float)abs(l_arr[l-1]-n);
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(10);

    cout<<max_diff;
}


#include<stdio.h>
#define N 1000
 int main()
(
 double b;
 int a,k;
 int i,temp;
 int d[N],j;
 printf("�������ܳ��Ⱥ͵Ƶ�����\n");
 scanf("%d%lf",&a��&b);
 printf("\n");
 for(i=0;i<N,i++)
 scanf("%d",&d[N]);
 for(i=0;i<=N-1;i++)
 for(j=N-1;j>=i;j--)
  if(d[N]<d[N-1])
  {
     temp=d[N];
     d[N]=d[N-1];
     d[N-1]=temp;
    }
b=d[1]-d[0];
 for(i=2;i<N,i++)
  if(d[i]-d[i-1]>b)
   b=d[i]-d[i-1];
printf("%lf",(doubule)b/a);
return 0;
}


#include<stdio.h>
int main()
{
	int a[1000],b[1000];
	int l,n;
	double d;
	scanf("%d\n",&l);
	scanf("%d",&n);
	d=l/(2*n);
	printf("%lf",d);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
 int main()
 {
	 int l,n;
	 scanf("%d""%d",&l,&n);
	 int a[1010];
	 int i;
	 for(i=0;i<n;i++)

	 {
		 scanf("%d",&a[i]);

	 }
	 for(double d=a[0];d<=n;d++)

	 {
		 int sum;
		 for(i=0;i<n;i++)

		 {
			 sum+=a[i];

		 }
		 double t;
		 t=double power(10 (-9));

		 if(sum*d-l<=t)

		 {
			 printf("%f",d);
				 break;

		 }
		 return 0;
	 }


#include<stdio.h>
#include <string.h>
int main()
{
	double l,d,n,c;
	long int i,a[n],b[n],j,k;
	do{
		puts("������Ƶ�����n�ܳ���l,:");
		scanf("%lf%lf",&n,&l);
		printf("\n");
		puts("������·��λ�ã�");

		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}

	}while((l<1)||(l>1000000000)||(n<1)||(n>1000));

	for(i=1;b[0]=a[0];i<=n-1,i++)
		{
			b[i]=a[i]-a[i-1];
		}

	for(i=0,c=b[0];i<=n;i++)
	{
		if(c<b[i])
		c=b[i];
	}
	if(c<l-b[i])
	c=l-b[i];
	printf("%lf",c);
	return 0;
 }


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
double lamp[1010];
int main()
{
	//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
	double length;
	int n;
	cin>>length>>n;
	for(int i=1;i<=n;i++)
	cin>>lamp[i];
	sort(lamp+1,lamp+n+1);
	double maxlen=-1;
	for(int i=2;i<=n;i++)
	{
		if(lamp[i]-lamp[i-1]>maxlen)
		maxlen=lamp[i]-lamp[i-1];
	}
	double ans=maxlen/2;
	if(ans<lamp[1])
	ans=lamp[1];
	if(ans<(length-lamp[n]))
	ans=length-lamp[n];
	printf("%.9lf",ans);
	return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
	double l,n;
	double d;
	scanf("%lf%lf",&l,&n);
	if(10<=l<=1000000000&&1<=n<=1000)
		d=l/(n-1)/2*10;
	printf("%.9lf",d);
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	int l,n,x,y;
	scanf("%d%d",&n,&l);
	int a[1005]={0},b[1005]={0};
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		b[i]=a[i]-a[i-1];
	}
	double max=l-a[n];
	for (int i=1;i<=n;i++)
	{
		if (max<b[i]) max=b[i];
	}
	if (max==a[1]-0 && a[1]!=0)
		printf("%.10f",max);
	else if(max==l-a[n])
		printf("%.10f",max);
	else
		printf("%.10f",max/2);
	return 0;
}


//û�������е�š���
//��������Ƕ�ά��Ӧ��ͦ�򵥵İɣ��������Լ�������Ȼ����sort��

#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <stack>

using namespace std;

long long l,n;
long long location[1001];
long long dif[1002];
long long beg,en;
long long maxn;

int main()
{
	cin>>l>>n;
	n--;
	for(int i=0;i<=n;i++)
	{
		cin>>location[i];
	}
	for(int i=1;i<n;i++)
	{
		dif[i]=(location[i+1]-location[i])/2;
	}
	beg=location[0];
	en=l-location[n];
	maxn=max(beg,en);
	for(int i=1;i<n;i++)
	{
		maxn=max(maxn,dif[i]);
	}
	cout<<maxn;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
int main()
{
	int n,l;
	scanf("%d%d",&n,&l);
	for(int i=0;i<n;i++)
		scanf("%d",a[i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<n-1;j++)
			if(a[j]>a[j+1])
			{
				int k=a[i];
				a[i]=a[j];
				a[j]=k;
			}
			double max= (a[0]>l-a[n-1])?a[0]:l-a[n-1];
			for(int i=1;i<n;i++)
				max=(max>a[i]-a[i-1])?max:a[i]-a[i-1];
	printf("%lf",max);
	return 0;
}


#include <stdio.h>
#include<stdlib.h>
int main()
{
	int i,j,k,l,h;
	double n,m=0,temp,max,s;
	double d[100];
	scanf("%d%d",&i,&j);
	for(k=0;k<i;k++)
	{
		scanf("%lf",&d[k]);
	}
	for(h=0;h<i;h++)
	{
		for(k=0;k<i;k++)
		{
			for(l=k;l<i;l++)
			{
				if(d[k]>d[l])
				{
					temp=d[l];
					d[l]=d[k];
					d[k]=temp;
				}
			}
		}
	}
	max=0;
	for(k=0;k<i-1;k++)
	{
		temp=d[k+1]-d[k];
		if(max<temp)
			max=temp;
	}
	if(max/2<d[0]||max/2<(j-d[i-1]))
		if(d[0]<(j-d[i-1]))
			s=j-d[i-1];
		else
			s=d[0];
	else
		s=max/2;
	printf("%f",s);
	system("pause");
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int l,n,i,x;
	double d;
	int max=0,flag=1;
	int t;
	int a[1005];
	scanf("%d%d",&l,&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++){
		t=a[i+1]-a[i];
		if(t>max){
			max=t;
		}
	}
	x=a[0];
	if(l-a[n-1]>x){
		x=l-a[n-1];
	}
	if(x*2>max){
		flag=0;
	}
	if(flag){
		d=max/2.0;
	}else{
		d=x;
	}
	printf("%.10f\n",d);
	return 0;
}


#include<stdio.h>//�Ƚ���յ��֮�䳤�ȣ��ٳ���2���յ㣬������⿼�ǣ�
int main()
{
	int length,num,i,temp=0;
	double r;
	int *position;
	scanf("%d%d",&length,&num);
	position=calloc(num,sizeof(int));
	for(i=0;i<num ;i++)
	{
		scanf("%d",&position[i]);
	}
	for(i=0;i<num-1;i++)
	{
		temp-=position[i+1]-position[i];
		if (temp<0)
		{
			r = (position[i+1]-position[i])/2.0;
		}

	}

	r= position[0]>r?position[0]:r;
	r= (length-position[num - 1])>r?(length-position[num-1]):r;
	printf("%f",r);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 1005
double a[MAX];
int x,y,z,n,sum,ans,cnt;
double m;

int main()
{
	cin>>m>>n;
	for(int i=1;i<=n;i++)
		scanf("%lf",&a[i]);
	sort(a+1,a+n+1);
	double max=a[1];
	for(int i=2;i<=n;i++)
		if(max<a[i]-a[i-1])
			max=a[i]-a[i-1];
	if(max<m-a[n]) max=m-a[n];
	printf("%.10lf",max/2);
	return 0;
}


#include <stdio.h>
#define MAX_AM 50

void sort(int *a, int n);
void print(int *a, int n)
{
	int i;
	for(i = 0; i < n; i++)
		printf("%d ", a[i]);
}

int main()
{
	int len, amount, i;
	int x[MAX_AM] = {0}, dist[MAX_AM] = {0};
	scanf("%d%d%*c", &len, &amount);
	for(i = 0; i < amount; i++)
		scanf("%d%*c", &x[i]);
	x[amount] = 0;
	x[amount+1] = len;
	amount += 2;
	sort(x, amount);
	for(i = 0; i < amount-1; i++)
		dist[i] = x[i]-x[i+1];
	sort(dist, amount-1);
	printf("%g", dist[0]/2.0);
	return 0;
}

//�ɴ�С
void sort(int *a, int n)
{
	int i, j, temp;
	for(i = n-1; i > 0; i--)
	{
		j = n-1;
		while(j > 0)
		{
			if(a[j] > a[j-1])
			{
				temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
			}
			j--;
		}
	}
}


#include<stdio.h>
#include<math.h>
/*�ȹ�������������飬Ȼ����������������Ĳ�������ó����Ĳ����2���ɵ���С�뾶��mdд����������Ҫ�Ǵ��˾ʹ��˷�����̬�ѱ�*/
int main()
{
	int n,a,b,h,j;
	scanf("%d%d",&n,&h);
	int arr[n],brr[n-1];
	for(a=0;a<n;a++)
	{
		scanf("%d",&arr[a]);
	}
	for(j=0;j<n;j++)
	{
		for(a=0;a<n;a++)
		{
			if(arr[a]>arr[a+1])
			{
				b=arr[a];
				arr[a]=arr[a+1];
				arr[a+1]=b;
			}
		}
	}
	for(a=0;a<n-1;a++)
	{
		brr[a]=abs(arr[a]-arr[a+1]);
	}
	for(a=0;a<n-1;a++)
	{
		if(brr[a]>brr[a+1])
		{
			b=brr[a];
			brr[a]=brr[a+1];
			brr[a+1]=b;
		}
	}
	printf("%d",(1.0*brr[n-2])/2);
}


#include <stdio.h>
int main()
{
	int n,length;
	double min;
	int array0[n];
	int array1[n+1];//���ֵ
	int i;
	scanf("%d",&n);
	scanf("%d",&length);

	for(i=0;i<n;i++)
	{
		scanf("%d",&array0[i]);

	}
	//��ʼ��������
	for(i=0;i<n;i++)
	{
		int j;
		int temp;

		for(j=i+1;j<n;j++)
		{
			if(array0[i]>array0[j])
			{
				temp=array0[i];
				array0[i]=array0[j];
				array0[j]=temp;
			}
		}
	 }
	 //��ֵ��Ϊ�ڶ��������ֵ
	for(i=0;i<n+1;i++)
	{
		if(i==0)
		{
			array1[i]=array0[0];
		}
		else
		{
			array1[i]=array0[i]-array0[i-1];
		}
	}
	array1[n]=length-array0[n-1];
	//�ֿ�ʼ������
	for(i=0;i<n+1;i++)
	{
		int j;
		int temp;

		for(j=i+1;j<n+1;j++)
		{
			if(array1[i]>array1[j])
			{
				temp=array1[i];
				array1[i]=array1[j];
				array1[j]=temp;
			}
		}
	 }
	 //�õ�������һ������
	 min=array1[n]/2;
	 printf ("%lf",min);
}


#include <stdio.h>
void bsort(double a[],int n);
double maxnum(double a[],int n);
int main()
{
	int l,n,i;
	double a[1001],b[1002],res;
	scanf("%d %d",&l,&n);
	for(i=0;i<n;i++)
		scanf("%lf",&a[i]);
	bsort(a,n);
	b[0]=a[0];
	b[1]=l-a[n-1];
	for(i=0;i<n-1;i++)
		b[i+2]=a[i+1]-a[i];
	res=maxnum(b,n+1)/2;
	printf("%lf",res);
	return 0;

}
void bsort(double a[],int n)
{
	int i,j;
	for(i=0;i<n-1;i++)
		for(j=n-1;j>i;j--)
		{
			if(a[j]<a[j-1])
			{
				double temp;
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
			}

		}
}
double maxnum(double a[],int n)
{
	int i;
	double max=a[0];
	for(i=1;i<n;i++)
		if(a[i]>max)
			max=a[i];
	return max;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	long long l =0,a[1010],max= 0,temp;
	int n = 0,i,j;
	double d;
	scanf("%I64d %d",&l,&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i]>a[j])
			{
				temp = a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	temp = 0;
	for(i=0;i<n-1;i++)
	{
		temp = a[i+1]-a[i];
		if(temp>max)
			max=temp;
	}
	d=(double)max/2.0;
	printf(".10f",d);
	return 0;
}


#include <stdio.h>
int main()
{
int l,n,i=0;
double d;
char zp[n];
scanf("%d%d",&l,&n);
while(i<=n-1)
{
zp[i]=l/(n-1);
i++;
}
d=l/(2*(n-1));
printf("%lf",d);
return 0 ;
}


#include<stdio.h>

int main()
{

 int m,i,l,n;
double d;
int array[100];//��ʾ·��λ��
int brray[100];//��ʾ�����ÿ���Ƽ��

scanf("%d %d\n",&l,&n);

for(i=0;i<n;i++)
  {
   scanf("%d",&array[i]);//����������·��λ��
  }

for(n=n;n<=2;n--)
{
for(i=0;i<n-1;i++)
{
 if(array[i]>=array[i+1])
  {
   m=array[i];
   array[i]=array[i+1];
   array[i+1]=m;
  }
}
}                                 //��С��������

for(i=0;i<n-1;i++)
{
 brray[i]=array[i+1]-array[i];
}

for(n=n;n<=2;n--)
{
 for(i=0;i<n-1;i++)
 {
  for(i=0;i<n-1;i++)
  if(array[i]>=array[i+1])
   {
     m=array[i];
     array[i]=array[i+1];
     array[i+1]=m;
   }
 }
}                                   //��·�Ƽ����С��������

d=(array[n-2]-array[0])/2;
printf("%lf",&d);
return 0;
}


#include <stdio.h>
int main(){
	int l , i ,n , a[1000]={0},min=a[0],max=a[0],dif[1000];
	double d;
	scanf("%d %d",&l,&n);
	for(i=0;i<n;i++)
		scanf("%d",a[i]);
	for(i=0;i<n-1;i++)
		if(a[i+1]>a[i])
			max=a[i+1];
	for(i=0;i<n-1;i++)
		if(a[i+1]<a[i])
			min=a[i+1];
	if(max>=min)
		d=n-max;
	else
		d=min;
	for(i=0;i<n-1;i++)
		dif[i]=a[i+1]-a[i];
	for(i=0;i<n-1;i++)
		if(dif[i+1]>dif[i])
			max=dif[i+1];
	if(d>max)
		printf("%f",d);
	else
		printf("%f",max);
	return 0;
}


#include<stdio.h>
#define N 1000
int main()
{
	int i,j,k=0,l,n;
	double a[N];
	double d;
	scanf("%d%d",&n,&l);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(d=l/n;d<l/n+n;d+=0.1)
	{
		for(i=0;i<n;i++)
		{
			k=0;
			for(j=0;j<n;j++)
			{
				if(a[i]-a[j]<0-(-9E)||a[i]-a[j]>-9E)
				{
					k=0;
					break;
				}
				else
					k=1;
			}
			if(k=1)
				continue;
			else
				break;
		}
		if(i=n)
		{
			printf("%lf",d);
			break;
		}
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

static int a[1000];
double max=0,l=0;
int n=0,m=0;

void paixu()
{
    int i,j,t;
    for(i=0;i<n;i++)
    {
        for (j=i+1;j<n;j++)
        {
            if (a[i]>a[j]) {t=a[i];a[i]=a[j];a[j]=t;}
        }
    }
}

void bidaxiao()
{
    int i;
    if ((a[0])>(l-a[n-1])) max=a[0];
        else max=l-a[n-1];
    for (i=1;i<n;i++)
    {
        if (a[i]-a[i-1]>max) {max=a[i]-a[i-1];m=i-1;}
//    printf("%lf\n",max);
    }
}

int main()
{
    int i,x=1,y=2;
    scanf("%d %lf",&n,&l);
    for (i=0;i<n;i++)
        scanf("%d",&a[i]);
    paixu();
 //   swap(x,y);
 //   printf("%d,%d\n",x,y);
 //   for (i=0;i<n;i++)
 //       printf("%d",a[i]);
    bidaxiao();
    if ((m==0)||(m==n-1)) printf("%lf\n",max);
    else printf("%lf\n",max/2);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int n;
    long long l;
    double d;
    scanf("%d %I64d", &n, &l);
    int *a = (int *)malloc(n*sizeof(int));
    for(int i = 0; i < n; i++){
    	scanf("%d", &a[i]);
	}
    for(int i = 0; i < n; i++){
		int min = a[i];
    	for(int j = i; j < n; j++)
    		if(a[j] < min){
				int temp = a[j];
    			a[j] = min;
				min = temp;
			}
		a[i] = min;
	}
	int dif = a[0]-0 > l-a[n-1] ? a[0]-0 : l-a[n-1];
	for(int i = 0; i < n-1 ; i++)
		if(a[i+1]-a[i]>dif)
			dif = a[i+1]-a[i];
	d = dif / 2.0;
    printf("%.10lf",d);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
double a[1005]={0};
int main()
{
	double l,maxn;
	int n;
	cin>>l>>n;
	for(int i=0;i<n;i++)
	    cin>>a[i];
	sort(a,a+n);
	maxn=a[1]-a[0];
	for(int i=2;i<n;i++)
		maxn=maxn>a[i]-a[i-1]?maxn:a[i]-a[i-1];
	printf("%.10lf",maxn/2);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
double a[1005];
int main()
{
	int l,n;
	cin>>n>>l;
	double d;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	double max=0;
	max=a[0]-0;
	for(int i=0;i<n-1;i++)
	if(max<(a[i+1]-a[i]))
	max=a[i+1]-a[i];
	if(max<l-a[n-1])
	max=l-a[n-1];
	d=max/2;
	printf("%.9lf\n",d);
	return 0;
}


#include<stdio.h>
#define SIZE 1000
int main()
{
	int n,i;							//nΪ������,iΪѭ�����Ʊ���
	float l,d;							//lΪ�ܳ��ȣ�dΪ��С�뾶
	int Light[SIZE]={0};

	scanf("%d",&l);
	scanf("%d",&n);
	for(i=0;i<=SIZE-1;i++)
	{
		scanf("%d",Light[i]);
	}

	getchar();
	getchar();
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

inline int min(int a, int b) {
    return a < b ? a : b;
}

int main() {
    int l, n;
    scanf("%d%d", &l, &n);
    int p[1005];
    for (int i = 0; i < n; ++i) scanf("%d", p + i);
    sort(p, p + n);
    int last = 0, maxd = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] < 0) continue;
        if (p[i] > l) {
            if (last + maxd >= l) break;
            if (p[i] - maxd <= l) break;
            int maxd = min(p[i] - l, l - last);
            break;
        }
        if (p[i] - last > maxd) maxd = p[i] - last;
        last = p[i];
    }
    printf("%f\n", maxd / 2.);
    return 0;
}