script to stack Picture X by x

Hi, I’m terrible with scripts and can’t get anything to work…
Could someone write a script that, starting from a loaded sequence in Siril, stacks the images in batches of X (with the number X being asked of the user at the start of the script)?
The idea is to end up with a new sequence featuring a better SNR.

And since I really am clueless, please explain how to save it in my script folder. Thanks for your help