fork download
  1. # your code goes here
  2. t = input()
  3. for i in range(t):
  4. n = input()
  5. x = map(int,raw_input().split())
  6. x.sort()
  7. ans = 0
  8. if (n%4) == 0:
  9. s = n/4
  10. j = 1
  11. while s*j <= n:
  12. ans += sum(x[j*4 - 2:j*4])
  13. j += 1
  14. else:
  15. l = 4 - n%4
  16. for k in range(l):
  17. x.append(0)
  18. x.sort()
  19. n = n + l
  20. s = n/4
  21. j = 1
  22. while s*j <= n:
  23. ans += sum(x[j*4 - 2:j*4])
  24. j += 1
  25. print ans
  26.  
  27.  
Success #stdin #stdout 0.01s 9032KB
stdin
3
4
1 1 2 2
2
10 200
7
1 1 10 2 2 2 1
stdout
4
210
14