Make sum of separat the points in different conditions

I was not claiming this code was bug free. That was just an idea showing how to proceed. You are free to change it as you need. I will look away way.