#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int l, r;

int v[300005];
long long sp[300005], mn[300005];

long long sum(int ok, int st, int dr) {
  long long s = 0, mx = 0, a = 1, b = 0;
  for(int i = st; i <= dr; i++) {
    if(s >= 0) {
      s += v[i];
      if(ok)
        b++;
    } else {
      s = v[i];
      if(ok)
        a = b = i;
    }
    if(s > mx) {
      if(ok)
        l = a, r = b;
      mx = s;
    }
  }
  return mx;
}

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  if(k > 0) {
    cout << sum(1, 1, n) * k;
    return 0;
  }
  long long val = sum(1, 1, n), val2;
  for(int i = 1; i <= n; i++) {
    v[i] *= -1;
    sp[i] = sp[i - 1] + v[i];
    mn[i] = min(mn[i - 1], sp[i]);
  }
  long long s1 = 0, s2 = 0;
  for(int i = l - 1; i >= 1; i--)
    s1 = max(s1, -mn[i] + sp[l - 1]);
  for(int i = n; i >= 1; i--)
    mn[i] = max(mn[i + 1], sp[i]);
  for(int i = r + 1; i <= n; i++)
    s2 = max(s2, mn[i] - sp[r]);
  val2 = -sum(0, 1, n) * k;
  cout << max(val2, val - k * max(s1, s2));
  return 0;
}


#include <iostream>

using namespace std;

int n;

string s, a;
int f[100005];

int main() {
  cin >> n >> s;
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == '8')
      cnt++;
  }
  if(cnt <= (n - 11) / 2) {
    cout << "NO";
    return 0;
  }
  int p2 = 0, val = (n - 11) / 2;
  while(val) {
    while(s[p2] != '8' && p2 < n)
      p2++;
    f[p2] = 1;
    p2++;
    val--;
  }
  for(int i = 0; i < n; i++) {
    if(f[i] == 0) {
      val++;
      if(val > (n - 11) / 2) {
        cout << (s[i] == '8' ? "YES" : "NO");
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}


#include <iostream>

using namespace std;

int n, x;
long long sol;

int v[300005];
long long dp[300005][3];

int main() {
  cin >> n >> x;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  for(int i = 1; i <= n; i++) {
    dp[i][0] = v[i] + max(dp[i - 1][0], 0LL);
    dp[i][1] = max(0LL, max(dp[i - 1][2], dp[i - 1][1])) + v[i];
    dp[i][2] = 1LL * x * v[i] + max(max(dp[i - 1][0], dp[i - 1][2]), 0LL);
  }
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 3; j++)
      sol = max(sol, dp[i][j]);
  }
  cout << sol;
  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int l, r;

int v[100005];

long long sum(int ok, int st, int dr) {
  long long s = 0, mx = 0, a = 1, b = 0;
  for(int i = st; i <= dr; i++) {
    if(s >= 0) {
      s += v[i];
      if(ok)
      b++;
    } else {
      s = v[i];
      if(ok)
      a = b = i;
    }
    if(s > mx) {
      l = a; r = b; mx = s;
    }
  }
  return mx;
}

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  if(k > 0) {
    cout << sum(1, 1, n) * k;
    return 0;
  }
  long long val = sum(1, 1, n), val2;
  for(int i = 1; i <= n; i++)
    v[i] *= -1;
  val2 = -sum(0, 1, n) * k;
  cout << max(val2, val + -1LL * k * max(sum(0, 1, l - 1), sum(0, r + 1, n)));
  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int l, r;

int v[300005];

long long sum(int ok, int st, int dr) {
  long long s = 0, mx = 0, a = 1, b = 0;
  for(int i = st; i <= dr; i++) {
    if(s >= 0) {
      s += v[i];
      if(ok)
        b++;
    } else {
      s = v[i];
      if(ok)
        a = b = i;
    }
    if(s > mx) {
      if(ok)
        l = a, r = b;
      mx = s;
    }
  }
  return mx;
}

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  if(k > 0) {
    cout << sum(1, 1, n) * k;
    return 0;
  }
  long long val = sum(1, 1, n), val2;
  for(int i = 1; i <= n; i++)
    v[i] *= -1;
  val2 = -sum(0, 1, n) * k;
  long long s1 = 0, s2 = 0, s = 0;
  for(int i = l - 1; i >= 1; i--) {
    s += v[i];
    s1 = max(s1, s);
  }
  s = 0;
  for(int i = r + 1; i <= n; i++) {
    s += v[i];
    s2 = max(s2, s);
  }
  cout << max(val2, val - k * max(s1, s2));
  return 0;
}


#include <iostream>

using namespace std;

int n, x;
long long sol;

int v[300005];
long long dp[300005][3];

int main() {
  cin >> n >> x;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  for(int i = 1; i <= n; i++) {
    dp[i][0] = v[i] + max(dp[i - 1][0], 0LL);
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][1] + v[i]);
    dp[i][2] = x * v[i] + max(dp[i - 1][0], dp[i - 1][2]);
  }
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 3; j++)
      sol = max(sol, dp[i][j]);
  }
  cout << sol;
  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int l, r;

int v[300005];
long long sp[300005];

long long sum(int ok, int st, int dr) {
  long long s = 0, mx = 0, a = 1, b = 0;
  for(int i = st; i <= dr; i++) {
    if(s >= 0) {
      s += v[i];
      if(ok)
        b++;
    } else {
      s = v[i];
      if(ok)
        a = b = i;
    }
    if(s > mx) {
      if(ok)
        l = a, r = b;
      mx = s;
    }
  }
  return mx;
}

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  if(k > 0) {
    cout << sum(1, 1, n) * k;
    return 0;
  }
  long long val = sum(1, 1, n), val2;
  for(int i = 1; i <= n; i++) {
    v[i] *= -1;
    sp[i] = sp[i - 1] + v[i];
  }
  long long s1 = 0, s2 = 0;
  for(int i = l - 1; i >= 1; i--)
    s1 = max(s1, sp[l - 1]);
  for(int i = r + 1; i <= n; i++)
    s2 = max(s2, sp[n] - sp[i - 1]);
  val2 = -sum(0, 1, n) * k;
  cout << max(val2, val - k * max(s1, s2));
  return 0;
}


#include <iostream>

using namespace std;

int n;

string s, a;
int f[100005];

int main() {
  cin >> n >> s;
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == '8') {
      cnt++;
      if(cnt <= (n - 11) / 2)
        f[i] = 1;
    }
  }
  if(cnt <= (n - 11) / 2) {
    cout << "NO";
    return 0;
  }
  cnt = 0;
  for(int i = 0; i < n; i++) {
    if(f[i] == 0) {
      cnt++;
      if(cnt > (n - 11) / 2) {
        if(s[i] == '8')
          cout << "YES";
        else
          cout << "NO";
        return 0;
      }
    }
  }
  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int l, r;

int v[300005];

long long sum(int ok, int st, int dr) {
  long long s = 0, mx = 0, a = 1, b = 0;
  for(int i = st; i <= dr; i++) {
    if(s >= 0) {
      s += v[i];
      if(ok)
        b++;
    } else {
      s = v[i];
      if(ok)
        a = b = i;
    }
    if(s > mx) {
      l = a; r = b; mx = s;
    }
  }
  return mx;
}

int main() {
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  if(k > 0) {
    cout << sum(1, 1, n) * k;
    return 0;
  }
  long long val = sum(1, 1, n), val2;
  for(int i = 1; i <= n; i++)
    v[i] *= -1;
  val2 = -sum(0, 1, n) * k;
  cout << max(val2, val - k * max(sum(0, 1, l - 1), sum(0, r + 1, n)));
  return 0;
}


#include <iostream>

using namespace std;

int n, x;
long long sol;

int v[300005];
long long dp[300005][3];

