#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 100100

typedef struct nodoDirectorio{
    long vertice;
    long cardinal;
    struct nodoAdyacente* Lista;
} NodoGrafo;

typedef struct nodoAdyacente{
    struct nodoDirectorio* destino;
    struct nodoAdyacente* enlace;
} NodoLista;

NodoGrafo* crearNodoG(long vertice);
void arista(NodoGrafo grafo[MAX],const long org, const long dst,long *color);
NodoLista* crearNodoA(NodoGrafo* vertice);

int main(){
    long n,m;
    NodoGrafo graph[MAX];
    scanf("%ld%ld",&n,&m);
    long color[n];
    long i;
    for(i=0;i<MAX;i++){
        graph[i].cardinal=0;
        graph[i].vertice=0;
        graph[i].Lista=NULL;
    }
    for(i=0;i<n;i++){
        scanf("%ld",&color[i]);
        graph[color[i]].vertice=color[i];
    }
    long f,c;
    for(i=0;i<m;i++){
        scanf("%ld %ld",&f,&c);
       if(color[f-1]!=color[c-1]){
                arista(graph,color[f-1],color[c-1],color);
                arista(graph,color[c-1],color[f-1],color);
       }
    }

    long may = color[0];

    for(i=0;i<n;i++){
        if(graph[color[i]].cardinal>graph[may].cardinal){
            may = color[i];
        }else if(graph[color[i]].cardinal==graph[may].cardinal){
            if(graph[color[i]].vertice<graph[may].vertice){
                may=color[i];
            }
        }
    }

    printf("%ld\n",may);

    return 0;
}
void arista(NodoGrafo grafo[MAX],const long org, const long dst,long *color){
    NodoGrafo* v1,*v2; /* se declaran la variables que contendr�n a los v�rtices*/
    NodoLista* ady; /* se declara el el nuevo arco*/

    v1 = &grafo[org];
    v2 = &grafo[dst]; /* se localiza el nodo destino*/
        /*comprueba la existencia de los v�rtiices */

    int esta = 0;
    if(v1->vertice&&v2->vertice){
        ady=v1->Lista; /* recorre la lista de adyacencia */
        while(ady){
            if(ady->destino==v2){
                esta=1;
                ady=NULL;   /* para terminar el bucle de busqueda */
            }else{
                ady=ady->enlace;
            }
        }
    }
    if(v1->vertice&&v2->vertice && (esta==0)){
        v1->cardinal++;
        ady = crearNodoA(v2); /* se crea el nuevo arco*/
        ady->enlace=v1->Lista; /* y se agrega a la lista de adyacentes al nodo origen*/
        v1 ->Lista = ady;
    }

}
NodoLista* crearNodoA(NodoGrafo* vertice){
        /* se crea un nuevo arco, se inicializan los campos*/
        NodoLista* nuevo;
        nuevo=malloc(sizeof(NodoLista));
        nuevo->destino=vertice;
        nuevo->enlace=NULL;
        return nuevo;
}


#include <stdio.h>
#include <stdlib.h>
struct dir{
    struct dir *sgte;
    long color;
    long vertice;
};
typedef struct dir Directo;
struct lis{
    long color;
    struct lis *sgte;
};
typedef struct lis Lista;
void crear_dir(Directo **gra, long pos, long color);
long insertar_color(Lista *color[],long color_origen, long color_destino, long colores[], long may,long *men,long *sum);
int main()
{
    Directo *Grafo,*recor;
    Lista *color[100100];
    long colores[100100];
    long n,m,l,k,j,color_destino,color_origen,ele,pos,may,i,men,sum;
    scanf("%ld%ld",&n,&m);
    l=1;
    while(l<=n){
        scanf("%ld",&k);
        crear_dir(&Grafo,l,k);
        colores[k]=1;
        l++;
    }
    men=k;
    l=1;
    may=0;
    sum=1;
    while(l<=m){
        scanf("%ld%ld",&k,&j);
        recor=Grafo;
        while(recor->vertice!=k){
            recor=recor->sgte;
        }
        color_origen=recor->color;
        recor=Grafo;
        while(recor->vertice!=j){
            recor=recor->sgte;
        }
        color_destino=recor->color;
        if(color_destino!=color_origen){
           may=insertar_color(color,color_origen,color_destino,colores,may,&men,&sum);
           may=insertar_color(color,color_destino,color_origen,colores,may,&men,&sum);
        }
        l++;
    }
    ele=0;
    pos=0;
    if(sum==1){
        i=1;
        while(colores[i]!=sum){
            i++;
        }
        pos=i;
    }else{
        for(i=1;i<=may;i++){
            if(colores[i]>ele){
                ele=colores[i];
                pos=i;
            }
        }
        if(ele==1){
            pos=men;
        }
    }
    printf("%ld",pos);
    return 0;
}
void crear_dir(Directo **gra, long pos, long color){
Directo *nuevo;
nuevo=malloc(sizeof(Directo));
if(*gra==NULL){
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=NULL;
    *gra=nuevo;
}else{
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=*gra;
    *gra=nuevo;
}
}

long insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long may,long *men,long *sum){
Lista *recor3,*nuevo;
nuevo=malloc(sizeof(Lista));
           if(color[color_origen]==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=NULL;
                    color[color_origen]=nuevo;
                    if(color_origen>may){
                        may=color_origen;
                    }
                    if(color_origen<(*men)){
                        *men=color_origen;
                    }
                    if(colores[color_origen]>(*sum)){
                        *sum=colores[color_origen];
                    }
           }else{
                recor3=color[color_origen];
                if(recor3->color!=color_destino){
                    while(recor3->color!=color_destino){
                            recor3=recor3->sgte;
                            if(recor3==NULL){
                                break;
                            }
                    }
                    if(recor3==NULL){
                        colores[color_origen]++;
                        nuevo->color=color_destino;
                        nuevo->sgte=color[color_origen];
                        color[color_origen]=nuevo;

                        if(color_origen>may){
                            may=color_origen;
                        }
                        if(color_origen<(*men)){
                            *men=color_origen;
                        }
                        if(colores[color_origen]>(*sum)){
                        *sum=colores[color_origen];
                    }
                    }

                }
            }

        return may;
}


#include <stdio.h>
#include <stdlib.h>
struct dir{
    struct dir *sgte;
    long color;
    long vertice;
};
typedef struct dir Directo;
struct lis{
    long color;
    struct lis *sgte;
};
typedef struct lis Lista;
void crear_dir(Directo **gra, long pos, long color);
void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum);
int main()
{
    Directo *Grafo,*recor;
    Lista *color[100010];
    long colores[100010];
    long n,m,l,k,j,color_destino,color_origen,men,sum;
    scanf("%ld%ld",&n,&m);
    l=1;
    while(l<=n){
        scanf("%ld",&k);
        crear_dir(&Grafo,l,k);
        colores[k]=1;
        l++;
    }
    men=k;
    l=1;
    sum=1;
    while(l<=m){
        scanf("%ld%ld",&k,&j);
        recor=Grafo;
        while(recor->vertice!=k){
            recor=recor->sgte;
        }
        color_origen=recor->color;
        recor=Grafo;
        while(recor->vertice!=j){
            recor=recor->sgte;
        }
        color_destino=recor->color;
        if(color_destino!=color_origen){
           insertar_color(color,color_origen,color_destino,colores,&men,&sum);
           insertar_color(color,color_destino,color_origen,colores,&men,&sum);
        }
        l++;
    }
    printf("%ld",men);
    return 0;
}
void crear_dir(Directo **gra, long pos, long color){
Directo *nuevo;
nuevo=malloc(sizeof(Directo));
if(*gra==NULL){
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=NULL;
    *gra=nuevo;
}else{
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=*gra;
    *gra=nuevo;
}
}

void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum){
Lista *recor3,*nuevo;
nuevo=malloc(sizeof(Lista));
           if(color[color_origen]==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=NULL;
                    color[color_origen]=nuevo;
                    if(colores[color_origen]>(*sum)){
                                *men=color_origen;
                                *sum=colores[color_origen];
                    }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }

           }else{
                recor3=color[color_origen];
                if(recor3->color!=color_destino){
                    while(recor3->color!=color_destino){
                            recor3=recor3->sgte;
                            if(recor3==NULL){
                                break;
                            }
                    }
                    if(recor3==NULL){
                        colores[color_origen]++;
                        nuevo->color=color_destino;
                        nuevo->sgte=color[color_origen];
                        color[color_origen]=nuevo;

                        if(colores[color_origen]>(*sum)){
                                    *men=color_origen;
                                    *sum=colores[color_origen];
                        }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }
                    }

                }
            }

}


#include <stdio.h>
#include <stdlib.h>
struct lis{
    long color;
    struct lis *sgte;
};
typedef struct lis Lista;
void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum);
int main()
{
    Lista *color[100010];
    long colores[100010];
    long usados[100010];
    long n,m,l,k,j,color_destino,color_origen,men,sum,ins,men2;
    scanf("%ld%ld",&n,&m);
    l=1;
    while(l<=n){
        scanf("%ld",&k);
        usados[l]=k;
        colores[k]=1;
        l++;
    }
    men=k;
    l=1;
    sum=1;
    ins=0;
    men2=k;
    while(l<=m){
        scanf("%ld%ld",&k,&j);
        color_origen=usados[k];
        color_destino=usados[j];
        if(color_destino!=color_origen){
                ins++;
            insertar_color(color,color_origen,color_destino,colores,&men,&sum);
           insertar_color(color,color_destino,color_origen,colores,&men,&sum);
        }else{
            if(color_origen<men2){
                men2=color_origen;
            }
            if(color_destino<men2){
                men2=color_destino;
            }
        }

        l++;
    }
    if(ins==0){
        printf("%ld",men2);
    }else{
        printf("%ld",men);
    }
    return 0;
}
void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum){
Lista *recor3,*nuevo;
nuevo=malloc(sizeof(Lista));
           if(color[color_origen]==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=NULL;
                    color[color_origen]=nuevo;
                    if(colores[color_origen]>(*sum)){
                                *men=color_origen;
                                *sum=colores[color_origen];
                    }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }

           }else{
                recor3=color[color_origen];
                if(recor3->color!=color_destino){
                    while(recor3->color!=color_destino){
                            recor3=recor3->sgte;
                            if(recor3==NULL){
                                break;
                            }
                    }
                    if(recor3==NULL){
                        colores[color_origen]++;
                        nuevo->color=color_destino;
                        nuevo->sgte=color[color_origen];
                        color[color_origen]=nuevo;

                        if(colores[color_origen]>(*sum)){
                                    *men=color_origen;
                                    *sum=colores[color_origen];
                        }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }
                    }

                }
            }

}


#include <stdio.h>
#include <stdlib.h>
struct dir{
    struct dir *sgte;
    int color;
    int vertice;
};
typedef struct dir Directo;
struct lis{
    int color;
    struct lis *sgte;
    struct lis *vecinos;
};
typedef struct lis Lista;
void crear_lis(Lista **col,int color);
void crear_dir(Directo **gra, int pos, int color);
int insertar_color(Lista **color, int color_origen, int color_destino, int colores[], int may,int *men);
int main()
{
    Directo *Grafo,*recor;
    Lista *color;
    int colores[100500];
    int n,m,l,k,j,color_destino,color_origen,ele,pos,may,i,men;
    scanf("%d%d",&n,&m);
    l=1;
    while(l<=n){
        scanf("%d",&k);
        crear_dir(&Grafo,l,k);
        crear_lis(&color,k);
        colores[k]=1;
        l++;
    }
    men=k;
    l=1;
    may=0;
    while(l<=m){
        scanf("%d%d",&k,&j);
        recor=Grafo;
        while(recor->vertice!=k){
            recor=recor->sgte;
        }
        color_origen=recor->color;
        recor=Grafo;
        while(recor->vertice!=j){
            recor=recor->sgte;
        }
        color_destino=recor->color;
        if(color_destino!=color_origen){
           may=insertar_color(&color,color_origen,color_destino,colores,may,&men);
           may=insertar_color(&color,color_destino,color_origen,colores,may,&men);
        }
        l++;
    }

    pos=0;
    ele=1;
        for(i=1;i<=may;i++){
            if(colores[i]>ele){
                ele=colores[i];
                pos=i;
            }
        }
        if(ele==1){
            pos=men;
        }
    printf("%d",pos);
    return 0;
}
void crear_dir(Directo **gra, int pos, int color){
Directo *nuevo;
nuevo=malloc(sizeof(Directo));
if(*gra==NULL){
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=NULL;
    *gra=nuevo;
}else{
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=*gra;
    *gra=nuevo;
}
}
void crear_lis(Lista **col,int color){
Lista *nuevo;
nuevo=malloc(sizeof(Lista));
if(*col==NULL){
    nuevo->color=color;
    nuevo->sgte=NULL;
    nuevo->vecinos=NULL;
    *col=nuevo;
}else{
    nuevo->color=color;
    nuevo->sgte=*col;
    nuevo->vecinos=NULL;
    *col=nuevo;
}
}
int insertar_color(Lista **color, int color_origen, int color_destino, int colores[],int may,int *men){
Lista *recor2,*recor3,*nuevo;
nuevo=malloc(sizeof(Lista));
           recor2=*color;
           while(recor2->color!=color_origen){
            recor2=recor2->sgte;
           }
           if(recor2->vecinos==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=NULL;
                    nuevo->vecinos=NULL;
           }else{
               recor3=recor2->vecinos;
                while((recor3->color!=color_destino)||(recor3==NULL)){
                    recor3=recor3->sgte;
                }
                if(recor3==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=recor2->vecinos;
                    recor2->vecinos=nuevo;
                }
            }
            if(color_destino>may){
                may=color_destino;
            }
            if(color_origen<(*men)){
                *men=color_origen;
            }
        return may;
}


#include <stdio.h>
#include <stdlib.h>
struct dir{
    struct dir *sgte;
    long color;
    long vertice;
};
typedef struct dir Directo;
struct lis{
    long color;
    struct lis *sgte;
};
typedef struct lis Lista;
void crear_dir(Directo **gra, long pos, long color);
void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum);
int main()
{
    Directo *Grafo,*recor;
    Lista *color[100100];
    long colores[100100];
    long n,m,l,k,j,color_destino,color_origen,men,sum;
    scanf("%ld%ld",&n,&m);
    l=1;
    while(l<=n){
        scanf("%ld",&k);
        crear_dir(&Grafo,l,k);
        colores[k]=1;
        l++;
    }
    men=k;
    l=1;
    sum=1;
    while(l<=m){
        scanf("%ld%ld",&k,&j);
        recor=Grafo;
        while(recor->vertice!=k){
            recor=recor->sgte;
        }
        color_origen=recor->color;
        recor=Grafo;
        while(recor->vertice!=j){
            recor=recor->sgte;
        }
        color_destino=recor->color;
        if(color_destino!=color_origen){
           insertar_color(color,color_origen,color_destino,colores,&men,&sum);
           insertar_color(color,color_destino,color_origen,colores,&men,&sum);
        }
        l++;
    }
    printf("%ld",men);
    return 0;
}
void crear_dir(Directo **gra, long pos, long color){
Directo *nuevo;
nuevo=malloc(sizeof(Directo));
if(*gra==NULL){
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=NULL;
    *gra=nuevo;
}else{
    nuevo->color=color;
    nuevo->vertice=pos;
    nuevo->sgte=*gra;
    *gra=nuevo;
}
}

void insertar_color(Lista *color[],long color_origen, long color_destino, long colores[],long *men,long *sum){
Lista *recor3,*nuevo;
nuevo=malloc(sizeof(Lista));
           if(color[color_origen]==NULL){
                    colores[color_origen]++;
                    nuevo->color=color_destino;
                    nuevo->sgte=NULL;
                    color[color_origen]=nuevo;
                    if(colores[color_origen]>(*sum)){
                                *men=color_origen;
                                *sum=colores[color_origen];
                    }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }

           }else{
                recor3=color[color_origen];
                if(recor3->color!=color_destino){
                    while(recor3->color!=color_destino){
                            recor3=recor3->sgte;
                            if(recor3==NULL){
                                break;
                            }
                    }
                    if(recor3==NULL){
                        colores[color_origen]++;
                        nuevo->color=color_destino;
                        nuevo->sgte=color[color_origen];
                        color[color_origen]=nuevo;

                        if(colores[color_origen]>(*sum)){
                                    *men=color_origen;
                                    *sum=colores[color_origen];
                        }
                        if(colores[color_origen]==(*sum)){
                            if(color_origen<(*men)){
                                *men=color_origen;
                            }
                        }
                    }

                }
            }

}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N], dp[N], f[N], ans, g[N];

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(a[i+1] < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, pos[N];
ll a[N], b[N], dp[N], c[N];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) {
        scanf("%lld",&a[i]);
    }

    ll ans = sq();

    if(x < 0) {
            rep(i,1,n) a[i] = -a[i];
            sq();
            rep(i,1,n) a[i] = -a[i];
    }

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq());
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
        }
    }

    cout << max(ans,0ll) <<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 1000100;
const int M = 2000100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, pos[N];
ll a[N], b[N], dp[N], c[N];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    //rep(i,1,n) cout << a[i] <<"-"; puts("");
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) {
        scanf("%lld",&a[i]);
    }

    ll ans = sq();
    if(x < 0) {
            rep(i,1,n) a[i] = -a[i];
            sq();
            rep(i,1,n) a[i] = -a[i];
    }

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
            //rep(i,1,n) cout << a[i] << " ";puts("");
        }
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }
        v2.clear();
        v.clear();

        ll tmp = sq();
        //cout <<"> "<< tmp << endl;
        for(auto aa: v) {
            //cout << aa.x << " "<< aa.y << endl;
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            //cout << mn << endl;
            ans = max(ans, tmp-mn);
            v2.clear();
        }
    }

    cout << max(ans,0ll) <<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N], dp[N], f[N], ans, g[N];

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
    }
    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(a[i+1] < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, pos[N];
ll a[N], b[N], dp[N], c[N];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) {
        scanf("%lld",&a[i]);
    }

    ll ans = sq();

    if(x < 0) {
        rep(i,1,n) a[i] = -a[i];
        sq();
        rep(i,1,n) a[i] = -a[i];
    }

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        sq2(a,n);
        for(auto aa: v2) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        v2.clear();
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq());
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
        }
    }

    cout << max(ans,0ll) <<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N], dp[N], f[N], ans, g[N];

int pos[N];
ll b[N], c[N];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);

    if(!x) {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq());
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
        }
    }

    cout << max(ans,0ll) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N], dp[N], f[N], ans, g[N];

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N<<1], dp[N<<1], f[N<<1], ans, g[N<<1];

int pos[N<<1];
ll b[N<<1], c[N<<1];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);

    if(!x) {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq()); v.clear();
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
            break;
        }
    }

    cout << max(ans,0ll) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N], dp[N], f[N], ans, g[N];

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);
    cout << max(ans,0ll) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N<<1], dp[N<<1], f[N<<1], ans, g[N<<1];

int pos[N<<1];
ll b[N<<1], c[N<<1];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx <= b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn >= b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        sq2(a,n);
        for(auto aa: v2) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        v2.clear();
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq()); v.clear();
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
            break;
        }
    }

    cout << max(ans,0ll) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m;
ll a[N], dp[N][3],ans,x;

int main() {
    scanf("%d%lld",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i,1,n) {
        if(dp[i-1][0] >= 0) dp[i][0] = dp[i-1][0] + a[i];
        else dp[i][0] = a[i];

        dp[i][1] = max(dp[i-1][1] + a[i]*x, dp[i][1]);
        dp[i][1] = max(dp[i-1][0] + a[i]*x, dp[i][1]);

        dp[i][2] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
        ans = max(ans, dp[i][0]);
        ans = max(ans, dp[i][1]);
        ans = max(ans, dp[i][2]);
    }
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 1000100;
const int M = 2000100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, pos[N];
ll a[N], b[N], dp[N], c[N];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    rep(i,1,n) cout << a[i] <<"-"; puts("");
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) {
        scanf("%lld",&a[i]);
    }

    ll ans = sq();

    if(x < 0) rep(i,1,n) a[i] = -a[i];

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
           // rep(i,1,n) cout << a[i] << " ";puts("");
        }
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
            //rep(i,1,n) cout << a[i] << " ";puts("");
        }
        v2.clear();
        v.clear();

        ll tmp = sq();
        //cout <<"> "<< tmp << endl;
        for(auto aa: v) {
            //cout << aa.x << " "<< aa.y << endl;
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            //cout << mn << endl;
            ans = max(ans, tmp-mn);
            v2.clear();
        }
    }
    cout << max(ans,0ll) <<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N<<1], dp[N<<1], f[N<<1], ans, g[N<<1];

int pos[N<<1];
ll b[N<<1], c[N<<1];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx < b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn > b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);

    if(!x) {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq()); v.clear();
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
        }
    }

    cout << max(ans,0ll) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i = (a); i >= (b); --i)
