static long permutation(int [] A, int n, int k, int v){
		
		long count = 0; // Let count be the number of all possible permutations in P(n,k)
		
		int current = 0; // Let current be the index where a swapping has just occurred
		
		do{
			// visit A[1...k] ONLY IF a distinct permutation is generated (a swapping occurs within [1...k])
			if(current <= k){
				count = visit(A, k, v, count);
			}
			
			// Find the max j with A[j] > A[j+1], scanning from right to left
			int j = n-1; 
			while(A[j] >= A[j+1]){
				// If j=1 then break
				if(j == 1) return count;
				j--;
			}
			
			// Find the max l with A[j] >= A[l], scanning from right to left
			int l = n;
			while(A[j] >= A[l]){
				l--;
			}
			
			// Exchange A[j] and A[l]
			swap(A, j, l);
			
			// Reverse A[j+1...n]
			for(int left = j+1, right = n; left < right ; left++, right--){
				swap(A, left, right);
			}
			
			current = j; // set current index to j
			
		} while(true);	// forever looping until j=1
			
	}