#include <bits/stdc++.h>
using namespace std;
int gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  long long a1, b1, a2, b2, L, R;
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  if (abs(a1) % 2 == 0 && abs(b1) % 2 == 0 && abs(a2) % 2 == 0 &&
      abs(b2) % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (abs(a1) % 2 == 0 && abs(b1) % 2 == 1 && abs(a2) % 2 == 0 &&
      abs(b2) % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  double left = (L - b1) * 1.0 / a1, right = (R - b1) * 1.0 / a1;
  long long l = left;
  if (l < left) l++;
  long long r = right;
  if (r > right) r--;
  if (l < 0) l = 0;
  if (r < 0) {
    cout << 0 << endl;
    return 0;
  }
  left = (L - b2) * 1.0 / a2, right = (R - b2) * 1.0 / a2;
  long long ll1 = left;
  if (ll1 < left) ll1++;
  long long rr = right;
  if (rr > right) rr--;
  if (ll1 < 0) ll1 = 0;
  if (rr < 0) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = 0;
  long long s = a1 * a2 / gcd(a1, a2);
  if (r - l < rr - ll1) {
    for (long long i = l; i <= r; i++) {
      if ((i * a1 + b1 - b2) % a2 == 0 && (i * a1 + b1 - b2) / a2 >= ll1 &&
          (i * a1 + b1 - b2) / a2 <= rr) {
        ans += (r - i) / (s / a1);
        ans++;
        break;
      }
    }
  } else {
    for (long long i = ll1; i <= rr; i++) {
      if ((i * a2 + b2 - b1) % a1 == 0 && (i * a2 + b2 - b1) / a1 >= l &&
          (i * a2 + b2 - b1) / a1 <= r) {
        ans += (rr - i) / (s / a2);
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

### Prompt

Create a solution in Cpp for the following problem:

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;
int gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  long long a1, b1, a2, b2, L, R;
  cin >> a1 >> b1 >> a2 >> b2 >> L >> R;
  if (abs(a1) % 2 == 0 && abs(b1) % 2 == 0 && abs(a2) % 2 == 0 &&
      abs(b2) % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (abs(a1) % 2 == 0 && abs(b1) % 2 == 1 && abs(a2) % 2 == 0 &&
      abs(b2) % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  double left = (L - b1) * 1.0 / a1, right = (R - b1) * 1.0 / a1;
  long long l = left;
  if (l < left) l++;
  long long r = right;
  if (r > right) r--;
  if (l < 0) l = 0;
  if (r < 0) {
    cout << 0 << endl;
    return 0;
  }
  left = (L - b2) * 1.0 / a2, right = (R - b2) * 1.0 / a2;
  long long ll1 = left;
  if (ll1 < left) ll1++;
  long long rr = right;
  if (rr > right) rr--;
  if (ll1 < 0) ll1 = 0;
  if (rr < 0) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = 0;
  long long s = a1 * a2 / gcd(a1, a2);
  if (r - l < rr - ll1) {
    for (long long i = l; i <= r; i++) {
      if ((i * a1 + b1 - b2) % a2 == 0 && (i * a1 + b1 - b2) / a2 >= ll1 &&
          (i * a1 + b1 - b2) / a2 <= rr) {
        ans += (r - i) / (s / a1);
        ans++;
        break;
      }
    }
  } else {
    for (long long i = ll1; i <= rr; i++) {
      if ((i * a2 + b2 - b1) % a1 == 0 && (i * a2 + b2 - b1) / a1 >= l &&
          (i * a2 + b2 - b1) / a1 <= r) {
        ans += (rr - i) / (s / a2);
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

```