405295: GYM101875 D Checkerboard

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Checkerboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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?

Input

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.

Output

An integer number indicating the number of outcomes that she'll get a good roll.

ExamplesInput
5 1 1 2 3
Output
2
Input
500 -100 -100 100 100
Output
51

Source/Category

加入题单

上一题 下一题 算法标签: