PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000286. Đếm nghiệm của Ai + Bj + Ck = X (Ai + Bj + Ck = X)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm nghiệm của Ai + Bj + Ck = X (Ai + Bj + Ck = X)

Ai + Bj + Ck = X

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given five positive integers N,A,B,C,XN,A,B,C,X, count the ordered triples of integers (i,j,k)(i,j,k) satisfying 1≤i,j,k≤N1\le i,j,k\le N and Ai+Bj+Ck=XAi+Bj+Ck=X. Two triples differing in at least one position are distinct.

Input

One line contains five integers N,A,B,C,XN,A,B,C,X, in this order.

Output

Print one integer: the number of qualifying triples (i,j,k)(i,j,k).

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le20; 1≤A,B,C≤1001\le A,B,C\le100; 1≤X≤1041\le X\le10^4.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le2000; 1≤A,B,C≤1051\le A,B,C\le10^5; 1≤X≤1081\le X\le10^8.
  • Subtask 3 (50 points): 1≤N≤1061\le N\le10^6; 1≤A,B,C≤1091\le A,B,C\le10^9; 1≤X≤3⋅10151\le X\le3\cdot10^{15}.

Examples

Input


5 3 1 5 15

Output


3

Explanation

For N=5,A=3,B=1,C=5,X=15N=5,A=3,B=1,C=5,X=15, precisely (1,2,2)(1,2,2), (2,4,1)(2,4,1) and (3,1,1)(3,1,1) satisfy the equation.

Input


1 1 1 1 1

Output


0

Explanation

When N=1N=1, the only possible triple has weighted sum 33, not X=1X=1; the answer is zero.

Input


100000 31415 92653 58979 1000000000

Output


2896

Explanation

For N=100000,A=31415,B=92653,C=58979,X=109N=100000,A=31415,B=92653,C=58979,X=10^9, there are 28962896 qualifying triples, obtained by counting bounded solutions for each first coordinate ii.