#include <bits/stdc++.h>
using namespace std;
long long a1, b1, a2, b2, ans;
double l, l1, r, r1;
long long gcd(long long a, long long b, long long &x0, long long &y0) {
  if (a == 0) {
    x0 = 0;
    y0 = 1;
    return b;
  }
  long long x, y;
  long long g = gcd(b % a, a, x, y);
  y0 = x;
  x0 = y - (b / a) * x;
  return g;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0x0);
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long a = a1, b = -a2, c = b2 - b1;
  long long x0, y0;
  long long g = gcd(a, b, x0, y0);
  if (g < 0) {
    g = -g;
    x0 = -x0;
    y0 = -y0;
  }
  if (c % g) {
    cout << 0 << "\n";
    return 0;
  }
  l1 = l, r1 = r;
  long double lb, rb;
  l -= b1, r -= b1;
  l = max(0.0, ceil(1.0 * l / a1));
  r = floor(1.0 * r / a1);
  lb = 1.0 * (r * 1.0 * g - x0 * c) / b;
  rb = (1.0 * (l * 1.0 * g - x0 * c) / b);
  long double lb1, rb1;
  l1 -= b2, r1 -= b2;
  l1 = max(ceil(1.0 * l1 / a2), 0.0);
  r1 = floor(1.0 * r1 / a2);
  cerr << fixed << 1.0 * y0 * c << "\n";
  lb1 = (1.0 * (r1 * 1.0 * g - y0 * c) / a1);
  rb1 = (1.0 * (l1 * 1.0 * g - y0 * c) / a1);
  lb1 *= -1;
  rb1 *= -1;
  ans = max((long double)0, floor(min(rb1, rb)) - ceil(max(lb1, lb)) + 1);
  cout << ans << "\n";
}

### 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;
long long a1, b1, a2, b2, ans;
double l, l1, r, r1;
long long gcd(long long a, long long b, long long &x0, long long &y0) {
  if (a == 0) {
    x0 = 0;
    y0 = 1;
    return b;
  }
  long long x, y;
  long long g = gcd(b % a, a, x, y);
  y0 = x;
  x0 = y - (b / a) * x;
  return g;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0x0);
  cin >> a1 >> b1 >> a2 >> b2 >> l >> r;
  long long a = a1, b = -a2, c = b2 - b1;
  long long x0, y0;
  long long g = gcd(a, b, x0, y0);
  if (g < 0) {
    g = -g;
    x0 = -x0;
    y0 = -y0;
  }
  if (c % g) {
    cout << 0 << "\n";
    return 0;
  }
  l1 = l, r1 = r;
  long double lb, rb;
  l -= b1, r -= b1;
  l = max(0.0, ceil(1.0 * l / a1));
  r = floor(1.0 * r / a1);
  lb = 1.0 * (r * 1.0 * g - x0 * c) / b;
  rb = (1.0 * (l * 1.0 * g - x0 * c) / b);
  long double lb1, rb1;
  l1 -= b2, r1 -= b2;
  l1 = max(ceil(1.0 * l1 / a2), 0.0);
  r1 = floor(1.0 * r1 / a2);
  cerr << fixed << 1.0 * y0 * c << "\n";
  lb1 = (1.0 * (r1 * 1.0 * g - y0 * c) / a1);
  rb1 = (1.0 * (l1 * 1.0 * g - y0 * c) / a1);
  lb1 *= -1;
  rb1 *= -1;
  ans = max((long double)0, floor(min(rb1, rb)) - ceil(max(lb1, lb)) + 1);
  cout << ans << "\n";
}

```