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

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

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

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

const long long N = 3 * 100000 + 5;

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

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

/**
TEST:

*/


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

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

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

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

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


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

const int N = 300005;
ll a[N], l[N], r[N];
ll n, x;

void nhap()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}
void xuly()
{
    long long val = 0, ans = 0, res = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += a[i];
        l[i] = max(0 * 1ll, ans - val);
        val = min(val, ans);
    }
    val = 0, ans = 0;
    for(int i = n; i >= 1; i--)
    {
        ans += a[i];
        r[i] = min(0 * 1ll, ans - val);
        val = max(val, ans);
    }

    if(x  == 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res, l[i]);
        cout << res;
        return;
    }
    if(x > 0)
    {
        for(int i = 1; i <= n; i++)
            res = max(res , l[i]);
        res = res * x;
        cout << res;
        return;
    }
    if(x < 0)
    {
        for(int i = 0; i <= n; i++)
        {
            res = max(res, l[i] + r[i + 1] * x);
        }
        cout << res;
    }
}

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


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

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

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

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

const long long N = 3 * 100000 + 5;

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

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

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

/**
TEST:

*/


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

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

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

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

const long long N = 3 * 100000 + 5;

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> x;
    for(long long i = 1; i <= n; i++)
        cin >> a[i];
    long long res = 0;
    for(long long i = 1; i <= n; i++)
    {
        f3 = max(f2 + x * a[i], f3 + a[i]);
        f2 = max(f2, f1) + x * a[i];
        f1 = f1 + a[i];
        f1 = max(0ll, f1);
        f2 = max(0ll, f2);
        res = max(res, f3);
    }
    cout << res;
}

/**
TEST:

*/


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

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

const long long N = 3 * 100000 + 5;

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

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

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

/**
TEST:

*/


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

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

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

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

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


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

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

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

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


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX][3],a[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],a[i]);
		dp[i][1]=max({dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x});
	}
	cout<<max({0ll,dp[n][0],dp[n][1]})<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 3*1e5+5;
const int INF = 1e18;
int n,x;
int a[N];
int32_t main(){
	fastio
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int dp[n+1][3],ans=0;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],a[i]);
		dp[i][1]=max({dp[i-1][1]+x*a[i],dp[i-1][0]+x*a[i],x*a[i]});
		dp[i][2]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		ans=max({ans,dp[i][0],dp[i][1],dp[i][2]});
	}
	cout<<ans<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX][3],a[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		dp[i][0]=max({dp[i-1][0]+a[i],a[i]});
		dp[i][1]=max({dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x});
		dp[i][2]=max({dp[i-1][1]+a[i],dp[i-1][2]+a[i]});
		ans=max({ans,dp[i][0],dp[i][1],dp[i][2]});
	}
	cout<<ans<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX][3],a[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],a[i]);
		dp[i][1]=max({dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x});
		dp[i][2]=max({dp[i-1][1]+a[i],dp[i-1][2]+a[i]});
	}
	cout<<max({0ll,dp[n][2],dp[n][0],dp[n][1]})<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=-a[i];
	}
	int sum=0,beg=0,st=0,end=0,mx=-INF;
	if(x<0){
		for(int i=0;i<n;i++){
			sum+=b[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	else{
		for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	int tot=0,i;
	for(int i=st;i<=end;i++){
		tot+=a[i];
	}
	tot*=x;
	i=st-1;
	int l=0,mx1=0,mx2=0;
	while(i>=0){
		l+=a[i];
		mx1=max(mx1,l);
		i--;
	}
	tot+=mx1;
	l=0;
	i=end+1;
	while(i<n){
		l+=a[i];
		mx2=max(mx2,l);
		i++;
	}
	tot+=mx2;
	mx1=-INF;
	sum=0;
	for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx1<sum){
				mx1=sum;
				st=beg;
				end=i;
			}
		}
	cout<<max(mx1,tot)<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX][3],a[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],a[i]);
		dp[i][1]=max({dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x});
		dp[i][2]=max({dp[i-1][1]+a[i],dp[i-1][2]+a[i],a[i]});
	}
	cout<<max({0ll,dp[n][2],dp[n][0],dp[n][1]})<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=-a[i];
	}
	int sum=0,beg=0,st=0,end=0,mx=-INF;
	if(x<0){
		for(int i=0;i<n;i++){
			sum+=b[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	else if(x>0){
		for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	for(int i=st;i<=end;i++){
		a[i]*=x;
	}
	int mx1=-INF;
	sum=0;
	for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx1<sum){
				mx1=sum;
				st=beg;
				end=i;
			}
		}
	cout<<mx1<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=-a[i];
	}
	int sum=0,beg=0,st=0,end=0,mx=-INF;
	if(x<0){
		for(int i=0;i<n;i++){
			sum+=b[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	else if(x>0){
		for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	for(int i=st;i<=end;i++){
		a[i]*=x;
	}
	int mx1=0;
	sum=0;
	for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx1<sum){
				mx1=sum;
				st=beg;
				end=i;
			}
		}
	cout<<mx1<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX][3],a[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[i][0]=max({0ll,dp[i-1][0]+a[i],a[i]});
		dp[i][1]=max({0ll,dp[i-1][0]+a[i]*x,dp[i-1][1]+a[i]*x,a[i]*x});
		dp[i][2]=max({0ll,dp[i-1][1]+a[i],dp[i-1][2]+a[i]});
	}
	cout<<max({dp[n][2],dp[n][0],dp[n][1]})<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=-a[i];
	}
	int sum=0,beg=0,st=0,end=0,mx=-INF;
	if(x<0){
		for(int i=0;i<n;i++){
			sum+=b[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	else{
		for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	int tot=0,i;
	for(int i=st;i<=end;i++){
		tot+=a[i];
	}
	tot*=x;
	i=st-1;
	while(i>=0 and tot+a[i]>tot){
		tot+=a[i];
		i--;
	}
	i=end+1;
	while(i<n and tot+a[i]>tot){
		tot+=a[i];
		i++;
	}
	int mx1=-INF;
	sum=0;
	for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx1<sum){
				mx1=sum;
				st=beg;
				end=i;
			}
		}
	cout<<max(mx1,tot)<<endl;
}


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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=-a[i];
	}
	int sum=0,beg=0,st=0,end=0,mx=-INF;
	if(x<0){
		for(int i=0;i<n;i++){
			sum+=b[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	else{
		for(int i=0;i<n;i++){
			sum+=a[i];
			if(sum<0){
				sum=0;
				beg=i+1;
			}
			if(mx<sum){
				mx=sum;
				st=beg;
				end=i;
			}
		}
	}
	int tot=0,i;
	for(int i=st;i<=end;i++){
		tot+=a[i];
	}
	tot*=x;
	i=st-1;
	while(i>=0 and tot+a[i]>tot){
		tot+=a[i];
		i--;
	}
	i=end+1;
	while(i<n and tot+a[i]>tot){
		tot+=a[i];
		i++;
	}
	cout<<tot<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 3*1e5+5;
const int INF = 1e18;
int n,x;
int a[N];
int32_t main(){
	fastio
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int dp[n+1][3],ans=0;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],a[i]);
		dp[i][1]=max(dp[i-1][1]+x*a[i],dp[i-1][0]+x*a[i]);
		dp[i][2]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		ans=max({ans,dp[i][0],dp[i][1],dp[i][2]});
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

//const int R=1<<20;
int n,len;
int t[300007];
long long res,w,x,lens,zm_w_s;
//long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> sum_L[300007], sum_P[300007];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=1; i<=n; i++)
    {
        cin>>t[i];
    }

    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_L[i]={w,len};
    }
    if (x>0)
    {
        cout<<res*x;
        return 0;
    } ///-------------------------------------------------------------

    //cerr<<".";

    w=0;
    len=0;
    for (int i=n; i>0; i--)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_P[i]={w,len};
    }

    cerr<<".";

    w=0;
    len=0;
    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        //zm_w_s+=t[i];
        if (t[i]>0)
        {
            zm_w_s=0;
            lens=0;
        }
        else
        {
            zm_w_s+=t[i];
            lens++;
        }
        len++;
        if (w>0)
        {
            w=0;
            len=0;
        }
        else if (w==0)
        {
            if (sum_L[i-len].ff<sum_L[i].ff)
                len=0;
        }
        //cout<<i<<") "<<zm_w_s<<" "<<sum_L[i-lens].ff<<"\n";
        res=max(res, max(w*x+sum_L[i-len].ff, zm_w_s*x+sum_L[i-lens].ff)+sum_P[i+1].ff);
    }
    cout<<res;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

