#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <climits>
#include <ctime>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring> // for memset
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define INF INT_MAX
#define LINF LLONG_MAX
#define EPS 1e-9
#define MOD 1000000007 // 10**9 + 7
#define MAXN 100001
#define ALPH 26 // Latin alphabet size
#define DALPH 52 // Double Latin alphabet size

#define mp(a, b) make_pair(a, b)
#define all(a) (a).begin(), (a).end()

#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()

#ifndef __GNUC__
    typedef unsigned long int uint;
#endif

typedef signed short int int16;
typedef unsigned short int uint16;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef long double real; // in msvc same as double

typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

int n, len;
vector<int> L;
int k;

class minq {
    public:
        bool operator () (const pii &e1, const pii &e2) {
            return e1 > e2;
        }
};

priority_queue<pii> Qk;
priority_queue<pii, vector<pii>, minq> Ql;
vector<int> isIn;
int szk, szl;
int64 sumk, suml;

int gettop(priority_queue<pii> &Q) {
    while (!isIn[Q.top().second]) {
        Q.pop();
    }

    return Q.top().first;
}

int gettop(priority_queue<pii, vector<pii>, minq> &Q) {
    while (!isIn[Q.top().second]) {
        Q.pop();
    }

    return Q.top().first;
}

void add(int val, int ind) {
    if (val < 0) {
        if (szk == k && gettop(Qk) > val) {
            pii e = Qk.top();
            Qk.pop();

            --szk;
            sumk -= e.first;

            Ql.push(e);
            isIn[e.second] = 2;
            ++szl;
            suml += e.first;
        }

        if (szk < k) {
            Qk.push(mp(val, ind));
            isIn[ind] = 1;
            ++szk;
            sumk += val;
            return;
        }
    }

    Ql.push(mp(val, ind));
    isIn[ind] = 2;
    ++szl;
    suml += val;
}

void del(int val, int ind) {
    if (isIn[ind] == 1) {
        --szk;
        sumk -= val;

        if (szl && gettop(Ql) < 0) {
            pii e = Ql.top();
            Ql.pop();
            --szl;
            suml -= e.first;

            Qk.push(e);
            ++szk;
            sumk += e.first;
            isIn[e.second] = 1;

        }
    } else {
        --szl;
        suml -= val;
    }

    isIn[ind] = 0;
}

int64 solve(vector<int> &seq) {
    Qk = priority_queue<pii>();
    Ql = priority_queue<pii, vector<pii>, minq>();

    isIn.clear();
    isIn.resize(n, 0);
    szk = szl =  0;
    sumk = suml = 0;

    for (int i = 0; i < len; ++i) {
        add(seq[i], i);
    }

    int64 ans = 0;
    for (int l = 0, r = len - 1;;) {
        ans = max(ans, suml - sumk);

        if (r + 1 == n) {
            break;
        }

        add(seq[r + 1], r + 1);
        del(seq[l], l);
        ++l, ++r;
    }

    return ans;
}

int main() {
    #ifdef _DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("log.txt", "w", stderr);
    #endif

    scanf("%d %d", &n, &len);
    L.resize(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &L[i]);
    }

    scanf("%d", &k);

    int64 ans = solve(L);
    for (int i = 0; i < n; ++i) {
        L[i] *= -1;
    }

    ans = max(ans, solve(L));
    printf("%I64d\n", ans);
}


#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <climits>
#include <ctime>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring> // for memset
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define INF INT_MAX
#define LINF LLONG_MAX
#define EPS 1e-9
#define MOD 1000000007 // 10**9 + 7
#define MAXN 100001
#define ALPH 26 // Latin alphabet size
#define DALPH 52 // Double Latin alphabet size

#define mp(a, b) make_pair(a, b)
#define all(a) (a).begin(), (a).end()

#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()

#ifndef __GNUC__
    typedef unsigned long int uint;
#endif

typedef signed short int int16;
typedef unsigned short int uint16;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef long double real; // in msvc same as double

typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

int n, len;
vector<int> L;
int k;

class minq {
    public:
        bool operator () (const pii &e1, const pii &e2) {
            return e1 > e2;
        }
};

priority_queue<pii> Qk;
priority_queue<pii, vector<pii>, minq> Ql;
vector<int> isIn;
int szk, szl;
int64 sumk, suml;

int gettop(priority_queue<pii> &Q) {
    while (!isIn[Q.top().second]) {
        Q.pop();
    }

    return Q.top().first;
}

int gettop(priority_queue<pii, vector<pii>, minq> &Q) {
    while (!isIn[Q.top().second]) {
        Q.pop();
    }

    return Q.top().first;
}

void add(int val, int ind) {
    if (val < 0) {
        if (szk > 0 && szk == k && gettop(Qk) > val) {
            pii e = Qk.top();
            Qk.pop();

            --szk;
            sumk -= e.first;

            Ql.push(e);
            isIn[e.second] = 2;
            ++szl;
            suml += e.first;
        }

        if (szk < k) {
            Qk.push(mp(val, ind));
            isIn[ind] = 1;
            ++szk;
            sumk += val;
            return;
        }
    }

    Ql.push(mp(val, ind));
    isIn[ind] = 2;
    ++szl;
    suml += val;
}

void del(int val, int ind) {
    if (isIn[ind] == 1) {
        --szk;
        sumk -= val;

        if (szl && gettop(Ql) < 0) {
            pii e = Ql.top();
            Ql.pop();
            --szl;
            suml -= e.first;

            Qk.push(e);
            ++szk;
            sumk += e.first;
            isIn[e.second] = 1;

        }
    } else {
        --szl;
        suml -= val;
    }

    isIn[ind] = 0;
}

int64 solve(vector<int> &seq) {
    Qk = priority_queue<pii>();
    Ql = priority_queue<pii, vector<pii>, minq>();

    isIn.clear();
    isIn.resize(n, 0);
    szk = szl =  0;
    sumk = suml = 0;

    for (int i = 0; i < len; ++i) {
        add(seq[i], i);
    }

    int64 ans = 0;
    for (int l = 0, r = len - 1;;) {
        ans = max(ans, suml - sumk);

        if (r + 1 == n) {
            break;
        }

        add(seq[r + 1], r + 1);
        del(seq[l], l);
        ++l, ++r;
    }

    return ans;
}

int main() {
    #ifdef _DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("log.txt", "w", stderr);
    #endif

    scanf("%d %d", &n, &len);
    L.resize(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &L[i]);
    }

    scanf("%d", &k);

    int64 ans = solve(L);
    for (int i = 0; i < n; ++i) {
        L[i] *= -1;
    }

    ans = max(ans, solve(L));
    printf("%I64d\n", ans);
}


#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

const int toMod = 1000000007;

int n, len, k;
int a[1 << 17];
int64 fp[1 << 17];
int64 fn[1 << 17];

inline int64 abs64(int64 x)
{
	if (x < 0) return -x;
	return x;
}

inline void init()
{
	scanf("%d%d", &n, &len);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		fp[i] = 0;
		fn[i] = 0;
		if (a[i] > 0) fp[i] = a[i];
		if (a[i] < 0) fn[i] = a[i];
		if (i)
		{
			fp[i] += fp[i - 1];
			fn[i] += fn[i - 1];
		}
	}
	scanf("%d", &k);
	if (k > len) k = len;
}

