1int sumOfDistinct(int a[], int n){
2 int sum = 0;
3 for (int i = 0; i < n; i++) {
4 // If element appears first time
5 if (a[abs(a[i]) - 1] >= 0) {
6 sum += abs(a[i]);
7 a[abs(a[i]) - 1] *= -1;
8 }
9 }
10 return sum;