Please look into this DEADEND lunchtime code

Can anyone please let me know what is the error in my logic?

Getting AC for 1 test case but runtime error for others.
I am not able to figure out why since yesterday night.
Please help.

The test case has been adding an extra space ’ ’ at the end in few scenarios
and since i used
a = list(map(int, input().split(’ ')))

instead of
a = list(map(int, input().split()))

I had been getting a runtime error because of the above mentioned problem…
Ideally there shouldn’t be an extra space at the end of input sequence…