inline int64 getSumP(int l, int r)
{
	int64 res = fp[r];
	if (l) res -= fp[l - 1];
	return res;
}

inline int64 getSumN(int l, int r)
{
	int64 res = fn[r];
	if (l) res -= fn[l - 1];
	return res;
}

struct megaset
{
	int cnt;
	int LAST;
	int64 curSum;
	int inSet[1 << 17];
	priority_queue < pii, vector<pii>, greater<pii> > qmin;
	priority_queue < pii > qmax;

	void clear()
	{
		LAST = -1;
		curSum = 0;
		cnt = 0;
		memset(inSet, 0, sizeof inSet);
		while (!qmin.empty()) qmin.pop();
		while (!qmax.empty()) qmax.pop();
	}

	void refresh()
	{
		if (!k) return;
		while (!qmax.empty())
		{
			if (qmax.top().second <= LAST)
			{
				qmax.pop();
				continue;
			}
			if (cnt == k) break;
			pii cur = qmax.top();
			qmax.pop();
			qmin.push(cur);
			curSum += (int64)cur.first;
			inSet[cur.second] = 1;
			++cnt;
		}
		while (!qmax.empty())
		{
			if (qmax.top().second <= LAST)
			{
				qmax.pop();
				continue;
			}
			pii cur = qmax.top();
			while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
			if (cur.first > qmin.top().first)
			{
				qmax.pop();
				pii cur2 = qmin.top();
				qmin.pop();
				qmin.push(cur);
				qmax.push(cur2);
				curSum -= (int64)cur2.first;
				curSum += (int64)cur.first;
				inSet[cur2.second] = 0;
				inSet[cur.second] = 1;
			} else break;
		}
	}

	void remove(int id)
	{
		LAST = id;
		if (!inSet[id]) return;
		inSet[id] = 0;
		curSum -= a[id];
		--cnt;
		while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
		refresh();
	}

	void add(int id)
	{
		qmax.push(pii(a[id], id));
		refresh();
	}
};

megaset A;

inline int64 solve()
{
	A.clear();

	for (int i = 0; i < len; ++i)
	{
		if (a[i] > 0) A.add(i);
	}

	int64 res = abs64(getSumP(0, len - 1) - 2 * A.curSum + getSumN(0, len - 1));

	for (int i = len; i < n; ++i)
	{
		if (a[i - len] > 0) A.remove(i - len);
		if (a[i] > 0) A.add(i);
		int64 cur = abs64(getSumP(i - len + 1, i) - 2 * A.curSum + getSumN(i - len + 1, i));
		res = max(res, cur);
	}

	return res;
}

int main()
{
	//freopen ("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);

	init();

	int64 res = solve();
	for (int i = 0; i < n; ++i)
		a[i] = -a[i];
	for (int i = 0; i < n; ++i)
	{
		fp[i] = 0;
		fn[i] = 0;
		if (a[i] > 0) fp[i] = a[i];
		if (a[i] < 0) fn[i] = a[i];
		if (i)
		{
			fp[i] += fp[i - 1];
			fn[i] += fn[i - 1];
		}
	}
	res = max(res, solve());
	cout << res << endl;

	return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : -1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                //SUM=0;
                //find(1,1,i,i+len-1,len);
                ans1=s[i].sum1+s[i].sum2;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,len-mm);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : -1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                //SUM=0;
                //find(1,1,i,i+len-1,len);
                ans1=s[i].sum1+s[i].sum2;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,len-mm+1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 - *(int *)b1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                //SUM=0;
                //find(1,1,i,i+len-1,len);
                ans1=s[i].sum1+s[i].sum2;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,len-mm+1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : -1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        /*  scanf("%d",&m);
        printf("Case #%d:\n",t);
        while(m--)
        {
        scanf("%d%d",&from,&to);
        from++;
        to++;
        if((to-from)%2==0)
        {
        SUM=0;
        k=(to-from)/2+1;
        find(1,1,from,to,(to-from)/2+1);
        ans1=SUM;
        val1=VAL;
        SUM=0;
        find(1,1,from,to,to-from+1);
        ans2=SUM;
        val2=VAL;
        ans=val1*k-ans1+ans2-ans1-(k-1)*val1;
        printf("%I64d\n",ans);
        }
        else
        {
        SUM=0;
        k=(to-from+1)/2;
        find(1,1,from,to,k);
        ans1=SUM;
        val1=VAL;
        SUM=0;
        find(1,1,from,to,to-from+1);
        ans2=SUM;
        val2=VAL;
        Max1=val1*k-ans1+ans2-ans1-k*val1;

          SUM=0;
          k++;
          find(1,1,from,to,k);
          ans1=SUM;
          val1=VAL;
          Max2=val1*k-ans1+ans2-ans1-(k-2)*val1;
          printf("%I64d\n",Max1<Max2?Max1:Max2);

            }
            }
        printf("\n");*/
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                SUM=0;
                find(1,1,i,i+len-1,len);
                ans1=SUM;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,mm+len-1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];

int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : -1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                //SUM=0;
                //find(1,1,i,i+len-1,len);
                ans1=s[i].sum1+s[i].sum2;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,len-mm+1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : 0;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }
            Max2=s[i].sum1+s[i].sum2;
            if(Max2<0) Max2=-Max2;
            if(Max2>Max1) Max1=Max2;
            if(K==0) continue;
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                //SUM=0;
                //find(1,1,i,i+len-1,len);
                ans1=s[i].sum1+s[i].sum2;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,len-mm+1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


# include<stdio.h>
# include<string.h>
# include<stdlib.h>
# define N 100005
struct node{
    int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];//第i个点前面有多少个点进入到了右子树(包括第i个点)
