#P4368. Cherry Blossom Escape

    ID: 17614 Type: Default 1000ms 256MiB

Cherry Blossom Escape

Cherry Blossom Escape

There is a row of n cherry trees, each with an identical height h. One day, a cute little cat, standing on the x-th tree at height y, finds itself suffering from a cherry allergy and wants to escape as quickly as possible.

The cat can perform two kinds of jumps:

  • Gentle Jump: From a tree at position \( (x, y) \), if \( y > b \), the cat can jump to \( (x \pm a, y - b) \). (Here, \( \pm \) means it can choose either the left or right direction.)
  • Hard Jump: From a tree at position \( (x, y) \), if \( y \le h - b \), the cat can jump to \( (x \pm a, y + b) \).

The cat's goal is to reach an exit position, which is defined as either the first tree or the last tree (i.e., tree 1 or tree n) with a height of either \( 1 \) or \( h \). In other words, the cat needs to move to a position \( (x, y) \) such that \( x = 1 \) or \( x = n \) and \( y = 1 \) or \( y = h \).

Your task is to determine the minimum number of jumps required for the cat to reach an exit position. If it is impossible, output -1.

Note: All formulas are represented in \( \LaTeX \) format.

inputFormat

The input consists of a single line containing six space-separated integers:

n h a b x y

where

  • n is the number of cherry trees,
  • h is the height of each tree,
  • a and b are the horizontal and vertical movement parameters respectively,
  • x and y specify the initial tree index and the height at which the cat is located.

outputFormat

Output a single integer representing the minimum number of jumps required for the cat to reach an exit position. If no sequence of moves can achieve this, output -1.

sample

5 10 2 3 3 7
1