Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const int inf = 2e9;
const ll infll = 1e18;
const int M = 1000000007;
const int N = 2e5;

int n, d, a[N];
int main(){
    scanf("%d%d", &n, &d);
    int ans = 0;
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
        ans += (a[i] == d);
    }
    if(ans){
        if((ans&1) || d == 0) cout << ans << endl;
        else cout << ans - 1;
    }
    else
        cout << 0 << endl;

}

Copy
Legendary Hambubger
GNU G++17
27 ms
1.7 MB
Accepted