Source Code
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define printv(x) for(int i : x) cout << i << " "; cout << endl;

#define fl(x) for(int i = 0 ; i < x.size(); i++ )
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl


void solve() {
    int n ,d ;
    cin >> n >> d;

    vector<int>v(n);

    vector<int> ds;

    for (int i = 0; i < n; ++i) {
        cin >> v[i];

        if(v[i] == d )  {
            if(i!=0 and v[i-1] == d) {
                ds[ds.size()- 1 ]++;
            }
            else {
                ds.push_back(1);
            }
        }
    }

    int max = 0;

    for (int i = 0; i < ds.size(); ++i) {
        if(ds[i] > max)
            max = ds[i];
    }


    if(max % 2 == 0 and max > 1 ) {
        max-- ;
    }


    cout << max << endl;

}

int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//    int t ; cin >> t; while(t--) solve();
    solve();

    return 0;

}
Copy
Legendary Shweiki
GNU G++17
3 ms
828 KB
Wrong Answer