Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <limits>
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

#define Max(a, b) ((a) > (b) ? (a) : (b))
using namespace std;
using ll = long long;


int main(){
    int l,n;
    ll ans = 0,max_ = 0;
    cin >> l >> n;
    vector<int> X(n),rX(n);
    vector<ll> S(n),rS(n);
    rep(i,n) {
        cin >> X[i];
        S[i] = X[i];
        if(i>0) S[i] += S[i-1];
    }
    rep(i,n){
        rX[i] = l - X[n - i - 1];
        rS[i] = rX[i];
        if(i>0) rS[i] += rS[i-1];

    }
    if(n%2==0){
        
        rep(i,n-1){//ccw
            if(i % 2==0){
                if(i > 0)
                    max_ = Max(max_,2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)]) - rX[floor((double)(n-i-1)/2)]);
                else
                    max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
                
            }else{
                
                max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2) -1]) - X[n - ceil((double)(n-i-1)/2) - 1]);
                
            }
        }
        

        rep(i,n-1){//ccw
            if(i % 2==0){
                if(i > 0)
                    max_ = Max(max_,2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)]) - X[floor((double)(n-i-1)/2)]);
                else
                    max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - rX[(n/2)+1]);
                
            }else{
                
                max_ = Max(max_, 2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2) -1]) - rX[n - ceil((double)(n-i-1)/2) - 1]);
    
            }
        }

    }else{//n が奇数

        rep(i,n-1){//ccw
            if(i % 2==0){
                if(i > 0)
                    max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)-1]) - X[n - ceil((double)(n-i-1)/2) - 1]);
                else
                    max_ = Max(max_, 2*(S[ceil(n/2)-1] + rS[floor(n/2)-1]) - X[ceil(n/2)-1]);                
            }else{

                max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)]) - rX[floor((double)(n-i-1)/2)] );
                
            }
        }


        rep(i,n-1){//cw
            if(i % 2==0){
                if(i > 0)
                    max_ = Max(max_,2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)-1]) - rX[n-ceil((double)(n-i-1)/2)-1]);
                else
                    max_ = Max(max_,2*(rS[floor(n/2)-1] + S[ceil(n/2)-1]) - rX[ceil(n/2)-1]);
                
            }else{
                max_ = Max(max_, 2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)]) - X[floor((double)(n-i-1)/2)]);
                
            }
        }
    }

    cout << max_ << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:66: error: no match for call to '(std::vector<int>) (int)'
   40 |                     max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
      |                                                                 ~^~~~~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:40:73: error: expected ')' before ']' token
   40 |                     max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
      |                                                                         ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:11:26: note: to match this '('
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                          ^
a.cc:40:28: note: in expansion of macro 'Max'
   40 |                     max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
      |                            ^~~
a.cc:40:75: error: expected ')' before ';' token
   40 |                     max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
      |                                                                           ^
a.cc:11:19: note: to match this '('
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                   ^
a.cc:40:28: note: in expansion of macro 'Max'
   40 |                     max_ = Max(max_, 2*(S[(n/2)] + rS[(n/2)]) - X(n/2)+1]);
      |                            ^~~