Only one correct output run error in few

Hello @samadsid7,

It is specified in the question that,
Second Line : n space separated numbers (0s or 1s)

so, if you would input this using string, then space would also be consider as a character and it’s size =2n-1 as it contains spaces at alternate positions.
Example:
1 0 0 1 0 1 0 1 0 1
The string s of your code will have the value β€œ1 0 0 1 0 1 0 1 0 1”
So, iterating it n times means you are iterating for {1, ,0, ,0, ,1, ,0, } only.

Hope, this would help.
If you still face issues, feel free to ask.
Give a like, if you are satisfied.