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[i]) - X[n/2]);
                
                
            }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*(rS[n/2] + S[i]) - rX[n/2]);
                
            }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{

        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[i]) - X[n/2]);

            }else{

                max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)] - X[n - ceil((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)]) - X[floor((double)(n-i-1)/2)]);
                else
                    max_ = Max(max_,2*(rS[n/2] + rS[i]) - rX[n/2]);
            }else{
                max_ = Max(max_, 2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)]) - rX[n - ceil((double)(n-i-1)/2)]);
            }
        }
    }


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

Compiler output:
a.cc: In function 'int main()':
a.cc:21:5: error: expected ',' or ';' before 'vector'
   21 |     vector<ll> S(n),rS(n);
      |     ^~~~~~
a.cc:24:9: error: 'S' was not declared in this scope
   24 |         S[i] = X[i];
      |         ^
a.cc:29:9: error: 'rS' was not declared in this scope; did you mean 'rX'?
   29 |         rS[i] = rX[i];
      |         ^~
      |         rX
a.cc:37:40: error: 'S' was not declared in this scope
   37 |                     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)]);
      |                                        ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:37:86: error: 'rS' was not declared in this scope; did you mean 'rX'?
   37 |                     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)]);
      |                                                                                      ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:39:41: error: 'S' was not declared in this scope
   39 |                     max_ = Max(max_, 2*(S[n/2] + rS[i]) - X[n/2]);
      |                                         ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:39:50: error: 'rS' was not declared in this scope; did you mean 'rX'?
   39 |                     max_ = Max(max_, 2*(S[n/2] + rS[i]) - X[n/2]);
      |                                                  ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:44:37: error: 'S' was not declared in this scope
   44 |                 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]);
      |                                     ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:44:83: error: 'rS' was not declared in this scope; did you mean 'rX'?
   44 |                 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]);
      |                                                                                   ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:53:40: error: 'rS' was not declared in this scope; did you mean 'rX'?
   53 |                     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)]);
      |                                        ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:53:88: error: 'S' was not declared in this scope
   53 |                     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)]);
      |                                                                                        ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:55:41: error: 'rS' was not declared in this scope; did you mean 'rX'?
   55 |                     max_ = Max(max_, 2*(rS[n/2] + S[i]) - rX[n/2]);
      |                                         ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:55:51: error: 'S' was not declared in this scope
   55 |                     max_ = Max(max_, 2*(rS[n/2] + S[i]) - rX[n/2]);
      |                                                   ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:59:37: error: 'rS' was not declared in this scope; did you mean 'rX'?
   59 |                 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]);
      |                                     ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:59:85: error: 'S' was not declared in this scope
   59 |                 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]);
      |                                                                                     ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:69:40: error: 'S' was not declared in this scope
   69 |                     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)]);
      |                                        ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:69:86: error: 'rS' was not declared in this scope; did you mean 'rX'?
   69 |                     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)]);
      |                                                                                      ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:71:41: error: 'S' was not declared in this scope
   71 |                     max_ = Max(max_, 2*(S[n/2] + rS[i]) - X[n/2]);
      |                                         ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:71:50: error: 'rS' was not declared in this scope; did you mean 'rX'?
   71 |                     max_ = Max(max_, 2*(S[n/2] + rS[i]) - X[n/2]);
      |                                                  ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:75:37: error: 'S' was not declared in this scope
   75 |                 max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)] - X[n - ceil((double)(n-i-1)/2)]));
      |                                     ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:75:83: error: 'rS' was not declared in this scope; did you mean 'rX'?
   75 |                 max_ = Max(max_, 2*(S[n - ceil((double)(n-i-1)/2) - 1] - S[i-1] + rS[floor((double)(n-i-1)/2)] - X[n - ceil((double)(n-i-1)/2)]));
      |                                                                                   ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:84:40: error: 'rS' was not declared in this scope; did you mean 'rX'?
   84 |                     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)]);
      |                                        ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:84:88: error: 'S' was not declared in this scope
   84 |                     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)]);
      |                                                                                        ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:86:40: error: 'rS' was not declared in this scope; did you mean 'rX'?
   86 |                     max_ = Max(max_,2*(rS[n/2] + rS[i]) - rX[n/2]);
      |                                        ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:88:37: error: 'rS' was not declared in this scope; did you mean 'rX'?
   88 |                 max_ = Max(max_, 2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)]) - rX[n - ceil((double)(n-i-1)/2)]);
      |                                     ^~
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^
a.cc:88:85: error: 'S' was not declared in this scope
   88 |                 max_ = Max(max_, 2*(rS[n - ceil((double)(n-i-1)/2) - 1] - rS[i-1] + S[floor((double)(n-i-1)/2)]) - rX[n - ceil((double)(n-i-1)/2)]);
      |                                                                                     ^
a.cc:11:27: note: in definition of macro 'Max'
   11 | #define Max(a, b) ((a) > (b) ? (a) : (b))
      |                           ^