#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <utility>

using namespace std;

class SegmentTree {
  public:
    SegmentTree(int width, int height): m_width(width), m_height(height), m_root(make_unique<Outer>()) {}

    void update(int x, int y) {
        m_root->update(0, m_width, x, x + 1, [&](Inner& data) {
            data.push_back(y);
        });
    }

    int query(int x1, int x2, int y1, int y2) {
        int answer = 0;
        m_root->query(0, m_width, x1, x2, [&](Inner& data) {
            answer += lower_bound(data.begin(), data.end(), y2) - lower_bound(data.begin(), data.end(), y1);
        });
        return answer;
    }
  private:
    template<class T>
    struct Node {
        T data = T();
        unique_ptr<Node>left, right;

        template<class Cb>
        void update(int begin, int end, int from, int to, Cb &&cb) {
            cb(data);
            if (from <= begin && end <= to) {
                return;
            }
            int mid = (begin + end) / 2;
            if (from < mid) {
                if (!left)
                    left = make_unique<Node>();
                left->update(begin, mid, from, to, cb);
            }
            if (mid < to) {
                if (!right)
                    right = make_unique<Node>();
                right->update(mid, end, from, to, cb);
            }
        }
        template<class Cb>
        void query(int begin, int end, int from, int to, Cb &&cb) {
            if (from <= begin && end <= to) {
                cb(data);
                return;
            }

            int mid = (begin + end) / 2;
            if (from < mid && left)
                left->query(begin, mid, from, to, cb);
            if (mid < to && right)
                right->query(mid, end, from, to, cb);
        }
    };

    using Inner = vector<int>;
    using Outer = Node<Inner>;

    int m_width, m_height;
    unique_ptr<Outer> m_root;
};

struct Piece {
    int first_half;
    int second_half;
    int index;

    bool operator<(const Piece& other) const {
        if (first_half != other.first_half)
            return first_half < other.first_half;
        return second_half < other.second_half;
    }
};

vector<int> suffix_array(const string &S) {
    int N = S.size();
    vector<int> repr(N);
    for (int i = 0; i < N; ++i)
        repr[i] = S[i] - 'a';
    vector<Piece> pieces(N);

    for (int i = 1; i <= N; i *= 2) {
        for (int j = 0; j < N; ++j)
            pieces[j] = Piece{
                repr[j],
                (j + i < N ? repr[j + i] : -1),
                j,
            };
        sort(pieces.begin(), pieces.end());
        int now = -1;
        for (int j = 0; j < N; ++j) {
            if (j == 0 || pieces[j - 1] < pieces[j])
                ++now;
            repr[pieces[j].index] = now;
        }
    }
    vector<int> order(N);
    for (int i = 0; i < N; ++i)
        order[i] = pieces[i].index;
    return order;
}

vector<int> kasai(const string &S, const vector<int> &sa) {
    int N = S.size(), k = 0;
    vector<int> lcp(N - 1, 0);
    vector<int> rank(N, 0);
    for (int i = 0; i < N; ++i)
        rank[sa[i]] = i;

    for (int i = 0; i < N; ++i, k = max(0, k - 1)) {
        if (rank[i] == N - 1) {
            k = 0;
            continue;
        }
        int j = sa[rank[i] + 1];
        while (i + k < N && j + k < N && S[i + k] == S[j + k])
            ++k;
        lcp[rank[i]] = k;
    }
    return lcp;
}