#define pb push_back
#define Pll pair< ll,ll >
#define Pii pair< int,int >
#define Plp pair< ll,Pii >
#define Pip pair< int,Pii >
#define Ppp pair< Pii,Pii >
#define x first
#define y second
typedef long long ll;
const int N = 300100;
const ll inf = 1e18;
template<class T> inline void read(T &x) {
	x = 0; char c = getchar(); T f = 1;
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}

using namespace std;

int n, m, posf[N], posg[N];
ll a[N<<1], dp[N<<1], f[N<<1], ans, g[N<<1];

int pos[N<<1];
ll b[N<<1], c[N<<1];
vector< Pii > v, v2;

ll sq2(ll a[], int n) {
    ll mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mx = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mx;
        pos[i] = p;
        if(mx <= b[i]) {
            mx = b[i];
            p = i;
        }
    }
    ll mn = inf;
    rep(i,1,n) mn = min(mn, dp[i]);
    rep(i,1,n) if(dp[i] == mn) {
        v2.pb({pos[i]+1,i});
    }
    return mn;
}

ll sq() {
    ll mn = inf, p = 0;
    for(int i = 1; i <= n; ++i) b[i] = b[i-1] + a[i];
    mn = 0, p = 0;
    for(int i = 1; i <= n; ++i) {
        dp[i] = b[i] - mn;
        pos[i] = p;
        if(mn >= b[i]) {
            mn = b[i];
            p = i;
        }
    }
    ll mx = -inf;
    rep(i,1,n) mx = max(mx, dp[i]);
    rep(i,1,n) if(dp[i] == mx) {
        v.pb({pos[i]+1,i});
    }
    return mx;
}

int x;
int main() {
    scanf("%d%d",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]);

    rep(i, 1, n) {
        if(f[i-1] < 0) f[i] = a[i], posf[i] = i-1;
        else f[i] = f[i-1] + a[i], posf[i] = posf[i-1];

        if(g[i-1] > 0) g[i] = a[i], posg[i] = i-1;
        else g[i] = g[i-1] + a[i],  posg[i] = posg[i-1];

        dp[i] = max(f[i]*x + f[posf[i]], g[i]*x + f[posg[i]]);
        dp[i] = max(dp[i], f[i]*x);
        dp[i] = max(dp[i], g[i]*x);
        ans = max(ans, dp[i]);
    }
//    cout << dp[3] << " " << dp[4] << endl;

    ll tmp = 0;
    per(i, n, 1) {
        ans = max(ans, dp[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }
    ans = max(ans, tmp);

    rep(i,2,n) f[i] = max(f[i],f[i-1]);
    tmp = 0;
    per(i, n, 1) {
        ans = max(ans, f[i]+tmp);
        if(tmp < 0) tmp = a[i];
        else tmp += a[i];
    }

    if(x != 0) {
        for(auto aa: v) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        sq2(a,n);
        for(auto aa: v2) {
            rep(i,aa.x,aa.y) a[i] *= x;
            ans = max(ans, sq());
            rep(i,aa.x,aa.y) a[i] /= x;
        }
        v2.clear();
    }
    else {
        sq2(a,n);
        for(auto aa: v2) {
            memcpy(c,a,sizeof(a));
            rep(i,aa.x,aa.y) a[i] = 0;
            ans = max(ans, sq());
            memcpy(a,c,sizeof(a));
        }

        v2.clear();
        v.clear();

        ll tmp = sq();
        for(auto aa: v) {
            int cc = 0;
            rep(i,aa.x,aa.y) c[++ cc] = a[i];
            ll mn = sq2(c,cc);
            for(auto bb: v2) {
               // cout << bb.x <<" - " << bb.y << endl;
                rep(i,bb.x+aa.x-1,bb.y+aa.x-1) c[i] = a[i], a[i] = 0;
                ans = max(ans, sq()); v.clear();
                rep(i,bb.x,bb.y) a[i] = c[i];
            }
            v2.clear();
            break;
        }
    }

    cout << max(ans,0ll) << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);

            max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                if (a[i] < 0)
                    cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);

            max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                if (a[i] < 0)
                    cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            // cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long n, x;
long long a[maxn], pref[maxn], min_pref[maxn], max_pref[maxn];
long long d[maxn][3];

long long solve() {
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + a[i];
        min_pref[i] = min(min_pref[i - 1], pref[i]);
        max_pref[i] = max(max_pref[i - 1], pref[i]);
    }

    long long result = 0;
    for (int i = 1; i <= n; ++i) {
            d[i][0] = max(d[i - 1][0], 0ll) + a[i];

        d[i][1] = max(d[i - 1][0], d[i - 1][1]) + a[i] * x;
        d[i][2] = max(d[i - 1][1], d[i - 1][2]) + a[i];

        result = max(result, d[i][0]);
        result = max(result, d[i][1]);
        result = max(result, d[i][2]);
    }

    return result;
}

int main() {
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    cout << solve() << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            ans[i] = pref[i] - min_pref;
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            } else {
                max_subarray = max(max_subarray, ans[i]);
            }

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            min_subarray[i] = pref[i] - max_pref;
            max_pref = max(max_pref, pref[i]);
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            ans[i] = pref[i] - min_pref;

            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * (x - 1));
        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);
            if (a[i] > 0)
                max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                if (a[i] < 0)
                    cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            // cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            ans[i] = pref[i] - min_pref;

            max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }

            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            ans[i] = pref[i] - min_pref;

            cur_min_subarray = min(cur_min_subarray, min_subarray[i]);

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * (x - 1));

            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            }
        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }
            if (a[i] > 0)
                max_subarray = max(max_subarray, ans[i]);

            ans[i] = pref[i] - min(min_pref, pref[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            }
            if (a[i] < 0)
                cur_min_subarray = min(cur_min_subarray, min_subarray[i]);

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            // cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            ans[i] = pref[i] - min(min_pref, pref[i]);

            max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }

            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            ans[i] = pref[i] - min(min_pref, pref[i]);
            if (pref[i] == min_pref)
                min_pref_index = i;
            //cout << ans[i] << endl;

            cur_min_subarray = min(cur_min_subarray, min_subarray[i]);

            // cout << cur_min_subarray << endl;
            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * (x - 1));

            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            }
        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long n, x;
long long a[maxn], pref[maxn], min_pref[maxn], max_pref[maxn];
long long d[maxn][3];

long long solve() {
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + a[i];
        min_pref[i] = min(min_pref[i - 1], pref[i]);
        max_pref[i] = max(max_pref[i - 1], pref[i]);
    }

    long long result = 0;
    for (int i = 1; i <= n; ++i) {
            d[i][0] = max(d[i - 1][0], 0ll) + a[i];

        d[i][1] = max(max(d[i - 1][0], d[i - 1][1]), 0ll) + a[i] * x;
        d[i][2] = max(max(d[i - 1][1], d[i - 1][2]), 0ll) + a[i];

        result = max(result, d[i][0]);
        result = max(result, d[i][1]);
        result = max(result, d[i][2]);
    }

    return result;
}

int main() {
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    cout << solve() << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long n, x;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

long long solve() {
    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {

        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            } else {
                if (a[i] > 0)
                    max_subarray = max(max_subarray, ans[i]);
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                if (a[i] < 0)
                    cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            // cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    return result;

}

int main() {
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long answer = 0;
    answer = max(answer, solve());
    reverse(a + 1, a + n + 1);
    answer = max(answer, solve());
    cout << answer << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            } else {
                if (a[i] > 0)
                    max_subarray = max(max_subarray, ans[i]);
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                if (a[i] < 0)
                    cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            // cout << ans[i] << ' ' << cur_min_subarray << endl;

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * x);

        }
    }

    cout << result << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cassert>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

const int maxn = (int)3e5 + 10;

long long a[maxn], pref[maxn], min_subarray[maxn], ans[maxn];

