i aint getting why I m getting two outputs in place of a single one? : I m solving a simple program and i am getting 2 outputs of the same data with a single cout statement...probably something went wrong with my loop , which i am not able to find where is the problem...also...if possible please answer acc. to my code and my logic or if not then atleast specify why my logic is wrong...

My code:-
`

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main(){
        int n ;
        cin >> n;
        vector<int> arr(n);
        vector<int> a(n);
        for(int arr_i = 0;arr_i < n;arr_i++){
           cin >> arr[arr_i];
           a[arr_i]=1;
        }
        int i,least,flag,count=n;
        do{
            cout<<count<<endl;
            count=0;
            flag=1;
            
            for(i=0;i<n;i++){   //for getting least number
                if(a[i]){
                    if(flag){
                        least=arr[i];
                        flag=0;    
                    }
                    if(arr[i]<least){
                        least=arr[i];
                    }
                }
            }
            
            for(i=0;i<n;i++){       // for actual logic
                if(arr[i]<=0||!a[i]){
                    a[i]=0;
                    
                    //continue;
                }
                else{    
                arr[i]-=least;
                count++;
                }
            }
            
        }while(count);
        return 0;
    }

`

**Sample input:-**
`

    6
    5 4 4 2 2 8

`
**Sample output:- (Expected Output)**


    6
    4
    2
    1

`
**Output I 'm getting in this Sample input**:-


    6
    6
    4
    4
    2
    2
    1
    1

`

**Problem statement:-**

You are given N sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the smallest stick.

Suppose we have six sticks of the following lengths:
5 4 4 2 2 8

Then, in one cut operation we make a cut of length 2 from each of the six sticks. For the next cut operation four sticks are left (of non-zero length), whose lengths are the following: 
3 2 2 6

The above step is repeated until no sticks are left.

Given the length of N sticks, print the number of sticks that are left before each subsequent cut operations.

**Note:** For each cut operation, you have to recalcuate the length of smallest sticks (excluding zero-length sticks).