Could you share some example of the input data you are using to get the segmentation fault?
I don't have examples because the site evaluates the code itself without inputs. But I heard that the site inputs a tons of possible samples in it, so maybe some sort of extreme sample causes problem...