I have algorithm like this.
for(int i=1; i<=n; i++){ for(int j=1; j<=2*n; j=j+2) { for(int k=i; k<=j; k++) { instr; }