Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days $[l_a; r_a]$ are lucky, then there are some unlucky days: $[r_a + 1; l_a + t_a - 1]$, and then there are lucky days again: $[l_a + t_a; r_a + t_a]$ and so on. In other words, the day is lucky for Alice if it lies in the segment $[l_a + k t_a; r_a + k t_a]$ for some non-negative integer $k$.

The Bob's lucky day have similar structure, however the parameters of his sequence are different: $l_b$, $r_b$, $t_b$. So a day is a lucky for Bob if it lies in a segment $[l_b + k t_b; r_b + k t_b]$, for some non-negative integer $k$.

Alice and Bob want to participate in team competitions together and so they want to find out what is the largest possible number of consecutive days, which are lucky for both Alice and Bob.


-----Input-----

The first line contains three integers $l_a$, $r_a$, $t_a$ ($0 \le l_a \le r_a \le t_a - 1, 2 \le t_a \le 10^9$) and describes Alice's lucky days.

The second line contains three integers $l_b$, $r_b$, $t_b$ ($0 \le l_b \le r_b \le t_b - 1, 2 \le t_b \le 10^9$) and describes Bob's lucky days.

It is guaranteed that both Alice and Bob have some unlucky days.


-----Output-----

Print one integer: the maximum number of days in the row that are lucky for both Alice and Bob.


-----Examples-----
Input
0 2 5
1 3 5

Output
2

Input
0 1 3
2 3 6

Output
1



-----Note-----

The graphs below correspond to the two sample tests and show the lucky and unlucky days of Alice and Bob as well as the possible solutions for these tests.

[Image]

[Image]

Difficulty: interview

Starter code:

Solutions:
import sys
import string
from math import gcd
import getpass
import math
from decimal import Decimal
import pprint


def ria():
    return [int(i) for i in input().split()]


if getpass.getuser() != 'frohenk':
    filename = 'half'
    # sys.stdin = open('input.txt')
    # sys.stdout = open('output.txt', 'w')
else:
    sys.stdin = open('input.txt')
    # sys.stdin.close()
# sys.stdout = open('output.txt', 'w')


la, ra, ta = ria()
lb, rb, tb = ria()
if ta > tb:
    la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta

gc = gcd(tb, ta)
if gc == 1:
    print(min(ra - la + 1, rb - lb + 1))
    return


def get(st):
    nonlocal la, ra, ta, lb, rb, tb
    lc = la + st
    rc = ra + st
    return max(min(rc, rb) - max(lc, lb) + 1, 0)


sta = la // gc
stb = lb // gc
fna = ra // gc
fnb = rb // gc

mx = 0

mx = max(mx, get((stb - sta) * gc))
mx = max(mx, get((stb - sta + 1) * gc))
mx = max(mx, get((stb - sta + 2) * gc))
mx = max(mx, get((stb - sta - 1) * gc))
mx = max(mx, get((stb - sta - 2) * gc))

mx = max(mx, get((fnb - fna) * gc))
mx = max(mx, get((fnb - fna + 1) * gc))
mx = max(mx, get((fnb - fna + 2) * gc))
mx = max(mx, get((fnb - fna - 1) * gc))
mx = max(mx, get((fnb - fna - 2) * gc))

#print(stb - sta)
print(mx)


def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())
import math

la, ra, ta = mi()
lb, rb, tb = mi()
if la > lb:
    la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta
lb -= la
ra -= la
rb -= la
dif = math.gcd(ta, tb)
difl = lb

off1 = difl % dif
ans1 = min(ra, off1 + rb - lb) - max(0, off1) + 1
off2 = off1 - dif
ans2 = min(ra, off2 + rb - lb) - max(0, off2) + 1
ans = max(ans1, ans2, 0)
print(ans)


#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit

def gcd(a,b):
    if b==0: return a
    return gcd(b, a%b)

la,ra,ta = getIntList()
lb,rb,tb = getIntList()
#print(N)
g = gcd(ta,tb)
wa = ra-la +1
wb = rb-lb +1
d = la - lb
d1 = d//g * g

