#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const int N = 40010;
const int M = N << 2;
const int inf = 0x3f3f3f3f;
const int mod = 19961993;
int p, a, b, x1, t;
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 tmp = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return tmp;
}
long long a1, b1, a2, b2, l, r;
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long x, y;
  long long d = exgcd(a1, a2, x, y);
  l = max(l, max(b1, b2));
  if (l > r) {
    puts("0");
    return 0;
  }
  if ((b2 - b1) % d) {
    puts("0");
    return 0;
  }
  x *= (b2 - b1) / d;
  a2 /= d;
  a2 = abs(a2);
  x = (x % a2 + a2) % a2;
  long long cnt = x * a1 + b1;
  long long tmp = abs(a1 * a2);
  long long ans = 0;
  if (cnt <= r) ans += (r - cnt) / tmp + 1;
  if (cnt < l) ans -= (l - 1 - cnt) / tmp + 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;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const int N = 40010;
const int M = N << 2;
const int inf = 0x3f3f3f3f;
const int mod = 19961993;
int p, a, b, x1, t;
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 tmp = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return tmp;
}
long long a1, b1, a2, b2, l, r;
int main() {
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long x, y;
  long long d = exgcd(a1, a2, x, y);
  l = max(l, max(b1, b2));
  if (l > r) {
    puts("0");
    return 0;
  }
  if ((b2 - b1) % d) {
    puts("0");
    return 0;
  }
  x *= (b2 - b1) / d;
  a2 /= d;
  a2 = abs(a2);
  x = (x % a2 + a2) % a2;
  long long cnt = x * a1 + b1;
  long long tmp = abs(a1 * a2);
  long long ans = 0;
  if (cnt <= r) ans += (r - cnt) / tmp + 1;
  if (cnt < l) ans -= (l - 1 - cnt) / tmp + 1;
  cout << ans;
  return 0;
}

```