int main() {
  cin >> n >> x;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  for(int i = 1; i <= n; i++) {
    dp[i][0] = v[i] + max(dp[i - 1][0], 0LL);
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][1] + v[i]);
    dp[i][2] = 1LL * x * v[i] + max(dp[i - 1][0], dp[i - 1][2]);
  }
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 3; j++)
      sol = max(sol, dp[i][j]);
  }
  cout << sol;
  return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){

	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);

	 	s1[i] = max(s,max(a[i],(ll)0));
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	s2[i] = max(s,max(a[i],(ll)0));
	 	if(s<0) s = 0;
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(i>=1) ans = max(ans,b[i]+s1[i-1]+s2[i+1]);
	 	else ans = max(ans,b[i]+s2[i+1]);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<=0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);
	 	if(s>=0) s1[i] = s;
	 	else s1[i] = 0;
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	if(s>=0) s2[i] = s;
	 	else s2[i] = 0;
	 	if(s<0) s = 0;
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);
	 	if(s>=0) s1[i] = s;
	 	else s1[i] = 0;
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	if(s>=0) s2[i] = s;
	 	else s2[i] = 0;
	 	if(s<0) s = 0;
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<=0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){

	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);

	 	s1[i] = max(s,max(a[i],(ll)0));
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	s2[i] = max(s,max(a[i],(ll)0));
	 	if(s<0) s = 0;
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<=0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){

	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);
	 	if(s>=0) s1[i] = s;
	 	else s1[i] = max(a[i],(ll)0);
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	if(s>=0) s2[i] = s;
	 	else s2[i] = 0;
	 	if(s<0) s = max(a[i],(ll)0);
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<=0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);
	 	if(s>=0) s1[i] = s;
	 	else s1[i] = 0;
	 	if(s<0) s = 0;

	 }

	 s=0;
	 ll idx = 0;

	 rep(i,0,n){
	 	s+=b[i];
	 	ans = max(ans,s+max(s1[idx],(ll)0));

	 	if(s<0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){

	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s2[n+1];
	 ll s = 0;
	 ll ans = -inf;
	 rep(i,0,n){
	 	s+=a[i];
	 	ans = max(ans,s);
	 	if(s>=0) s1[i] = s;
	 	else s1[i] = 0;
	 	if(s<0) s = 0;

	 }

	 s=0;
	 rrep(i,n-1,0){
	 	s+=a[i];
	 	if(s>=0) s2[i] = s;
	 	else s2[i] = 0;
	 	if(s<0) s = 0;
	 }
	 s2[n] = 0;
	 ll idx = -1;
	s = 0;
	 rep(i,0,n){
	 	s+=b[i];
	 	//cout<<s<<endl;
	 	ans = max(ans,s);
	 	if(idx!=-1) ans = max(ans,s+s1[idx]+s2[i+1]);

	 	if(s<=0) s = 0,idx = i;
	 }
	 if(ans<=0) cout<<0;
	 else cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s = 0;
	 rep(i,0,n){
	 	s+=a[i];
	 	s1[i] = s;
	 	if(s<0) s = 0;
	 }
	 ll ans = s;
	 s=0;
	 ll idx = 0;

	 rep(i,0,n){
	 	s+=b[i];
	 	ans = max(ans,s+max(s1[idx],(ll)0));

	 	if(s<0) s = 0,idx = i;
	 }
	 cout<<ans;

}


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

#define ll long long
#define ld long double
#define pb push_back

#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
	 ll n,x;
	 cin>>n>>x;
	 ll a[n];
	 ll b[n];
	 rep(i,0,n) cin>>a[i],b[i] = x*a[i];

	 ll s1[n];
	 ll s = 0;
	 rep(i,0,n){
	 	s+=a[i];
	 	s1[i] = s;
	 	if(s<0) s = 0;
	 }
	 ll ans = s;
	 s=0;
	 ll idx = 0;

	 rep(i,0,n){
	 	s+=b[i];
	 	if(s1[idx]>0 && s>0){
	 		ans = max(ans,s+s1[idx]);
	 	}
	 	if(s<0) s = 0,idx = i;
	 }
	 cout<<ans;

}


#include <bits/stdc++.h>
#define TASK "something"
#define int long long
using namespace std;

const int N = 3e5 + 5;
int n, a[N], s[N], x;

int Left[N], Right[N];
int last_solve() {
	for (int i = 1; i <= n; i++)
		s[i] = s[i-1] + a[i];
	int smin = 0;
	for (int i = 1; i <= n; i++) {
		smin = min (s[i], smin);
		Left[i] = max (0LL, s[i] - smin);
	}
	int smax = s[n];
	for (int i = n; i >= 1; i--) {
		smax = max (s[i], smax);
		Right[i] = max (0LL, smax - s[i-1]);
	}
	int res = 0, best = 0;
	for (int i = 1; i <= n; i++) {
		res = max (res, x * s[i] + Right[i+1] + best);
		res = max (res, Left[i]);
		best = max (best, Left[i] - x * s[i]);
	}
	return res;
}