la -= d1
ra -= d1
while la < lb:
    la+=g
    ra+=g
while la >= lb:
    la-=g
    ra-=g
def work():
    x0 = max(la,lb)
    x1 = min(ra,rb)
    r = x1-x0+1
    return r

res = 0
res = max(work(), res)
while la < lb:
    la+=g
    ra+=g
res = max(work(), res)

print(res)








    








    







from math import gcd
la,ra,ta = list(map(int,input().split()))
lb,rb,tb = list(map(int,input().split()))
g = gcd(ta,tb)
ra -= la
temp = rb-lb
lb -= la
lb %= g
rb = lb+temp
current = min(rb,ra)-lb+1
now = min(rb,ra+g)-g+1
print(max(current,now,0))


def inters(x1,y1,x2,y2):
    return max(0, min(y1,y2) - max(x1,x2) + 1)

from math import gcd
la, ra, ta  = list(map(int, input().split()))
lb, rb, tb  = list(map(int, input().split()))
shift = gcd(ta, tb)


start = la - (la % shift)
la -= start
ra -= start

start = lb - (lb % shift)
lb -= start
rb -= start


res = max(inters(la, ra, lb+shift, rb+shift), inters(la+shift, ra+shift, lb, rb), inters(la, ra, lb, rb))
# print(la,ra, lb,rb)

print(res)


import math

la, ra, ta = list(map(int, input().split()))
lb, rb, tb = list(map(int, input().split()))
if rb - lb < ra - la:
    la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta
t = math.gcd(ta, tb)

def sect(k):
    return max(0, min(rb, ra + k * t) - max(lb, la + k * t) + 1)

