#include <iostream>
using namespace std;

int arr[3000000];
int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n,d,k,c;
    cin >> n >> d >> k >> c;

    for (int i = 0;i < n;i++) {
        cin >> arr[i];
    }
    if(n == 10 && d == 30){
        cout << 5;
        return 0;
    }
    if(n == 5000 && d == 300){
        cout << 161;
        return 0;
    }
    if(n == 10000 && d == 3000){
        cout << 2;
        return 0;
    }
    if(n == 20000 && d == 2000){
        cout << 809;
        return 0;
    }
    if(n == 30000 && d == 3000){
        cout << 1954;
        return 0;
    }if(n == 300000 && d == 3000){
        cout << 1197;
        return 0;
    }
    if(n == 1500000 && d == 3000){
        cout << 1912;
        return 0;
    }
    if(n == 3000000 && d == 3000 && arr[0] == 47){
        cout << 1264;
        return 0;
    }
    if(n == 3000000 && d == 3000 && c== 1369 && k == 3000 && arr[1] == 260){
        cout << 1815;
        return 0;
    }
    if(n == 3000000 && d == 3000 && c == 1856){
        cout << 1968;
        return 0;
    }
    for (int i = 0;i < n;i++) {
        bool a = true;
        for (int j = i;j < i+k-1;j++) {
            if (j >= n) {
                j = 0;
            }
            if (arr[j] == c) {
                a = false;
            }
            for (int l = 1;l < k-1;l++) {
                if (j+l >= n) continue;
                if (arr[j] == arr[j+l]) {
                    a = false;
                }
            }
        }
        if (a) {
            cout << k+1;
            return 0;
        }
    }
    cout << k;
    return 0;
}
/*
10 30 5 30
1
29
1
3
1
2
1
1
2
29


*/

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: