All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
A sequence of integers is beautiful if each element of this sequence is divisible by 4.
You are given a sequence a1, a2, ..., an. 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.
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer n.
- The second line contains n space-separated integers a1, a2, ..., an.
For each test case, print a single line containing one number — the minimum number of steps necessary to make the given sequence beautiful. If it's impossible to make the sequence beautiful, print -1 instead.
- 1 ≤ T ≤ 105
- 1 ≤ n ≤ 105
- 1 ≤ sum of n over all test cases ≤ 106
- 0 ≤ ai ≤ 109
Input: 1 7 1 2 3 1 2 3 8 Output: 3
|Tags||chemthan, chemthan, cook89, easy, greedy, likecs|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.