```
int distributeCandies(vector<int>& candies) {
std::sort(candies.begin(), candies.end());
int n = candies.size(), cnt = 0;
for(int i=0; i<n && cnt < n/2 ;i++)
if(i+1==n||candies[i] != candies[i+1])cnt++;
return cnt;
}
```