Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.  The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.  The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.  Four elements a, b, c and d are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.

The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.

Print one integer — the number of distinct valid squares.

NoteBelow are all the possible paintings for the first sample.  In the second sample, only paintings displayed below satisfy all the rules.

import java.util.Scanner;
import java.util.StringTokenizer;

public class CF_675B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		StringTokenizer st = new StringTokenizer(s.nextLine());

		int n = Integer.parseInt(st.nextToken());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());

		int num1 = Math.abs(d-a);
		int num2 = Math.abs(c-b);
		int num3 = Math.abs(d-a+c-b);
		int num4 = Math.abs(d-a-c+b);
		long f = n - (long)Math.max(num1, Math.max(num2, Math.max(num3, num4)));
		long x = 0;
		if(f >= 0) {
			x = n * f;
		}

		System.out.println(x);
	}
}

/**
 *
 * @author meashish
 */
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.Stack;

public class Main {

    InputReader in;
    Printer out;

    long MOD = 1000000007;

    private void start() throws Exception {
        long n = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();
        long c = in.nextLong();
        long d = in.nextLong();

        long res = 0;
        for (int i = 1; i <= n; i++) {
            long sMin1 = i + a + b + 1;
            long sMax1 = i + a + b + n;

            long sMin2 = i + a + c + 1;
            long sMax2 = i + a + c + n;

            long sMin3 = i + d + b + 1;
            long sMax3 = i + d + b + n;

            long sMin4 = i + d + c + 1;
            long sMax4 = i + d + c + n;

            long min = Math.max(sMin1, Math.max(sMin2, Math.max(sMin3, sMin4)));
            long max = Math.min(sMax1, Math.min(sMax2, Math.min(sMax3, sMax4)));

            if (min <= max) {
                res += max - min + 1;
            }
        }

        out.println(res);
    }

    class Bipartite {

        int m, n;
        boolean[][] graph;
        boolean seen[];
        int matchL[];   //What left vertex i is matched to (or -1 if unmatched)
        int matchR[];   //What right vertex j is matched to (or -1 if unmatched)

        public Bipartite(boolean[][] graph) {
            this.graph = graph;
            n = graph.length;
            m = graph[0].length;

            matchL = new int[m];
            matchR = new int[n];
            seen = new boolean[n];
        }

        int maximumMatching() {
            //Read input and populate graph[][]
            //Set m to be the size of L, n to be the size of R
            Arrays.fill(matchL, -1);
            Arrays.fill(matchR, -1);

            int count = 0;
            for (int i = 0; i < m; i++) {
                Arrays.fill(seen, false);
                if (bpm(i)) {
                    count++;
                }
            }
            return count;
        }

        boolean bpm(int u) {
            //try to match with all vertices on right side
            for (int v = 0; v < n; v++) {
                if (!graph[u][v] || seen[v]) {
                    continue;
                }
                seen[v] = true;
                //match u and v, if v is unassigned, or if v's match on the left side can be reassigned to another right vertex
                if (matchR[v] == -1 || bpm(matchR[v])) {
                    matchL[u] = v;
                    matchR[v] = u;
                    return true;
                }
            }
            return false;
        }

    }

    long power(long x, long n) {
        if (n <= 0) {
            return 1;
        }
        long y = power(x, n / 2);

        if ((n & 1) == 1) {
            return (((y * y) % MOD) * x) % MOD;
        }

        return (y * y) % MOD;
    }

    public int gcd(int a, int b) {
        a = Math.abs(a);
        b = Math.abs(b);
        return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
    }

