The Intriguing Obsession
Contest: Codeforces Round 439 (Div. 2)
Difficulty rating: 1800
Tags: combinatorics, dp, math

— This is not playing but duty as allies of justice, Nii-chan!

— Not allies but justice itself, Onii-chan!

With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!

There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.

Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.

The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.

Input format:
The first and only line of input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output format:
Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

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

Note:
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.

In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.

Example input:
1 1 1

Example output:
8

Example input:
1 2 2

Example output:
63

Editorial:
First step: Consider what does at least 3 mean?
'The shortest distance between them is at least 3' means it can't be 1 or 2. The distance can't be 1 means that no two islands with the same colour can be straightly connected. The distance can't be 2 means that for each island, no two islands with the same colour can both be straightly connected with it.
Second step: Make the graph into 3 parts.
The bridges between red and blue islands have no effection with those between red and purple ones. Therefore, we can make the graph into 3 parts: one between red and blue, one between blue and purple, and the last one between red and purple.
Suppose there are A red islands and B blue islands, and there are k bridges between them. Then, the answer will be $${ \binom { A } { k } } { \binom { B } { k } } ( k! )$$. So, the answer of bridges between red and blue ones should be $$\sum_{k=0}^{\min(A,B)} \binom{A}{k} \binom{B}{k} (k!)$$
Therefore, the final answer should be ans1 * ans2 * ans3.
You can calculate it with an O(n2) brute force. Also, you can make it into O(n).