import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): t = int(input()) a,b,c,d,e = map(int, input().split()) from collections import defaultdict mod = 10**9+7 dp = defaultdict(lambda: 0) dp[(0, 0, 0)] = 1 for i in range(t): ndp = defaultdict(lambda: 0) for (x, y, z), v in dp.items(): for dx, dy, dz in (-1,0,0),(1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1): nx, ny, nz = x+dx, y+dy, z+dz ndp[(nx, ny, nz)] += v ndp[(nx, ny, nz)] += mod dp = ndp ans = 0 for (x, y, z), v in dp.items(): if d <= a*x+b*y+c*z <= e: ans += v ans %= mod print(ans) if __name__ == '__main__': main()