#P1758. Pipe Beads

    ID: 15043 Type: Default 1000ms 256MiB

Pipe Beads

Pipe Beads

This problem is a variant of a game called "Pipe Beads". Initially, there are two left‐side tubes and one right‐side output tube. The left side consists of an upper tube and a lower tube.

The upper tube contains n beads and the lower tube contains m beads. In each move you may choose one of the two left tubes and push its rightmost bead into the output tube. After exactly n+m moves all beads will have been transferred. The beads in the output tube form a sequence when read from right‐to‐left.

For this problem the configuration of the beads is fixed as follows:

  • The upper tube’s beads are arranged so that the bead that is pushed first from this tube is dark (denoted by B), the second is light (A), the third is dark (B), the fourth is light (A), and so on. That is, if we label the beads of the upper tube in the order in which they are removed (from first removed to last removed), then the i-th bead is B if i is odd and A if i is even.
  • The lower tube’s beads are all dark (B).

An operation order is defined by a binary string of length n+m with exactly n occurrences of U (indicating that the upper tube is chosen) and m occurrences of D (indicating that the lower tube is chosen). For any such order, the beads from the upper tube appear in the order described above and the beads from the lower tube (all B) appear in their natural order.

Thus, every operation order produces an output sequence X of length n+m where for each position:

  • If the move is from the upper tube, then the letter is B if it is the 1st, 3rd, 5th, … upper move and A if it is the 2nd, 4th, … upper move.
  • If the move is from the lower tube, the letter is always B.

Note that different operation orders might yield the same output sequence. Suppose there are K distinct possible output sequences. Denote by ai the number of operation orders that produce the i-th output sequence. Then we have

$$\sum_{i=1}^{K}a_i=\binom{n+m}{m}\,,$$

and the problem asks you to compute:

$$\sum_{i=1}^{K}a_i^2 \quad (\bmod\;1024523)\,.$$


Note: It may be more convenient to think of the process in pairs. In other words, if we let F(p) be the output sequence generated by the operation order p, then the quantity required is

$$\sum_{X}\;[\#\{p: F(p)=X\}]^2\,,$$

which is exactly the number of pairs (p, q) of operation orders such that F(p)=F(q).

Your task is to compute this value modulo 1024523.

inputFormat

The input consists of a single line containing two integers n and m (0<= n, m <= 100). Here, n is the number of beads in the upper tube and m is the number of beads in the lower tube.

Remember that the configuration of beads is fixed: the upper tube’s removal order produces beads: B, A, B, A, … (starting from the first removal) and the lower tube’s beads are all B.

outputFormat

Output a single integer: the value of
$$\sum_{i=1}^{K}a_i^2\quad(\bmod\;1024523)$$
where ai is the number of operation orders that yield the i-th output sequence.

sample

1 1
4