#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   int main() {     int l_a, r_a, t_a;     int l_b, r_b, t_b;     int l_x, r_x, t_x;     cin >> l_a >> r_a >> t_a;     cin >> l_b >> r_b >> t_b;     if (r_b - l_b < r_a - l_a) {       l_x = l_b, r_x = r_b, t_x = t_b;       l_b = l_a, r_b = r_a, t_b = t_a;       l_a = l_x, r_a = r_x, t_a = t_x;     }     int g = gcd(t_a, t_b);     int c = l_b - l_a;     int c_1, c_2;     if (l_b - l_a >= 0) {       c_1 = c % g;       c_2 = (-(c % g - g)) % g;     } else {       c_1 = g - (-c) % g;       c_2 = (-(c_1 - g)) % g;     }     int answer = r_a - l_a + 1 - c_1;     answer = max(answer, min(r_b - l_b + 1 - c_2, r_a - l_a + 1));     cout << max(answer, 0);   }   