In the second part you are using Python ints instead of SageMath Integers.
Use srange instead of range, or convert to an Integer before the division, e.g. Integer(i[0])/len(a).
In the second part you are using Python ints instead of SageMath Integers.
Use srange (with universe=ZZ if you're not passing an Integer) instead of range, or convert to an Integer before the division, e.g. Integer(i[0])/len(a).