static boolean nextPermutation(List<Integer> a){

		int[]p = new int [a.size()];
		for (int i = 0; i < p.length; i++) {
			p[i]=a.get(i);
		}

		int k,l,aux,i,j;
		for (k = p.length-1; k>0 && p[k-1]>=p[k]; k--);
		if (k!=0){
			for (l = p.length-1; l>0 && p[k-1]>=p[l]; l--);
			aux=p[k-1]; p[k-1]=p[l]; p[l]=aux;
			for (i = k, j = p.length-1; i<j ; i++,j--){
				aux=p[i]; p[i]=p[j]; p[j]=aux;
			}
			return true;
		} 	
		else return false;
	}