//const int R=1<<20;
int n,len;
int t[300007];
long long res,w,x,lens,zm_w_s;
//long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> sum_L[300007], sum_P[300007];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=1; i<=n; i++)
    {
        cin>>t[i];
    }

    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_L[i]={w,len};
    }
    if (x>0)
    {
        cout<<res*x;
        return 0;
    } ///-------------------------------------------------------------

    //cerr<<".";

    w=0;
    len=0;
    for (int i=n; i>0; i--)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_P[i]={w,len};
    }

    cerr<<".";

    w=0;
    len=0;
    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        zm_w_s+=t[i];
        if (t[i]>0)
        {
            zm_w_s=0;
            lens=0;
        }
        else
        {
            zm_w_s+=t[i];
            lens++;
        }
        len++;
        if (w>0)
        {
            w=0;
            len=0;
        }
        res=max(res, max(w*x+sum_L[i-len].ff, zm_w_s*x+sum_L[i-lens].ff)+sum_P[i+1].ff);
    }
    cout<<res;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

const int R=1<<19;
int n,lwu,pocz;
int t[300007];
long long res,w,res2,x,ciag_ujemny,mx_c_u,mxw,wu,mxu;
long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> ujemny[300007];
vector<int> maxy_ujemne;
bool zm;

long long tree[R+7];

