#P13710. [NWERC 2023] Klompendans

[NWERC 2023] Klompendans

题目描述

In traditional Dutch clog dancing, as the dancer, you need to follow a very specific sequence of movements. The dance takes place on a square grid of square tiles. At the start of the dance, you stand on the top - left corner tile of the grid. Then, you alternate between two types of dance moves, moving from tile to tile in the grid for as long as you want. Your first move can be either type, but after that, you must strictly alternate between the two types of moves.

Both moves are similar to knight moves in chess: In the first type of move, you move from your current square to a square that is aa tiles away along one axis of the grid and bb tiles away along the other axis. Similarly, in the second type of move, you need to move cc tiles and dd tiles along the respective axes. Since you can freely swap the two axes and choose the movement direction along each axis, there can be up to 8 ways to perform a given type of move. Figure K.1 shows an example dance routine with (a,b)=(1,2)(a, b)=(1, 2) and (c,d)=(2,3)(c, d)=(2, 3).

:::align{center} Figure K.1: Illustration of Sample Input 3, showing a dance that begins in the top - left corner of a 4×44\times4 grid and ends in the bottom - left corner, visiting the blue squares along the way. There are 13 reachable squares in total. The three squares highlighted in red cannot be part of any dance performance. :::

Starting on the top - left corner tile, how many different tiles could you reach while doing a clog dance? It is not allowed to step outside the grid, and you do not count tiles that you simply step over while making a move. Note that you need to count all tiles that can be reached during some performance of the dance, not necessarily during the same one.

输入格式

The input consists of:

  • One line with an integer nn (3n5003\leq n\leq500), the side length of the square.
  • One line with two integers aa and bb (1a,b<n1\leq a, b\lt n), describing the first dance move.
  • One line with two integers cc and dd (1c,d<n1\leq c, d\lt n), describing the second dance move.

输出格式

Output the number of tiles you can reach using these dance moves.

3
2 1
2 2
6
8
1 2
1 2
64
4
1 2
2 3
13
5
1 2
2 3
25
10
3 3
4 4
50