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);

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

            if(v[i] == d )
                ans = 1 ;
        }
    }
    else {
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
            if(v[i] == d)
                ans++;
        }

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

    cout << ans << 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
960 KB
Wrong Answer