#K64792. Count Words with Exactly k Characters

    ID: 32054 Type: Default 1000ms 256MiB

Count Words with Exactly k Characters

Count Words with Exactly k Characters

Given a string S consisting of uppercase English letters and an integer k, your task is to compute the number of distinct words that can be formed by selecting exactly k characters from S and arranging them in any order.

If k = 0, there is exactly one way (by choosing nothing). If k is greater than the length of S, output 0. The problem can be mathematically expressed using permutations as follows:

\( \text{Result} = \frac{n!}{(n-k)!} \)

where \( n \) is the length of S.

inputFormat

The input consists of exactly two lines:

  • The first line contains the string S (only uppercase English letters).
  • The second line contains the integer k.

outputFormat

Output a single integer representing the number of words that can be formed by using exactly k characters from S.

## sample
ABCDE
3
60