long long query(int l, int r, int ll, int rr, int v)
{
    if (ll>r || rr<l)
        return 0;
    if (ll<=l && r<=rr)
        return tree[v];
    return min(query(l,r,ll,(ll+rr)/2,2*v),query(l,r,(ll+rr)/2,rr,2*v+1));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        t2[i]=(long long)t[i]*x;
        pref2[i+1]=pref2[i]+t2[i];
    }

    for (int i=0; i<n; i++)
    {
        w+=t[i];
        wu+=t[i];
        if (w<0)
            w=0;
        else if (w>res)
            res=w;
        sum_dod[i]=w;
        if (t[i]>0 && zm)
        {
            if (wu<mxu)
            {
                mxu=wu;
                maxy_ujemne.push_back(i-1);
                zm=0;
            }
        }
        if (t[i]<0)
            zm=1;

        if (wu<0)
        {
            lwu++;
            mxu=0;
        }
        else
        {
            lwu=0;
            wu=0;
        }
        ujemny[i]={wu,lwu};
    }
    if (wu<0)
        maxy_ujemne.push_back(n-1);
    if (x>0)
    {
        cout<<res*x;
        return 0;
    }
    else if (maxy_ujemne.size()==0)
    {
        cout<<pref2[n]/x;
        return 0;
    }

    for (int i=0; i<maxy_ujemne.size(); i++)
        tree[R/2+i]=ujemny[maxy_ujemne[i]].ss;
    for (int i=R/2-1; i>0; i--)
    {
        tree[i]=min(tree[2*i],tree[2*i+1]);
    }

    for (int i=0; i<n; i++)
    {
        //cout<<i<<" "<<t[i]<<" "<<w<<"\n";
        if (t[i]<0 && w>0)
        {
            ciag_ujemny+=t[i];
            long long nwm=0;
            auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
            auto b=upper_bound(maxy_ujemne.begin(), maxy_ujemne.end(), i-1);
            b--;

            int ind=maxy_ujemne[(int)(a-maxy_ujemne.begin())];
            int ind2=maxy_ujemne[(int)(b-maxy_ujemne.begin())];
            if (ind-ujemny[ind].ss<pocz)
            {
                nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
                ind++;
            }
            if (ind<=ind2)
                nwm=min(nwm, query(ind,ind2,1,R/2,1));

            if (ind-ujemny[i-1].ss<pocz)
                nwm=min(nwm,pref2[i]-pref2[pocz]);
            else
                nwm=min(nwm,ujemny[i-1].ff);

            /*for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<i; j++)
            {
                int ind=maxy_ujemne[j];
                if (ind-ujemny[ind].ss<pocz)
                    nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
                else
                    nwm=min(nwm,ujemny[ind].ff);

            }
            nwm=min(nwm,ujemny[i-1].ff);*/
            //cout<<i<<") "<<nwm<<" "<<pocz<<"\n";
            if (pocz>0)
                res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
            else
                res2=max(res2, mxw+max((long long)0,nwm*x));
        }

        w+=t[i];
        mxw=max(mxw,w);

        if (t[i]>=0)
        {
            mx_c_u=min(mx_c_u, ciag_ujemny);
        }
        if (w<0)
        {
            res2=max(res2, w-t[i]+mx_c_u*x);
            w=0;
            mxw=0;
            ciag_ujemny=0;
            mx_c_u=0;
            if (t[i+1]>0)
                pocz=i+1;
        }
    }
    ///--------
    long long nwm=0;
    auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
    for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<n; j++)
    {
        int ind=maxy_ujemne[j];
        if (ind-ujemny[ind].ss<pocz)
            nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
        else
            nwm=min(nwm,ujemny[ind].ff);

    }
    nwm=min(nwm,ujemny[n-1].ff);
    if (pocz>0)
        res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
    else
        res2=max(res2, mxw+max((long long)0,nwm*x));
    res2=max(res2,x*ujemny[n-1].ff+sum_dod[n-1-ujemny[n-1].ss]);
    ///----
    cout<<max((long long)0,res2);
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int n,lwu,pocz;
int t[300007];
long long res,w,res2,x,ciag_ujemny,mx_c_u,mxw,wu,mxu;
long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> ujemny[300007];
vector<int> maxy_ujemne;
bool zm;

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    cin>>n>>x;
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        t2[i]=(long long)t[i]*x;
        pref2[i+1]=pref2[i]+t2[i];
    }

    for (int i=0; i<n; i++)
    {
        w+=t[i];
        wu+=t[i];
        if (w<0)
            w=0;
        else if (w>res)
            res=w;
        sum_dod[i]=w;
        if (t[i]>0 && zm)
        {
            if (wu<mxu)
            {
                mxu=wu;
                maxy_ujemne.push_back(i-1);
                zm=0;
            }
        }
        if (t[i]<0)
            zm=1;

        if (wu<0)
        {
            lwu++;
        }
        else
        {
            lwu=0;
            wu=0;
            mxu=0;
        }
        ujemny[i]={wu,lwu};
    }
    if (wu<0)
        maxy_ujemne.push_back(n-1);
    if (x>0)
    {
        cout<<res*x;
        return 0;
    }
    else if (maxy_ujemne.size()==0)
    {
        cout<<pref2[n]/x;
        return 0;
    }

   // cerr<<".";
    if (maxy_ujemne.size()>(1<<18))
        cout<<"DUPA\n";
    //cerr<<".";

    for (int i=0; i<n; i++)
    {
        //cerr<<".";
        //cout<<i<<" "<<t[i]<<" "<<w<<"\n";
        if (t[i]<0 && w>0)
        {
            ciag_ujemny+=t[i];
            long long nwm=0;
            auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
            if (a!=maxy_ujemne.end())
            {
                for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<i; j++)
                {
                    int ind=maxy_ujemne[j];
                    if (ind-ujemny[ind].ss<pocz)
                        nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
                    else
                        nwm=min(nwm,ujemny[ind].ff);

                }
            }
            nwm=min(nwm,ujemny[i-1].ff);
            //cout<<i<<") "<<nwm<<" "<<pocz<<"\n";
            if (pocz>0)
                res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
            else
                res2=max(res2, mxw+max((long long)0,nwm*x));
        }

        w+=t[i];
        mxw=max(mxw,w);

        if (t[i]>=0)
        {
            mx_c_u=min(mx_c_u, ciag_ujemny);
        }
        if (w<0)
        {
            res2=max(res2, w-t[i]+mx_c_u*x);
            w=0;
            mxw=0;
            ciag_ujemny=0;
            mx_c_u=0;
            if (t[i+1]>0)
                pocz=i+1;
        }
    }

    //cerr<<"*";

    ///--------
    long long nwm=0;
    auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
    if (a!=maxy_ujemne.end())
    {
        //cerr<<"*";
        for (int j=(int)(a-maxy_ujemne.begin()); j<maxy_ujemne.size() && maxy_ujemne[j]<n; j++)
        {
            int ind=maxy_ujemne[j];
            if (ind-ujemny[ind].ss<pocz)
                nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
            else
                nwm=min(nwm,ujemny[ind].ff);

        }
    }

    nwm=min(nwm,ujemny[n-1].ff);
    if (pocz>0)
        res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
    else
        res2=max(res2, mxw+max((long long)0,nwm*x));
    res2=max(res2,x*ujemny[n-1].ff+sum_dod[n-1-ujemny[n-1].ss]);
    ///----
    cout<<max((long long)0,res2);
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

//const int R=1<<20;
int n,len;
int t[300007];
long long res,w,x;
//long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> sum_L[300007], sum_P[300007];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=1; i<=n; i++)
    {
        cin>>t[i];
    }

    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_L[i]={w,len};
    }
    if (x>0)
    {
        cout<<res*x;
        return 0;
    } ///-------------------------------------------------------------

    //cerr<<".";

    w=0;
    len=0;
    for (int i=n; i>0; i--)
    {
        w+=t[i];
        len++;
        if (w<0)
        {
            w=0;
            len=0;
        }
        else if (w>res)
            res=w;
        sum_P[i]={w,len};
    }

    //cerr<<".";

    w=0;
    len=0;
    for (int i=1; i<=n; i++)
    {
        w+=t[i];
        len++;
        if (w>0)
        {
            w=0;
            len=0;
        }
        res=max(res, w*x+sum_P[i+1].ff+sum_L[i-len].ff);
    }
    cout<<res;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int n,lwu,pocz;