int main() {
    ios::sync_with_stdio(false);
    int N, Q; cin >> N >> Q;

    vector<int> position(N), length(N);
    string S;
    for (int i = 0; i < N; ++i) {
        string temp; cin >> temp;
        position[i] = S.size();
        length[i] = temp.size();
        S += temp;
        S += '#';
    }

    auto sa = suffix_array(S);
    auto lcp = kasai(S, sa);

    int L = S.size();
    vector<int> rank(L, 0);
    for (int i = 0; i < L; ++i)
        rank[sa[i]] = i;

    vector<int> need(L, -1);
    for (int i = 0; i < N; ++i)
        need[rank[position[i]]] = length[i];

    vector<int> stack;
    vector<int> left(L), right(L);
    for (int i = 0; i < L; ++i) {
        left[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                left[i] = *it + 1;
            } else {
                left[i] = 0;
            }
        }
        if (i == L - 1)
            break;
        while (!stack.empty() && lcp[stack.back()] >= lcp[i])
            stack.pop_back();
        stack.push_back(i);
    }

    stack.clear();
    for (int i = L - 1; i >= 0; --i) {
        if (i < L) {
            while (!stack.empty() && lcp[stack.back()] >= lcp[i])
                stack.pop_back();
            stack.push_back(i);
        }

        right[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                right[i] = *it;
            } else {
                right[i] = L - 1;
            }
        }
    }

    SegmentTree ST(S.size(), N);
    for (int i = 0; i < N; ++i)
        for (int j = position[i]; j < position[i] + length[i]; ++j) {
            ST.update(rank[j], i);
        }

    while (Q--) {
        int l, r, k; cin >> l >> r >> k;

        --l;
        k = rank[position[k - 1]];
        cout << ST.query(left[k], right[k] + 1, l, r) << "\n";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <utility>

using namespace std;

class SegmentTree {
  public:
    SegmentTree(int width, int height): m_width(width), m_height(height), m_root(make_unique<Outer>()) {}

    void update(int x, int y) {
        m_root->update(0, m_width, x, x + 1, [&](Inner& data) {
            data.push_back(y);
        });
    }

    int query(int x1, int x2, int y1, int y2) {
        int answer = 0;
        m_root->query(0, m_width, x1, x2, [&](Inner& data) {
            answer += lower_bound(data.begin(), data.end(), y2) - lower_bound(data.begin(), data.end(), y1);
        });
        return answer;
    }
  private:
    template<class T>
    struct Node {
        T data = T();
        unique_ptr<Node>left, right;

        template<class Cb>
        void update(int begin, int end, int from, int to, Cb &&cb) {
            cb(data);
            if (from <= begin && end <= to) {
                return;
            }
            int mid = (begin + end) / 2;
            if (from < mid) {
                if (!left)
                    left = make_unique<Node>();
                left->update(begin, mid, from, to, cb);
            }
            if (mid < to) {
                if (!right)
                    right = make_unique<Node>();
                right->update(mid, end, from, to, cb);
            }
        }
        template<class Cb>
        void query(int begin, int end, int from, int to, Cb &&cb) {
            if (from <= begin && end <= to) {
                cb(data);
                return;
            }

            int mid = (begin + end) / 2;
            if (from < mid && left)
                left->query(begin, mid, from, to, cb);
            if (mid < to && right)
                right->query(mid, end, from, to, cb);
        }
    };

    using Inner = vector<int>;
    using Outer = Node<Inner>;

    int m_width, m_height;
    unique_ptr<Outer> m_root;
};

struct Piece {
    int first_half;
    int second_half;
    int index;

    bool operator<(const Piece& other) const {
        if (first_half != other.first_half)
            return first_half < other.first_half;
        return second_half < other.second_half;
    }
};

vector<int> suffix_array(const string &S) {
    int N = S.size();
    vector<int> repr(N);
    for (int i = 0; i < N; ++i)
        repr[i] = S[i] - 'a';
    vector<Piece> pieces(N);

    for (int i = 1; i <= N; i *= 2) {
        for (int j = 0; j < N; ++j)
            pieces[j] = Piece{
                repr[j],
                (j + i < N ? repr[j + i] : -1),
                j,
            };
        sort(pieces.begin(), pieces.end());
        int now = -1;
        for (int j = 0; j < N; ++j) {
            if (j == 0 || pieces[j - 1] < pieces[j])
                ++now;
            repr[pieces[j].index] = now;
        }
    }
    vector<int> order(N);
    for (int i = 0; i < N; ++i)
        order[i] = pieces[i].index;
    return order;
}

vector<int> kasai(const string &S, const vector<int> &sa) {
    int N = S.size(), k = 0;
    vector<int> lcp(N - 1, 0);
    vector<int> rank(N, 0);
    for (int i = 0; i < N; ++i)
        rank[sa[i]] = i;

    for (int i = 0; i < N; ++i, k = max(0, k - 1)) {
        if (rank[i] == N - 1) {
            k = 0;
            continue;
        }
        int j = sa[rank[i] + 1];
        while (i + k < N && j + k < N && S[i + k] == S[j + k])
            ++k;
        lcp[rank[i]] = k;
    }
    return lcp;
}

int main() {
    ios::sync_with_stdio(false);
    int N, Q; cin >> N >> Q;

    vector<int> position(N), length(N);
    string S;
    for (int i = 0; i < N; ++i) {
        string temp; cin >> temp;
        position[i] = S.size();
        length[i] = temp.size();
        S += temp;
        S += '#';
    }

    auto sa = suffix_array(S);
    auto lcp = kasai(S, sa);

    int L = S.size();
    vector<int> rank(L, 0);
    for (int i = 0; i < L; ++i)
        rank[sa[i]] = i;

    vector<int> need(L, -1);
    for (int i = 0; i < N; ++i)
        need[rank[position[i]]] = length[i];

    vector<int> stack;
    vector<int> left(L), right(L);
    for (int i = 0; i < L; ++i) {
        left[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                left[i] = *it + 1;
            } else {
                left[i] = 0;
            }
        }
        if (i == L - 1)
            break;
        while (!stack.empty() && lcp[stack.back()] >= lcp[i])
            stack.pop_back();
        stack.push_back(i);
    }

    stack.clear();
    for (int i = L - 1; i >= 0; --i) {
        if (i < L) {
            while (!stack.empty() && lcp[stack.back()] >= lcp[i])
                stack.pop_back();
            stack.push_back(i);
        }

        right[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                right[i] = *it;
            } else {
                right[i] = L - 1;
            }
        }
    }

    SegmentTree ST(N, S.size());
    vector<int> to_update(L, -1);
    for (int i = 0; i < N; ++i)
        for (int j = position[i]; j < position[i] + length[i]; ++j) {
            to_update[rank[j]] = i;
        }

    for (int i = 0; i < L; ++i) {
        if (to_update[i] == -1)
            continue;
        ST.update(to_update[i], i);
    }

    while (Q--) {
        int l, r, k; cin >> l >> r >> k;

        --l;
        k = rank[position[k - 1]];
        cout << ST.query(l, r, left[k], right[k] + 1) << "\n";
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <utility>

using namespace std;

class SegmentTree {
  public:
    SegmentTree(int width, int height): m_width(width), m_height(height), m_root(make_unique<Outer>()) {}

    void update(int x, int y, int value) {
        m_root->update(0, m_width, x, x + 1, [&](Inner& data) {
            data.update(0, m_height, y, y + 1, [=](int64_t &data) {
                data += value;
            });
        });
    }

    int query(int x1, int x2, int y1, int y2) {
        int answer = 0;
        m_root->query(0, m_width, x1, x2, [&](Inner& data) {
            data.query(0, m_height, y1, y2, [&](int64_t &data) {
                answer += data;
            });
        });
        return answer;
    }
  private:
    template<class T>
    struct Node {
        T external = T();
        T internal = T();
        unique_ptr<Node>left, right;

        template<class Cb>
        void update(int begin, int end, int from, int to, Cb &&cb) {
            if (from <= begin && end <= to) {
                cb(external);
                return;
            }
            int mid = (begin + end) / 2;
            if (from < mid) {
                if (!left)
                    left = make_unique<Node>();
                left->update(begin, mid, from, to, cb);
            }
            if (mid < to) {
                if (!right)
                    right = make_unique<Node>();
                right->update(mid, end, from, to, cb);
            }
            cb(internal);
        }
        template<class Cb>
        void query(int begin, int end, int from, int to, Cb &&cb) {
            cb(external);

            if (from <= begin && end <= to) {
                cb(internal);
                return;
            }

            int mid = (begin + end) / 2;
            if (from < mid && left)
                left->query(begin, mid, from, to, cb);
            if (mid < to && right)
                right->query(mid, end, from, to, cb);
        }
    };

    using Inner = Node<int64_t>;
    using Outer = Node<Inner>;

    int m_width, m_height;
    unique_ptr<Outer> m_root;
};

struct Piece {
    int first_half;
    int second_half;
    int index;

    bool operator<(const Piece& other) const {
        if (first_half != other.first_half)
            return first_half < other.first_half;
        return second_half < other.second_half;
    }
};

vector<int> suffix_array(const string &S) {
    int N = S.size();
    vector<int> repr(N);
    for (int i = 0; i < N; ++i)
        repr[i] = S[i] - 'a';
    vector<Piece> pieces(N);

    for (int i = 1; i <= N; i *= 2) {
        for (int j = 0; j < N; ++j)
            pieces[j] = Piece{
                repr[j],
                (j + i < N ? repr[j + i] : -1),
                j,
            };
        sort(pieces.begin(), pieces.end());
        int now = -1;
        for (int j = 0; j < N; ++j) {
            if (j == 0 || pieces[j - 1] < pieces[j])
                ++now;
            repr[pieces[j].index] = now;
        }
    }
    vector<int> order(N);
    for (int i = 0; i < N; ++i)
        order[i] = pieces[i].index;
    return order;
}

vector<int> kasai(const string &S, const vector<int> &sa) {
    int N = S.size(), k = 0;
    vector<int> lcp(N - 1, 0);
    vector<int> rank(N, 0);
    for (int i = 0; i < N; ++i)
        rank[sa[i]] = i;

    for (int i = 0; i < N; ++i, k = max(0, k - 1)) {
        if (rank[i] == N - 1) {
            k = 0;
            continue;
        }
        int j = sa[rank[i] + 1];
        while (i + k < N && j + k < N && S[i + k] == S[j + k])
            ++k;
        lcp[rank[i]] = k;
    }
    return lcp;
}

int main() {
    ios::sync_with_stdio(false);
    int N, Q; cin >> N >> Q;

    vector<int> position(N), length(N);
    string S;
    for (int i = 0; i < N; ++i) {
        string temp; cin >> temp;
        position[i] = S.size();
        length[i] = temp.size();
        S += temp;
        S += '#';
    }

    auto sa = suffix_array(S);
    auto lcp = kasai(S, sa);

    int L = S.size();
    vector<int> rank(L, 0);
    for (int i = 0; i < L; ++i)
        rank[sa[i]] = i;

    vector<int> need(L, -1);
    for (int i = 0; i < N; ++i)
        need[rank[position[i]]] = length[i];

    vector<int> stack;
    vector<int> left(L), right(L);
    for (int i = 0; i < L; ++i) {
        left[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                left[i] = *it + 1;
            } else {
                left[i] = 0;
            }
        }
        if (i == L - 1)
            break;
        while (!stack.empty() && lcp[stack.back()] >= lcp[i])
            stack.pop_back();
        stack.push_back(i);
    }

    stack.clear();
    for (int i = L - 1; i >= 0; --i) {
        if (i < L) {
            while (!stack.empty() && lcp[stack.back()] >= lcp[i])
                stack.pop_back();
            stack.push_back(i);
        }

        right[i] = i;
        if (need[i] != -1 && !stack.empty()) {
            auto it = lower_bound(stack.begin(), stack.end(), need[i], [&](int elem, int need) {
                return lcp[elem] < need;
            });
            if (it != stack.begin()) {
                --it;
                right[i] = *it;
            } else {
                right[i] = L - 1;
            }
        }
    }

    SegmentTree ST(S.size(), N);
    for (int i = 0; i < N; ++i)
        for (int j = position[i]; j < position[i] + length[i]; ++j) {
            ST.update(rank[j], i, 1);
        }

    while (Q--) {
        int l, r, k; cin >> l >> r >> k;

        --l;
        k = rank[position[k - 1]];
        cout << ST.query(left[k], right[k] + 1, l, r) << "\n";
    }
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    for (int i = 0; i < n; ++i) {
        long long int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        if (gIdx == 1) {
            for (int i = 0; i < va.size(); ++i)
                va[i] = -va[i];
        }

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < va.size(); ++i) {
            if (i >= len) {
                multiset<long long int>::iterator vIt = vSet.find(va[i - len]);
                if (vIt != vSet.end()) {
                    vSet.erase(vIt);
                    sum -= va[i - len];
                } else {
                    multiset<long long int>::iterator kIt = kSet.find(va[i - len]);
                    kSet.erase(kIt);
                    sum -= -va[i - len];
                }
            }

            vSet.insert(va[i]);
            sum += va[i];
            bool bFound = true;
            while (kSet.size() < k && bFound && !vSet.empty()) {
                bFound = false;
                long long int val = *(vSet.begin());
                if (val < 0) {
                    vSet.erase(vSet.begin());
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                    bFound = true;
                }
                if (!bFound) {
                    if (!kSet.empty() && *(--kSet.end()) > val) {
                        long long int kVal = *(--kSet.end());
                        kSet.erase(--kSet.end());
                        vSet.erase(vSet.begin());
                        sum -= -kVal;
                        sum += kVal;
                        sum -= val;
                        sum += -val;
                        kSet.insert(val);
                        vSet.insert(kVal);
                        bFound = true;
                    }
                }
            }

            if (i >= len - 1) {
                if (maxSum < sum)
                    maxSum = sum;
                if (maxSum < -sum)
                    maxSum = -sum;
            }
        }
    }
    cout << maxSum;
    return 0;
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
        int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        vector<long long int> vb;
        if (gIdx == 1)
            for (int i = 0; i < n; ++i)
                va[i] = -va[i];
        for (int i = 0; i < len; ++i)
            vb.push_back(va[i]);
        sort(vb.begin(), vb.end());

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < len; ++i) {
            if (kSet.size() < k && vb[i] < 0) {
                sum += -vb[i];
                kSet.insert(vb[i]);
            } else {
                sum += vb[i];
                vSet.insert(vb[i]);
            }
        }
        if (maxSum < sum)
            maxSum = sum;
        if (maxSum < -sum)
            maxSum = -sum;

        for (int i = len; i < va.size(); ++i) {
            if (kSet.find(va[i - len]) != kSet.end()) {
                kSet.erase(va[i - len]);
                sum -= -va[i - len];
            } else {
                vSet.erase(va[i - len]);
                sum -= va[i - len];
            }

            multiset<long long int>::iterator it = vSet.begin();
            if (kSet.size() < k && (va[i] < 0 || (!vSet.empty() && *it < 0))) {
                if (vSet.empty() || va[i] < *it) {
                    sum += -va[i];
                    kSet.insert(va[i]);
                } else {
                    long long int val = *it;
                    vSet.erase(val);
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                    vSet.insert(va[i]);
                    sum += va[i];
                }
            } else {
                vSet.insert(va[i]);
                sum += va[i];
            }

            if (maxSum < sum)
                maxSum = sum;
            if (maxSum < -sum)
                maxSum = -sum;
        }
    }
    cout << maxSum;
    return 0;
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
        long long int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        if (gIdx == 1) {
            for (int i = 0; i < n; ++i)
                va[i] = -va[i];
        }

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < va.size(); ++i) {
            if (i >= len) {
                multiset<long long int>::iterator vIt = vSet.find(va[i - len]);
                if (vIt != vSet.end()) {
                    vSet.erase(vIt);
                    sum -= va[i - len];
                } else {
                    multiset<long long int>::iterator kIt = kSet.find(va[i - len]);
                    kSet.erase(kIt);
                    sum -= -va[i - len];
                }
            }

            vSet.insert(va[i]);
            sum += va[i];
            if (kSet.size() < k && !vSet.empty()) {
                long long int val = *(vSet.begin());
                if (val < 0) {
                    vSet.erase(vSet.begin());
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                }
            }

            if (i >= len - 1) {
                if (maxSum < sum)
                    maxSum = sum;
                if (maxSum < -sum)
                    maxSum = -sum;
            }
        }
    }
    cout << maxSum;
    return 0;
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
        int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        if (gIdx == 1) {
            for (int i = 0; i < n; ++i)
                va[i] = -va[i];
        }

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < va.size(); ++i) {
            if (i >= len) {
                if (kSet.find(va[i - len]) != kSet.end()) {
                    kSet.erase(va[i - len]);
                    sum -= -va[i - len];
                } else {
                    vSet.erase(va[i - len]);
                    sum -= va[i - len];
                }
            }

            vSet.insert(va[i]);
            sum += va[i];
            bool bFound = true;
            while (kSet.size() < k && bFound && !vSet.empty()) {
                bFound = false;
                long long int val = *(vSet.begin());
                if (val < 0) {
                    vSet.erase(val);
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                    bFound = true;
                }
            }

            if (i >= len - 1) {
                if (maxSum < sum)
                    maxSum = sum;
                if (maxSum < -sum)
                    maxSum = -sum;
            }
        }
    }
    cout << maxSum;
    return 0;
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
        int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        vector<long long int> vb;
        if (gIdx == 1)
            for (int i = 0; i < n; ++i)
                va[i] = -va[i];
        for (int i = 0; i < len; ++i)
            vb.push_back(va[i]);
        sort(vb.begin(), vb.end());

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < len; ++i) {
            if (kSet.size() < k && vb[i] < 0) {
                sum += -vb[i];
                kSet.insert(vb[i]);
            } else {
                sum += vb[i];
                vSet.insert(vb[i]);
            }
        }
        if (maxSum < sum)
            maxSum = sum;
        if (maxSum < -sum)
            maxSum = -sum;

        for (int i = len; i < va.size(); ++i) {
            if (kSet.find(va[i - len]) != kSet.end()) {
                kSet.erase(va[i - len]);
                sum -= -va[i - len];
            } else {
                vSet.erase(va[i - len]);
                sum -= va[i - len];
            }

            multiset<long long int>::iterator it = vSet.begin();
            if (kSet.size() < k && (va[i] < 0 || (!vSet.empty() && *it < 0))) {
                if (vSet.empty() || va[i] < *it) {
                    sum += -va[i];
                    kSet.insert(va[i]);
                } else {
                    long long int val = *it;
                    vSet.erase(val);
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                    sum += va[i];
                }
            } else {
                vSet.insert(va[i]);
                sum += va[i];
            }

            if (maxSum < sum)
                maxSum = sum;
            if (maxSum < -sum)
                maxSum = -sum;
        }
    }
    cout << maxSum;
    return 0;
}


