using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
noOfbarsVisibleFromLeft(
int
[] v)
{
int
last = 0, ans = 0;
foreach
(
var
u
in
v){
if
(last < u) {
ans++;
last = u;
}
}
return
ans;
}
public
static
void
NextPermutation(
int
[] nums) {
var
startIndex = nums.Length - 2;
while
(startIndex >= 0) {
if
(nums[startIndex] < nums[startIndex + 1]) {
break
;
}
--startIndex;
}
if
(startIndex >= 0) {
int
endIndex = nums.Length - 1;
while
(endIndex > startIndex) {
if
(nums[endIndex] > nums[startIndex]) {
break
;
}
--endIndex;
}
Swap(
ref
nums[startIndex],
ref
nums[endIndex]);
}
Reverse(nums, startIndex + 1);
}
static
void
Reverse(
int
[] nums,
int
startIndex) {
for
(
int
start = startIndex, end = nums.Length - 1; start < end; ++start, --end) {
Swap(
ref
nums[start],
ref
nums[end]);
}
}
static
void
Swap(
ref
int
a,
ref
int
b) {
var
tmp = a;
a = b;
b = tmp;
}
static
int
KvisibleFromLeft(
int
N,
int
K)
{
int
[] v =
new
int
[N];
for
(
int
i = 0 ; i < N ; i++){
v[i] = i + 1;
}
int
ans = 0;
int
count = 1;
for
(
int
i = 1 ; i <= N ; i++){
count *= i;
}
for
(
int
i = 0 ; i < count ; i++){
if
(noOfbarsVisibleFromLeft(v) == K){
ans++;
}
NextPermutation(v);
}
return
ans;
}
public
static
void
Main(
string
[] args){
int
N = 5, K = 2;
Console.Write(KvisibleFromLeft(N, K) +
"\n"
);
}
}