int t[300007];
long long res,w,res2,x,ciag_ujemny,mx_c_u,mxw,wu,mxu;
long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> ujemny[300007];
vector<int> maxy_ujemne;
bool zm;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        t2[i]=(long long)t[i]*x;
        pref2[i+1]=pref2[i]+t2[i];
    }

    for (int i=0; i<n; i++)
    {
        w+=t[i];
        wu+=t[i];
        if (w<0)
            w=0;
        else if (w>res)
            res=w;
        sum_dod[i]=w;
        if (t[i]>0 && zm)
        {
            if (wu<mxu)
            {
                mxu=wu;
                maxy_ujemne.push_back(i-1);
                zm=0;
            }
        }
        if (t[i]<0)
            zm=1;

        if (wu<0)
        {
            lwu++;

        }
        else
        {
            lwu=0;
            wu=0;
            mxu=0;
        }
        ujemny[i]={wu,lwu};
    }
    if (wu<0)
        maxy_ujemne.push_back(n-1);
    if (x>0)
    {
        cout<<res*x;
        return 0;
    }
    else if (maxy_ujemne.size()==0)
    {
        cout<<pref2[n]/x;
        return 0;
    }

    for (int i=0; i<n; i++)
    {
        //cout<<i<<" "<<t[i]<<" "<<w<<"\n";
        if (t[i]<0 && w>0)
        {
            ciag_ujemny+=t[i];
            long long nwm=0;
            auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
            for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<i; j++)
            {
                int ind=maxy_ujemne[j];
                if (ind-ujemny[ind].ss<pocz)
                    nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
                else
                    nwm=min(nwm,ujemny[ind].ff);

            }
            nwm=min(nwm,ujemny[i-1].ff);
            //cout<<i<<") "<<nwm<<" "<<pocz<<"\n";
            if (pocz>0)
                res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
            else
                res2=max(res2, mxw+max((long long)0,nwm*x));
        }

        w+=t[i];
        mxw=max(mxw,w);

        if (t[i]>=0)
        {
            mx_c_u=min(mx_c_u, ciag_ujemny);
        }
        if (w<0)
        {
            res2=max(res2, w-t[i]+mx_c_u*x);
            w=0;
            mxw=0;
            ciag_ujemny=0;
            mx_c_u=0;
            if (t[i+1]>0)
                pocz=i+1;
        }
    }
    ///--------
    long long nwm=0;
    auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
    for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<n; j++)
    {
        int ind=maxy_ujemne[j];
        if (ind-ujemny[ind].ss<pocz)
            nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
        else
            nwm=min(nwm,ujemny[ind].ff);

    }
    nwm=min(nwm,ujemny[n-1].ff);
    if (pocz>0)
        res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
    else
        res2=max(res2, mxw+max((long long)0,nwm*x));
    res2=max(res2,x*ujemny[n-1].ff+sum_dod[n-1-ujemny[n-1].ss]);
    ///----
    cout<<max((long long)0,res2);
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int n,lwu,pocz;
int t[300007];
long long res,w,res2,x,ciag_ujemny,mx_c_u,mxw,wu,mxu;
long long t2[300007], pref2[300007], sum_dod[300007];
pair<long long, int> ujemny[300007];
vector<int> maxy_ujemne;
bool zm;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for (int i=0; i<n; i++)
    {
        cin>>t[i];
        t2[i]=(long long)t[i]*x;
        pref2[i+1]=pref2[i]+t2[i];
    }

    for (int i=0; i<n; i++)
    {
        w+=t[i];
        wu+=t[i];
        if (w<0)
            w=0;
        else if (w>res)
            res=w;
        sum_dod[i]=w;
        if (t[i]>0 && zm)
        {
            if (wu<mxu)
            {
                mxu=wu;
                maxy_ujemne.push_back(i-1);
                zm=0;
            }
        }
        if (t[i]<0)
            zm=1;

        if (wu<0)
        {
            lwu++;
        }
        else
        {
            lwu=0;
            wu=0;
            mxu=0;
        }
        ujemny[i]={wu,lwu};
    }
    if (wu<0)
        maxy_ujemne.push_back(n-1);
    if (x>0)
    {
        cout<<res*x;
        return 0;
    }
    else if (maxy_ujemne.size()==0)
    {
        cout<<pref2[n]/x;
        return 0;
    }

   // cerr<<".";
    if (maxy_ujemne.size()>(1<<18))
        cout<<"DUPA\n";
    //cerr<<".";

    for (int i=0; i<n; i++)
    {
        //cerr<<".";
        //cout<<i<<" "<<t[i]<<" "<<w<<"\n";
        if (t[i]<0 && w>0)
        {
            ciag_ujemny+=t[i];
            long long nwm=0;
            auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
            if (a!=maxy_ujemne.end())
            {
                for (int j=(int)(a-maxy_ujemne.begin()); maxy_ujemne[j]<i; j++)
                {
                    int ind=maxy_ujemne[j];
                    if (ind-ujemny[ind].ss<pocz)
                        nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
                    else
                        nwm=min(nwm,ujemny[ind].ff);

                }
            }
            nwm=min(nwm,ujemny[i-1].ff);
            //cout<<i<<") "<<nwm<<" "<<pocz<<"\n";
            if (pocz>0)
                res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
            else
                res2=max(res2, mxw+max((long long)0,nwm*x));
        }

        w+=t[i];
        mxw=max(mxw,w);

        if (t[i]>=0)
        {
            mx_c_u=min(mx_c_u, ciag_ujemny);
        }
        if (w<0)
        {
            res2=max(res2, w-t[i]+mx_c_u*x);
            w=0;
            mxw=0;
            ciag_ujemny=0;
            mx_c_u=0;
            if (t[i+1]>0)
                pocz=i+1;
        }
    }

    //cerr<<"*";

    ///--------
    long long nwm=0;
    auto a=lower_bound(maxy_ujemne.begin(), maxy_ujemne.end(), pocz);
    if (a!=maxy_ujemne.end())
    {
        //cerr<<"*";
        for (int j=(int)(a-maxy_ujemne.begin()); j<maxy_ujemne.size() && maxy_ujemne[j]<n; j++)
        {
            int ind=maxy_ujemne[j];
            if (ind-ujemny[ind].ss<pocz)
                nwm=min(nwm,pref2[ind+1]-pref2[pocz]);
            else
                nwm=min(nwm,ujemny[ind].ff);

        }
    }

    nwm=min(nwm,ujemny[n-1].ff);
    if (pocz>0)
        res2=max(res2, mxw+max((long long)0,max(nwm*x, x*ujemny[pocz-1].ff+sum_dod[pocz-1-ujemny[pocz-1].ss])));
    else
        res2=max(res2, mxw+max((long long)0,nwm*x));
    res2=max(res2,x*ujemny[n-1].ff+sum_dod[n-1-ujemny[n-1].ss]);
    ///----
    cout<<max((long long)0,res2);
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,end) for(i=s;i<end;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    fn(i,n+1)
        fn(j,3)
        	dp[i][j]=0;
    ll ans=-MM;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];
        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
    }
    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    fn(i,n+1)
        fn(j,3)
        	dp[i][j]=-MM;
    ll ans=-MM;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];

        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
        //  cout<<ans<<endl;
    }

    cout<<max(0LL,ans)<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    fn(i,n+1)
        fn(j,3)
        	dp[i][j]=-MM;
    ll ans=-MM;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];
        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
    }
    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    ll ans=0;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max(dp[i-1][1],max(0LL,dp[i-1][0]))+a[i]*x;
        dp[i][2]=max(dp[i-1][2],max(dp[i-1][1],max(dp[i-1][0],0LL)))+a[i];

        ans=max(ans,max(dp[i][2],max(dp[i][1],dp[i][0])));
        //  cout<<ans<<endl;
    }

    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=5e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    ll ans=0;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max(dp[i-1][1],max(0LL,dp[i-1][0]))+a[i]*x;
        dp[i][2]=max(dp[i-1][2],max(dp[i-1][1],max(dp[i-1][0],0LL)))+a[i];

        ans=max(ans,max(dp[i][2],max(dp[i][1],dp[i][0])));
        //  cout<<ans<<endl;
    }

    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,end) for(i=s;i<end;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    fn(i,n+1)
        fn(j,3)
        	dp[i][j]=0;
    ll ans=-MM;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];
        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
    }
    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    ll ans=0;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max(dp[i-1][1],max(0LL,dp[i-1][0]))+1LL*a[i]*x;
        dp[i][2]=max(dp[i-1][2],max(dp[i-1][1],max(dp[i-1][0],0LL)))+a[i];

        ans=max(ans,max(dp[i][2],max(dp[i][1],dp[i][0])));
        //  cout<<ans<<endl;
    }

    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    ll ans=0;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];

        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
        //  cout<<ans<<endl;
    }

    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long  long