#undef int
int main() {
#define int long long
	ios :: sync_with_stdio(0);
	cin.tie (0); cout.tie (0);

	if (fopen ("main.in", "r"))
		freopen ("main.in", "r", stdin);
	else if (fopen (TASK".inp", "r"))
		freopen (TASK".inp", "r", stdin),
		freopen (TASK".out", "w", stdout);

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

	int res = last_solve();

	cout << res << '\n';

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n]={0},arrcum[n]={0};
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;

				continue;
			}

			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		ll min=0;
		for(int i=0;i<size;i++){
			if(arrcum[i]<min)
			min=arrcum[i];
			arrcum[i]-=min;
		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	int n,k,x,temp=0,max=0,ans=0,size=0,flag=0;
	cin>>n>>k;
	ll arr[n];
	if(k>=0) {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(int i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}
		arr[size]=temp;
		size++;
		temp=0;
		max=0;
		for(int i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				ans=arr[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+arr[i+1]<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+arr[i+1];
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				arrcum[i]=x;
				continue;
			}
			arrcum[i]=x+arrcum[i-1];
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		ll min=0;
		for(int i=0;i<size;i++){
			if(arrcum[i]<min)
			min=arrcum[i];
			arrcum[i]-=min;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		for(int i=0;i<size;i++){
			if(arr[i]>0)
			temp+=arr[i];
			if(temp>max)
			max=temp;
			arrcum[i]=max;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;

				continue;
			}
			arrcum[i]=x+arrcum[i-1];
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		ll min=0;
		for(int i=0;i<size;i++){
			if(arrcum[i]<min)
			min=arrcum[i];
			arrcum[i]-=min;
		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		for(int i=0;i<size;i++){
			temp+=arr[i];
			if(temp>max)
			max=temp;
			if(max>arr[i])
			arrcum[i]=max;
			else
			arrcum[i]=arr[i];

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				arrcum[i]=x;
				continue;
			}
			arrcum[i]=x+arrcum[i];
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		ll min=0
		for(int i=0;i<size;i++){
			if(arrcum[i]<min)
			min=arrcum[i];
			arrcum[i]-=min;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0,min=0;
	cin>>n>>k;
	ll arr[n]={0},arrcum[n]={0};
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {
			if(arr[i]-min>max)
			max=arr[i]-min;
			if(arr[i]<min)
			min=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;

				continue;
			}

			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arrcum[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		min=0;
		for(int i=0;i<size;i++){
			x=arrcum[i];
			arrcum[i]-=min;
			if(x<min)
			min=x;

			//cout<<"cum is"<<arrcum[i];
		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				//cout<<"cum is"<<arrcum[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
			//cout<<"temp is"<<temp<<" "<<temp1<<" "<<max<<'\n';
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0;
	cin>>n>>k;
	ll arr[n];
	if(k>=0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}
		arr[size]=temp;
		size++;
		temp=0;
		max=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				ans=arr[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+arr[i+1]<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+arr[i+1];
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		for(int i=0;i<size;i++){
			temp+=arr[i];
			if(temp>max)
			max=temp;
			if(max<arr[i]){

				max=arr[i];
			}

			arrcum[i]=max;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0,min=0;
	cin>>n>>k;
	ll arr[n]={0},arrcum[n]={0};
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {
			if(arr[i]<min)
			min=arr[i];
			if(arr[i]-min>max)
			max=arr[i]-min;

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;

				continue;
			}

			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					if(size==0)
					arrcum[size]=temp;
					else
					arrcum[size]=arrcum[size-1]+temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		min=0;
		for(int i=0;i<size;i++){
			if(arrcum[i]<min)
			min=arrcum[i];
			arrcum[i]-=min;
		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arr[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		for(int i=0;i<size;i++){
			temp+=arr[i];
			if(temp>max)
			max=temp;
			arrcum[i]=max;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0;
	cin>>n>>k;
	ll arr[n];
	if(k>=0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}
		arr[size]=temp;
		size++;
		temp=0;
		max=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(arr[i]>max)
				max=arr[i];
				ans=arr[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+arr[i+1]<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+arr[i+1];
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,k,x,temp=0,max=0,ans=0,size=0,flag=0,temp1=0;
	cin>>n>>k;
	ll arr[n],arrcum[n];
	if(k>0) {
		for(ll i=0; i<n; i++) {
			cin>>x;
			if(i==0)
				arr[i]=x;
			else
				arr[i]=arr[i-1]+x;
		}
		max=0;
		for(ll i=0; i<n; i++) {

				if(arr[i]>max)
					max=arr[i];

		}
		if(k!=0)
		cout<<k*max;
		else
		cout<<max;
	} else {
		for(int i=0; i<n; i++) {
			cin>>x;
			if(i==0) {
				if(x>0)
					flag=0;
				else
					flag=1;
				temp=x;
				continue;
			}
			if(x>0) {
				if(flag==0)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=0;
				}
			} else {
				if(flag==1)
					temp+=x;
				else {
					arr[size]=temp;
					size++;
					temp=x;
					flag=1;
				}
			}
		}

		arr[size]=temp;
		size++;
//		for(int i=0;i<size;i++)
//		cout<<arr[i]<<" ";
//		cout<<"\n";
		temp=0;max=0;
		for(int i=0;i<size;i++){
			temp+=arr[i];
			if(temp>max)
			max=temp;
			if(max<arr[i]){

				max=arr[i];
				temp=max;
			}

			arrcum[i]=max;

		}
		temp=0;
		max=0;
		temp1=0;
		for(ll i=size-1; i>=0; i--) {
			if(arr[i]>0) {
				if(i==size-1||i==size-2)
				temp1=arr[i];

				else if(arr[i]+arr[i+1]+temp1>arr[i]){
						temp1=arr[i]+arr[i+1]+temp1;
					}
					else{
						temp1=arr[i];
					}

				if(temp1>max)
				max=temp1;
				if(arr[i]>max)
				max=arr[i];
				ans=arrcum[i]+temp;
				if(ans>max)
					max=ans;
			} else {
				if(i==size-1)
				{
					temp=k*arr[i];
					if(temp>max){
						max=temp;
					}

				}
				else if(k*arr[i]+temp1<k*(arr[i]+arr[i+1])+temp) {
					temp=k*(arr[i]+arr[i+1])+temp;
					if(temp>max)
					max=temp;
				} else
				{
					temp=k*arr[i]+temp1;
					if(temp>max)
					max=temp;
				}
			}
		}

		cout<<max;

	}

	//input

}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )
    {
         cin>>a[i];
    }
    ll ans=0;
        ll f[n],b[n], pre[n], suf[n],  sum[n];
        f[0]=a[0];
        b[n-1]=a[n-1];

        sum[0]=a[0];
        for(ll i=1;i<n;++i)
        {
            sum[i]=sum[i-1]+a[i];
        }
        pre[0]=f[0]-(x*sum[0]);
        suf[n-1]=x*sum[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(a[i], f[i-1]+a[i]);
       pre[i]=max(pre[i-1], f[i]- (x*sum[i]));
   }
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(a[i], b[i+1]+a[i]);
       suf[i]=max(suf[i+1],b[i+1]+ (x*sum[i]));
   }
   ans=max((ll)0, suf[0]);
   for(ll i=0; i<n;++i)
   {
       ans= max(ans, pre[i]+ suf[i]);
   }
    cout<<ans;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )cin  >> a[i];
    if(x>0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else
    {
        ll go[n],kad1[n],kad2[n],kad3[n],l[n];
        for(ll i=0;i<n;++i) go[i]=x*a[i];
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        for(ll i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
        }
        ll ans= max((ll)0,kad2[0]);
        for(ll i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(ll i=n-2;i>=0;--i) kad3[i]=max(a[i], kad3[i+1]+a[i]);

        for(ll i=0;i<n;++i)
        {
            ll c= kad1[i];
            if(i+1<n)c+=kad3[i+1];
            if(l[i]-1>=0)c+=kad2[l[i]-1];
            ans =max(c,ans);
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    vector<ll> a;
    for( ll i=0; i<n; ++i )
    {
        ll x; cin>>x;
        if(x!=0)a.push_back(x);
    }
    if(a.size()==0)
    {
        cout<<0;
        return 0;
    }
    n=a.size();

    if(x==0)
    {
        ll ans=0;
        ll f[n],b[n], pre[n], suf[n];
        f[0]=a[0];
        b[n-1]=a[n-1];
        pre[0]=f[0];
        suf[n-1]=b[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(a[i], f[i-1]+a[i]);
       ans= max(ans, f[i]);
       pre[i]=max(pre[i-1], f[i]);
   }
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(a[i], b[i+1]+a[i]);
       suf[i]=max(suf[i+1],b[i]);
   }

   for(ll i=1; i<n;++i)
   {
       ans= max(ans, pre[i-1]+ suf[i]);
   }
    cout<<ans;
    }
    else if(x>0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else if (x<0)
    {
        ll go[n],kad1[n],kad2[n],kad3[n],l[n];
        for(ll i=0;i<n;++i) go[i]=x*a[i];
        l[0]=0;
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        for(ll i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
        }
        ll ans= max((ll)0,kad2[0]);
        for(ll i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(ll i=n-2;i>=0;--i) kad3[i]=max(a[i], kad3[i+1]+a[i]);
        for(ll i=0;i<n;++i)
        {
            ll c= kad1[i];
            if(i+1<n)c+=kad3[i+1];
            if(l[i]-1>=0)c+=kad2[l[i]-1];
            ans =max(c,ans);
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )
    {
         cin>>a[i];
    }
    ll ans=max((ll)0,a[0]);
        ll f[n],b[n], pre[n], suf[n],  sum[n];
        f[0]=a[0];
        b[n-1]=a[n-1];
        sum[0]=a[0];
        for(ll i=1;i<n;++i)
        {
            sum[i]=sum[i-1]+a[i];
        }
        pre[0]=f[0]-(x*sum[0]);
        suf[n-1]=x*sum[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(a[i], f[i-1]+a[i]);
       pre[i]=max(pre[i-1], f[i]- (x*sum[i]));
       ans=max(ans,f[i]);
   }
   ans=max(x*ans, ans);
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(a[i], b[i+1]+a[i]);
       suf[i]=max(suf[i+1],b[i+1]+ (x*sum[i]));
   }
   for(ll i=0; i<n;++i)
   {
       ans= max(ans, pre[i]+ suf[i]);
   }
    cout<<ans;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )
    {
         cin>>a[i];
    }
    ll ans=0;
        ll f[n],b[n], pre[n], suf[n],  sum[n];
        f[0]=a[0];
        b[n-1]=a[n-1];

        sum[0]=a[0];
        for(ll i=1;i<n;++i)
        {
            sum[i]=sum[i-1]+a[i];
        }
        pre[0]=f[0]-(x*sum[0]);
        suf[n-1]=x*sum[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(a[i], f[i-1]+a[i]);
       pre[i]=max(pre[i-1], f[i]- (x*sum[i]));
   }
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(a[i], b[i+1]+a[i]);
       suf[i]=max(suf[i+1],b[i+1]+ (x*sum[i]));
   }

   for(ll i=0; i<n;++i)
   {
       ans= max(ans, pre[i]+ suf[i]);
   }
    cout<<ans;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )cin  >> a[i];
    if(x==0)
    {
        deque<ll>compr;
        for(ll i=0;i<n;++i)
        {
            if(compr.empty() || ((compr.back()^a[i])<0))compr.push_back(a[i]);
            else
            {
                ll x= compr.back()+a[i];
                compr.pop_back();
                compr.push_back(x);
            }
        }
        n=compr.size();
        ll ans=0;
        ll f[n],b[n];
        f[0]=compr[0];
        b[n-1]=compr[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(compr[i], f[i-1]+compr[i]);
       ans= max(ans, f[i]);
   }
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(compr[i], b[i+1]+compr[i]);
   }

   for(ll i=1; i<n-1;++i)
   {
       ans= max(ans, f[i-1]+ b[i+1]);
   }
    cout<<ans;
    }
    else if(x>0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else if (x<0)
    {
        ll go[n],kad1[n],kad2[n],kad3[n],l[n];
        for(ll i=0;i<n;++i) go[i]=x*a[i];
        l[0]=0;
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        for(ll i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
        }
        ll ans= max((ll)0,kad2[0]);
        for(ll i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(ll i=n-2;i>=0;--i) kad3[i]=max(a[i], kad3[i+1]+a[i]);
        for(ll i=0;i<n;++i)
        {
            ll c= kad1[i];
            if(i+1<n)c+=kad3[i+1];
            if(l[i]-1>=0)c+=kad2[l[i]-1];
            ans =max(c,ans);
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )cin  >> a[i];
    if(x>=0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else
    {
        int go[n], l[n],r[n];
        for(int i=0;i<n;++i)
        {
            go[i]=x*a[i];
        }
        l[0]=0; r[0]=0;
        int kad1[n],kad2[n],kad3[n];
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        int pre[n],suf[n];
        for(int i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
            r[i]=i;
            //cout<<l[i]<<" ";
        }
        int ans= max(0,kad2[0]);
        for(int i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(int i=n-2;i>=0;--i)
        {
            kad3[i]=max(a[i], kad3[i+1]+a[i]);
        }
        pre[0]=kad2[0];
        suf[n-1]=kad2[n-1];
        for(int i=1;i<n;++i) pre[i]=max(pre[i-1],kad2[i]);
        for(int i=n-2;i>=0;--i) suf[i]=max(suf[i+1],kad2[i]);

        for(int i=0;i<n;++i)
        {
            int c= kad1[i];
           // cout<<kad1[i]<<" ";
            if(i+1<n)c+=kad3[i+1];
         //  cout<<kad2[l[i]-1]<<" ";
            if(l[i]-1>=0)c+=kad2[l[i]-1];
         //   cout<<kad3[i+1]<<" ";
        //    cout<<"\n";
            ans =max(c,ans);
        }
        cout<<ans;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )cin  >> a[i];
    if(x==0)
    {
        deque<ll>compr;
        for(ll i=0;i<n;++i)
        {
            if(compr.empty() || ((compr.back()^a[i])<0))compr.push_back(a[i]);
            else
            {
                ll x= compr.back()+a[i];
                compr.pop_back();
                compr.push_back(x);
            }
        }
        n=compr.size();
        ll ans=0;
        ll st=0;
        if(compr[0]<0)
        {
            st++;
            if(n>1)
            ans=compr[1];
        }
        else ans=compr[0];
        for(int i=st ;i<n-2; i+=2)
        {
            ans=max(compr[i]+compr[i+2], ans);
        }
        cout<<ans;
    }
    else if(x>0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else if (x<0)
    {
        ll go[n],kad1[n],kad2[n],kad3[n],l[n];
        for(ll i=0;i<n;++i) go[i]=x*a[i];
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        for(ll i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
        }
        ll ans= max((ll)0,kad2[0]);
        for(ll i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(ll i=n-2;i>=0;--i) kad3[i]=max(a[i], kad3[i+1]+a[i]);
        for(ll i=0;i<n;++i)
        {
            ll c= kad1[i];
            if(i+1<n)c+=kad3[i+1];
            if(l[i]-1>=0)c+=kad2[l[i]-1];
            ans =max(c,ans);
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )cin  >> a[i];
    if(x==0)
    {
        deque<ll>compr;
        for(ll i=0;i<n;++i)
        {
            if(compr.empty() || ((compr.back()^a[i])<0))compr.push_back(a[i]);
            else
            {
                ll x= compr.back()+a[i];
                compr.pop_back();
                compr.push_back(x);
            }
        }
        n=compr.size();
        ll ans=0;
        ll f[n],b[n];
        f[0]=compr[0];
        b[n-1]=compr[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(compr[i], f[i-1]+compr[i]);
       ans= max(ans, f[i]);
   }
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(compr[i], b[i+1]+compr[i]);
   }

   for(ll i=1; i<n-1;++i)
   {
       ans= max(ans, f[i-1]+ b[i+1]);
   }
   cout<<ans;
    }
    else if(x>0)
    {
        ll kad[n+1];  kad[0]=-1e15;
        ll ans=-1e15;
        for(ll i=0;i<n;++i)
        {
            kad[i+1]=max(a[i], kad[i]+a[i]);
            ans=max(kad[i+1],ans);
        }
        ans=max(ans*x,ans);
        ans=max((ll)0,ans);
        cout<<ans;
    }
    else if (x<0)
    {
        ll go[n],kad1[n],kad2[n],kad3[n],l[n];
        for(ll i=0;i<n;++i) go[i]=x*a[i];
        kad1[0]=go[0];
        kad2[0]=a[0];
        kad3[n-1]=a[n-1];
        for(ll i=1;i<n;++i)
        {
            kad1[i]=max(go[i], kad1[i-1]+go[i]);
            if(go[i]>=kad1[i-1]+go[i])l[i]=i;
            else l[i]=l[i-1];
        }
        ll ans= max((ll)0,kad2[0]);
        for(ll i=1;i<n;++i)
        {
            kad2[i]=max(a[i], kad2[i-1]+a[i]);
            ans=max(kad2[i],ans);
        }
        for(ll i=n-2;i>=0;--i) kad3[i]=max(a[i], kad3[i+1]+a[i]);
        for(ll i=0;i<n;++i)
        {
            ll c= kad1[i];
            if(i+1<n)c+=kad3[i+1];
            if(l[i]-1>=0)c+=kad2[l[i]-1];
            ans =max(c,ans);
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod= 1e9+7;

int main( )
{
    ll n,x;  cin>>n>>x;
    ll a[n];
    for( ll i=0; i<n; ++i )
    {
         cin>>a[i];
    }
    ll ans=max((ll)0,a[0]);
        ll f[n],b[n], pre[n], suf[n],  sum[n];
        f[0]=a[0];
        b[n-1]=a[n-1];
        sum[0]=a[0];
        for(ll i=1;i<n;++i)
        {
            sum[i]=sum[i-1]+a[i];
        }
        pre[0]=f[0]-(x*sum[0]);
        suf[n-1]=x*sum[n-1];
   for(ll i=1;i<n;++i)
   {
       f[i]=max(a[i], f[i-1]+a[i]);
       pre[i]=max(pre[i-1], f[i]- (x*sum[i]));
       ans=max(ans,f[i]);
   }
   ans=max(x*ans, ans);
   for(ll i=n-2;i>=0;--i)
   {
       b[i]=max(a[i], b[i+1]+a[i]);
       suf[i]=max(suf[i+1],b[i+1]+ (x*sum[i]));
   }
   ans=max(ans,suf[0]);
   for(ll i=0; i<n;++i)
   {
       ans= max(ans, pre[i]+ suf[i]);
   }
    cout<<ans;
}


#include <bits/stdc++.h>
#define O2 __attribute__((optimize("O2")))
using namespace std ;
int n,m, k ;
const int MAXN (3000005) ;
const int64_t INF (0x7f7f7f7f7f7f7f7f) ;

int  a[MAXN];
int64_t sum[MAXN] ;

O2 int64_t fen(int l,int r,int &ll,int &rr)
{
	if(l == r) {
		ll = rr = l ;
		return a[l] ;
	}
	int mid((l+r)>>1) ;
	int L1(0),R1(0),L2(0),R2(0),L3(0),R3(0) ;
	int64_t lans = fen(l,mid,L1,R1) ;
	int64_t rans = fen(mid+1,r,L2,R2) ;
	int64_t maxL(-INF),maxR(-INF) ;
	for(register int i(mid);i>=l;--i) {
		if(sum[mid]-sum[i-1]>=maxL) {
			maxL = sum[mid]-sum[i-1] ;
			L3 = i ;
		}
	}
	for(register int i(mid+1);i<=r;++i) {
		if(sum[i]-sum[mid-1]>=maxL) {
			maxR = sum[i]-sum[mid] ;
			R3 = i ;
		}
	}
	ll = L3,rr = R3 ;
	int64_t ans(maxL+maxR) ;
	if(lans>=ans) {
		ll = L1;rr = R1 ;
		ans = lans ;
	}
	if(rans>=ans) {
		ll = L2;rr = R2 ;
		ans = rans ;
	}
	return ans ;
}

O2 int main()
{
	//ios::sync_with_stdio(false) ;
	int64_t SUM(0) ;
	scanf("%d%d",&n,&m) ;
	//scan_d(n);scan_d(m) ;
 	for(int i(1);i<=n;++i) {
		scanf("%d",a+i) ;
		//scan_d(a[i]) ;
		SUM += a[i] ;
		sum[i] = sum[i-1] + m*a[i] ;
	}
	int L(0),R(0) ;
	int64_t ans = fen(1,n,L,R) ;
	//printf("[%d,%d]:%lld\n",L,R,ans) ;
	//cout<<SUM[n]<<"***"<<SUM[R]-SUM[L-1]<<endl;
	//printf("%lld\n",max(max(SUM[n]+ans-(SUM[R]-SUM[L-1]),SUM[n]),0LL)) ;
	for(int i(1);i<=n;++i) {
		if(i<=R&&i>=L)
			sum[i] = sum[i-1] + m*a[i] ;
		else
			sum[i] = sum[i-1] + a[i] ;
	}
	printf("%lld\n",max(max(fen(1,n,L,R),0LL),SUM)) ;
	return 0 ;
}


#include <bits/stdc++.h>
const int MAXN (1000005) ;
const int64_t INF = 0x3f3f3f3f3f3f3f3f3f ;
using namespace std ;

struct Node
{
	string name ;
	int d,c ;
};

vector<Node> node;
///int dp[1<<20];
int64_t dp[MAXN][5] ;
// 0: 前边不乘k,当前也不乘k
// 1: 前边乘k,当前不乘k
// 2: 前边不乘k,当前乘k
// 3: 前边乘k,当前乘k
int64_t arr[MAXN] ;

int main()
{
	int n,buff,k,t = 1 ;
	//cin >> t ;
	//while(t-->0)
	ios::sync_with_stdio(false) ;
	{
		cin >> n >>k;
		for(int i(1);i<=n;++i) {
			cin >>arr[i] ;
		}
		int64_t ans(0) ;
		for(int i(1);i<=n;++i) {
			dp[i][0] = max(dp[i-1][0],0LL) + arr[i] ;
			dp[i][1] = max(dp[i-1][2],dp[i-1][3]) + arr[i] ;
			dp[i][2] = dp[i-1][0] + arr[i]*k ;
			dp[i][3] = max(dp[i-1][2],dp[i-1][3]) + arr[i] * k ;
			ans = max({dp[i][0],dp[i][1],dp[i][2],dp[i][3]}) ;
		}
		cout<<max(0LL,ans)<<endl;
//		for(int i(1);i<=n;++i) {
//			string str ;
//			int d,c ;
//			cin >> str >> d >> c ;
//			node.push_back({str,d,c}) ;
//		}
	}
}


#include <bits/stdc++.h>
#define O2 __attribute__((optimize("O2")))
using namespace std ;
int n,m, k ;
const int MAXN (3000005) ;
const int64_t INF (0x7f7f7f7f7f7f7f7f) ;

int64_t  a[MAXN],sum[MAXN] ;

O2 int64_t fen(int l,int r,int &ll,int &rr)
{
	if(l == r) {
		ll = rr = l ;
		return a[l] ;
	}
	int mid((l+r)>>1) ;
	int L1(0),R1(0),L2(0),R2(0),L3(0),R3(0) ;
	int64_t lans = fen(l,mid,L1,R1) ;
	int64_t rans = fen(mid+1,r,L2,R2) ;
	int64_t maxL(-INF),maxR(-INF) ;
	for(int i(mid);i>=1;--i) {
		if(sum[mid]-sum[i-1]>=maxL) {
			maxL = sum[mid]-sum[i-1] ;
			L3 = i ;
		}
	}
	for(int i(mid+1);i<=n;++i) {
		if(sum[i]-sum[mid-1]>=maxL) {
			maxR = sum[i]-sum[mid] ;
			R3 = i ;
		}
	}
	ll = L3,rr = R3 ;
	int64_t ans(maxL+maxR) ;
	if(lans>=ans) {
		ll = L1;rr = R1 ;
		ans = lans ;
	}
	if(rans>=ans) {
		ll = L2;rr = R2 ;
		ans = rans ;
	}
	return ans ;
}
int64_t SUM[MAXN] ;

O2 int main()
{
	//ios::sync_with_stdio(false) ;
	int64_t SUM(0) ;
	scanf("%d%d",&n,&m) ;
 	for(int i(1);i<=n;++i) {
		scanf("%lld",a+i) ;
		SUM += a[i] ;
		sum[i] = sum[i-1] + m*a[i] ;
	}
	int L(0),R(0) ;
	int64_t ans = fen(1,n,L,R) ;
	//printf("[%d,%d]:%lld\n",L,R,ans) ;
	//cout<<SUM[n]<<"***"<<SUM[R]-SUM[L-1]<<endl;
	//printf("%lld\n",max(max(SUM[n]+ans-(SUM[R]-SUM[L-1]),SUM[n]),0LL)) ;
	for(int i(1);i<=n;++i) {
		if(i<=R&&i>=L)
			sum[i] = sum[i-1] + m*a[i] ;
		else
			sum[i] = sum[i-1] + a[i] ;
	}
	printf("%lld\n",max(max(fen(1,n,L,R),0LL),SUM)) ;
	return 0 ;
}


#include <bits/stdc++.h>
const int MAXN (1000005) ;
const int64_t INF = 0x3f3f3f3f3f3f3f3f3f ;
using namespace std ;

struct Node
{
	string name ;
	int d,c ;
};

vector<Node> node;
///int dp[1<<20];
int64_t dp[MAXN][5] ;
// 0: 当前不乘k,前边也不乘k
// 1: 当前不乘k,前边乘k
// 2: 当前乘k
int64_t arr[MAXN] ;

int main()
{
	int n,buff,k,t = 1 ;
	//cin >> t ;
	//while(t-->0)
	ios::sync_with_stdio(false) ;
	{
		cin >> n >>k;
		for(int i(1);i<=n;++i) {
			cin >>arr[i] ;
		}
		int64_t ans(0) ;
		for(int i(1);i<=n;++i) {
			dp[i][0] = max(dp[i-1][0],0LL)+arr[i] ;
			dp[i][1] = max({dp[i-1][2],dp[i-1][1],0LL})+arr[i] ;
			dp[i][2] = max({dp[i-1][2],dp[i-1][0],0LL})+arr[i]*k  ;
			ans = max({dp[i][0],dp[i][1],dp[i][2]}) ;
		}
		cout<<ans<<endl;
//		for(int i(1);i<=n;++i) {
//			string str ;
//			int d,c ;
//			cin >> str >> d >> c ;
//			node.push_back({str,d,c}) ;
//		}
	}
}


#include <bits/stdc++.h>
#define O2 __attribute__((optimize("O2")))
using namespace std ;
int64_t n,m, k ;
const int MAXN (3000005) ;
const int64_t INF (0x7f7f7f7f7f7f7f7f) ;

int64_t  a[MAXN],sum[MAXN] ;

O2 int64_t fen(int l,int r,int &ll,int &rr)
{
	if(l == r) {
		ll = rr = l ;
		return a[l] ;
	}
	int mid((l+r)>>1) ;
	int L1(0),R1(0),L2(0),R2(0),L3(0),R3(0) ;
	int64_t lans = fen(l,mid,L1,R1) ;
	int64_t rans = fen(mid+1,r,L2,R2) ;
	int64_t maxL(-INF),maxR(-INF) ;
	for(int i(mid);i>=l;--i) {
		if(sum[mid]-sum[i-1]>=maxL) {
			maxL = sum[mid]-sum[i-1] ;
			L3 = i ;
		}
	}
	for(int i(mid+1);i<=r;++i) {
		if(sum[i]-sum[mid-1]>=maxL) {
			maxR = sum[i]-sum[mid] ;
			R3 = i ;
		}
	}
	ll = L3,rr = R3 ;
	int64_t ans(maxL+maxR) ;
	if(lans>=ans) {
		ll = L1;rr = R1 ;
		ans = lans ;
	}
	if(rans>=ans) {
		ll = L2;rr = R2 ;
		ans = rans ;
	}
	return ans ;
}

inline bool scan_d(int64_t &num)
{
        char in;bool IsN=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;}
        else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){
                num*=10,num+=in-'0';
        }
        if(IsN) num=-num;
        return true;
}

O2 int main()
{
	//ios::sync_with_stdio(false) ;
	int64_t SUM(0) ;
	//scanf("%d%d",&n,&m) ;
	scan_d(n);scan_d(m) ;
 	for(int i(1);i<=n;++i) {
		//scanf("%lld",a+i) ;
		scan_d(a[i]) ;
		SUM += a[i] ;
		sum[i] = sum[i-1] + m*a[i] ;
	}
	int L(0),R(0) ;
	int64_t ans = fen(1,n,L,R) ;
	//printf("[%d,%d]:%lld\n",L,R,ans) ;
	//cout<<SUM[n]<<"***"<<SUM[R]-SUM[L-1]<<endl;
	//printf("%lld\n",max(max(SUM[n]+ans-(SUM[R]-SUM[L-1]),SUM[n]),0LL)) ;
	for(int i(1);i<=n;++i) {
		if(i<=R&&i>=L)
			sum[i] = sum[i-1] + m*a[i] ;
		else
			sum[i] = sum[i-1] + a[i] ;
	}
	printf("%lld\n",max(max(fen(1,n,L,R),0LL),SUM)) ;
	return 0 ;
}


#include <bits/stdc++.h>
#define TVVTEYYZQB *
#define CWBFRFAXJQ +
#define KXYKRFQVXY ++){
#define QBPBHHSJRU -
#define ZJERMVFLZP 0){dp[i][j]
#define VVJMPJZJKY 0;
#define OCUDMUQZLC 0;j
#define TKNLLFXQBB 1){dp[i][j]
#define NXBTTXPNTD 1;i
#define ZQBDRAJWVB 1]
#define PUPUSJZGRX 1][j
#define RLDTJYNGJR 1][j]
#define YFJOCRKSBY 2){dp[i][j]
#define ZOCFGPOOSJ 3;j
#define EEFJGSITMH ;
#define BNNXLUMFCM <
#define IUYYTJNJQS <<
#define ZAXBLRXKHI <=
#define XHMRLGEIKZ =
#define EQVBWTRFFN ==
#define NRKBZKLNSX >>
#define FJUIQONEUF a[300005];
#define PKJSLMNBAN a[i]
#define CWZFUQJYSB a[i]);
#define QYMHXSPYRJ a[i],a[i]);}
#define ISRRHSHFQT a[i],dp[i
#define QWZRZUGCLN ans
#define ELKMLFSRKU cin
#define CHRCQMWHUF cout
#define KLIBKOHAXO dp[300005][4];
#define EOXCYHWXSG dp[i][j]
#define FAELDPXTEK endl;
#define ESDZHRVSPE for(int
#define QEGJADFMZC i
#define WGWMMMEUVK if(j
#define VBCJPQOOFE int
#define YXSDUTRZTK j
#define CCWQECFBUC long
#define PZNKWNFSZI main()
#define ZQDTDAZEAQ max(dp[i
#define KZHZVPCYXB max(dp[i][0],dp[i][1]);
#define BOBGUTDJLO max(dp[i][j],a[i]
#define VLNWOEFPGP max(dp[i][j],a[i]);}
#define GBEHMSBXQA max(res,ans);
#define QQDNCQNLCE max(res,dp[i][2]);
#define FTEONXIJND memset(dp,0,sizeof(dp));
#define NUZJOJKZVM n
#define NHJHCNHYNG n;
#define XRZUJPARQL n;i
#define QMGTUELUHR namespace
#define GAZEOZYLAF res
#define DYPTJSEKDX return
#define ETYXOTDMEO std;
#define VSYQZPYLQP using
#define SZSSCOTUOW x);
#define SWYPSAFVPT x);}
#define VZRXEPMFCO x,dp[i
#define SADFFYQYBS x;
#define EIDWLBQIQW {
#define MSBVPFNLCA }
VSYQZPYLQP
QMGTUELUHR
ETYXOTDMEO
CCWQECFBUC
CCWQECFBUC
FJUIQONEUF
CCWQECFBUC
CCWQECFBUC
KLIBKOHAXO
VBCJPQOOFE
PZNKWNFSZI
EIDWLBQIQW
VBCJPQOOFE
NHJHCNHYNG
CCWQECFBUC
CCWQECFBUC
SADFFYQYBS
ELKMLFSRKU
NRKBZKLNSX
NUZJOJKZVM
NRKBZKLNSX
SADFFYQYBS
ESDZHRVSPE
QEGJADFMZC
XHMRLGEIKZ
NXBTTXPNTD
ZAXBLRXKHI
XRZUJPARQL
KXYKRFQVXY
ELKMLFSRKU
NRKBZKLNSX
PKJSLMNBAN
EEFJGSITMH
MSBVPFNLCA
CCWQECFBUC
CCWQECFBUC
QWZRZUGCLN
XHMRLGEIKZ
VVJMPJZJKY
FTEONXIJND
ESDZHRVSPE
QEGJADFMZC
XHMRLGEIKZ
NXBTTXPNTD
ZAXBLRXKHI
XRZUJPARQL
KXYKRFQVXY
ESDZHRVSPE
YXSDUTRZTK
XHMRLGEIKZ
OCUDMUQZLC
BNNXLUMFCM
ZOCFGPOOSJ
KXYKRFQVXY
WGWMMMEUVK
EQVBWTRFFN
ZJERMVFLZP
XHMRLGEIKZ
ZQDTDAZEAQ
QBPBHHSJRU
RLDTJYNGJR
CWBFRFAXJQ
QYMHXSPYRJ
WGWMMMEUVK
EQVBWTRFFN
TKNLLFXQBB
XHMRLGEIKZ
ZQDTDAZEAQ
QBPBHHSJRU
RLDTJYNGJR
CWBFRFAXJQ
PKJSLMNBAN
TVVTEYYZQB
VZRXEPMFCO
QBPBHHSJRU
PUPUSJZGRX
QBPBHHSJRU
ZQBDRAJWVB
CWBFRFAXJQ
PKJSLMNBAN
TVVTEYYZQB
SZSSCOTUOW
EOXCYHWXSG
XHMRLGEIKZ
BOBGUTDJLO
TVVTEYYZQB
SWYPSAFVPT
WGWMMMEUVK
EQVBWTRFFN
YFJOCRKSBY
XHMRLGEIKZ
ZQDTDAZEAQ
QBPBHHSJRU
RLDTJYNGJR
CWBFRFAXJQ
ISRRHSHFQT
QBPBHHSJRU
PUPUSJZGRX
QBPBHHSJRU
ZQBDRAJWVB
CWBFRFAXJQ
CWZFUQJYSB
EOXCYHWXSG
XHMRLGEIKZ
VLNWOEFPGP
MSBVPFNLCA
CCWQECFBUC
CCWQECFBUC
GAZEOZYLAF
XHMRLGEIKZ
KZHZVPCYXB
GAZEOZYLAF
XHMRLGEIKZ
QQDNCQNLCE
QWZRZUGCLN
XHMRLGEIKZ
GBEHMSBXQA
MSBVPFNLCA
CHRCQMWHUF
IUYYTJNJQS
QWZRZUGCLN
IUYYTJNJQS
FAELDPXTEK
DYPTJSEKDX
VVJMPJZJKY
MSBVPFNLCA


#include <bits/stdc++.h>
#define O2 __attribute__((optimize("O2")))
using namespace std ;
int64_t n,m, k ;
const int MAXN (3000005) ;
const int64_t INF (0x7f7f7f7f7f7f7f7f) ;

int64_t  a[MAXN],sum[MAXN] ;

O2 int64_t fen(int l,int r,int &ll,int &rr)
{
	if(l == r) {
		ll = rr = l ;
		return a[l] ;
	}
	int mid((l+r)>>1) ;
	int L1(0),R1(0),L2(0),R2(0),L3(0),R3(0) ;
	int64_t lans = fen(l,mid,L1,R1) ;
	int64_t rans = fen(mid+1,r,L2,R2) ;
	int64_t maxL(-INF),maxR(-INF) ;
	for(int i(mid);i>=1;--i) {
		if(sum[mid]-sum[i-1]>=maxL) {
			maxL = sum[mid]-sum[i-1] ;
			L3 = i ;
		}
	}
	for(int i(mid+1);i<=n;++i) {
		if(sum[i]-sum[mid-1]>=maxL) {
			maxR = sum[i]-sum[mid] ;
			R3 = i ;
		}
	}
	ll = L3,rr = R3 ;
	int64_t ans(maxL+maxR) ;
	if(lans>=ans) {
		ll = L1;rr = R1 ;
		ans = lans ;
	}
	if(rans>=ans) {
		ll = L2;rr = R2 ;
		ans = rans ;
	}
	return ans ;
}

inline bool scan_d(int64_t &num)
{
        char in;bool IsN=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;}
        else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){
                num*=10,num+=in-'0';
        }
        if(IsN) num=-num;
        return true;
}

O2 int main()
{
	//ios::sync_with_stdio(false) ;
	int64_t SUM(0) ;
	//scanf("%d%d",&n,&m) ;
	scan_d(n);scan_d(m) ;
 	for(int i(1);i<=n;++i) {
		//scanf("%lld",a+i) ;
		scan_d(a[i]) ;
		SUM += a[i] ;
		sum[i] = sum[i-1] + m*a[i] ;
	}
	int L(0),R(0) ;
	int64_t ans = fen(1,n,L,R) ;
	//printf("[%d,%d]:%lld\n",L,R,ans) ;
	//cout<<SUM[n]<<"***"<<SUM[R]-SUM[L-1]<<endl;
	//printf("%lld\n",max(max(SUM[n]+ans-(SUM[R]-SUM[L-1]),SUM[n]),0LL)) ;
	for(int i(1);i<=n;++i) {
		if(i<=R&&i>=L)
			sum[i] = sum[i-1] + m*a[i] ;
		else
			sum[i] = sum[i-1] + a[i] ;
	}
	printf("%lld\n",max(max(fen(1,n,L,R),0LL),SUM)) ;
	return 0 ;
}


#include <bits/stdc++.h>
const int MAXN (1000005) ;
const int64_t INF = 0x3f3f3f3f3f3f3f3f3f ;
using namespace std ;

struct Node
{
	string name ;
	int d,c ;
};

vector<Node> node;
///int dp[1<<20];
int64_t dpk[MAXN],dp[MAXN],dpans[MAXN],l[MAXN] ;
int64_t arr[MAXN] ;

int main()
{
	int n,buff,k,t = 1 ;
	//cin >> t ;
	//while(t-->0)
	ios::sync_with_stdio(false) ;
	{
		cin >> n >>k;
		for(int i(1);i<=n;++i) {
			cin >>arr[i] ;
			dp[i] = dpk[i] = 0 ;
		}
		int64_t ans(0) ;
		for(int i(1);i<=n;++i) {
			dp[i] = max(dp[i-1]+arr[i],arr[i]) ;
			dpk[i] = max(dpk[i-1]+k*arr[i],k*arr[i]) ;
			if(k*arr[i]+dp[i-1]>dpk[i-1]+k*arr[i]+dp[i-1-l[i-1]]) {
				dpans[i] = k*arr[i]+dp[i-1];
				l[i] = 1;
			} else {
				dpans[i] = dpk[i-1]+k*arr[i]+dp[(i-1)-l[i-1]];
				l[i] = l[i-1]+1;
			}
			///cout<<dpans[i]<<","<<l[i]<<endl;
			//cout<<dp[i]<<endl;
			ans = max({ans,dp[i],dpk[i],dpans[i]}) ;
		}
		cout<<ans<<endl;
//		for(int i(1);i<=n;++i) {
//			string str ;
//			int d,c ;
//			cin >> str >> d >> c ;
//			node.push_back({str,d,c}) ;
//		}

	}
}


#include <bits/stdc++.h>
using namespace std ;
int n,m, k ;
const int MAXN (1000005) ;
const int64_t INF (0x7f7f7f7f7f7f7f7f) ;
string buff ;

int64_t  a[MAXN],sum[MAXN] ;

int64_t fen(int l,int r,int &ll,int &rr)
{
	if(l == r) {
		ll = rr = l ;
		return a[l] ;
	}
	int mid((l+r)>>1) ;
	int L1(0),R1(0),L2(0),R2(0),L3(0),R3(0) ;
	int64_t lans = fen(l,mid,L1,R1) ;
	int64_t rans = fen(mid+1,r,L2,R2) ;
	int64_t maxL(-INF),maxR(-INF) ;
	for(int i(mid);i>=1;--i) {
		if(sum[mid]-sum[i-1]>=maxL) {
			maxL = sum[mid]-sum[i-1] ;
			L3 = i ;
		}
	}
	for(int i(mid+1);i<=n;++i) {
		if(sum[i]-sum[mid-1]>=maxL) {
			maxR = sum[i]-sum[mid] ;
			R3 = i ;
		}
	}
	ll = L3,rr = R3 ;
	int64_t ans(maxL+maxR) ;
	if(lans>=ans) {
		ll = L1;rr = R1 ;
		ans = lans ;
	}
	if(rans>=ans) {
		ll = L2;rr = R2 ;
		ans = rans ;
	}
	return ans ;
}
int64_t SUM[MAXN] ;
int main()
{
	ios::sync_with_stdio(false) ;
	scanf("%d%d",&n,&m) ;
 	for(int i(1);i<=n;++i) {
		scanf("%lld",a+i) ;
		SUM[i] = SUM[i-1] + a[i] ;
		sum[i] = sum[i-1] + m*a[i] ;
	}
	int L(0),R(0) ;
	int64_t ans = fen(1,n,L,R) ;
	//printf("[%d,%d]:%lld\n",L,R,ans) ;
	//cout<<SUM[n]<<"***"<<SUM[R]-SUM[L-1]<<endl;
	//printf("%lld\n",max(max(SUM[n]+ans-(SUM[R]-SUM[L-1]),SUM[n]),0LL)) ;
	for(int i(1);i<=n;++i) {
		if(i<=R&&i>=L)
			sum[i] = sum[i-1] + m*a[i] ;
		else
			sum[i] = sum[i-1] + a[i] ;
	}
	printf("%lld\n",max(max(fen(1,n,L,R),0LL),SUM[n])) ;
	return 0 ;
}


#include <bits/stdc++.h>
const int MAXN (1000005) ;
const int64_t INF = 0x3f3f3f3f3f3f3f3f3f ;
using namespace std ;

int64_t dp[MAXN][5] ;
// 0: 当前不乘k,前边也不乘k
// 1: 当前不乘k,前边乘k
// 2: 当前乘k
int64_t arr[MAXN] ;

int main()
{
	int n,buff,k,t = 1 ;
	ios::sync_with_stdio(false) ;
	{
		cin >> n >>k;
		for(int i(1);i<=n;++i) {
			cin >>arr[i] ;
		}
		int64_t ans(0) ;
		for(int i(1);i<=n;++i) {
			dp[i][0] = max(dp[i-1][0],0LL)+arr[i] ;
			dp[i][1] = max({dp[i-1][2],dp[i-1][1],0LL})+arr[i] ;
			dp[i][2] = max({dp[i-1][2],dp[i-1][0],0LL})+arr[i]*k  ;
			ans = max({ans,dp[i][0],dp[i][1],dp[i][2]}) ;
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+max(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x==0)
            {
                idx[i]=i;
                if(ai[i]>0)
                {
                    lexsum[i]=ai[i];
                }
                else
                {
                    if(lexsum[i-1]<0)
                    {
                        lexsum[i]=lexsum[i-1]+ai[i];
                        idx[i]=idx[i-1];
                    }
                    else
                    {
                        lexsum[i]=ai[i];
                    }
                }

            }
            else if(x<0)
            {
                idx[i]=i;
                if(lexsum[i-1]<0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2; i<=n; i++)
        {
            //not use
            if(dp[i-1][0]>0)
            {
                dp[i][0]=dp[i-1][0]+ai[i];
            }
            else
            {
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+max(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; i++)
        {
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x==0)
            {
                idx[i]=i;
                                     lexsum[i]=ai[i];

            }
            else if(x<0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2; i<=n; i++)
        {
            //not use
            if(dp[i-1][0]>0)
            {
                dp[i][0]=dp[i-1][0]+ai[i];
            }
            else
            {
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+max(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; i++)
        {
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
LL ai[maxn];
//0 dont 1 used;
LL dp[maxn][3];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&ai[i]);
        }

        memset(dp,0,sizeof(dp));
        dp[1][0]=ai[1];
        dp[1][1]=ai[1]*x;
        dp[1][2]=ai[1]*x;
        for(int i=2;i<=n;i++){
            dp[i][0]=max(dp[i-1][0]+ai[i],ai[i]);
            dp[i][1]=max(dp[i-1][0]+ai[i]*x,dp[i-1][1]+ai[i]*x);
            dp[i][2]=max(dp[i][1],dp[i-1][2]+ai[i]);
        }
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;

        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; 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 <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x==0)
            {
                idx[i]=i;
                if(ai[i]>0)
                {
                    lexsum[i]=ai[i];
                }
                else
                {
                    if(lexsum[i-1]<=0)
                    {
                        lexsum[i]=lexsum[i-1]+ai[i];
                        idx[i]=idx[i-1];
                    }
                    else
                    {
                        lexsum[i]=ai[i];
                    }
                }

            }
            else if(x<0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2; i<=n; i++)
        {
            //not use
            if(dp[i-1][0]>0)
            {
                dp[i][0]=dp[i-1][0]+ai[i];
            }
            else
            {
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+max(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; i++)
        {
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+dp[idx[i]-1][0];
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]<0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+dp[idx[i]-1][0];
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+min(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]=<0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+dp[idx[i]-1][0];
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
LL ai[maxn];
//0 dont 1 used;
LL dp[maxn][3];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&ai[i]);
        }

        memset(dp,0,sizeof(dp));
        dp[1][0]=ai[1];
        dp[1][1]=ai[1]*x;
        dp[1][2]=ai[1]*x;
        for(int i=2;i<=n;i++){
            dp[i][0]=max(dp[i-1][0]+ai[i],ai[i]);
            dp[i][1]=max(dp[i-1][0]+ai[i]*x,dp[i-1][1]+ai[i]*x);
            dp[i][1]=max(dp[i][1],ai[i]*x);
            dp[i][2]=max(dp[i][1],dp[i-1][2]+ai[i]);
        }
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;

        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; 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 <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x<=0)
            {
                idx[i]=i;
                if(lexsum[i-1]<=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>=0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
       // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2;i<=n;i++){
            //not use
            if(dp[i-1][0]>0){
                dp[i][0]=dp[i-1][0]+ai[i];
            }else{
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+min(dp[idx[i]-1][0],0);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
       // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1;i<=n;i++){
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;

void init()
{

}

void play()
{

}

void Pri()
{

}

int n,x;
const int maxn=3*123456;
int ai[maxn];
//0 dont 1 used;
LL dp[maxn][2];
LL lexsum[maxn];
int idx[maxn];
int main()
{

    while(scanf("%d%d",&n,&x)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&ai[i]);
        }
        lexsum[1]=ai[1];
        idx[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(x==0)
            {
                idx[i]=i;
                if(ai[i]>=0)
                {
                    lexsum[i]=ai[i];
                }
                else
                {
                    if(lexsum[i-1]<0)
                    {
                        lexsum[i]=lexsum[i-1]+ai[i];
                        idx[i]=idx[i-1];
                    }
                    else
                    {
                        lexsum[i]=ai[i];
                    }
                }

            }
            else if(x<0)
            {
                idx[i]=i;
                if(lexsum[i-1]<0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
            else
            {
                idx[i]=i;
                if(lexsum[i-1]>0)
                {
                    lexsum[i]=lexsum[i-1]+ai[i];
                    idx[i]=idx[i-1];
                }
                else
                {
                    lexsum[i]=ai[i];
                }
            }
        }
        dp[0][0]=dp[0][1]=0;
        dp[1][0]=lexsum[1];
        dp[1][1]=lexsum[1]*x;
        // cout<<idx[n]<<" "<<lexsum[n]<<endl;
        for(int i=2; i<=n; i++)
        {
            //not use
            if(dp[i-1][0]>0)
            {
                dp[i][0]=dp[i-1][0]+ai[i];
            }
            else
            {
                dp[i][0]=ai[i];
            }

            //use
            dp[i][1]=lexsum[i]*x+max(dp[idx[i]-1][0],0LL);
            dp[i][1]=max(dp[i][1],dp[i-1][1]+ai[i]);

        }
        // cout<<dp[2][0]<<" "<<dp[n][1]<<endl;
        LL ans=0;
        for(int i=1; i<=n; i++)
        {
            ans=max(ans,dp[i][0]);
            ans=max(ans,dp[i][1]);
        }
        printf("%lld\n",ans);
    }

    return 0;

}


#include<bits/stdc++.h>

#define LL long long
#define inf 1E20
#define pb push_back
#define vsort(v) sort(v.begin(),v.end())
#define pi acos(-1)
#define clr(a) memset(a,0,sizeof a)
#define bclr(a) memset(a,false,sizeof a)
#define MOD 1073741824
#define MX 1000100

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie();
    int n;
    string p="<3",str,s="";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        s+=str+p;
    }
    cin>>str;
    int sz=str.length(),indx=0;
    for(int i=0;i<sz;i++){
        if(str[i]==s[indx]) indx++;
    }
    if(indx==s.length()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define inf 1E20
#define pb push_back
#define vsort(v) sort(v.begin(),v.end())
#define pi acos(-1)
#define inf 2147483647
#define MOD 1073741824
#define MX 50000

using namespace std;
vector<string>V,ans;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie();
    int n;
    string str;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        V.pb(str);
    }
    //sort(V.begin(),V.end());
    cin>>str;
    int sz=str.length();
    string tmp="";
    for(int i=0;i<sz-1;i++){
        if(str[i]=='<'){
            if(tmp.size()){
                ans.pb(tmp);
                tmp="";
            }
            while(str[i]!='3' && i<sz) i++;
        }
        else{
            tmp=tmp+str[i];
        }
    }
    //sort(ans.begin(),ans.end());
    if(tmp.size()) cout<<"no"<<endl;
    else if(V.size()==ans.size()){
        int zs=ans.size();
        for(int i=0;i<zs;i++){
            string a=V[i],b=ans[i];
        if(a.size()>b.size()){
            cout<<"no"<<endl;
            return 0;
            }
            else{
                int az=a.size(),bz=b.size(),nn=-1;
                for(int k=0;k<bz;k++){
                    int l=0,cnt=0,mm=k;
                    while(l<az){
                        if(a[l]==b[mm]){
                            l++;
                            mm++;
                            cnt++;
                        }
                        else break;
                    }
                    if(cnt==az){
                        nn=1;
                        break;
                    }
                }
                if(nn==-1){
                    cout<<"no"<<endl;
                    return 0;
                }
            }
        }
        cout<<"yes"<<endl;
    }
    else cout<<"no"<<endl;
    return 0;
}