| 2018 USP-ICMC |
|---|
| Finished |
Byung is playing a game on her infinite checkerboard. The goal of the game is to move from a starting position (rs, cs) to a target position (rt, ct) using exactly x moves, where x is determined by a roll of a N-sided dice.
A move consists in going from a square on the checkerboard to one of its four neighbors - up, down, left or right.
Her dice is unbiased, meaning that every number from 1 to N has the same probability of being rolled.
She's interested in knowing what's the number of different rolls that allow her to move to the target position in the last move. She can move to the same square more than once if she needs to. Can you help her?
The input is composed by a single line containing 5 integers N (1 ≤ N ≤ 109), rs, cs, rt and ct ( - 109 ≤ rs, cs, rt, ct ≤ 109) indicating respectively the number of sides of the dice, the coordinates of the starting position and the coordinates of the target position.
An integer number indicating the number of outcomes that she'll get a good roll.
5 1 1 2 3
2
500 -100 -100 100 100
51
| Name |
|---|


