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

#GL0000292. Bài toán lựa chọn quà (Gift Dilemma)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bài toán lựa chọn quà (Gift Dilemma)

Gift Dilemma

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Sheldon wants to purchase gifts whose total cost is exactly PP. A shop offers three kinds of goods: Rubik’s cubes, harmonicas, and chocolates, costing A,B,CA,B,C respectively. Let x,y,zx,y,z denote the quantities of each kind. Every quantity must be a nonnegative integer. Count all distinct triples (x,y,z)(x,y,z) satisfying Ax+By+Cz=PAx+By+Cz=P. Each different triple counts as one way, including triples with zero quantities.

Input

One line containing four integers A,B,C,PA,B,C,P in that order.

Output

Print one integer: the number of nonnegative integer triples satisfying the equation.

Subtasks

  • Subtask 1 (20 points): 1≤A,B,P≤15001\le A,B,P\le1500, 200≤C≤1500200\le C\le1500, C/gcd⁡(A,B,C)≥200C/\gcd(A,B,C)\ge200.
  • Subtask 2 (30 points): 1≤A,B,P≤1061\le A,B,P\le10^6, 200≤C≤106200\le C\le10^6, C/gcd⁡(A,B,C)≥200C/\gcd(A,B,C)\ge200.
  • Subtask 3 (50 points): 1≤A,B,P≤1081\le A,B,P\le10^8, 200≤C≤108200\le C\le10^8, C/gcd⁡(A,B,C)≥200C/\gcd(A,B,C)\ge200.

Examples

Example 1

Input

202 203 200 606

Output

2

Explanation

There are exactly two choices: (3,0,0)(3,0,0) gives 3⋅202=6063\cdot202=606, and (0,2,1)(0,2,1) gives 2⋅203+200=6062\cdot203+200=606.