title: Beautiful sequence
body: <p>A sequence of integers is beautiful if each element of this sequence is divisible by <code>4</code>.You are given a sequence <code>a1, a2, ..., an</code>. In one step, you may choose any two elements of this sequence, remove them from the sequence and append their sum to the sequence. Compute the minimum number of steps necessary to make the given sequence beautiful else print <code>-1</code> if this is not possible.</p>
  
  <pre><code>for i in range(int(input())):
      n=int(input())
      arr=list(map(int,input().split()))
      if((sum(arr))%4)!=0:
          print(-1)
          continue
      else:
          counter=[]
          for i in range(n):
              if arr[i]%4!=0:
                  counter.append(arr[i])
              else:
                  continue
  
          x=sum(counter)
          while(x%4==0):
              x=x//4
  
          print(x)
  </code></pre>
  
  <p>My approach:if the sum of the array is not divisible by <code>4</code> then the array can not be beautiful else  if the sum of the array mod <code>4</code> is equal to zero i count the elements in the array whose mod by 4 is not equal to zero and append them in the list and then find the sum  of the list and divide the sum by 4 till its quotient modulus 4 is not equal to zero.what i am doing wrong here?</p>
  
  <p>Edit:I have a working script which works well </p>
  
  <pre><code>for i in range(int(input())):
      n=int(input())
      arr=list(map(int,input().split()))
      count1=0
      count2=0
      count3=0
      summ=0
      for i in range(n):
          x=arr[i]%4
          summ+=x
  
  
          if x==1:
              count1+=1
  
          if x==2:
              count2+=1
  
          if x==3:
              count3+=1
      if (summ%4)!=0:
          print(-1)
          continue
  
      else:
  
  
          if count2==0 and count1!=0 and count3==0:
              tt=count1//4
              print(3*tt)
  
          if count2==0 and count1==0 and count3!=0:
              tt=count3//4
              print(3*tt)
  
          if count2%2==0 and count1==count3:
              print(count2//2+count1)
  
          flag1=min(count1,count3)
          flag2=abs(count1-count3)
  
          if count2%2==0 and count1!=count3:
  
              flag3=flag2//4
              flag4=flag3*3
  
              print(count2//2+ flag1+ flag4)
  
          if count2%2!=0 and count1!=count3:
              flag3=flag2-2
              flag4=flag3//4
              flag5=flag4*3
  
  
              print(((count2-1)//2)+flag1+flag5+2)
  </code></pre>