#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    vector<int> pnl = {4, 3, -2, 9, -4, 2,7};
    int n = pnl.size();
    int k = 6;

    // p[i] stores the sum of the first i elements
    vector<long long> p(n + 1, 0);
    for (int i = 0; i < n; i++) {
        p[i + 1] = p[i] + pnl[i];
    }

    long long maxi = -1e18;

    // Subarray ending at index i (1-based index in prefix array: 1 to n)
    for (int i = 1; i <= n; i++) {
        // j is the start boundary: subarray length is (i - j), which is <= k
        for (int j = max(0, i - k); j < i; j++) {
            long long sum = p[i] - p[j];
            maxi = max(maxi, sum);
        }
    }

    cout << maxi << "\n";
    return 0;
}