__int64 sum[20][N];//记录比当前元素小的元素和
int a[N];
__int64 VAL,SUM;
struct node1{
    int count1;//负数的个数
    int count2;//正数的个数
    __int64 sum1;//负数的和
    __int64 sum2;//正数的和
}s[N];
int cmp(const void *a1,const void *b1)
{
    return *(int *)a1 > *(int *)b1 ? 1 : -1;
}
void bulid(int l,int r,int h,int t)
{
    int i,mid,count;
    int count1,ans1,ans2;
    tree[t].l=l;
    tree[t].r=r;
    if(l==r) return;
    mid=(l+r)/2;
    count=0;
    for(i=l;i<=r;i++)
        if(val[h][i]<a[mid]) count++;
        //count记录该区间比中间值小的元素的个数，那进入右孩子的与中间值相等的点的个数是mid-l+1-count;
        ans1=l;
        ans2=mid+1;
        count1=0;
        for(i=l;i<=r;i++)
        {
            if(i==l) sum[h][i]=0;
            else sum[h][i]=sum[h][i-1];
            if(val[h][i]<a[mid])
            {
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else if(val[h][i]==a[mid] && count1<mid-l+1-count)
            {
                count1++;
                val[h+1][ans1++]=val[h][i];
                sum[h][i]+=val[h][i];
            }
            else val[h+1][ans2++]=val[h][i];
            num[h][i]=ans1-l;
        }
        bulid(l,mid,h+1,2*t);
        bulid(mid+1,r,h+1,2*t+1);
}
void find(int t,int h,int from,int to,int k)
{
    int ans1,ans2;
    __int64 sum1,sum2;
    int l,r;
    l=tree[t].l;
    r=tree[t].r;
    if(l==r) {SUM+=val[h][l];VAL=val[h][l];return;}
    if(from==1) ans1=0;
    else ans1=num[h][from+l-2];
    ans2=num[h][to+l-1];
    if(ans2-ans1>=k) find(2*t,h+1,ans1+1,ans2,k);
    else
    {
        find(2*t+1,h+1,from-1-ans1+1,to-ans2,k-(ans2-ans1));///////////一定要注意，两次都写错了
        if(from==1) sum1=0;
        else sum1=sum[h][l+from-2];
        sum2=sum[h][to+l-1];
        SUM+=(sum2-sum1);
    }
}
int main()
{
    int i,j,n,ncase,t,K,len,mm;
    __int64 ans1,ans2,val1,val2,ans;
    __int64 Max1,Max2;
    int from,to,k;

    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&val[1][i]);
            a[i]=val[1][i];
        }
        qsort(a+1,n,sizeof(a[1]),cmp);
        bulid(1,n,1,1);
        /*  scanf("%d",&m);
        printf("Case #%d:\n",t);
        while(m--)
        {
        scanf("%d%d",&from,&to);
        from++;
        to++;
        if((to-from)%2==0)
        {
        SUM=0;
        k=(to-from)/2+1;
        find(1,1,from,to,(to-from)/2+1);
        ans1=SUM;
        val1=VAL;
        SUM=0;
        find(1,1,from,to,to-from+1);
        ans2=SUM;
        val2=VAL;
        ans=val1*k-ans1+ans2-ans1-(k-1)*val1;
        printf("%I64d\n",ans);
        }
        else
        {
        SUM=0;
        k=(to-from+1)/2;
        find(1,1,from,to,k);
        ans1=SUM;
        val1=VAL;
        SUM=0;
        find(1,1,from,to,to-from+1);
        ans2=SUM;
        val2=VAL;
        Max1=val1*k-ans1+ans2-ans1-k*val1;

          SUM=0;
          k++;
          find(1,1,from,to,k);
          ans1=SUM;
          val1=VAL;
          Max2=val1*k-ans1+ans2-ans1-(k-2)*val1;
          printf("%I64d\n",Max1<Max2?Max1:Max2);

            }
            }
        printf("\n");*/
        scanf("%d",&K);
        s[1].count1=0;
        s[1].count2=0;
        s[1].sum1=0;
        s[1].sum2=0;
        for(i=1;i<=len;i++)
        {
            if(val[1][i]<0) {s[1].count1++;s[1].sum1+=val[1][i];}
            else if(val[1][i]>0) {s[1].count2++;s[1].sum2+=val[1][i];}
        }
        Max1=-1;
        for(i=1;i<=n-len+1;i++)
        {
            if(i!=1)
            {
                s[i]=s[i-1];
                if(val[1][i-1]<0)
                {
                    s[i].count1--;
                    s[i].sum1-=val[1][i-1];
                }
                else if(val[1][i-1]>0)
                {
                    s[i].count2--;
                    s[i].sum2-=val[1][i-1];
                }
                if(val[1][i+len-1]<0)
                {
                    s[i].count1++;
                    s[i].sum1+=val[1][i+len-1];
                }
                else if(val[1][i+len-1]>0)
                {
                    s[i].count2++;
                    s[i].sum2+=val[1][i+len-1];
                }
            }

            if(K==0)
            {
                Max2=s[i].sum1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
                continue;
            }
            if(s[i].count1!=0)
            {
                mm=K<s[i].count1?K:s[i].count1;
                SUM=0;
                find(1,1,i,i+len-1,mm);
                ans1=SUM;
                ans1=-ans1;
                Max2=s[i].sum1+ans1+ans1+s[i].sum2;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
            if(s[i].count2!=0)
            {
                SUM=0;
                find(1,1,i,i+len-1,len);
                ans1=SUM;
                mm=K<s[i].count2?K:s[i].count2;
                SUM=0;
                find(1,1,i,i+len-1,mm+len-1);
                ans2=SUM;
                val2=VAL;
                ans=ans1-ans2+val2;
                Max2=s[i].sum1+s[i].sum2-ans-ans;
                if(Max2<0) Max2=-Max2;
                if(Max2>Max1) Max1=Max2;
            }
        }
        printf("%I64d\n",Max1);
    }
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    pq.erase(MP(a[i - 1], i - 1));
                    ++k;
                } else {
                    cur -= a[i - 1];
                    can.erase(MP(a[i - 1], i - 1));
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] >= 0) {
            } else {
                can.insert(MP(a[i + len - 1], i + len - 1));
                for (; !can.empty() && k; can.erase(can.begin()), --k) {
                    pii p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
                for (; !can.empty() && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
                    pii p = *pq.rbegin();
                    inv[p.second] = false;
                    cur += 2 * p.first;
                    pq.erase(p);
                    p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
            }
            res = max(res, abs64(cur));
        }
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    for (int it = 2; it--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        k = min(k, len);
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    pq.erase(MP(a[i - 1], i - 1));
                    ++k;
                } else {
                    cur -= a[i - 1];
                    can.erase(MP(a[i - 1], i - 1));
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] >= 0) {
            } else {
                can.insert(MP(a[i + len - 1], i + len - 1));
                for (; !can.empty() && k; can.erase(can.begin()), --k) {
                    pii p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
                for (; !can.empty() && k && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
                    pii p = *pq.rbegin();
                    inv[p.second] = false;
                    cur += 2 * p.first;
                    pq.erase(p);
                    p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
            }
            res = max(res, abs64(cur));
        }
        if (!it) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    pq.erase(MP(a[i - 1], i - 1));
                    ++k;
                } else {
                    cur -= a[i - 1];
                    can.erase(MP(a[i - 1], i - 1));
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] < 0) {
                can.insert(MP(a[i + len - 1], i + len - 1));
            }
            for (; !can.empty() && k; --k) {
                pii p = *can.begin();
                inv[p.second] = true;
                cur -= 2 * p.first;
                pq.insert(p);
                can.erase(p);
            }
            for (; !can.empty() && !pq.empty() && can.begin()->first < pq.rbegin()->first; ) {
                pii p = *pq.rbegin();
                inv[p.second] = false;
                cur += 2 * p.first;
                pq.erase(p);
                can.insert(p);
                p = *can.begin();
                inv[p.second] = true;
                cur -= 2 * p.first;
                pq.insert(p);
                can.erase(p);
            }
            res = max(res, abs64(cur));
        }
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
int b[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        for (int i = 0; i + len - 1 < n; ++i) {
            int64 cur = 0;
            int m = 0;
            for (int j = 0; j < len; ++j)
                if (a[i + j] < 0)
                    b[m++] = a[i + j];
                else
                    cur += a[i + j];
            sort(b, b + m);
            for (int j = 0; j < m; ++j)
                if (j < k)
                    cur -= b[j];
                else
                    cur += b[j];
            res = max(res, abs64(cur));
        }
        //set<pii> pq, can;
        //for (int i = 0; i < len; ++i) {
        //  if (a[i] < 0)
        //      pq.insert(MP(a[i], i));
        //  cur += a[i];
        //}
        //for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
        //  cur -= 2 * it->first;
        //  inv[it->second] = true;
        //}
        //for (int i = 0; i < len; ++i) {
        //  if (a[i] < 0)
        //      if (!inv[i])
        //          pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        //}
        //res = max(res, abs64(cur));
        //for (int i = 1; i + len - 1 < n; ++i) {
        //  if (a[i - 1] >= 0) {
        //      cur -= a[i - 1];
        //  } else {
        //      if (inv[i - 1]) {
        //          cur += a[i - 1];
        //          pq.erase(MP(a[i - 1], i - 1));
        //          ++k;
        //      } else {
        //          cur -= a[i - 1];
        //          can.erase(MP(a[i - 1], i - 1));
        //      }
        //  }
        //  cur += a[i + len - 1];
        //  if (a[i + len - 1] >= 0) {
        //  } else {
        //      can.insert(MP(a[i + len - 1], i + len - 1));
        //      for (; !can.empty() && k; can.erase(can.begin()), --k) {
        //          pii p = *can.begin();
        //          inv[p.second] = true;
        //          cur -= 2 * p.first;
        //          pq.insert(p);
        //      }
        //      for (; !can.empty() && !pq.empty() && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
        //          pii p = *pq.rbegin();
        //          inv[p.second] = false;
        //          cur += 2 * p.first;
        //          pq.erase(p);
        //          can.insert(p);
        //          p = *can.begin();
        //          inv[p.second] = true;
        //          cur -= 2 * p.first;
        //          pq.insert(p);
        //      }
        //  }
        //  res = max(res, abs64(cur));
        //}
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    pq.erase(MP(a[i - 1], i - 1));
                    ++k;
                } else {
                    cur -= a[i - 1];
                    can.erase(MP(a[i - 1], i - 1));
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] >= 0) {
            } else {
                can.insert(MP(a[i + len - 1], i + len - 1));
                for (; !can.empty() && k; can.erase(can.begin()), --k) {
                    pii p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
                for (; !can.empty() && !pq.empty() && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
                    pii p = *pq.rbegin();
                    inv[p.second] = false;
                    cur += 2 * p.first;
                    pq.erase(p);
                    can.insert(p);
                    p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
            }
            res = max(res, abs64(cur));
        }
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
int b[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        for (int i = 0; i + len - 1 < n; ++i) {
            int64 cur = 0;
            int m = 0;
            for (int j = 0; j < len; ++j)
                if (a[i + j] < 0)
                    b[m++] = a[i + j];
                else
                    cur += a[i + j];
            sort(b, b + m);
            for (int j = 0; j < len; ++j)
                if (j < k)
                    cur -= b[j];
                else
                    cur += b[j];
            res = max(res, abs64(cur));
        }
        //set<pii> pq, can;
        //for (int i = 0; i < len; ++i) {
        //  if (a[i] < 0)
        //      pq.insert(MP(a[i], i));
        //  cur += a[i];
        //}
        //for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
        //  cur -= 2 * it->first;
        //  inv[it->second] = true;
        //}
        //for (int i = 0; i < len; ++i) {
        //  if (a[i] < 0)
        //      if (!inv[i])
        //          pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        //}
        //res = max(res, abs64(cur));
        //for (int i = 1; i + len - 1 < n; ++i) {
        //  if (a[i - 1] >= 0) {
        //      cur -= a[i - 1];
        //  } else {
        //      if (inv[i - 1]) {
        //          cur += a[i - 1];
        //          pq.erase(MP(a[i - 1], i - 1));
        //          ++k;
        //      } else {
        //          cur -= a[i - 1];
        //          can.erase(MP(a[i - 1], i - 1));
        //      }
        //  }
        //  cur += a[i + len - 1];
        //  if (a[i + len - 1] >= 0) {
        //  } else {
        //      can.insert(MP(a[i + len - 1], i + len - 1));
        //      for (; !can.empty() && k; can.erase(can.begin()), --k) {
        //          pii p = *can.begin();
        //          inv[p.second] = true;
        //          cur -= 2 * p.first;
        //          pq.insert(p);
        //      }
        //      for (; !can.empty() && !pq.empty() && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
        //          pii p = *pq.rbegin();
        //          inv[p.second] = false;
        //          cur += 2 * p.first;
        //          pq.erase(p);
        //          can.insert(p);
        //          p = *can.begin();
        //          inv[p.second] = true;
        //          cur -= 2 * p.first;
        //          pq.insert(p);
        //      }
        //  }
        //  res = max(res, abs64(cur));
        //}
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    pq.erase(MP(a[i - 1], i - 1));
                    ++k;
                } else {
                    cur -= a[i - 1];
                    can.erase(MP(a[i - 1], i - 1));
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] >= 0) {
            } else {
                can.insert(MP(a[i + len - 1], i + len - 1));
                for (; !can.empty() && k; can.erase(can.begin()), --k) {
                    pii p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
                for (; !can.empty() && !pq.empty() && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
                    pii p = *pq.rbegin();
                    inv[p.second] = false;
                    cur += 2 * p.first;
                    pq.erase(p);
                    p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
            }
            res = max(res, abs64(cur));
        }
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#pragma comment(linker, "/STACK:64000000")

template<class T> inline T sqr (T x) {return x * x;}

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<pii, int> ppi;
typedef pair<int64, int> pii64;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
#define next huynext
#define FAIL ++*(int*)0
#define eps  1e-9
#define inf  0x7f7f7f7f
#define MP make_pair
#define sz(C) (int)((C).size())
#define all(C) (C).begin(), (C).end()
#define TASK "codeforces"
#define RR 300000001

inline int64 abs64 (int64 x) {
    return x < 0 ? - x : x;
}

int n, len, k;
int a[1 << 17];
bool inv[1 << 17] = {0};

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    scanf("%d", &k);
    int64 res = LLONG_MIN;
    k = min(k, len);
    for (int iter = 2; iter--; ) {
        int k = ::k;
        int64 cur = 0;
        set<pii> pq, can;
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                pq.insert(MP(a[i], i));
            cur += a[i];
        }
        for (set<pii>::iterator it = pq.begin(); it != pq.end() && k; ++it, --k) {
            cur -= 2 * it->first;
            inv[it->second] = true;
        }
        for (int i = 0; i < len; ++i) {
            if (a[i] < 0)
                if (!inv[i])
                    pq.erase(MP(a[i], i)), can.insert(MP(a[i], i));
        }
        res = max(res, abs64(cur));
        for (int i = 1; i + len - 1 < n; ++i) {
            if (a[i - 1] >= 0) {
                cur -= a[i - 1];
            } else {
                if (inv[i - 1]) {
                    cur += a[i - 1];
                    if (!pq.erase(MP(a[i - 1], i - 1))) FAIL;
                    ++k;
                } else {
                    cur -= a[i - 1];
                    if (!can.erase(MP(a[i - 1], i - 1))) FAIL;
                }
            }
            cur += a[i + len - 1];
            if (a[i + len - 1] >= 0) {
            } else {
                can.insert(MP(a[i + len - 1], i + len - 1));
                for (; !can.empty() && k; can.erase(can.begin()), --k) {
                    pii p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
                for (; !can.empty() && k && can.begin()->first < pq.rbegin()->first; can.erase(can.begin())) {
                    pii p = *pq.rbegin();
                    inv[p.second] = false;
                    cur += 2 * p.first;
                    pq.erase(p);
                    p = *can.begin();
                    inv[p.second] = true;
                    cur -= 2 * p.first;
                    pq.insert(p);
                }
            }
            res = max(res, abs64(cur));
        }
        if (!iter) break;
        memset(inv, 0, sizeof inv);
        for (int i = 0; i < n; ++i)
            a[i] = - a[i];
    }
    cout << res << endl;

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <assert.h>

//#pragma warning(disable:4996)
using namespace std;

#define TIME fprintf(stderr,"\n-----------\ntime : %.2f sec\n",double(clock())/CLOCKS_PER_SEC);
#define EXIT exit(0);
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INP(_X) scanf("%d",& _X);
#define OUT(_X) printf("%d ",_X);
#define LINE printf("\n");
#define DOUT(_X) fprintf(stderr,"%d ",_X);
#define DLINE fprintf(stderr,"\n");

#define M 112345
#define MOD 0
#define ADD(_X,_Y) _X=(_X+_Y)%MOD;

#define abs(_Z) (((_Z)<0)?-(_Z):(_Z))
#define f0(_X,_Y) for(_X=0;_X<_Y;++_X)
#define f1(_X,_Y) for(_X=1;_X<=_Y;++_X)
#define ff(_X,_Y,_Z) for(_X=_Y;_X<=_Z;++_X)
#define fF(_X,_Y,_Z) for(_X=_Y;_X<_Z;++_X)
#define pb push_back
#define sz(_X) _X.size()
typedef long long ll;

int a[M],cnt[M*3],pos[M]; ll tree[M*3];
struct P{int i,num;
    bool friend operator < (const P &p,const P &q)
    {
        if(p.num!=q.num) return p.num<q.num;
        return p.i<q.i;
    }
} b[M];

int main()
{
    int n,m,len,i,j,k,size=0,N;
    ll ans,s=0,s2;

    INP(n) INP(len)
    f1(i,n) INP(a[i])
    f1(i,n) b[i].i=i, b[i].num=a[i];
    INP(m) if(m>len) m=len;
    for(N=1;N<n;N<<=1);--N;
    sort(b+1,b+n+1);
    f1(i,n) pos[b[i].i]=i;

    f1(i,len-1)
    {
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];
        s+=a[i];
    }
    ff(i,len,n)
    {
        s+=a[i]-a[i-len];
        if(a[i-len]<0)
            for(j=N+pos[i-len];j;j>>=1) --cnt[j], tree[j]-=a[i-len];
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];

        j=m; s2=0;
        if(m)
            for(k=1;k<=N+n;)
            {
                if(cnt[k]<=j){s2+=tree[k];break;}
                if(cnt[k*2]<=j) k=k*2; else j-=cnt[k*2], s2+=tree[k*2], k=k*2+1;
            }
        if(i==len || s-s2*2>ans) ans=s-s2*2;
    }
    printf("%I64d\n",ans);

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <assert.h>

