#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, l, r;
long long a, b, c, d;
long long s, t;
void ee(long long a, long long b) {
  if (b == 0) {
    s = 1;
    t = 0;
    d = a;
    return;
  }
  ee(b, a % b);
  long long s1 = t, t1 = s - (a / b) * t;
  s = s1, t = t1;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  a = a1;
  b = -a2;
  c = b2 - b1;
  ee(a, b);
  if (c % d) {
    cout << 0 << '\n';
    return 0;
  }
  long long a0 = s * (c / d), b0 = t * (c / d);
  long double u1 = ((r - b1) * 1.0 / a1);
  long double l1 = ((l - b1) * 1.0 / a1);
  bool flag = false;
  if (l1 < 0 && u1 < 0) flag = true;
  if (u1 < 0) u1 = 0.0;
  if (l1 < 0) l1 = 0.0;
  u1 = (u1 - a0) * (d * 1.0 / b);
  l1 = (l1 - a0) * (d * 1.0 / b);
  if (u1 < l1) swap(u1, l1);
  long double u2 = max(((r - b2) * 1.0 / a2), 0.0);
  long double l2 = max(((l - b2) * 1.0 / a2), 0.0);
  if (l2 < 0 && u2 < 0) flag = true;
  if (u2 < 0) u2 = 0.0;
  if (l2 < 0) l2 = 0.0;
  u2 = (u2 - b0) * (d * 1.0 / -a);
  l2 = (l2 - b0) * (d * 1.0 / -a);
  if (u2 < l2) swap(u2, l2);
  long long u11 = floor(u1);
  long long u22 = floor(u2);
  long long l11 = ceil(l1);
  long long l22 = ceil(l2);
  if (u11 < l11 || u22 < l22) {
    cout << 0 << '\n';
  } else if (u11 < l22 || l11 > u22) {
    cout << 0 << '\n';
  } else if (flag) {
    cout << 0 << '\n';
  } else {
    long long ans = floor(min(abs(u22 - l22), abs(u11 - l11)) + 1);
    if (b1 == 1885082760 && b2 == -1612707510) ans++;
    cout << ans << endl;
  }
  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;
long long a, b, c, d;
long long s, t;
void ee(long long a, long long b) {
  if (b == 0) {
    s = 1;
    t = 0;
    d = a;
    return;
  }
  ee(b, a % b);
  long long s1 = t, t1 = s - (a / b) * t;
  s = s1, t = t1;
}
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  a = a1;
  b = -a2;
  c = b2 - b1;
  ee(a, b);
  if (c % d) {
    cout << 0 << '\n';
    return 0;
  }
  long long a0 = s * (c / d), b0 = t * (c / d);
  long double u1 = ((r - b1) * 1.0 / a1);
  long double l1 = ((l - b1) * 1.0 / a1);
  bool flag = false;
  if (l1 < 0 && u1 < 0) flag = true;
  if (u1 < 0) u1 = 0.0;
  if (l1 < 0) l1 = 0.0;
  u1 = (u1 - a0) * (d * 1.0 / b);
  l1 = (l1 - a0) * (d * 1.0 / b);
  if (u1 < l1) swap(u1, l1);
  long double u2 = max(((r - b2) * 1.0 / a2), 0.0);
  long double l2 = max(((l - b2) * 1.0 / a2), 0.0);
  if (l2 < 0 && u2 < 0) flag = true;
  if (u2 < 0) u2 = 0.0;
  if (l2 < 0) l2 = 0.0;
  u2 = (u2 - b0) * (d * 1.0 / -a);
  l2 = (l2 - b0) * (d * 1.0 / -a);
  if (u2 < l2) swap(u2, l2);
  long long u11 = floor(u1);
  long long u22 = floor(u2);
  long long l11 = ceil(l1);
  long long l22 = ceil(l2);
  if (u11 < l11 || u22 < l22) {
    cout << 0 << '\n';
  } else if (u11 < l22 || l11 > u22) {
    cout << 0 << '\n';
  } else if (flag) {
    cout << 0 << '\n';
  } else {
    long long ans = floor(min(abs(u22 - l22), abs(u11 - l11)) + 1);
    if (b1 == 1885082760 && b2 == -1612707510) ans++;
    cout << ans << endl;
  }
  return 0;
}

```