#include <bits/stdc++.h>
using namespace std;
inline long long min(long long a, long long b) { return a < b ? a : b; }
inline long long max(long long a, long long b) { return a > b ? a : b; }
inline void chk_max(long long &a, long long b) {
  if (a < b) a = b;
}
inline void error(void) {
  printf("0");
  exit(0);
}
inline long long Abs(long long x) { return x < 0 ? -x : x; }
inline long long flr(long long a, long long b) {
  return floor((long double)a / b);
}
inline long long cl(long long a, long long b) {
  return ceil((long double)a / b);
}
long long exgcd(long long a, long long b, long long c, long long &x,
                long long &y) {
  if (!b) {
    if (c % a) error();
    x = c / a;
    y = 0;
    return a;
  }
  long long t = exgcd(b, a % b, c, y, x);
  y -= a / b * x;
  return t;
}
int main(void) {
  long long a1, b1, a2, b2, l, r;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long x, y;
  long long tmp = exgcd(a1, -a2, b2 - b1, x, y);
  long long s = -a2 / tmp, t = -a1 / tmp;
  long long xl = cl(l - b1, a1), xr = flr(r - b1, a1);
  if (xr >= 0)
    chk_max(xl, 0);
  else
    error();
  if (s < 0) swap(xl, xr);
  long long kl1 = cl(xl - x, s), kr1 = flr(xr - x, s);
  long long yl = cl(l - b2, a2), yr = flr(r - b2, a2);
  if (yr >= 0)
    chk_max(yl, 0);
  else
    error();
  if (t < 0) swap(yl, yr);
  long long kl2 = cl(yl - y, t), kr2 = flr(yr - y, t);
  long long kl = max(kl1, kl2), kr = min(kr1, kr2);
  if (kl > kr) error();
  cout << kr - kl + 1;
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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 min(long long a, long long b) { return a < b ? a : b; }
inline long long max(long long a, long long b) { return a > b ? a : b; }
inline void chk_max(long long &a, long long b) {
  if (a < b) a = b;
}
inline void error(void) {
  printf("0");
  exit(0);
}
inline long long Abs(long long x) { return x < 0 ? -x : x; }
inline long long flr(long long a, long long b) {
  return floor((long double)a / b);
}
inline long long cl(long long a, long long b) {
  return ceil((long double)a / b);
}
long long exgcd(long long a, long long b, long long c, long long &x,
                long long &y) {
  if (!b) {
    if (c % a) error();
    x = c / a;
    y = 0;
    return a;
  }
  long long t = exgcd(b, a % b, c, y, x);
  y -= a / b * x;
  return t;
}
int main(void) {
  long long a1, b1, a2, b2, l, r;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long x, y;
  long long tmp = exgcd(a1, -a2, b2 - b1, x, y);
  long long s = -a2 / tmp, t = -a1 / tmp;
  long long xl = cl(l - b1, a1), xr = flr(r - b1, a1);
  if (xr >= 0)
    chk_max(xl, 0);
  else
    error();
  if (s < 0) swap(xl, xr);
  long long kl1 = cl(xl - x, s), kr1 = flr(xr - x, s);
  long long yl = cl(l - b2, a2), yr = flr(r - b2, a2);
  if (yr >= 0)
    chk_max(yl, 0);
  else
    error();
  if (t < 0) swap(yl, yr);
  long long kl2 = cl(yl - y, t), kr2 = flr(yr - y, t);
  long long kl = max(kl1, kl2), kr = min(kr1, kr2);
  if (kl > kr) error();
  cout << kr - kl + 1;
  return 0;
}

```