//#pragma warning(disable:4996)
using namespace std;

#define TIME fprintf(stderr,"\n-----------\ntime : %.2f sec\n",double(clock())/CLOCKS_PER_SEC);
#define EXIT exit(0);
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INP(_X) scanf("%d",& _X);
#define OUT(_X) printf("%d ",_X);
#define LINE printf("\n");
#define DOUT(_X) fprintf(stderr,"%d ",_X);
#define DLINE fprintf(stderr,"\n");

#define M 112345
#define MOD 0
#define ADD(_X,_Y) _X=(_X+_Y)%MOD;

#define abs(_Z) (((_Z)<0)?-(_Z):(_Z))
#define f0(_X,_Y) for(_X=0;_X<_Y;++_X)
#define f1(_X,_Y) for(_X=1;_X<=_Y;++_X)
#define ff(_X,_Y,_Z) for(_X=_Y;_X<=_Z;++_X)
#define fF(_X,_Y,_Z) for(_X=_Y;_X<_Z;++_X)
#define pb push_back
#define sz(_X) _X.size()
typedef long long ll;

int a[M],cnt[M*3],pos[M]; ll tree[M*3];
struct P{int i,num;
    bool friend operator < (const P &p,const P &q)
    {
        if(p.num!=q.num) return p.num<q.num;
        return p.i<q.i;
    }
} b[M];

int n,m,len;

ll process()
{
    int i,j,k,N;
    ll ans,s=0,s2;

    f1(i,n) b[i].i=i, b[i].num=a[i];
    for(N=1;N<n;N<<=1);--N;
    sort(b+1,b+n+1);
    f1(i,n) pos[b[i].i]=i;
    f1(i,N+n) tree[i]=0, cnt[i]=0;

    f1(i,len-1)
    {
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];
        s+=a[i];
    }
    ff(i,len,n)
    {
        s+=a[i]-a[i-len];
        if(a[i-len]<0)
            for(j=N+pos[i-len];j;j>>=1) --cnt[j], tree[j]-=a[i-len];
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];

        j=m; s2=0;
        if(m)
            for(k=1;k<=N+n;)
            {
                if(cnt[k]<=j){s2+=tree[k];break;}
                if(cnt[k*2]>=j) k=k*2; else j-=cnt[k*2], s2+=tree[k*2], k=k*2+1;
            }
        if(i==len || s-s2*2>ans) ans=s-s2*2;
    }
    return ans;
}

int main()
{
    int i;
    ll ans1,ans2;

    INP(n) INP(len)
    f1(i,n) INP(a[i])
    INP(m) if(m>len) m=len;

    ans1=process();
    f1(i,n) a[i]=-a[i];
    ans2=process();

    printf("%I64d\n",max(ans1,ans2));

    return 0;
}
/*
5 4
-1 -1 -1 -1 -1
5
*/


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <assert.h>

//#pragma warning(disable:4996)
using namespace std;

#define TIME fprintf(stderr,"\n-----------\ntime : %.2f sec\n",double(clock())/CLOCKS_PER_SEC);
#define EXIT exit(0);
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INP(_X) scanf("%d",& _X);
#define OUT(_X) printf("%d ",_X);
#define LINE printf("\n");
#define DOUT(_X) fprintf(stderr,"%d ",_X);
#define DLINE fprintf(stderr,"\n");

#define M 112345
#define MOD 0
#define ADD(_X,_Y) _X=(_X+_Y)%MOD;

#define abs(_Z) (((_Z)<0)?-(_Z):(_Z))
#define f0(_X,_Y) for(_X=0;_X<_Y;++_X)
#define f1(_X,_Y) for(_X=1;_X<=_Y;++_X)
#define ff(_X,_Y,_Z) for(_X=_Y;_X<=_Z;++_X)
#define fF(_X,_Y,_Z) for(_X=_Y;_X<_Z;++_X)
#define pb push_back
#define sz(_X) _X.size()
typedef long long ll;

int a[M],cnt[M*3],pos[M]; ll tree[M*3];
struct P{int i,num;
    bool friend operator < (const P &p,const P &q)
    {
        if(p.num!=q.num) return p.num<q.num;
        return p.i<q.i;
    }
} b[M];