#define vl vector<ll>
#define fs(i,s,e) for(i=s;i<e;i++)
#define fn(i,n) for(i=0;i<n;i++)
#define W while
#define pb push_back
using namespace std;
const int MAX=2e5+5;
const ll MM=1e16;
ll dp[MAX][3];
void solve()
{
    ll n,m,x,i,j,k;
    cin>>n>>x;
    vl a(n+1);
    fn(i,n)cin>>a[i+1];
    fn(i,n+1)
        fn(j,3)
        	dp[i][j]=-MM;
    ll ans=-MM;
    fs(i,1,n+1)
    {
        dp[i][0]=max(0LL,dp[i-1][0])+a[i];
        dp[i][1]=max({dp[i-1][1],0LL,dp[i-1][0]})+1LL*a[i]*x;
        dp[i][2]=max({dp[i-1][2],dp[i-1][1],dp[i-1][0],0LL})+a[i];
        ans=max({ans,dp[i][2],dp[i][1],dp[i][0]});
    }
    cout<<ans<<endl;

}

int main()
{
    ll t=1;
    // cin>>t;
    W(t--)
    {
        solve();
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = max((ll)0, a[i]);
    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
      solve[idx][i] =
      max(solve[idx][i], (solve[2][i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(j <= i && (best <= 0 ||a[j] < 0))
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < 0)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    if(idx == 1) {
      solve[idx][i] =
      max(a[i] + (i >0? solve[idx][i-1]:0), solve[2][i]);
      solve[idx][i] =
      max(solve[idx][i], solve[2][i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(j <= i && (best <= 0 || a[j] < 0))
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < n)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;

    if(idx == 1 && j>0)
        before = solve[2][j-1];

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);
    best += a[i];
    while(best <= 0 && j <= i){
      best -= a[j];
      if(idx == 1)
        before = solve[2][j];
      ++j;
    }
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
    best = solve[1][i];
    if(i + 1 < n){
     best += solve[0][n-i-2];
    }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = (i>0? solve[2][i-1]:0) + a[i];
    solve[idx][i] = max(solve[idx][i], (ll)0);
    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
    best = solve[1][i];
    if(i + 1 < n){
     best += solve[0][n-i-2];
    }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    if(idx == 1)
      solve[idx][i] = max(a[i] + i >0? solve[idx][i-1]:0, solve[2][i]);

    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
      solve[idx][i] =
      max(solve[idx][i], solve[2][i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(j <= i && (best <= 0 ||a[j] < 0))
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < n)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = max((ll)0, a[i]);
    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
      solve[idx][i] =
      max(solve[idx][i], solve[2][i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(j <= i && (best <= 0 ||a[j] < 0))
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < 0)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = max((ll)0, a[i]);
    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(j <= i && (best <= 0 ||a[j] < 0))
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < 0)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = (i>0? solve[2][i-1]:0) + a[i];
    solve[idx][i] = max(solve[idx][i], (ll)0);
    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx == 1 && j>0 && j <= i)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  /*
  for(int i = 0 ; i < n; ++i)
    cout << a[i] << " ";
  cout << "\n";
  */
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = (i>0? solve[2][i-1]:0) + a[i];
    solve[idx][i] = max(solve[idx][i], (ll)0);
    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx == 1 && j>0 && j <= i)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
    best = solve[1][i];
    if(i + 1 < n){
     best += solve[0][n-i-2];
    }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = max((ll)0, a[i]);
    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < 0)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx == 1 && j>0)
        before = solve[2][j-1];

    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < n)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300000];
ll solve[3][300000];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];

    solve[idx][i] = max((ll)0, a[i]);
    if(idx == 1)
    {
      solve[idx][i] =
      max(solve[idx][i], (i>0? solve[2][i-1]:0)+ a[i]);
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i){
      best -= a[j++];
      before = solve[2][j-1];
      if(idx == 1)
      solve[idx][i] = max(solve[idx][i], best + before);
    }
    if(idx == 1 && j>0)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    solve[0][i] = solve[1][i] = solve[2][i] = 0;
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n)
     best += solve[1][n-i-2];
    ret = max(best, ret);

    best = solve[1][i];
    if(i + 1 < 0)
     best += solve[0][n-i-2];
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    solve[idx][i] = max((ll)0, a[i]);

    best += a[i];
    while(best <= 0 && j <= i)
      best -= a[j++];

    if(idx > 0 && j>0)
        before = solve[idx-1][j-1];

    if(idx >0)
      solve[idx][i] = max(solve[idx][i], solve[idx-1][i]);

    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i)
    cin >> a[i];

  run(0);
  multi(mul);
  run(1);
  div(mul);
  run(2);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ret = max(solve[2][i], ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    solve[idx][i] = max((ll)0, a[i]);

    best += a[i];
    while((best < 0 || (best == 0 && a[j] < 0)) && j <= i)
      best -= a[j++];

    if(idx > 0 && j>0)
        before = solve[idx-1][j-1];

    if(idx >0)
      solve[idx][i] = max(solve[idx][i], solve[idx-1][i]);

    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i)
    cin >> a[i];

  run(0);
  multi(mul);
  run(1);
  div(mul);
  run(2);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ret = max(solve[2][i], ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;

    if(idx == 1){
      solve[idx][i] =
        max((i>0? solve[2][i-1]:0) + a[i], (ll)0);
      if(j>0)
        before = solve[2][j-1];
    }

    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best + before <= 0 && j <= i){
      best -= a[j];
      if(idx == 1)
        before = solve[2][j];
      ++j;
    }
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
    best = solve[1][i];
    if(i + 1 < n){
     best += solve[0][n-i-2];
    }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <stack>
