• + 0 comments

    My versiion:

        s=[x%k for x in s]
        s1=[x for x in s if x!=0]
        if 0 in s:
            s1.append(0)
        counter=[0] * (k+1)
        for x in s1: 
            counter[x]+=1
        count=0;
        for i in range(0,k//2+1):
            max_k=max(counter)
            max_ind_rem=counter.index(max_k)
            if max_ind_rem*2==k:
                if max_ind_rem *2== k :
                    count=count+1
                else:
                    count=count+max(1, counter[k-max_ind_rem])
            else:
                count+=max_k
           #we include already
            counter[max_ind_rem]=0;
            counter[k-max_ind_rem]=0
        return count