    public Integer[] input(int n) {
        Integer a[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        return a;
    }

    public static void main(String[] args) throws Exception {
        InputReader in;
        PrintStream out;

//        in = new InputReader(new FileInputStream(new File("in.txt")));
//        out = new PrintStream("out.txt");
        in = new InputReader(System.in);
        out = System.out;

        Main main = new Main();

        main.in = in;
        main.out = new Printer(out);
//        main.out.autoFlush = true;

        main.start();
        main.out.flush();
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private static class Printer {

        PrintStream out;
        StringBuilder buffer = new StringBuilder();
        boolean autoFlush;

        public Printer(PrintStream out) {
            this.out = out;
        }

        public Printer(PrintStream out, boolean autoFlush) {
            this.out = out;
            this.autoFlush = autoFlush;
        }

        public void println() {
            buffer.append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void println(int n) {
            println(Integer.toString(n));
        }

        public void println(long n) {
            println(Long.toString(n));
        }

        public void println(double n) {
            println(Double.toString(n));
        }

        public void println(float n) {
            println(Float.toString(n));
        }

        public void println(boolean n) {
            println(Boolean.toString(n));
        }

        public void println(char n) {
            println(Character.toString(n));
        }

        public void println(byte n) {
            println(Byte.toString(n));
        }

        public void println(short n) {
            println(Short.toString(n));
        }

        public void println(Object o) {
            println(o.toString());
        }

        public void println(Object[] o) {
            println(Arrays.deepToString(o));
        }

        public void println(String s) {
            buffer.append(s).append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void print(char s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void print(String s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void flush() {
            try {
                BufferedWriter log = new BufferedWriter(new OutputStreamWriter(out));
                log.write(buffer.toString());

                log.flush();
                buffer = new StringBuilder();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private class Pair<T, U> implements Serializable {

        private T key;

        public T getKey() {
            return key;
        }

        private U value;

        public U getValue() {
            return value;
        }

        public Pair(T key, U value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }

            final Pair other = (Pair) obj;
            if (!this.key.equals(other.key)) {
                return false;
            }

            return this.value.equals(other.value);
        }

        @Override
        public int hashCode() {
            return key.hashCode() + 13 * value.hashCode();
        }
    }

    private class PairSet<T, S> {

        HashMap<T, HashSet<S>> map = new HashMap<>();

        public void add(T a, S b) {
            if (map.containsKey(a)) {
                map.get(a).add(b);
            }

            HashSet<S> set = new HashSet<>();
            set.add(b);
            map.put(a, set);
        }

        public boolean contains(T a, S b) {
            if (map.containsKey(a)) {
                return map.get(a).contains(b);
            }

            return false;
        }
    }

    private class Bit {

        int N;
        long ft1[], ft2[];

        Bit(int n) {
            N = n;
            ft1 = new long[N + 1];
            ft2 = new long[N + 1];
        }

        void update(long ft[], int p, long v) {
            for (; p <= N; p += p & (-p)) {
                ft[p] += v;
//                ft[p] %= MOD;
            }
        }

        void update(int a, int b, long v) {
            update(ft1, a, v);
            update(ft1, b + 1, -v);
            update(ft2, a, v * (a - 1));
            update(ft2, b + 1, -v * b);
        }

        long query(long ft[], int b) {
            long sum = 0;
            for (; b > 0; b -= b & (-b)) {
                sum += ft[b];
//                sum %= MOD;
            }

            return sum;
        }

        long query(int b) {
            return query(ft1, b) * b - query(ft2, b);
        }

        long query(int a, int b) {
            return query(b) - query(a - 1);
        }
    }

    public static Set<Integer[]> getPermutationsRecursive(Integer[] num) {
        if (num == null) {
            return null;
        }

        Set<Integer[]> perms = new HashSet<>();

        //base case
        if (num.length == 0) {
            perms.add(new Integer[0]);
            return perms;
        }

        //shave off first int then get sub perms on remaining ints.
        //...then insert the first into each position of each sub perm..recurse
        int first = num[0];
        Integer[] remainder = Arrays.copyOfRange(num, 1, num.length);
        Set<Integer[]> subPerms = getPermutationsRecursive(remainder);
        for (Integer[] subPerm : subPerms) {
            for (int i = 0; i <= subPerm.length; ++i) { // '<='   IMPORTANT !!!
                Integer[] newPerm = Arrays.copyOf(subPerm, subPerm.length + 1);
                for (int j = newPerm.length - 1; j > i; --j) {
                    newPerm[j] = newPerm[j - 1];
                }
                newPerm[i] = first;
                perms.add(newPerm);
            }
        }

        return perms;
    }
}

import java.io.*;

public class ProblemB {
    StreamTokenizer in;
    PrintWriter out;
    public static void main(String[] args) throws IOException {
        new ProblemB().run();
    }

    void run() throws IOException
    {
        in  = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    private void solve() throws IOException{
        int N = nextInt();
        int A = nextInt();
        int B = nextInt();
        int C = nextInt();
        int D = nextInt();
        int max = Math.max(Math.max(A+B, A+C), Math.max(B+D, C+D));
        int min = Math.min(Math.min(A+B, A+C), Math.min(B+D, C+D));
        long X = max - min + 1;
        if (X > N){
            out.println("0");
        }
        else {
            out.println((N - X + 1)*N);
        }

    }

    int nextInt() throws IOException
    {
        in.nextToken();
        return (int)in.nval;
    }

    String next() throws IOException
    {
        in.nextToken();
        return in.sval;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;

public class B {
    public static void main(String[] args) {
        FastScanner s = new FastScanner();

        long n = s.nextInt();
        int[] in = new int[4];
        int a = s.nextInt();
        int b = s.nextInt();
        int c = s.nextInt();
        int d = s.nextInt();

        int min = Math.min(a+b, b+d);
        min = Math.min(min, c+d);
        min = Math.min(min, a+c);
        int max  = Math.max(a+b, b+d);
        max = Math.max(max, c+d);
        max = Math.max(max, a+c);
        int diff = max - min;
        if (diff >= n) {
            System.out.println(0);
        }
        else
            System.out.println(n*(n - diff));
    }

    static void shuffle(int[] arr) {
        Random rng = new Random();
        int length = arr.length;
        for (int idx = 0; idx < arr.length; idx++) {
            int toSwap = idx + rng.nextInt(length - idx);
            int tmp = arr[idx];
            arr[idx] = arr[toSwap];
            arr[toSwap] = tmp;
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}

import java.util.Scanner;

public class Pinturas {

	public static void main(String[] agrs){

		String x=""; //Input String
		int y=0;
		long max=0,min=999999;
		long[] z=new long[5], w=new long[4];//z=inputs, w=max & minimum

		Scanner scan=new Scanner(System.in);
		x=scan.nextLine();

		for(int i=0;i<x.length();i++){
			if(x.charAt(i)==' '){
				y++;
			}
			else{
				if(z[y]>0)
					z[y]=z[y]*10+x.charAt(i)-'0';
				else
					z[y]+=x.charAt(i)-'0';
			}
		}

		w[0]=z[1]+z[2];
		w[1]=z[1]+z[3];
		w[2]=z[4]+z[2];
		w[3]=z[4]+z[3];

		for(int i=0;i<4;i++){
			if(w[i]>max)
				max=w[i];
			if(w[i]<min)
				min=w[i];
		}
		if((z[0])*(z[0]-(max-min))>0)
			System.out.println((z[0])*(z[0]-(max-min)));
		else
			System.out.println("0");
		scan.close();
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class MainB {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	long start = System.currentTimeMillis();
	long fin = System.currentTimeMillis();
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cnt = 0;
		for (int t1 = 1; t1 <= n; t1++) {
			int[] t = new int[4];
			int t2 = t1 + a + b;
			int t3 = t1 + a + c;
			int t4 = t1 + b + d;
			int t5 = t1 + c + d;
			t[0] = t2;
			t[1] = t3;
			t[2] = t4;
			t[3] = t5;
			int minMax = 0;
			int maxMin = Integer.MAX_VALUE / 10;
			for (int j = 0; j < 4; j++) {
				minMax = Math.max(t[j] + 1, minMax);
				maxMin = Math.min(t[j] + n, maxMin);
			}
			if (minMax <= maxMin) {
				cnt += maxMin - minMax + 1;
			}
		}
		System.out.println(cnt);
	}

	public static void main(String[] args) {
		new MainB().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(char[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (k <= a[i])
	int lower_bound(int a[], int k) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (k <= a[mid])
				r = mid;
			else
				l = mid;
		}
		// r = l + 1
		return r;
	}

	// find minimum i (k < a[i])
	int upper_bound(int a[], int k) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (k < a[mid])
				r = mid;
			else
				l = mid;
		}
		// r = l + 1
		return r;
	}

	long gcd(long a, long b) {
		return a % b == 0 ? b : gcd(b, a % b);
	}

	long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	boolean palindrome(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

		int[] nextIntArray(int n) {
			int[] in = new int[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextInt();
			}
			return in;
		}

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

		long[] nextLongArray(int n) {
			long[] in = new long[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextLong();
			}
			return in;
		}

		char[][] nextCharField(int n, int m) {
			char[][] in = new char[n][m];
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				for (int j = 0; j < m; j++) {
					in[i][j] = s.charAt(j);
				}
			}
			return in;
		}
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;

public class Problem_02 {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner();
        //BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d = input.nextInt();

        long res = 0;
        for (int x = 1; x <= n; x++) {
            int min_s = Math.max(Math.max(Math.max(a + b + x + 1, a + c + x + 1), b + d + x + 1), c + d + x + 1);
            int max_s = Math.min(Math.min(Math.min(a + b + x + n, a + c + x + n), b + d + x + n), c + d + x + n);

            if (min_s <= a+c +x + n && max_s >= a+b+x+1 && min_s <= max_s) {
                res += max_s - min_s +1;
            }
        }
        System.out.println(res);

    }

    static class Scanner {
        final BufferedReader input;
        String[] buffer;
        int pos;

        public Scanner() {
            input = new BufferedReader(new InputStreamReader(System.in));
        }

        private String read() {
            try {
                if (buffer == null || pos >= buffer.length) {
                    buffer = input.readLine().split("\\s+");
                    pos = 0;
                }
                return buffer[pos++];
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

        long nextLong() {
            return Long.parseLong(read());
        }

        int nextInt() {
            return Integer.parseInt(read());
        }

        double nextDouble() {
            return Double.parseDouble(read());
        }

        String nextLine() {
            if (buffer != null && pos < buffer.length) {
                throw new RuntimeException("Buffer is not empty");
            }
            try {
                return input.readLine();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }

}

import java.util.Scanner;

/**
 *
 * @author mbp
 */
public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input =new Scanner(System.in);
        int n;
        int a , b , c ,d;
        n=input.nextInt();
        a=input.nextInt();
        b=input.nextInt();
        c=input.nextInt();
        d=input.nextInt();
        long result=0;
        int val1,val2,val3;
        for(int i=1;i<=n;++i){
            val1=i+a-d;
            val2=i+b-c;
            val3=i+a+b-c-d;
            if(val1>0&&val2>0&&val3>0){
                if(val1<=n&&val2<=n&&val3<=n){
                if(Math.ceil(val1)==val1 &&Math.ceil(val2)==val2&&Math.ceil(val3)==val3){
                    result++;

        }
            }
            }
        }
        System.out.println(result*n);

    }

}

import java.io.*;

import java.util.*;

public class Main {

	public static int mod = 1000000007;

	public static void main(String[] args)throws IOException {

OutputWriter out=new OutputWriter(System.out);
  Reader r=new Reader();
 BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

int n=r.nextInt();
	int a=r.nextInt();
	int b=r.nextInt();
	int c=r.nextInt();
	int d=r.nextInt();

int a1=a+b;
int a2=a+c;
int a3=b+d;
int a4=c+d;

int greatest =Math.max(a1,Math.max(a2,Math.max(a3,a4)));

int smallest =Math.min(a1,Math.min(a2,Math.min(a3,a4)));
//System.out.println(greatest+" "+smallest);
long cc=0;
for(int i=1;i<=n;i++)
{
  if((greatest+i)-smallest<=n) cc++;

}
	System.out.println(cc*n);
}
}

class Reader {
    final private int BUFFER_SIZE = 1 << 16;private DataInputStream din;private byte[] buffer;private int bufferPointer, bytesRead;
    public Reader(){din=new DataInputStream(System.in);buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0;
    }public Reader(String file_name) throws IOException{din=new DataInputStream(new FileInputStream(file_name));buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0;
    }public String readLine() throws IOException{byte[] buf=new byte[64];int cnt=0,c;while((c=read())!=-1){if(c=='\n')break;buf[cnt++]=(byte)c;}return new String(buf,0,cnt);
    }public int nextInt() throws IOException{int ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;
    }public long nextLong() throws IOException{long ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;
    }public double nextDouble() throws IOException{double ret=0,div=1;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c = read();do {ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(c=='.')while((c=read())>='0'&&c<='9')ret+=(c-'0')/(div*=10);if(neg)return -ret;return ret;
    }private void fillBuffer() throws IOException{bytesRead=din.read(buffer,bufferPointer=0,BUFFER_SIZE);if(bytesRead==-1)buffer[0]=-1;
    }private byte read() throws IOException{if(bufferPointer==bytesRead)fillBuffer();return buffer[bufferPointer++];
    }public void close() throws IOException{if(din==null) return;din.close();}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

import java.util.HashMap;
import java.util.Scanner;
import java.math.*;
import java.awt.*;
import java.util.*;
public class Main{
	private static HashMap<String,Integer> q=new HashMap<String,Integer>() ;
	public static void main(String args[])
	{
		Scanner cin=new Scanner(System.in);
		q.clear();
		int n,a,b,c,d;
		n=cin.nextInt();
		a=cin.nextInt();
		b=cin.nextInt();
		c=cin.nextInt();
		d=cin.nextInt();
		long ans=0;
		for(int x1=1;x1<=n;x1++)
        {
            int x2=x1+b-c;
            int x5=x2+a-d;
            int x4=x5+c-b;
            if(x2>=1&&x5>=1&&x4>=1&&check(a,b,c,d,x1,x2,x4,x5)==1&&x2<=n&&x5<=n&&x4<=n)
            {
                ans++;
            }
        }
		System.out.println(ans*n);
	}
	public static int check(int a,int b,int c,int d,int x1,int x2,int x4,int x5)
	{

		int x[]=new int[10];
		x[0]=a;
	    x[1]=b;
	    x[2]=c;
	    x[3]=d;
	    x[4]=x1;
	    x[5]=x2;
	    x[6]=x4;
	    x[7]=x5;
	    Arrays.sort(x, 0, 7);
	    String y=(x[0]+"")+(x[1]+"")+(x[2]+"")+(x[3]+"")+(x[4]+"")+(x[5]+"")+(x[6]+"")+(x[7]+"");
	    int ok=0;
	    for(String s:q.keySet())
	    {
	    	if(s.equals(y))
	    	{
	    		ok=1;
	    		return 0;
	    	}
	    }
	    return 1;
	}
}

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        int w, x, y, z;
        long sum = 0;
        w = 1;
        x = w + b - c;
        y = x + a - d;
        z = y + c - b;
        int min = Math.min(x, Math.min(y, Math.min(w, z)));
        w = n;
        x = w + b - c;
        y = x + a - d;
        z = y + c - b;
        int max = Math.max(x, Math.max(y, Math.max(w, z)));
        sum += n - Math.max(max - n, 0) - Math.max(1 - min, 0);
        System.out.println(Math.max(sum, 0) * n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n) {
            int array[] = nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public int[] nextSumIntArray(int n) {
            int[] array = new int[n];
            array[0] = nextInt();
            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; ++i) array[i] = nextLong();
            return array;
        }

        public long[] nextSumLongArray(int n) {
            long[] array = new long[n];
            array[0] = nextInt();
            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
            return array;
        }

        public long[] nextSortedLongArray(int n) {
            long array[] = nextLongArray(n);
            Arrays.sort(array);
            return array;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class RestoringPainting {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            while(testNumber-->0){
            	int n = in.nextInt();
            	int a = in.nextInt();
            	int b = in.nextInt();
            	int c = in.nextInt();
            	int d = in.nextInt();
            	long ans = 0;
            	for(int j=1;j<=n;j++){
            		int e = j;
            		int f = e+b-c;
            		int h = e+a-d;
            		int i = h+b-c;
            		if(i == f+a-d && f>0 && f<=n && h>0 && h<=n && i>0 && i<=n)
            			ans++;
            	}
            	out.println(n*ans);
            }
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
	        if (start > end) {
	            return;
	        }
	  		int mid = (start + end) / 2;
	        a.add(mid);
	        sortedArrayToBST(a, start, mid - 1);
	  		sortedArrayToBST(a, mid + 1, end);
	    }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(a%b==0)
                return b;
            return gcd(b , a%b);
        }
        public void print2d(int a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            long n = in.nextInt();
            long a = in.nextInt();
            long b = in.nextInt();
            long c = in.nextInt();
            long d = in.nextInt();

            long count = 0;
            for (long x1 = 1; x1 <= n; x1++)
            {
                long x2 = x1 + b - c;
                long x5 = x2 + a - d;
                long x4 = x5 - b + c;
                boolean b1 = x2 >= 1 && x2 <= n;
                boolean b2 = x5 >= 1 && x5 <= n;
                boolean b3 = x4 >= 1 && x4 <= n;
                if (b1 && b2 && b3)
                {
                    //System.out.println("x = " + x + " X = " + X);
                    count++;
                }
            }
            out.println(count * n);
        }

    }

    static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}

import java.util.Scanner;

/**
 * Created by dhreeraj on 4/2/16.
 */
public class ChefBalloons {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int x1,x3,x4;
        int count=0;
        if(b==c & a!=d){
            for(int  i=1;i<=n;i++){
                if((d-a+i)<=n && (d-a+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        }else if(a==d && b!=c){
            for(int  i=1;i<=n;i++){
                if((b-c+i)<=n && (b-c+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        } else{
            if(a==b && b==c && c==d){
                System.out.println(n*n);
            }
            else{
                for(int i=1;i<=n;i++){
                    x1=d-a+i;
                    x4=b-c+i;
                    x3=x1+b-c;
                    if((x1<=n && x1>=1) && (x3<=n && x3>=1) && (x4<=n && x4>=1)){
                        count++;
                    }
                }
                System.out.println(n*count);
            }
        }

    }
}

import java.util.Scanner;

public class D_20181223 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int y1 = 0;
		int y2 = 0;
		int y3 = 0;
		int y4 = 0;
		long s = 0;
		for (int i = 1; i < n+1; i++) {
            y1 = i;
            y2 = y1 + b - c;
            y3 = y1 + a - d;
            y4 = y3 + b - c;
            if (y2>0&&y3>0&&y4>0&&y2<n+1&&y3<n+1&&y4<n+1) s++;

		}
		System.out.println(s*n);

	}

}

import java.util.Scanner;

/**
 * http://codeforces.com/contest/675/problem/B?locale=en
 */
public class B {

	public static void main(String[] args) {
		new B().doJob();
	}

	private void doJob() {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			int d = scanner.nextInt();
			int d1 = a + b + 2;
			int d2 = b + d + 2;
			int d3 = d + c + 2;
			int d4 = c + a + 2;

			int max = Math.max(d1, Math.max(d2, Math.max(d3, d4)));
			int min = Math.min(d1, Math.min(d2, Math.min(d3, d4)));
			int maxNumber = 1 + max - min;
			if (maxNumber > n) {
				System.out.println(0);
				return;
			}
			System.out.println((long) n * (n + 1 - maxNumber));

		}

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class R353B {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int n = s.nextInt(), a = s.nextInt(), b = s.nextInt(), c = s.nextInt(), d = s.nextInt();
		int ab = a+b, ac = a+c, cd = c+d, db = d+b;
		long ans = 0;
//		System.out.printf("%d %d %d %d\n", ab, ac, cd, db);
		for(int i = 1; i <= n; i++) {
			int topLeft = ab+i, topRight = ac+i, bottomLeft = db+i, bottomRight = cd+i;
			int maxDif = Integer.MIN_VALUE;
			maxDif = Math.max(maxDif, Math.abs(topLeft-topRight)); maxDif = Math.max(maxDif, Math.abs(topRight-bottomLeft));
			maxDif = Math.max(maxDif, Math.abs(bottomLeft-bottomRight)); maxDif = Math.max(maxDif, Math.abs(bottomRight-topLeft));
			ans += Math.max(0, n-maxDif);
		}
		System.out.println(ans);
	}
}

import java.io.*;
import java.util.*;
public class test
{
	public static void main(String[] args)throws IOException {
		new test().run();
	}
	void run() throws IOException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int cnt=0;
		for(int y1=1;y1<=n;y1++){
			int y2=y1+b-c;
			int y3=y1+a-d;
			int y4=y1+a+b-c-d;
			if(y2>=1 && y2<=n && y3<=n && y3>=1 && y4>=1 && y4<=n)
				cnt++;
		}
		System.out.println(cnt*1L*n);
	}
}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);

    public void solve() {
        int n = in.ni(), a = in.ni(), b = in.ni(), c = in.ni(), d = in.ni();
        long result = 0;
        for (int x = 1; x <= n; x++) {
            int y = x + b - c;
            int z = x + a - d;
            int w = a + y - d;
            if (1 <= y && y <= n && 1 <= z && z <= n && 1 <= w && w <= n) {
                result++;
            }
        }
        out.println(n * result);
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) {
        new B().solve();
    }
}

import java.io.*;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.net.ssl.SSLContext;

public class Main
{
   static long mod=(long)(998244353);
   static int[] sieve;
   static ArrayList<Integer> primes;

   public static void main(String[] args) throws java.lang.Exception
   {
	     fast s = new fast();
	     PrintWriter out=new PrintWriter(System.out);
	     Scanner sc=new Scanner(System.in);
	     StringBuilder fans = new StringBuilder();

	     long n=s.nextLong();
	     long a=s.nextLong();
	     long b=s.nextLong();
	     long c=s.nextLong();
	     long d=s.nextLong();

	     long low=Math.max(1+c-b, Math.max(1+d-a, Math.max(1,1+d+c-a-b)));
	     long high=Math.min(n+c-b, Math.min(n+d-a, Math.min(n,n+c+d-a-b)));

	     if(low>high) System.out.println("0");
	     else System.out.println((high-low+1)*n);

   }

static class fast {
	private InputStream i;
		private byte[]  buf = new byte[1024];
		private int curChar;
		private int numChars;

		//Return floor log2n
		public static int log2(int bits) // returns 0 for bits=0
			{
			    int log = 0;
			    if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }
			    if( bits >= 256 ) { bits >>>= 8; log += 8; }
			    if( bits >= 16  ) { bits >>>= 4; log += 4; }
			    if( bits >= 4   ) { bits >>>= 2; log += 2; }
			    return log + ( bits >>> 1 );
			}

		public static boolean next_permutation(int a[])
		   {
			   int i=0,j=0;int index=-1;
			   int n=a.length;

			   for(i=0;i<n-1;i++)
				   if(a[i]<a[i+1]) index=i;

			   if(index==-1) return false;
			   i=index;

			   for(j=i+1;j<n && a[i]<a[j];j++);

			   int temp=a[i];
			   a[i]=a[j-1];
			   a[j-1]=temp;

			   for(int p=i+1,q=n-1;p<q;p++,q--)
			   {
				   temp=a[p];
				   a[p]=a[q];
				   a[q]=temp;
			   }

			   return true;
		   }

		public static void division(char ch[],int divisor)
		   {
			   int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0;
			   StringBuilder quotient=new StringBuilder("");
			   for(int i=1;i<ch.length;i++)
			   {
				   div=div*mul+Character.getNumericValue(ch[i]);
				   if(div<divisor) {quotient.append("0");continue;}
				   quotient.append(div/divisor);
				   div=div%divisor;mul=10;

			   }
			   remainder=div;
			   while(quotient.charAt(0)=='0')quotient.deleteCharAt(0);
			   System.out.println(quotient+" "+remainder);
		   }

		public static void sieve(int size)
		{
			sieve=new int[size+1];

			primes=new ArrayList<Integer>();

			sieve[1]=1;

			for(int i=2;i<=Math.sqrt(size);i++)
			{
				if(sieve[i]==0)
				 {
					for(int j=i*i;j<size;j+=i) {sieve[j]=1;}
				 }
			}

			for(int i=2;i<=size;i++)
			{
				if(sieve[i]==0) primes.add(i);
			}
		}

		public static long pow(long n, long b, long MOD)
		   {
		       long x=1;long y=n;
		       while(b > 0)
		       {
		           if(b%2 == 1)
		           {
		               x=x*y;
		               if(x>MOD) x=x%(MOD);
		           }
		           y = y*y;
		           if(y>MOD) y=y%(MOD);
		           b >>= 1;
		       }
		       return x;
		   }

		public static long mod_inv(long n,long mod)
		{
			return pow(n,mod-2,mod);
		}

		 public static int upper(Integer[] a,int start,int end,int key)
		 {
			   int mid=(start+end)>>1;
			   if(start==end && a[mid]<key) {return -1;}
			   if(start>end) return -1;

			   if(a[mid]>=key && (((mid-1)>=0 && a[mid-1]<key) || (mid-1)==0)) return mid;
			   else if(a[mid]== key && (mid-1)>=0 && a[mid-1]==key) return upper(a,start,mid-1,key);
			   else if(key>a[mid]) return upper(a,mid+1,end,key);
			   else return upper(a,start,mid-1,key);
		}

		 public static int lower(int[] a,int start,int end,int key)
		 {
			   int mid=(start+end)>>1;
			   if(start==end && a[mid]>key) {return -1;}
			   if(start>end) return -1;

			   if(a[mid]<=key && (((mid+1)<a.length && a[mid+1]>key) || (mid+1)==a.length)) return mid;
			   else if(a[mid]== key && (mid+1)<a.length && a[mid+1]==key) return lower(a,mid+1,end,key);
			   else if(key>=a[mid]) return lower(a,mid+1,end,key);
			   else return lower(a,start,mid-1,key);
		}

		public long gcd(long r,long ans)
		{
			if(r==0) return ans;
			return gcd(ans%r,r);
		}
		public fast() {
			this(System.in);
		}
		public fast(InputStream is) {
			i = is;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = i.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		public String nextString() {
     		int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
}

import java.util.Arrays;
import java.util.Scanner;

public class RestoringPainting {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextInt();
		long a = scan.nextInt();
		long b = scan.nextInt();
		long c = scan.nextInt();
		long d = scan.nextInt();
		long[] l = new long[3];
		l[0] = 1 - b + c;
		l[1] = 1 - a + d;
		l[2] = 1 + c + d - b - a;
		long[] m = new long[3];
		m[0] = n + c - b;
		m[1] = n + d - a;
		m[2] = n + c + d - b - a;

		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 2; j++) {
				if (l[j] > l[j + 1]) {
					long temp = l[j];
					l[j] = l[j + 1];
					l[j + 1] = temp;
				}
				if (m[j] > m[j + 1]) {
					long temp = m[j];
					m[j] = m[j + 1];
					m[j + 1] = temp;
				}

			}

		long min = n - m[0];
		long max = l[2] - 1;
		if (m[0] > n - 1)
			min = 0;
		if (l[2] <= 1)
			max = 0;
		if(n * n - (min + max) * n>=0)
			System.out.println(n * n - (min + max) * n);
		else
			System.out.println(0);
	}
}

//package myPackage;

import java.util.*;
import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long m = (n - Math.abs(a - d)) + (n - Math.abs(b - c)) - n;
		if(m < 0) m = 0;
		out.println(m * n);
	}
}

import java.util.Scanner;

/**
 * Created by zaremba on 17.05.16.
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
        long result = 0;
        long sum;

        for(int i = 1; i <= n; i++) {
            sum = a + b + i;
            long sum2 = sum - a - c;
            long sum3 = sum - b - d;
            long sum4 = sum - c - d;
            if(sum2 > 0 && sum2 <= n && sum3 > 0 && sum3 <= n && sum4 > 0 && sum4 <= n)
                result++;
        }

        System.out.println(result * n);

    }
}

import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        int a, b, c, d, n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        long res = 0;
        for (int i = a + b + 1; i <= a + b + n; ++i) {
            if (i - c - d > 0 && i - c - d <= n && i - b - d > 0 && i - b - d <= n && i - a - c > 0 && i - a - c <= n) {
                res++;
            }
        }
        System.out.println(res * n);
    }
}

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        int answer = 0;
        for (int x = 1; x <= n; ++ x) {
            int q = x;
            q = b + q - c;
            if (q < 1 || q > n) continue;
            q = a + q - d;
            if (q < 1 || q > n) continue;
            q = c + q - b;
            if (q < 1 || q > n) continue;
            q = q + d - a;
            if (q != x) continue;
            answer ++;
        }
        System.out.println(answer * 1l * n);
    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class ProblemB {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        long n = input.nextInt();
        long a = input.nextInt();
        long b = input.nextInt();
        long c = input.nextInt();
        long d = input.nextInt();
        long ab = a + b;
        long cd = c + d;
        long bd = b + d;
        long ac = a + c;
        ArrayList<Long> sum = new ArrayList<Long>();
        sum.add(ab);
        sum.add(bd);
        sum.add(cd);
        sum.add(ac);
        Collections.sort(sum);
        long range = sum.get(3)-sum.get(0);
        if(range > n-1){
            System.out.println(0);
        }
        else{
            System.out.println((n-range)*n);
        }
    }

}

import java.util.Scanner;

public class RestoringPainting {

	static boolean range(long x, long n) {
		if(x>=1 && x<=n)
			return true;
		return false;
	}
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long a =  sc.nextInt();
		long b =  sc.nextInt();
		long c =  sc.nextInt();
		long d =  sc.nextInt();

		long m = 0;
		for (int x1=1; x1<=n; ++x1) {
			long x3 = x1+b-c;
			long x7 = x1+a-d;
			long x9 = x1+a+b-c-d;

			if(range(x3, n) && range(x7, n) && range(x9, n))
				m++;
		}
		System.out.println(n*m);

	}
}

import java.util.*;
import java.io.*;

public class CodeForces {

    public static void main(String args[]) throws IOException {
        Reader.init(System.in);
        PrintWriter write = new PrintWriter(System.out);

        int n =  Reader.nextInt(), min = (int)1e9, max = -1, arr[] = new int[4];
        for (int i = 0; i < 4; i++) {
            int val = Reader.nextInt();

            if(i == 0){
                arr[0] += val;
                arr[1] += val;
            }

            if(i == 1){
                arr[0] += val;
                arr[2] += val;
            }
            if(i == 2){
                arr[1] += val;
                arr[3] += val;
            }

            if(i == 3){
                arr[2] += val;
                arr[3] += val;
            }
        }

        for (int i = 0; i < 4; i++) {
            min = Math.min(min, arr[i]);
            max = Math.max(max, arr[i]);
        }
        long ans = 1l * (n - (max-min)) * n;
        System.out.println(ans > 0 ? ans : 0);
        write.close();
    }

}

class Pair {

    int x, y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        Pair p = (Pair) o;
        return (p.x == x && p.y == y) || (p.x == y || p.y == x);
    }

    @Override
    public int hashCode() {

        return ((x + 1) * (y + 1)) % ((int) 1e7 + 7);
    }

}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class B {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	long n=sc.nextLong();
	long a=sc.nextLong();
	long b=sc.nextLong();
	long c=sc.nextLong();
	long d=sc.nextLong();
	long x=1,y=0,z=0,l=0,k=1;
	if(b-c+1>0){
		y=b-c+1;
	}else{
		y=1;x=(c-b+1);
	}
//	System.out.println(x+" "+y);
	l=a-d+x;
	if(l<=0){
		x=x-l;x++;
		y=y-l;y++;
		l=l-l;l++;
	}
	k=b-c+l;
	if(k<=0){
		x=x-k;x++;
		y=y-k;y++;
		l=l-k;l++;
		k=k-k;k++;
	}
	long []q=new long[4];
	q[0]=x;
	q[1]=y;
	q[2]=l;
	q[3]=k;
//	for (int i = 0; i < q.length; i++) {
//		System.out.print(q[i]+" ");
//	}System.out.println();
	Arrays.sort(q);
	if((n-q[3])<0){
		System.out.println("0");
	}else{
//		for (int i = 0; i < q.length; i++) {
//			System.out.print(q[i]+" ");
//		}System.out.println();
		System.out.println(((n-q[3])+1)*n);
	}

}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

//		String[] split = br.readLine().split(" ");
		StringTokenizer tk = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(tk.nextToken());
		int a = Integer.parseInt(tk.nextToken()),b = Integer.parseInt(tk.nextToken());;
		int c = Integer.parseInt(tk.nextToken()), d = Integer.parseInt(tk.nextToken());;

		long ans = 0;
		for(int i = 1; i <= n; i++) {
			int topLeft = a+b+i, topRight = a+c+i, bottomRight = c+d+i, bottomLeft = b+d+i;
			int maxDiff = 0;
			maxDiff = Math.max(maxDiff, Math.abs(topLeft-topRight));
			maxDiff = Math.max(maxDiff, Math.abs(topRight-bottomRight));
			maxDiff = Math.max(maxDiff, Math.abs(topRight-bottomLeft));
			maxDiff = Math.max(maxDiff, Math.abs(bottomRight-bottomLeft));
			maxDiff = Math.max(maxDiff, Math.abs(bottomLeft-topLeft));
			maxDiff = Math.max(maxDiff, Math.abs(topLeft-bottomRight));
			ans += Math.max(0, n-maxDiff);
		}
		out.println(ans);
		out.close();
	}
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Tester {
	public static void main(String args[])
	{
		//Map<Integer, Integer> hm=new HashMap<>();
		Scanner sc=new Scanner(System.in);
			int i,j,k,l=1,r,m=1,n,o,p,a,b,c,d,x,t,h,count=0,max=Integer.MAX_VALUE,sum=0,index=0,temp;
			BigInteger bi1=BigInteger.ZERO, bi2=BigInteger.ONE;
			n=sc.nextInt();
			a=sc.nextInt();
			b=sc.nextInt();
			c=sc.nextInt();
			d=sc.nextInt();
			for(x=1;x<=n;x++)
			{
				int y=x+b-c;
				int z=x+a-d;
				int w=z+b-c;
				if((y>=1&&y<=n)&&(z>=1&&z<=n)&&(w>=1&&w<=n))
				{
					count++;
				}
			}
			bi2=bi2.multiply(BigInteger.valueOf(count));
			bi2=bi2.multiply(BigInteger.valueOf(n));
			System.out.println(bi2);
	}
}

//Comment out before submit
//package Round353Div2.ProblemB;

/**
 * Created by evergreen on 5/16/16.
 */

/*
ID: najmul.1
LANG: JAVA
TASK: RestoringPainting
*/

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class RestoringPainting {

    private static MyScanner input;
    private static PrintWriter output;

    private static void solve() {

        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d = input.nextInt();

        int x = c - b;
        int y = d - a;
        int z = c + d - a - b;

        int count = 0;

        for (int e = 1; e <= n; e++) {

            int f = e - x;
            int g = e - y;
            int h = e - z;

            //if(e+b != f+c) continue;
            //if(e+a != g+d) continue;
            //if(a+e+b != d+c+h) continue;

            if(isaBoolean(n, f) && isaBoolean(n, g) && isaBoolean(n, h)) {

                ++count;
            }
        }

        BigInteger bigInteger = new BigInteger(String.valueOf(count));
        BigInteger bigInteger1 = new BigInteger(String.valueOf(n));
        BigInteger aaa = bigInteger.multiply(bigInteger1);

        output.println(aaa);
        output.flush();
    }

    private static boolean isaBoolean(int n, int f) {
        return f >= 1 && f <= n;
    }

    public static void main(String[] args) throws FileNotFoundException {

        input = SmartInOut.getInitInput();
        output = SmartInOut.getInitOutput();

        solve();

        output.close();
    }
}

class SmartInOut {

    private static MyScanner input;
    private static PrintWriter output;

    private static String getFilePathPrefix() {

        String filePathPrefix = "";

        Class<? extends RestoringPainting> aClass = new RestoringPainting().getClass();
        Package aPackage = aClass.getPackage();

        if (aPackage != null) {
            String packageName = aPackage.getName();
            String partialPath = packageName.replace(".", "/");
            filePathPrefix = "src/" + partialPath + "/";
        }

        return filePathPrefix;
    }

    public static MyScanner getInitInput() throws FileNotFoundException {

        String filePath = getFilePathPrefix() + "RestoringPainting.in";
        File f = new File(filePath);
        input = f.exists() && !f.isDirectory() ? new MyScanner(filePath) : new MyScanner();
        return input;
    }

    public static PrintWriter getInitOutput() throws FileNotFoundException {

        String filePathPrefix = getFilePathPrefix();
        File f = new File(filePathPrefix + "RestoringPainting.in");
        String outputFilePath = filePathPrefix + "RestoringPainting.out";

        output = f.exists() && !f.isDirectory() ? new PrintWriter(outputFilePath) : new PrintWriter(System.out);
        return output;
    }
}

class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public MyScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    public List<String> readLineAsStringList() throws IOException {

        //Modify it if you need a different delimiter
        String delimiter = " ";
        String st = br.readLine();
        List<String> list = Arrays.asList(st.split(delimiter));
        return list;
    }

    public List<String> readStringList(int howMany) {

        List<String> list = new ArrayList<String>();
        while (howMany-- > 0) {

            String st = nextToken();
            list.add(st);
        }
        return list;
    }

    public List<Integer> readIntegerList(int howMany) {

        List<Integer> list = new ArrayList<Integer>();
        while (howMany-- > 0) {

            int st = nextInt();
            list.add(st);
        }
        return list;
    }

    public List<Double> readDoubleList(int howMany) {

        List<Double> list = new ArrayList<Double>();
        while (howMany-- > 0) {

            double st = nextDouble();
            list.add(st);
        }
        return list;
    }
}

class BasicUtility {

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItems(List<T> list) {

        String delimiter = " ";
        String formattedJoin = BasicUtility.joinItemsWithDelimiter(delimiter, list);

        return formattedJoin;
    }

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItemsWithDelimiter(String delimiter, List<T> list) {

        String formattedJoin = "";
        int count = list.size();
        for (int i = 0; i < count - 1; ++i) {

            //Join all elements except last element
            formattedJoin += (list.get(i) + delimiter);
        }

        if (count > 1) {
            //Now join last element
            formattedJoin += list.get(count - 1);
        }

        //For Java 8
        //String formattedJoin = list.stream().map(i -> i.toString()).collect(Collectors.joining(delimiter));

        return formattedJoin;
    }

    public static <T> List<T> getCopyList(List<T> list) {

        List<T> copiedList = new ArrayList<T>(list);
        //For Java 8
        //List<T> copiedList = list.stream().collect(Collectors.toList());
        return copiedList;
    }
}

import java.util.Scanner;

public class Train {
	private static Scanner cin = new Scanner(System.in);
	public static void main(String[] args){
		int a,b,c,d,n;
		long res = 0;
		n = cin.nextInt();
		a = cin.nextInt();
		b = cin.nextInt();
		c = cin.nextInt();
		d = cin.nextInt();
		int p, q;
		if(a > d) p = a - d;
		else p = d - a;
		if(b > c) q = b - c;
		else q = c - b;
		res = n - p - q;
		if (res < 0) res = 0;
		res = res * n;
		System.out.println(res);
	}

}

import java.io.*;
import java.util.Arrays;
public class restoringPainting {

	public static void main(String[]args) throws IOException{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		String [] line = br.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int a = Integer.parseInt(line[1]);
		int b = Integer.parseInt(line[2]);
		int c = Integer.parseInt(line[3]);
		int d = Integer.parseInt(line[4]);

		long count = 0;

		for(int j =1; j <=n ;j++){
			int k = j+b-c;
			int l = j+a-d;
			int m = a+b+j-c-d;
			if(k>0 && l>0 && m>0 &&k<=n&&l<=n&&m<=n){
				count++;

			}
		}
		System.out.println(count*n);
	}
}

import java.io.*;
import java.util.StringTokenizer;

public class B {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = in(), a = in(), b = in(), c = in(), d = in();
        long r = 0;
        for (int x1 = 1; x1 <= n; x1++) {
            int k = x1 + a + b, x2 = k - a - c, x3 = k - b - d, x4 = k - c - d;
            if (x2 > 0 && x3 > 0 && x4 > 0 && x2 <= n && x3 <= n && x4 <= n)
                r += n;
        }
        out.println(r);
        out.flush();
    }

    public static int in() throws IOException {
        return Integer.parseInt(next());
    }

    public static long inl() throws IOException {
        return Long.parseLong(next());
    }

    public static double ind() throws IOException {
        return Double.parseDouble(next());
    }

    public static String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public static boolean nextPerm(int[] a) {
        int j = a.length - 1, k = j, r = j;
        for (; j > 0; j--)
            if (a[j - 1] < a[j]) break;
        if (j == 0) return false;
        for (; k > j; k--)
            if (a[j - 1] < a[k]) break;
        swap(a, j - 1, k);
        while (j < r) swap(a, j++, r--);
        return true;
    }

    public static void swap(int[] a, int i, int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(char[] a, int i, int j) {
        char t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(long[] a, int i, int j) {
        long t = a[i];
        a[i] = a[j];
        a[j] = t;
    }
}

import java.util.*;
public class cf675B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
long d=sc.nextLong();
long diff1=b-c,diff2=a-d,diff3=a-c+b-d;long ways=0;
long min=(long)Math.min(diff1,(long)Math.min(diff2,diff3));
long max=(long)Math.max(diff1,(long)Math.max(diff2,diff3));
if(max<0)
max=0;
if(min>=0)
min=0;
if(max>=n || min<=(-n))
System.out.println(0);
else
{
{if((1-min)>(n-max))
ways=0;
else
ways=n*(n-max+min);}
System.out.println(ways);}
sc.close();

}
}

import java.util.Scanner;

public class Q675B_RestoringPainting {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int x1_min = max(1, 1 + c - b, 1 + c + d - b - a, 1 + d - a);
        int x1_max = min(n, n + c - b, n + c + d - b - a, n + d - a);
        if (x1_min > x1_max)
            System.out.println(0);
        else {
            long x1 = x1_max - x1_min + 1;
            System.out.println(x1 * n);
        }

    }

    public static int max(int... as) {
        int max = as[0];
        for (int a : as) {
            if (a > max)
                max = a;
        }
        return max;
    }

    public static int min(int... as) {
        int min = as[0];
        for (int a : as) {
            if (a < min)
                min = a;
        }
        return min;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

//		String[] split = br.readLine().split(" ");
		StringTokenizer tk = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(tk.nextToken());
		int a = Integer.parseInt(tk.nextToken()),b = Integer.parseInt(tk.nextToken());;
		int c = Integer.parseInt(tk.nextToken()), d = Integer.parseInt(tk.nextToken());;

		long ans = 0;
			int topLeft = a+b, topRight = a+c, bottomRight = c+d, bottomLeft = b+d;
			int maxDiff = 0;
			maxDiff = Math.max(maxDiff, Math.abs(topLeft-topRight));
			maxDiff = Math.max(maxDiff, Math.abs(topRight-bottomRight));
			maxDiff = Math.max(maxDiff, Math.abs(topRight-bottomLeft));
			maxDiff = Math.max(maxDiff, Math.abs(bottomRight-bottomLeft));
			maxDiff = Math.max(maxDiff, Math.abs(bottomLeft-topLeft));
			maxDiff = Math.max(maxDiff, Math.abs(topLeft-bottomRight));
			ans += Math.max(0, n-maxDiff);
		out.println(ans*n);
		out.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Sport{
    public static void main(String[] args) throws IOException{
        BufferedReader vod=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer s=new StringTokenizer(vod.readLine());
        int n=Integer.parseInt(s.nextToken());
        int a=Integer.parseInt(s.nextToken());
        int b=Integer.parseInt(s.nextToken());
        int c=Integer.parseInt(s.nextToken());
        int d=Integer.parseInt(s.nextToken());
        int y=0;
        for (int i=1; i<=n; i++){
            if ((b+i-c>0&b+i-c<=n)&(a+i-d>0&a+i-d<=n)&(a+b+i-c-d>0&a+b+i-c-d<=n))
                y++;
        }
        long ans=0;
        ans=(long)y*n;
        System.out.print(ans);
    }
}

//package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class OK_GOOGLE {
	private static StringTokenizer st;
	private static BufferedReader in;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
	in = new BufferedReader(new InputStreamReader(System.in));
	pw = new PrintWriter(new OutputStreamWriter(System.out));

	long n = nextLong(), a = nextLong(), b = nextLong(), c = nextLong(), d = nextLong();
	long sum = 0, sum1 = 0, x = 0, y = 0, z = 0;
	for (long i = 1; i <= n; i++) {
		sum = a + b + i;
		x = sum - (a + c);
		y = sum - (b + d);
		z = sum - (c + d);
		if(x > 0 && x <= n && y > 0 && y <= n && z > 0 && z <= n){
			sum1 += n;
		}
	}
	pw.print(sum1);
	in.close();
	pw.close();
	}

	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

}

import java.util.Arrays;
import java.util.Scanner;

public class RestoringPainting {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextInt();
		long a = scan.nextInt();
		long b = scan.nextInt();
		long c = scan.nextInt();
		long d = scan.nextInt();
		long[] l = new long[3];
		l[0] = 1 - b + c;
		l[1] = 1 - a + d;
		l[2] = 1 + c + d - b - a;
		long[] m = new long[3];
		m[0] = n + c - b;
		m[1] = n + d - a;
		m[2] = n + c + d - b - a;

		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 2; j++) {
				if (l[j] > l[j + 1]) {
					long temp = l[j];
					l[j] = l[j + 1];
					l[j + 1] = temp;
				}
				if (m[j] > m[j + 1]) {
					long temp = m[j];
					m[j] = m[j + 1];
					m[j + 1] = temp;
				}

			}

		long min = n - m[0];
		long max = l[2] - 1;
		if (m[0] > n - 1)
			min = 0;
		if (l[2] <= 1)
			max = 0;
		if(n * n - (min + max) * n>=0)
			System.out.println(n * n - (min + max) * n);
		else
			System.out.println(0);
	}
}

import java.util.Scanner;

public class D_20181223 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int y1 = 0;
		int y2 = 0;
		int y3 = 0;
		int y4 = 0;
		long s = 0;
		for (int i = 1; i < n+1; i++) {
            y1 = i;
            y2 = y1 + b - c;
            y3 = y1 + a - d;
            y4 = y3 + b - c;
            if (y2>0&&y3>0&&y4>0&&y2<n+1&&y3<n+1&&y4<n+1) s++;

		}
		System.out.println(s*n);

	}

}

import java.io.*;
import java.util.*;

public class B353 {

    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        long n, a, b, c, d;
        n = IO.nextLong();
        a = IO.nextLong();
        b = IO.nextLong();
        c = IO.nextLong();
        d = IO.nextLong();

        long ab = a+b;
        long cd = c+d;
        long ans=1;
        long diff = Math.abs(ab-cd);

        long add = diff+1;
        if(add>n){
            IO.println(0);return;
        }
        long rem = n-(add-1);
        ans = n*rem;

        long ac = a+c;
        long bd = b+d;
        long diff2 = Math.abs(ac-bd);
        add = diff2+1;
        if(add>n){
            IO.println(0);return;
        }
        rem = n-(add-1);
        long ans2 = n*rem;
//        IO.println("ans = "+ans+" ans2 = "+ans2);
        ans = Math.min(ans, ans2);
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt( next() );
        }
        static long nextLong() throws IOException {
            return Long.parseLong( next() );
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble( next() );
        }

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}

import java.util.*;
import java.io.*;

public class B675
{

	public static void main(String[] args) throws Exception
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();

		long ans = 0;
		for (int i = 1; i <= n; i++) {
			int x1 = i+c+d-a-b;
			int x2 = i+d-a;
			int x3 = i+c-b;
			if (x1 > 0 && x1 <= n && x2 > 0 && x2 <= n && x3 > 0 && x3 <= n) {
				ans++;
			}
		}
		ans *= n;
		System.out.println(ans);
	}
}

import java.util.Scanner;
/*
 * Problem B in O(1)
 *
 *
 *
 *
 *
 * */

public class Main {
	public static void main(String []args){
		Scanner sc= new Scanner(System.in);
		long n = sc.nextLong();
		long a= sc.nextLong() ;
		long b = sc.nextLong() ;
		long c= sc.nextLong() ;
		long d= sc.nextLong() ;
		long max= 0L;
		long min = 0L ;

		if(a-d >0)
			if(a-d>max) max = (a-d);

		if((a+b-d-c)>0)
			if((a+b-d-c)>max)max =a+b-d-c;
		if((b-c)>0)
			if((b-c)>max)max= b-c ;

		if(a-d <0)
			if(a-d<min) min = (a-d);

		if((a+b-d-c)<0)
			if((a+b-d-c)<min)min =a+b-d-c;
		if((b-c)<0)
			if((b-c)<min)min= b-c ;
		long ans;
		ans= n* (n-max +min);
		ans = ans>=0?ans:0;

		System.out.println(ans);

	}

}

import java.util.*;
import java.io.*;

public class marte{

private int contor=0;

public static void main (String args[]) throws Exception{

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> start= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> finish= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> maxime= new HashMap<Integer, Integer>();

			int n=input.nextInt();
			int a=input.nextInt();
			int b=input.nextInt();
			int c=input.nextInt();
			int d=input.nextInt();

	Long result=0L;
	for(int e=1;e<=n;e++)
	{

	    if(e+b-c>=1 && e+b-c<=n && e+a-d>=1 && e+a-d<=n && e+a+b-c-d>=1 &&
	    e+a+b-c-d<=n) result++;}

	  result=result*n;
	    System.out.println(result);

	}

					}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class R353B {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int n = s.nextInt(), a = s.nextInt(), b = s.nextInt(), c = s.nextInt(), d = s.nextInt();
		int ab = a+b, ac = a+c, cd = c+d, db = d+b;
		long ans = 0;
//		System.out.printf("%d %d %d %d\n", ab, ac, cd, db);
		for(int i = 1; i <= n; i++) {
			int topLeft = ab+i, topRight = ac+i, bottomLeft = db+i, bottomRight = cd+i;
			int maxDif = Integer.MIN_VALUE;
			maxDif = Math.max(maxDif, Math.abs(topLeft-topRight)); maxDif = Math.max(maxDif, Math.abs(topRight-bottomLeft));
			maxDif = Math.max(maxDif, Math.abs(bottomLeft-bottomRight)); maxDif = Math.max(maxDif, Math.abs(bottomRight-topLeft));
			ans += Math.max(0, n-maxDif);
		}
		System.out.println(ans);
	}
}

import java.awt.Point;
import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.sql.Array;
import java.util.*;
import java.util.jar.Attributes.Name;
import java.util.logging.Level;

import javax.print.attribute.HashAttributeSet;
import javax.swing.text.MaskFormatter;

public class TestClass {

static long mod ;

static ArrayList<Integer>[] maps;
static long[][] dp;
static int z;
static int[] V;
static long[][] Tree;
static long[][] lazy;
static int[] P;
static int[] A;
static int[] S;
static int nextnode;
static long max;
static boolean important;
static ArrayList<Integer> Final;
static HashMap<Long,Long>[] Why = new HashMap[11];

static class me{
	  double dis;
	  int index;
	  public me(double dis , int index){
		   this.dis = dis;
		   this.index = index;
	  }
}

public static double dis(long a , long b){ return Math.sqrt(a*a+b*b);}

public static void main(String args[] ) throws java.lang.Exception {

InputStream inputStream = System.in;
InputReader in = new InputReader(inputStream);

//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
//Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.java"));
 //PrintWriter pw = new PrintWriter(new FileWriter("C:\\Users\\sompathak\\Desktop\\output.txt"));
//InputStream inputStream = System.in;
//InputReader in = new InputReader(inputStream);
//Scanner in = new Scanner(new InputStreamReader(System.in));
// Scanner in = new Scanner(new FileReader("C:\\Users\\sompathak\\Desktop\\yes.java"));
//we can we will ??? !!!!!! SOM RISES
//long startTime = System.currentTimeMillis();
//long startTime = System.currentTimeMillis();

//float endTime   = System.currentTimeMillis();
//float totalTime = (endTime - startTime)/(float)1000;
//System.out.println(totalTime+" sec.....");

// {is, in ,the ,to ,he ,she}
mod=1000000007;
long o =0;
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();
for(int i=1;i<=n;i++){

	int x = i+b-c;
	if(x>n || x<=0) continue;
	x = i+a-d;
	if(x>n || x<=0) continue;
	x = i+b-c+a-d;
	if(x>n || x<=0) continue;

	o++;
}
o*=n;
System.out.println(o);

}public static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;

public InputReader(InputStream stream)
{
this.stream = stream;
}

public int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}

public int nextInt()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}

public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}

public String next()
{
return readString();
}

public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.lang.*;
import java.util.*;
/**
 *
 * @author hp
 */
public class Cell
{
    int sum(int a,int b,int c,int d)
    {
        return a+b+c+d;
    }
    public static void main(String args[])
    {
        Cell obj=new Cell();
        Scanner ob=new Scanner(System.in);
        int n,a,b,c,d;
        n=ob.nextInt();
        a=ob.nextInt();
        b=ob.nextInt();
        c=ob.nextInt();
        d=ob.nextInt();
        int x1,x2,x3,x4,x5;long ct=0;
        x2=1;x1=1;boolean fl=true;
            while(x1<=n)
            {

                fl=true;
                int s=obj.sum(x1,x2,a,b);

                x3=s-a-c-x2;

                if(x3<1 || x3>n)
                {  fl=false;}
                x4=s-b-d-x2;

                if(x4<1 || x4>n)
                {fl=false;}
                x5=s-d-c-x2;

                if(x5<1 || x5>n)
                {fl=false;}
                if(fl==true)
                {   ct++;}
                x1++;
            }
            ct=ct*n;
        System.out.println(ct);
    }
}

import java.util.Scanner;

public class RestoringPaintings {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int count=0;
		for(int x=1;x<=n;x++)
		{
			int y=x+b-c;
			int w=a+y-d;
			int z=c+w-b;
			if((y>=1&&y<=n)&&(z>=1&&z<=n)&&(w>=1&&w<=n))
				count++;
		}
		System.out.println((long)count*n);

	}

}

import java.util.Scanner;

public class RestoringPainting {

	static boolean range(long x, long n) {
		if(x>=1 && x<=n)
			return true;
		return false;
	}
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long a =  sc.nextInt();
		long b =  sc.nextInt();
		long c =  sc.nextInt();
		long d =  sc.nextInt();

		long m = 0;
		for (int x1=1; x1<=n; ++x1) {
			long x3 = x1+b-c;
			long x7 = x1+a-d;
			long x9 = x1+a+b-c-d;

			if(range(x3, n) && range(x7, n) && range(x9, n))
				m++;
		}
		System.out.println(n*m);

	}
}

/**
 * Created by abhishek on 5/16/2016.
 */
import java.util.*;
import java.io.*;
public class Maths {
    public static void main(String [] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        long n = Integer.parseInt(st.nextToken());
        long a = Integer.parseInt(st.nextToken());
        long b = Integer.parseInt(st.nextToken());
        long c = Integer.parseInt(st.nextToken());
        long d = Integer.parseInt(st.nextToken());
        long min = Math.min(0,Math.min(a - d,b - c));
        long max = Math.max(0,Math.max(a - d,b - c));
        min = Math.min(min,a - d + b - c);
        max = Math.max(max,a - d + b - c);
        if(n - max < Math.abs(min - 1)){
            System.out.print("0");
            return;
        }
        long ans = n - (max + Math.abs(min));
        System.out.print(ans*n);
    }
}

import java.util.*;

/**
 * Created by Harrison Fang on 5/16/2016.
 */
public class RestoringPainting {
static int n;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (solve(a, b, c, d, i)) {
                ans++;
            }
        }

        System.out.println(((long)ans) * n);
    }

    static boolean solve(int a, int b, int c, int d, int topleft) {
        int topright = topleft + b - c;
        int botleft = topleft + a - d;

        int botright = topright + a - d;
        // botleft + b - c;

        if (topright > 0 && topright <= n && botleft > 0 && botleft <= n&& botright > 0 && botright <= n)
            return true;

        return false;
    }
}

import java.util.Scanner;

public class B353 {
	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int square1 = a + b;
		int square2 = a + c;
		int square3 = b + d;
		int square4 = c + d;
		int min = Math.min(square1, square2);
		min = Math.min(min, square3);
		min = Math.min(min, square4);
		int max = Math.max(square1, square2);
		max = Math.max(max, square3);
		max = Math.max(max, square4);
		int maximum = min + (2 * n);
		int minimum = max + 2;
		if (maximum < minimum) {
			System.out.println(0);
		} else {
			long ans = 0;
			for (int mid = minimum; mid <= maximum; mid++) {
				int smallestmid = 1;
				if (mid - min - 1 > n) {
					int left = mid - min - n;
					smallestmid = left;
				}
				int largestmid = 0;
				if (max + 1 + n <= mid) {
					largestmid = n;
				} else {
					if (max + 1 + n > mid) {
						largestmid = mid - 1 - max;
					}
				}
				if (smallestmid <= largestmid) {
					ans += 1 + (Math.abs(largestmid - smallestmid));
				}
		//		System.out.println(mid + " " + smallestmid + " " + largestmid);
			}
			System.out.println(ans);
		}

	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Likai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            while (testNumber-- > 0) {
                int n = in.nextInt();
                int a = in.nextInt();
                int b = in.nextInt();
                int c = in.nextInt();
                int d = in.nextInt();
                int maxval = Math.max(a + b, Math.max(b + d, Math.max(c + a, d + c)));
                int minval = Math.min(a + b, Math.min(b + d, Math.min(c + a, d + c)));
                out.println(Math.max(0, (long) n * (n - maxval + minval)));
            }
        }

    }
}

import java.util.*;
import java.io.*;

public class CF675B{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static void soln(){
		int n = nextInt();
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();
		int d = nextInt();
		int ab = a+b;
		int ac = a+c;
		int bd = b+d;
		int cd = c+d;
		int max = Math.max(ab,Math.max(ac,Math.max(bd,cd)));
		int min = Math.min(ab,Math.min(ac,Math.min(bd,cd)));
		int i =0;
		int right = Math.min(n+max-min,n);
		int left = Math.max(max+1-min,1);
		long ans = (long)(n)*(right-left+1);
		if(ans>0)
			pw.println(ans);
		else
			pw.println("0");
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

//################################################################################################################
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.util.InputMismatchException;

//################################################################################################################
public class R353D2B {
	public static void main(String[] args) {
		R353D2B b = new R353D2B();
		InputReader1 reader = b.new InputReader1(System.in);
		OutputWriter writer = b.new OutputWriter(System.out);
		// think about the brute-force approach
		// read input
		// code boundary conditions
		int n = reader.readInt();
		int aa = reader.readInt();
		int bb = reader.readInt();
		int cc = reader.readInt();
		int dd = reader.readInt();
		long total = 0;
		for (int i = 1; i <= n; i++) {
			int v13 = i + bb - cc;
			if (!(v13 >= 1 && v13 <= n)) {
				continue;
			}
			int v33 = i + aa + bb - cc - dd;
			if (!(v33 >= 1 && v33 <= n)) {
				continue;
			}
			int v31 = i + aa - dd;
			if (!(v31 >= 1 && v31 <= n)) {
				continue;
			}
			if (((v13 + aa) == (v33 + dd))
					&& ((aa + cc + v13) == (bb + dd + v31))
					&& ((v31 + bb) == (v33 + cc))) {
				total += n;
			}
		}
		writer.println(total);
		reader.close();
		writer.close();
	}

	class InputReader1 {
		// private final boolean finished = false;

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader1(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int peek() {
			if (numChars == -1)
				return -1;
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					return -1;
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int length = readInt();
			if (length < 0)
				return null;
			byte[] bytes = new byte[length];
			for (int i = 0; i < length; i++)
				bytes[i] = (byte) read();
			try {
				return new String(bytes, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				return new String(bytes);
			}
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public boolean isExhausted() {
			int value;
			while (isSpaceChar(value = peek()) && value != -1)
				read();
			return value == -1;
		}

		public String next() {
			return readString();
		}

		public boolean readBoolean() {
			return readInt() == 1;
		}

		public void close() {
			try {
				stream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream stream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
					stream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void println(String s) {
			writer.println(s);
		}

		public void println(int x) {
			writer.println(x);
		}

		public void print(int x) {
			writer.print(x);
		}

		public void println(long x) {
			writer.println(x);
		}

		public void printSpace() {
			writer.print(" ");
		}

		public void close() {
			writer.close();
		}
	}
}

import java.util.Scanner;

public class Q675B_RestoringPainting {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int x1_min = max(1, 1 + c - b, 1 + c + d - b - a, 1 + d - a);
        int x1_max = min(n, n + c - b, n + c + d - b - a, n + d - a);
        if (x1_min > x1_max)
            System.out.println(0);
        else {
            long x1 = x1_max - x1_min + 1;
            System.out.println(x1 * n);
        }

    }

    public static int max(int... as) {
        int max = as[0];
        for (int a : as) {
            if (a > max)
                max = a;
        }
        return max;
    }

    public static int min(int... as) {
        int min = as[0];
        for (int a : as) {
            if (a < min)
                min = a;
        }
        return min;
    }
}

import java.util.Scanner;
import java.util.StringTokenizer;

public class CF_675B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		StringTokenizer st = new StringTokenizer(s.nextLine());

		int n = Integer.parseInt(st.nextToken());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());

		int num1 = Math.abs(d-a);
		int num2 = Math.abs(c-b);
		int num3 = Math.abs(d-a+c-b);
		int num4 = Math.abs(d-a-c+b);
		long f = n - (long)Math.max(num1, Math.max(num2, Math.max(num3, num4)));
		long x = 0;
		if(f >= 0) {
			x = n * f;
		}

		System.out.println(x);
	}
}

import java.util.HashMap;
import java.util.Scanner;
import java.math.*;
import java.awt.*;
import java.util.*;
public class Main{
	private static HashMap<String,Integer> q=new HashMap<String,Integer>() ;
	public static void main(String args[])
	{
		Scanner cin=new Scanner(System.in);
		q.clear();
		int n,a,b,c,d;
		n=cin.nextInt();
		a=cin.nextInt();
		b=cin.nextInt();
		c=cin.nextInt();
		d=cin.nextInt();
		long ans=0;
		for(int x1=1;x1<=n;x1++)
        {
            int x2=x1+b-c;
            int x5=x2+a-d;
            int x4=x5+c-b;
            if(x2>=1&&x5>=1&&x4>=1&&check(a,b,c,d,x1,x2,x4,x5)==1&&x2<=n&&x5<=n&&x4<=n)
            {
                ans++;
            }
        }
		System.out.println(ans*n);
	}
	public static int check(int a,int b,int c,int d,int x1,int x2,int x4,int x5)
	{

		int x[]=new int[10];
		x[0]=a;
	    x[1]=b;
	    x[2]=c;
	    x[3]=d;
	    x[4]=x1;
	    x[5]=x2;
	    x[6]=x4;
	    x[7]=x5;
	    Arrays.sort(x, 0, 7);
	    String y=(x[0]+"")+(x[1]+"")+(x[2]+"")+(x[3]+"")+(x[4]+"")+(x[5]+"")+(x[6]+"")+(x[7]+"");
	    int ok=0;
	    for(String s:q.keySet())
	    {
	    	if(s.equals(y))
	    	{
	    		ok=1;
	    		return 0;
	    	}
	    }
	    return 1;
	}
}

import java.util.Scanner;

public class b {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();
		int tl=a+b;
		int tr=a+c;
		int bl=b+d;
		int br=c+d;
		int max=Math.max(tl, tr);
		max=Math.max(max, br);
		max=Math.max(max, bl);
		int min=Math.min(tl, tr);
		min=Math.min(min, br);
		min=Math.min(min, bl);

		int dif=max-min;
		long ans=n-dif;

		ans*=n;
        if(ans<0){
            System.out.println("0");
        }else{
		System.out.println(ans);
        }
	}

}

//package myPackage;

import java.util.*;
import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long m = (n - Math.abs(a - d)) + (n - Math.abs(b - c)) - n;
		if(m < 0) m = 0;
		out.println(m * n);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProblemB_ {
    static int n, a, b, c, d;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        parse(br.readLine().split(" "));
        br.close();

        long count = 0;
        int k, p, q;
        int C1 = c + d - a - b;
        int C2 = b + d - a - c;
        for (int i = 0; i < n; i++) {
            k = Math.abs((i + 1) + (C2 + C1) / 2);
            p = Math.abs(C2 + (i + 1));
            q = Math.abs((i + 1) + (C2 - C1) / 2);
//            int[][] A = {
//                    {k, a, p},
//                    {b, 0, c},
//                    {i + 1, d, q}
//            };
//            show(A);
            if (k > n || p > n || q > n || k == 0 || p == 0 || q == 0) {
//                System.out.println(-1);
                continue;
            }
            else {
                if (a + b + k == a + c + p && a + c + p == b + i + 1 + d && b + i + 1 + d == c + d + q && c + d + q == a + b + k)
                    count += n;
            }
        }
        System.out.println(count);
    }

    static void parse(String[] s){
        n = Integer.parseInt(s[0]);
        a = Integer.parseInt(s[1]);
        b = Integer.parseInt(s[2]);
        c = Integer.parseInt(s[3]);
        d = Integer.parseInt(s[4]);
    }