#include <set>

typedef long long ll;
using namespace  std;

ll n, mul;
ll a[300100];
ll solve[3][300100];

void multi(ll factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] * factor;
}
void div(int factor){
  for(int i = 0; i < n; ++i)
    a[i] = a[i] / factor;
}
void run(int idx){

  ll best = 0;
  int j = 0;
  for(int i = 0; i < n; ++i){
    ll before = 0;
    if(idx == 1 && j>0)
       before = solve[2][j-1];
    if(idx == 1)
      solve[idx][i] = (i>0? solve[2][i-1]:0) + a[i];
    solve[idx][i] = max(solve[idx][i], (ll)0);
    solve[idx][i] = max(solve[idx][i], best + a[i] + before);

    best += a[i];
    while(best <= 0 && j <= i){
      best -= a[j];
      if(idx == 1){
        solve[idx][i] = max(solve[idx][i],
        best + solve[2][j]);
      }
      ++j;
    }

    if(idx == 1 && j>0 && j <= i)
       before = solve[2][j-1];
    solve[idx][i] = max(best + before, solve[idx][i]);
  }
}
void print(int idx){
  for(int i = 0; i < n; ++i)
    cout << solve[idx][i] << " ";
  cout<<"\n";
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  ll ret = 0;
  cin >> n >> mul;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  run(0);
  //print(0);

  std::reverse(a, a + n);
  run(2);
  multi(mul);
  run(1);
  //print(2);
  //print(1);

  for(int i = 0; i < n; ++i){
   ll best = solve[0][i];
   if(i + 1 < n){
     best += solve[1][n-i-2];
   }
    ret = max(best, ret);
    best = solve[1][i];
    if(i + 1 < n){
     best += solve[0][n-i-2];
    }
    ret = max(best, ret);
  }
  cout << ret;
  cout <<"\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

short q , n;
string a[60];

bool Compare(string a , string b)
{
    short i , nra = 0 , nrb = 0;

    for(i = 0 ; i < a.size() / 2 ; i++)
        if(a[i] != a[a.size() - i - 1])
            ++nra;

    for(i = 0 ; i < b.size() / 2 ; i++)
        if(b[i] != b[b.size() - i - 1])
            ++nrb;

    return nra < nrb;
}

int main()
{
    short i , j , m = 0;

    cin >> q;

    while(q--)
    {
        cin >> n;

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

        m = n;

        sort(a + 1 , a + n + 1 , Compare);

        for(i = 1 ; i <= n ; i++)
        {
            m = a[i].size();

            short nr1 = 0;
            short nr0 = 0;

            for(short j = 0 ; j < a[i].size() ; j++)
                if(a[i][j] == '0')
                    ++nr0;
                else ++nr1;

            if(m % 2 == 1 && ((nr1 % 2 == 1 && nr0 % 2 == 0) || (nr1 % 2 == 0 && nr0 % 2 == 1)))
                ;
            else if(m % 2 == 0 && nr1 % 2 == 0 && nr0 % 2 == 0)
                ;
            else
            {
                cout << n - 1 << '\n';
                break;
            }
        }

        if(i == n + 1)
            cout << n << '\n';
    }

    return 0;
}


    #include <bits/stdc++.h>

using namespace std;

short q , n;
string a;

int main()
{
    short i , j , nr = 0 , nr0 , nr1;

    cin >> q;

    while(q--)
    {
        cin >> n;

        nr0 = nr1 = nr = 0;

        for(i = 1 ; i <= n ; i++)
        {
            cin >> a;

            if(a.size() % 2 == 1)
                ++nr;

            for(j = 0 ; j < a.size() ; j++)
                if(a[i] == '0')
                    ++nr0;
                else ++nr1;
        }

        if(nr < nr0 % 2 + nr1 % 2)
            cout << n - 1 << '\n';
        else cout << n << '\n';
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;ll sum4=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
//            cout<<"s:"<<s.length()<<endl;
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    sum4++;
                    if(sum2>=1){
                        sum++;
                        sum2--;
                    }
                }
            }
        }
        sum+=sum2;
        if(sum4%2==0){
            sum=n;
        }
//        cout<<sum<<" "<<sum1<<" "<<sum2<<" "<<sum3<<endl;
        if(sum>n){
            sum=n;
        }
        cout<<max(sum,n-1)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;ll sum4=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
//            cout<<"s:"<<s.length()<<endl;
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    sum4++;
                    if(sum2>=1){
                        sum++;
                        //sum2--;
                    }
                }
            }
        }
        sum+=sum2;
        if(sum4%2==0){
            sum=n;
        }
//        cout<<sum<<" "<<sum1<<" "<<sum2<<" "<<sum3<<endl;
        if(sum>n){
            sum=n;
        }
        cout<<max(sum,n-1)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    if(sum2>=1){
                        sum++;
                        sum2--;
                    }
                }
            }
        }
        sum+=sum2;
//        cout<<sum<<" "<<sum1<<" "<<sum2<<" "<<sum3<<endl;
        if(sum>n){
            sum=n;
        }
        cout<<max(sum,sum3-1)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;ll sum4=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
//            cout<<"s:"<<s.length()<<endl;
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    sum4++;
                    if(sum2>=1){
                        sum++;
                        //sum2--;
                    }
                }
            }
        }
        //sum+=sum2;
        if(sum4%2==0){
            sum=n;
        }
        if(sum2>=1){
            sum=n;
        }
//        cout<<sum<<" "<<sum1<<" "<<sum2<<" "<<sum3<<endl;

        cout<<max(sum,n-1)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    if(sum2>=1){
                        sum++;
                        sum2--;
                    }
                }
            }
        }
        cout<<max(sum,sum3-1)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,sum2;
    cin>>t;
    while(t--){
        cin>>n;
        string s;
        vector<string>v;
        sum=0;sum2=0;ll sum3=0;ll sum4=0;
        for(i=0;i<n;i++){
            cin>>s;
            v.pb(s);
//            cout<<"s:"<<s.length()<<endl;
            if(s.length()%2!=0){
                sum++;
                sum2++;
            }
            if(s.length()%2==0){
                sum1=0;sum3++;
                for(j=0;j<s.length();j++){
                    if(s[j]=='1'){
                        sum1++;
                    }
                }
                if(sum1%2==0){
                    sum++;
                }else{
                    sum4++;
                    if(sum2>=1){
                        sum++;
                        sum2--;
                    }
                }
            }
        }
        sum+=sum2;
        if(sum4%2==0){
            sum=n;
        }
//        cout<<sum<<" "<<sum1<<" "<<sum2<<" "<<sum3<<endl;
        if(sum>n){
            sum=n;
        }
        cout<<max(sum,sum3-1)<<endl;
    }

}


