Problem:
 Score: 600 points    Problem Statement  Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.  They start simultaneously at the same point and moves as follows towards the east :   Takahashi runs A_1 meters per minute for the first T_1 minutes,  then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.  Aoki runs B_1 meters per minute for the first T_1 minutes,  then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.   How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.      Constraints   1 \leq T_i \leq 100000  1 \leq A_i \leq 10^{10}  1 \leq B_i \leq 10^{10}  A_1 \neq B_1  A_2 \neq B_2  All values in input are integers.         Input  Input is given from Standard Input in the following format:  T_1  T_2  A_1  A_2  B_1  B_2       Output  Print the number of times Takahashi and Aoki will meet each other. If they meet infinitely many times, print infinity instead.        Sample Input 1 1 2
10 10
12 4      Sample Output 1 1  They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start.       Sample Input 2 100 1
101 101
102 1      Sample Output 2 infinity  They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times.       Sample Input 3 12000 15700
3390000000 3810000000
5550000000 2130000000      Sample Output 3 113  The values in input may not fit into a 32 -bit integer type.

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            
            ok = mid
        else:
            
            ng = mid
    return ok

T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()


def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a > b and a1 <= b1 or a < b and a1 >= b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 > b1 and a2 <= b2 or a1 < b1 and a2 >= b2:
        cnt += 1
    return a2, b2, cnt


def check(x):
    a = (T1 * A1 + T2 * A2) * x
    b = (T1 * B1 + T2 * B2) * x
    _, _, cnt = calc(a, b)
    return cnt >= 1


a, b, cnt = calc(0, 0)
if a == b:
    print('infinity')
    exit()


res = bisearch_max(-1, 10**18, check)

if res == -1:
    print(0)
    exit()


ans = max(0, res * 2 - 1)

a = (T1 * A1 + T2 * A2) * res
b = (T1 * B1 + T2 * B2) * res

_, _, cnt = calc(a, b)
ans += cnt
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            
            ok = mid
        else:
            
            ng = mid
    return ok

T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()


def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a > b and a1 <= b1 or a < b and a1 >= b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 > b1 and a2 <= b2 or a1 < b1 and a2 >= b2:
        cnt += 1
    return a2, b2, cnt


def check(x):
    a = (T1 * A1 + T2 * A2) * x
    b = (T1 * B1 + T2 * B2) * x
    _, _, cnt = calc(a, b)
    return cnt >= 1


a, b, cnt = calc(0, 0)
if a == b:
    print('infinity')
    exit()


res = bisearch_max(-1, 10**18, check)

if res == -1:
    print(0)
    exit()


ans = max(0, res * 2 - 1)

a = (T1 * A1 + T2 * A2) * res
b = (T1 * B1 + T2 * B2) * res

_, _, cnt = calc(a, b)
ans += cnt
print(ans)