#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <list>
#include <deque>
#include <stack>
#include <map>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int n; cin >> n;
    int len; cin >> len;
    vector<long long int> va;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
        int val; cin >> val;
        va.push_back(val);
    }
    int k; cin >> k;

    long long int maxSum = 0;
    for (int gIdx = 0; gIdx < 2; ++gIdx) {
        if (gIdx == 1) {
            for (int i = 0; i < n; ++i)
                va[i] = -va[i];
        }

        multiset<long long int> kSet;
        multiset<long long int> vSet;
        long long int sum = 0;
        for (int i = 0; i < va.size(); ++i) {
            if (i >= len) {
                multiset<long long int>::iterator vIt = vSet.find(va[i - len]);
                if (vIt != vSet.end()) {
                    vSet.erase(vIt);
                    sum -= va[i - len];
                } else {
                    multiset<long long int>::iterator kIt = kSet.find(va[i - len]);
                    kSet.erase(kIt);
                    sum -= -va[i - len];
                }
            }

            vSet.insert(va[i]);
            sum += va[i];
            bool bFound = true;
            while (kSet.size() < k && bFound && !vSet.empty()) {
                bFound = false;
                long long int val = *(vSet.begin());
                if (val < 0) {
                    vSet.erase(vSet.begin());
                    sum -= val;
                    kSet.insert(val);
                    sum += -val;
                    bFound = true;
                }
            }

            if (i >= len - 1) {
                if (maxSum < sum)
                    maxSum = sum;
                if (maxSum < -sum)
                    maxSum = -sum;
            }
        }
    }
    cout << maxSum;
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define N 100005
struct node
{
   int l,r;
}tree[4*N];
int val[20][N];
int num[20][N];
__int64 sum[20][N];
int b[N];
__int64 VAL,SUM;
struct s
{
  int count1,count2;
  __int64 sum1,sum2;
}s[N];