#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {

  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int Q;
  cin >> Q;

  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    vector<int> v;

    int odd = 0;
    int good = 0;
    int bad = 0;

    for (int j = 0; j < n; ++j) {
      string s;
      cin >> s;

      if(s.size() % 2 != 0) {
        odd++;
      } else {
        if( count(s.begin(), s.end(), '1') % 2 == 0 ) {
          good++;
        } else {
          bad++;
        }
      }
    }

    int ret = odd + good + bad;
    if( bad%2 == 1 && odd == 0) {
      ret--;
    }
    cout << ret << '\n';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int solve(vector<int> &v, int n) {

  int count = 0;

  for (auto it = v.rbegin(); it != v.rend(); ++it ) {

    int top = *it;

    if(n == 0)
    {

    }
    else if (n == 1)
    {
      if(top%2 == 1)
      {
        n = 0;
      } else
      {
        continue;
      }
    }
    else if(n >= top)
    {
        n = n - top;
    }
    else
    {
      if( (n%2 && top%2) || (!(n%2) && !(top%2)) ) {
        n = n - top;
      }
      else {
        n = 1;
      }
    }
    count++;
  }

  return count;
}

int main(int argc, char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int Q;
  cin >> Q;

  for(int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    int total = 0;
    vector<int> v;

    for(int j = 0; j < n; ++j) {
      string s;
      cin >> s;
      total += count(s.begin(), s.end(), '1');
      v.push_back(s.size());
    }

    cout << solve(v, total) << '\n';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {

  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int Q;
  cin >> Q;

  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    int odd = 0;
    int bad = 0;

    for (int j = 0; j < n; ++j) {
      string s;
      cin >> s;

      if (s.size() % 2 != 0) {
        odd++;
      } else {
        if (count(s.begin(), s.end(), '1') % 2 != 0) {
          bad++;
        }
      }
    }

    if (bad % 2 == 1 && odd == 0) {
      cout << n - 1 << '\n';
    } else {
      cout << n << '\n';
    }

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int solve(vector<int> &v, int n) {

  int count = 0;

  for (auto it = v.rbegin(); it != v.rend(); ++it) {

    int top = *it;

    if (n == 0) {

    } else if (n == 1) {

      if( top%2 == 1) {
        n = 0;
      } else if (it == v.rend() - 1){
        n = 0;
        continue;
      }

    } else if (n >= top) {
      n = n - top;
    } else {
      if ((n % 2 && top % 2) || (!(n % 2) && !(top % 2))) {
        n = n - top;
      } else {
        if (it == v.rend() - 1) {
          n = 0;
          continue;
        } else {
          n = 1;
        }
      }
    }
    count++;
  }

  return count;
}

int main(int argc, char *argv[]) {
  int Q;
  cin >> Q;

  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    int total = 0;
    vector<int> v;

    for (int j = 0; j < n; ++j) {
      string s;
      cin >> s;
      total += count(s.begin(), s.end(), '1');
      v.push_back(s.size());
    }

    cout << solve(v, total) << '\n';

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int solve(vector<int> &v, int n) {

  int count = 0;

  for (auto it = v.rbegin(); it != v.rend(); ++it) {

    int top = *it;

    if (n == 0) {

    } else if (n == 1) {
      if (top % 2 == 1) {
        n = 0;
      } else {
        continue;
      }
    } else if (n >= top) {
      n = n - top;
    } else {
      if ((n % 2 && top % 2) || (!(n % 2) && !(top % 2))) {
        n = n - top;
      } else {
        if (it == v.rend() - 1) {
          n = 0;
          continue;
        } else {
          n = 1;
        }
      }
    }
    count++;
  }

  return count;
}

int main(int argc, char *argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int Q;
  cin >> Q;

  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    int total = 0;
    vector<int> v;

    for (int j = 0; j < n; ++j) {
      string s;
      cin >> s;
      total += count(s.begin(), s.end(), '1');
      v.push_back(s.size());
    }

    cout << solve(v, total) << '\n';

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int solve(vector<int> &v, int n) {

  int count = 0;

  for (auto it = v.rbegin(); it != v.rend(); ++it) {

    int top = *it;

    if (n == 0) {

    } else if (n == 1) {
      n = 0;
      if (top % 2 != 1) {
        continue;
      }
    } else if (n >= top) {
      n = n - top;
    } else {
      if ((n % 2 && top % 2) || (!(n % 2) && !(top % 2))) {
        n = n - top;
      } else {
        if (it == v.rend() - 1) {
          n = 0;
          continue;
        } else {
          n = 1;
        }
      }
    }
    count++;
  }

  return count;
}

int main(int argc, char *argv[]) {
  int Q;
  cin >> Q;

  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;

    int total = 0;
    vector<int> v;

    for (int j = 0; j < n; ++j) {
      string s;
      cin >> s;
      total += count(s.begin(), s.end(), '1');
      v.push_back(s.size());
    }

    cout << solve(v, total) << '\n';

  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 , l , cnt = 0 , cnt1 = 0 , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{      cnt = 0 ;
       m.clear();
       cnt1 = 0;
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      l = s.size();

      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];

     if( m['1']%2!=0 && m['0']%2!=0 )++cnt;
     else if( (m['1']%2 + m['0']%2) == 1 )++cnt1;

      m['1'] = 0 ; m['0'] = 0 ;
    }
   // cout << cnt << " " << cnt1 << "\n";
    if( cnt1 <  cnt%2 )--n;
    printf("%d\n",n);
    clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 , l , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{
       m.clear();
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      l = s.size();
      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];
    }
    l = 0 ;
    if( m['1']%2!=0 && m['0']%2!=0 )++l;
    n = n  -  l%2;
    printf("%d\n",n);
    clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 , l , cnt = 0 , cnt1 = 0 , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{      cnt = 0 ;
       m.clear();
       cnt1 = 0;
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      l = s.size();

      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];

     if( m['1']%2!=0 && m['0']%2!=0 )++cnt;
     else if( (m['1']%2 + m['0']%2) == 1 )++cnt1;

      m['1'] = 0 ; m['0'] = 0 ;
    }
    if( cnt1 >= cnt || cnt%2==0 );
    else --n;
    printf("%d\n",n);
    clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 , l , cnt = 0 , cnt1 = 0 , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{      cnt = 0 ;
       m.clear();
       cnt1 = 0;
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      l = s.size();

      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];

     if( m['1']%2!=0 && m['0']%2!=0 )++cnt;
     else if( (m['1']%2 + m['0']%2) == 1 )++cnt1;

      m['1'] = 0 ; m['0'] = 0 ;
    }
    if( cnt1 >= cnt/2 || cnt%2==0 );
    else --n;
    printf("%d\n",n);
    clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 , l , cnt = 0 , cnt1 = 0 , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{      cnt = 0 ;
       m.clear();
       cnt1 = 0;
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      l = s.size();

      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];

     if( m['1']%2!=0 && m['0']%2!=0 )++cnt;
     else if( (m['1']%2 + m['0']%2) == 1 )++cnt1;

      m['1'] = 0 ; m['0'] = 0 ;
    }
    if( cnt1 >= cnt/2 && cnt1 || cnt%2==0 );
    else --n;
    printf("%d\n",n);
    clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6;
const ll M=1e9;
ll  n , mx = 0 ,ind , t = 1 ;
map<char,int>m;string s;
ll Icm(ll i,ll j)
{
   return (i*j)/__gcd(i,j);
}
ll po(ll i,ll j)
{  if( j == 0)return 1;
   return i*po( i , j-1 );
}
void Show_re()
{
}
void clear_()
{
       m.clear();
}
void solve()
{
    scanf("%d",&n);
    for(int i =  0  ;  i < n  ; ++i)
    {
      cin >> s ;
      int l = s.size();
      for(int j = 0 ; j < l ; ++j)
      ++m[s[j]];
    }
    if(m['1']%2==0||m['0']%2==0)
    printf("%d\n",n);
    else{
        printf("%d\n",n-1);
    }
 clear_();
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    solve();
  }
}


