Please let me know why code is giving segmentation fault

Code -https://ide.codingblocks.com/s/246238

@7nishit
I have fixed your code.
there were 2 mistakes, declaring such a big array (> 1e6) in main().
and comparing s[i] and not s[i-1].