I have an array with integers, I just have to count the pairs and return that counted value.

```
static int StockMerchant(int n , int arr[]){
    int[] temp = new int[n];
    int count = 0;
    for(int i =0  ; i<n ; i++){
            for(int j= i+1 ; j<n ; j++){

                if(arr[i]==arr[j]){

                   arr[j] = '0';
                   arr[i] ='0';
                   count++;
                }
            }

    }
        return count;
}

```

when I try: `1 1 2 2 2`: gives output 2

But when I change the input to `1 2 1 2 2`: gives output 3

I want the output to be 2 in the second case also. please help.