This was indeed a headache but think i finally solved it:

Take a look at this algorithm

E(1):=1;E(2)=1 .........E(5):=1;

For (k=1; k<=p; k++)

{

For (i=1;i<=5;i++)

{ V(1)=0; v(2)=0; ............v(5)=0;

For(j=1;j<=5;j++)

{

V(i)=V(i)+j(7-j)*E(j)

}

E(i):=V(i);

}

}

S:= E(1)+E(2)+E(3)+E(4)+E(5);

And that's all

Enjoy and have a nice day !