# codechef error nzec

T = int(input()) for i in range(T): N = int(input()) s = input() a=list(s) s=a j=0 i=0 for i in range(0,N-1): if a[i]==a[i+1]: if a[i]=='0': a[i+1]='1' j=j+1 else: if a[i]==s[i]: a[i]='0' j=j-1 print(j) this is my code ,its working on idle but on codechef its showing error, can anyone help me out.

3/23/2019 1:20:19 PM

yash Chitty7 Answers

New Answerhi yash, I get an error when running the code: Traceback (most recent call last): File "help sololearn 2.py", line xy, in <module> if a[i]==a[i+1]: IndexError: list index out of range For me it's not very clear what you want to achieve with this code. Can you give us some more information?

What error is it showing? On a cursory look, I notice you have embedded for loops, both using the variable ‘i’ to iterate, which could cause an error. But the syntax looks correct at least.

There are N watchtowers built in a row. Each watchtower can only accommodate one person. Some of them are already occupied by members of the Night's Watch. Since the members of the Night's Watch do not get along, no two consecutive towers can be occupied at any moment. Arya heard that the wildlings are planning an attack. She is not satisfied by the current security, so she plans to place more members of the Night's Watch in the empty towers. What is the maximum number of people she can place in the towers such that no two consecutive towers are occupied afterwards? Note that Arya may not remove anyone from already occupied towers. Input 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 next line contains a single string S with length N. For each valid i, the i-th character of this string is '1' if the i-th watchtower is initially occupied or '0' if it is empty.

Output For each test case, print a single line containing one integer — the maximum number of people Arya can place in the towers. Constraints 1≤T≤1,000 1≤N≤106 S contains only characters '0' and '1' initially, no two consecutive towers are occupied the sum of N over all test cases does not exceed 106 Subtasks Subtask #1 (20 points): initially, all towers are empty Subtask #2 (80 points): original constraints Example Input 2 6 010001 11 00101010000 Example Output 1 3 this is the senario given in codeshef so im a beginner so , not able to understand why my code is not running on codeshef it is running on my idle