Under construction

Still being built. Things may change

One more line

Time limit1sMemory limit1024 MB

Summary
Given a grid of lines x=0..n and y=0..n plus one segment between two cell centers, count the axis-parallel rectangles whose sides lie on those lines.
Level

Medium6 of 10

Topics
Math, Geometry, Combinatorics
Solved
No attempts yet

Problem

A coordinate plane has 2n+22n+2 lines drawn on it. The lines are x=0,x=1,⋯ ,x=nx = 0, x = 1, \cdots, x = n and y=0,y=1,⋯ ,y=ny = 0, y = 1, \cdots, y = n. Bsil was counting the rectangles that can be formed from this figure.

Then a segment connecting the points (xa+0.5,ya+0.5)(x_a + 0.5, y_a + 0.5) and (xb+0.5,yb+0.5)(x_b + 0.5, y_b + 0.5) was added. Bsil, who likes solving every problem with a single formula, now faces a very hard problem. To help him, count the rectangles with sides parallel to the coordinate axes whose sides can be formed from the intersections of lines with lines or lines with the segment.

Input

The first line contains an integer nn. (1≤n≤1041 \le n \le 10^4)

The second line contains two integers xax_a and yay_a. (−104≤xa,ya≤104-10^4 \le x_a, y_a \le 10^4)

The third line contains two integers xbx_b and yby_b. (−104≤xb,yb≤104-10^4 \le x_b, y_b \le 10^4)

It is guaranteed that (xa+0.5,ya+0.5)(x_a + 0.5, y_a + 0.5) and (xb+0.5,yb+0.5)(x_b + 0.5, y_b + 0.5) are different points.

Output

Print the answer to the problem.

Examples1

  1. Example 1

    Input
    3
    0 2
    2 2
    
    Expected output
    40