int main()
{
    int n,m,len,i,j,k,size=0,N;
    ll ans,s=0,s2;

    INP(n) INP(len)
    f1(i,n) INP(a[i])
    f1(i,n) b[i].i=i, b[i].num=a[i];
    INP(m) if(m>len) m=len;
    for(N=1;N<n;N<<=1);--N;
    sort(b+1,b+n+1);
    f1(i,n) pos[b[i].i]=i;

    f1(i,len-1)
    {
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];
        s+=a[i];
    }
    ff(i,len,n)
    {
        s+=a[i]-a[i-len];
        if(a[i-len]<0)
            for(j=N+pos[i-len];j;j>>=1) --cnt[j], tree[j]-=a[i-len];
        if(a[i]<0)
            for(j=N+pos[i];j;j>>=1) ++cnt[j], tree[j]+=a[i];

        j=m; s2=0;
        if(m)
            for(k=1;k<=N+n;)
            {
                if(cnt[k]<=j){s2+=tree[k];break;}
                if(cnt[k*2]>=j) k=k*2; else j-=cnt[k*2], s2+=tree[k*2], k=k*2+1;
            }
        if(i==len || s-s2*2>ans) ans=s-s2*2;
    }
    printf("%I64d\n",ans);

    return 0;
}
/*
5 4
-1 -1 -1 -1 -1
5
*/


#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

const int toMod = 1000000007;

int n, len, k;
int a[1 << 17];
int64 fp[1 << 17];
int64 fn[1 << 17];

inline int64 abs64(int64 x)
{
	if (x < 0) return -x;
	return x;
}

inline void init()
{
	scanf("%d%d", &n, &len);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		fp[i] = 0;
		fn[i] = 0;
		if (a[i] > 0) fp[i] = a[i];
		if (a[i] < 0) fn[i] = a[i];
		if (i)
		{
			fp[i] += fp[i - 1];
			fn[i] += fn[i - 1];
		}
	}
	scanf("%d", &k);
}

inline int64 getSumP(int l, int r)
{
	int64 res = fp[r];
	if (l) res -= fp[l - 1];
	return res;
}

inline int64 getSumN(int l, int r)
{
	int64 res = fn[r];
	if (l) res -= fn[l - 1];
	return res;
}

struct megaset
{
	int cnt;
	int64 curSum;
	int inSet[1 << 17];
	priority_queue < pii, vector<pii>, greater<pii> > qmin;
	priority_queue < pii > qmax;

	void clear()
	{
		curSum = 0;
		cnt = 0;
		memset(inSet, 0, sizeof inSet);
		while (!qmin.empty()) qmin.pop();
		while (!qmax.empty()) qmax.pop();
	}

	void refresh()
	{
		if (!k) return;
		while (!qmax.empty())
		{
			if (cnt == k) break;
			pii cur = qmax.top();
			qmax.pop();
			qmin.push(cur);
			curSum += (int64)cur.first;
			inSet[cur.second] = 1;
			++cnt;
		}
		while (!qmax.empty())
		{
			pii cur = qmax.top();
			while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
			if (cur.first > qmin.top().first)
			{
				qmax.pop();
				pii cur2 = qmin.top();
				qmin.pop();
				qmin.push(cur);
				qmax.push(cur2);
				curSum -= (int64)cur2.first;
				curSum += (int64)cur.first;
				inSet[cur2.second] = 0;
				inSet[cur.second] = 1;
			} else break;
		}
	}

	void remove(int id)
	{
		if (!inSet[id]) return;
		inSet[id] = 0;
		curSum -= a[id];
		--cnt;
		while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
		refresh();
	}

	void add(int id)
	{
		qmax.push(pii(a[id], id));
		refresh();
	}
};

megaset A;

inline int64 solve()
{
	A.clear();

	for (int i = 0; i < len; ++i)
	{
		if (a[i] > 0) A.add(i);
	}

	int64 res = abs64(getSumP(0, len - 1) - 2 * A.curSum + getSumN(0, len - 1));

	for (int i = len; i < n; ++i)
	{
		if (a[i - len] > 0) A.remove(i - len);
		if (a[i] > 0) A.add(i);
		int64 cur = abs64(getSumP(i - len + 1, i) - 2 * A.curSum + getSumN(i - len + 1, i));
		res = max(res, cur);
	}

	return res;
}

int main()
{
	//freopen ("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);

	init();

	int64 res = solve();
	for (int i = 0; i < n; ++i)
		a[i] = -a[i];
	res = min(res, solve());
	cout << res << endl;

	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

const int toMod = 1000000007;

int n, len, k;
int a[1 << 17];
int64 fp[1 << 17];
int64 fn[1 << 17];

inline int64 abs64(int64 x)
{
    if (x < 0) return -x;
    return x;
}

inline void init()
{
    scanf("%d%d", &n, &len);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i)
    {
        fp[i] = 0;
        fn[i] = 0;
        if (a[i] > 0) fp[i] = a[i];
        if (a[i] < 0) fn[i] = a[i];
        if (i)
        {
            fp[i] += fp[i - 1];
            fn[i] += fn[i - 1];
        }
    }
    scanf("%d", &k);
    if (k > len) k = len;
}

inline int64 getSumP(int l, int r)
{
    int64 res = fp[r];
    if (l) res -= fp[l - 1];
    return res;
}

inline int64 getSumN(int l, int r)
{
    int64 res = fn[r];
    if (l) res -= fn[l - 1];
    return res;
}

struct megaset
{
    int cnt;
    int LAST;
    int64 curSum;
    int inSet[1 << 17];
    priority_queue < pii, vector<pii>, greater<pii> > qmin;
    priority_queue < pii > qmax;

    void clear()
    {
        LAST = -1;
        curSum = 0;
        cnt = 0;
        memset(inSet, 0, sizeof inSet);
        while (!qmin.empty()) qmin.pop();
        while (!qmax.empty()) qmax.pop();
    }

    void refresh()
    {
        if (!k) return;
        while (!qmax.empty())
        {
            if (qmax.top().second <= LAST)
            {
                qmax.pop();
                continue;
            }
            if (cnt == k) break;
            pii cur = qmax.top();
            qmax.pop();
            qmin.push(cur);
            curSum += (int64)cur.first;
            inSet[cur.second] = 1;
            ++cnt;
        }
        while (!qmax.empty())
        {
            if (qmax.top().second <= LAST)
            {
                qmax.pop();
                continue;
            }
            pii cur = qmax.top();
            while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
            if (cur.first > qmin.top().first)
            {
                qmax.pop();
                pii cur2 = qmin.top();
                qmin.pop();
                qmin.push(cur);
                qmax.push(cur2);
                curSum -= (int64)cur2.first;
                curSum += (int64)cur.first;
                inSet[cur2.second] = 0;
                inSet[cur.second] = 1;
            } else break;
        }
    }

    void remove(int id)
    {
        LAST = id;
        if (!inSet[id]) return;
        inSet[id] = 0;
        curSum -= a[id];
        --cnt;
        while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
        refresh();
    }

    void add(int id)
    {
        qmax.push(pii(a[id], id));
        refresh();
    }
};

megaset A;

