long NSets(int N){
long C=0;
int[] res=new int[N];
k=-1;
_forward:
if(++k==N){
C++; goto _backward;
}
res[k]=k==0 ? 0 : res[k-1];
goto _forward;
_backward:
if(--k<0) return C;
if(++res[k]>=M) goto _backward;
goto _forward;
}
long NSets(int N){
const int FORWARD=0;
const int BACKWARD=1;
const int RETURN=2;
long C=0;
int[] res=new int[N];
k=-1;
int state=FORWARD;
while(state!=RETURN){
swtich(state){
case FORWARD:
if(++k==N){
C++; state=BACKWARD;
}else{
res[k]=k==0 ? 0 : res[k-1];
}
break;
case BACKWARD:
if(--k<0) state=RETURN;
else if(++res[k]<M) state=FORWARD;
break;
}
}
return C;
}