Solution (Python):
def main():
    t1,t2=map(int,input().split())
    a1,a2=map(int,input().split())
    b1,b2=map(int,input().split())
    if a1<b1:
        a1,b1,a2,b2 = b1,a1,b2,a2

    d1 = a1*t1
    d2 = b1*t1

    dd1 = d1 - d2

    d1 += a2*t2
    d2 += b2*t2

    if d1 == d2:
        return "infinity"

    dd2 = d1 - d2

    if dd1 * dd2 > 0:
        return 0
    else:
        d1 += a1*t1
        d2 += b1*t1

        dd3 = d1 - d2

        if dd2 * dd3 > 0:
            return 1
        else:
            d1 += a2*t2
            d2 += b2*t2

            dd4 = d1 - d2
        if dd3 * dd4 > 0:
            return 2
        else:
            if dd1 > dd3:
                if dd1 % (dd1-dd3) == 0:
                    return (dd1 // (dd1-dd3) )*2
                else:
                    return (dd1 // (dd1-dd3) )*2+1
            else:
                if dd2 % (dd2-dd4) == 0:
                    return (dd2 // (dd2-dd4) )*2 +1
                else:
                    return (dd2 // (dd2-dd4) )*2+2



print(main())

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    T1,T2 = MI()
    A1,A2 = MI()
    B1,B2 = MI()
    if T1*A1+T2*A2==T1*B1+T2*B2:
        print("infinity")
        exit()
    A1*=T1
    B1*=T1
    A2*=T2
    B2*=T2
    diff1 = A1-B1
    diff2 = A2-B2
    

    if diff1*diff2>0:
        print(0)
    else:
        if abs(diff1)>abs(diff2):
            print(0)
            exit()
        else:
            ans = 2 * (abs(diff1) // abs(diff1+diff2))
            if diff1//(diff1+diff2) == diff1/(diff1+diff2):
                ans -= 1 
            print(ans + 1)
    

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

T1, T2 = IL()
a1, a2 = IL()
b1, b2 = IL()
if a1*T1 + a2*T2 > b1*T1 + b2*T2:
  pass
else:
  a1,a2,b1,b2 = b1,b2,a1,a2

if a1*T1 + a2*T2 == b1*T1 + b2*T2:
  print("infinity")
elif a1*T1 >= b1*T1:
  print(0)
else:
  half = b1*T1 - a1*T1
  x = (a1*T1 + a2*T2 - (b1*T1 + b2*T2))
  
  loop = half//x + 1
  if (loop - 1)*x == half:
    print(loop*2 -2)
  else:
    print(loop*2 -1)

Solution (Python):
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())

if B1>A1:
  A1,A2,B1,B2=B1,B2,A1,A2
  
if A1*T1+A2*T2>B1*T1+B2*T2:
  print(0)
  exit()
if A1*T1+A2*T2==B1*T1+B2*T2:
  print("infinity")
  exit()

x=(T1*A1-T1*B1)//((B1-A1)*T1+(B2-A2)*T2)+1
ans=2*x-1
if (T1*A1-T1*B1)%((B1-A1)*T1+(B2-A2)*T2)==0:
  ans-=1
print(ans)

Solution (Python):


import sys
import math
import collections




tmp = input().split()
t1,t2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
a1,a2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
b1,b2 = list(map(lambda a: int(a), tmp))

if(a1*t1+a2*t2==b1*t1+b2*t2):
	print("infinity")
	sys.exit()
diff=(a1*t1+a2*t2)-(b1*t1+b2*t2)


if(diff>0):
	c1=a1-b1
	c2=a2-b2
else:
	c1=b1-a1
	c2=b2-a2

if(c1>0):
	print("0")
	sys.exit()

diff=c1*t1+c2*t2
pitch=c1*t1*-1

ans=pitch//diff*2+1
if(pitch%diff==0):
	ans-=1
print(ans)

Solution (Python):
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
if a1*t1+a2*t2>=b1*t1+b2*t2:
    a1,a2,b1,b2 = b1,b2,a1,a2
d = b1*t1+b2*t2 - (a1*t1+a2*t2)
if d == 0:
    print('infinity')

elif a1*t1<b1*t1:
    print(0)
else:
    if (a1*t1 - b1*t1)*2%d ==0:
        print(((a1*t1 - b1*t1)*2+d-1)//d)
    else:
        print((a1*t1 - b1*t1)//d*2+1)

Solution (Python):

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
p = (A1 - B1) * T1
q = (A2 - B2) * T2
if p < 0:
    p *= -1
    q *= -1

if p + q > 0:
    print(0)
elif p + q == 0:
    print('infinity')
else:
    s = -p // (p + q)
    t = -p % (p + q)
    if t != 0:
        print(s*2+1)
    else:
        print(s*2)

Solution (Python):
def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    p = (A1 - B1) * T1
    q = (A2 - B2) * T2
    if p < 0:
        p *= -1
        q *= -1

    if p + q > 0:
        print(0)
    elif p + q == 0:
        print('infinity')
    else:
        s = -p // (p + q)
        t = -p % (p + q)
        if t != 0:
            print(s*2+1)
        else:
            print(s*2)


if __name__ == '__main__':
    solve()

Solution (Python):
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    sa1*=-1
    sa2*=-1
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=((-sa1)//(sa2+sa1))*2+1
    if sa1%(sa1+sa2)==0:
        ans-=1
    print(ans)

Solution (Python):
import sys

t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
  print ("infinity")
  sys.exit(0)

if a > b:
  a, b = b, a
  ha, hb = hb, ha

gap = b - a
hgap = ha - hb

if hgap < 0:
  print (0)
  sys.exit(0)

ans = 2 * (hgap // gap) + (1 if hgap % gap > 0 else 0)
print (ans)

Solution (Python):
T = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))


da, db = 0, 0
for i in range(2):
    da += T[i] * A[i]
    db += T[i] * B[i]

if da == db:
    print("infinity")
    exit()

x = (B[0] - A[0]) * T[0]
y = da - db

print(max(0, x // y * 2 + (0 if x % y == 0 else 1)))

Solution (Python):
def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    p = (A1 - B1) * T1
    q = (A2 - B2) * T2
    if p < 0:
        p *= -1
        q *= -1

    if p + q > 0:
        print(0)
    elif p + q == 0:
        print('infinity')
    else:
        s = -p // (p + q)
        t = -p % (p + q)
        if t != 0:
            print(s*2+1)
        else:
            print(s*2)


if __name__ == '__main__':
    solve()

Solution (Python):
s,t,a,b,x,y=map(int,open(0).read().split())
if a*s+b*t==x*s+y*t:
  print('infinity')
  exit()
if a<x:a,b,x,y=x,y,a,b
if a*s+b*t>x*s+y*t:
  print(0)
  exit()
n=(a*s-x*s)/(x*s+y*t-(a*s+b*t))
m=int(n)
print(m*2+(n>m))

Solution (Python):
s,t,a,b,x,y=map(int,open(0).read().split())
if a*s+b*t==x*s+y*t:
  print('infinity')
  exit()
if a<x:a,b,x,y=x,y,a,b
if a*s+b*t>x*s+y*t:
  print(0)
  exit()
n=(a*s-x*s)/(x*s+y*t-(a*s+b*t))
m=int(n)
print(m*2+(n>m))

Solution (Python):
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
X=(B1-A1)*T1
Y=(B2-A2)*T2
if X>0:
    X=-X
    Y=-Y
if X+Y<0:
    print(0)
elif X+Y==0:
    print("infinity")
else:
    A=(-X)//(X+Y)
    B=(-X)%(X+Y)
    if B!=0:
        print(2*A+1)
    else:
        print(2*A)

Solution (Python):
t1, t2 = [ int(v) for v in input().split() ]
a1, a2 = [ int(v) for v in input().split() ]
b1, b2 = [ int(v) for v in input().split() ]

if a1*t1 + a2*t2 == b1*t1 + b2*t2:
    ans = -1
else:
    if a1*t1 + a2*t2 < b1*t1 + b2*t2:
        a1, b1 = b1, a1
        a2, b2 = b2, a2

    mind = a1*t1 - b1*t1
    if mind > 0:
        ans = 0
    else:
        lastd = a1*t1 + a2*t2 - b1*t1 - b2*t2
        mind = abs(mind)
        if mind % lastd == 0:
            ans = 2 * (mind // lastd) 
        else:
            ans = 2 * (mind // lastd) + 1
    
print(ans if ans != -1 else "infinity")

Solution (Python):
T = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = T[0]*A[0] + T[1]*A[1]
b = T[0]*B[0] + T[1]*B[1]

if(a==b):
    print("infinity")
    exit()

if(a<b):
    A[0], B[0] = B[0], A[0]
    A[1], B[1] = B[1], A[1]


a = T[0]*A[0] 
b = T[0]*B[0] 

if a>b:
    print(0)
    exit()

left = 1
right = 10**20

while left+1!=right:
    center = (left+right)//2
    tak = a + (center-1) * (A[0]*T[0]+A[1]*T[1])
    aok = b + (center-1) * (B[0]*T[0]+B[1]*T[1])

    if(tak==aok):
        ans = (center-1)*2
        print(ans)
        exit()
    elif aok<tak:
        right = center
    else:
        left = center

ans = (left-1)*2 + 1
print(ans)

Solution (Python):
def f():
	from math import ceil
	T1,T2 = map(int,input().split())
	A1,A2 = map(int,input().split())
	B1,B2 = map(int,input().split())
	if B1 > A1:
		A1,A2,B1,B2 = B1,B2,A1,A2
	diff1 = (A1 - B1) * T1
	fac = (B2 - A2) * T2 - diff1
	if fac == 0:
		print("infinity")
	elif diff1 / fac < 0:
		print(0)
	elif diff1 / fac <= 1:
		print(1)
	else:
		print(2 * ceil(diff1 / fac) - int(diff1 % fac != 0))
f()

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2

if P > 0:
    P *= -1
    Q *= -1
    
if P + Q < 0:
    print(0)
elif P + Q == 0:
    print("infinity")
else:
    S = -P // (P + Q)
    T = -P % (P + Q)
    if T != 0:
        print(S * 2 + 1)
    else:
        print(S * 2)

Solution (Python):
T1,T2 = map(int, input().split())
A1,A2 = map(int, input().split())
B1,B2 = map(int, input().split())
d1,d2 = (A1-B1)*T1,(A2-B2)*T2
if d1 < 0: d1,d2 = -d1,-d2
if d1+d2 == 0: print("infinity")
elif d1+d2>0: print(0)
elif d1 % (-(d1+d2)) == 0: print(d1//(-(d1+d2))*2)
else: print(d1//(-(d1+d2))*2+1)

Solution (Python):
import math
t1,t2 = map(int, input().split())
c1,c2 = map(int, input().split())
d1,d2 = map(int, input().split())

x = [(c1*t1, c2*t2),(d1*t1, d2*t2)]

x.sort(reverse=True)

if x[0][0]+x[0][1] == x[1][0]+x[1][1]:
    print("infinity")
elif x[0][0]+x[0][1] > x[1][0]+x[1][1]:
    print(0)
else:
    n = (x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1])
    m = math.ceil(n)
    if math.floor(n) == m:
        print(2*m)
    else:
        print(2*m-1)

Solution (Python):
from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
    print("infinity")
    exit()
if a1*(a1+a2) > 0:
    print(0)
    exit()

x = -a1/(a1+a2)
n = ceil(x)
if n == x:
    print(2*n)
else:
    print(2*n-1)

Solution (Python):
t,T,a,A,b,B=map(int,open(0).read().split())
x,y=(b-a)*t,(A-B)*T
if y-x==0:
 r="infinity"
else:
 s,t=divmod(x,y-x)
 r=max(0,s*2+(t!=0))
print(r)

Solution (Python):
t,T,a,A,b,B=map(int,open(0).read().split())
x,y=(b-a)*t,(A-B)*T
if y-x==0:
 r="infinity"
else:
 s,t=divmod(x,y-x)
 r=max(0,s*2+bool(t))
print(r)

Solution (Python):

import sys


def solve(T: "List[int]", A: "List[int]", B: "List[int]"):
    dif1 = T[0]*(A[0] - B[0])
    dif2 = T[1]*(A[1] - B[1])

    if dif1+dif2 == 0:
        print('infinity')
        return
    
    if dif1*dif2>0 or abs(dif1)>abs(dif2):
        print(0)
        return
    
    
    t = abs(dif1)
    a = abs(dif2)

    if t%abs(t-a)==0:
        print(2*(t//abs(t-a)))
    else:
        print(2*(t//abs(t-a))+1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = [int(next(tokens)) for _ in range(2)]  
    A = [int(next(tokens)) for _ in range(2)]  
    B = [int(next(tokens)) for _ in range(2)]  
    solve(T, A, B)

if __name__ == '__main__':
    main()

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 < B1 :
    A1, A2, B1, B2 = B1, B2, A1, A2

def solve() :    
    A = T1 * A1 + T2 * A2
    B = T1 * B1 + T2 * B2
    
    if A == B :
        return 'infinity'
    
    if (A1 > B1 and A > B) or (A1 < B1 and A < B) :
        return 0
    
    D0 = abs(A1 - B1) * T1
    D = abs(A - B)
    
    if D0 % D == 0 :
        return D0 // D * 2
    else :
        return D0 // D * 2 + 1
        
print(solve())

Solution (Python):
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(b-a)*t,(A-B)*T
if y-x==0:
 r="infinity"
else:
 s,t=divmod(x,y-x)
 r=max(0,s*2+(1 if t else 0))
print(r)

Solution (Python):
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())
if T1*A1 + T2*A2 == T1*B1 + T2*B2:
    print("infinity")
else:
    if T1*A1 + T2*A2 > T1*B1 + T2*B2:
        A1, B1 = B1, A1
        A2, B2 = B2, A2
    if T1*A1 < T1*B1:
        print("0")
    else:
        forward = T1*A1 - T1*B1
        shrink = (T1*B1 + T2*B2) - (T1*A1 + T2*A2)
        
        
        if forward % shrink == 0:
            print(str(2*forward//shrink))
        else:
            print(str((forward//shrink + 1)*2 - 1))

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2

if P > 0:
    P *= -1
    Q *= -1

if P + Q < 0:
    print(0)
elif P + Q == 0:
    print('infinity')
else:
    S, T = divmod(-P, P+Q)
    if T != 0:
        print(S * 2 + 1)
    else:
        print(S * 2)

Solution (Python):
from sys import exit

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 > B1:
  A1, B1 = B1, A1
  A2, B2 = B2, A2

if A2 < B2:
  print(0)
  exit()

if A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2:
  print(0)
  exit()

if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
  print('infinity')
  exit()

a = B1 * T1 - A1 * T1
b = (A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)
t = a // b

if a % b == 0:
  print(t * 2)
else:
  print(t * 2 + 1)

Solution (Python):
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
T = T1 + T2
C = A1*T1+A2*T2
D = B1*T1+B2*T2
if C == D:
    print("infinity")
    exit()
if C > D:
    A1,B1=B1,A1
    A2,B2=B2,A2
    C,D  = D,C
if A1 < B1:
    print(0)
    exit()
ok = 0
ng = pow(10,30)
while ng - ok > 1:
    md = (ok + ng)//2
    if A1*T1+C*md>=B1*T1+D*md:
        ok = md
    else:
        ng = md
ans = 2*ok + 1
if A1*T1+C*ok == B1*T1+D*ok:
    ans -= 1
print(ans)

Solution (Python):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if a1 < b1:
  a1, b1 = b1, a1
  a2, b2 = b2, a2
f = (a1-b1)*t1
l = (b2-a2)*t2
if f > l:
  print(0)
elif f == l:
  print("infinity")
else:
   print(2 * (f//(l-f)) + int(f%(f-l)!=0))

Solution (Python):
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(a-b)*t,(A-B)*T
if x+y==0:
 r="infinity"
else:
 s,t=divmod(-x, x+y)
 r=0 if s<0 else s*2+(1 if t else 0)
print(r)

Solution (Python):
import math
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
C1,C2=A1-B1,A2-B2
D1,D2=T1*C1,T2*C2

if D1==-D2:
    print("infinity")
    exit(0)

diff=0
x=-1
ans=0

if  D1*(D1+D2)<0:
    ans+=1
    diff+=D1+D2
else:
    print(ans)
    exit(0)

if diff*(diff+D1)<=0:
    ans+=2*abs((diff+D1)//(D1+D2))

if diff+(D1+D2)*abs((diff+D1)//(D1+D2))+D1==0:
    ans+=1
if diff+(D1+D2)*abs((diff+D1)//(D1+D2))+D1+D2==0:
    ans+=1

print(ans)

Solution (Python):
import numpy

t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())

v1=b1-a1
v2=b2-a2

x1=v1*t1
x2=v2*t2
di = abs(abs(x2)-abs(x1))
if numpy.sign(x1)==numpy.sign(x2):
    print(0)
elif abs(x2)<abs(x1):
    print(0)
elif abs(x1)==abs(x2):
    print("infinity")
else:
    if abs(x1)%di==0:
        print(abs(int(2*(x1/di))))
        
    else:
        print(abs(int(2*(x1//di)+1)))

Solution (Python):
t1,t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1,b2 = map(int, input().split())
x,y=(a1-b1)*t1 + (a2-b2)*t2, (a1-b1)*t1
if x == 0:
    print("infinity")
elif x*y > 0:
    print(0)
else:
    s,t = divmod(abs(y), abs(x))
    print(s*2+(1 if t else 0))

Solution (Python):
def main():
    import sys
    import math
    s,t=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    if a[0]<b[0]:
        a,b=b,a
    x=(a[0]-b[0])*s
    y=(a[1]-b[1])*t

    if x+y>0:
        print(0)
        sys.exit()
    elif x+y==0:
        print('infinity')
        sys.exit()

    y=abs(y)
    if x%(y-x)==0: ans=(x//(y-x))*2
    else: ans=math.floor(x/(y-x))*2+1
    print(ans)


 
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    t = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    diff_0 = a[0]-b[0]
    diff_1 = a[1]-b[1]

    if diff_0*diff_1 > 0:
        return 0
    
    d_one_iter = diff_0*t[0]+diff_1*t[1]

    if diff_0*d_one_iter > 0:
        return 0
    if diff_0*d_one_iter == 0:
        return 'infinity'
    
    if abs(diff_0*t[0])%abs(d_one_iter) == 0:
        return 2*abs(diff_0*t[0])//abs(d_one_iter)
    else:
        return 2*(abs(diff_0*t[0])//abs(d_one_iter))+1

if __name__ == "__main__":
    print(main())

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

D1 = T1 * A1 - T1 * B1
D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2

if D1 * D2 > 0:
    print(0)
elif D2 == 0:
    print("infinity")
else:
    D1 = abs(D2 - D1)
    D2 = abs(D2)
    c = (D1 // D2) * 2 - 1
    if D1 % D2 == 0:
        c -= 1
    print(c)

Solution (Python):
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())

A1 *= T1
B1 *= T1
A2 *= T2
B2 *= T2

if A1+A2 > B1+B2: 
    A1,B1 ,A2,B2 = B1,A1 ,B2,A2

if A1+A2 == B1+B2:
    print("infinity")
    exit()

if A1 < B1:
    print(0)
    exit()

def nibu(l,r):
    if l >= r:
        return l
    c = (l+r+1)//2
    if (A1+A2)*(c-1)+A1 >= (B1+B2)*(c-1)+B1:
        return nibu(c,r)
    else:
        return(nibu(l,c-1))

ans = nibu(0,10**100)
if (A1+A2)*(ans-1)+A1 == (B1+B2)*(ans-1)+B1:
    print(ans*2-2)
else:
    print(ans*2-1)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
'''
def GI(V,E,DAG=False,index=0):
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[1:])
            bb=(inp[1:])
        g[a].append(b)
        if g[b].append(a)
        h.append(b)
'''

def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
 
show_flg=False
show_flg=True

ans=0

s,t=LI()
a,c=LI()
b,d=LI()
if a*s+c*t<b*s+d*t:
    a,b,c,d=b,a,d,c
if a*s+c*t==b*s+d*t:
    print('infinity')
    exit()
p,q=(a-b)*s,(c-d)*t
if p>0 and p+q>0:
    print(0)
    exit()


n=-p//(p+q)
ans=2*n+1
if -p%(p+q)==0:
    ans-=1

print(ans)

Solution (Python):

t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
d1 = (b1 - a1) * t1
d2 = (b2 - a2) * t2
if d1 > 0:
    d1 = -d1
    d2 = -d2
if d1 + d2 < 0:
    print(0)
    exit()
if d1 + d2 == 0:
    print('infinity')
    exit()

ok, ng = 0, 10**20
while ng - ok > 1:
    m = (ok + ng) // 2
    if m * d2 + (m + 1) * d1 <= 0:
        ok = m
    else:
        ng = m
if ok * d2 + (ok + 1) * d1 == 0:
    print(2 * ok)
else:
    print(2 * ok + 1)

Solution (Python):

T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

d1 = A1*T1-B1*T1
d2 = A2*T2-B2*T2

import sys
if d1+d2 == 0:
    print('infinity')
    sys.exit()
elif d1*d2 > 0 or (abs(d1)-abs(d2)>0 and d1*d2<0):
    print(0)
    sys.exit()
    
else:
    start = abs(d1)
    delta = abs(d2+d1)
    ans = start//delta * 2
    if (start%delta)!=0:
        ans += 1
    print(ans)

Solution (Python):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

v1, v2 = b1 - a1, b2 - a2
x1, x2 = t1 * v1, t2 * v2
if x1 + x2 == 0:
  print('infinity')
else:
  if x1 < 0:
    x1, x2 = [x1 * -1, x2 * -1]

  if x1 + x2 > 0:
    print(0)
  else:
    dx = abs(x1 + x2)
    c = (x1 // dx) * 2 + 1
    if x1 % dx == 0:
      c -= 1
    
    print(c)

Solution (Python):
def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    if A1 < B1 and A2 < B2:
        return 0
    elif A1 > B1 and A2 > B2:
        return 0

    C1, C2 = B1-A1, B2-A2

    if C1 < 0:
        C1, C2 = -C1, -C2

    dist = C1*T1 + C2*T2
    if dist == 0:
        return 'infinity'
    elif dist > 0:
        return 0

    diff = C1*T1
    num = diff // abs(dist) * 2

    if diff % abs(dist):
        num += 1

    return num


print(solve())

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    t1, t2 = list(map(int, readline().split()))
    a1, a2 = list(map(int, readline().split()))
    b1, b2 = list(map(int, readline().split()))
    a1 -= b1
    a2 -= b2
    if a1 * t1 + a2 * t2 == 0:
        print("infinity")
        exit()
    elif a1 < 0:
        if a1 * t1 + a2 * t2 < 0:
            print(0)
            exit()
    elif a1 > 0:
        if a1 * t1 + a2 * t2 > 0:
            print(0)
            exit()
    s = abs(a1 * t1) // abs(a1 * t1 + a2 * t2)
    m = abs(a1 * t1) % abs(a1 * t1 + a2 * t2)
    print(s * 2 if m == 0 else s * 2 + 1)


if __name__ == '__main__':
    solve()

Solution (Python):
from math import floor
t1, t2 = map(int,input().split())
a1, a2 = map(int,input().split())
b1, b2 = map(int,input().split())

v1 = a1-b1
v2 = a2-b2

m1 = v1*t1
m2 = v2*t2

if m1>0:
    m1 *= -1
    m2 *= -1

if m1 == -m2:
    print('infinity')
elif m1+m2>0:
    ans = floor(-m1/(m2+m1)) * 2
    if m1%(m2+m1) != 0:
        ans += 1
    print(ans)
else:
    print(0)

Solution (Python):
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

C1 = (A1-B1)*T1
C2 = (A2-B2)*T2

if C1+C2==0:
    print('infinity')
elif C1*(C1+C2)>0:
    print(0)
else:
    if abs(C1)%abs(C1+C2)==0:
        print(abs(C1)//abs(C1+C2)*2)
    else:
        print(abs(C1)//abs(C1+C2)*2+1)

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = (A1 - B1) * T1
d2 = d1 + (A2 - B2) * T2
if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
    print(0)
    exit()
if d2 == 0:
    print('infinity')
    exit()
d1 = abs(d1)
d2 = abs(d2)
if d1 % d2 == 0:
    print(d1 // d2 * 2)
else:
    print(1 + d1 // d2 * 2)

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
flag = False
if ((T1*A1 > T1*B1) and (T1*A1 + T2*A2 <= T1*B1 + T2*B2)) or ((T1*A1 < T1*B1) and (T1*A1 + T2*A2 >= T1*B1 + T2*B2)):
  flag = True

if flag:
  a1 = abs(T1*A1 - T1*B1)
  a2 = abs(T1*A1+T2*A2-T1*B1-T2*B2)
  if a2 == 0:
    print("infinity")
  else:
    b1 = a1//a2
    b2 = a1 % a2
    if b2 == 0:
      print(a1//a2*2)
    else:
  	  print(1 + a1//a2*2)
else:
  print(0)

Solution (Python):
T1, T2=(int(i) for i in input().split())
A1, A2=(int(i) for i in input().split())
B1, B2=(int(i) for i in input().split())

if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif ((A1>B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)>0)) or ((A1<B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)<0)):
    print(0)
else:
    d=abs(T1*A1+T2*A2-(T1*B1+T2*B2))
    ss=0
    if abs(T1*(A1-B1))%d==0:
        ss=1
        
    print(abs(T1*(A1-B1))//d*2-ss+1)

Solution (Python):
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())

LA = T1*A1+T2*A2
LB = T1*B1+T2*B2
if LA == LB:
    print("infinity")
    exit()
elif LA < LB:
    LA, LB = LB, LA 
    A1, B1 = B1, A1
    A2, B2 = B2, A2

l = LA - LB
r = T1*B1-T1*A1 
if r < 0:
    print(0)
    exit()
else:
    
    
    if r%l==0:
        print( (r//l)*2)
    else:
        print( (r//l)*2 +1 )

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
diff1 = (A1 - B1) * T1
diff2 = (A2 - B2) * T2

if diff1 > 0:
    diff1, diff2 = -1 * diff1, -1 * diff2

if diff1 + diff2 < 0:
    print(0)
elif diff1 + diff2 == 0:
    print('infinity')
else:
    q, r = divmod(-diff1, diff1 + diff2)
    print(2*q + (1 if r != 0 else 0))

Solution (Python):
import sys
import string
input = sys.stdin.readline

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 < B1 and A2 < B2:
    print(0)
    exit()
if A1 > B1 and A2 > B2:
    print(0)
    exit()
delta1 = T1 * A1 - T1 * B1
delta2 = T2 * A2 - T2 * B2
if (delta1 + delta2) / delta1 > 0:
    print(0)
    exit()
if delta1 + delta2 == 0:
    print('infinity')
    exit()
if delta1 % (delta1 + delta2) == 0:
    print(2 * abs(delta1 // (delta1 + delta2)))
else:
    print(2 * abs(delta1 // (delta1 + delta2)) - 1)