#!/usr/bin/env python t = int(input().strip()) indat = [int(x) for x in input().split()] points = {(0, 0, 0):1} moves = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] moves = set(moves) for i in range(t): tmp = {} for point, times in points.items(): for move in moves: a = tuple([x + y for (x, y) in zip(point, move)]) if tmp.get(a) == None: tmp[a] = times else: tmp[a] += times a = tuple([x - y for (x, y) in zip(point, move)]) if tmp.get(a) == None: tmp[a] = times else: tmp[a] += times points = tmp p = 0 for point, times in points.items(): eqs = sum([a * x for (a, x) in zip(indat[:3], point)]) if eqs >= indat[3] and eqs <= indat[4]: p += times print(p % (10**9 + 7))