Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(0);
    int n, d;
    cin>>n>>d;
    int cnt = 0;
    while(n--) {
        int x;
        cin>>x;
        if (x==d) cnt++;
    }
    if (d==0) cout<<cnt<<endl;
    else {
        if (cnt%2==0 && cnt>0) cnt--;
        cout<<cnt<<endl;
    }
}
Copy
Legendary RedNextCentury
GNU G++17
30 ms
1.0 MB
Accepted