int main() {
    long long n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    long long result = 0;
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + a[i];

    if (x > 0) {
        long long min_pref = 0;
        long long max_subarray = 0;
        for (int i = 1; i <= n; ++i)  {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                max_subarray = 0;
            }

            ans[i] = pref[i] - min(min_pref, pref[i]);

            max_subarray = max(max_subarray, ans[i]);

            result = max(result, ans[i]);
            if (max_subarray > 0) {
                result = max(result, ans[i] + max_subarray * (x - 1ll));
            }
        }
    } else {
        long long max_pref = 0;
        for (int i = 1; i <= n; ++i) {
            max_pref = max(max_pref, pref[i]);
            min_subarray[i] = pref[i] - max_pref;
        }

        int min_pref_index = 0;
        long long min_pref = 0;
        long long cur_min_subarray = 0;
        for (int i = 1; i <= n; ++i) {
            if (pref[i] < min_pref) {
                min_pref = pref[i];
                cur_min_subarray = 0;
                min_pref_index = i;
            } else {
                cur_min_subarray = min(cur_min_subarray, min_subarray[i]);
            }

            ans[i] = pref[i] - min_pref;

            // cur_min_subarray = min(cur_min_subarray, min_subarray[i]);

            result = max(result, ans[i]);
            if (cur_min_subarray < 0)
                result = max(result, ans[i] + cur_min_subarray * (x - 1));
            if (min_subarray[min_pref_index] < 0)
                result = max(result,
                             ans[i] + min_subarray[min_pref_index] * (x - 1));

        }
    }

    cout << result << endl;
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,m=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		temp=msum;
		csum=msum=0;
		for(i=0;i<l;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		m=msum;
		csum=msum=0;
		for(i=r+1;i<n;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		cout<<temp+max(m,msum);
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp*(-x);
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,m=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		temp=msum;
		csum=msum=0;
		for(i=0;i<l;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		m=msum;
		csum=msum=0;
		for(i=r+1;i<n;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		cout<<temp+max(m,msum);
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||msum=0)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,m=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		temp=msum;
		csum=msum=0;
		for(i=0;i<l;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		m=msum;
		csum=msum=0;
		for(i=r+1;i<n;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		cout<<temp+max(m,msum);
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||msum==0)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,max=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		sum=0;
		for(i=0;i<l;i++)
		{
			if(a[i]>0)
			{
				sum+=a[i];
				if(sum>max)
					max=sum;
			}
			else
			{
				sum=0;
			}
		}
		for(i=r+1;i<n;i++)
		{
			if(a[i]>0)
			{
				sum+=a[i];
				if(sum>max)
					max=sum;
			}
			else
			{
				sum=0;
			}
		}
		cout<<msum+max;
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
		}
		else if(msum<csum)
		{
			msum=csum;
		}
	}
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		cout<<msum;
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		msum=csum=0;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long
#define mod 1000000007
#define pb push_back

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%mod;
        // y must be even now
        y = y/2; // y = y/2
        x = (x*x)%mod;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n, x, i, ans;
    cin>>n>>x;
    ll a[n], dp[n][3];
    for(i = 0; i < n; i++)
    	cin>>a[i];

	ans = dp[n - 1][0] = max(0ll, x*a[n - 1]);
	dp[n - 1][1] = max(0ll, a[n - 1]);
	dp[n - 1][2] = dp[n - 1][1];
	ans = max(ans, dp[n - 1][1]);

	for(i = n - 2; i >= 0; i--)
	{
		dp[i][0] = max(0ll, x*a[i] + max(dp[i + 1][0], dp[i + 1][2]));
		dp[i][1] = max(0ll, a[i] + max(dp[i + 1][0], dp[i + 1][1]));
		dp[i][2] = max(0ll, a[i] + dp[i + 1][2]);
		ans = max(ans, max(dp[i][0], max(dp[i][1], dp[i][2])));
	}
	cout<<ans<<"\n";
/*	for(i = 0; i < n; i++)
		cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<"\n";*/
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,max=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		sum=0;
		for(i=0;i<l;i++)
		{
			if(a[i]>0)
			{
				sum+=a[i];
				if(a[i]>sum)
					sum=a[i];
			}
			else
			{
				sum=0;
			}
		}
		for(i=r+1;i<n;i++)
		{
			if(a[i]>0)
			{
				sum+=a[i];
				if(a[i]>sum)
					sum=a[i];
			}
			else
			{
				sum=0;
			}
		}
		cout<<msum+sum;
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,m=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		temp=msum;
		csum=msum=0;
		for(i=0;i<l;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		m=msum;
		csum=msum=0;
		for(i=r+1;i<n;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		cout<<temp+max(m,msum);
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp*x;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,m=0,sum;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		temp=msum;
		csum=msum=0;
		for(i=0;i<l;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		m=msum;
		csum=msum=0;
		for(i=r+1;i<n;i++)
		{
			csum+=a[i];
			if(csum<0)
			{
				csum=0;
			}
			else if(msum<csum)
			{
				msum=csum;
			}
		}
		cout<<temp+max(m,msum);
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp,max=0;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
			templ=i+1;
			r=tempr;
		}
		else if(msum<csum)
		{
			msum=csum;
			l=templ;
			tempr=i;
		}
	}
	r=tempr;
	if(x>0)
	{
		cout<<msum*x;
	}
	else if(x==0)
	{
		for(i=0;i<l;i++)
		{
			if(a[i]>max)
				max=a[i];
		}
		for(i=r+1;i<n;i++)
		{
			if(a[i]>max)
				max=a[i];
		}
		cout<<msum+max;
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		templ=tempr=msum=csum=0;
		l=-1,r=-1;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define ll long long

int main()
{
	ll n,x,i,csum=0,msum=0,ans,l=-1,r=-1,templ=0,tempr=0,temp;
	cin>>n>>x;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		csum+=a[i];
		if(csum<0)
		{
			csum=0;
		}
		else if(msum<csum)
		{
			msum=csum;
		}
	}
	if(x>0)
	{
		cout<<msum*x;
	}
	else
	{
	//	cout<<msum<<" ";
		ans=msum;
		msum=csum=0;
		for(i=0;i<n;i++)
		{
			csum-=a[i];
			//cout<<csum<<endl;
			if(csum<0)
			{
				csum=0;
				templ=i+1;
				r=tempr;
			}
			else if(msum<csum)
			{
				msum=csum;
				l=templ;
				tempr=i;
			}
		}
		r=tempr;
		temp=msum*(-x);
		if(l==-1||r==-1)
		{
			cout<<ans;
			return 0;
		}
		//cout<<l<<" "<<r;
		for(i=l;i<=r;i++)
		{
			a[i]*=x;
		}
		csum=msum=0;
		for(i=0;i<n;i++)
		{
			if(i==l)
			{
				csum+=temp;
				if(msum<csum)
				{
					msum=csum;
				}
				i=r;
			}
			else
			{
				csum+=a[i];
				if(csum<0)
				{
					csum=0;
				}
				else if(msum<csum)
				{
					msum=csum;
				}
			}
		}
		if(msum>ans)
			cout<<msum;
		else
			cout<<ans;
	}
    return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double

typedef pair<long long, long long> II;
typedef pair<long long, II> III;

const long long INF = (1 << 30) - 1;
const long long oo = (1ll << 62) - 1;
const long double PI = 3.1415926535898;

const long long N = 3 * 100000 + 5;

long long n, x;
long long a[N];
long long f1 = 0, f2 = 0, f3 = 0;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("SUMSEQ.inp", "r", stdin);
    //freopen("SUMSEQ.out", "w", stdout);
    cin >> n >> x;
    for(long long i = 1; i <= n; i++)
        cin >> a[i];
    long long res = 0;
    for(long long i = 1; i <= n; i++)
    {
        f3 = max(f2 + x * a[i], f3 + a[i]);
        f2 = max(f2, f1) + x * a[i];
        f1 = f1 + a[i];
        f1 = max(0ll, f1);
        f2 = max(0ll, f2);

        res = max(res, f1);
        res = max(res, f2);
        res = max(res, f3);
    }
    cout << res;
}

/**
TEST:

*/


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double

typedef pair<long long, long long> II;
typedef pair<long long, II> III;

const long long INF = (1 << 30) - 1;
const long long oo = (1ll << 62) - 1;
const long double PI = 3.1415926535898;

const long long N = 3 * 100000 + 5;

long long n, x;
long long a[N];
long long f1 = 0, f2 = 0, f3 = 0;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("SUMSEQ.inp", "r", stdin);
    //freopen("SUMSEQ.out", "w", stdout);
    cin >> n >> x;
    for(long long i = 1; i <= n; i++)
        cin >> a[i];
    long long res = 0;
    for(long long i = 1; i <= n; i++)
    {
        f3 = max(f2 + x * a[i], f1 + a[i]);
        f2 = max(f2, f1) + x * a[i];
        f1 = f1 + a[i];
        f1 = max(0ll, f1);
        f2 = max(0ll, f2);
        f3 = max(0ll, f3);

        res = max(res, f1);
        res = max(res, f2);
        res = max(res, f3);
    }
    cout << res;
}

/**
TEST:

*/


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

const int N = 300005;
ll f[N][3], a[N];
ll n, x;

void nhap()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}
void xuly()
{
    ll res = 0;
    for(int i = 1; i <= n; i++)
    {
        f[i][0] = max(max(f[i - 1][0] + a[i], a[i]), 0ll);
        f[i][1] = max(max(f[i - 1][0] + a[i] * x, f[i - 1][1] + a[i] * x), 0ll);
        f[i][2] = max(max(f[i - 1][1] + a[i] * x, f[i - 1][2] + a[i]), 0ll);
        for(int j = 0; j <= 2; j++)
            res = max(res, f[i][j]);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    nhap();
    xuly();
}


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

const int N = 300005;
ll a[N], l1[N], r[N], l2[N];
ll n, x;
int vt[N];

void nhap()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}
void xuly()
{
    memset(vt, -1, sizeof(vt));
    long long val1 = 0, val2 = 0, ans = 0, res = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += a[i];
        l1[i] = max(0ll, ans - val1);
        val1 = min(val1, ans);
    }
    val1 = 0, val2 = 0, ans = 0;
    int t = n;
    for(int i = n; i >= 1; i--)
    {
        ans += a[i];
        if(0ll < ans - val1)
        {
            r[i] = 0ll;
            vt[i] = i - 1;
        }
        else
        {
            r[i] = ans - val1;
            vt[i] = t;
        }
        r[i] = min(0ll, ans - val1);
        l2[i] = max(0ll, ans - val2);
        if(ans >= val1)
        {
            val1 = ans;
            t = i - 1;
        }
        val2 = min(val2, ans);
    }

    if(x  == 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res, l1[i]);
        cout << res;
        return;
    }
    if(x > 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res , l1[i]);
        res = res * x;
        cout << res;
        return;
    }
    if(x < 0)
    {
        for(int i = 0; i <= n; i++)
        {
            //cout << i << " " << l1[i]  << " "<<  r[i + 1] * x << " " << vt[i + 1] + 1 << endl;
            res = max(res, l1[i] + r[i + 1] * x + l2[vt[i + 1] + 1]);
        }
        for(int i = 1; i <= n; i++)
            res = max(res, l1[i]);
        cout << res;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    nhap();
    xuly();
}


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

