Source Code
#include <bits/stdc++.h> 
#define int long long
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define SORT(c) sort(all(c))
#define rSORT(c) sort(rall(c))
#define f first
#define s second
#define pb push_back
#define endl "\n"
using namespace std;
void solve();
bool pr[2000001];//sieve(2000001);
int fact[100000];//factorial();
int choose(int n, int r){return r<0||r>n?0:(r==0||r==n)?1:choose(n-1,r-1)+choose(n-1,r);}
void factorial(){fact[0]=1;for(int i=1;i<10001;i++)fact[i]=fact[i-1]*i%7901;}
void sieve(int n){for(int i=2;i<=n;i++)pr[i]=1;for(int i=2;i<=n;i++)if(pr[i])for(int j=i*2;j<=n;j+=i)pr[j]=0;}
int countSubarrays(int s, int k){if(s<k)return 0;return(s-k+1)*(s-k+2)/2;}
int power(int b, int e){int r=1;while(e>0){if(e % 2 != 0)r*=b;b*= b;e/=2;}return r;}
int bitsNeeded(int n){int count = 0;while (n > 0){count++;n >>= 1;}return count;}
int32_t main(){ios::sync_with_stdio(false);cin.tie(0);int t = 1;int i = 1;
    //cin >> t;
    while(t--){//cout<<"_________________________________\n";cout<<"Test case Number: "<<i++<<endl<<endl;
        solve();
    }
}
void solve(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    
    for(int i = 0;i<n;i++){
        int x;cin >> x;
        if(x == k){
            ans++;
        }
    }
    if(ans % 2 == 0) ans--;
    cout << max(ans,0LL);
}
Copy
Legendary barakat
GNU G++17
4 ms
988 KB
Wrong Answer