```
int distributeCandies(vector<int>& candies) {
int res=0;
int num=candies.size();
unordered_map<int,int>m;
for(int i=0;i<num;i++) m[candies[i]]++;
for(auto x:m){
if(x.second>0) res++;
if(res==num/2) break;
}
return res;
}
```