const int N = 300005;
ll a[N], l1[N], r1[N], l2[N], r2[N];
ll n, x;

void nhap()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}
void xuly()
{
    long long val1 = 0, val2 = 0, ans = 0, res = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += a[i];
        l1[i] = max(0ll, ans - val1);
        r2[i] = min(0ll, ans - val2);
        val1 = min(val1, ans);
        val2 = max(val1, ans);
    }
    val1 = 0, val2 = 0, ans = 0;
    for(int i = n; i >= 1; i--)
    {
        ans += a[i];
        r1[i] = min(0ll, ans - val1);
        l2[i] = max(0ll, ans - val2);
        val1 = max(val1, ans);
        val2 = min(val2, ans);
    }

    if(x  == 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res, l1[i]);
        cout << res;
        return;
    }
    if(x > 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res , l1[i]);
        res = res * x;
        cout << res;
        return;
    }
    if(x < 0)
    {
        for(int i = 0; i <= n; i++)
        {
            res = max(res, l1[i] + r1[i + 1] * x);
            res = max(res, r2[i + 1] * x + l2[i + 2]);
        }
        cout << res;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    nhap();
    xuly();
}


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

const int N = 300005;
ll f[N][3], a[N];
ll n, x;

void nhap()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}
void xuly()
{
    ll res = 0;
    for(int i = 1; i <= n; i++)
    {
        f[i][0] = max(max(f[i - 1][0] + a[i], a[i]), 0ll);
        f[i][1] = max(max(f[i - 1][0] + a[i] * x, f[i - 1][1] + a[i] * x), a[i]);
        f[i][2] = max(max(f[i - 1][1] + a[i], f[i - 1][2] + a[i]), a[i]);
        for(int j = 0; j <= 2; j++)
            res = max(res, f[i][j]);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    nhap();
    xuly();
}