inline int64 solve()
{
    A.clear();

    for (int i = 0; i < len; ++i)
    {
        if (a[i] > 0) A.add(i);
    }

    int64 res = abs64(getSumP(0, len - 1) - 2 * A.curSum + getSumN(0, len - 1));

    for (int i = len; i < n; ++i)
    {
        if (a[i - len] > 0) A.remove(i - len);
        if (a[i] > 0) A.add(i);
        int64 cur = abs64(getSumP(i - len + 1, i) - 2 * A.curSum + getSumN(i - len + 1, i));
        res = max(res, cur);
    }

    return res;
}

int main()
{

    init();

    int64 res = solve();
    for (int i = 0; i < n; ++i)
        a[i] = -a[i];
    res = min(res, solve());
    cout << res << endl;

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

const int toMod = 1000000007;

int n, len, k;
int a[1 << 17];
int64 fp[1 << 17];
int64 fn[1 << 17];

inline int64 abs64(int64 x)
{
	if (x < 0) return -x;
	return x;
}

inline void init()
{
	scanf("%d%d", &n, &len);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		fp[i] = 0;
		fn[i] = 0;
		if (a[i] > 0) fp[i] = a[i];
		if (a[i] < 0) fn[i] = a[i];
		if (i)
		{
			fp[i] += fp[i - 1];
			fn[i] += fn[i - 1];
		}
	}
	scanf("%d", &k);
	if (k > len) k = len;
}

inline int64 getSumP(int l, int r)
{
	int64 res = fp[r];
	if (l) res -= fp[l - 1];
	return res;
}

inline int64 getSumN(int l, int r)
{
	int64 res = fn[r];
	if (l) res -= fn[l - 1];
	return res;
}

struct megaset
{
	int cnt;
	int LAST;
	int64 curSum;
	int inSet[1 << 17];
	priority_queue < pii, vector<pii>, greater<pii> > qmin;
	priority_queue < pii > qmax;

	void clear()
	{
		LAST = -1;
		curSum = 0;
		cnt = 0;
		memset(inSet, 0, sizeof inSet);
		while (!qmin.empty()) qmin.pop();
		while (!qmax.empty()) qmax.pop();
	}

	void refresh()
	{
		if (!k) return;
		while (!qmax.empty())
		{
			if (qmax.top().second <= LAST)
			{
				qmax.pop();
				continue;
			}
			if (cnt == k) break;
			pii cur = qmax.top();
			qmax.pop();
			qmin.push(cur);
			curSum += (int64)cur.first;
			inSet[cur.second] = 1;
			++cnt;
		}
		while (!qmax.empty())
		{
			if (qmax.top().second <= LAST)
			{
				qmax.pop();
				continue;
			}
			pii cur = qmax.top();
			while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
			if (cur.first > qmin.top().first)
			{
				qmax.pop();
				pii cur2 = qmin.top();
				qmin.pop();
				qmin.push(cur);
				qmax.push(cur2);
				curSum -= (int64)cur2.first;
				curSum += (int64)cur.first;
				inSet[cur2.second] = 0;
				inSet[cur.second] = 1;
			} else break;
		}
	}

	void remove(int id)
	{
		LAST = id;
		if (!inSet[id]) return;
		inSet[id] = 0;
		curSum -= a[id];
		--cnt;
		while (!qmin.empty() && !inSet[qmin.top().second]) qmin.pop();
		refresh();
	}

	void add(int id)
	{
		qmax.push(pii(a[id], id));
		refresh();
	}
};

megaset A;

inline int64 solve()
{
	A.clear();

	for (int i = 0; i < len; ++i)
	{
		if (a[i] > 0) A.add(i);
	}

	int64 res = abs64(getSumP(0, len - 1) - 2 * A.curSum + getSumN(0, len - 1));

	for (int i = len; i < n; ++i)
	{
		if (a[i - len] > 0) A.remove(i - len);
		if (a[i] > 0) A.add(i);
		int64 cur = abs64(getSumP(i - len + 1, i) - 2 * A.curSum + getSumN(i - len + 1, i));
		res = max(res, cur);
	}

	return res;
}

int main()
{
	//freopen ("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);

	init();

	int64 res = solve();
	for (int i = 0; i < n; ++i)
		a[i] = -a[i];
	for (int i = 0; i < n; ++i)
	{
		fp[i] = 0;
		fn[i] = 0;
		if (a[i] > 0) fp[i] = a[i];
		if (a[i] < 0) fn[i] = a[i];
		if (i)
		{
			fp[i] += fp[i - 1];
			fn[i] += fn[i - 1];
		}
	}
	res = max(res, solve());
	cout << res << endl;

	return 0;
}


#pragma comment(linker, "/STACK:25600000")
#define _CRT_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;

typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(ll i = x; i <= y; i++)
#define RFOR(i, x, y) for(ll i = x; i >= y; i--)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PII pair<ll, ll>
const double pi = acos(-1.0);
const double eps = 1e-9;
#define X first
#define Y second

ll a[102400];

class maxpt
{
public:
	ll K;
	ll total_sum;
	ll gr_sum;
	multiset<ll> greatest;
	multiset<ll> others;

	maxpt(ll _k)
	{
		K = _k;
		total_sum = 0;
		gr_sum = 0;
	}

	void add(ll x)
	{
		total_sum += x;

		if (K == 0)
		{
			others.insert(x);
			return;
		}

		if (greatest.size() < K)
		{
			greatest.insert(x);
			gr_sum += x;
			return;
		}

		if (!greatest.empty() && x > *greatest.begin())
		{
			ll t = *greatest.begin();
			others.insert(t);
			greatest.erase(greatest.begin());
			greatest.insert(x);

			gr_sum += x - t;
			return;
		}
		others.insert(x);
	}

	void remove(ll x)
	{
		total_sum -= x;

		if (!others.empty() && others.find(x) != others.end())
		{
			multiset<ll>::iterator it = others.find(x);
			others.erase(it);
			return;
		}

		multiset<ll>::iterator it = greatest.find(x);
		greatest.erase(it);
		gr_sum -= x;

		if (others.size())
		{
			multiset<ll>::iterator it = others.end();
			--it;
			greatest.insert(*it);
			gr_sum += *it;
			others.erase(it);
		}
	}
};

ll ABS(ll x)
{
	if (x < 0) return -x;
	return x;
}

int main()
{
	ll n, len;
	cin >> n >> len;
	REP(i, n)
		cin >> a[i];

	ll k;
	cin >> k;

	ll ans = 0;
	maxpt pos(k), neg(k);

	REP(i, len)
	{
		if (a[i] >= 0)
			pos.add(a[i]);
		else
			neg.add(-a[i]);
	}

	ll start = 0;
	while(true)
	{
		assert(pos.greatest.size() <= k);
	//	assert(neg.greatest.size() <= k);
		ans = max(ans, ABS(pos.total_sum + 2 * neg.gr_sum - neg.total_sum));
		ans = max(ans, ABS(neg.total_sum + 2 * pos.gr_sum - pos.total_sum));
		if (a[start] >= 0)
			pos.remove(a[start]);
		else
			neg.remove(-a[start]);

		if (start + len >= n) break;
		if (a[start+len] >= 0)
			pos.add(a[start + len]);
		else
			neg.add(-a[start + len]);
		++start;
	}
	cout << ans << endl;
}