    static void show(int[][] A){
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < A.length; j++) {
                System.out.print(A[i][j] + "\t");
            }
            System.out.println();
        }
        System.out.println();
    }
}

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
        	int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            long count = 0L;
            if(a > n || b > n || c > n || d > n)
            	break;
            for(int i = 1; i <= n; i++) {
            	int m = b - c + i;
            	int s = a - d + i;
            	int t = a - d + b - c + i;
            	if(m >= 1 && m <= n && s >= 1 && s <= n && t >= 1 && t <= n)
            		count++;
            }
            System.out.println(n * count);
        }
	}
}

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

	static int mod = (int) 1e9 + 7;
	static int MAX = (int) 1e9;
	static ArrayList<Integer>[] g;
	static int n, m;
	static long k;
	static int[][] a;
	static int nodes = 0;
	static int edges = 0;
	static boolean[][] done;
	static int[][] ans;
	static int[] dp;
	static int curX, curY;
	static int rx, ry, x1, y1, x2, y2;

	public static void main(String[] args) {
		FasterScanner s = new FasterScanner();
		PrintWriter out = new PrintWriter(System.out);
		int test = 1;

		testloop: while (test-- > 0) {
			int n = s.nextInt();
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int d = s.nextInt();
			long sum = 0;
			for(int k = 1; k <= 4*n; k++){
				int k1 = k - (a+b);
				int k2 = k - (a+c);
				int k3 = k - (d+b);
				int k4 = k - (c+d);

				int min = 1;
				int max = n;

				max = Math.min(max, k1-1);
				max = Math.min(max, k2-1);
				max = Math.min(max, k3-1);
				max = Math.min(max, k4-1);
				min = Math.max(min, k1 - n);
				min = Math.max(min, k2 - n);
				min = Math.max(min, k3 - n);
				min = Math.max(min, k4 - n);
				sum += Math.max(0, max - min + 1);
			}
			System.out.println(sum);

		}

		out.close();
	}

	public static int find(int[] a, int val) {
		int left = 0;
		if (val > a[a.length - 1])
			return a.length;
		int right = a.length;

		while (left < right) {

			int mid = (left + right) >> 1;
			// System.out.println("HERE" + left +" " + right +" "+mid);

			if (a[mid] > val) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		return right;
	}

	static class Pair implements Comparable<Pair> {
		long x;
		long y;

		public int compareTo(Pair o) {
			return Double.compare(this.curDistance(), o.curDistance());
		}

		public double curDistance() {
			return Math.sqrt((x - curX) * (x - curX) + (y - curY) * (y - curY))
					- Math.sqrt((x - rx) * (x - rx) + (y - ry) * (y - ry));
		}

		public double distance1() {
			return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1))
					- Math.sqrt((x - rx) * (x - rx) + (y - ry) * (y - ry));
		}

		public double distance2() {
			return Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2))
					- Math.sqrt((x - rx) * (x - rx) + (y - ry) * (y - ry));
		}

		public double distance() {
			return 2 * Math.sqrt((x - rx) * (x - rx) + (y - ry) * (y - ry));
		}
	}

	static class Component implements Comparable<Component> {
		int id;
		int size;

		Component(int id, int size) {
			this.id = id;
			this.size = size;
		}

		@Override
		public int compareTo(Component o) {
			return size - o.size;
		}
	}

	static class Point {
		int x, y;

		Point(int xx, int yy) {
			x = xx;
			y = yy;
		}
	}

	static void dfs(int x, int y, int rem, int val) {
		if (rem <= 0)
			return;
		rem--;
		done[x][y] = true;
		if (check(x + 1, y) && !done[x + 1][y] && a[x + 1][y] >= val)
			dfs(x + 1, y, rem, val);
		if (check(x - 1, y) && !done[x - 1][y] && a[x - 1][y] >= val)
			dfs(x - 1, y, rem, val);
		if (check(x, y + 1) && !done[x][y + 1] && a[x][y + 1] >= val)
			dfs(x, y + 1, rem, val);
		if (check(x, y - 1) && !done[x][y - 1] && a[x][y - 1] >= val)
			dfs(x, y - 1, rem, val);
	}

	static boolean check(int x, int y) {
		return x >= 0 && y >= 0 && x < n && y < m;
	}

	static class Player implements Comparable<Player> {
		String name;
		int score;

		Player(String n, int v) {
			name = n;
			score = v;
		}

		@Override
		public int compareTo(Player o) {
			return o.score - score;
		}
	}

	static class Edge {
		int t, rev, f;
		long cap;

		public Edge(int t, int rev, long cap) {
			this.t = t;
			this.rev = rev;
			this.cap = cap;
		}
	}

	public static List<Edge>[] createGraph(int nodes) {
		List<Edge>[] graph = new List[nodes];
		for (int i = 0; i < nodes; i++)
			graph[i] = new ArrayList<>();
		return graph;
	}

	public static void addEdge(List<Edge>[] graph, int s, int t, long cap) {
		graph[s].add(new Edge(t, graph[t].size(), cap));
		graph[t].add(new Edge(s, graph[s].size() - 1, 0));
	}

	static boolean dinicBfs(List<Edge>[] graph, int src, int dest, int[] dist) {
		Arrays.fill(dist, -1);
		dist[src] = 0;
		int[] Q = new int[graph.length];
		int sizeQ = 0;
		Q[sizeQ++] = src;
		for (int i = 0; i < sizeQ; i++) {
			int u = Q[i];
			for (Edge e : graph[u]) {
				if (dist[e.t] < 0 && e.f < e.cap) {
					dist[e.t] = dist[u] + 1;
					Q[sizeQ++] = e.t;
				}
			}
		}
		return dist[dest] >= 0;
	}

	static long dinicDfs(List<Edge>[] graph, int[] ptr, int[] dist, int dest, int u, long l) {
		if (u == dest)
			return l;
		for (; ptr[u] < graph[u].size(); ++ptr[u]) {
			Edge e = graph[u].get(ptr[u]);
			if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
				long df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(l, e.cap - e.f));
				if (df > 0) {
					e.f += df;
					graph[e.t].get(e.rev).f -= df;
					return df;
				}
			}
		}
		return 0;
	}

	public static long maxFlow(List<Edge>[] graph, int src, int dest) {
		long flow = 0;
		int[] dist = new int[graph.length];
		while (dinicBfs(graph, src, dest, dist)) {
			int[] ptr = new int[graph.length];
			while (true) {
				long df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);
				if (df == 0)
					break;
				flow += df;
			}
		}
		return flow;
	}

	static int ans(ArrayList<Character>[] l, char a, int n) {
		if (n == 1)
			return 1;
		int sum = 0;
		for (int i = 0; i < l[a - 'a'].size(); i++) {
			sum += ans(l, l[a - 'a'].get(i), n - 1);
		}
		return sum;
	}

	static void dfs1(List<Integer>[] graph, boolean[] used, List<Integer> order, int u) {
		used[u] = true;
		for (int v : graph[u])
			if (!used[v])
				dfs1(graph, used, order, v);
		order.add(u);
	}

	static void dfs2(List<Integer>[] reverseGraph, int[] comp, int u, int color) {
		comp[u] = color;
		for (int v : reverseGraph[u])
			if (comp[v] == -1)
				dfs2(reverseGraph, comp, v, color);
	}

	public static boolean[] solve2Sat(List<Integer>[] graph) {
		int n = graph.length;
		boolean[] used = new boolean[n];
		List<Integer> order = new ArrayList<>();
		for (int i = 0; i < n; ++i)
			if (!used[i])
				dfs1(graph, used, order, i);

		List<Integer>[] reverseGraph = new List[n];
		for (int i = 0; i < n; i++)
			reverseGraph[i] = new ArrayList<>();
		for (int i = 0; i < n; i++)
			for (int j : graph[i])
				reverseGraph[j].add(i);

		int[] comp = new int[n];
		Arrays.fill(comp, -1);
		for (int i = 0, color = 0; i < n; ++i) {
			int u = order.get(n - i - 1);
			if (comp[u] == -1)
				dfs2(reverseGraph, comp, u, color++);
		}

		for (int i = 0; i < n; ++i)
			if (comp[i] == comp[i ^ 1])
				return null;

		boolean[] res = new boolean[n / 2];
		for (int i = 0; i < n; i += 2)
			res[i / 2] = comp[i] > comp[i ^ 1];
		return res;
	}

	public static int[] createSets(int size) {
		int[] p = new int[size];
		for (int i = 0; i < size; i++)
			p[i] = i;
		return p;
	}

	public static int root(int[] p, int x) {
		return x == p[x] ? x : (p[x] = root(p, p[x]));
	}

	public static void unite(int[] p, int a, int b) {
		a = root(p, a);
		b = root(p, b);
		if (a != b)
			p[a] = b;
	}

	public static boolean nextPermutation(int[] p) {
		for (int a = p.length - 2; a >= 0; --a)
			if (p[a] < p[a + 1])
				for (int b = p.length - 1;; --b)
					if (p[b] > p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for (++a, b = p.length - 1; a < b; ++a, --b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
		return false;
	}

	public static boolean isPrime(long n) {
		if (n <= 1)
			return false;
		for (long i = 2; i * i <= n; i++)
			if (n % i == 0)
				return false;
		return true;
	}

	static class SegTree {
		int[] val;
		int n;

		SegTree(int n) {
			val = new int[2 * n];
			this.n = n;
		}

		void upd(int p, int l) {
			p += n;
			val[p] = l;
			for (; (p >>= 1) != 0;) {
				val[p] = Math.max(val[2 * p], val[2 * p + 1]);

			}
		}

		int query(int l, int r) { // sum on interval [l, r)
			// System.out.println(l+" "+r);
			int res = 0;
			for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
				if ((l & 1) != 0)
					res = Math.max(res, val[l++]);
				if ((r & 1) != 0)
					res = Math.max(res, val[--r]);
			}
			return res;
		}
	}

	static boolean check(int i, int j, int n) {
		if (i >= 0 && j >= 0 && i < n && j < n)
			return true;
		return false;
	}

	public static int[] generateDivisorTable(int n) {
		int[] divisor = new int[n + 1];
		for (int i = 1; i <= n; i++)
			divisor[i] = i;
		for (int i = 2; i * i <= n; i++)
			if (divisor[i] == i)
				for (int j = i * i; j <= n; j += i)
					divisor[j] = i;
		return divisor;
	}

	public static int[][] matrixMul(int[][] a, int[][] b) {
		int n = a.length;
		int m = a[0].length;
		int k = b[0].length;
		int[][] res = new int[n][k];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				for (int p = 0; p < m; p++) {
					res[i][j] = (res[i][j] + (int) ((a[i][p] * 1l * b[p][j]) % mod)) % mod;
				}
			}
		}
		return res;
	}

	public static int[][] matrixPow(int[][] a, int p) {
		if (p == 0) {
			return matrixUnit(a.length);
		} else if (p % 2 == 0) {
			return matrixPow(matrixMul(a, a), p / 2);
		} else {
			return matrixMul(a, matrixPow(a, p - 1));
		}
	}

	public static int[][] matrixUnit(int n) {
		int[][] res = new int[n][n];
		for (int i = 0; i < n; ++i) {
			res[i][i] = 1;
		}
		return res;
	}

	static int[] modInv(int n, int mod) {
		int[] ans = new int[n];
		for (int i = 1; i < n; i++)
			ans[i] = (int) pow(i, mod - 2, mod);
		return ans;
	}

	static int[] primes;

	public static long ncr(int n, int r) {
		if (n < r)
			return 0;
		if (n == r)
			return 1;
		if (r == 0)
			return 1;
		if (r < 0)
			return 0;
		long ans = 1;
		for (int i = 0; i < primes.length; i++) {
			long power = count(n, primes[i]) - count(n - r, primes[i]) - count(r, primes[i]);
			ans *= pow(primes[i], power, mod);
			ans %= mod;
		}
		return ans;
	}

	public static long pow(long x, long n, int mod) {
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
			if ((n & 1) != 0) {
				res = (int) (res * p % mod);
			}
		}
		return res;
	}

	public static long count(int n, int p) {
		long count = 0;
		long z = p;
		while (z <= n) {
			count += n / z;
			z *= p;
		}
		return count;

	}

	public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;

		return Arrays.copyOf(primes, cnt);
	}

	static class Pairxy implements Comparable<Pairxy> {
		int x;
		int y;

		Pairxy(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pairxy o) {
			return Integer.compare(this.x, o.x);
		}

	}

	public static long C(int n, int r) {
		long ans = 1;
		int x = 1;
		while (x <= r) {
			ans *= n;
			ans /= x;
			x++;
			n--;
		}
		return ans;
	}

	static class DisjointSetsRank {

		int[] p;
		int[] rank;
		int[] size;

		public DisjointSetsRank(int size) {
			p = new int[size];
			this.size = new int[size];
			for (int i = 0; i < size; i++) {
				p[i] = i;
				this.size[i] = 1;
			}
			rank = new int[size];
		}

		public int root(int x) {
			return x == p[x] ? x : (p[x] = root(p[x]));
		}

		public int sameSet(int x, int y) {
			if (root(x) == root(y))
				return 1;
			return 0;

		}

		public int unite(int a, int b) {
			a = root(a);
			b = root(b);
			if (a == b)
				return -1;

			if (rank[a] < rank[b]) {
				p[a] = b;
				size[b] += size[a];
				return a;
			} else {
				p[b] = a;
				size[a] += size[b];
				if (rank[a] == rank[b])
					++rank[a];
				return b;
			}
		}

	}

	static int gcd(long m, long n) {
		long x;
		long y;
		while (m % n != 0) {
			x = n;
			y = m % n;
			m = x;
			n = y;
		}
		return (int) n;
	}

	static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class RestoringPainting {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int a = r.nextInt();
		int b = r.nextInt();
		int c = r.nextInt();
		int d = r.nextInt();
		long res = 0;
		for (int one = 1; one <= n; one++) {
			int four = one + a - d;
			int two = one + b - c;
			int five = a + two - d;
			if (two >= 1 && two <= n && four >= 1 && four <= n && five >= 1
					&& five <= n)
				res += n;
		}
		System.out.println(res);
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

import java.io.*;
import java.util.*;

public class Main {
    private final static InputReader ir = new InputReader(System.in);
    private final static PrintWriter ow = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n = ir.ni();
        int a = ir.ni(), b = ir.ni(), c = ir.ni(), d = ir.ni();
        int s1 = a + b;
        int s2 = b + d;
        int s3 = c + a;
        int s4 = d + c;
        int max = Math.max(Math.max(s1, s2), Math.max(s3, s4));
        int min = Math.min(Math.min(s1, s2), Math.min(s3, s4));
        System.out.println((long) n * Math.max(0, n - max + min));
    }

}

class InputReader implements AutoCloseable {
    private final InputStream in;
    private int capacity;
    private byte[] buffer;
    private int len = 0;
    private int cur = 0;

    InputReader(InputStream stream) {
        this(stream, 100_000);
    }

    InputReader(InputStream stream, int capacity) {
        this.in = stream;
        this.capacity = capacity;
        buffer = new byte[capacity];
    }

    private boolean update() {
        if (cur >= len) {
            try {
                cur = 0;
                len = in.read(buffer, 0, capacity);
                if (len <= 0)
                    return false;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    private int read() {
        if (update())
            return buffer[cur++];
        else return -1;
    }

    public boolean isEmpty() {
        return !update();
    }

    private boolean isSpace(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == ' ';
    }

    private boolean isEscape(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == -1;
    }

    private int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    int ni() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    int nc() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        return c;
    }

    String ns(int initialCapacity) {
        StringBuilder res = new StringBuilder(initialCapacity);
        int c = readSkipSpace();
        do {
            res.append((char) (c));
            c = read();
        } while (!isEscape(c));
        return res.toString();
    }

    @Override
    public void close() throws IOException {
        in.close();
    }
}

import java.util.Scanner;

public class RestoringPainting {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		 int b= input.nextInt();
		int c = input.nextInt();
		int d = input.nextInt();
		long total=0;
		for(int x1=1;x1<=n; x1++){
			int x4 = x1+a-d;
			int x3 = x1+b-c;
			int x5 = x1+a+b-c-d;
			if(x3>0 && x4>0 && x5>0 && x3<=n && x4<=n && x5<=n){
				total+=n;
			}
		}
		System.out.println(total);
	}

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c =sc.nextInt(), d = sc.nextInt();

        long result = 0;
        for(int i = 1; i <= n ; i++){
            long stl = a + b + i;
            long lb = stl - (b+d);
            long rb = stl - (c+d);
            long rt = stl - (a+c);
            if((1 <= lb && lb <= n) && (1 <= rb && rb <= n) && (1 <= rt && rt <= n) )
                result++;
         }
        System.out.println(result*n);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class B {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	long n=sc.nextLong();
	long a=sc.nextLong();
	long b=sc.nextLong();
	long c=sc.nextLong();
	long d=sc.nextLong();
	long x=1,y=0,z=0,l=0,k=1;
	if(b-c+1>0){
		y=b-c+1;
	}else{
		y=1;x=(c-b+1);
	}
//	System.out.println(x+" "+y);
	l=a-d+x;
	if(l<=0){
		x=x-l;x++;
		y=y-l;y++;
		l=l-l;l++;
	}
	k=b-c+l;
	if(k<=0){
		x=x-k;x++;
		y=y-k;y++;
		l=l-k;l++;
		k=k-k;k++;
	}
	long []q=new long[4];
	q[0]=x;
	q[1]=y;
	q[2]=l;
	q[3]=k;
//	for (int i = 0; i < q.length; i++) {
//		System.out.print(q[i]+" ");
//	}System.out.println();
	Arrays.sort(q);
	if((n-q[3])<0){
		System.out.println("0");
	}else{
//		for (int i = 0; i < q.length; i++) {
//			System.out.print(q[i]+" ");
//		}System.out.println();
		System.out.println(((n-q[3])+1)*n);
	}

}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a = s.nextInt(); int b = s.nextInt();
		int c = s.nextInt(); int d = s.nextInt();
		int[] dr = new int[4];
		dr[0] = a+b; dr[1] = a+c; dr[2] = b+d; dr[3] = c+d;
		Arrays.sort(dr);
		int min = dr[0];  int max = dr[3];
		long res = n;
		if(n-(max-min)>=0)
			res*= n-(max-min);
		else if(max-min > n)
			res = 0;

		System.out.println(res);

	}
}

import java.io.*;

public class ProblemB {
    StreamTokenizer in;
    PrintWriter out;
    public static void main(String[] args) throws IOException {
        new ProblemB().run();
    }

    void run() throws IOException
    {
        in  = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    private void solve() throws IOException{
        int N = nextInt();
        int A = nextInt();
        int B = nextInt();
        int C = nextInt();
        int D = nextInt();
        int max = Math.max(Math.max(A+B, A+C), Math.max(B+D, C+D));
        int min = Math.min(Math.min(A+B, A+C), Math.min(B+D, C+D));
        long X = max - min + 1;
        if (X > N){
            out.println("0");
        }
        else {
            out.println((N - X + 1)*N);
        }

    }

    int nextInt() throws IOException
    {
        in.nextToken();
        return (int)in.nval;
    }

    String next() throws IOException
    {
        in.nextToken();
        return in.sval;
    }
}

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Contest {
	private static PrintWriter out = new PrintWriter(System.out);
	private static final Random random = new Random();
	private static int n, m, k, tc, s, d;
	private static int[] a;
	private static final int OO = (int) 1e9;
	private static final int mod = (int) 1e9 + 7;
	private static final int MAX = (int) (1e5 + 3);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int top = sc.nextInt(), left = sc.nextInt(), right = sc.nextInt(), bottom = sc.nextInt();
		long ans = 0;
		for (int a = 1; a <= n; a++) {
//			for (int i = 1; i <= n; i++) {
				int total = top + left + a + 1;
				int d = total - (top + right+1), e = total - (bottom + left+1), f = total - (bottom + right+1);
//				System.out.println(a + " " + e + " " + d + " " + f);
				if (v(d) && v(e) && v(f))
					ans+=(long)n;
//			}
		}
		out.println(ans);
		out.flush();
	}

	private static boolean v(int a) {
		return (a > 0 && a <= n);
	}

	private static void ruffleSort(int[] a) {
		int n = a.length;// shuffle, then sosrt
		for (int i = 0; i < n; i++) {
			int oi = random.nextInt(n), temp = a[oi];
			a[oi] = a[i];
			a[i] = temp;
		}
		java.util.Arrays.sort(a);
	}

	private static class Scanner {
		public BufferedReader reader;
		public StringTokenizer st;

		public Scanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			st = null;
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String line = reader.readLine();
					if (line == null)
						return null;
					st = new StringTokenizer(line);
				} catch (Exception e) {
					throw (new RuntimeException());
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}

//Comment out before submit
//package Round353Div2.ProblemB;

/**
 * Created by evergreen on 5/16/16.
 */

/*
ID: najmul.1
LANG: JAVA
TASK: RestoringPainting
*/

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class RestoringPainting {

    private static MyScanner input;
    private static PrintWriter output;

    private static void solve() {

        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d = input.nextInt();

        int x = c - b;
        int y = d - a;
        int z = c + d - a - b;

        int count = 0;

        for (int e = 1; e <= n; e++) {

            int f = e - x;
            int g = e - y;
            int h = e - z;

            if(e+b != f+c) continue;
            if(e+a != g+d) continue;
            if(a+e+b != d+c+h) continue;

            if(isaBoolean(n, f) && isaBoolean(n, g) && isaBoolean(n, h)) {

                ++count;
            }
        }

        BigInteger bigInteger = new BigInteger(String.valueOf(count));
        BigInteger bigInteger1 = new BigInteger(String.valueOf(n));
        BigInteger aaa = bigInteger.multiply(bigInteger1);

        output.println(aaa);
        output.flush();
    }

    private static boolean isaBoolean(int n, int f) {
        return f >= 1 && f <= n;
    }

    public static void main(String[] args) throws FileNotFoundException {

        input = SmartInOut.getInitInput();
        output = SmartInOut.getInitOutput();

        solve();

        output.close();
    }
}

class SmartInOut {

    private static MyScanner input;
    private static PrintWriter output;

    private static String getFilePathPrefix() {

        String filePathPrefix = "";

        Class<? extends RestoringPainting> aClass = new RestoringPainting().getClass();
        Package aPackage = aClass.getPackage();

        if (aPackage != null) {
            String packageName = aPackage.getName();
            String partialPath = packageName.replace(".", "/");
            filePathPrefix = "src/" + partialPath + "/";
        }

        return filePathPrefix;
    }

    public static MyScanner getInitInput() throws FileNotFoundException {

        String filePath = getFilePathPrefix() + "RestoringPainting.in";
        File f = new File(filePath);
        input = f.exists() && !f.isDirectory() ? new MyScanner(filePath) : new MyScanner();
        return input;
    }

    public static PrintWriter getInitOutput() throws FileNotFoundException {

        String filePathPrefix = getFilePathPrefix();
        File f = new File(filePathPrefix + "RestoringPainting.in");
        String outputFilePath = filePathPrefix + "RestoringPainting.out";

        output = f.exists() && !f.isDirectory() ? new PrintWriter(outputFilePath) : new PrintWriter(System.out);
        return output;
    }
}

class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public MyScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    public List<String> readLineAsStringList() throws IOException {

        //Modify it if you need a different delimiter
        String delimiter = " ";
        String st = br.readLine();
        List<String> list = Arrays.asList(st.split(delimiter));
        return list;
    }

    public List<String> readStringList(int howMany) {

        List<String> list = new ArrayList<String>();
        while (howMany-- > 0) {

            String st = nextToken();
            list.add(st);
        }
        return list;
    }

    public List<Integer> readIntegerList(int howMany) {

        List<Integer> list = new ArrayList<Integer>();
        while (howMany-- > 0) {

            int st = nextInt();
            list.add(st);
        }
        return list;
    }

    public List<Double> readDoubleList(int howMany) {

        List<Double> list = new ArrayList<Double>();
        while (howMany-- > 0) {

            double st = nextDouble();
            list.add(st);
        }
        return list;
    }
}

class BasicUtility {

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItems(List<T> list) {

        String delimiter = " ";
        String formattedJoin = BasicUtility.joinItemsWithDelimiter(delimiter, list);

        return formattedJoin;
    }

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItemsWithDelimiter(String delimiter, List<T> list) {

        String formattedJoin = "";
        int count = list.size();
        for (int i = 0; i < count - 1; ++i) {

            //Join all elements except last element
            formattedJoin += (list.get(i) + delimiter);
        }

        if (count > 1) {
            //Now join last element
            formattedJoin += list.get(count - 1);
        }

        //For Java 8
        //String formattedJoin = list.stream().map(i -> i.toString()).collect(Collectors.joining(delimiter));

        return formattedJoin;
    }

    public static <T> List<T> getCopyList(List<T> list) {

        List<T> copiedList = new ArrayList<T>(list);
        //For Java 8
        //List<T> copiedList = list.stream().collect(Collectors.toList());
        return copiedList;
    }
}

import java.util.*;

/**
 * Created by Harrison Fang on 5/16/2016.
 */
public class RestoringPainting {
static int n;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (solve(a, b, c, d, i)) {
                ans++;
            }
        }

        System.out.println(((long)ans) * n);
    }

    static boolean solve(int a, int b, int c, int d, int topleft) {
        int topright = topleft + b - c;
        int botleft = topleft + a - d;

        int botright = topright + a - d;
        // botleft + b - c;

        if (topright > 0 && topright <= n && botleft > 0 && botleft <= n&& botright > 0 && botright <= n)
            return true;

        return false;
    }
}

import java.util.Scanner;

/**
 *
 * @author mbp
 */
public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input =new Scanner(System.in);
        int n;
        int a , b , c ,d;
        n=input.nextInt();
        a=input.nextInt();
        b=input.nextInt();
        c=input.nextInt();
        d=input.nextInt();
        long result=0;
        int val1,val2,val3;
        for(int i=1;i<=n;++i){
            val1=i+a-d;
            val2=i+b-c;
            val3=i+a+b-c-d;
            if(val1>0&&val2>0&&val3>0){
                if(val1<=n&&val2<=n&&val3<=n){
                if(Math.ceil(val1)==val1 &&Math.ceil(val2)==val2&&Math.ceil(val3)==val3){
                    result++;

        }
            }
            }
        }
        System.out.println(result*n);

    }

}

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        int answer = 0;
        for (int x = 1; x <= n; ++ x) {
            int q = x;
            q = b + q - c;
            if (q < 1 || q > n) continue;
            q = a + q - d;
            if (q < 1 || q > n) continue;
            q = c + q - b;
            if (q < 1 || q > n) continue;
            q = q + d - a;
            if (q != x) continue;
            answer ++;
        }
        System.out.println(answer * 1l * n);
    }
}

import java.io.*;
import java.util.*;

public class CfRestoringPainting {

    public static void main(String args[]) throws IOException
    {
        InputReader in = new InputReader(System.in);
	PrintWriter w = new PrintWriter(System.out);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        long ans = 0;
        for(int i = 1; i <= n; i++){
            int y = i+b-c;
            int z = i+a-d;
            int r = z+b-c;
            if(valid(y,n)&&valid(z,n)&&valid(r,n)) ans += n;
        }
        System.out.println(ans);
        w.close();
    }

    private static boolean valid(int x, int n){
        if(x >= 1 && x <= n) return true;
        return false;
    }

      static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(new BufferedInputStream(System.in));
		int n = cin.nextInt();
		int a = cin.nextInt();
		int b = cin.nextInt();
		int c = cin.nextInt();
		int d = cin.nextInt();
		int x[] = new int[5];
		x[1] = a + b;
		x[2] = a + c;
		x[3] = b + d;
		x[4] = c + d;
		long cnt = 0;
		for (int i = 1; i <= n; ++i) {
			int l = 0, r = 4*n+1;
			for (int j = 1; j <= 4; ++j) {
				l = Math.max(l, i + x[j] + 1);
				r = Math.min(r, i + x[j] + n);
//				System.out.printf("x[%d] = %d\n", j, x[j]);
			}
//			System.out.println("l = " + l + ", r = " + r);
			if (r >= l) {
				cnt += (r-l+1);
			}
		}
		System.out.println(cnt);
		cin.close();
	}

}

import java.util.Scanner;
public class DaVinci{
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args){
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		long s=0L;
		for(int i=1;i<=n;i++){
			if(((i+b-c)<=n)
				&&((i+b-c)>=1)
				&&((i+a-d)<=n)
				&&((i+a-d)>=1)
				&&((i+a+b-d-c)<=n)
				&&((i+a+b-d-c)>=1)){s+=n;}
		}
		System.out.print(s);
	}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class ProblemB {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        long n = input.nextInt();
        long a = input.nextInt();
        long b = input.nextInt();
        long c = input.nextInt();
        long d = input.nextInt();
        long ab = a + b;
        long cd = c + d;
        long bd = b + d;
        long ac = a + c;
        ArrayList<Long> sum = new ArrayList<Long>();
        sum.add(ab);
        sum.add(bd);
        sum.add(cd);
        sum.add(ac);
        Collections.sort(sum);
        long range = sum.get(3)-sum.get(0);
        if(range > n-1){
            System.out.println(0);
        }
        else{
            System.out.println((n-range)*n);
        }
    }

}

import java.util.Scanner;

public class Pinturas {

	public static void main(String[] agrs){

		String x=""; //Input String
		int y=0;
		long max=0,min=999999;
		long[] z=new long[5], w=new long[4];//z=inputs, w=max & minimum

		Scanner scan=new Scanner(System.in);
		x=scan.nextLine();

		for(int i=0;i<x.length();i++){
			if(x.charAt(i)==' '){
				y++;
			}
			else{
				if(z[y]>0)
					z[y]=z[y]*10+x.charAt(i)-'0';
				else
					z[y]+=x.charAt(i)-'0';
			}
		}

		w[0]=z[1]+z[2];
		w[1]=z[1]+z[3];
		w[2]=z[4]+z[2];
		w[3]=z[4]+z[3];

		for(int i=0;i<4;i++){
			if(w[i]>max)
				max=w[i];
			if(w[i]<min)
				min=w[i];
		}
		if((z[0])*(z[0]-(max-min))>0)
			System.out.println((z[0])*(z[0]-(max-min)));
		else
			System.out.println("0");
		scan.close();
	}
}

import java.util.Scanner;

/**
 * http://codeforces.com/contest/675/problem/B?locale=en
 */
public class B {

	public static void main(String[] args) {
		new B().doJob();
	}

	private void doJob() {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			int d = scanner.nextInt();
			int d1 = a + b + 2;
			int d2 = b + d + 2;
			int d3 = d + c + 2;
			int d4 = c + a + 2;

			int max = Math.max(d1, Math.max(d2, Math.max(d3, d4)));
			int min = Math.min(d1, Math.min(d2, Math.min(d3, d4)));
			int maxNumber = 1 + max - min;
			if (maxNumber > n) {
				System.out.println(0);
				return;
			}
			System.out.println((long) n * (n + 1 - maxNumber));

		}

	}
}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
//	public void print(){
//		for(int i=0;i<cells.length;i++){
//			for(int j=0;j<cells[0].length;j++){
//				System.out.print(cells[i][j]+" ");
//			}
//			System.out.println();
//		}
//	}
	public int check(){
			int nr=0;

			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
			if(sum1<=1 || sum2<=1 || sum3<=1 || sum4 <=1 || cells[0][1]>maxn ||
					cells[1][0]>maxn || cells[1][2]>maxn || cells[2][1]>maxn){
				return 0;
			}
			for(int i=1;i<=maxn;i++){

				if((sum1+i)-(sum2)>=1 && (sum1+i)-(sum3)>=1 && (sum1+i)-(sum4)>=1 &&
						(sum1+i)-(sum2)<=maxn && (sum1+i)-(sum3)<=maxn && (sum1+i)-(sum4)<=maxn){
					nr=nr+maxn;
				}
			}
			return nr;

		}

	public static void main(String args[]){
		Painting art=new Painting();
		//art.print();
		System.out.println(art.check());
	}
}

import java.util.Scanner;

/**
 * Created by dhreeraj on 4/2/16.
 */
