Bandit Blues
Contest: Divide by Zero 2018 and Codeforces Round 474 (Div. 1 + Div. 2, combined)
Difficulty rating: 2900
Tags: combinatorics, dp, fft, math

Japate, while traveling through the forest of Mala, saw N bags of gold lying in a row. Each bag has some distinct weight of gold between 1 to N. Japate can carry only one bag of gold with him, so he uses the following strategy to choose a bag.

Initially, he starts with an empty bag (zero weight). He considers the bags in some order. If the current bag has a higher weight than the bag in his hand, he picks the current bag.

Japate put the bags in some order. Japate realizes that he will pick A bags, if he starts picking bags from the front, and will pick B bags, if he starts picking bags from the back. By picking we mean replacing the bag in his hand with the current one.

Now he wonders how many permutations of bags are possible, in which he picks A bags from the front and B bags from back using the above strategy.

Since the answer can be very large, output it modulo 998244353.

Input format:
The only line of input contains three space separated integers N (1 ≤ N ≤ 105), A and B (0 ≤ A, B ≤ N).

Output format:
Output a single integer — the number of valid permutations modulo 998244353.

Constraints:
Time limit: 3.5 s
Memory limit: 256.0 MB

Note:
In sample case 1, the only possible permutation is [1]

In sample cases 2 and 3, only two permutations of size 2 are possible:{[1, 2], [2, 1]}. The values of a and b for first permutation is 2 and 1, and for the second permutation these values are 1 and 2.

In sample case 4, out of 120 permutations of [1, 2, 3, 4, 5] possible, only 22 satisfy the given constraints of a and b.

Example input:
1 1 1

Example output:
1

Example input:
2 1 1

Example output:
0

Editorial:
The problem can be seen as to count the number of permutations such that the number of records from the front is A and the number of records from the back is B, where a record is an element greater than all previous.
let s(A, N) be the number of permutations such that for N elements exactly A records are present from front. Then s(A, N) can be calculated as
s(A, N) = s(A - 1, N - 1) + (N - 1) * s(A, N - 1)
Let's consider the smallest element if we have it as a record then we can place it on front and have the remaining A - 1 records in s(A - 1, N - 1) ways or we don't have it as a record than we can have the remaining A records in s(A, N - 1) ways and place this smallest element at any of the remaining N - 1 positions.
let h(A, B, N) be the number of permutations such that the number of records from the front is A and the number of records from the back is B.
$$h(A,B,N) = \sum_{k=0}^{N-1} s(k,A-1) * s(N-k-1,B-1) * {N-1 \choose k}$$
k elements are chosen and placed before the largest record such that exactly A - 1 records are present in them in s(k, A - 1) ways and the remaining N - k - 1 after the largest record such that B - 1 records are present in s(N - k - 1, B - 1) ways.We choose the k elements in $${ \binom { N - 1 } { k } }$$ ways.
Now we claim that
$$h(A,B,N) = s(A+B-2,N-1) * \binom{A+B-2}{A-1}$$
Proof — Consider permutations of length N - 1 with A + B - 2 records of which A - 1 are colored blue and B - 1 are colored green.
Note — Coloring a record means coloring the record and every element between this record and previous record.
We can choose permutations of N - 1 with A + B - 2 records ,then choose A - 1 of these records to be blue in $$s(A+B-2,N-1)*(A+B-2 \choose A-1)$$ ways.
Also for any k between 0 and N - 1 we choose k elements to be in blue then make permutations in these k elements with A - 1 records and make permutations with exactly B - 1 records on remaining N - k - 1 elements, thus we have in total $$\sum_{k=0}^{N-1} s(k,A-1) * s(N-k-1,B-1) * \binom{N-1}{k}$$ ways.
Hence both are equivalent. Therefore calculating s(A + B - 2, N - 1) gives our answer. s(k, n) forms stirling number of first kind which can be calculated by coefficent of xk in x * (x + 1) * (x + 2) * ..... * (x + n - 1) using FFT.