Solution gives RE with vector but passes test cases with array

The below code gives runtime error (SIGABRT) while using vector, but if I make the count variable an array without changing anything else, it passes the test cases. Solution: 40843829 | CodeChef

I looked up what causes SIGABRT and I found it mostly happens while using assert statements or accessing an invalid memory location. I don’t think either is happening with my code. Please help me find the source of error.


PS : I figured out my mistake, I am indeed accessing indices out of the bounds of the vector. Precisely, I am accessing count[-1]. The thing is arrays show undefined behaviour when accessing indices out of bounds. See https://stackoverflow.com/questions/1239938/accessing-an-array-out-of-bounds-gives-no-erro for more information. Hence, my code worked when switching count to an array. I am leaving this post as it is partly for self reference and I also believe many beginners like me are unaware of this fact. Maybe this will save some from a RE during a contest.