public class ChefBalloons {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int x1,x3,x4;
        int count=0;
        if(b==c & a!=d){
            for(int  i=1;i<=n;i++){
                if((d-a+i)<=n && (d-a+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        }else if(a==d && b!=c){
            for(int  i=1;i<=n;i++){
                if((b-c+i)<=n && (b-c+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        } else{
            if(a==b&&b==c&&c==d){
                System.out.println(n*n);
            }
            else{
                for(int i=1;i<=n;i++){
                    x1=d-a+i;
                    x4=b-c+i;
                    x3=x1+b-c;
                    if((x1<=n && x1>=1) && (x3<=n && x3>=1) && (x4<=n && x4>=1)){
                        count++;
                    }
                }
                System.out.println(n*count);
            }
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProblemB_ {
    static int n, a, b, c, d;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        parse(br.readLine().split(" "));
        br.close();

        int count = 0;
        int k, p, q;
        int C1 = c + d - a - b;
        int C2 = b + d - a - c;
        for (int i = 0; i < n; i++) {
            k = C1 + (i + 1);
            p = C2 + (i + 1);
            q = (i + 1) + (C1 - C2) / 2;
            if (k > n || p > n || q > n)
                continue;
            else count++;
        }
        System.out.println(n * count);
    }

    static void parse(String[] s){
        n = Integer.parseInt(s[0]);
        a = Integer.parseInt(s[1]);
        b = Integer.parseInt(s[2]);
        c = Integer.parseInt(s[3]);
        d = Integer.parseInt(s[4]);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class B {

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String l[];
		l = bf.readLine().split(" ");
		int n = Integer.parseInt(l[0]);
		int a = Integer.parseInt(l[1]);
		int b = Integer.parseInt(l[2]);
		int c = Integer.parseInt(l[3]);
		int d = Integer.parseInt(l[4]);
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			int s0 = i + a + b;
			int s1 = s0 - b - d;
			int s2 = s0 - c - d;
			int s3 = s0 - c - a;
			if (valid(s1, n) && valid(s2, n) && valid(s3, n))
				ans += n;
		}
		System.out.println(ans);
	}

	static boolean valid(int i, int n) {
		return i <= n && i > 0;
	}
}

import java.util.Scanner;

/**
 * 5/19/16 6:52 PM.
 */
public class RestoringPainting {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextLong();
        long a = scan.nextLong();
        long b = scan.nextLong();
        long c = scan.nextLong();
        long d = scan.nextLong();

        long x = n - Math.abs((a+b) - (c+d));
        long ans = n * x;
        System.out.println(ans);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer s = new StringTokenizer(in.readLine());

		int n = Integer.parseInt(s.nextToken());
		int A = Integer.parseInt(s.nextToken());
		int B = Integer.parseInt(s.nextToken());
		int C = Integer.parseInt(s.nextToken());
		int D = Integer.parseInt(s.nextToken());

		long res = 0;

		for (int X = 1; X <= n; X++) {
			int M, N, Z;

			M = B - C + X;
			N = A - D + X;
			Z = A + B - C - D + X;

			if(M <= 0 || N <= 0 || Z <= 0) continue;

			res++;
		}

		System.out.println(res * n);
	}
}

import java.util.*;
import java.io.*;
public class RestoringPainting{
	public static void main(String []args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int topleft, count = 0;
		long counter;
		//, bottomleft, topright, bottomright;
		for( topleft = 1; topleft <= n; topleft++){
				//bottomleft = topleft + a - d;
				//bottomright = topleft + a + b -c -d;
				//topright = topleft + b - c;
				if(((topleft + a - d) > 0) && ((topleft + a + b - c - d) > 0) && ((topleft + b - c) > 0) && ((topleft + a - d) <= n) && ((topleft + a + b - c - d) <= n) && ((topleft + b - c) <= n))
					count++;
		}
		counter = count*n;
		System.out.println();
	}
}

import java.util.*;
public class Q1
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		long max1 = n + c - b;
		long max2 = n + d - a;
		long max3 = n+c+d-a-b;

		max1 = Math.min(Math.min(max1, max2), max3);
		if(max1<0)
			max1=0;

		long min1 = 1 + c - b;
		long min2 = 1 + d - a;
		long min3 = 1+c+d-a-b;

		min1 = Math.min(Math.max(min1, min2), min3);
		if(min1<0)
			min1=0;

		long diff = max1-min1+1;
		if(diff<0)
			diff=0;
		System.out.println(diff*n);

	}

}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a = s.nextInt(); int b = s.nextInt();
		int c = s.nextInt(); int d = s.nextInt();
		int[] dr = new int[4];
		dr[0] = a+b; dr[1] = a+c; dr[2] = b+d; dr[3] = c+d;
		Arrays.sort(dr);
		int min = dr[0];  int max = dr[3];
		System.out.println(dr[0]+" "+dr[1]+" "+dr[2]+" "+dr[3]);
		long res = n;
		if(n-(max-min)>=0)
			res*= n-(max-min);
		else if(max-min > n)
			res = 0;

		System.out.println(res);

	}
}

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
		int n=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		long ans=1;
		ans*=n;
		if(n<=c-b||n<=d-a||n<=d+c-a-b)ans=0;
		else{
		ans*=(	Math.min(Math.min(Math.min(n+d-a,n+c-b),n+d+c-a-b),n)-Math.max(Math.max(Math.max(d-a+1,c-b+1),d+c-a-b+1),1)+1);
		}
		System.out.println(ans);

	}

}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int n,a,b,c,d;
		n=Integer.parseInt(st.nextToken());
		a=Integer.parseInt(st.nextToken());
		b=Integer.parseInt(st.nextToken());
		c=Integer.parseInt(st.nextToken());
		d=Integer.parseInt(st.nextToken());

		int max=-1,e,f,g,h,min=Integer.MAX_VALUE;

		max=Math.max(a+b,a+c);
		max=Math.max(max,b+d);
		max=Math.max(max,c+d);

		min=Math.min(a+b,a+c);
		min=Math.min(min,b+d);
		min=Math.min(min,c+d);

	//	System.out.println(max+" "+min);

		int cnt=0;

		int valMax,valMin=1;

		while(true){
			valMax=max+valMin-min;
			if(valMax>n){
				break;
			}
			else{
				cnt++;
				valMin++;
			}

		}

		System.out.println(cnt*n);
	}
}

import java.util.Scanner;

public class RestoringPainting {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		 int b= input.nextInt();
		int c = input.nextInt();
		int d = input.nextInt();
		int total=0;
		for(int x1=1;x1<=n; x1++){
			int x4 = x1+a-d;
			int x3 = x1+b-c;
			int x5 = x1+a+b-c-d;
			if(x3>0 && x4>0 && x5>0 && x3<=1000 && x4<=1000 && x5<=1000){
				total+=n;
			}
		}
		System.out.println(total);
	}

}

import java.util.Scanner;

public class Pinturas {

	public static void main(String[] agrs){

		String x=""; //Input String
		int y=0;
		long max=0,min=999999999;
		long[] z=new long[5], w=new long[4];//z=inputs, w=max & minimum

		Scanner scan=new Scanner(System.in);
		x=scan.nextLine();

		for(int i=0;i<x.length();i++){
			if(x.charAt(i)==' '){
				y++;
			}
			else{
				if(z[y]>0)
					z[y]=z[y]*10+x.charAt(i)-'0';
				else
					z[y]+=x.charAt(i)-'0';
			}
		}

		w[0]=z[1]+z[2];
		w[1]=z[1]+z[3];
		w[2]=z[4]+z[2];
		w[3]=z[4]+z[3];

		for(int i=0;i<4;i++){
			if(w[i]>max)
				max=w[i];
			if(w[i]<min)
				min=w[i];
		}
		System.out.println(min);
		System.out.println(max);
		System.out.println(max-min);
		System.out.println(z[0]-(max-min));
		System.out.println((z[0])*(z[0]-(max-min)));
		scan.close();
	}
}

import java.util.*;
import java.io.*;

public class CF675B{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static void soln(){
		int n = nextInt();
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();
		int d = nextInt();
		int ab = a+b;
		int ac = a+c;
		int bd = b+d;
		int cd = c+d;
		int max = Math.max(ab,Math.max(ac,Math.max(bd,cd)));
		int min = Math.min(ab,Math.min(ac,Math.min(bd,cd)));
		int i =0;
		for (i=n; i>=1; i--) {
			int temp = min+i-max;
			if(temp>=1 && temp<=n)
				continue;
		}
		int left = i+1;
		for (i=1; i<n; i++) {
			int temp = max+i-min;
			if(temp>=1 && temp<=n)
				continue;
		}
		int right = i-1;
		int ans = (n)*(right-left+1);
		pw.println(ans);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class abc {

	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int minAC = a+c+1 , maxAC = minAC+n-1;
		int minCD = c+d+1 , maxCD = minCD+n-1;
		int minDB = d+b+1 , maxDB = minDB+n-1;
		int minBA = b+a+1 , maxBA = minBA+n-1;
		int min = Math.max(minAC, minCD);
		min = Math.max(min, minDB);
		min = Math.max(min, minBA);
		int max = Math.min(maxAC, maxCD);
		max = Math.min(max, maxDB);
		max = Math.min(max, maxBA);
		long res = (max - min +1)*((long)n);
		System.out.println(res);

	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {

			br = new BufferedReader(new InputStreamReader(s));

		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.util.Scanner;

public class Q675B_RestoringPainting {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int x1_min = max(1, 1 + c - b, 1 + c + d - b - a, 1 + d - a);
        int x1_max = min(n, n + c - b, n + c + d - b - a, n + d - a);
        if (x1_min > x1_max)
            System.out.println(0);
        else
            System.out.println((x1_max - x1_min + 1) * n);
    }

    public static int max(int... as) {
        int max = as[0];
        for (int a : as) {
            if (a > max)
                max = a;
        }
        return max;
    }

    public static int min(int... as) {
        int min = as[0];
        for (int a : as) {
            if (a < min)
                min = a;
        }
        return min;
    }
}

import java.util.*;
public class CF675B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n,a,b,c,d,x,y1,y2,y3,y4;
		n=sc.nextInt();
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		d=sc.nextInt();
		int ans=0;

			for(y1=1;y1<=n;y1++)
			{
				y2=c-b+y1;
				y3=a+c-b-d+y1;
				y4=a-d+y1;
				if(y2>0&&y3>0&&y4>0&&y2<=n&&y3<=n&&y4<=n)
				{
					ans++;
					//System.out.println(y1+" "+y2+" "+y3+" "+y4+""+x);
				}
				if(y2>n||y3>n||y4>n)
					break;
			}

		System.out.println(ans*n);
	}

}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        long r = 0L;
        for(int w=1;w<=n;w++) {
            int x = w + b - c;
            int y = w + a - d;
            int z = x + a - d;

            if(1<=x && x<=n && 1<=y && y<=n && 1<=c && c<=n) {
                ++r;
            }
        }

        r *= n;
        System.out.println(r);
    }
}

import java.util.Scanner;

public class Main {
	static int n;
	static int a, b, c, d;
	static int s1, s2, s3, s4, s5;
	static int s1Old, s2Old, s3Old, s4Old, s5Old;
	static int Block1; // Block1 = a + b + s1 + s2
	static int Block2; // Block2 = b + d + s2 + s3
	static int Block3; // Block3 = a + c + s2 + s4
	static int Block4; // Block4 = c + d + s2 + s5
	static int distinctSquares = 0;

	static int Block1Calculate () {
		Block1 = a + b + s1 + s2;
		return Block1;
	}

	static int Block2Calculate () {
		Block2 = b + d + s2 + s3;
		return Block2;
	}

	static int Block3Calculate () {
		Block3 = a + c + s2 + s4;
		return Block3;
	}

	static int Block4Calculate () {
		Block4 = c + d + s2 + s5;
		return Block4;
	}

	static void setOldValuesminus1() {
		s1Old = s1;
		s2Old = s2;
		s3Old = s3;
		s4Old = s4;
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		sc.close();

		int x1 = - a + d;
		int x2 = - b + c;
		int x3 = - a - b + c + d;

		for (s1 = 1; s1 <= n; s1++) {
			int s3 = s1 - x1;
			int s4 = s1 - x2;
			int s5 = s1 - x3;
			if ( (s3 <= n) && ( s4 <= n) && ( s5 <= n)
				&& (s3 > 0) && ( s4 > 0) && ( s5 > 0) ) {
				distinctSquares++;
			}
		}

		distinctSquares *= 3;

		System.out.println(distinctSquares);
	}
}

import java.util.*;
import java.io.*;
public class RestoringPainting{
	public static void main(String []args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int topleft, count = 0;
		//, bottomleft, topright, bottomright;
		for( topleft = 1; topleft <= n; topleft++){
				//bottomleft = topleft + a - d;
				//bottomright = topleft + a + b -c -d;
				//topright = topleft + b - c;
				if(((topleft + a - d) > 0) && ((topleft + a + b - c - d) > 0) && ((topleft + b - c) > 0) && ((topleft + a - d) < n) && ((topleft + a + b - c - d) < n) && ((topleft + b - c) < n))
					count++;
		}
		System.out.println(count*n);
	}
}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
	public void print(){
		for(int i=0;i<cells.length;i++){
			for(int j=0;j<cells[0].length;j++){
				System.out.print(cells[i][j]+" ");
			}
			System.out.println();
		}
	}
	public int check(){
			int nr=-1;
			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
			for(int i=1;i<=maxn;i++){
				if((sum1+i)-(sum2)>=0 && (sum1+i)-(sum3)>=0 && (sum1+i)-(sum4)>=0 ){
					nr++;
				}
			}
			return nr*maxn;
		}

	public static void main(String args[]){
		Painting art=new Painting();
		art.print();
		System.out.println(art.check());
	}
}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
//	public void print(){
//		for(int i=0;i<cells.length;i++){
//			for(int j=0;j<cells[0].length;j++){
//				System.out.print(cells[i][j]+" ");
//			}
//			System.out.println();
//		}
//	}
	public int check(){
			int nr=0;
			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
			for(int i=1;i<=maxn;i++){
				if((sum1+i)-(sum2)>=0 && (sum1+i)-(sum3)>=0 && (sum1+i)-(sum4)>=0 &&
						(sum1+i)-(sum2)<=maxn && (sum1+i)-(sum3)<=maxn && (sum1+i)-(sum4)<=maxn){
					nr++;
				}
			}

	return nr*maxn;
}

	public static void main(String args[]){
		Painting art=new Painting();
		//art.print();
		System.out.println(art.check());
	}
}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
//	public void print(){
//		for(int i=0;i<cells.length;i++){
//			for(int j=0;j<cells[0].length;j++){
//				System.out.print(cells[i][j]+" ");
//			}
//			System.out.println();
//		}
//	}
	public int check(){
			int nr=0;
			if(maxn==1){
				return 0;
			}
			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
//			for(int i=1;i<=maxn;i++){
//				if((sum1+i)-(sum2)>=0 && (sum1+i)-(sum3)>=0 && (sum1+i)-(sum4)>=0 &&
//						(sum1+i)-(sum2)<=maxn && (sum1+i)-(sum3)<=maxn && (sum1+i)-(sum4)<=maxn){
//					nr=nr+maxn;
//				}
//			}
//			return nr;
			for(int a=1;a<=maxn;a++){
				for(int b=1;b<=maxn;b++){
					for(int c=1;c<=maxn;c++){
						for(int d=1;d<=maxn;d++){
							for( int e=0;e<=maxn;e++){
								if(sum1+a+c==sum2+b+c &&
										sum1+a+c==sum3+d+c &&
												sum1+a+c==sum4+e+c){
									nr++;

								}
							}
						}
					}
				}

			}
			return nr;
		}

	public static void main(String args[]){
		Painting art=new Painting();
		//art.print();
		System.out.println(art.check());
	}
}

import java.io.*;
import java.util.*;
public class Restoring_Painting_1400 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()),
				c = Integer.parseInt(st.nextToken()), d = Integer.parseInt(st.nextToken());
		int topleft = a + b, topright = a + c, botleft = b + d, botright = c + d;
		int max = Math.max(topleft, Math.max(topright, Math.max(botleft, botright)));
		int min = Math.min(topleft, Math.min(topright, Math.min(botleft, botright)));
		System.out.println((long)n * (long)(n  - (max - min)));
	}
}

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
		int n=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		int ans=1;
		ans*=n;
		if(n<=c-b||n<=d-a||n<=d+c-a-b)ans=0;
		else{
			ans*=Math.min(Math.min((n+b-c),(n+a-d)),(n+a+b-d-c));
		}
		System.out.println(ans);

	}

}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
//	public void print(){
//		for(int i=0;i<cells.length;i++){
//			for(int j=0;j<cells[0].length;j++){
//				System.out.print(cells[i][j]+" ");
//			}
//			System.out.println();
//		}
//	}
	public int check(){
			int nr=0;
			if(maxn==1){
				return 0;
			}
			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
			for(int i=1;i<=maxn;i++){
				if((sum1+i)-(sum2)>=0 && (sum1+i)-(sum3)>=0 && (sum1+i)-(sum4)>=0 &&
						(sum1+i)-(sum2)<=maxn && (sum1+i)-(sum3)<=maxn && (sum1+i)-(sum4)<=maxn){
					nr=nr+1;
				}
			}
//			return nr;
//			for(int a=1;a<=maxn;a++){
//				for(int b=1;b<=maxn;b++){
//					if(sum1+a==sum2+b){
//						for(int e=1;e<=maxn;e++){
//							if(sum1+a==sum4+e){
//								for(int d=1;d<=maxn;d++){
//									if(sum1+a==sum3+d){
//										nr++;
//
//									}
//								}
//
//							}
//
//						}
//					}
//				}
//			}

	return nr*maxn;
}

	public static void main(String args[]){
		Painting art=new Painting();
		//art.print();
		System.out.println(art.check());
	}
}

import java.util.*;
public class CF675B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n,a,b,c,d,x,y1,y2,y3,y4;
		n=sc.nextInt();
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		d=sc.nextInt();
		double ans=0;

			for(y1=1;y1<=n;y1++)
			{
				y2=c-b+y1;
				y3=a+c-b-d+y1;
				y4=a-d+y1;
				if(y2>n||y3>n||y4>n)
					break;
				if(y2>0&&y3>0&&y4>0&&y2<=n&&y3<=n&&y4<=n)
				{
					ans++;
					//System.out.println(y1+" "+y2+" "+y3+" "+y4+""+x);
				}

			}

		System.out.println(ans*n);
	}

}

import java.util.Scanner;

public class Train {
	private static Scanner cin = new Scanner(System.in);
	public static void main(String[] args){
		int a,b,c,d,n;
		long res = 0;
		n = cin.nextInt();
		a = cin.nextInt();
		b = cin.nextInt();
		c = cin.nextInt();
		d = cin.nextInt();
		int p, q;
		if(a > d) p = a - d;
		else p = d - a;
		if(b > c) q = b - c;
		else q = c - b;
		res = n - p - q;
		res = res * n;
		System.out.println(res);
	}

}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);

    public void solve() {
        long n = in.nl();
        out.println(n * (n - 1));
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) {
        new B().solve();
    }
}

import java.util.Scanner;

/**
 * Created by dhreeraj on 4/2/16.
 */
public class ChefBalloons {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int x1,x3,x4;
        int count=0;
        if(b==c & a!=d){
            for(int  i=1;i<=n;i++){
                if((d-a+i)<=n && (d-a+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        }else if(a==d && b!=c){
            for(int  i=1;i<=n;i++){
                if((b-c+i)<=n && (b-c+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        } else{
            for(int i=1;i<=n;i++){
                x1=d-a+i;
                x4=b-c+i;
                x3=x1+b-c;
                if((x1<=n && x1>=1) && (x3<=n && x3>=1) && (x4<=n && x4>=1)){
                    count++;
                }
            }
            System.out.println(n*count);
        }

    }
}

//package myPackage;

import java.util.*;
import java.math.*;
import java.lang.Math;
import static java.lang.System.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long A = a + b;
		long B = b + d;
		long C = d + c;
		long D = a + c;
		long mmax = Math.max(A, Math.max(B, Math.max(C, D)));
		long mmin = Math.min(A, Math.min(B, Math.min(C, D)));
		out.println((n + (mmin - mmax)) * n);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n;
            long[] arr = new long[4];

            n = in.nextInt();

            for (int i = 0; i < 4; i++) {
                arr[i] = in.nextInt();
            }

            long ways = 0;

            if (arr[0] == arr[1] && arr[2] == arr[0] && arr[3] == arr[0]) {
                ways = n * n;
            } else if (arr[0] == arr[2]) {
                ways = n * (n - Math.abs(arr[1] - arr[3]));
            } else if (arr[1] == arr[3]) {
                ways = n * (n - Math.abs(arr[0] - arr[2]));
            } else if (arr[0] == arr[1]) {
                ways = n * (n - Math.abs(arr[2] - arr[3]));
            } else if (arr[1] == arr[2]) {
                ways = n * (n - Math.abs(arr[0] - arr[3]));
            } else if (arr[2] == arr[3]) {
                ways = n * (n - Math.abs(arr[0] - arr[1]));

            } else if (arr[3] == arr[0]) {
                ways = n * (n - Math.abs(arr[1] - arr[2]));
            } else {
                long Min = 0;
                Min += Math.abs(arr[0] - arr[2]);
                Min += Math.abs(arr[1] - arr[3]);
                ways = n * (n - Min);
            }

            out.println(Math.max(ways, 0));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by mohannadhassan on 5/16/16.
 */
public class RestoringPainting {

    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        int c = Integer.parseInt(input[3]);
        int d = Integer.parseInt(input[4]);

        int co1 = b - c;
        int co2 = a - d;
        int co3 = a + b - c - d;

        int min1 = 1;
        int min2 = n;

        int cos [] = {co1, co2, co3};
        for (int temp : cos) {
            if (1 - temp > min1) {
                min1 = 1 - temp;
            }
            if (n - temp < min2) {
                min2 = n - temp;
            }
        }

        System.out.println((min2 - min1 + 1) * n);

    }
}

import java.util.Scanner;

public class RestoringPainting {

	static boolean range(int x, int n) {
		if(x>=1 && x<=n)
			return true;
		return false;
	}
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a =  sc.nextInt();
		int b =  sc.nextInt();
		int c =  sc.nextInt();
		int d =  sc.nextInt();

		int m = 0;
		for (int x1=1; x1<=n; ++x1) {
			int x3 = x1+b-c;
			int x7 = x1+a-d;
			int x9 = x1+a+b-c-d;

			if(range(x3, n) && range(x7, n) && range(x9, n))
				m++;
		}
		System.out.println(n*m);

	}
}

import java.io.IOException;
import java.io.StreamTokenizer;

/**
 * Created by abragin on 5/9/2016.
 */
public class B {

    public static void main(String[] args) throws IOException {
        final StreamTokenizer tokenizer = new StreamTokenizer(System.in);
        tokenizer.nextToken();
        final int n = (int) tokenizer.nval;
        tokenizer.nextToken();
        final int a = (int) tokenizer.nval;
        tokenizer.nextToken();
        final int b = (int) tokenizer.nval;
        tokenizer.nextToken();
        final int c = (int) tokenizer.nval;
        tokenizer.nextToken();
        final int d = (int) tokenizer.nval;

        int res = 0;
        for (int x5 = 1; x5 <= n; x5++) {
            final int x1 = x5 + d - a + c - b;
            final int x2 = x5 + d - a;
            final int x3 = x5 + c - b;
            if (validateRes(n, x1, x2, x3)) {
                res++;
            }
        }

        System.out.println(n * res);
    }

    private static boolean validateRes(int n, int x1, int x2, int x3) {
        return x1 > 0 && x1 <= n && x2 > 0 && x2 <= n && x3 > 0 && x3 <= n;
    }
}

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(new BufferedInputStream(System.in));
		int n = cin.nextInt();
		int a = cin.nextInt();
		int b = cin.nextInt();
		int c = cin.nextInt();
		int d = cin.nextInt();
		int x[] = new int[5];
		x[1] = a + b;
		x[2] = a + c;
		x[3] = b + d;
		x[4] = c + d;
		int cnt = 0;
		for (int i = 1; i <= n; ++i) {
			int l = 0, r = 4*n+1;
			for (int j = 1; j <= 4; ++j) {
				l = Math.max(l, i + x[j] + 1);
				r = Math.min(r, i + x[j] + n);
//				System.out.printf("x[%d] = %d\n", j, x[j]);
			}
//			System.out.println("l = " + l + ", r = " + r);
			cnt += (r-l+1);
		}
		System.out.println(cnt);
		cin.close();
	}

}

	import java.util.*;
import java.io.*;
	public class Main {
		public static long mod= (long) (1e9 +7);
		public static void main(String args[]){
			InputReader s= new InputReader(System.in);
			OutputStream outputStream= System.out;
			PrintWriter out= new PrintWriter(outputStream);
			int n = s.nextInt();
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int d = s.nextInt();
			int diff = c+d - (a+b);
			int ans  = n * (n- diff);
			if(ans<0) out.println("0");
			else out.println(ans);
			out.close();
		}
		static class InputReader {

		    public BufferedReader reader;
		    public StringTokenizer tokenizer;

		    public InputReader(InputStream inputstream) {
		      reader = new BufferedReader(new InputStreamReader(inputstream));
		      tokenizer = null;
		    }

