#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  while (a && b)
    if (a > b)
      a %= b;
    else
      b %= a;
  return a + b;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  long long a, b, c, d, l, r, k, x, y, ans = 0;
  std::cin >> a >> b >> c >> d >> l >> r;
  if ((d - b) % gcd(a, c) == 0) {
    k = (l - b) / a;
    if (k < 0) k = 0;
    x = k * a + b;
    if (x < l) x += a;
    k = (l - d) / c;
    if (k < 0) k = 0;
    y = k * c + d;
    if (y < l) y += c;
    if (x <= r && y <= r) {
      while (x != y && x <= r && y <= r)
        if (x < y)
          x += (y - x > a ? (y - x) / a * a : a);
        else
          y += (x - y > c ? (x - y) / c * c : c);
      if (x == y) ans = (r - x) / lcm(a, c) + 1;
    }
  }
  std::cout << ans;
}

### Prompt

In cpp, your task is to solve 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>
long long gcd(long long a, long long b) {
  while (a && b)
    if (a > b)
      a %= b;
    else
      b %= a;
  return a + b;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  long long a, b, c, d, l, r, k, x, y, ans = 0;
  std::cin >> a >> b >> c >> d >> l >> r;
  if ((d - b) % gcd(a, c) == 0) {
    k = (l - b) / a;
    if (k < 0) k = 0;
    x = k * a + b;
    if (x < l) x += a;
    k = (l - d) / c;
    if (k < 0) k = 0;
    y = k * c + d;
    if (y < l) y += c;
    if (x <= r && y <= r) {
      while (x != y && x <= r && y <= r)
        if (x < y)
          x += (y - x > a ? (y - x) / a * a : a);
        else
          y += (x - y > c ? (x - y) / c * c : c);
      if (x == y) ans = (r - x) / lcm(a, c) + 1;
    }
  }
  std::cout << ans;
}

```