The Circle

No attempts yetTime limit1sMemory limit128 MB

Problem

A circle is divided into $n$ sectors ($1 \le n \le 6$). You place one positive integer in each sector; every value must be at least $k$.

A number is reachable if it equals the value of a single sector, or the sum of the values of two or more consecutive sectors along the circle. Because the sectors form a circle, a block of consecutive sectors may wrap around from the last sector back to the first. In total there are $n(n-1)+1$ distinct blocks: the $n$ single sectors, the blocks of length $2, 3, \dots, n-1$, and the one whole circle.

Choose the sector values so that the reachable numbers contain every integer of the unbroken run $m, m+1, m+2, \dots, i$, and make the largest value $i$ as large as possible.

For example, with $n = 5$, $m = 2$, $k = 1$ the arrangement $(1, 3, 10, 2, 5)$ around the circle makes every integer from $1$ to $21$ reachable, so $i = 21$.

Input

Three integers $n$, $m$, and $k$ ($1 \le n \le 6$, $1 \le m \le 20$, $1 \le k \le 20$), given in this order and separated by whitespace or newlines.

It is guaranteed that $k \le m$, so the value $m$ is always reachable (place a sector equal to $m$).

Output

Print a single integer: the largest $i$ such that every integer from $m$ to $i$ inclusive is reachable.

Hint

Consider the example $n = 5$, $m = 2$, $k = 1$ with the circular arrangement $(1, 3, 10, 2, 5)$. Summing every block of consecutive sectors (wrapping around when needed) yields all integers from $1$ to $21$:

  • length 1: $1,\ 3,\ 10,\ 2,\ 5$
  • length 2: $1+3=4,\ 3+10=13,\ 10+2=12,\ 2+5=7,\ 5+1=6$
  • length 3: $1+3+10=14,\ 3+10+2=15,\ 10+2+5=17,\ 2+5+1=8,\ 5+1+3=9$
  • length 4: $1+3+10+2=16,\ 3+10+2+5=20,\ 10+2+5+1=18,\ 2+5+1+3=11,\ 5+1+3+10=19$
  • whole circle: $1+3+10+2+5=21$

Every value in $[2, 21]$ appears, so the answer for this case is $i = 21$.