		    public String nextLine(){
		    	String fullLine=null;
		    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		            try {
		              fullLine=reader.readLine();
		            } catch (IOException e) {
		              throw new RuntimeException(e);
		            }
		            return fullLine;
		          }
		          return fullLine;
		    }
			public String next() {
		      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		        try {
		          tokenizer = new StringTokenizer(reader.readLine());
		        } catch (IOException e) {
		          throw new RuntimeException(e);
		        }
		      }
		      return tokenizer.nextToken();
		    }
			public long nextLong() {
			      return Long.parseLong(next());
			    }
		    public int nextInt() {
		      return Integer.parseInt(next());
		    }
		  }
		static class Pair implements Comparable<Pair>
		{
			long f,s;
			Pair(long ii, long cc)
			{
				f=ii;
				s=cc;
			}

			public int compareTo(Pair o)
			{
				return Long.compare(this.f, o.f);
			}

		}
		public static int gcd(int number1, int number2) {
			if(number2 == 0){
				return number1;
			}
			return gcd(number2, number1%number2);
		}
		public static int combinations(int n,int r){
			if(n==r) return 1;
			if(r==1) return n;
			if(r==0) return 1;
			return combinations(n-1,r)+ combinations(n-1,r-1);
		}
		public static long binomialCoeff(int n, int k)
		{
		    long C[][]= new long[n+1][k+1];
		    int i, j;

		    // Caculate value of Binomial Coefficient in bottom up manner
		    for (i = 0; i <= n; i++)
		    {
		        for (j = 0; j <= Math.min(i, k); j++)
		        {
		            // Base Cases
		            if (j == 0 || j == i)
		                C[i][j] = 1;

		            // Calculate value using previosly stored values
		            else
		                C[i][j] = C[i-1][j-1] + C[i-1][j];
		        }
		    }

		    return C[n][k];
		}
		public static int expo(int a, int b){
		    if (b==1)
		        return a;
		    if (b==2)
		        return a*a;

		    if (b%2==0){
		            return expo(expo(a,b/2),2);
		    }
		    else{
		        return a*expo(expo(a,(b-1)/2),2);
		    }
		}

		public static void sieve(int N){
			int arr[]= new int[N+1];
			for(int i=2;i<Math.sqrt(N);i++){
				if(arr[i]==0){
					for(int j= i*i;j<= N;j= j+i){
						arr[j]=1;
					}
				}
			}
			// All the i for which arr[i]==0 are prime numbers.
		}
	}

//Comment out before submit
//package Round353Div2.ProblemB;

/**
 * Created by evergreen on 5/16/16.
 */

/*
ID: najmul.1
LANG: JAVA
TASK: RestoringPainting
*/

import java.io.*;
import java.util.*;

public class RestoringPainting {

    private static MyScanner input;
    private static PrintWriter output;

    private static void solve() {

        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d = input.nextInt();

        int x = c - b;
        int y = d - a;
        int z = c + d - a - b;

        int count = 0;

        for (int e = 1; e <= n; e++) {

            int f = e - x;
            int g = e - y;
            int h = e - z;

            if(isaBoolean(n, f) && isaBoolean(n, g) && isaBoolean(n, h)) {

                ++count;
            }
        }

        output.println(count * n);
        output.flush();
    }

    private static boolean isaBoolean(int n, int f) {
        return f >= 1 && f <= n;
    }

    public static void main(String[] args) throws FileNotFoundException {

        input = SmartInOut.getInitInput();
        output = SmartInOut.getInitOutput();

        solve();

        output.close();
    }
}

class SmartInOut {

    private static MyScanner input;
    private static PrintWriter output;

    private static String getFilePathPrefix() {

        String filePathPrefix = "";

        Class<? extends RestoringPainting> aClass = new RestoringPainting().getClass();
        Package aPackage = aClass.getPackage();

        if (aPackage != null) {
            String packageName = aPackage.getName();
            String partialPath = packageName.replace(".", "/");
            filePathPrefix = "src/" + partialPath + "/";
        }

        return filePathPrefix;
    }

    public static MyScanner getInitInput() throws FileNotFoundException {

        String filePath = getFilePathPrefix() + "RestoringPainting.in";
        File f = new File(filePath);
        input = f.exists() && !f.isDirectory() ? new MyScanner(filePath) : new MyScanner();
        return input;
    }

    public static PrintWriter getInitOutput() throws FileNotFoundException {

        String filePathPrefix = getFilePathPrefix();
        File f = new File(filePathPrefix + "RestoringPainting.in");
        String outputFilePath = filePathPrefix + "RestoringPainting.out";

        output = f.exists() && !f.isDirectory() ? new PrintWriter(outputFilePath) : new PrintWriter(System.out);
        return output;
    }
}

class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public MyScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    public List<String> readLineAsStringList() throws IOException {

        //Modify it if you need a different delimiter
        String delimiter = " ";
        String st = br.readLine();
        List<String> list = Arrays.asList(st.split(delimiter));
        return list;
    }

    public List<String> readStringList(int howMany) {

        List<String> list = new ArrayList<String>();
        while (howMany-- > 0) {

            String st = nextToken();
            list.add(st);
        }
        return list;
    }

    public List<Integer> readIntegerList(int howMany) {

        List<Integer> list = new ArrayList<Integer>();
        while (howMany-- > 0) {

            int st = nextInt();
            list.add(st);
        }
        return list;
    }

    public List<Double> readDoubleList(int howMany) {

        List<Double> list = new ArrayList<Double>();
        while (howMany-- > 0) {

            double st = nextDouble();
            list.add(st);
        }
        return list;
    }
}

class BasicUtility {

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItems(List<T> list) {

        String delimiter = " ";
        String formattedJoin = BasicUtility.joinItemsWithDelimiter(delimiter, list);

        return formattedJoin;
    }

    //you can join Strings, ints, longs, doubles etc
    public static <T> String joinItemsWithDelimiter(String delimiter, List<T> list) {

        String formattedJoin = "";
        int count = list.size();
        for (int i = 0; i < count - 1; ++i) {

            //Join all elements except last element
            formattedJoin += (list.get(i) + delimiter);
        }

        if (count > 1) {
            //Now join last element
            formattedJoin += list.get(count - 1);
        }

        //For Java 8
        //String formattedJoin = list.stream().map(i -> i.toString()).collect(Collectors.joining(delimiter));

        return formattedJoin;
    }

    public static <T> List<T> getCopyList(List<T> list) {

        List<T> copiedList = new ArrayList<T>(list);
        //For Java 8
        //List<T> copiedList = list.stream().collect(Collectors.toList());
        return copiedList;
    }
}

import java.util.*;
import java.io.*;

public class CF675B{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static void soln(){
		int n = nextInt();
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();
		int d = nextInt();
		int ab = a+b;
		int ac = a+c;
		int bd = b+d;
		int cd = c+d;
		int max = Math.max(ab,Math.max(ac,Math.max(bd,cd)));
		int min = Math.min(ab,Math.min(ac,Math.min(bd,cd)));
		int i =0;
		int right = Math.min(n+max-min,n);
		int left = Math.max(max+1-min,1);
		int ans = (n)*(right-left+1);
		pw.println(ans);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

import java.util.Scanner;

public class Painting {
	private int[][]cells;
	private int maxn;
	public Painting(){
		cells=new int[3][3];
		Scanner key=new Scanner(System.in);
		maxn=key.nextInt();
		cells[0][1]=key.nextInt();
		cells[1][0]=key.nextInt();
		cells[1][2]=key.nextInt();
		cells[2][1]=key.nextInt();

	}
//	public void print(){
//		for(int i=0;i<cells.length;i++){
//			for(int j=0;j<cells[0].length;j++){
//				System.out.print(cells[i][j]+" ");
//			}
//			System.out.println();
//		}
//	}
	public int check(){
			int nr=0;

			int sum1=cells[0][1]+cells[1][0];
			int sum2=cells[0][1]+cells[1][2];
			int sum3=cells[1][0]+cells[2][1];
			int sum4=cells[2][1]+cells[1][2];
			for(int i=1;i<=maxn;i++){

				if((sum1+i)-(sum2)>=1 && (sum1+i)-(sum3)>=1 && (sum1+i)-(sum4)>=1 &&
						(sum1+i)-(sum2)<=maxn && (sum1+i)-(sum3)<=maxn && (sum1+i)-(sum4)<=maxn){
					nr=nr+1;
					System.out.println(nr);
				}
			}
			return nr*maxn;

		}

	public static void main(String args[]){
		Painting art=new Painting();
		//art.print();
		System.out.println(art.check());
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class R353B {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int n = s.nextInt(), a = s.nextInt(), b = s.nextInt(), c = s.nextInt(), d = s.nextInt();
		int ab = a+b, ac = a+c, cd = c+d, db = d+b;
		long ans = 0;
//		System.out.printf("%d %d %d %d\n", ab, ac, cd, db);
		for(int i = 1; i <= n; i++) {
			int topLeft = ab+i, topRight = ac+i, bottomLeft = db+i, bottomRight = cd+i;
			int maxDif = Integer.MIN_VALUE;
			maxDif = Math.max(maxDif, Math.abs(topLeft-topRight)); maxDif = Math.max(maxDif, Math.abs(topRight-bottomLeft));
			maxDif = Math.max(maxDif, Math.abs(bottomLeft-bottomRight)); maxDif = Math.max(maxDif, Math.abs(bottomRight-topLeft));
			ans += n-maxDif;
		}
		System.out.println(ans);
	}
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int n, a, b, c, d;

	public void solve() {
		n = nextInt();
		a = nextInt();
		b = nextInt();
		c = nextInt();
		d = nextInt();

		int LT = a + b;
		int RT = a + c;
		int LB = b + d;
		int RB = c + d;

		long ans = 0;

		for (int i = 1; i <= n; i++) {
			int A = LT + i;
			int B = RT + i;
			int C = LB + i;
			int D = RB + i;

			int min = Math.min(A, Math.min(B, Math.min(C, D)));
			int max = Math.max(A, Math.max(B, Math.max(C, D)));

			ans += (n - Math.max(0, max- min));
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Test {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] str=new String[5];
        str=line.split(" ");
        int n=Integer.parseInt(str[0]);
        int a=Integer.parseInt(str[1]);
        int b=Integer.parseInt(str[2]);
        int c=Integer.parseInt(str[3]);
        int d=Integer.parseInt(str[4]);
        int p,q,s,t;
        int count=0;
        for(int i=1;i<=n;i++){
        	count++;
        	p=i;
        	s=a+p-d;
        	t=b+s-c;
        	q=b+p-c;
        	if(s<1||s>n||t<1||t>n||q<1||q>n){
        		count--;
        	}
        }
        System.out.println(n*count);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Arthur Gazizov - 2oo7 [Kazan FU #4.3]
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        private int n;
        private int[][] a = new int[3][3];

        private int get(int t) {
            a[1][1] = t;
            int sumLeft = 0;
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    sumLeft += a[i][j];
                }
            }
            int sumRight = 0;
            for (int i = 0; i < 2; i++) {
                for (int j = 1; j < 3; j++) {
                    sumRight += a[i][j];
                }
            }
            int sumLeftDown = 0;
            for (int i = 1; i < 3; i++) {
                for (int j = 0; j < 2; j++) {
                    sumLeftDown += a[i][j];
                }
            }
            int sumRightDown = 0;
            for (int i = 1; i < 3; i++) {
                for (int j = 1; j < 3; j++) {
                    sumRightDown += a[i][j];
                }
            }
            int max = MathUtils.max(sumLeft, sumRight, sumLeftDown, sumRightDown);
            int min = MathUtils.min(sumLeft, sumRight, sumLeftDown, sumRightDown);
            int a = max + 1;
            int b = min + n;
            if (b >= a) {
                return (b - a) + 1;
            } else {
                return 0;
            }
        }

        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            n = in.nextInt();
            a[0][1] = in.nextInt();
            a[1][0] = in.nextInt();
            a[1][2] = in.nextInt();
            a[2][1] = in.nextInt();
            int count = 0;
            for (int i = 1; i <= n; i++) {
                count += get(i);
            }
            out.print(count);
        }

    }

    static class FastScanner extends BufferedReader {
        boolean isEOF;

        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public FastScanner(InputStreamReader inputStreamReader) {
            super(inputStreamReader);
        }

        public int read() {
            try {
                int ret = super.read();
                if (isEOF && ret < 0) {
                    throw new InputMismatchException();
                }
                isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public static boolean isWhiteSpace(int c) {
            return c >= -1 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (!isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(Writer writer) {
            super(writer);
        }

        public FastPrinter(OutputStream out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static class MathUtils {
        public static final int max(int... values) {
            int ans = Integer.MIN_VALUE;
            for (int i = 0; i < values.length; i++) {
                ans = values[i] > ans ? values[i] : ans;
            }
            return ans;
        }

        public static final int min(int... values) {
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < values.length; i++) {
                ans = values[i] < ans ? values[i] : ans;
            }
            return ans;
        }

    }
}

import java.util.Scanner;

/**
 * Created by zaremba on 17.05.16.
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
        int result = 0;

        int[] array = {0, a, 0,
                       b, 0, c,
                       0, d, 0};

        for (int i = 1; i <= n; i++) {

            array[4] = i;

            for (int j = 1; j <= n; j++) {
                array[0] = j;

                int sum1 = array[4] + array[0] + array[1] + array[3];

                int sum2 = sum1 - (array[4] + array[1] + array[5]);
                if (sum2 < 0) {
                    System.out.println("0");
                    return;
                }
                if (sum2 == 0 || sum2 > n)
                    continue;

                int sum3 = sum1 - (array[4] + array[3] + array[7]);
                if (sum3 < 0) {
                    System.out.println("0");
                    return;
                }
                if (sum3 <= 0 || sum3 > n)
                    continue;

                int sum4 = sum1 - (array[4] + array[7] + array[5]);
                if (sum4 < 0) {
                    System.out.println("0");
                    return;
                }
                if (sum4 <= 0 || sum4 > n)
                    continue;

                result++;

            }

        }

        System.out.println(result);

    }
}

import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class RestoringPainting {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            while(testNumber-->0){
            	int n = in.nextInt();
            	int a = in.nextInt();
            	int b = in.nextInt();
            	int c = in.nextInt();
            	int d = in.nextInt();
            	long ans = 0;
            	ans = n*(Math.max(Math.abs(d-a) , Math.abs(c-b)) + 1);
            	out.println(ans);
            }
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
	        if (start > end) {
	            return;
	        }
	  		int mid = (start + end) / 2;
	        a.add(mid);
	        sortedArrayToBST(a, start, mid - 1);
	  		sortedArrayToBST(a, mid + 1, end);
	    }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(a%b==0)
                return b;
            return gcd(b , a%b);
        }
        public void print2d(int a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);

		int n=input.nextInt();
		int a=input.nextInt();
		int b=input.nextInt();
		int c=input.nextInt();
		int d=input.nextInt();
		int[]x=new int[4];
		int[]y=new int[5];

		y[0]=0;
		y[4]=a+b;
		y[1]=a+c;
		y[2]=b+d;
		y[3]=c+d;
		int max=0;
		int min=100000;
		for(int i=1;i<=4;i++){
			if(y[i]>max) max=y[i];
		}
		for(int i=1;i<=4;i++){
			if(y[i]<min) min=y[i];
		}
		int dif=max-min;
		if(n-dif<=0) System.out.print(0);
		else System.out.print((n-dif)*n);

	}

}

import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class test7 {
	@SuppressWarnings("resource")
	public static void main(String args[]){
		Scanner scanner=new Scanner(System.in);
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = scanner.nextInt();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int n1 = Math.abs(c-b)>Math.abs(d-a)?Math.abs(c-b):Math.abs(d-a);
		int n2 = Math.abs(d-a-c+b)>Math.abs(d-a+c-b)?Math.abs(d-a-c+b):Math.abs(d-a+c-b);
		int num1 = n1>n2?n1:n2;
		int num2 = 0;
		for(int i=1;i<=n;i++){
			if(num1+i<=n){
				num2++;
			}else{
				break;
			}
		}
		System.out.println(n*num2);

		out.close();

	}

}

import java.util.Scanner;

/**
 * Created by dhreeraj on 4/2/16.
 */
public class ChefBalloons {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int x1,x4;
        int count=0;
        if(b==c & a!=d){
            for(int  i=1;i<=n;i++){
                if((d-a+i)<=n && (d-a+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        }else if(a==d && b!=c){
            for(int  i=1;i<=n;i++){
                if((b-c+i)<=n && (b-c+i)>=1){
                    count++;
                }
            }
            System.out.println(n*count);
        } else{
            for(int i=1;i<=n;i++){
                x1=d-a+i;
                if((x1<=n && x1>=1) && ((x1+b-c)<=n && (x1+b-c)>=1)){
                    count++;
                }
            }
            System.out.println(n*count);
        }

    }
}

import java.io.*;
import java.util.*;

public class Main {
    private final static InputReader ir = new InputReader(System.in);
    private final static PrintWriter ow = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n = ir.ni();
        int a = ir.ni(), b = ir.ni(), c = ir.ni(), d = ir.ni();
        int s1 = a + b;
        int s2 = b + c;
        int s3 = c + d;
        int s4 = d + a;
        int max = Math.max(Math.max(s1, s2), Math.max(s3, s4));
        int min = Math.min(Math.min(s1, s2), Math.min(s3, s4));

        System.out.println(n * Math.max(0, n - max + min));
    }

}

class InputReader implements AutoCloseable {
    private final InputStream in;
    private int capacity;
    private byte[] buffer;
    private int len = 0;
    private int cur = 0;

    InputReader(InputStream stream) {
        this(stream, 100_000);
    }

    InputReader(InputStream stream, int capacity) {
        this.in = stream;
        this.capacity = capacity;
        buffer = new byte[capacity];
    }

    private boolean update() {
        if (cur >= len) {
            try {
                cur = 0;
                len = in.read(buffer, 0, capacity);
                if (len <= 0)
                    return false;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    private int read() {
        if (update())
            return buffer[cur++];
        else return -1;
    }

    public boolean isEmpty() {
        return !update();
    }

    private boolean isSpace(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == ' ';
    }

    private boolean isEscape(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == -1;
    }

    private int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    int ni() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    int nc() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        return c;
    }

    String ns(int initialCapacity) {
        StringBuilder res = new StringBuilder(initialCapacity);
        int c = readSkipSpace();
        do {
            res.append((char) (c));
            c = read();
        } while (!isEscape(c));
        return res.toString();
    }

    @Override
    public void close() throws IOException {
        in.close();
    }
}

import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        int a, b, c, d, n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        int res = 0;
        for (int i = a + b + 1; i <= a + b + n; ++i) {
            if (i - c - d > 0 && i - b - d > 0 && i - a - c > 0) {
                res++;
            }
        }
        System.out.println(res * n);
    }
}

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ali Dman
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
        int max = scan.nextInt();

        int sum = 0, dif = 0, x;
        for (int i = 0; i < 4; i++) {
            x = scan.nextInt();
            sum += x;
            dif += (max - x);
        }
        if (max == 1) {
            System.out.println(1);
        } else {
            System.out.println(sum - dif);
        }

    }

}

import java.util.Scanner;

public class Train {
	private static Scanner cin = new Scanner(System.in);
	public static void main(String[] args){
		int a,b,c,d,n;
		long res = 0;
		n = cin.nextInt();
		a = cin.nextInt();
		b = cin.nextInt();
		c = cin.nextInt();
		d = cin.nextInt();
		int p, q;
		if(a > d) p = a - d;
		else p = d - a;
		if(b > c) q = b - c;
		else q = c - b;
		res = n - p - q;
		res = res * n;
		System.out.println(res);
	}

}

import java.io.*;
import java.util.*;

public class B {

    public static void main(String args[]) throws IOException
    {
        //InputReader in = new InputReader(System.in);
	PrintWriter w = new PrintWriter(System.out);
        Scanner in = new Scanner(System.in);
        double n = in.nextDouble();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        double diff1 = Math.abs((a+b) - (c+d));
        double diff2 = Math.abs((b+d) - (c+a));
        double x = Math.ceil(n/diff1) -1;
        double y = Math.ceil(n/diff2) -1;
        if(diff1 == diff2)
        {
        int ans = (int)(n*x);
        w.println(ans);
        }
        else if(diff1 < diff2)
        {
        int ans = (int)(n*x);
        w.println(ans);
        }
        else if(diff2 < diff1)
        {
        int ans = (int)(n*y);
        w.println(ans);
        }

        w.close();
    }

      static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner (System.in);

 		int n = scan.nextInt();

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();

		int min = Math.max(c+d,c+a);
		min = Math.max(min ,b+d);

		int count=0;

		for (int i=1; i<=n; ++i)
			for (int j=1; j<=n; ++j)
				if (i+j+a+b>min+j)
					count++;

		System.out.println(count);

 	}

}

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
		int n=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		long ans=1;
		ans*=n;
		if(n<=c-b||n<=d-a||n<=d+c-a-b)ans=0;
		else{
		ans*=(	Math.min(Math.min(Math.min(n+d-a,n+c-b),n+d+c-a-b),n)-Math.max(Math.max(Math.max(d-a+1,c-b+1),d+c-a-b+1),1)+1);
		}
		System.out.println(ans);

	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n;
            long[] arr = new long[4];

            n = in.nextInt();

            for (int i = 0; i < 4; i++) {
                arr[i] = in.nextInt();
            }

            long ways = 0;

            if (arr[0] == arr[1] && arr[2] == arr[0] && arr[3] == arr[0]) {
                ways = n * n;
            } else if (arr[0] == arr[2]) {
                ways = n * (n - Math.abs(arr[1] - arr[3]));
            } else if (arr[1] == arr[3]) {
                ways = n * (n - Math.abs(arr[0] - arr[2]));
            } else if (arr[0] == arr[1]) {
                ways = n * (n - Math.abs(arr[2] - arr[3]));
            } else if (arr[1] == arr[2]) {
                ways = n * (n - Math.abs(arr[0] - arr[3]));
            } else if (arr[2] == arr[3]) {
                ways = n * (n - Math.abs(arr[0] - arr[1]));

            } else if (arr[3] == arr[0]) {
                ways = n * (n - Math.abs(arr[1] - arr[2]));
            } else {
                long Max = 0;
                long Min = Long.MAX_VALUE;
                for (long val : arr) {
                    Max = Math.max(val, Max);
                    Min = Math.min(val, Min);
                }
                ways = n * (n - (Max - Min));
            }

            out.println(Math.max(ways, 0));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Prob675B {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String []numbers = br.readLine().split(" ");
		int n = Integer.parseInt(numbers[0]);
		int a = Integer.parseInt(numbers[1]);
		int b = Integer.parseInt(numbers[2]);
		int c = Integer.parseInt(numbers[3]);
		int d = Integer.parseInt(numbers[4]);

		int adDifference = a>=d?(a-d):(d-a);
		int bcDifference = b>=c?(b-c):(c-b);

		int minimumIntersection = adDifference>=bcDifference?adDifference:bcDifference;
		System.out.println((n-minimumIntersection)*n);
	}

}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);

    public void solve() {
        int n = in.ni(), a = in.ni(), b = in.ni(), c = in.ni(), d = in.ni();
        int m = Math.max(a + b, a + c), k = Math.max(b + d, c + d);
        int max = Math.max(m, k);
        out.println((long) n * (long) Math.abs((n - max)));
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) {
        new B().solve();
    }
}

import java.io.*;
import java.util.*;
public class Main
{

	private void solve()throws IOException
	{
		int n=nextInt();
		int a=nextInt();
		int b=nextInt();
		int c=nextInt();
		int d=nextInt();
		long ans=0;
		for(int i=1;i<=n;i++)//value of square (2,2)
		{
			int l,r;//possible range of (1,1)
			int max=max(a+c+i,b+d+i,c+d+i);
			l=max+1-a-b-i;
			int min=min(a+c+i,b+d+i,c+d+i);
			r=min+n-a-b-i;
			if(l>=1 && l<=n && r>=1 && r<=n)
				ans+=r-l+1;
		}
		out.println(ans);
	}
	int max(int ...a)
	{
		int max=0;
		for(int i:a)
			max=Math.max(max,i);
		return max;
	}
	int min(int ...a)
	{
		int min=(int)(1e9+1);
		for(int i:a)
			min=Math.min(min,i);
		return min;
	}

	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a = s.nextInt(); int b = s.nextInt();
		int c = s.nextInt(); int d = s.nextInt();
		int[] dr = new int[4];
		dr[0] = a+b; dr[1] = a+c; dr[2] = b+d; dr[3] = c+d;
		Arrays.sort(dr);
		int min = dr[0];  int max = dr[3];
		System.out.println(dr[0]+" "+dr[1]+" "+dr[2]+" "+dr[3]);
		long res = n;
		if(n-(max-min)>=0)
			res*= n-(max-min);
		else if(max-min > n)
			res = 0;

		System.out.println(res);

	}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int n,a,b,c,d;
		n=Integer.parseInt(st.nextToken());
		a=Integer.parseInt(st.nextToken());
		b=Integer.parseInt(st.nextToken());
		c=Integer.parseInt(st.nextToken());
		d=Integer.parseInt(st.nextToken());

		int max=-1,e,f,g,h,min=Integer.MAX_VALUE;

		max=Math.max(a+b,a+c);
		max=Math.max(max,b+d);
		max=Math.max(max,c+d);

		min=Math.min(a+b,a+c);
		min=Math.min(min,b+d);
		min=Math.min(min,c+d);

	//	System.out.println(max+" "+min);

		int cnt=0;

		int valMax,valMin=1;

		while(true){
			valMax=max+valMin-min;
			if(valMax>n){
				break;
			}
			else{
				cnt++;
				valMin++;
			}

		}

		System.out.println(cnt*n);
	}
}

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        long r = 0L;
        for(int w=1;w<=n;w++) {
            int x = w + b - c;
            int y = w + a - d;
            int z = x + a - d;

            if(1<=x && x<=n && 1<=y && y<=n && 1<=c && c<=n) {
                ++r;
            }
        }

        r *= n;
        System.out.println(r);
    }
}

