#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, L, R, x, y;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long res = exgcd(b, a % b, x, y);
  long long k = x;
  x = y;
  y = k - a / b * y;
  return res;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  long long x, y;
  long long gcd = exgcd(a1, a2, x, y);
  long long c = b2 - b1;
  if (c % gcd) {
    cout << 0;
    return 0;
  }
  L = max(L, max(b1, b2));
  if (L > R) {
    cout << 0;
    return 0;
  }
  long long w = a2 / gcd;
  x *= c / gcd;
  x = (x % w + w) % w;
  long long now = x * a1 + b1;
  long long lcm = a1 / gcd * a2;
  long long ans = 0;
  if (now <= R) ans = (R - now) / lcm + 1;
  if (now < L) ans -= (L - now - 1) / lcm + 1;
  cout << ans;
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0.

Input

The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·109, - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R).

Output

Print the desired number of integers x.

Examples

Input

2 0 3 3 5 21


Output

3


Input

2 4 3 0 6 17


Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, L, R, x, y;
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long res = exgcd(b, a % b, x, y);
  long long k = x;
  x = y;
  y = k - a / b * y;
  return res;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  long long x, y;
  long long gcd = exgcd(a1, a2, x, y);
  long long c = b2 - b1;
  if (c % gcd) {
    cout << 0;
    return 0;
  }
  L = max(L, max(b1, b2));
  if (L > R) {
    cout << 0;
    return 0;
  }
  long long w = a2 / gcd;
  x *= c / gcd;
  x = (x % w + w) % w;
  long long now = x * a1 + b1;
  long long lcm = a1 / gcd * a2;
  long long ans = 0;
  if (now <= R) ans = (R - now) / lcm + 1;
  if (now < L) ans -= (L - now - 1) / lcm + 1;
  cout << ans;
  return 0;
}

```