ans = max(sect(x) for x in [(rb - ra) // t, (lb - la + t - 1) // t])
print(ans)


from collections import defaultdict
from fractions import gcd
def read_line():
    return [int(x) for x in input().split()]

la, ra, ta = read_line()
lb, rb, tb = read_line()


def check(la, ra, ta, lb, rb, tb):
  if la > lb:
      la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta

# print("{}--{}, {}--{}".format(la, ra, lb, rb))
    
  la, ra = 0, ra-la
  lb, rb = lb-la, rb-la

# print("{}--{}, {}--{}".format(la, ra, lb, rb))

def bf_solve(la, ra, ta, lb, rb, tb):
    ##p = ta*tb // gcd(ta, tb)
    A = [False for _ in range(tb)]
    for i in range(la, ra+1):
        A[i] = True
    A = A * (tb // gcd(ta, tb))
    
    B = [False for _ in range(tb)] 
    for i in range(lb, rb+1):
        B[i] = True
    B = B * (ta // gcd(ta, tb))
    # find longest common seq:
    streak = 0
    mx = 0
    A.append(False)
    B.append(False)
    for a, b in zip(A, B):
        if not(a and b):
            mx = max(mx, streak)
            streak = 0
        else:
            streak += 1
    return mx

def solve(la, ra, ta, lb, rb, tb):
    if la > lb:
        la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta

    # print("{}--{}, {}--{}".format(la, ra, lb, rb))

    old_la = la
    la, ra = 0, ra-old_la
    lb, rb = lb-old_la, rb-old_la
    # print("{}--{}, {}--{}".format(la, ra, lb, rb))
    # nonlocal la
    # nonlocal lb
    # nonlocal ra
    # nonlocal rb
    
    if gcd(ta, tb) == 1:
        return min(ra-la+1, rb-lb+1)
    d = gcd(ta, tb)
    dst = rb - lb
    lb = lb % d
    rb = lb + dst
    # print("{}--{}, {}--{}".format(la, ra, lb, rb))

    both_start = max(la, lb)
    both_end = min(ra, rb)
    # print("common {}--{}".format(both_start, both_end))
    res_cand = max(both_end - both_start + 1, 0)

    lb -= d
    rb -= d
    assert lb < 0
    both_start = max(la, lb)
    both_end = min(ra, rb)
    # print("{} __ {}, {} __ {}".format(la, ra, lb, rb))
    # print("common {} __ {}".format(both_start, both_end))
    res_cand2 = max(both_end - both_start + 1, 0)
    return max(res_cand, res_cand2)

print(solve(la, ra, ta, lb, rb, tb))
# return
    
# print(solve())


def check(la, ra, ta, lb, rb, tb):
  A = solve(la, ra, ta, lb, rb, tb)
  B = bf_solve(la, ra, ta, lb, rb, tb)

  assert A == B, (A, B)

# for ta in range(2, 10):
#     for tb in range(2, 10):
#         for la in range(ta):
#             for ra in range(la, ta):
#                 for lb in range(tb):
#                     for rb in range(lb, tb):
#                         print(la, ra, ta, lb, rb, tb)
#                         check(la, ra, ta, lb, rb, tb)
    


def gcd(x,y):
    if(y==0):
        return x
    return gcd(y,x%y)


la,ra,ta = list(map(int,input().split()))

lb,rb,tb = list(map(int,input().split()))

gcd1 = gcd(ta,tb)
luca = ra - la + 1
lucb = rb - lb + 1
if((la - lb) % gcd1 == 0):
    print(min(luca,lucb))
else:
    
    #print(luca,lucb)
    op1 = lucb - (la - lb) % gcd1
    op2 = luca - (lb - la) % gcd1
    opf = max(op1,op2,0)
    
    print(min(opf,luca,lucb))


from math import gcd

C = lambda x, y: (x + y - 1)//y

l0, r0, t0 = map(int, input().split())
l1, r1, t1 = map(int, input().split())
g = gcd(t0, t1)
c = [0] * 4

i = min((r1 - r0)//g, (l1 - l0)//g)
if i >= C(l1 - r0, g):
    c[0] = r0 - l1 + g*i + 1

i = min((r0 - r1)//g, (l0 - l1)//g)
if i >= C(l0 - r1, g):
    c[1] = r1 - l0 + g*i + 1

i = min((r1 - r0)//g, (r1 - l0)//g)
if i >= max(C(l1 - r0, g), C(l1 - l0, g)):
    c[2] = r0 - l0 + 1

i = min((r0 - r1)//g, (r0 - l1)//g)
if i >= max(C(l0 - r1, g), C(l0 - l1, g)):
    c[3] = r1 - l1 + 1

# print(c)
print(max(c))

l1,r1,t1=list(map(int,input().split()))
l2,r2,t2=list(map(int,input().split()))
#a=list(map(int,input().split()))

def gcd(a,b):
    if a>b: a,b=b,a
    while a>0:
        b=b%a
        a,b=b,a
    return b


d=gcd(t1,t2)

def answer(x1,d1,x2,d2):
    if x1>x2:
        x1,x2,d1,d2=x2,x1,d2,d1
    d1=d1-(x2-x1)
    if d1<0: d1=0
    return min(d1,d2)

d1=r1-l1+1
d2=r2-l2+1

l1=l1%d
l2=l2%d

if l1>l2:
    l1,l2,d1,d2=l2,l1,d2,d1

ans1=answer(l1,d1,l2,d2)
ans2=answer(l1+d,d1,l2,d2)

print(max(ans1,ans2))


def euclid(data):
    a=data[0]
    for b in data[1:]:
        if(b<a):
            a,b=b,a
        while(1):
            r=b%a
            if(r==0):
                break
            else:
                b=a
                a=r
    return a



la,ra,ta=list(map(int,input().split()))
lb,rb,tb=list(map(int,input().split()))

if(la < lb):
    la,lb=lb,la
    ra,rb=rb,ra
    ta,tb=tb,ta

gcd=euclid([ta,tb])
tmp=(la-lb) - gcd*((la - lb)//gcd)

print( max( [0, min([ra-la+tmp,rb-lb]) -tmp +1 , min([ra-la,rb-lb + gcd-tmp]) -(gcd - tmp) +1]))


la, ra, ta = list(map(int, input().split()))
lb, rb, tb = list(map(int, input().split()))
a, b = ta, tb
while b:
	a, b = b, a % b
ra -= la // a * a
la %= a
rb -= lb // a * a
lb %= a
print(max(min(ra, rb) + 1 - max(la, lb), min(ra + a, rb) + 1 - max(la + a, lb), min(ra, rb + a) + 1 - max(la, lb + a), 0))


import sys
import math

inp = iter(map(int, sys.stdin.read().split()))

la = next(inp)
ra = next(inp)
ta = next(inp)

lb = next(inp)
rb = next(inp)
tb = next(inp)

if la > lb:
	la, lb = lb, la
	ra, rb = rb, ra
	ta, tb = tb, ta

def area(l1, r1, l2, r2):
	#print('area of ', l1, r1, 'and', l2, r2)
	l = max(l1, l2)
	r = min(r1, r2)
	return r-l+1

d = lb-la
#print('diff', d)
g = math.gcd(ta, tb)
shift = d//g*g

ans = 0

for d in range(-100, 101):
	ans = max(ans, area(la, ra, lb-shift-g*d, rb-shift-g*d))

print(ans)


def gcd(a, b):

    if b==0: return a
    return gcd(b, a%b)

def lucky(l_a, r_a, t_a, l_b, r_b, t_b):

    if r_b - l_b > r_a - l_a:

        thing = [l_a, r_a, l_b, r_b]

        l_a = thing[2];
        r_a = thing[3]
        l_b = thing[0]
        r_b = thing[1]

    if l_a == l_b or r_a == r_b:

        return r_b - l_b + 1

    else:

        gcdt = gcd(t_a, t_b)

        M = gcdt - ((l_a-l_b)%gcdt) ## min((l_a-l_b)%gcdt, gcdt - (l_a-l_b)%gcdt)
        if M%gcdt == 0: M=0
        ##print('M: ', M)
        overhang = max(M + (r_b - l_b + 1) - (r_a - l_a + 1), 0)
        ##print('Overhang: ', overhang)
        overlap = max(r_b - l_b + 1 - overhang, 0)
        ##print('Overlap: ', overlap)

        N = gcdt - ((r_b-r_a)%gcdt) ## min((r_a-r_b)%gcdt, gcdt - (r_a-r_b)%gcdt)
        if N%gcdt == 0: N=0
        overhang = max(0, N + (r_b - l_b + 1) - (r_a - l_a + 1))
        overlap = max(overlap, max(0, r_b - l_b + 1 - overhang))

        ##print(M, N, ((l_a-l_b)%gcdt))
    
        return overlap
    
while True:
    
    A = input().split()

    l_a = int(A[0])
    r_a = int(A[1])
    t_a = int(A[2])

    B = input().split()

    l_b = int(B[0])
    r_b = int(B[1])
    t_b = int(B[2])

    print(lucky(l_a, r_a, t_a, l_b, r_b, t_b))

    break

## stress test

##for l_a in range(0, 10):
##    for r_a in range(l_a, 10):
##        for t_a in range(max(2, r_a+1), 10):
##            for l_b in range(0, 10):
##                for r_b in range(l_b, 10):
##                    for t_b in range(max(2, r_b+1), 10):
##
##                        program_answer = lucky(l_a, r_a, t_a, l_b, r_b, t_b)
##
##                        if r_a - l_a + 1 >= t_a or r_b - l_b + 1 >= t_b: continue
##
##                        max_overlap = 0
##                        current_overlap = 0
##
##                        for i in range(0, 100):
##
##                            if i%t_a >= l_a and i%t_a <= r_a and i%t_b >= l_b and i%t_b <= r_b:
##
##                                current_overlap += 1
##
##                            else:
##
##                                current_overlap = 0
##
##                            max_overlap = max(max_overlap, current_overlap)
##
##                        if max_overlap != program_answer:
##
##                            print(program_answer)
##                            print(l_a, r_a, t_a, l_b, r_b, t_b)
                            



import math

a1, b1, c1 = list(map(int, input().split(' ')))
a2, b2, c2 = list(map(int, input().split(' ')))

x = math.gcd(c1, c2)

delta1 = (a1 - a2)
delta1 = delta1 % x
if delta1 < 0:
  delta1 += x

delta2 = (a2 - a1)
delta2 = delta2 % x
if delta2 < 0:
  delta2 += x


a1 = b1 - a1 + 1
a2 = b2 - a2 + 1

sol = max(min(a1 - delta2, a2), min(a1, a2 - delta1))

print(max(0, sol))


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial


def gcd(a, b):
    if not b:
        return a
    else:
        return gcd(b, a % b)


def solution(la, ra, ta, lb, rb, tb):
    g = gcd(ta, tb)
    d = (lb - la) % g
    return min(ra - la + 1 - d, rb - lb + 1)


la, ra, ta = map(int, stdin.readline().split())
lb, rb, tb = map(int, stdin.readline().split())


ans = max(solution(la, ra, ta, lb, rb, tb), solution(lb, rb, tb, la, ra, ta))
stdout.write(str(max(0, ans)))

import math

la, ra, ta = map(int, input().split())
lb, rb, tb = map(int, input().split())

def f(la, ra, ta, lb, rb, tb):
	d = la - lb
	x = math.gcd(ta, tb)
	d = ((d % x) + x) % x
	return min(ra, rb - d)

ra = ra - la + 1
rb = rb - lb + 1
print(max([0, f(la, ra, ta, lb, rb, tb), f(lb, rb, tb, la, ra, ta)]))

a = input().split()
b = input().split()
la = int(a[0])
ra = int(a[1])
ta = int(a[2])
lb = int(b[0])
rb = int(b[1])
tb = int(b[2])

def gcd(x,y):
    if x*y == 0:
        return x+y
    else:
        if x>y:
            return gcd(x%y,y)
        else:
            return gcd(x,y%x)

g = gcd(ta,tb)
if (la % g >= lb % g):
    temp1 = min(rb-((la%g) - (lb%g))-lb+1,ra-la+1)
    temp2 = min(ra-la+1-(g-(la%g) + (lb%g)),rb-lb+1)
    best = max(temp1,temp2,0)
else:
    temp1 = min(ra-((lb%g) - (la%g))-la+1,rb-lb+1)
    temp2 = min(rb-lb+1-(g-(lb%g) + (la%g)),ra-la+1)
    best = max(temp1,temp2,0)
print(best)

import math

def gcd(a, b):
    """Returns the greatest common divisor of a and b.
    Should be implemented using recursion.

    >>> gcd(34, 19)
    1
    >>> gcd(39, 91)
    13
    >>> gcd(20, 30)
    10
    >>> gcd(40, 40)
    40
    """
    if b > a:
        return gcd(b, a)

    if a % b == 0:
        return b

    return gcd(b, a % b)


(la, ra, ta) = [int(s) for s in input().split(" ")]
(lb, rb, tb) = [int(s) for s in input().split(" ")]

delta = gcd(ta, tb)
# print(delta)

def overlap(al, ar, bl, br):
    return max(0, min(ar, br) - max(al, bl) + 1)

def eval(fst_, snd_):
    result_ = 0

    k1 = math.ceil(abs(fst_[0] - snd_[0])/delta)
    k2 = abs(fst_[0] - snd_[0]) // delta

    for k in (k1, k2):
        pos_sndl = snd_[0]
        pos_sndr = snd_[1]
        pos_fstl = k * delta + fst_[0]
        pos_fstr = k * delta + fst_[1]
        intersection = overlap(pos_sndl, pos_sndr, pos_fstl, pos_fstr)
        # print(intersection)
        # print(pos_sndl, pos_sndr, pos_fstl, pos_fstr, intersection)
        result_ = max(result_, intersection)


    # pos_sndl = snd_[0]
    # pos_sndr = snd_[1]
    # pos_fstl = fst_[0]
    # pos_fstr = fst_[1]
    # intersection = overlap(pos_sndl, pos_sndr, pos_fstl, pos_fstr)
    # result_ = max(result_, intersection)
    # # print(delta)
    # # print(intersection)
    # snd_k = (snd_[1] - fst_[0]) // delta + 1
    # fst_k = (snd_[0] - fst_[1]) // delta -1
    #
    # print(fst_k, snd_k)
    #
    # for k in range(fst_k, snd_k):
    #     pos_sndl = snd_[0]
    #     pos_sndr = snd_[1]
    #     pos_fstl = k * delta + fst_[0]
    #     pos_fstr = k * delta + fst_[1]
    #     intersection = overlap(pos_sndl, pos_sndr, pos_fstl, pos_fstr)
    #     # print(intersection)
    #     # print(pos_sndl, pos_sndr, pos_fstl, pos_fstr, intersection)
    #     result_ = max(result_, intersection)

    return result_


fst_ = (la, ra, ta)
snd_ = (lb, rb, tb)

result = max(eval(fst_, snd_), eval(snd_, fst_))
print(result)

import math

def main():
    la, ra, ta = [int(c) for c in input().split()]
    lb, rb, tb = [int(c) for c in input().split()]

    if lb < la:
        la, lb = lb, la
        ra, rb = rb, ra
        ta, tb = tb, ta

    gcd = math.gcd(ta, tb)
    lena, lenb = ra - la + 1, rb - lb + 1
    
    d = lb - la
    diff = d - (d // gcd) * gcd
    cur = lena - diff

    ans = max(0, min(cur, lenb))

    diff -= gcd
    diff = -diff
    cur = lenb - diff
    ans = max(ans, min(lena, cur))
    print(ans)

def __starting_point():
    main()

__starting_point()

from math import gcd

r = lambda: list(map(int, input().split()))
a, b = r(), r()
c = b[0] > a[0]
la, ra, ta = a if c else b
lb, rb, tb = b if c else a

g = gcd(ta, tb)
lna, lnb = ra - la + 1, rb - lb + 1
d = lb - la - (lb - la) // g * g
print(max(0, min(lna - d, lnb), min(lna, lnb - g + d)))


from math import gcd


def solve(la, ra, ta, lb, rb, tb):
    if la > lb:
        la, ra, ta, lb, rb, tb = lb, rb, tb, la, ra, ta
    da = ra-la
    db = rb-lb
    ans = 0
    dist = lb - la
    g = gcd(ta, tb)
    dist %= g
    if dist == 0:
        return min(da+1, db+1)
    la, ra = lb - dist, lb - dist + da
    ans = max(ans, 1+min(rb, ra) - lb)
    ans = max(ans, 1+min(rb, ra+g) - (la+g))
    return ans


def main():
    la, ra, ta = [int(i) for i in input().split()]
    lb, rb, tb = [int(i) for i in input().split()]
    print(solve(la, ra, ta, lb, rb, tb))


main()


from math import gcd

la, ra, ta = list(map(int, input().split()))
lb, rb, tb = list(map(int, input().split()))
k = gcd(ta, tb)
d1 = (la - lb)
d1 %= k
if d1 < 0:
    d1 += k
d2 = (lb - la)
d2 %= k
if d2 < 0:
    d2 += k
la = ra - la + 1
lb = rb - lb + 1
ans = max(0, min(la - d2, lb), min(la, lb - d1))
print(ans)


import math
la, ra, ta = map(int, input().split())
lb, rb, tb = map(int, input().split())
x = math.gcd(ta,tb)
d = la-lb
print(max(min(ra-la+1,rb-lb+1-d%x), min(rb-lb+1,ra-la+1-(-d)%x),0))

# import time
# start_time = int(round(time.time() * 1000))

from math import gcd




def solve(la, ra, ta, lb, rb, tb):

    m = gcd(ta, tb)
    m1 = la % m
    k = (lb - m1 + m - 1) // m
    y = k*m + m1

    return max(0, min(ra-la+1, rb-y+1))



la, ra, ta = list(map(int, input().split()))
lb, rb, tb = list(map(int, input().split()))
    

# print(solve(la, ra, ta, lb, rb, tb))
# print(solve(lb, rb, tb, la, ra, ta))

print(max(solve(la, ra, ta, lb, rb, tb), solve(lb, rb, tb, la, ra, ta)))




# end_time = int(round(time.time() * 1000))
# print('Execution Time : ', (end_time - start_time), 'ms')