import java.util.*;
import java.io.*;
public class RestoringPainting{
	public static void main(String []args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int topleft, count = 0;
		long counter;
		//, bottomleft, topright, bottomright;
		for( topleft = 1; topleft <= n; topleft++){
				//bottomleft = topleft + a - d;
				//bottomright = topleft + a + b -c -d;
				//topright = topleft + b - c;
				if(((topleft + a - d) > 0) && ((topleft + a + b - c - d) > 0) && ((topleft + b - c) > 0) && ((topleft + a - d) <= n) && ((topleft + a + b - c - d) <= n) && ((topleft + b - c) <= n))
					count++;
		}
		counter = count*n;
		System.out.println();
	}
}

import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();

		int count=0;

		//int tempw=0,tempz=0,tempy=0;

		for(int x=1;x<=n;x++){
			int w=x+a+b-c-d;
			int z=x+a-d;
			int y=x+b-c;

			//(w!=tempw)&&(z!=tempz)&&(y!=tempy)&&
			if((z>=1)&&(w>=1)&&(y>=1)&&(w<=n)&&(z<=n)&&(y<=n)){
				count++;
			}

			//tempw=w;
			//tempz=z;
			//tempy=y;
		}

		count=count*n;

		System.out.println(count);

	}

}

import java.io.*;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Solver {

	private void run(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		HashSet<Long> found = new HashSet<Long>();
		for (int x1 = 1; x1 <= n; x1++) {
			int x2 = x1 - c + b;
			int x4 = x1 - d + a;
			int x5 = x4 + b - c;
			if (inRange(x2, 1, n) && inRange(x4, 1, n) && inRange(x5, 1, n)) {
				long mask = ((x1 * 100000L) + x2) * 100000L + x4;
				found.add(mask);
			}
		}
		out.println(found.size() * n);
	}

	private boolean inRange(int k, int a, int b) {
		return k >= a && k <= b;
	}

	public static void main(String[] args) {
		Solver solver = new Solver();
		InputReader in;
		if (LOCAL) {
			in = new InputReader(solver.getClass().getResourceAsStream("input"));
		} else {
			in = new InputReader(System.in);
		}
		PrintWriter out = new PrintWriter(System.out);
		solver.run(in, out);
		out.flush();
		out.close();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

	private static final boolean LOCAL = false;
}

import java.io.*;
import java.util.StringTokenizer;

public class B {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = in(), a = in(), b = in(), c = in(), d = in(), r = 0;
        for (int x1 = 1; x1 <= n; x1++) {
            int k = x1 + a + b, x2 = k - a - c, x3 = k - b - d, x4 = k - c - d;
            if (x2 > 0 && x3 > 0 && x4 > 0) {
                r += n;
            }
        }
        out.println(r);
        out.flush();
    }

    public static int in() throws IOException {
        return Integer.parseInt(next());
    }

    public static long inl() throws IOException {
        return Long.parseLong(next());
    }

    public static double ind() throws IOException {
        return Double.parseDouble(next());
    }

    public static String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public static boolean nextPerm(int[] a) {
        int j = a.length - 1, k = j, r = j;
        for (; j > 0; j--)
            if (a[j - 1] < a[j]) break;
        if (j == 0) return false;
        for (; k > j; k--)
            if (a[j - 1] < a[k]) break;
        swap(a, j - 1, k);
        while (j < r) swap(a, j++, r--);
        return true;
    }

    public static void swap(int[] a, int i, int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(char[] a, int i, int j) {
        char t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(long[] a, int i, int j) {
        long t = a[i];
        a[i] = a[j];
        a[j] = t;
    }
}

import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();

		int count=0;

		int tempw=0,tempz=0,tempy=0;

		for(int x=1;x<=n;x++){
			int w=x+a+b-c-d;
			int z=x+a-d;
			int y=x+b-c;

			if((w!=tempw)&&(z!=tempz)&&(y!=tempy)&&(z>=1)&&(w>=1)&&(y>=1)){
				count++;
			}

			tempw=w;
			tempz=z;
			tempy=y;
		}

		count=count*n;

		System.out.println(count);

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Prob675B {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String []numbers = br.readLine().split(" ");
		long n = Integer.parseInt(numbers[0]);
		long a = Integer.parseInt(numbers[1]);
		long b = Integer.parseInt(numbers[2]);
		long c = Integer.parseInt(numbers[3]);
		long d = Integer.parseInt(numbers[4]);
		long smallerBound = 0;
		long largerBound = 0;

		if(a<d)
			//smallerBound towards A and diff+1
			smallerBound = d-a+1;
		else
			//smallerBound towards D and diff+1
			smallerBound = a-d+1;

		if(b<c)
			//largerBound towards C and N-diff
			largerBound = n-(c-b);
		else
			//largerBound towards B and N-diff
			largerBound = n-(b-c);

			long answer = largerBound>smallerBound?(largerBound-smallerBound+1)*n:0;

		System.out.println(answer);
	}

}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);

    public void solve() {
        int n = in.ni(), a = in.ni(), b = in.ni(), c = in.ni(), d = in.ni();
        int result = 0;
        for (int x = 1; x <= n; x++) {
            int y = x + b - c;
            int z = x + a - d;
            int w = a + y - d;
            if (1 <= y && y <= n && 1 <= z && z <= n && 1 <= w && w <= n) {
                result++;
            }
        }
        out.println(n * result);
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) {
        new B().solve();
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class RestoringPainting {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int[] l = new int[3];
		l[0] = 1 - b + c;
		l[1] = 1 - a + d;
		l[2] = 1 + c + d - b - a;
		int[] m = new int[3];
		m[0] = n + c - b;
		m[1] = n + d - a;
		m[2] = n + c + d - b - a;

		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 2; j++) {
				if (l[j] > l[j + 1]) {
					int temp = l[j];
					l[j] = l[j + 1];
					l[j + 1] = temp;
				}
				if (m[j] > m[j + 1]) {
					int temp = m[j];
					m[j] = m[j + 1];
					m[j + 1] = temp;
				}

			}

		int min = n - m[0];
		int max = l[2]-1;
		if (m[0] > n - 1)
			min = 0;
		if (l[2] <= 1)
			max = 0;
		System.out.println(n*n-(min+max)*n);
	}
}

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ali Dman
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
        int max = scan.nextInt();

        int sum = 0, dif = 0, x;
        for (int i = 0; i < 4; i++) {
            x = scan.nextInt();
            sum += x;
            dif += (max - x);
        }
        System.out.println(sum - dif);

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class abc {

	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int minAC = a+c+1 , maxAC = minAC+n-1;
		int minCD = c+d+1 , maxCD = minCD+n-1;
		int minDB = d+b+1 , maxDB = minDB+n-1;
		int minBA = b+a+1 , maxBA = minBA+n-1;
		int min = Math.max(minAC, minCD);
		min = Math.max(min, minDB);
		min = Math.max(min, minBA);
		int max = Math.min(maxAC, maxCD);
		max = Math.min(max, maxDB);
		max = Math.min(max, maxBA);
		System.out.println((max - min +1)*n);

	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {

			br = new BufferedReader(new InputStreamReader(s));

		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Prob675B {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String []numbers = br.readLine().split(" ");
		int n = Integer.parseInt(numbers[0]);
		int a = Integer.parseInt(numbers[1]);
		int b = Integer.parseInt(numbers[2]);
		int c = Integer.parseInt(numbers[3]);
		int d = Integer.parseInt(numbers[4]);
		int smallerBound = 0;
		int largerBound = 0;

		if(a<d)
			//smallerBound towards A and diff+1
			smallerBound = d-a+1;
		else
			//smallerBound towards D and diff+1
			smallerBound = a-d+1;

		if(b<c)
			//largerBound towards C and N-diff
			largerBound = n-(c-b);
		else
			//largerBound towards B and N-diff
			largerBound = n-(b-c);

		System.out.println((largerBound-smallerBound+1)*n);
	}

}

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// Use the Scanner class
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long res = go(n, a, b, c, d);
		System.out.println(res);
	}

	public static long go(int n, int a, int b, int c, int d) {
		long res = 0;
		int xmin = max(0,c + d - a - b + 1);
		int xmax = min(n, c + d - a - b + n);
		for (int x = xmin; x <= xmax; x++) {
			for (int y = 1; y <= n; y++) {
				int k = a + b + x;
				int k1 = k - b - d;
				int k2 = k - a - c;
				int k3 = k - c - d;
				if (k1 > 0 && k1 <= n && k2 > 0 && k2 <= n && k3 > 0 && k3 <= n)
					res++;
			}

		}
		return res;
	}

	private static int min(int a, int b) {
		return a > b ? b : a;
	}
	private static int max(int a, int b) {
		return a > b ? a : b;
	}
}

import java.util.*;

public class CF353C {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int x1=0,x2=0,x3=0,x4=0,x5=0,ans=0;
		for (int i=1;i<=n;i++){
			x1=i;
			x4=x1+a-d;
			x2=x1+b-c;
			x3=x1+b-c+a-d;
			if(x2>=1&&x2<=n &&x3>=1 &&x3<=n &&x4>=1 &&x4<=n)
				ans++;
		}
		System.out.println(ans*n);
	}
}

import java.util.Scanner;

/**
 * Created by zaremba on 17.05.16.
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
        int result = 0;
        long sum;

        for(int i = 1; i <= n; i++) {
            sum = a + b + i;
            long sum2 = sum - a - c;
            long sum3 = sum - b - d;
            long sum4 = sum - c - d;
            if(sum2 > 0 && sum2 <= n && sum3 > 0 && sum3 <= n && sum4 > 0 && sum4 <= n)
                result++;
        }

        System.out.println(result*2);

    }
}

import java.util.*;

/**
 * Created by Harrison Fang on 5/16/2016.
 */
public class RestoringPainting {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (solve(a, b, c, d, i)) {
                ans++;
            }
        }

        System.out.println(ans * n);
    }

    static boolean solve(int a, int b, int c, int d, int topleft) {
        int topright = topleft + b - c;
        int botleft = topleft + a - d;

        int botright = topright + a - d;
        // botleft + b - c;

        if (topright > 0 && botleft > 0 && botright > 0)
            return true;

        return false;
    }
}

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ali Dman
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new Scanner(System.in);
        int max = scan.nextInt();

        int sum = 0;
        for (int i = 0; i < 4; i++) {
            sum += scan.nextInt();
        }
        int min = 9;
        int dif = (max * 9) - min - sum;
        if (dif < 0) {
            System.out.println(1);
        } else {
            System.out.println(dif - max);
        }
    }

}

import java.util.Scanner;

public class B675 {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] a = new int[4];
    for (int i = 0; i < 4; i++) {
      a[i] = scanner.nextInt();
    }
    int s01 = a[0] + a[1];
    int[] d = {s01 - a[0] - a[2], s01 - a[1] - a[3], s01 - a[2] - a[3]};
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int k;
      for (k = 0; k < d.length; k++) {
        int di = d[k] + i;
        if (di < 1 || di > 100000)
          break;
      }
      if (k == d.length)
        ans++;
    }
    System.out.println(ans * n);
  }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class codeforcesq2
{
    public static void main (String[] args) throws java.lang.Exception
    {
        PrintWriter pw = new PrintWriter(System.out);
        // your code goes here
        //BufferedReader br = new BufferedReader(new FileReader("test.dat"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());

        int t = 0;
        int mint = 0;
        int Y[] =  new int[n];
        int yc = 0;
        int Z[] = new int[n];
        int zc = 0;
        for(int i = 1 ; i <= n ; i++)
        {
            int y = i + b - c;
            if(y >= 1 && y <= n){
                t++;
                Y[yc++] = y;
            }
        }
        mint = t;
        t = 0;
        for(int i = 1 ; i <= n ; i++)
        {
            int z = i + a - d;
            if(z >= 1 && z <= n){
                t++;
                Z[zc++] = z;
            }
        }
        if(mint > t)
        mint = t;
        t = 0;
        for(int i = 0 ; i < yc ; i++)
        {
            int w = a + Y[i] - d;
            if(w >= 1 && w <= n)
            t++;
        }
        if(mint > t)
        mint = t;
        t = 0;
        for(int i = 0 ; i < zc ; i++)
        {
            int w = b + Z[i] - c;
            if(w >= 1 && w <= n)
            t++;
        }
        if(mint > t)
        mint = t;

        System.out.println(mint*(long)n);
    }
}

/**
 *
 * @author meashish
 */
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;

public class Main {

    InputReader in;
    Printer out;

    long MOD = 1000000007;

    private void start() throws Exception {
        long n = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();
        long c = in.nextLong();
        long d = in.nextLong();

        long res = 0;
        for (int i = 1; i <= n; i++) {
            long sMin1 = i + a + b + 1;
            long sMax1 = i + a + b + n;

            long sMin2 = i + a + c + 1;
            long sMax2 = i + a + c + n;

            long sMin3 = i + d + b + 1;
            long sMax3 = i + d + b + n;

            long sMin4 = i + d + c + 1;
            long sMax4 = i + d + c + n;

            long min = Math.max(sMin1, Math.max(sMin2, Math.max(sMin3, sMin4)));
            long max = Math.min(sMax1, Math.min(sMax2, Math.min(sMax3, sMax4)));

            res += max - min + 1;
        }

        out.println(res);
    }

    class Bipartite {

        int m, n;
        boolean[][] graph;
        boolean seen[];
        int matchL[];   //What left vertex i is matched to (or -1 if unmatched)
        int matchR[];   //What right vertex j is matched to (or -1 if unmatched)

        public Bipartite(boolean[][] graph) {
            this.graph = graph;
            n = graph.length;
            m = graph[0].length;

            matchL = new int[m];
            matchR = new int[n];
            seen = new boolean[n];
        }

        int maximumMatching() {
            //Read input and populate graph[][]
            //Set m to be the size of L, n to be the size of R
            Arrays.fill(matchL, -1);
            Arrays.fill(matchR, -1);

            int count = 0;
            for (int i = 0; i < m; i++) {
                Arrays.fill(seen, false);
                if (bpm(i)) {
                    count++;
                }
            }
            return count;
        }

        boolean bpm(int u) {
            //try to match with all vertices on right side
            for (int v = 0; v < n; v++) {
                if (!graph[u][v] || seen[v]) {
                    continue;
                }
                seen[v] = true;
                //match u and v, if v is unassigned, or if v's match on the left side can be reassigned to another right vertex
                if (matchR[v] == -1 || bpm(matchR[v])) {
                    matchL[u] = v;
                    matchR[v] = u;
                    return true;
                }
            }
            return false;
        }

    }

    long power(long x, long n) {
        if (n <= 0) {
            return 1;
        }
        long y = power(x, n / 2);

        if ((n & 1) == 1) {
            return (((y * y) % MOD) * x) % MOD;
        }

        return (y * y) % MOD;
    }

    public int gcd(int a, int b) {
        a = Math.abs(a);
        b = Math.abs(b);
        return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
    }

