/*
    Problem: Minimum Top-Ranked Elements Needed to Form a Majority Subarray
    Company Tag: Trilogy OA problem

    Problem Statement:
        We are given A books in a row.

        B[i] is the thickness of the i-th book.
        All thicknesses are unique.

        If we cover a book of thickness x, then every book thicker than x
        must also be covered.

        So we can only choose the k thickest books.

        We need the minimum k such that there exists a contiguous subarray
        of length at least C where:

            number of covered books > number of uncovered books

    Constraints:
        1 <= A <= 100000
        1 <= B[i] <= A
        B[i] values are unique.
        1 <= C <= A

    Simple Brute Force:
        Try every k.
        For every k, check every possible subarray.

    Why Brute Force Fails:
        There can be 100000 books.
        Checking all subarrays for every k is too slow.

    Better Idea:
        Binary search the answer k.

        For a fixed k:
            - Mark the k thickest books as +1.
            - Mark all other books as -1.

        Now the question becomes:
            Is there any subarray of length at least C with sum > 0?

        If yes, covered books are more than uncovered books in that subarray.

    Dry Run:
        A = 6
        B = [6, 1, 4, 2, 5, 3]
        C = 4

        Try k = 3.
        Covered books are 6, 5, and 4.

        Converted array:
            [1, -1, 1, -1, 1, -1]

        Subarray [6, 1, 4, 2, 5] has sum 1.
        So it has more covered books.

        Answer = 3

    Time Complexity:
        O(A log A)

    Space Complexity:
        O(A)
*/

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

bool canCreateMajoritySubarray(int A, vector<int>& B, int C, int k) {
    vector<int> prefix(A + 1, 0);

    /*
        Since B contains unique values from 1 to A,
        the k thickest books have thickness >= A - k + 1.
    */
    int minimumCoveredThickness = A - k + 1;

    for (int i = 0; i < A; i++) {
        int value;

        if (B[i] >= minimumCoveredThickness) {
            value = 1;
        } else {
            value = -1;
        }

        prefix[i + 1] = prefix[i] + value;
    }

    int minimumPrefixSeen = 0;

    for (int right = C; right <= A; right++) {
        /*
            For a subarray ending at right and having length at least C,
            the left prefix can be at most right - C.
        */
        minimumPrefixSeen = min(minimumPrefixSeen, prefix[right - C]);

        int bestSum = prefix[right] - minimumPrefixSeen;

        if (bestSum > 0) {
            return true;
        }
    }

    return false;
}

int solution(int A, vector<int> B, int C) {
    int low = 1;
    int high = A;
    int answer = A;

    while (low <= high) {
        int mid = low + (high - low) / 2;

        if (canCreateMajoritySubarray(A, B, C, mid)) {
            answer = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    return answer;
}

int main() {
    int A, C;
    cin >> A;

    vector<int> B(A);

    for (int i = 0; i < A; i++) {
        cin >> B[i];
    }

    cin >> C;

    cout << solution(A, B, C) << endl;

    return 0;
}