B - AtCoder Language
Source: atcoder
Difficulty: 500

Problem Statement
The AtCoder language has
L
different characters.
How many
N
-character strings
s
consisting of characters in the AtCoder language satisfy the following condition?
Find the count modulo
998244353
.
All
K
-character subsequences of the string
s
are different. More precisely, there are
_N\mathrm{C}_K
ways to obtain a
K
-character string by extracting
K
characters from the string
s
and concatenating them without changing the order, and all of these ways must generate different strings.
What is
_N\mathrm{C}_K
?
_N\mathrm{C}_K
refers to the total number of ways to choose
K
from
N
items. More precisely,
_N\mathrm{C}_K
is the value of
N!
divided by
K! \times (N-K)!
.
Constraints
1 \leq K < N \leq 500000
1 \leq L \leq 10^9
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
K
L
Output
Print the count modulo
998244353
.
Sample Input 1
4 3 2
Sample Output 1
2
If
a
and
b
represent the first and second characters in the language, the condition is satisfied by two strings:
abab
and
baba
.
Sample Input 2
100 80 26
Sample Output 2
496798269
Approximately
10^{86}
strings satisfy the condition, but here we print the count modulo
998244353
, which is
496798269
.
Sample Input 3
100 1 26
Sample Output 3
0
Sample Input 4
500000 172172 503746693
Sample Output 4
869120

C++ solution:
#include <math.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include <random>
#include <chrono>
#include <vector>
#include <algorithm>

#define LOG(FMT...) fprintf(stderr, FMT)

#define eb emplace_back

using namespace std;

typedef long long LL;
constexpr int N = 32, mod = 998244353;

int n, m, L;