    public Integer[] input(int n) {
        Integer a[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        return a;
    }

    public static void main(String[] args) throws Exception {
        InputReader in;
        PrintStream out;

//        in = new InputReader(new FileInputStream(new File("in.txt")));
//        out = new PrintStream("out.txt");
        in = new InputReader(System.in);
        out = System.out;

        Main main = new Main();

        main.in = in;
        main.out = new Printer(out);
//        main.out.autoFlush = true;

        main.start();
        main.out.flush();
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private static class Printer {

        PrintStream out;
        StringBuilder buffer = new StringBuilder();
        boolean autoFlush;

        public Printer(PrintStream out) {
            this.out = out;
        }

        public Printer(PrintStream out, boolean autoFlush) {
            this.out = out;
            this.autoFlush = autoFlush;
        }

        public void println() {
            buffer.append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void println(int n) {
            println(Integer.toString(n));
        }

        public void println(long n) {
            println(Long.toString(n));
        }

        public void println(double n) {
            println(Double.toString(n));
        }

        public void println(float n) {
            println(Float.toString(n));
        }

        public void println(boolean n) {
            println(Boolean.toString(n));
        }

        public void println(char n) {
            println(Character.toString(n));
        }

        public void println(byte n) {
            println(Byte.toString(n));
        }

        public void println(short n) {
            println(Short.toString(n));
        }

        public void println(Object o) {
            println(o.toString());
        }

        public void println(Object[] o) {
            println(Arrays.deepToString(o));
        }

        public void println(String s) {
            buffer.append(s).append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void print(char s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void print(String s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void flush() {
            try {
                BufferedWriter log = new BufferedWriter(new OutputStreamWriter(out));
                log.write(buffer.toString());

                log.flush();
                buffer = new StringBuilder();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private class Pair<T, U> implements Serializable {

        private T key;

        public T getKey() {
            return key;
        }

        private U value;

        public U getValue() {
            return value;
        }

        public Pair(T key, U value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }

            final Pair other = (Pair) obj;
            if (!this.key.equals(other.key)) {
                return false;
            }

            return this.value.equals(other.value);
        }

        @Override
        public int hashCode() {
            return key.hashCode() + 13 * value.hashCode();
        }
    }

    private class PairSet<T, S> {

        HashMap<T, HashSet<S>> map = new HashMap<>();

        public void add(T a, S b) {
            if (map.containsKey(a)) {
                map.get(a).add(b);
            }

            HashSet<S> set = new HashSet<>();
            set.add(b);
            map.put(a, set);
        }

        public boolean contains(T a, S b) {
            if (map.containsKey(a)) {
                return map.get(a).contains(b);
            }

            return false;
        }
    }

    private class Bit {

        int N;
        long ft1[], ft2[];

        Bit(int n) {
            N = n;
            ft1 = new long[N + 1];
            ft2 = new long[N + 1];
        }

        void update(long ft[], int p, long v) {
            for (; p <= N; p += p & (-p)) {
                ft[p] += v;
//                ft[p] %= MOD;
            }
        }

        void update(int a, int b, long v) {
            update(ft1, a, v);
            update(ft1, b + 1, -v);
            update(ft2, a, v * (a - 1));
            update(ft2, b + 1, -v * b);
        }

        long query(long ft[], int b) {
            long sum = 0;
            for (; b > 0; b -= b & (-b)) {
                sum += ft[b];
//                sum %= MOD;
            }

            return sum;
        }

        long query(int b) {
            return query(ft1, b) * b - query(ft2, b);
        }

        long query(int a, int b) {
            return query(b) - query(a - 1);
        }
    }

    public static Set<Integer[]> getPermutationsRecursive(Integer[] num) {
        if (num == null) {
            return null;
        }

        Set<Integer[]> perms = new HashSet<>();

        //base case
        if (num.length == 0) {
            perms.add(new Integer[0]);
            return perms;
        }

        //shave off first int then get sub perms on remaining ints.
        //...then insert the first into each position of each sub perm..recurse
        int first = num[0];
        Integer[] remainder = Arrays.copyOfRange(num, 1, num.length);
        Set<Integer[]> subPerms = getPermutationsRecursive(remainder);
        for (Integer[] subPerm : subPerms) {
            for (int i = 0; i <= subPerm.length; ++i) { // '<='   IMPORTANT !!!
                Integer[] newPerm = Arrays.copyOf(subPerm, subPerm.length + 1);
                for (int j = newPerm.length - 1; j > i; --j) {
                    newPerm[j] = newPerm[j - 1];
                }
                newPerm[i] = first;
                perms.add(newPerm);
            }
        }

        return perms;
    }
}

import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.io.InputStream;
import java.math.BigInteger;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;

        OutputStream outputStream = System.out;
        FastScanner in;
        PrintWriter out;

           in=new FastScanner(System.in);
            out=new PrintWriter(System.out);
        //in=new FastScanner(new FileInputStream(new File("C://Users//KANDARP//Desktop//coding_contest_creation (1).txt")));

        TaskC solver = new TaskC();
        long var=System.currentTimeMillis();
        solver.solve(1, in, out);
        /*if(System.getProperty("ONLINE_JUDGE")==null){
            out.println("["+(double)(System.currentTimeMillis()-var)/1000+"]");
        }*/
        out.close();
    }
}
class Pair {

    long x,y,index;
    long  r1,r2;
    HashMap<Double,Long> map=new HashMap<>();
    Pair(long x,long y,int index){
        this.x=x;
        this.y=y;
        this.index=index;
    }
    public String toString(){
        return this.x+" "+this.y+" ";
    }

}
class tupple{
    long x,y,z;
    ArrayList<String> list=new ArrayList<>();
    tupple(long x,long y,long z){
        this.x=x;
        this.y=y;
        this.z=z;
    }
    tupple(tupple cl){
        this.x=cl.x;
        this.y=cl.y;
        this.z=cl.z;
        this.list=cl.list;
    }
}
class Edge implements  Comparable<Edge>{
    int u;
    int v;
    int time;
    long cost;
    long wcost;
    public Edge(int u,int v,long cost,long wcost){
        this.u=u;
        this.v=v;
        this.cost=cost;
        this.wcost=wcost;
        time=Integer.MAX_VALUE;
    }
    public int other(int x){
        if(u==x)return v;
        return u;
    }
    @Override
    public int compareTo(Edge o) {
        // TODO Auto-generated method stub
        return Long.compare(cost, o.cost);
    }
}
class Ss{
    Integer a[]=new Integer[3];
    Ss(Integer a[]){
        this.a=a;

    }
    public int hashCode(){
        return a[0].hashCode()+a[1].hashCode()+a[2].hashCode();
    }
    public boolean equals(Object o){
        Ss x=(Ss)o;
        for(int i=0;i<3;i++){
            if(x.a[i]!=this.a[i]){
                return false;
            }
        }
        return true;

    }
}
class queary{
    int type;
    int l;
    int r;
    int index;
    queary(int type,int l,int r){
        this.type=type;
        this.l=l;
        this.r=r;
    }
}
class boat implements Comparable<boat>{
    int capacity;
    int index;
    boat(int capacity,int index)
    {
        this.capacity=capacity;
        this.index=index;
    }
    @Override
    public int compareTo(boat o) {
        // TODO Auto-generated method stub
        return this.capacity-o.capacity;
    }
}
class angle{
    double x,y,angle;
    int index;
    angle(int x,int y,double angle){
        this.x=x;
        this.y=y;
        this.angle=angle;
    }
}
class TaskC {
    static long mod=1000000007;
//    SegTree tree;
    //    int min[];
 /*   static int prime_len=1000010;
    static int prime[]=new int[prime_len];
    static long n_prime[]=new long[prime_len];
    static ArrayList<Integer> primes=new ArrayList<>();
    static{
        for(int i=2;i<=Math.sqrt(prime.length);i++){
            for(int j=i*i;j<prime.length;j+=i){

                prime[j]=i;

            }
        }
        for(int i=2;i<prime.length;i++){
            n_prime[i]=n_prime[i-1];
            if(prime[i]==0){
               n_prime[i]++;
            }

        }
    //  System.out.println("end");

    //  prime[0]=true;
    //  prime[1]=1;
    }
    /*
     *  long pp[]=new long[10000001];
            pp[0]=0;
            pp[1]=1;
            for(int i=2;i<pp.length;i++){
                if(prime[i]!=0){
                    int gcd=(int)greatestCommonDivisor(i/prime[i], prime[i]);
                    pp[i]=(pp[i/prime[i]]*pp[prime[i]]*gcd)/pp[(int)gcd];
                }
                else
                    pp[i]=i-1;
            }

}
     * */
    class Rmq {

		  int[] logTable;
		  int[][] rmq;
		  int[] a;

		  public Rmq(int[] a) {
		    this.a = a;
		    int n = a.length;

		    logTable = new int[n + 1];
		    for (int i = 2; i <= n; i++)
		      logTable[i] = logTable[i >> 1] + 1;

		    rmq = new int[logTable[n] + 1][n];

		    for (int i = 0; i < n; ++i)
		      rmq[0][i] = i;

		    for (int k = 1; (1 << k) < n; ++k) {
		      for (int i = 0; i + (1 << k) <= n; i++) {
		        int x = rmq[k - 1][i];
		        int y = rmq[k - 1][i + (1 << k - 1)];
		        rmq[k][i] = a[x] <= a[y] ? x : y;
		      }
		    }
		  }

		  public int minPos(int i, int j) {
		    int k = logTable[j - i];
		    int x = rmq[k][i];
		    int y = rmq[k][j - (1 << k) + 1];
		    return a[x] <= a[y] ? a[x] : a[y];
		  }

	}

   public void solve(int testNumber, FastScanner in, PrintWriter out) throws IOException {
	   long n=in.nextInt();
	   int a=in.nextInt();
	   int b=in.nextInt();
	   int c=in.nextInt();
	   int d=in.nextInt();
	   out.println((n-Math.max(c+d-a-b, c-b))*n);
   }

   static long greatestCommonDivisor (long m, long n){
       long x;
       long y;
       while(m%n != 0){
           x = n;
           y = m%n;
           m = x;
           n = y;
       }
       return n;
   }

 }

    /*
     * 	   long res[]=new long[m];
    	   int cl=1;
    	   int cr=0;
    	   for(int i=0;i<m;i++){
    		   int l=(int)q[i].x;
    		   int r=(int)q[i].y;
    		   while(cl>l){
    			   cl--;
    			   ans+=add(cl);

    		   }
    		   while(cl<l){
    			   ans-=remove(cl);
    			   cl++;

    		   }
    		   while(cr>r){
    			   ans-=remove(cr);
    			   cr--;
    		   }
    		   while(cr<r){
    			   cr++;
    			   ans+=add(cr);
    		   }
    		   res[(int)q[i].index]=ans;
    	   }
    	   for(int i=0;i<m;i++)
    		   out.println(res[i]);
     */
	   	 class SegmentTree2D {
          public  long max(int[][] t, int x1, int y1, int x2, int y2) {
            int n = t.length >> 1;
            x1 += n;
            x2 += n;
            int m = t[0].length >> 1;
            y1 += m;
            y2 += m;
            long res = 0;
            for (int lx = x1, rx = x2; lx <= rx; lx = (lx + 1) >> 1, rx = (rx - 1) >> 1)
              for (int ly = y1, ry = y2; ly <= ry; ly = (ly + 1) >> 1, ry = (ry - 1) >> 1) {
                if ((lx & 1) != 0 && (ly & 1) != 0) res = (res+ t[lx][ly]);
                if ((lx & 1) != 0 && (ry & 1) == 0) res = (res+ t[lx][ry]);
                if ((rx & 1) == 0 && (ly & 1) != 0) res =(res+t[rx][ly]);
                if ((rx & 1) == 0 && (ry & 1) == 0) res = (res+ t[rx][ry]);
              }
            return res;
          }

          public  void add(int[][] t, int x, int y, int value) {
            x += t.length >> 1;
            y += t[0].length >> 1;
            t[x][y] += value;
            for (int tx = x; tx > 0; tx >>= 1)
              for (int ty = y; ty > 0; ty >>= 1) {
                if (tx > 1) t[tx >> 1][ty] = (t[tx][ty]+t[tx ^ 1][ty]);
                if (ty > 1) t[tx][ty >> 1] = (t[tx][ty]+ t[tx][ty ^ 1]);
              }

//          for (int ty = y; ty > 1; ty >>= 1)
//            t[x][ty >> 1] = Math.max(t[x][ty], t[x][ty ^ 1]);
//          for (int tx = x; tx > 1; tx >>= 1)
//            for (int ty = y; ty > 0; ty >>= 1)
//              t[tx >> 1][ty] = Math.max(t[tx][ty], t[tx ^ 1][ty]);

//          for (int lx=x; lx> 0; lx >>= 1) {
//            if (lx > 1)
//              t[lx >> 1][y] = Math.max(t[lx][y], t[lx ^ 1][y]);
//            for (int ly = y; ly > 1; ly >>= 1)
//              t[lx][ly >> 1] = Math.max(t[lx][ly], t[lx][ly ^ 1]);
//          }
          }
    }
     class SegmentTree {

          // Modify the following 5 methods to implement your custom operations on the tree.
          // This example implements Add/Max operations. Operations like Add/Sum, Set/Max can also be implemented.
          long modifyOperation(long x, long y) {
            return  y;
          }

          // query (or combine) operation
          long queryOperation(long leftValue, long rightValue) {
            return (leftValue| rightValue);
          }

          long deltaEffectOnSegment(long delta, long segmentLength) {
            // Here you must write a fast equivalent of following slow code:
            // int result = delta;
            // for (int i = 1; i < segmentLength; i++) result = queryOperation(result, delta);
            // return result;
            return delta;
          }

          int getNeutralDelta() {
            return 0;
          }

          int getInitValue() {
            return 0;
          }

          // generic code
          int n;
          long[] value;
          long[] delta; // delta[i] affects value[i], delta[2*i+1] and delta[2*i+2]

          long joinValueWithDelta(long value, long delta) {
            if (delta == getNeutralDelta()) return value;
            return modifyOperation(value, delta);
          }

          long joinDeltas(long delta1, long delta2) {
            if (delta1 == getNeutralDelta()) return delta2;
            if (delta2 == getNeutralDelta()) return delta1;
            return modifyOperation(delta1, delta2);
          }

          void pushDelta(int root, int left, int right) {
            value[root] = joinValueWithDelta(value[root], deltaEffectOnSegment(delta[root], right - left + 1));
            delta[2 * root + 1] = joinDeltas(delta[2 * root + 1], delta[root]);
            delta[2 * root + 2] = joinDeltas(delta[2 * root + 2], delta[root]);
            delta[root] = getNeutralDelta();
          }

          public SegmentTree(int n) {
            this.n = n;
            value = new long[4 * n];
            delta = new long[4 * n];
            init(0, 0, n - 1);
          }

          void init(int root, int left, int right) {
            if (left == right) {
              value[root] = getInitValue();
              delta[root] = getNeutralDelta();
            } else {
              int mid = (left + right) >> 1;
              init(2 * root + 1, left, mid);
              init(2 * root + 2, mid + 1, right);
              value[root] = queryOperation(value[2 * root + 1], value[2 * root + 2]);
              delta[root] = getNeutralDelta();
            }
          }

          public long query(int from, int to) {
            return query(from, to, 0, 0, n - 1);
          }

          long query(int from, int to, int root, int left, int right) {
            if (from == left && to == right)
              return joinValueWithDelta(value[root], deltaEffectOnSegment(delta[root], right - left + 1));
            pushDelta(root, left, right);
            int mid = (left + right) >> 1;
            if (from <= mid && to > mid)
              return queryOperation(
                  query(from, Math.min(to, mid), root * 2 + 1, left, mid),
                  query(Math.max(from, mid + 1), to, root * 2 + 2, mid + 1, right));
            else if (from <= mid)
              return query(from, Math.min(to, mid), root * 2 + 1, left, mid);
            else if (to > mid)
              return query(Math.max(from, mid + 1), to, root * 2 + 2, mid + 1, right);
            else
              throw new RuntimeException("Incorrect query from " + from + " to " + to);
          }

          public void modify(int from, int to, long delta) {
            modify(from, to, delta, 0, 0, n - 1);
          }

          void modify(int from, int to, long delta, int root, int left, int right) {
            if (from == left && to == right) {
              this.delta[root] = joinDeltas(this.delta[root], delta);
              return;
            }
            pushDelta(root, left, right);
            int mid = (left + right) >> 1;
            if (from <= mid)
              modify(from, Math.min(to, mid), delta, 2 * root + 1, left, mid);
            if (to > mid)
              modify(Math.max(from, mid + 1), to, delta, 2 * root + 2, mid + 1, right);
            value[root] = queryOperation(
                joinValueWithDelta(value[2 * root + 1], deltaEffectOnSegment(this.delta[2 * root + 1], mid - left + 1)),
                joinValueWithDelta(value[2 * root + 2], deltaEffectOnSegment(this.delta[2 * root + 2], right - mid)));
          }
    }

    class LcaSparseTable {

          int len;
          int[][] up;
          int[][] max;
          int[] tin;
          int[] tout;
          int time;
          int []lvel;

          void dfs(List<Integer>[] tree, int u, int p) {
            tin[u] = time++;
            lvel[u]=lvel[p]+1;
            up[0][u] = p;
            if(u!=p)
            //max[0][u]=weight(u,p);
            for (int i = 1; i < len; i++)
              {
                up[i][u] = up[i - 1][up[i - 1][u]];
                max[i][u]=Math.max(max[i-1][u],max[i-1][up[i-1][u]]);
              }
            for (int v : tree[u])
              if (v != p)
                dfs(tree, v, u);
            tout[u] = time++;
          }

          public LcaSparseTable(List<Integer>[] tree, int root) {
            int n = tree.length;
            len = 1;
            while ((1 << len) <= n) ++len;
            up = new int[len][n];
            max=new int[len][n];
            tin = new int[n];
            tout = new int[n];
            lvel=new int[n];
            lvel[root]=0;
            dfs(tree, root, root);
          }

          boolean isParent(int parent, int child) {
            return tin[parent] <= tin[child] && tout[child] <= tout[parent];
          }

          public int lca(int a, int b) {
            if (isParent(a, b))
              return a;
            if (isParent(b, a))
              return b;
            for (int i = len - 1; i >= 0; i--)
              if (!isParent(up[i][a], b))
                a = up[i][a];
            return up[0][a];
          }
          public long max(int a,int b){
              int lca=lca(a,b);
        //    System.out.println("LCA "+lca);
              long ans=0;
              int h=lvel[a]-lvel[lca];
            //  System.out.println("Height "+h);
              int index=0;
              while(h!=0){
                  if(h%2==1){
                      ans=Math.max(ans,max[index][a]);
                      a=up[index][a];
                  }
                  h/=2;
                  index++;
              }
              h=lvel[b]-lvel[lca];
             // System.out.println("Height "+h);

              index=0;
              while(h!=0){
                  if(h%2==1){
                      ans=Math.max(ans,max[index][b]);
                      b=up[index][b];
                  }
                  h/=2;
                  index++;
              }
              return ans;
          }

    static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u,int parent,List<Integer> collection) {

        used[u] = true;
        Integer uu=new Integer(u);
        collection.add(uu);
        for (int v : graph[u]){
          if (!used[v]){
            dfs(graph, used, res, v,u,collection);

          }
          else if(collection.contains(v)){
              System.out.println("Impossible");
              System.exit(0);
          }
        }
        collection.remove(uu);
        res.add(u);
      }

      public static List<Integer> topologicalSort(List<Integer>[] graph) {
        int n = graph.length;
        boolean[] used = new boolean[n];
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < n; i++)
          if (!used[i])
            dfs(graph, used, res, i,-1,new ArrayList<Integer>());
        Collections.reverse(res);
        return res;
      }

    static class pairs{
                String company,color;
                String type;
                boolean visit=false;
                pairs(String company,String color,String type){
                    this.company=company;
                    this.color=color;
                    this.type=type;
                }
            }

            static void dfs1(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
            used[u] = true;
            for (int v : graph[u])
              if (!used[v])
                dfs1(graph, used, res, v);
            res.add(u);
          }

          public static List<Integer> topologicalSort1(List<Integer>[] graph) {
            int n = graph.length;
            boolean[] used = new boolean[n];
            List<Integer> res = new ArrayList<>();
            for (int i = n-1; i >0; i--)
              if (!used[i])
                dfs1(graph, used, res, i);
            Collections.reverse(res);
            return res;
          }

        public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
            long ans[][]=new long[m1.length][m2[0].length];
            for(int i=0;i<m1.length;i++){
                for(int j=0;j<m2[0].length;j++){
                    for(int k=0;k<m1.length;k++){
                        ans[i][j]+=(m1[i][k]*m2[k][j]);
                        ans[i][j]%=mod;
                    }
                }
            }
            return ans;
        }
        public static long[][] matrixexpo(long m[][],String n,long mod){
            if(n.equals("1")){
                return m.clone();
            }
            if(n.equals("10")){
                return mulmatrix(m, m , mod);
            }
            else{
                long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
                temp=mulmatrix(temp, temp, mod);
                if(n.charAt(n.length()-1)=='0')return temp;
                else return mulmatrix(temp, m,mod);
            }
        }
        public static boolean isCompatible(long x[],long y[]){

            for(int i=0;i<x.length-1;i++){
                if(x[i]==y[i] && x[i+1]==y[i+1] && x[i]==x[i+1] && y[i]==y[i+1]){
                    return false;
                }
            }
            return true;
        }

        int phi(int n) {
            int res = n;
            for (int i = 2; i * i <= n; ++i) {
                if (n % i == 0) {
                    while (n % i == 0) {
                        n /= i;
                    }
                    res -= res / i;
                }
            }
            if (n != 1) {
                res -= res / n;
            }
            return res;
        }
        long pow(long x,long y,long mod){
            if(y<=0){
                return 1;
            }
            if(y==1){
                return x%mod;
            }
            long temp=pow(x,y/2,mod);
            if(y%2==0){
                return (temp*temp)%mod;
            }
            else{
                return (((temp*temp)%mod)*x)%mod;
            }
        }

/*      long DP(int id,int mask){
            //System.out.println("hi"+dp[id][mask]+" "+id+" "+Integer.toBinaryString(mask));
            if(id==0 && mask==0){
                dp[0][mask]=1;
                return 1;
            }
            else if(id==0){
                dp[0][mask]=0;
                return 0;
            }
            if(dp[id][mask]!=-1){

                return dp[id][mask];
            }
            long ans=0;
            for(int i=0;i<n;i++){
                if((mask & (1<<i))!=0 && c[i][id]>=1){
                        ans+=DP(id-1,mask ^ (1 << i));
                        ans%=mod;
                }
            }
            ans+=DP(id-1,mask);
            ans%=mod;
            dp[id][mask]=ans;
            return ans;
        }*/
                long no_of_primes(long m,long n,long k){
                    long count=0,i,j;
                    int primes []=new int[(int)(n-m+2)];
                       if(m==1)    primes[0] = 1;
                        for(i=2; i<=Math.sqrt(n); i++)
                        {
                            j = (m/i);    j *= i;
                            if(j<m)
                                j+=i;
                            for(; j<=n; j+=i)
                             {
                                 if(j!=i)
                                    primes[(int)(j-m)] = 1;
                             }
                        }

                for(i=0; i<=n-m; i++)
                            if(primes[(int)i]==0 && (i-1)%k==0)
                                count++;
                return count;
                }
}
class SegTree {
    int n;
    long  t[];
    long mod=(long)(1000000007);
    SegTree(int n,long  t[]){
        this.n=n;
        this.t=t;
        build();
    }

    void build() {  // build the tree

        for (int i = n - 1; i > 0; --i)
            t[i]=(t[i<<1]|t[i<<1|1]);
    }

     void modify(int p, long value) {  // set value at position p
      for (t[p += n]+=value; p > 1; p >>= 1) t[p>>1] = (t[p]|t[p^1]);
    }

     long query(int l, int r) {  // sum on interval [l, r)
      long res=0;

      for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if ((l&1)!=0) res=Math.max(res,t[l++]);
            if ((r&1)!=0) res=Math.max(res,t[--r]);
          }
      return res;
    }

    //
//
//
}
class FastScanner
{

    private InputStream stream;
    private byte[] buf = new byte[8192];
    private int curChar;
    private int snumChars;
    private SpaceCharFilter filter;

    public FastScanner(InputStream stream) {
        this.stream = stream;
    }

    public int snext() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public int nextInt() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = snext();
        }

        int res = 0;

        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = snext();
        } while (!isSpaceChar(c));

        return res * sgn;
    }

    public long nextLong() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = snext();
        }

        long res = 0;

        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = snext();
        } while (!isSpaceChar(c));

        return res * sgn;
    }

    public String readString() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = snext();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}
 class UF {

    private int[] parent;  // parent[i] = parent of i
    private byte[] rank;   // rank[i] = rank of subtree rooted at i (never more than 31)
    private int count;     // number of components
    public UF(int N) {
        if (N < 0) throw new IllegalArgumentException();
        count = N;
        parent = new int[N];
        rank = new byte[N];
        for (int i = 0; i < N; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    public int find(int p) {
        if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
        while (p != parent[p]) {
            parent[p] = parent[parent[p]];    // path compression by halving
            p = parent[p];
        }
        return p;
    }
    public int count() {
        return count;
    }

    public boolean connected(int p, int q) {
        return find(p) == find(q);
    }

    public boolean union(int p, int q) {
        int rootP = find(p);
        int rootQ = find(q);
        if (rootP == rootQ) return false;

        // make root of smaller rank point to root of larger rank
        if      (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
        else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
        else {
            parent[rootQ] = rootP;
            rank[rootP]++;
        }
        count--;
        return true;
    }

}
 class MyArrayList {

    private int[] myStore;
    private int actSize = 0;

    public MyArrayList(){
        myStore = new int[2];
    }

    public int get(int index){
        if(index < actSize)
            return myStore[index];
         else
            throw new ArrayIndexOutOfBoundsException();
    }

    public void add(int obj){
        if(myStore.length-actSize <= 1)
            increaseListSize();
        myStore[actSize++] = obj;
    }

    public int size(){
        return actSize;
    }

    private void increaseListSize(){
        myStore = Arrays.copyOf(myStore, myStore.length*2);
    }
}

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
		int n=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		long ans=1;
		ans*=n;
		if(n<=c-b||n<=d-a||n<=d+c-a-b)ans=0;
		else{
		ans*=(	Math.min(Math.min(Math.min(n+d-a,n+c-b),n+d+c-a-b),n)-Math.max(Math.max(Math.max(-d+a,-c+b),-d-c+a+b),1)+1);
		}
		System.out.println(ans);

	}

}

import java.util.Scanner;

public class B {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int[] ar = new int[4];
		ar[0]=a+b;
		ar[1]=a+c;
		ar[2]=b+d;
		ar[3]=c+d;
		int min = ar[0];
		int max = ar[0];
		for(int i = 1; i<4; i++){
			min = Math.min(min, ar[i]);
			max = Math.max(max, ar[i]);
		}
		int takesUp = max-min+1;
		int canDo = n-takesUp+1;
		if(canDo<=0){
			System.out.println(0);
		}
		long ans = 1L;
		ans*=(long)canDo;
		ans*=(long)n;
		System.out.println(ans);
	}
}

import java.util.Scanner;
public class RestoringPainting {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		double n=0,a[]=new double[4],max=0,c1=0,min=0;
		n=in.nextDouble();
		for(int i=0; i<4; i++){
			a[i]=in.nextDouble();
		}
		min=a[0]+a[1];
		for(int i=0; i<2; i++){
			if(max<(a[i+1]+a[0])){
				max=a[i+1]+a[0];
			}
			else if(min>(a[i+1]+a[0])){
				min=a[i+1]+a[0];
			}
			if(max<(a[i+1]+a[3])){
				max=a[i+1]+a[3];
			}
			else if(min>(a[i+1]+a[3])){
				min=(a[i+1]+a[3]);
			}
		}

		if(max==(a[0]+a[1])){
			c1=n-max+min;
		}
		else{
			c1=n-(max-a[0]-a[1]+1)+1;
		}
		c1=n*c1;
		System.out.println(c1);
	}

}

import java.util.Scanner;

public class RestoringPaiting {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		 int b= input.nextInt();
		int c = input.nextInt();
		int d = input.nextInt();
		int total=0;
		for(int x1=1;x1<=n; x1++){
			int x4 = x1+a-d;
			int x3 = x1+b-c;
			int x5 = x1+a+b-c-d;
			if(x3>0 && x4>0 && x5>0){
				total+=n;
			}
		}
		System.out.println(total);
	}

}

import java.util.*;
public class cf675B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
long d=sc.nextLong();
long diff1=b-c,diff2=a-d,diff3=a-c+b-d;long ways=0;
long min=Math.min(diff1,(long)Math.min(diff2,diff3));
long max=Math.max(diff1,(long)Math.max(diff2,diff3));
if(max>=n)
System.out.println(0);
else
{if(min<0)
ways=n*(n-(Math.abs(min)+max));
else
ways=n*(n-max);
System.out.println(ways);}
sc.close();

}
}

import java.io.*;
import java.util.StringTokenizer;

public class B {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = in(), a = in(), b = in(), c = in(), d = in(), r = 0;
        for (int x1 = 1; x1 <= n; x1++) {
            int k = x1 + a + b, x2 = k - a - c, x3 = k - b - d, x4 = k - c - d;
            if (x2 > 0 && x3 > 0 && x4 > 0 && x2 <= n && x3 <= n && x4 <= n) {
                r += n;
            }
        }
        out.println(r);
        out.flush();
    }

    public static int in() throws IOException {
        return Integer.parseInt(next());
    }

    public static long inl() throws IOException {
        return Long.parseLong(next());
    }

    public static double ind() throws IOException {
        return Double.parseDouble(next());
    }

    public static String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public static boolean nextPerm(int[] a) {
        int j = a.length - 1, k = j, r = j;
        for (; j > 0; j--)
            if (a[j - 1] < a[j]) break;
        if (j == 0) return false;
        for (; k > j; k--)
            if (a[j - 1] < a[k]) break;
        swap(a, j - 1, k);
        while (j < r) swap(a, j++, r--);
        return true;
    }

    public static void swap(int[] a, int i, int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(char[] a, int i, int j) {
        char t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void swap(long[] a, int i, int j) {
        long t = a[i];
        a[i] = a[j];
        a[j] = t;
    }
}

import java.io.*;
import java.util.*;

public class b353 {

	static class Task {

		public void Solve(InputReader in,PrintWriter out)
		{
			int n=in.nextInt();
			int a=in.nextInt();
			int b=in.nextInt();
			int c=in.nextInt();
			int d=in.nextInt();
			int diff=abs((a+b)-(c+d));
			System.out.println((long)n*(n-diff));
		}
	}

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Task solve = new Task();
        solve.Solve(in,out);
        out.close();
    }

    static void sort(int arr[][]){
        Arrays.sort(arr,new Comparator<int[]>(){
        public int compare(int[] a, int[] b) {
            return a[0]-b[0];
        }});
    }

    static void sort(int arr[]){
		int cnt[]=new int[(1<<16)+1];
		int ys[]=new int[arr.length];
		for(int j=0;j<=16;j+=16){
			Arrays.fill(cnt,0);
			for(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}
			for(int i=1;i<cnt.length;i++){cnt[i]+=cnt[i-1];}
			for(int x:arr){ys[cnt[x>>j&0xFFFF]++]=x;}
			{ final int t[]=arr;arr=ys;ys=t;}
		}
		if(arr[0]<0||arr[arr.length-1]>=0)return;
		int i,j,c;
		for(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}
		for(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}
		for(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}
	}

	static int[] di={1,0,-1,0,1,-1,-1,1};
	static int[] dj={0,1,0,-1,1,1,-1,-1};

    static int min(int x,int y){return x<y?x:y;}
    static int max(int x,int y){return x>y?x:y;}
    static int lcm(int a,int b){return a*b/gcd(a,b);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
    static int abs(int x){if(x>=0)return x;else return -x;}

    static long min(long x,long y){return x<y?x:y;}
    static long max(long x,long y){return x>y?x:y;}
    static long lcm(long a,long b){return a*b/gcd(a,b);}
    static long gcd(long a,long b){return b==0?a:gcd(b,a%b);}
    static long abs(long x){if(x>=0)return x;else return -x;}

    static void joutArray(int arr[]){
    	for(int i=0;i<arr.length;i++){
    		System.out.print(arr[i]+" ");
    	}
    	System.out.println();
    }

    static void joutArray(int arr[][],int n,int m){
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++)
    		System.out.print(arr[i][j]+" ");
    		System.out.println();
    	}
    	System.out.println();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
        	return Long.parseLong(next());
        }

        public double nextDouble() {
        	return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++)
        		arr[i]=nextInt();
        	return arr;
        }

        public char[] nextCharArray(){
        	char arr[]=next().toCharArray();
        	return arr;
        }

        public HashMap<Integer,Integer> nextHashMap(int n){
        	HashMap<Integer,Integer> hm=new HashMap<>();
        	for(int i=0;i<n;i++){
    			int num=nextInt();
    			hm.put(num,hm.get(num)==null?1:hm.get(num)+1);
    		}
        	return hm;
        }
     }

   }

import java.io.*;
import java.util.StringTokenizer;

public class CFR353Div2B {

    public static void main(String[] args) throws IOException {
        CFR353Div2B solver = new CFR353Div2B();
        solver.solve();
    }

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("2 1 1 1 2");
//        sc = new FastScanner("3 3 1 2 3");

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;
        for (int x3 = 1; x3 <= n; x3++) {
            int x1 = a + b;
            int x2 = a + c;
            int x4 = b + d;
            int x5 = c + d;

//            System.out.printf("%d: %d %d %d %d\n", x3, x1, x2, x4, x5);

            int lo = 0;
            int hi = 1000000;

            while (hi - lo > 1) {
                int S = (lo + hi) / 2;

                if (S - x1 < 1 || S - x2 < 1 || S - x4 < 1 || S - x5 < 1) {
                    lo = S;
                } else {
                    hi = S;
                }
            }
            int S1 = hi;

            lo = 0;
            hi = 1000000;
            while (hi - lo > 1) {
                int S = (lo + hi) / 2;

                if (S - x1 > n || S - x2 > n || S - x4 > n || S - x5 > n) {
                    hi = S;
                } else {
                    lo = S;
                }
            }
            int S2 = lo;

            int diff = S2 - S1;
            if (diff >= 0) {
                ans += diff + 1;
            }
        }

        System.out.println(ans);
    }

    private static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}

import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();

		int s1=a+b;
		int s2=b+d;
		int s3=c+d;
		int s4=c+a;

		int max=Math.max(s1, s2);
		max=Math.max(s3,max);
		max=Math.max(s4,max);

		int min=Math.min(s1, s2);
		min=Math.min(s3,min);
		min=Math.min(s4, min);

	/*	System.out.println(max);
		System.out.println(min);*/
		int count=0,tmpmax=max,tmpmin=min;

		/*
		for(int i=1;i<=n;i++)//For Middle Value
		{
			tmpmax+=i;
			tmpmin+=i;

			int diff=(tmpmin+n)-(tmpmax+1);//Maxsum-minsum
			if(diff>=0){
				count+=(diff+1);
			}

			tmpmax=max;
			tmpmin=min;

		}
		*/

		int maxsum=tmpmin+n;//maxsum
		int minsum=tmpmax+1;//minsum

		if(maxsum-minsum<0)
		{
			System.out.println(0);
		}
		else
		{
			System.out.println(n*(maxsum-minsum+1));
		}

	//	System.out.println(count);

	}

}

import java.io.*;
import java.util.Arrays;
public class restoringPainting {

	public static void main(String[]args) throws IOException{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		String [] line = br.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int a = Integer.parseInt(line[1]);
		int b = Integer.parseInt(line[2]);
		int c = Integer.parseInt(line[3]);
		int d = Integer.parseInt(line[4]);

		int count = 0;

		for(int j =1; j <=n ;j++){
			int k = j+b-c;
			int l = j+a-d;
			int m = a+b+j-c-d;
			if(k>0 && l>0 && m>0){
				count++;
			}
		}
		System.out.println(count*n);
	}
}