bool cmp(int a,int b)
{
  if (a<b) return 1;
  return 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]<b[mid]) 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]<b[mid])
        {
            val[h+1][ans1++]=val[h][i];
            sum[h][i]+=val[h][i];
        }
        else if(val[h][i]==b[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 numm,n,m,i,k;
  __int64 ans,max;
  scanf("%d%d",&n,&m);
  for (i=1;i<=n;i++)
  {
    scanf("%d",&val[1][i]);
	b[i]=val[1][i];
  }
  scanf("%d",&k);
  sort(b+1,b+n+1,cmp);
  bulid(1,n,1,1);
  s[0].count1=0;
  s[0].count2=0;
  s[0].sum1=0;
  s[0].sum2=0;
  for (i=1;i<=m;i++)
  {
	s[i]=s[i-1];
    if (val[1][i]>0)
	{
	  s[i].count1++;
	  s[i].sum1+=val[1][i];
	}
	else
	{
	  s[i].count2++;
	  s[i].sum2+=val[1][i];
	}
  }
  max=0;
  for (i=m;i<=n;i++)
  {
    if (i!=m)
    {
	  s[i]=s[i-1];
	  if (val[1][i-m]>0)
	  {
	    s[i].count1--;
		s[i].sum1-=val[1][i-m];
	  }
	  else
	  {
	    s[i].count2--;
		s[i].sum2-=val[1][i-m];
	  }
	  if (val[1][i]>0)
	  {
	    s[i].count1++;
		s[i].sum1+=val[1][i];
	  }
	  else
	  {
	    s[i].count2++;
		s[i].sum2+=val[1][i];
	  }
	}
	ans=s[i].sum1+s[i].sum2;
	if (ans<0) ans=-ans;
    if (ans>max) max=ans;
    if (k==0) continue;
    if (s[i].count2>0)
	{
	  numm=k<s[i].count2?k:s[i].count2;
      SUM=0;
	  find(1,1,i-m+1,i,numm);
	  SUM=-SUM;
      ans=s[i].sum1+s[i].sum2+2*SUM;
	  if (ans<0) ans=-ans;
	  if (ans>max) max=ans;

	}
    if (s[i].count1>0)
	{

	  numm=k<s[i].count1?k:s[i].count1;

	  SUM=0;
	  find(1,1,i-m+1,i,m);
	  ans=SUM;
	  if (m>numm)
	  {
	  SUM=0;
	  find(1,1,i-m+1,i,m-numm);
	  ans=ans-SUM;
	  }
	  ans=s[i].sum1+s[i].sum2-2*ans;
	  if (ans<0) ans=-ans;
	  if (ans>max) max=ans;
	}
  }
  printf("%I64d\n",max);
  return 0;
}


#include "stdio.h"
#include "set"

#define MAXN 100100
#define ABS(a) ((a)<0 ? -(a) : (a))

int n, len;
int a[MAXN];

struct CMyCmp
{
    bool operator ()( int i, int j ) const
    {
        return (a[i] > a[j] ) || ( a[i] == a[j] && i < j );
    }
};

typedef std::set< int, CMyCmp > CSet;

void process( long long & ans, CSet & inv, CSet & not_inv, int & ost, int i )
{
    if( a[i] < 0 )
    {
        if( ost > 0 )
        {
            --ost;
            inv.insert( i );
            ans -= a[i];
        }
        else
        {
            CSet::iterator p = inv.begin();
            if( p != inv.end() && a[i] < a[*p] )
            {
                ans += 2*a[*p];
                ans -= a[i];
                not_inv.insert( *p);
                inv.erase( p );
                inv.insert( i );
            }
            else
            {
                ans += a[i];
                not_inv.insert(i);
            }
        }
    }
    else
    {
        ans += a[i];
    }
}

long long find( int const k)
{
    CSet inv, not_inv;
    long long cur = 0;
    int ost = k;
    for( int i = 0; i < len; ++ i )
    {
        process( cur, inv, not_inv, ost, i );
    }

    long long max = ABS(cur);
    for( int i = len; i < n; ++ i )
    {
        CSet::iterator j = inv.find( i-len );
        if( j != inv.end() )
        {
            cur += a[i-len];
            inv.erase( j );
            ++ost;
        }
        else
            cur -= a[i-len];

        j = not_inv.find( i-len );
        if( j != not_inv.end() )
            not_inv.erase( j );

        while( ost > 0 && !not_inv.empty() )
        {
            -- ost;
            CSet::iterator n_it = not_inv.end();
            --n_it;

            cur -= 2*a[ *n_it ];
            inv.insert( *n_it );
            not_inv.erase( n_it );
        }

        process( cur, inv, not_inv, ost, i );

        if( ABS(cur) > max )
            max = ABS(cur);
    }

    return max;
}

int main()
{
    //freopen( "in.txt", "rt", stdin );

    scanf( "%d %d", &n, &len );
    for( int i = 0; i < n; ++ i )
        scanf( "%d", &a[i] );

    int k;
    scanf( "%d", &k );

    long long a1 = find(k);

    for( int i =  0; i < n; ++ i )
        a[i] = -a[i];

    long long a2 = find(k);

    if( a2 > a1 )
        a1 = a2;

    printf( "%I64d", a1 );

    return 0;
}


#include "stdio.h"
#include "set"

#define MAXN 100100
#define ABS(a) ((a)<0 ? -(a) : (a))

int n, len;
int a[MAXN];

struct CMyCmp
{
    bool operator ()( int i, int j ) const
    {
        return (a[i] > a[j] ) || ( a[i] == a[j] && i < j );
    }
};

typedef std::set< int, CMyCmp > CSet;

void process( long long & ans, CSet & inv, CSet & not_inv, int & ost, int i )
{
    if( a[i] < 0 )
    {
        if( ost > 0 )
        {
            --ost;
            inv.insert( i );
            ans -= a[i];
        }
        else
        {
            CSet::iterator p = inv.begin();
            if( p != inv.end() && a[i] < a[*p] )
            {
                ans += 2*a[*p];
                ans -= a[i];
                not_inv.insert( *p);
                inv.erase( p );
                inv.insert( i );
            }
            else
            {
                ans += a[i];
                not_inv.insert(i);
            }
        }
    }
    else
    {
        ans += a[i];
    }
}

long long find( int const k)
{
    CSet inv, not_inv;
    long long cur = 0;
    int ost = k;
    for( int i = 0; i < len; ++ i )
    {
        process( cur, inv, not_inv, ost, i );
    }

    long long max = ABS(cur);
    for( int i = len; i < n; ++ i )
    {
        CSet::iterator j = inv.find( i-len );
        if( j != inv.end() )
        {
            cur += a[i-len];
            inv.erase( j );
            ++ost;
        }
        else
            cur -= a[i-len];

        j = not_inv.find( i-len );
        if( j != not_inv.end() )
            not_inv.erase( j );

        while( ost > 0 && !not_inv.empty() )
        {
            -- ost;
            CSet::iterator n_it = not_inv.begin();
            cur -= 2*a[ *n_it ];
            inv.insert( *n_it );
            not_inv.erase( n_it );
        }

        process( cur, inv, not_inv, ost, i );

        if( ABS(cur) > max )
            max = ABS(cur);
    }

    return max;
}

int main()
{
    //freopen( "in.txt", "rt", stdin );

    scanf( "%d %d", &n, &len );
    for( int i = 0; i < n; ++ i )
        scanf( "%d", &a[i] );

    int k;
    scanf( "%d", &k );

    long long a1 = find(k);

    for( int i =  0; i < n; ++ i )
        a[i] = -a[i];

    long long a2 = find(k);

    if( a2 > a1 )
        a1 = a2;

    printf( "%I64d", a1 );

    return 0;
}


#include "stdio.h"
#include "set"

#define MAXN 100100
#define ABS(a) ((a)<0 ? -(a) : (a))

int n, len;
int a[MAXN];

struct CMyCmp
{
    bool operator ()( int i, int j ) const
    {
        if( a[i] > a[j] )
            return true;
        if( a[i] < a[j] )
            return false;
        return i < j;
    }
};

typedef std::set< int, CMyCmp > CSet;

void process( long long & ans, CSet & inv, int & ost, int i )
{
    if( a[i] < 0 )
    {
        if( ost > 0 )
        {
            --ost;
            inv.insert( i );
            ans -= a[i];
        }
        else
        {
            CSet::iterator p = inv.begin();
            if( p != inv.end() && a[i] < a[*p] )
            {
                ans += 2*a[*p];
                ans -= a[i];
                inv.erase( p );
                inv.insert( i );
            }
            else
            {
                ans += a[i];
            }
        }
    }
    else
    {
        ans += a[i];
    }
}

long long find( int const k)
{
    CSet inv;
    long long cur = 0;
    int ost = k;
    for( int i = 0; i < len; ++ i )
    {
        process( cur, inv, ost, i );
    }

    long long max = ABS(cur);
    for( int i = len; i < n; ++ i )
    {
        CSet::iterator j = inv.find( i-len );
        if( j != inv.end() && *j == i-len )
        {
            cur += a[i-len];
            inv.erase( j );
            ++ost;
        }
        else
            cur -= a[i-len];
        process( cur, inv, ost, i );

        if( ABS(cur) > max )
            max = ABS(cur);
    }

    return max;
}

int main()
{
    //freopen( "in.txt", "rt", stdin );

    scanf( "%d %d", &n, &len );
    for( int i = 0; i < n; ++ i )
        scanf( "%d", &a[i] );

    int k;
    scanf( "%d", &k );

    long long a1 = find(k);

    for( int i =  0; i < n; ++ i )
        a[i] = -a[i];

    long long a2 = find(k);

    if( a2 > a1 )
        a1 = a2;

    printf( "%I64d", a1 );

    return 0;
}


#include "stdio.h"
#include "set"

#define MAXN 100100
#define ABS(a) ((a)<0 ? -(a) : (a))

int n, len;
int a[MAXN];

struct CMyCmp
{
    bool operator ()( int i, int j ) const
    {
        if( a[i] > a[j] )
            return true;
        if( a[i] < a[j] )
            return false;
        return i < j;
    }
};

typedef std::set< int, CMyCmp > CSet;

void process( long long & ans, CSet & inv, int & ost, int i )
{
    if( a[i] < 0 )
    {
        if( ost > 0 )
        {
            --ost;
            inv.insert( i );
            ans -= a[i];
        }
        else
        {
            CSet::iterator p = inv.begin();
            if( p != inv.end() && a[i] < a[*p] )
            {
                ans += 2*a[*p];
                ans -= a[i];
                inv.erase( p );
                inv.insert( i );
            }
            else
            {
                ans += a[i];
            }
        }
    }
    else
    {
        ans += a[i];
    }
}

long long find( int const k)
{
    CSet inv;
    long long cur = 0;
    int ost = k;
    for( int i = 0; i < len; ++ i )
    {
        process( cur, inv, ost, i );
    }

    long long max = ABS(cur);
    for( int i = len; i < n; ++ i )
    {
        CSet::iterator j = inv.find( i-len );
        if( j != inv.end() && *j == i-len )
        {
            cur += a[i-len];
            inv.erase( j );
            ++ost;
        }
        else
            cur -= a[i-len];
        process( cur, inv, ost, i );

        if( ABS(cur) > max )
            max = ABS(cur);
    }

    return max;
}

int main()
{
   // freopen( "in.txt", "rt", stdin );

    scanf( "%d %d", &n, &len );
    for( int i = 0; i < n; ++ i )
        scanf( "%d", &a[i] );

    int k;
    scanf( "%d", &k );

    long long a1 = find(k);

    for( int i =  0; i < n; ++ i )
        a[i] = -a[i];

    long long a2 = find(k);

    if( a2 > a1 )
        a1 = a2;

    printf( "%I64d", a1 );

    return 0;
}


#include <cassert>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for (int i = (a); (i) <= (b); ++(i))
#define mp make_pair
#define inf 2000000000
#define pb push_back
#define X first
#define Y second
#define LL long long

const int maxN = 400002;
inline void check(LL &a, LL b)
{
	if (b > a) a = b;
	//	cout << " check " <<b << endl;
}

struct El
{
	int cnt;
	LL sum;
};

LL a[maxN];
int where[maxN];
pair<LL, int> b[maxN];
multiset<int> plus, minus;
int n, len, k, mn, ps;

class Tree
{
private:

	El tr[maxN * 5];

public:

	void add(int root, int l, int r, int pos)
	{
		assert(l <= r);
		assert(pos >= l);
		assert(pos <= r);
		//cout << "insert " << root << " " << l << " " << r << " " << pos << endl;
		if (l == r)
		{
			++tr[root].cnt;
			tr[root].sum += b[l].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (pos <= m) add(left, l, m, pos);
		else	add(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
		//if (root == 1)
//			cout << endl;
	}

	LL suma(int root, int l, int r, int k)
	{
		assert(l <= r);
		//cout << "Sum " << root << " " << l << " " << r << " " << k << endl;
		if (k <= 0) return 0LL;
		//cout << " tree " << root << " " << l << " " << r <<" " << k << endl;
		if (tr[root].cnt == k)
			return tr[root].sum;
		if (l == r)
		{
			return (k>0) ? tr[root].sum : 0LL;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (tr[right].cnt >= k)
			return suma(right, m + 1, r, k);
		else
			return tr[right].sum + suma(left, l, m, k - tr[right].cnt);
	}

	void del(int root, int l, int r, int pos)
	{
		assert(l <= r);
		if (l == r)
		{
			--tr[root].cnt;
			tr[root].sum -= (LL)b[pos].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = root * 2 + 1;
		if (pos <= m) del(left, l, m, pos);
		else	del(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
	}

};

LL ans, minsum, plussum;
Tree one, two;

void printNumbers(multiset<int> nm){
	cout << "\t\t";
	for (auto it = nm.begin(); nm.end() != it; ++it){
		cout << *it << " ";
	}
	cout << endl;
}

int main()
{
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	cin >> n >> len;
	FOR(i, 1, n)
	{
		scanf("%I64d", &a[i]);
		b[i].first = abs(a[i]);
		b[i].second = i;
	}
	cin >> k;
	sort(b + 1, b + n + 1);
	FOR(i,1,n)
		where[b[i].second] = i;

	mn = ps = 0;
	minsum = plussum = 0LL;
	LL sum = 0LL;
	FOR(i, 1, len)
		if (a[i] >= 0)
		{
			sum += (LL)a[i];
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
			plus.insert(a[i]);
		}
		else
		{
			sum += (LL)a[i];
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
			minus.insert(-a[i]);
		}
	//printNumbers(plus);
	//printNumbers(minus);
	if (ps <= k || mn <= k)
	{
		check(ans, minsum + plussum);
	}
	long long first = one.suma(1, 1, n, min(ps, k));
	long long second = two.suma(1, 1, n, min(mn, k));
	//cout << first << " " << second <<endl;
	check(ans, minsum - plussum + 2LL * first);
	check(ans, plussum - minsum + 2LL * second);

	for (int i = len + 1; i <= n; ++i)
	{
		//plus
		sum += (long long)a[i] - (long long)a[i - len];
		if (a[i] >= 0)
		{
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
			plus.insert(a[i]);
		}
		else
		{
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
			minus.insert(-a[i]);
		}
		//delete
		if (a[i - len] >= 0)
		{
			--ps;
			plussum -= (LL)a[i - len];
			one.del(1, 1, n, where[i - len]);
			plus.erase(a[i-len]);
		}
		else
		{
			--mn;
			minsum -= (LL)abs(a[i - len]);
			two.del(1, 1, n, where[i - len]);
			minus.erase(a[i-len]);
		}
		//check answer
		check(ans, sum);
		if (ps <= k || mn <= k) check(ans, minsum + plussum);
		long long first = one.suma(1, 1, n, min(ps, k));
		long long second = two.suma(1, 1, n, min(mn, k));
		check(ans, minsum - plussum + 2LL * first);
		check(ans, plussum - minsum + 2LL * second);
	}

	cout << ans << endl;
	return 0;
}


#include <cassert>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for (int i = (a); (i) <= (b); ++(i))
#define mp make_pair
#define inf 2000000000
#define pb push_back
#define X first
#define Y second
#define LL long long

const int maxN = 400002;
inline void check(LL &a, LL b)
{
	if (b > a) a = b;
	//	cout << " check " <<b << endl;
}

struct El
{
	int cnt;
	LL sum;
};

LL a[maxN];
int where[maxN];
pair<LL, int> b[maxN];
multiset<int> plus, minus;
int n, len, k, mn, ps;

class Tree
{
private:

	El tr[maxN * 5];

public:

	void add(int root, int l, int r, int pos)
	{
		assert(l <= r);
		assert(pos >= l);
		assert(pos <= r);
		//cout << "insert " << root << " " << l << " " << r << " " << pos << endl;
		if (l == r)
		{
			++tr[root].cnt;
			tr[root].sum += b[l].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (pos <= m) add(left, l, m, pos);
		else	add(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
		//if (root == 1)
//			cout << endl;
	}

	LL suma(int root, int l, int r, int k)
	{
		assert(l <= r);
		//cout << "Sum " << root << " " << l << " " << r << " " << k << endl;
		if (k <= 0) return 0LL;
		//cout << " tree " << root << " " << l << " " << r <<" " << k << endl;
		if (tr[root].cnt == k)
			return tr[root].sum;
		if (l == r)
		{
			return (k>0) ? tr[root].sum : 0LL;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (tr[right].cnt >= k)
			return suma(right, m + 1, r, k);
		else
			return tr[right].sum + suma(left, l, m, k - tr[right].cnt);
	}

	void del(int root, int l, int r, int pos)
	{
		assert(l <= r);
		if (l == r)
		{
			--tr[root].cnt;
			tr[root].sum -= (LL)b[pos].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = root * 2 + 1;
		if (pos <= m) del(left, l, m, pos);
		else	del(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
	}

};

LL ans, minsum, plussum;
Tree one, two;

//void printNumbers(multiset<int> nm){
//	cout << "\t\t";
//	for (auto it = nm.begin(); nm.end() != it; ++it){
//		cout << *it << " ";
//	}
//	cout << endl;
//}

int main()
{
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	cin >> n >> len;
	FOR(i, 1, n)
	{
		scanf("%I64d", &a[i]);
		b[i].first = abs(a[i]);
		b[i].second = i;
	}
	cin >> k;
	sort(b + 1, b + n + 1);
	FOR(i,1,n)
		where[b[i].second] = i;

	mn = ps = 0;
	minsum = plussum = 0LL;
	LL sum = 0LL;
	FOR(i, 1, len)
		if (a[i] >= 0)
		{
			sum += (LL)a[i];
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
			plus.insert(a[i]);
		}
		else
		{
			sum += (LL)a[i];
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
			minus.insert(-a[i]);
		}
	//printNumbers(plus);
	//printNumbers(minus);
	if (ps <= k || mn <= k)
	{
		check(ans, minsum + plussum);
	}
	long long first = one.suma(1, 1, n, min(ps, k));
	long long second = two.suma(1, 1, n, min(mn, k));
	//cout << first << " " << second <<endl;
	check(ans, minsum - plussum + 2LL * first);
	check(ans, plussum - minsum + 2LL * second);

	for (int i = len + 1; i <= n; ++i)
	{
		//plus
		sum += (long long)a[i] - (long long)a[i - len];
		if (a[i] >= 0)
		{
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
			plus.insert(a[i]);
		}
		else
		{
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
			minus.insert(-a[i]);
		}
		//delete
		if (a[i - len] >= 0)
		{
			--ps;
			plussum -= (LL)a[i - len];
			one.del(1, 1, n, where[i - len]);
			plus.erase(a[i-len]);
		}
		else
		{
			--mn;
			minsum -= (LL)abs(a[i - len]);
			two.del(1, 1, n, where[i - len]);
			minus.erase(a[i-len]);
		}
		//check answer
		check(ans, sum);
		if (ps <= k || mn <= k) check(ans, minsum + plussum);
		long long first = one.suma(1, 1, n, min(ps, k));
		long long second = two.suma(1, 1, n, min(mn, k));
		check(ans, minsum - plussum + 2LL * first);
		check(ans, plussum - minsum + 2LL * second);
	}

	cout << ans << endl;
	return 0;
}


#include <cassert>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for (int i = (a); (i) <= (b); ++(i))
#define mp make_pair
#define inf 2000000000
#define pb push_back
#define X first
#define Y second
#define LL long long

const int maxN = 400002;
inline void check(LL &a, LL b)
{
	if (b > a) a = b;
	//	cout << " check " <<b << endl;
}

struct El
{
	int cnt;
	LL sum;
};

LL a[maxN];
int where[maxN];
pair<LL, int> b[maxN];
//multiset<int> plus, minus;
int n, len, k, mn, ps;

class Tree
{
private:

	El tr[maxN * 5];

public:

	void add(int root, int l, int r, int pos)
	{
		assert(l <= r);
		assert(pos >= l);
		assert(pos <= r);
		//cout << "insert " << root << " " << l << " " << r << " " << pos << endl;
		if (l == r)
		{
			++tr[root].cnt;
			tr[root].sum += b[l].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (pos <= m) add(left, l, m, pos);
		else	add(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
		//if (root == 1)
//			cout << endl;
	}

	LL suma(int root, int l, int r, int k)
	{
		assert(l <= r);
		//cout << "Sum " << root << " " << l << " " << r << " " << k << endl;
		if (k <= 0) return 0LL;
		//cout << " tree " << root << " " << l << " " << r <<" " << k << endl;
		if (tr[root].cnt == k)
			return tr[root].sum;
		if (l == r)
		{
			return (k>0) ? tr[root].sum : 0LL;
		}
		int m = (l + r) / 2, left = root * 2, right = left + 1;
		if (tr[right].cnt >= k)
			return suma(right, m + 1, r, k);
		else
			return tr[right].sum + suma(left, l, m, k - tr[right].cnt);
	}

	void del(int root, int l, int r, int pos)
	{
		assert(l <= r);
		if (l == r)
		{
			--tr[root].cnt;
			tr[root].sum -= (LL)b[pos].first;
			return;
		}
		int m = (l + r) / 2, left = root * 2, right = root * 2 + 1;
		if (pos <= m) del(left, l, m, pos);
		else	del(right, m + 1, r, pos);
		tr[root].cnt = tr[left].cnt + tr[right].cnt;
		tr[root].sum = tr[left].sum + tr[right].sum;
	}

};

LL ans, minsum, plussum;
Tree one, two;

//void printNumbers(multiset<int> nm){
//	cout << "\t\t";
//	for (auto it = nm.begin(); nm.end() != it; ++it){
//		cout << *it << " ";
//	}
//	cout << endl;
//}

int main()
{
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	cin >> n >> len;
	FOR(i, 1, n)
	{
		scanf("%I64d", &a[i]);
		b[i].first = abs(a[i]);
		b[i].second = i;
	}
	cin >> k;
	sort(b + 1, b + n + 1);
	FOR(i,1,n)
		where[b[i].second] = i;

	mn = ps = 0;
	minsum = plussum = 0LL;
	LL sum = 0LL;
	FOR(i, 1, len)
		if (a[i] >= 0)
		{
			sum += (LL)a[i];
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
//			plus.insert(a[i]);
		}
		else
		{
			sum += (LL)a[i];
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
	//		minus.insert(-a[i]);
		}
	//printNumbers(plus);
	//printNumbers(minus);
	if (ps <= k || mn <= k)
	{
		check(ans, minsum + plussum);
	}
	long long first = one.suma(1, 1, n, min(ps, k));
	long long second = two.suma(1, 1, n, min(mn, k));
	//cout << first << " " << second <<endl;
	check(ans, minsum - plussum + 2LL * first);
	check(ans, plussum - minsum + 2LL * second);

	for (int i = len + 1; i <= n; ++i)
	{
		//plus
		sum += (long long)a[i] - (long long)a[i - len];
		if (a[i] >= 0)
		{
			++ps;
			plussum += (long long)a[i];
			one.add(1, 1, n, where[i]);
		//	plus.insert(a[i]);
		}
		else
		{
			++mn;
			minsum += (long long)abs(a[i]);
			two.add(1, 1, n, where[i]);
			//minus.insert(-a[i]);
		}
		//delete
		if (a[i - len] >= 0)
		{
			--ps;
			plussum -= (LL)a[i - len];
			one.del(1, 1, n, where[i - len]);
			//plus.erase(a[i-len]);
		}
		else
		{
			--mn;
			minsum -= (LL)abs(a[i - len]);
			two.del(1, 1, n, where[i - len]);
			//minus.erase(a[i-len]);
		}
		//check answer
		check(ans, sum);
		if (ps <= k || mn <= k) check(ans, minsum + plussum);
		long long first = one.suma(1, 1, n, min(ps, k));
		long long second = two.suma(1, 1, n, min(mn, k));
		check(ans, minsum - plussum + 2LL * first);
		check(ans, plussum - minsum + 2LL * second);
	}

	cout << ans << endl;
	return 0;
}


#include <stdlib.h>
#include <time.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int M=100000+10;
typedef long long int ll;

struct QUERY{
	int L,R;
	int totalblock;
	//QUERY(int L, int R):L(L),R(R){
	//}
	bool operator <(const QUERY&x) const
	{
		int interlen=sqrt(1.0*totalblock);
		if ( (L/interlen)!=(x.L/interlen) )
		{
			return (L/interlen)<(x.L/interlen);
		}
		else
		{
			return R<x.R;
		}
	}
}query[M];

ll maxksum;
multiset<int> maxk,candidatek;

int a[M];
ll prefixsum[M];
int k;

void Add(int id)
{
	if (a[id]>=0)
	{
		return ;
	}
	else
	{
		int isize=maxk.size();
		if (isize<k)
		{
			maxk.insert(-a[id]);
			maxksum=maxksum+(-a[id]);
		}
		else
		{
			multiset<int>::iterator it=maxk.begin();
			int lastval=(*it);
			if (lastval>=(-a[id]))
			{
				candidatek.insert(-a[id]);
			}
			else
			{
				maxksum=maxksum-lastval+(-a[id]);
				candidatek.insert(lastval);
				maxk.erase(it);
				maxk.insert(-a[id]);
			}
		}

	}
	return ;
}

void Remove(int id)
{
	if (a[id]>=0)
	{
		return ;
	}
	else
	{
		multiset<int>::iterator it=candidatek.find(-a[id]);
		if (it!=candidatek.end())
		{
			candidatek.erase(it);
		}
		else
		{
			it=maxk.find(-a[id]);
			maxksum=maxksum-(-a[id]);
			maxk.erase(it);
			int isize=candidatek.size();
			if (isize>0)
			{
				multiset<int>::reverse_iterator rit=candidatek.rbegin();
				int lastval=(*rit);
				it=candidatek.find(lastval);
				candidatek.erase(it);
				maxksum=maxksum+lastval;
				maxk.insert(lastval);
			}
		}
		return ;
	}
}

ll ans=-1;
void Mo (int qnum)
{
	// initialization
	maxk.clear(); candidatek.clear();
	maxksum=0;

	int curL=0;
	int curR=-1;

	for (int i=0; i<qnum; i++)
	{

		int L=query[i].L; int R=query[i].R;

		//cout<<"L="<<L<<" R="<<R<<endl;
		//cout<<"curL="<<curL<<" curR="<<curR<<endl;
		// right border
		while (curR<R)
		{
			//cout<<"curR="<<curR<<endl;
			curR++; Add(curR);
		}
		//cout<<"curR="<<curR<<endl;
		while (curR>R)
		{
			Remove(curR); curR--;
		}

		// left border
		while (curL<L)
		{
			Remove(curL); curL++;
		}
		while (curL>L)
		{
			curL--; Add(curL);
		}

		ll num2=prefixsum[R];
		ll num1=0;
		if (L>0)
		{
			num1=prefixsum[L-1];
		}
		ll tsum=num2-num1;
		tsum=tsum+2*maxksum;
		ans=max(ans,abs(tsum));
	}
}

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

	int n,len;
	cin>>n>>len;
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	cin>>k;
	k=min(k,len);
	prefixsum[0]=a[0];
	for (int i=1; i<n; i++)
	{
		prefixsum[i]=prefixsum[i-1]+a[i];
	}

	int qnum=0;
	for (int i=0; i+len-1<n; i++)
	{
		query[qnum].L=i; query[qnum].R=i+len-1; query[qnum].totalblock=n-len+1;
		qnum++;
	}
	sort(query, query+qnum);

	if (k==0)
	{
		for (int i=0; i+len-1<n; i++)
		{
			ll num2=prefixsum[i+len-1];
			ll num1=0;
			if (i>0)
			{
				num1=prefixsum[i-1];
			}
			ll tsum=num2-num1;
			ans=max(ans,abs(tsum));
		}
		cout<<ans<<endl;
	}
	else
	{
		for (int i=0; i<2; i++)
		{
			//cout<<i<<endl;
			for (int j=0; j<n; j++)
			{
				a[j]=(1-2*i)*a[j];
				prefixsum[j]=(1-2*i)*prefixsum[j];
			}
			Mo(qnum);
		}
		cout<<ans<<endl;
	}

	return 0;

}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0) {
			it = curr.find(-arr[lf]);
			if (it == curr.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else {
				sum -= *it;
				curr.erase(it);
			}
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0 && k) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0) {
			it = curr.find(-arr[lf]);
			if (it == curr.end() && wait.find(arr[lf]) != wait.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else if (it != curr.end()) {
				sum -= *it;
				curr.erase(it);
			}
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0 && k) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0) {
			it = curr.find(-arr[lf]);
			if (it == curr.end() && wait.find(arr[lf]) != wait.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else if (it != curr.end()) {
				sum -= *it;
				curr.erase(it);
			}
			else sum -= arr[lf];
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0 && k) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0) {
			it = curr.find(-arr[lf]);
			if (it == curr.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else {
				sum -= *it;
				curr.erase(it);
			}
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0 && k) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0 && k) {
			it = curr.find(-arr[lf]);
			if (it == curr.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else {
				sum -= *it;
				curr.erase(it);
			}
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
	curr.clear();
	wait.clear();
	ll sum = 0;
	for(int i = 0; i < len; i ++) {
		if (arr[i] < 0 && k) {
			int px = -arr[i];
			if (curr.size() < k)
				curr.insert(px);
			else {
				int mn = *curr.begin();
				if (px > mn) {
					curr.erase(curr.begin());
					curr.insert(px);
					wait.insert(mn);
				}
				else
					wait.insert(-px);
			}
		}
		else sum += arr[i];
	}
	for(it = curr.begin(); it != curr.end(); it ++)
		sum += *it;
	for(it = wait.begin(); it != wait.end(); it ++)
		sum += *it;
	int lf = 0, rg = len;
	ll ans = sum;
	while (rg < n) {
		if (arr[rg] < 0) {
			sum += arr[rg];
			wait.insert(arr[rg]);
		}
		else sum += arr[rg];
		if (arr[lf] < 0) {
			it = curr.find(-arr[lf]);
			if (it == curr.end() && wait.find(arr[lf]) != wait.end()) {
				wait.erase(wait.find(arr[lf]));
				sum -= arr[lf];
			}
			else {
				sum -= *it;
				curr.erase(it);
			}
		}
		else sum -= arr[lf];

		if (curr.size() < k && !wait.empty()) {
			sum -= 2 * (*wait.begin());
			curr.insert(-(*wait.begin()));
			wait.erase(wait.begin());
		}
		else if (!curr.empty() && !wait.empty()) {
			int x = *curr.begin();
			int y = *wait.begin();
			y = -y;
			if (x < y) {
				curr.erase(curr.begin());
				wait.erase(wait.begin());
				curr.insert(y);
				wait.insert(-x);
				sum += 2 * y;
				sum -= 2 * x;

			}
		}

		ans = max(ans, sum);
		lf ++, rg ++;
	}
	return ans;
}

int main () {
	//freopen ("input.txt","r",stdin);
	scanf("%d%d", &n, &len);
	for(int i = 0; i < n; i ++)
		scanf("%d", &arr[i]);
	scanf("%d", &k);
	ll ans = 0;
	ans = max(ans, solve());
	for(int i = 0; i < n; i ++)
		arr[i] *= -1;
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

const int MN = 1000 * 100 + 10;

int n, len, k;

int arr[MN];

multiset <int> curr, wait;
multiset <int> :: iterator it;

ll solve() {
    curr.clear();
    wait.clear();
    ll sum = 0;
    for(int i = 0; i < len; i ++) {
        if (arr[i] < 0 && k) {
            int px = -arr[i];
            if (curr.size() < k)
                curr.insert(px);
            else {
                int mn = *curr.begin();
                if (px > mn) {
                    curr.erase(curr.begin());
                    curr.insert(px);
                    wait.insert(-mn);
                }
                else
                    wait.insert(-px);
            }
        }
        else sum += arr[i];
    }
    for(it = curr.begin(); it != curr.end(); it ++)
        sum += *it;
    for(it = wait.begin(); it != wait.end(); it ++)
        sum += *it;
    int lf = 0, rg = len;
    ll ans = sum;
    while (rg < n) {
        if (arr[rg] < 0) {
            sum += arr[rg];
            wait.insert(arr[rg]);
        }
        else sum += arr[rg];
        if (arr[lf] < 0 && k) {
            it = curr.find(-arr[lf]);
            if (it == curr.end()) {
                wait.erase(wait.find(arr[lf]));
                sum -= arr[lf];
            }
            else {
                sum -= *it;
                curr.erase(it);
            }
        }
        else sum -= arr[lf];

        if (curr.size() < k && !wait.empty()) {
            sum -= 2 * (*wait.begin());
            curr.insert(-(*wait.begin()));
            wait.erase(wait.begin());
        }
        else if (!curr.empty() && !wait.empty()) {
            int x = *curr.begin();
            int y = *wait.begin();
            y = -y;
            if (x < y) {
                curr.erase(curr.begin());
                wait.erase(wait.begin());
                curr.insert(y);
                wait.insert(-x);
                sum += 2 * y;
                sum -= 2 * x;

            }
        }

        ans = max(ans, sum);
        lf ++, rg ++;
    }
    return ans;
}

int main () {
    //freopen ("input.txt","r",stdin);
    scanf("%d%d", &n, &len);
    for(int i = 0; i < n; i ++)
        scanf("%d", &arr[i]);
    scanf("%d", &k);
    ll ans = 0;
    ans = max(ans, solve());
    for(int i = 0; i < n; i ++)
        arr[i] *= -1;
    ans = max(ans, solve());
    cout << ans << 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;
}


#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 (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(x);
		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;
}


#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 (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(x);
		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;
}


#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 (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(x);
		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;
}


#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>
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

int a[102400];

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

	maxpt(int _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 (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(x);
		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()
{
	int n, len;
	cin >> n >> len;
	REP(i, n)
		cin >> a[i];

	int 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]);
	}

	int start = 0;
	while(true)
	{
		ans = max(ans, ABS(pos.total_sum - neg.total_sum));
		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 <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <numeric>
using namespace std;

int nextInt() {
    int x;
    scanf("%d", &x);
    return x;
}

long long nextLong() {
    long long x;
    scanf("%I64d", &x);
    return x;
}

double nextDouble() {
    double x;
    scanf("%lf", &x);
    return x;
}

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
    scanf("%s", buf);
    return buf;
}
string nextLine() {
    gets(buf);
    return buf;
}

int stringToInt(string s) {
    stringstream in(s);
    int x;
    in >> x;
    return x;
}

struct Point {
    typedef double T;
    T x, y;
    Point () : x(0), y(0) {}
    Point (T x, T y) : x(x), y(y) {}
    Point operator - (Point op) const { return Point(x - op.x, y - op.y); }
    Point operator + (Point op) const { return Point(x + op.x, y + op.y); }
    Point operator * (T op) const { return Point(x * op, y * op); }
    T operator * (Point op) const { return x * op.x + y * op.y; }
    T operator % (Point op) const { return x * op.y - y * op.x; }
    T length2() { return x * x + y * y; }
    double length() { return sqrt(length2()); }
};

Point nextPoint() {
    double x = nextDouble();
    double y = nextDouble();
    return Point(x, y);
}

typedef multiset<long long> Set;

void add(Set &neg, Set &negK, long long &sumNeg, long long x, int k) {
    negK.insert(x);
    sumNeg += x;
    if (negK.size() > k) {
        sumNeg -= *negK.begin();
        neg.insert(*negK.begin());
        negK.erase(negK.begin());
    }
}

void remove(Set &neg, Set &negK, long long &sumNeg, long long x, int k) {
    if (neg.find(x) != neg.end()) {
        neg.erase(neg.find(x));
    } else {
        Set::iterator it = negK.find(x);
        sumNeg -= x;
        negK.erase(it);
        if (negK.size() < k && !neg.empty()) {
            sumNeg += *neg.rbegin();
            negK.insert(*neg.rbegin());
            neg.erase(--neg.end());
        }
    }
}

long long solve(vector<long long> &a, int len, int k) {
    Set neg;
    Set negK;
    long long sumNeg = 0;
    long long sum = 0;
    for (int i = 0; i < len; ++i) {
        if (a[i] < 0) {
            add(neg, negK, sumNeg, -a[i], k);
        }
        sum += a[i];
    }
    long long res = sum + 2 * sumNeg;
    for (int i = len; i < a.size(); ++i) {
        if (a[i] < 0) {
            add(neg, negK, sumNeg, -a[i], k);
        }
        sum += a[i];

        int j = i - len;
        if (a[j] < 0) {
            remove(neg, negK, sumNeg, -a[j], k);
        }
        sum -= a[j];
        res = max(res, sum + 2 * sumNeg);
    }
    return res;
}

int main() {
    int n = nextInt();
    int len = nextInt();
    vector<long long> a(n);
    for (int i = 0; i < a.size(); ++i) {
        a[i] = nextInt();
    }
    int k = nextInt();
    long long r1 = solve(a, len, k);
    for (int i = 0; i < a.size(); ++i) {
        a[i] *= -1;
    }
    long long r2 = solve(a, len, k);
    cout << max(r1, r2) << endl;
    return 0;
}


#include<cstdio>
#include<set>
typedef __int64 LL;
#define MAXN 100010
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
LL a[MAXN];
struct SET
{
    int limit;
    LL big,small;
    multiset<LL>high;
    multiset<LL,greater<LL> >low;
    void Init(int x)
    {
        limit=x;
        big=small=0;
        high.clear();
        low.clear();
    }
    void Insert(LL x)
    {
        high.insert(x);
        big+=x;
        if(high.size()>limit)
        {
            x=*high.begin();
            high.erase(high.begin());
            low.insert(x);
            big-=x;
            small+=x;
        }
    }
    void Delete(LL x)
    {
        if(low.count(x))
        {
            low.erase(low.find(x));
            small-=x;
        }
        else
        {
            high.erase(high.find(x));
            big-=x;
            if(!low.empty())
            {
                x=*low.begin();
                low.erase(low.begin());
                high.insert(x);
                small-=x;
                big+=x;
            }
        }
    }
};
SET pos,neg;
void Insert(LL x)
{
    if(x<0)
        neg.Insert(-x);
    else
        pos.Insert(x);
}
void Delete(LL x)
{
    if(x<0)
        neg.Delete(-x);
    else
        pos.Delete(x);
}
inline LL Query()
{
    return MAX(pos.big+pos.small+neg.big-neg.small,neg.big+neg.small+pos.big-pos.small);
}
int main()
{
    LL ans;
    int n,len,k,i;
    while(~scanf("%d%d",&n,&len))
    {
        for(i=0;i<n;i++)
            scanf("%I64d",&a[i]);
        scanf("%d",&k);
        pos.Init(k);
        neg.Init(k);
        for(i=0;i<len;i++)
            Insert(a[i]);
        ans=Query();
        for(;i<n;i++)
        {
            Delete(a[i-len]);
            Insert(a[i]);
            ans=MAX(ans,Query());
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<set>
typedef __int64 LL;
#define MAXN 100010
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
LL a[MAXN];
struct SET
{
    int limit;
    LL big,small;
    multiset<LL>high;
    multiset<LL,greater<LL> >low;
    void Init(int x)
    {
        limit=x;
        big=small=0;
        high.clear();
        low.clear();
    }
    void Insert(LL x)
    {
        high.insert(x);
        big+=x;
        if(high.size()>limit)
        {
            x=*high.begin();
            high.erase(high.begin());
            low.insert(x);
            big-=x;
            small+=x;
        }
    }
    void Delete(LL x)
    {
        if(low.count(x))
        {
            low.erase(low.find(x));
            small-=x;
        }
        else
        {
            high.erase(high.find(x));
            big-=x;
            if(!low.empty())
            {
                x=*low.begin();
                low.erase(low.begin());
                high.insert(x);
                small-=x;
                big+=x;
            }
        }
    }
};
SET pos,neg;
void Insert(LL x)
{
    if(x<0)
        neg.Insert(-x);
    else
        pos.Insert(x);
}
void Delete(LL x)
{
    if(x<0)
        neg.Delete(-x);
    else
        pos.Delete(x);
}
inline int Query()
{
    return MAX(pos.big+pos.small+neg.big-neg.small,neg.big+neg.small+pos.big-pos.small);
}
int main()
{
    LL ans;
    int n,len,k,i;
    while(~scanf("%d%d",&n,&len))
    {
        for(i=0;i<n;i++)
            scanf("%I64d",&a[i]);
        scanf("%d",&k);
        pos.Init(k);
        neg.Init(k);
        for(i=0;i<len;i++)
            Insert(a[i]);
        ans=Query();
        for(;i<n;i++)
        {
            Delete(a[i-len]);
            Insert(a[i]);
            ans=MAX(ans,Query());
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<set>
typedef __int64 LL;
#define MAXN 100010
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
LL a[MAXN];
struct SET
{
	int limit;
	LL big,small;
	multiset<LL>high;
	multiset<LL,greater<LL> >low;
	void Init(int x)
	{
		limit=x;
		big=small=0;
		high.clear();
		low.clear();
	}
	void Insert(LL x)
	{
		high.insert(x);
		big+=x;
		if(high.size()>limit)
		{
			x=*high.begin();
			high.erase(x);
			low.insert(x);
			big-=x;
			small+=x;
		}
	}
	void Delete(LL x)
	{
		if(low.count(x))
		{
			low.erase(low.find(x));
			small-=x;
		}
		else
		{
			high.erase(high.find(x));
			big-=x;
			if(!low.empty())
			{
				x=*low.begin();
				low.erase(x);
				high.insert(x);
				small-=x;
				big+=x;
			}
		}
	}
};
SET pos,neg;
void Insert(LL x)
{
	if(x<0)
		neg.Insert(-x);
	else
		pos.Insert(x);
}
void Delete(LL x)
{
	if(x<0)
		neg.Delete(-x);
	else
		pos.Delete(x);
}
inline int Query()
{
	return MAX(pos.big+pos.small+neg.big-neg.small,neg.big+neg.small+pos.big-pos.small);
}
int main()
{
	LL ans;
	int n,len,k,i;
	while(~scanf("%d%d",&n,&len))
	{
		for(i=0;i<n;i++)
			scanf("%I64d",&a[i]);
		scanf("%d",&k);
		pos.Init(k);
		neg.Init(k);
		for(i=0;i<len;i++)
			Insert(a[i]);
		ans=Query();
		for(;i<n;i++)
		{
			Delete(a[i-len]);
			Insert(a[i]);
			ans=MAX(ans,Query());
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cmath>
#include <cstdio>
#include <set>
using namespace std;
#define inf 1000000000
#define ll long long
#define eps 1e-9
#define L(s) (int)((s).size())
int a[111111];
int k, n, m;
multiset<int> opt_pos, opt_neg, oth_pos, oth_neg;
ll sum_pos, sum_neg, rest_pos, rest_neg, ans;
inline void put_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (L(opt_pos) < k) {
		opt_pos.insert(x);
		sum_pos += x;
	} else
		if (x > *opt_pos.begin()) {
			sum_pos -= *opt_pos.begin();
			sum_pos += x;
			rest_pos += *opt_pos.begin();
			oth_pos.insert(*opt_pos.begin());
			opt_pos.erase(opt_pos.begin());
			opt_pos.insert(x);
		} else {
			rest_pos += x;
			oth_pos.insert(x);
		}
}
inline void take_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (oth_pos.find(x) != oth_pos.end()) {
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
		return;
	}
	opt_pos.erase(opt_pos.find(x));
	sum_pos -= x;
	if (L(oth_pos)) {
		multiset<int>::iterator it = oth_pos.end(); --it; x = *it;
		opt_pos.insert(x);
		sum_pos += x;
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	scanf("%d", &k);
	ans = 0;
	for(int i = 0; i < n; ++i) {
		if (a[i] > 0) put_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i]);
		else
			if (a[i] < 0) put_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i]);
		if (i >= m) {
				if (a[i - m] > 0) take_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i - m]);
				else
					if (a[i - m] < 0) take_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i - m]);
		}
		ll v1 = rest_pos - rest_neg + sum_pos + sum_neg;
		if (v1 < 0) v1 *= -1;
		ll v2 = rest_pos - rest_neg - sum_pos - sum_neg;
		if (v2 < 0) v2 *= -1;
		ans = max(ans, max(v1, v2));
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cmath>
#include <cstdio>
#include <set>
using namespace std;
#define inf 1000000000
#define ll long long
#define eps 1e-9
#define L(s) (int)((s).size())
int a[111111];
int k, n, m;
multiset<int> opt_pos, opt_neg, oth_pos, oth_neg;
ll sum_pos, sum_neg, rest_pos, rest_neg, ans;
inline void put_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (L(opt_pos) < k) {
		opt_pos.insert(x);
		sum_pos += x;
	} else
		if (k && x > *opt_pos.begin()) {
			sum_pos -= *opt_pos.begin();
			sum_pos += x;
			rest_pos += *opt_pos.begin();
			oth_pos.insert(*opt_pos.begin());
			opt_pos.erase(opt_pos.begin());
			opt_pos.insert(x);
		} else {
			rest_pos += x;
			oth_pos.insert(x);
		}
}
inline void take_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (oth_pos.find(x) != oth_pos.end()) {
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
		return;
	}
	opt_pos.erase(opt_pos.find(x));
	sum_pos -= x;
	if (L(oth_pos)) {
		multiset<int>::iterator it = oth_pos.end(); --it; x = *it;
		opt_pos.insert(x);
		sum_pos += x;
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	scanf("%d", &k);
	ans = 0;
	for(int i = 0; i < n; ++i) {
		if (a[i] > 0) put_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i]);
		else
			if (a[i] < 0) put_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i]);
		if (i >= m) {
				if (a[i - m] > 0) take_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i - m]);
				else
					if (a[i - m] < 0) take_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i - m]);
		}
		if (i >= m - 1) {
			ll v1 = rest_pos - rest_neg + sum_pos + sum_neg;
			if (v1 < 0) v1 *= -1;
			ll v2 = rest_pos - rest_neg - sum_pos - sum_neg;
			if (v2 < 0) v2 *= -1;
			ans = max(ans, max(v1, v2));
		}
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cmath>
#include <cstdio>
#include <set>
using namespace std;
#define inf 1000000000
#define ll long long
#define eps 1e-9
#define L(s) (int)((s).size())
int a[111111];
int k, n, m;
multiset<int> opt_pos, opt_neg, oth_pos, oth_neg;
ll sum_pos, sum_neg, rest_pos, rest_neg, ans;
inline void put_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (L(opt_pos) < k) {
		opt_pos.insert(x);
		sum_pos += x;
	} else
		if (x > *opt_pos.begin()) {
			sum_pos -= *opt_pos.begin();
			sum_pos += x;
			rest_pos += *opt_pos.begin();
			oth_pos.insert(*opt_pos.begin());
			opt_pos.erase(opt_pos.begin());
			opt_pos.insert(x);
		} else {
			rest_pos += x;
			oth_pos.insert(x);
		}
}
inline void take_it(multiset<int> &opt_pos, multiset<int> &oth_pos, ll &sum_pos, ll &rest_pos, int x) {
	if (oth_pos.find(x) != oth_pos.end()) {
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
		return;
	}
	opt_pos.erase(opt_pos.find(x));
	sum_pos -= x;
	if (L(oth_pos)) {
		multiset<int>::iterator it = oth_pos.end(); --it; x = *it;
		opt_pos.insert(x);
		sum_pos += x;
		oth_pos.erase(oth_pos.find(x));
		rest_pos -= x;
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	scanf("%d", &k);
	ans = 0;
	for(int i = 0; i < n; ++i) {
		if (a[i] > 0) put_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i]);
		else
			if (a[i] < 0) put_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i]);
		if (i >= m) {
				if (a[i - m] > 0) take_it(opt_pos, oth_pos, sum_pos, rest_pos, a[i - m]);
				else
					if (a[i - m] < 0) take_it(opt_neg, oth_neg, sum_neg, rest_neg, -a[i - m]);
		}
		ll now  = max(
			abs(rest_pos - rest_neg + sum_pos + sum_neg),
			abs(rest_pos - rest_neg - sum_pos - sum_neg));
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}