Darshan And His Cat
All submissions for this problem are available.Darshan loves his cat! But his cat doesn't love him. His cat is too selfish to be homed! Once a day, while his cat was asleep, Darshan thought he could complete a task given by his boss. Darshan had a string of $N + 1$ integers (0 to $N$) written on his book, but in their binary form and without any leading zeroes. For example if $N = 4$, his book contained 011011100. ("0" + "1" + "10" + "11" + "100" for 0,1,2,3,4). Tired of his work, Darshan went to have some coffee. His cat woke up and got interested in his work a little. It randomized the string in his book and after that it erased all the leading zeroes! For example the cat randomized the above string to 000110111 and then erased the first 3 zeroes leaving 110111. When Darshan returned, he was furious about his cat messing his work! Also, Darshan cannot remember what was his $N$ for this string. Help him with finding $N$ so that he can try to rebuild the original string. ###Input: - First line contains $T$ number of testcases - Every testcase consists of - First line contains a integer $M$ - Next line contains $M$ space separated integers $A_1,A_2,...,A_M$ - This describes the damaged string as $A_1$ 1's followed by $A_2$ 0's and continued alternately. ###Output: For each testcase, print a single integer $N$. ###Constraints - $1 \leq T \leq 10$ - $1 \leq M \leq 10^6$ - $1 \leq A_i \leq 10^9$ ###Sample Input: 1 3 2 1 3 ###Sample Output: 4 ###Explanation: This testcase is explained in the problem statement.
|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, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions