Source Code
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define t int t;cin>>t; while(t--)
#define out(a,n) for(int i=0;i<n;i++){cout<<a[i]<< " ";}
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
using pll = pair<ll, ll>;
int main ()
{
    FAST;
    // t
    {
        ll n,d;
        cin>>n>>d;
        ll a[n];
        bool f=0;
        ll cnt=0;
        for (int i=0; i<n; i++)
        {
            cin>>a[i];
            if (a[i]==d)
            {
                cnt++;
                break;
            }
        }
        if (d==0)
            cout<<cnt<<endl;
        else if (cnt&1)
            cout<<cnt<<endl;
        else if (cnt%2==0&&cnt>0)
            cout<<cnt-1;
        else
            cout<<0<<endl;
    }


}





Copy
Legendary Ann_Sam65
GNU G++17
3 ms
884 KB
Wrong Answer