#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long long a1, a2, b1, b2, l, r, ans;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  l = max(b1, max(b2, l));
  long long lcm = (a1 * a2) / gcd(a1, a2);
  if (a2 >= a1) {
    swap(a1, a2);
    swap(b1, b2);
  }
  long long delta = ((b1 % a1) + a1) % a1;
  long long rho = ((b2 % a2) + a2) % a2;
  long long firstx = l + ((a1 + delta - (l % a1)) % a1);
  long long firstbothx;
  bool got = false;
  long long t = firstx;
  while (firstx <= t + lcm && firstx <= r) {
    if ((firstx % a2 + a2) % a2 == rho) {
      firstbothx = firstx;
      got = true;
      break;
    } else {
      firstx = firstx + a1;
    }
  }
  if (got == false) {
    cout << "0\n";
    return 0;
  }
  ans = 0;
  ans = (r - firstbothx) / lcm + 1;
  cout << ans << "\n";
  return 0;
}

### Prompt

Please formulate a CPP solution to 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;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  long long a1, a2, b1, b2, l, r, ans;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  l = max(b1, max(b2, l));
  long long lcm = (a1 * a2) / gcd(a1, a2);
  if (a2 >= a1) {
    swap(a1, a2);
    swap(b1, b2);
  }
  long long delta = ((b1 % a1) + a1) % a1;
  long long rho = ((b2 % a2) + a2) % a2;
  long long firstx = l + ((a1 + delta - (l % a1)) % a1);
  long long firstbothx;
  bool got = false;
  long long t = firstx;
  while (firstx <= t + lcm && firstx <= r) {
    if ((firstx % a2 + a2) % a2 == rho) {
      firstbothx = firstx;
      got = true;
      break;
    } else {
      firstx = firstx + a1;
    }
  }
  if (got == false) {
    cout << "0\n";
    return 0;
  }
  ans = 0;
  ans = (r - firstbothx) / lcm + 1;
  cout << ans << "\n";
  return 0;
}

```