#include<bits/stdc++.h>
int main(){
	int t,n;
	scanf("%d",&t);
	char s[60];
	while (t--){
		scanf("%d",&n);
		int i,f=0;
		for (i=0; i<n; i++){
			scanf("%s",s);
			if (strlen(s)&1) f=1;
		}
		printf("%d\n",f? n:n-1);
	}
}


#include<bits/stdc++.h>
#define SeeYouAgain return 0
using ll=long long int;
using namespace std;
int main(){
	int t,n;
	scanf("%d",&t);
	char s[60][60];
	while (t--){
		vector<int>v;
		scanf("%d",&n);
		int one=0,zero=0,l,i,j,ans=0;
		for (i=0; i<n; i++){
			scanf("%s",s[i]);
			l=strlen(s[i]);
			for (j=0; j<l; j++)
				s[i][j]=='1'? one++:zero++;
			v.push_back(l);
		}
		for (i=0; i<v.size(); i++){
			//printf("one=%d zero=%d for %d\n",one,zero,v[i]);
			if (!(v[i]&1)){
				if (one>=v[i]){
					one-=v[i],ans++;
					v.erase(v.begin()+i), i--;
				}
				else if (zero>=v[i]){
					zero-=v[i],ans++;
					v.erase(v.begin()+i), i--;
				}
				else{
					int x=0,ze=zero;
					if (zero&1) x=zero-1, zero=1;
					else x=zero, zero=0;
					x=v[i]-x;
					if (one>=x){
						one-=x;
						ans++;
						v.erase(v.begin()+i), i--;
					}else zero=ze;
				}
			}
		}
		//puts("For odd");
		for (i=0; i<v.size(); i++){
			//printf("one=%d zero=%d for %d\n",one,zero,v[i]);
			if (!(v[i]&1)) continue;
			if (one>=v[i]){
				one-=v[i],ans++;
				v.erase(v.begin()+i), i--;
			}
			else if (zero>=v[i]){
				zero-=v[i],ans++;
				v.erase(v.begin()+i), i--;
			}
			else{
				int x=zero,ze=zero;
				zero=0;
				x=v[i]-x;
				if (one>=x){
					one-=x;
					ans++;
					v.erase(v.begin()+i), i--;
				}else zero=ze;
			}
		}

		//printf("one=%d zero=%d\n",one,zero);
		printf("%d\n",ans);

	}
	SeeYouAgain;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int t,n,i,f,o,l;
int main(){
	cin>>t;
	while (t--){
		cin>>n;
		for (i=o=f=0; i<n; i++){
			cin>>s;
			if (s.size()&1) f=1;
			for (auto it:s) o+=it-'0';
		}
		if (o&1 && !f) n--;
		cout<<n<<endl;
	}
}


#include<bits/stdc++.h>
char s[60];
int t,n,i,j,f,o,l;
int main(){
	scanf("%d",&t);
	while (t--){
		scanf("%d",&n);
		for (i=o=f=0; i<n; i++){
			scanf("%s",s);
			if (strlen(s)&1) f=1;
			for (j=0; j<strlen(s); j++)
				o+=s[j]-'0';
		}
		if (o&1 && !f) n--;
		printf("%d\n",n);
	}
}


#include<bits/stdc++.h>
using namespace std;
string s;
int t,n,i,f,o,l;
int main(){
	cin>>t;
	while (t--){
		cin>>n;
		for (i=o=f=0; i<n; i++){
			cin>>s;
			if (s.size()&1) f=1;
			for (it:s) o+=it-'0';
		}
		if (o&1 && !f) n--;
		cout<<n<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		int ans=0,sum1=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				sum1+=s.size();
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2==0&&count2%2==0) ans++;
				else sum2++;
			}
		}
		cout<<ans+min(sum1,sum2)<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		int ans=0,sum1=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				sum1+=s.size();
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2!=0&&count2%2!=0&&count1==count2) ans++;
				else sum2++;
			}
		}
		cout<<ans+min(sum1,sum2)<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		int ans=0,sum1=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				sum1+=s.size();
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2==0&&count2%2==0) ans++;
				else sum2++;
			}
		}
		if(sum1>=sum2)
		cout<<ans+min(sum1,sum2)<<endl;
		else cout<<ans+(sum2-sum1)-(sum2-sum1)%2+sum1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		int ans=0,flag=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				flag=1;
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2==0&&count2%2==0) ans++;
				else sum2++;
			}
		}
		if(flag) cout<<n<<endl;
		else {
			if(sum2%2) cout<<n-1<<endl;
			else cout<<n<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		ll ans=0,sum1=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				sum1+=s.size();
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2==0&&count2%2==0) ans++;
				else sum2++;
			}
		}
		if(sum1>=sum2)
		cout<<ans+min(sum1,sum2)<<endl;
		else cout<<ans+(sum2-sum1)-(sum2-sum1)%2+sum1<<endl;
	}
	return 0;
}