#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long gcd(long long a, long long b, long long& first, long long& second) {
  if (b == 0) {
    first = 1;
    second = 0;
    return a;
  }
  long long x1, y1;
  long long d = gcd(b, a % b, x1, y1);
  first = y1;
  second = x1 - y1 * (a / b);
  return d;
}
bool find_any_solution(long long a, long long b, long long c, long long& x0,
                       long long& y0, long long& g) {
  g = gcd(abs(a), abs(b), x0, y0);
  if (c % g) {
    return false;
  }
  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 = -x0;
  if (b < 0) y0 = -y0;
  return true;
}
void shift_solution(long long& first, long long& second, long long a,
                    long long b, long long cnt) {
  first += cnt * b;
  second -= cnt * a;
}
long long find_all_solutions(long long a, long long b, long long c,
                             long long minx, long long maxx, long long miny,
                             long long maxy) {
  long long first, second, g;
  if (!find_any_solution(a, b, c, first, second, g)) return 0;
  a /= g;
  b /= g;
  long long sign_a = a > 0 ? +1 : -1;
  long long sign_b = b > 0 ? +1 : -1;
  shift_solution(first, second, a, b, (minx - first) / b);
  if (first < minx) shift_solution(first, second, a, b, sign_b);
  if (first > maxx) return 0;
  long long lx1 = first;
  shift_solution(first, second, a, b, (maxx - first) / b);
  if (first > maxx) shift_solution(first, second, a, b, -sign_b);
  long long rx1 = first;
  shift_solution(first, second, a, b, -(miny - second) / a);
  if (second < miny) shift_solution(first, second, a, b, -sign_a);
  if (second > maxy) return 0;
  long long lx2 = first;
  shift_solution(first, second, a, b, -(maxy - second) / a);
  if (second > maxy) shift_solution(first, second, a, b, sign_a);
  long long rx2 = first;
  if (lx2 > rx2) swap(lx2, rx2);
  long long lx = max(lx1, lx2);
  long long rx = min(rx1, rx2);
  if (lx > rx) return 0;
  return (rx - lx) / abs(b) + 1;
}
long long solve() {
  long long a1, b1, a2, b2, l, r;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long maxx = floor(1.0 * (r - b2) / a2);
  long long minx = ceil(1.0 * (l - b2) / a2);
  long long maxy = floor(1.0 * (r - b1) / a1);
  long long miny = ceil(1.0 * (l - b1) / a1);
  miny = max(0LL, miny);
  minx = max(0LL, minx);
  if (miny > maxy || minx > maxx) {
    cout << 0 << "\n";
    return 0;
  }
  cout << find_all_solutions(a1, -a2, b2 - b1, miny, maxy, minx, maxx) << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  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;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long gcd(long long a, long long b, long long& first, long long& second) {
  if (b == 0) {
    first = 1;
    second = 0;
    return a;
  }
  long long x1, y1;
  long long d = gcd(b, a % b, x1, y1);
  first = y1;
  second = x1 - y1 * (a / b);
  return d;
}
bool find_any_solution(long long a, long long b, long long c, long long& x0,
                       long long& y0, long long& g) {
  g = gcd(abs(a), abs(b), x0, y0);
  if (c % g) {
    return false;
  }
  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 = -x0;
  if (b < 0) y0 = -y0;
  return true;
}
void shift_solution(long long& first, long long& second, long long a,
                    long long b, long long cnt) {
  first += cnt * b;
  second -= cnt * a;
}
long long find_all_solutions(long long a, long long b, long long c,
                             long long minx, long long maxx, long long miny,
                             long long maxy) {
  long long first, second, g;
  if (!find_any_solution(a, b, c, first, second, g)) return 0;
  a /= g;
  b /= g;
  long long sign_a = a > 0 ? +1 : -1;
  long long sign_b = b > 0 ? +1 : -1;
  shift_solution(first, second, a, b, (minx - first) / b);
  if (first < minx) shift_solution(first, second, a, b, sign_b);
  if (first > maxx) return 0;
  long long lx1 = first;
  shift_solution(first, second, a, b, (maxx - first) / b);
  if (first > maxx) shift_solution(first, second, a, b, -sign_b);
  long long rx1 = first;
  shift_solution(first, second, a, b, -(miny - second) / a);
  if (second < miny) shift_solution(first, second, a, b, -sign_a);
  if (second > maxy) return 0;
  long long lx2 = first;
  shift_solution(first, second, a, b, -(maxy - second) / a);
  if (second > maxy) shift_solution(first, second, a, b, sign_a);
  long long rx2 = first;
  if (lx2 > rx2) swap(lx2, rx2);
  long long lx = max(lx1, lx2);
  long long rx = min(rx1, rx2);
  if (lx > rx) return 0;
  return (rx - lx) / abs(b) + 1;
}
long long solve() {
  long long a1, b1, a2, b2, l, r;
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long maxx = floor(1.0 * (r - b2) / a2);
  long long minx = ceil(1.0 * (l - b2) / a2);
  long long maxy = floor(1.0 * (r - b1) / a1);
  long long miny = ceil(1.0 * (l - b1) / a1);
  miny = max(0LL, miny);
  minx = max(0LL, minx);
  if (miny > maxy || minx > maxx) {
    cout << 0 << "\n";
    return 0;
  }
  cout << find_all_solutions(a1, -a2, b2 - b1, miny, maxy, minx, maxx) << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```