int main() {
	scanf("%d%d%d", &n, &m, &L), m = n - m;
	int res = 1;
	for (int i = 1; i <= n; ++i) {
		res = res * (LL)(L - min(i - 1, m)) % mod;
	}
	printf("%d\n", res);
	return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

const (
	inf = 1 << 60
	MOD = 998244353
)

func main() {
	/*** INIT ***/
	defer wt.Flush()
	sc.Buffer([]byte{}, inf)
	sc.Split(bufio.ScanWords)

	n, k, l := InputInt(), InputInt(), InputInt()
	ans := l
	for i := 1; i < n; i++ {
		if i < n-k {
			ans *= Max(0, l-i)
		} else {
			ans *= Max(0, l-(n-k))
		}
		ans %= MOD
	}

	OutInt(ans)
}

func Max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

/*** I/O ***/
func InputInt() int {
	sc.Scan()
	val, _ := strconv.Atoi(sc.Text())
	return val
}

func InputString() string {
	sc.Scan()
	return sc.Text()
}

func OutInt(val int) {
	fmt.Fprintln(wt, val)
}

func OutString(s string) {
	fmt.Fprintln(wt, s)
}

Java solution:
import java.io.*;
import java.util.*;
import java.util.function.*;

public class Main {
  private static void execute(ContestReader reader, ContestWriter out) {
    int n = reader.nextInt();
    int k = reader.nextInt();
    int l = reader.nextInt();
    long answer = 1;
    for (int i = 0; i < n; i++) {
      answer *= l - Math.min(i, n - k);
      answer %= 998244353;
    }
    out.println(answer);
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    ContestWriter out = new ContestWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestWriter extends PrintWriter {
  ContestWriter(PrintStream printStream) {
    super(printStream);
  }

  public void printYN(boolean b) {
    println(b ? "Yes" : "No");
  }

  public void printYNList(List<Boolean> bList) {
    for (boolean b : bList) {
      printYN(b);
    }
  }

  public void printList(List<? extends Object> list) {
    for (Object object : list) {
      println(object);
    }
  }

  public void printListOneLine(List<? extends Object> list) {
    List<String> stringList = new ArrayList<>();
    for (Object object : list) {
      stringList.add(object.toString());
    }
    println(String.join(" ", stringList));
  }
}

class ContestReader {
  private static final int BUFFER_SIZE = 1024;
  
  private final InputStream stream;
  private final byte[] buffer;
  private int pointer;
  private int bufferLength;
  
  ContestReader(InputStream stream) {
    this.stream = stream;
    this.buffer = new byte[BUFFER_SIZE];
    this.pointer = 0;
    this.bufferLength = 0;
  }
  
  private boolean hasNextByte() {
    if (pointer < bufferLength) {
      return true;
    }
    
    pointer = 0;
    try {
      bufferLength = stream.read(buffer);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return bufferLength > 0;
  }
  
  private int readByte() {
    if (hasNextByte()) {
      return buffer[pointer++];
    } else {
      return -1;
    }
  }
  
  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }
  
  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
      pointer++;
    }
    return hasNextByte();
  }
  
  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    while(true) {
      int b = readByte();
      if (!isPrintableChar(b)) {
        break;
      }
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }
  
  public String nextLine() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    while(true) {
      int b = readByte();
      if (!isPrintableChar(b) && b != 0x20) {
        break;
      }
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }
  
  public char nextChar() {
    return next().charAt(0);
  }
  
  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    
    int n = 0;
    boolean minus = false;
    
    {
      int b = readByte();
      if (b == '-') {
        minus = true;
      } else if ('0' <= b && b <= '9') {
        n = b - '0';
      } else {
        throw new NumberFormatException();
      }
    }
    
    while(true){
      int b = readByte();
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
    }
  }
  
  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    
    long n = 0;
    boolean minus = false;
    
    {
      int b = readByte();
      if (b == '-') {
        minus = true;
      } else if ('0' <= b && b <= '9') {
        n = b - '0';
      } else {
        throw new NumberFormatException();
      }
    }
    
    while(true){
      int b = readByte();
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
    }
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public String[] nextLine(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLine();
    }
    return array;
  }
  
  public char[] nextChar(int n) {
    char[] array = new char[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextChar();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public String[][] next(int n, int m) {
    String[][] matrix = new String[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = next();
      }
    }
    return matrix;
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public char[][] nextChar(int n, int m) {
    char[][] matrix = new char[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextChar();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}

class Pair<T, U> {
  T first;
  U second;

  Pair(T first, U second) {
    this.first = first;
    this.second = second;
  }
}

class MyAssert {
  public static void myAssert(boolean flag, String message) {
    if (!flag) {
      throw new RuntimeException(message);
    }
  }
 
  public static void myAssert(boolean flag) {
    myAssert(flag, "");
  }
}

JavaScript solution:
function Main(input) {
    const [N, K, L] = input.split(" ").map(BigInt);
    const mod = 998244353n;
    let ans = 1n;
    let tmp = 0n;
    for (let i = 0; i < N; i++) {
        ans *= L - tmp;
        ans %= mod;
        if (tmp < N - K) tmp++;
    }
    console.log(ans.toString());
}
Main(require("fs").readFileSync(0)+"")

Python solution:
#ARC172B AtCoder Language

#入力受取
N, K, L = map(int, input().split())
MOD = 998244353

#愚直解
def brute(N, K, L):
    from itertools import product, combinations
    ans = 0
    for S in product(range(L), repeat = N):
        T = set()
        for X in combinations(range(N), r = K):
            Y = tuple([S[Xi] for Xi in X])
            if Y in T: break
            else: T.add(Y)
        else:
            ans += 1
    return ans
        

#最初に使ったK文字は末尾K - 1文字で再使用できるようになる: abcxxxab の要領
#区間の重複があっても問題なさそうに見えるが
def solve(N, K, L):
    left = L
    ans = 1
    for i in range(N):
        Li = N - i  #自身を含めた残り文字数
        if Li < K: left += 1
        ans *= left
        ans %= MOD
        left -= 1
    return ans
        
#実行
print(solve(N, K, L))

Ruby solution:
END { load __FILE__ unless $stdin.eof? }
@m = 998_244_353

n, k, l = gets.split.map!(&:to_i)

if n - k >= l
  puts 0
  exit
end

c = (l - n + k).pow(k, @m)
(n - k).times { |i| c *= (l - i); c %= @m }

puts c
$stdout.flush

__END__