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):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
p = (a1 - b1) * t1
q = (a2 - b2) * t2
if p > 0:
    p = -p
    q = -q
if p + q == 0:
    print('infinity')
elif p + q < 0:
    print(0)
else:
    print((-p // (p + q)) * 2 + bool(-p % (p + q)))

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

C1 = A1 - B1
C2 = A2 - B2
if C1 > 0:
    C1, C2 = -C1, -C2

x1 = C1 * T1 + C2 * T2
x2 = x1 + C1 * T1

if x1 == 0:
    print('infinity')
elif x1 < 0:
    print(0)
else:
    if 0 < x2:
        count = 1
    elif 0 == x2:
        count = 2
    else:
        n = (-x2 + x1 - 1) // x1
        count = 1 + 2 * n
        if x2 % x1 == 0:
            count += 1
    print(count)

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())

sa = t1*a1+t2*a2-t1*b1-t2*b2

if sa==0:
    print("infinity")
else:
    if sa>0:
        if a1>b1:
            print(0)
        else:
            ganba=t1*b1-t1*a1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)
            
    else:
        sa=sa*(-1)
        if b1>a1:
            print(0)
        else:
            ganba=t1*a1-t1*b1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)

Solution (Python):
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
import time
start=time.time()
x=(a1-b1)*t1
y=(a2-b2)*t2
if x<0:
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    if -1*x%(x+y):
        print(-1*x//(x+y)*2+1)
    else:
        print(-1*x//(x+y)*2)
else:
    x*=-1
    y*=-1
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    if -1*x%(x+y):
        print(-1*x//(x+y)*2+1)
    else:
        print(-1*x//(x+y)*2)

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

p,q=(a1-b1)*t1,(a2-b2)*t2
if p>0:
  p*=-1
  q*=-1
if p+q<0:
  print(0)
if p+q==0:
  print('infinity')
if p+q>0:
  s,t=divmod((-p),(p+q))
  print(s*2+1) if t!=0 else print(s*2)

Solution (Python):
import math

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

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D, D1 = (A1 - B1) * T1 + (A2 - B2) * T2, (A1 - B1) * T1
    if (D1 > 0) == (D > 0):
        print(0)
    else:
        if D1 % D == 0:
            print(2 * math.floor(-D1 / D))
        else:
            print(2 * math.floor(-D1 / D) + 1)

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

sum_a = t1 * a1 + t2 * a2
sum_b = t1 * b1 + t2 * b2

if sum_a == sum_b:
    print('infinity')
    exit()
    
if sum_a > sum_b:
    big_sum = sum_a
    big_1 = a1*t1
    big_2 = a2*t2
    sml_sum = sum_b
    sml_1 = b1*t1
    sml_2 = b2*t2
else:
    big_sum = sum_b
    big_1 = b1*t1
    big_2 = b2*t2
    sml_sum = sum_a
    sml_1 = a1*t1
    sml_2 = a2*t2
    
if sml_1 < big_1:
    print(0)
    exit()
    

    
n = (big_1-sml_1) // (sml_sum-big_sum)

if (big_1-sml_1) % (sml_sum-big_sum) == 0:
    print(n*2)
else:
    print(n*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 = (b2-a2)*t2

if d1 == d2:
    print('infinity')
 
if d1 * (d2 - d1) < 0:
    print(0)

if d1*(d2-d1)>0:
    if d1%(d1-d2)==0:
        print((d1//(d2-d1))*2)
    else:
        print((d1//(d2-d1))*2+1)

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()]

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

if d1 == d2:
    print('infinity')

if d1 * (d2 - d1) < 0:
    print(0)

if d1 * (d2 - d1) > 0:
    if d1 % (d2 - d1) != 0:
        print(d1 // (d2 - d1) * 2+ 1)
    else:
        print(d1 // (d2 - d1) * 2)

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



t1, t2 = list(map(int, sys.stdin.buffer.readline().split()))
a1, a2 = list(map(int, sys.stdin.buffer.readline().split()))
b1, b2 = list(map(int, sys.stdin.buffer.readline().split()))

da1 = t1 * a1
da2 = t2 * a2
db1 = t1 * b1
db2 = t2 * b2
if da1 + da2 > db1 + db2:
    a1, b1 = b1, a1
    a2, b2 = b2, a2
    da1, db1 = db1, da1
    da2, db2 = db2, da2



if da1 + da2 == db1 + db2:
    print('infinity')
    exit()

if da1 < db1:
    print(0)
    exit()


cnt = abs(da1 - db1) / abs(da1 + da2 - db1 - db2)
ans = int(cnt) * 2 + 1
if cnt == int(cnt):
    ans -= 1
print(ans)

Solution (Python):
tt = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

p = (aa[0] - bb[0]) * tt[0]
q = (aa[1] - bb[1]) * tt[1]

if p > 0:
	p *= -1
	q *= -1

if p + q < 0:
	print(0)
elif p + q == 0:
	print("infinity")
else:
	r, s = divmod((-1 * p), (p + q))
	if s == 0:
		print(r * 2)
	else:
		print(r * 2 + 1)

Solution (Python):
t=list(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
p=t[0]*(a[0]-b[0])
q=t[1]*(a[1]-b[1])
if p+q==0:
    print('infinity')
elif p+q<0:
    print(0)
else:
    k=-p//(p+q)
    if -p%(p+q)==0:
        print(2*k)
    else:
        print(2*k+1)

Solution (Python):
from sys import stdin
T1,T2 = [int(x) for x in stdin.readline().rstrip().split()]
A1,A2 = [int(x) for x in stdin.readline().rstrip().split()]
B1,B2 = [int(x) for x in stdin.readline().rstrip().split()]
f = (A1-B1)*T1
s = (A2-B2)*T2
 
if f + s == 0:
    print("infinity")

else:
    if (f > 0) and ((f + s) > 0):
        print(0)
    
    elif (f < 0) and ((f + s) < 0):
        print(0)
        
    elif f > 0 and f + s < 0:
        if  f % (-(f + s)) == 0:
            print((f//-(f+s))*2)
        else:
            print((f//-(f+s))*2+1)
    
    elif f < 0 and f + s > 0:
        if (-f) % (f+s) == 0:
            print((-f//(f+s))*2)
        else:
            print((-f//(f+s))*2+1)

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

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

fin_gap = t1 * (a1 - b1) + t2 * (a2 - b2)
mid_gap = t1 * (a1 - b1) 

if fin_gap == 0:
  print("infinity")
else:
  if mid_gap * fin_gap > 0:
    print(0)
  else:
    
    mod = abs(mid_gap) % abs(fin_gap)
    q = abs(mid_gap) // abs(fin_gap)
    
    if mod == 0:
      ans = q * 2
    else:
      ans = q * 2 + 1
    
    print(ans)

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()]

c1,c2 = (a1-b1)*t1,(a2-b2)*t2

if c1 < 0:
    c1 *= -1
    c2 *= -1

if  c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c1 % (c1 + c2) == 0 else num * 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 = (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(2*(d1//(-d1-d2)))
else: print(2*(d1//(-d1-d2))+1)

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

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2

if dis1 > 0:
    dis1 = -dis1
    dis2 = -dis2

"""
if dis1 + dis2 <0:
    print(0)

elif dis1 == -dis2:
    print("infinity")
"""

if dis1 + dis2 == 0:
    print("infinity")

elif dis1+dis2 < 0:
    print(0)

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(ans))

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

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2

if dis1 > 0:
    dis1 = -dis1
    dis2 = -dis2

if dis1 + dis2 <0:
    print(0)

elif dis1 == -dis2:
    print("infinity")
    
else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(ans))

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*T1 + C2*T2 == 0:
        return 'infinity'

    if C1*T1 + C2*T2 < 0:
        C1, C2 = -C1, -C2

    if abs(C1*T1) > abs(C2*T2):
        return 0

    x1, x2 = T1, 2*T1+T2
    y1, y2 = C1*T1, 2*C1*T1+C2*T2

    x = -y1 * (x2-x1) // (y2-y1) + x1

    z = x-T1
    T = T1+T2
    num = z//T
    ans = num*2
    dist = C1*T1 + (C1*T1 + C2*T2)*num
    if dist != 0:
        ans += 1

    return int(ans)


print(solve())

Solution (Python):
def solve():
    maxCycle = 10**20

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

    C1, C2 = B1-A1, B2-A2
    if C1 > 0:
        C1, C2 = -C1, -C2

    dist = C1*T1 + C2*T2

    def binarySearch(isOK):
        ng, ok = -1, maxCycle
        while abs(ok-ng) > 1:
            mid = (ng+ok) // 2
            if isOK(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def isOK1(c):
        return dist*(c+1) >= 0
    cycle1 = binarySearch(isOK1)
    if cycle1 == maxCycle:
        return 0

    def isOK2(c):
        return dist*c > 0
    cycle2 = binarySearch(isOK2)
    if cycle2 == maxCycle:
        return 'infinity'

    def isOK3(c):
        return dist*c + C1*T1 >= 0
    cycle3 = binarySearch(isOK3)

    def isOK4(c):
        return dist*c + C1*T1 > 0
    cycle4 = binarySearch(isOK4)

    ans = 1*(cycle2-cycle1) + 2*(cycle3-cycle2) + 1*(cycle4-cycle3)
    return ans


print(solve())

Solution (Python):
import sys
read = sys.stdin.read

T1, T2, A1, A2, B1, B2 = map(int, read().split())
answer = 0
v1 = A1 - B1
v2 = A2 - B2
d = v1 * T1 + v2 * T2

if d == 0:
    print('infinity')
    exit()
elif v1 * d > 0:
    print(0)
    exit()

if v1 * T1 % -d == 0:
    print(v1 * T1 // -d * 2)
else:
    print(v1 * T1 // -d * 2 + 1)

Solution (Python):

from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2

if a1 + a2 == b1 + b2:
    print("infinity")
    exit()
if a1 + a2 > b1 + b2:
    a1, a2, b1, b2 = b1, b2, a1, a2

diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
    print(0)
else:
    ans = (abs(mid_diff) + diff - 1) // diff * 2
    if abs(mid_diff) % diff == 0:
        ans += 1
    print(ans - 1)

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

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, A1, A2, B1, B2 = map(int, open(0).read().split())

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

if P > 0:
    P, Q = -P, -Q

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

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

    x = (a1-b1)*t1
    y = (a2-b2)*t2
    diff = x+y

    if x == -y:
        print("infinity")
        return
    elif x*y>0 or abs(x)>abs(y):
        print(0)
        return

    x = abs(x)
    diff = abs(diff)
    ans = x//diff
    remainder = x%diff
    if remainder==0:
        print(ans*2)
    else:
        print(ans*2+1)

    

if __name__ == '__main__':
    main()

Solution (Python):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
x = (a1 - b1) * t1
y = (a2 - b2) * t2
p, q = x // abs(x), y // abs(y)

if x + y == 0:
    print('infinity')
else:
    l, r = 0, 10 ** 40 + 1
    ans = 0
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if (t - y < 0) ^ (t <= 0):
            l = m
        else:
            r = m
    ans += l
    l, r = 0, 10 ** 40 + 1
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if (t + x <= 0) ^ (t < 0):
            l = m
        else:
            r = m
    ans += l
    print(ans)

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

a1 = t1*a1
a2 = t2*a2
b1 = t1*b1
b2 = t2*b2

if (a1 + a2) == (b1 + b2):
    print('infinity')
    exit(0)

elif (a1 + a2) > (b1 + b2):
    a1, b1 = b1, a1
    a2, b2 = b2, a2
if b1 > a1:
    print(0)
    exit(0)

tmp00 = a1 - b1
tmp01 = b1 + b2 - a1 - a2

ans = tmp00 // tmp01 * 2 + 1
if tmp00 % tmp01 == 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())
 
def ispos(x):
    return x==abs(x)

first = (a1-b1)*t1
second = (a2-b2)*t2
net = first+second
if net == 0:
    print("infinity")
elif ispos(first) == ispos(net):
    print(0)
else:
    res = 1
    first = -abs(first)
    second = abs(second)
    net = first+second
    res += 2*int(abs(first)/net)
    if first%net == 0:
        res -= 1
    print(res)

Solution (Python):
import sys


		
def main():
	t1, t2 = map(int, input().split())
	a1, a2 = map(int, input().split())
	b1, b2 = map(int, input().split())
	
	a_d = t1*a1 + t2 * a2
	b_d = t1*b1 + t2 * b2
	
	if a_d == b_d:
		return 'infinity'
	
	pp=a_d-b_d
	pc=t1*(a1-b1)
	if pp*pc > 0:
		return 0
	
	

		
	return (2 * (-pc // pp) + 1) -(1 if pc % pp == 0 else 0)
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid,2):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid,n):
        dif=(d_0+d_1)*(mid-1)
        c=0
        if dif*(dif+d_0) == 0:
            c+=1
        elif dif*(dif+d_0) < 0:
            c+=1
            if (dif+d_0)*(dif+d_0+d_1) < 0:
                c+=1
        if c==n:
            return True
        else:
            return False
    
    T=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    d_0=T[0]*(A[0]-B[0])
    d_1=T[1]*(A[1]-B[1])
    if d_0==-d_1:
        print('infinity')
    elif d_0*(d_0+d_1)<0:
        if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
            n=nibutan(2,10**40)
            ans=n*2-1
            ans+=solve(n+1,1)
            print(ans)
        else:
            print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

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

x = t[0] * (a[0] - b[0])
y = x + t[1] * (a[1] - b[1])
if x*y > 0:
	print(0)
elif x*y == 0:
	print('infinity')
elif abs(x) % abs(y) == 0:
	print(2 * (abs(x) // abs(y)))
else:
	print(2 * (abs(x) // abs(y)) + 1)

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

a1 *= t1
a2 *= t2
b1 *= t1
b2 *= t2

if a1 > b1:
    l1 = a1
    l2 = a2
    s1 = b1
    s2 = b2
else:
    l1 = b1
    l2 = b2
    s1 = a1
    s2 = a2


if l1 + l2 == s1 + s2:
    print('infinity')
elif l1 + l2 < s1 + s2:
    lim = l1 - s1
    if lim % (s1+s2-l1-l2):
        print(1 + 2 * (lim // (s1+s2-l1-l2)))
    else:
        print(2 * (lim // (s1+s2-l1-l2)))
else:
    print(0)

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):
import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

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

if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:
    print('infinity')
    exit()
if (A1 > B1 and A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2) or \
        (A1 < B1 and A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2):
    print(0)
    exit()
diff = abs(A1-B1) * T1
diff2 = abs(T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2))
x, y = divmod(diff, diff2)
print(x * 2 if y == 0 else x * 2 + 1)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(T1, T2, A1, A2, B1, B2):
    la1 = T1*A1
    la2 = T2*A2
    lb1 = T1*B1
    lb2 = T2*B2

    la = la1 + la2
    lb = lb1 + lb2
    if la == lb:
        return 'infinity'

    if la1 > lb1 and la2 > lb2:
        return 0
    if la1 < lb1 and la2 < lb2:
        return 0

    if la > lb and la1 > lb1:
        return 0

    if la < lb and la1 < lb1:
        return 0


    p = la1 - lb1
    q = la2 - lb2
    if p > q:
        p *= -1
        q *= -1
    ans = -p//(q+p)*2
    if -p % (q+p) != 0:
        ans += 1
    return ans

def main():
    T1, T2 = read_int_n()
    A1, A2 = read_int_n()
    B1, B2 = read_int_n()
    print(slv(T1, T2, A1, A2, B1, B2))


if __name__ == '__main__':
    main()

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

a1 = A1*T1
a2 = A2*T2
b1 = B1*T1
b2 = B2*T2

if a1+a2 < b1+b2:
  a1,b1 = b1,a1
  a2,b2 = b2,a2


if a1+a2 == b1+b2:
  print('infinity')
else:
  if a1 > b1:
    print(0)
  else:
    c = (b1-a1)/((a1+a2)-(b1+b2))
    print(int(c)*2 if c.is_integer() else int(c)*2+1)

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


def main():
    T1, T2 = [int(x) for x in input().split()]
    A1, A2 = [int(x) for x in input().split()]
    B1, B2 = [int(x) for x in input().split()]

    if (T1 * A1 + T2 * A2) == (T1 * B1 + T2 * B2):
        print("infinity")
        return


    x = (T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2)
    y = (T1 * A1) - (T1 * B1)
    if (y > 0 and x > 0) or (y < 0 and x < 0):
        print("0")
        return
    x = abs(x)
    y = abs(y)
    count = (y // x) * 2
    if y % x != 0:
        count += 1
    print(count)






if __name__ == '__main__':
    main()

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):
*T, = map(int,input().split())
*A, = map(int,input().split())
*B, = map(int,input().split())

if A[0]*T[0]+A[1]*T[1] == B[0]*T[0]+B[1]*T[1]:
    print("infinity")
else:
    if A[0]<B[0] : A,B = B,A
    if A[0]*T[0]+A[1]*T[1] > B[0]*T[0]+B[1]*T[1] :
        print(0)
    else:
        L = (A[0]-B[0]) * T[0]
        d = -((A[0]-B[0]) * T[0] + (A[1]-B[1]) * T[1])
        ans = L//d*2 + (L%d>0)
        print(ans)

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=abs(c1*t1),-abs(c2*t2)

if (c1>0 and c2>0) or (c1<0 and c2<0) or d1+d2>0:
    print(0)
elif d1+d2==0:
    print("infinity")
else:
    x=d1//(-(d1+d2))
    y=d1%(-(d1+d2))
    if y==0:
        print(2*x)
    else:
        print(2*x+1)

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

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    M = (B1 - A1) * T1
    d = SA - SB
    cnt = M // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(max(0, ans))
elif SB > SA and B1 < A1:
    M = (A1 - B1) * T1
    d = SB - SA
    cnt = M // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(max(0, ans))
else:
    print(0)

Solution (Python):
s,t,a,b,x,y=map(int,open(0).read().split())
i=(x-a)*s
j=(b-y)*t-i
print(max(0,i//j*2+(i%j!=0))if j else'infinity')

Solution (Python):
T = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
B = [int(t) for t in input().split()]

d1 = T[0]*(A[0]-B[0])
d2 = d1 + T[1]*(A[1]-B[1])

if d2 == 0:
    ans = "infinity"
elif d1 > 0 and d2 > 0:
    ans = 0
elif d1 < 0 and d2 < 0:
    ans = 0
else:
    d1 = abs(d1)
    d2 = abs(d2)
    ans = d1 // d2 * 2
    if d1%d2 != 0:
        ans += 1 
    
    
print(ans)

Solution (Python):
import sys
from math import ceil
def main():
    T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())
    
    
    BA1 = A1 - B1
    BA2 = A2 - B2

    if BA1 == 0:
        print(0)
        sys.exit()

    
    if BA1 < 0:
        BA1 = -BA1
        BA2 = -BA2
    
    d = BA1 * T1 + BA2 * T2
    if d > 0:
        print(0)
        sys.exit()
    if d == 0:
        print('infinity')
        sys.exit()
    
    
    
    
    n = ceil((- BA1 * T1) / d)
    if n * d == - BA1 * T1:
        ans = 2 * n
    else:
        ans = 2 * n - 1
    
    print(ans)
    
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:
    B1, A1 = A1, B1
    B2, A2 = A2, B2
P = T1*(A1-B1)  
Q = T2*(A2-B2)
if P + Q == 0:
    print("infinity")
    exit()
elif P + Q < 0:  
    print(0)
    exit()
elif P + Q > 0:  
    if (-P % (P + Q)) == 0:
        print(2*(-P // (P+Q)))
    else:
        print(2*(-P // (P+Q))+1)

Solution (Python):
import sys
from math import ceil

def main():
    T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())

    BA1 = A1 - B1
    BA2 = A2 - B2

    if BA1 == 0:
        print(0)
        sys.exit()
    
    if BA1 < 0:
        BA1 = -BA1
        BA2 = -BA2
    
    d = BA1 * T1 + BA2 * T2

    if d > 0:
        print(0)
        sys.exit()
    if d == 0:
        print('infinity')
        sys.exit()

    
    n = ceil((- BA1 * T1) / d) 
    if n * d + BA1 * T1 == 0:
        ans = n * 2
    else:
        ans = n * 2 - 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
Ad = A1 * T1 + A2 * T2
Bd = B1 * T1 + B2 * T2
if Ad == Bd:
    print('infinity')
else:
    if Bd > Ad:
        Ad, Bd = Bd, Ad
        A1, B1 = B1, A1
    if A1 > B1:
        print(0)
    else:
        num = (B1 - A1) * T1 // (Ad - Bd)
        if (B1 - A1) * T1 % (Ad - Bd) == 0:
            print(num * 2)
        else:
            print(num * 2 + 1)

Solution (Python):
import sys
from math import ceil
def main():
    T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())
    
    
    BA1 = A1 - B1
    BA2 = A2 - B2

    if BA1 == 0:
        print(0)
        sys.exit()

    
    if BA1 < 0:
        BA1 = -BA1
        BA2 = -BA2
    
    d = BA1 * T1 + BA2 * T2
    if d > 0:
        print(0)
        sys.exit()
    if d == 0:
        print('infinity')
        sys.exit()
    
    n = ceil((- BA1 * T1) / d)
    if n * d == - BA1 * T1:
        ans = 2 * n
    else:
        ans = 2 * n - 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import ceil
def main():
    T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())
    
    BA1 = A1 - B1
    BA2 = A2 - B2

    if BA1 == 0:
        print(0)
        sys.exit()

    
    if BA1 < 0:
        BA1 = -BA1
        BA2 = -BA2
    
    d = BA1 * T1 + BA2 * T2
    if d > 0:
        print(0)
        sys.exit()
    if d == 0:
        print('infinity')
        sys.exit()
    
    n = ceil((- BA1 * T1) / d)
    if n * d == - BA1 * T1:
        ans = 2 * n
    else:
        ans = 2 * n - 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

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:
    
    i = P * (-1)
    if i % (P + Q) == 0:
        print(2 * (i // (P + Q)))
    else:
        print(2 * (i // (P + Q)) + 1)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline


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

    P = t1 * (b1 - a1)
    Q = t2 * (b2 - a2)
    if P + Q == 0:
        print("infinity")
        return
    if P * (P + Q) > 0:
        print(0)
        return
    P = abs(P)
    Q = abs(Q)
    T = P % (Q - P)
    S = P // (Q - P)
    if T == 0:
        ans = 2 * S
    else:
        ans = 2 * S + 1
    print(ans)


main()

Solution (Python):
import sys
import math
t1, t2 = [int(i) for i in sys.stdin.readline().split()]
a1, a2 = [int(i) for i in sys.stdin.readline().split()]
b1, b2 = [int(i) for i in sys.stdin.readline().split()]
a1 -= b1
a2 -= b2
_sum = a1 * t1 + a2 * t2
if _sum == 0:
    print("infinity")
elif _sum * a1 > 0:
    print("0")
else:
    cnt = (-a1 * t1) / _sum
    res = math.ceil(cnt) * 2 - 1 + (cnt % 1 == 0)
    print(res)

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 * p
    q = -1 * q

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(2*s)
    else:
        print(2*s+1)