I get Segmentation Fault after submitting.

When you get segmentation fault, it generally means that your program crashed while processing the judge input. Note that your code might work for the sample input but fail with the judge input. This is because the judge input generally has higher numbers, as specified in the constraints section.

Sometimes, you don’t realize that you’re making the program accessing data that should not even exist. Take this for example:

The last few lines of the output this program gives looks like:

Note that the output might vary depending on your compiler! This is what happens with mine.

When i = 66, i + 3 = 69, and we did not (and can not) put anything on a[69] because the elements of the array a are a[0], a[1], a[2], up to a[68]. And so, a[i+3] = a[69] is not in any way related to a. But it is.

Moreover, another strange phenomenon happens when we check a[70]. Note that it is equal to 200. Moreover, a[71] is 201. It seems that instead of accessing values of a, we are already accessing the values of b. Note that the program does not complain, but it definitely gives wrong answers. So you definitely should be careful not to do that.

Now, let’s modify the program a bit and see what happens if we push it to the limit.

Now, the program complains and says Segmentation Fault. And so, for higher numbers, instead of using other data, the computer just gives up and says Segmentation Fault. And this is what normally happens when you access array elements that are out of bounds.

Note that this is a not-so-technical treatment of something technical. If you are interested, Google is your friend.