#include <stdio.h>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,k,v[100000],len;
ll calc(){
    multiset<int> used,free;
    multiset<int>::iterator it;
    ll res=0,sum=0;
    for(int i=0;i<n;++i){
        if(v[i]>=0)
            sum+=v[i];
        else{
            used.insert(v[i]);
            sum+=-v[i];
        }
        if(i-len>=0){
            if(v[i-len]>=0)
                sum-=v[i-len];
            else{
                it=used.find(v[i-len]);
                if(it!=used.end()){
                    sum-=-*it;
                    used.erase(it);
                }else{
                    it=free.find(v[i-len]);
                    sum-=*it;
                    free.erase(it);
                }
            }
        }
        while(used.size()>k){
            sum-=-*--used.end();
            sum+=*--used.end();
            free.insert(*--used.end());
            used.erase(--used.end());
        }
        while(used.size()<k && !free.empty()){
            used.insert(*free.begin());
            sum-=*free.begin();
            sum+=-*free.begin();
            free.erase(free.begin());
        }
        int x,y;
        while(!used.empty() && !free.empty() && -(x=*--used.end())<-(y=*free.begin())){
            used.erase(--used.end());
            used.insert(y);
            free.erase(free.begin());
            free.insert(x);
            sum-=-x;
            sum+=x;
            sum-=y;
            sum+=-y;
        }
        if(i>=len-1)
            res=max(res,sum);
    }
    return res;
}
int main(){
    scanf("%d%d",&n,&len);
    for(int i=0;i<n;++i)
        scanf("%d",v+i);
    scanf("%d",&k);
    ll res=-1;
    for(int it=0;it<2;++it){
        res=max(res,calc());
        for(int i=0;i<n;++i)
            v[i]*=-1;
    }
    printf("%lld",res);
    return 0;
}


#include <stdio.h>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,k,v[100000],len;
ll calc(){
    multiset<int> used,free;
    multiset<int>::iterator it;
    ll res=0,sum=0;
    for(int i=0;i<n;++i){
        if(v[i]>=0)
            sum+=v[i];
        else{
            used.insert(v[i]);
            sum+=-v[i];
        }
        if(i-len>=0){
            if(v[i-len]>=0)
                sum-=v[i-len];
            else{
                it=used.find(v[i-len]);
                if(it!=used.end()){
                    sum-=-*it;
                    used.erase(it);
                }else{
                    it=free.find(v[i-len]);
                    sum-=*it;
                    free.erase(it);
                }
            }
        }
        while(used.size()>k){
            sum-=-*--used.end();
            sum+=*--used.end();
            free.insert(*--used.end());
            used.erase(--used.end());
        }
        while(used.size()<k && !free.empty()){
            used.insert(*free.begin());
            sum-=*free.begin();
            sum+=-*free.begin();
            free.erase(free.begin());
        }
        int x,y;
        while(!used.empty() && !free.empty() && -(x=*--used.end())<-(y=*free.begin())){
            used.erase(--used.end());
            used.insert(y);
            free.erase(free.begin());
            free.insert(x);
            sum-=-x;
            sum+=x;
            sum-=y;
            sum+=-y;
        }
        if(i>=len-1)
            res=max(res,sum);
    }
    return res;
}
int main(){
    scanf("%d%d",&n,&len);
    for(int i=0;i<n;++i)
        scanf("%d",v+i);
    scanf("%d",&k);
    ll res=-1;
    for(int it=0;it<1;++it){
        res=max(res,calc());
        for(int i=0;i<n;++i)
            v[i]*=-1;
    }
    printf("%lld",res);
    return 0;
}


#include <stdio.h>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,k,v[100000];
ll calc(){
    multiset<int> used,free;
    multiset<int>::iterator it;
    ll res=0,sum=0;
    for(int i=0;i<n;++i){
        if(v[i]>=0)
            sum+=v[i];
        else{
            used.insert(v[i]);
            sum+=-v[i];
        }
        if(i-k>=0){
            if(v[i-k]>=0)
                sum-=v[i-k];
            else{
                it=used.find(v[i-k]);
                sum-=-*it;
                if(it!=used.end())
                    used.erase(it);
                else{
                    it=free.find(v[i-k]);
                    sum-=-*it;
                    free.erase(it);
                }
            }
        }
        while(used.size()>k){
            sum-=-*--used.end();
            used.erase(--used.end());
        }
        while(used.size()<k && !free.empty()){
            used.insert(*free.begin());
            sum+=-*free.begin();
            free.erase(free.begin());
        }
        int x,y;
        while(!used.empty() && !free.empty() && -(x=*--used.end())<-(y=*free.begin())){
            used.erase(--used.end());
            used.insert(y);
            free.erase(free.begin());
            free.insert(x);
            sum+=-y;
            sum-=-x;
        }
        if(i>=k-1)
            res=max(res,sum);
    }
    return res;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)
        scanf("%d",v+i);
    ll res=-1;
    for(int it=0;it<2;++it){
        res=max(res,calc());
        for(int i=0;i<n;++i)
            v[i]*=-1;
    }
    printf("%lld",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n;
int f(int x)
{
    int q[100001][2]={},front=1,rear=1;
    map<int,bool>vis;
    q[1][0]=x;
    while(front<=rear)
    {
        int a=q[front][0],s=q[front][1];
        if(a==1)return s;
        if(a%6==0&&!vis[a/6])
        {
            vis[a/6]=true;
            q[++rear][0]=a/6;
            q[rear][1]=s+1;
        }
        if(!vis[a<<1]&&a<=5e8)
        {
            vis[a<<1]=true;
            q[++rear][0]=a<<1;
            q[rear][1]=s+1;
        }
        front++;
    }
    return -1;
}
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
    t=read();
    while(t--)printf("%d\n",f(read()));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t;
int f(int x)
{
    int q[100001][2]={},front=1,rear=1;
    bitset<1000000001>vis;
    q[1][0]=x;
    while(front<=rear)
    {
        int a=q[front][0],s=q[front][1];
        if(a==1)return s;
        if(a%6==0&&!vis[a/6])
        {
            vis[a/6]=true;
            q[++rear][0]=a/6;
            q[rear][1]=s+1;
        }
        if(!vis[a<<1]&&a<=5e8)
        {
            vis[a<<1]=true;
            q[++rear][0]=a<<1;
            q[rear][1]=s+1;
        }
        front++;
    }
    return -1;
}
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
    t=read();
    while(t--)printf("%d\n",f(read()));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t;
int f(int x)
{
    int q[100001][2]={},front=1,rear=1;
    map<int,bool>vis;
    q[1][0]=x;
    while(front<=rear)
    {
        int a=q[front][0],s=q[front][1];
        if(a==1)return s;
        if(a%6==0&&!vis[a/6])
        {
            vis[a/6]=true;
            q[++rear][0]=a/6;
            q[rear][1]=s+1;
        }
        if(!vis[a<<1]&&a<=5e8)
        {
            vis[a<<1]=true;
            q[++rear][0]=a<<1;
            q[rear][1]=s+1;
        }
        front++;
    }
    return -1;
}
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
    t=read();
    while(t--)printf("%d\n",f(read()));
    return 0;
}