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 Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = inpl()
b = inpl()
if (a[0] > b[0] and a[1] > b[1]) or (a[0] < b[0] and a[1] < b[1]):
    print(0)
    quit()
c = [0,0]
for i in range(2):
    c[i] = abs(a[i]-b[i]) * t[i]
if c[0] == c[1]:
    print('infinity')
    quit()
if c[0] > c[1]:
    print(0)
else:
    sa = c[1]-c[0]
    tmp = 0
    if c[1]%sa:
        tmp = 1
    print((c[1]-1)//(c[1]-c[0])*2 - tmp)

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
A1 *= T1
A2 *= T2
B1 *= T1
B2 *= T2
if A1 > B1:
    A1, B1 = B1, A1
    A2, B2 = B2, A2
C = B1 - A1
D = A2 - B2

if C == D:
    print("infinity")
elif C > D:
    print(0)
else:
    q, r = divmod(C, (D - C))
    if r == 0:
        print(2 * q)
    else:
        print(2 * q + 1)

Solution (Python):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
A1 *= T1
A2 *= T2
B1 *= T1
B2 *= T2
if A1 > B1:
    A1, B1 = B1, A1
    A2, B2 = B2, A2
C = B1 - A1
D = A2 - B2

if A1 + A2 == B1 + B2:
    print("infinity")
    exit()
elif C > D:
    print(0)
    exit()

q, r = divmod(C, (D - C))
if r == 0:
    print(2 * q)
else:
    print(2 * q + 1)

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

c = 0
c += a1*t1-b1*t1
c += a2*t2-b2*t2


if c == 0:
    print('infinity')
    exit()

if c > 0:
    if b1*t1-a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(b1*t1-a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
else:
    c *= (-1)
    if -b1*t1+a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(-b1*t1+a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
print(ans)

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

c = 0
c += a1*t1-b1*t1
c += a2*t2-b2*t2


if c == 0:
    print('infinity')
    exit()

if c > 0:
    if b1*t1-a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(b1*t1-a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
else:
    c *= (-1)
    if -b1*t1+a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(-b1*t1+a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353





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




t1_diff = (A1 - B1) * T1
t2_diff = (A1 - B1) * T1 + (A2 - B2) * T2
if t1_diff == 0 or t2_diff == 0: 
    print('infinity')
    exit()
if t1_diff * t2_diff > 0: 
    print(0)
    exit()





if abs(t1_diff) % abs(t2_diff) == 0:
    
    print((abs(t1_diff) // abs(t2_diff)) * 2)
else:
    print((abs(t1_diff) // abs(t2_diff)) * 2 + 1)

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

a, b, ans = 0, 0, 0
n1 = (A1-B1)*T1
n2 = n1 + (A2-B2)*T2
if n2 == 0:
  print('infinity')
elif n1*n2 < 0:
  ans += 2 * (abs(n1)//abs(n2))
  if abs(n1)%abs(n2) > 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 = T1*A1-T1*B1
c2 = T2*A2-T2*B2
if c1 > 0:
    c1 *= -1
    c2 *= -1
power = c1+c2
if power == 0:
    print('infinity')
elif power < 0:
    print(0)
else:
    ans = 2*(-c1//power)+(c1%power > 0)
    print(ans)

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

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

a1-=b1;b2-=a2

b2-=a1
if b2<0:
    print(0)
    exit()

ans=1+(a1//b2)*2
if a1%b2==0:
    ans-=1

print(ans)

Solution (Python):

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


import sys


readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


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


def read_float():
    return float(readline())


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


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


def read_str_n():
    return readline().strip().split()


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(T, A, B):
    P = (A[0] - B[0]) * T[0]
    Q = (A[1] - B[1]) * T[1]

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

    if P+Q == 0:
        return 'infinity'
    elif P+Q < 0:
        return 0

    S = -P // (P + Q)
    T = -P % (P + Q)
    return S * 2 + (1 if T != 0 else 0)


def main():
    T = read_int_n()
    A = read_int_n()
    B = read_int_n()
    print(slv(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*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)>0:print(0)
elif (a1*t1-b1*t1)*(a1*t1+a2*t2-b1*t1-b2*t2)==0:print('infinity')
else:print(-(a1*t1-b1*t1)//(a1*t1+a2*t2-b1*t1-b2*t2)*2+((a1*t1-b1*t1)%(a1*t1+a2*t2-b1*t1-b2*t2)!=0))

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    if D1 == D2:
        print('infinity')
    else:
        if D2 > D1:
            A1, B1 = B1, A1
            A2, B2 = B2, A2
            D1, D2 = D2, D1
        M1 = T1 * A1
        M2 = T1 * B1
        if M1 > M2:
            print(0)
        else:
            cnt = (M2 - M1) // (D1 - D2)
            ans = cnt * 2
            diff = (M2 - M1) % (D1 - D2)
            if diff > 0:
                ans += 1
            print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def meet(diff, T1, T2, A1, A2, B1, B2):
    ans = 0
    pre_diff = diff
    a = T1 * A1
    b = T1 * B1

    diff += a
    diff -= b

    if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
        ans += 1

    pre_diff = diff
    a = T2 * A2
    b = T2 * B2

    diff += a
    diff -= b

    if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
        ans += 1

    return ans


def solve():
    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")
        return

    
    if (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
        print(0)
        return

    one_diff = (T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2)

    ans = 0
    diff = 0
    for i in range(100):
        num = meet(diff, T1, T2, A1, A2, B1, B2)
        if num == 0:
            break
        ans += num
        diff += one_diff

    left = -1
    right = 10**20
    while right - left > 1:
        m = (right + left) // 2
        tmp = diff + m * one_diff
        if meet(tmp, T1, T2, A1, A2, B1, B2):
            left = m
        else:
            right = m

    x = max(0, left - 10)
    ans += meet(diff, T1, T2, A1, A2, B1, B2) * x
    diff += one_diff * x

    for i in range(100):
        num = meet(diff, T1, T2, A1, A2, B1, B2)
        if num == 0:
            break
        ans += num
        diff += one_diff

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

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


def solve(T1, T2, A1, A2, B1, B2):
    if (Da := T1 * A1 + T2 * A2) == (Db := T1 * B1 + T2 * B2) or A1 == B1:
        return 'infinity'

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

    if A1 > B1:
        return 0
    else:
        D1 = (B1 - A1) * T1
        if D1 % (Da - Db):
            return D1 // (Da - Db) * 2 + 1
        else:
            return D1 // (Da - Db) * 2


print(solve(T1, T2, A1, A2, B1, B2))

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

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

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

    da1 = T1 * A1
    da2 = T2 * A2
    db1 = T1 * B1
    db2 = T2 * B2

    if da1 == db1:
        if db1 == db2:
            ans = "infinity"
        else:
            ans = 1
    else:
        if da1 + da2 == db1 + db2:
            ans = "infinity"
        elif da1 + da2 < db1 + db2:
            ans = 0
        else:
            d1 = db1 - da1
            d2 = (da1 + da2) - (db1 + db2)
            ans = 1 + (d1 // d2) * 2
            if d1 % d2 == 0:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    T1, T2 = list(map(int, input().split()))
    A1, A2 = list(map(int, input().split()))
    B1, B2 = list(map(int, input().split()))
    
    V1, V2 = A1 - B1, A2 - B2
    if V1 == 0 or V2 == 0 or V1 * V2 > 0:
        print(0)
        return
    
    d1, d2 = V1 * T1, V2 * T2
    d12 = d1 + d2
    if d1 * d12 > 0:
        print(0)
    elif d12 == 0:  
        print('infinity')
    else:  
        cnt = 0
        
        cnt += abs(d1) // abs(d12)
        
        cnt += 1 + (abs(d1) - 1) // abs(d12)
        print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

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

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

if A1*T1 + A2*T2 > B1*T1 + B2*T2:
    A1,B1 = B1,A1
    A2,B2 = B2,A2

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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

    if a2 > b2:
        return print(0)
    else:
        d1 = t1 * a1 + t2 * a2
        d2 = t1 * b1 + t2 * b2
        if d1 == d2:
            return print("infinity")
        elif d2 > d1:
            ans = 1
            diff = d2 - d1
            x = t1 * (a1 - b1)
            cnt = x // diff
            ans += cnt * 2
            if x % diff == 0:
                ans -= 1
            return print(ans)
        else:
            return print(0)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()

a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2

if a == b:
    print('infinity')
else:
    if b > a:
        if a1 * t1 < b1 * t1:
            print(0)
        elif a1 * t1 == b1 * t1:
            print(1)
        elif a1 * t1 > b1 * t1:
            c = b - a
            d = a1 * t1 - b1 * t1
            e = d % c != 0
            print(2 * (d // c) + e)
    else:
        if b1 * t1 < a1 * t1:
            print(0)
        elif b1 * t1 == a1 * t1:
            print(1)
        elif b1 * t1 > a1 * t1:
            c = a - b
            d = b1 * t1 - a1 * t1
            e = d % c != 0
            print(2 * (d // c) + e)

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

ave_a = t1 * a1 + t2 * a2
ave_b = t1 * b1 + t2 * b2
if ave_a == ave_b:
    print('infinity')
    exit()

half, all = t1 * (b1 - a1), ave_a - ave_b
ans = half // all * 2 + (half % all != 0)
print(max(0, ans))

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

ave_a = t1 * a1 + t2 * a2
ave_b = t1 * b1 + t2 * b2
if ave_a < ave_b:
    (a1, a2), (b1, b2) = (b1, b2), (a1, a2)
    ave_a, ave_b = ave_b, ave_a

if ave_a == ave_b:
    print('infinity')
    exit()

half, all = t1 * (b1 - a1), ave_a - ave_b
ans = half // all * 2 + (half % all != 0)
print(max(0, ans))

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

ave_a, ave_b = t1 * a1 + t2 * a2, t1 * b1 + t2 * b2
if ave_a < ave_b:
    a1, a2, b1, b2 = b1, b2, a1, a2
    ave_a, ave_b = ave_b, ave_a

if ave_a == ave_b:
    print('infinity')
    exit()

first, second = t1 * (b1 - a1), ave_a - ave_b
ans = first // second * 2 + (first % second != 0)
print(max(0, ans))

Solution (Python):
def main(v1, v2, t1, t2):
    if v1 * v2 >= 0:  
        return 0
    
    d1 = abs(v1) * t1
    d2 = abs(v2) * t2

    if d1 > d2:  
        return 0
    if d1 == d2:  
        return "infinity"

    dL = d2 - d1
    peak = (d1 + dL - 1) // dL
    if d1 % dL == 0:
        return peak * 2
    else:
        return peak * 2 - 1


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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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

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

if P+Q == 0:
	print("infinity")
	exit()
elif 0 <= P*(P+Q):
	print(0)
	exit()
else:
	a = abs(P)
	b = abs(P - (2*P+Q))
	n = a//b
	if a%b:
		print(2*n+1)
	else:
		print(2*n)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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

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

elif 0 < ((A1-B1)*T1) * ((A1-B1)*T1 + (A2-B2)*T2):
	print(0)

else:
	p = A1*T1-B1*T1
	q = 2*A1*T1+A2*T2-2*B1*T1-B2*T2
	if p*q < 0:
		print(1)
	elif p%(p-q):
		print(2*(p//(p-q))+ 1)
	else:
		print(2*(p//(p-q)))

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:
    print("infinity")
    quit()
x = (a1-b1)*t1
y = (a2-b2)*t2
if x < 0:
    x,y = -x,-y
d = x+y
if d > 0:
    print(0)
    quit()
if x%(-d) == 0:
    print(2*(x//(-d)))
else:
    print(2*(x//(-d))+1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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__':
    resolve()

Solution (Python):
def sumitb2019_f():
    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:
        ans = 0
    elif p + q == 0:
        ans = 'infinity'
    else:
        s, t = divmod(-p, p + q)
        if t == 0: ans = s * 2
        else: ans = s * 2 + 1
    print(ans)

if __name__ == '__main__':
    sumitb2019_f()

Solution (Python):
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)
elif b1>a1 and b2>a2:
    print(0)
elif a1*t1+a2*t2==b1*t1+b2*t2:
    print("infinity")
else:
    ans=-1
    num2=-1
    num3=-1
    if a1*t1+a2*t2>b1*t1+b2*t2:
        if a1>b1:
            ans=0
        else:
            num2=(b1-a1)*t1
            num3=((a1-b1)*t1)+((a2-b2)*t2)
            if num2//num3==num2/num3:
                ans=(num2//num3)*2
            else:
                ans=(num2//num3)*2+1
    else:
        if b1>a1:
            ans=0
        else:
            num2=(a1-b1)*t1
            num3=((b1-a1)*t1)+((b2-a2)*t2)
            if num2//num3==num2/num3:
                ans=(num2//num3)*2
            else:
                ans=(num2//num3)*2+1
    print(ans)

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

a=a1-b1
b=a2-b2

if a<=0:
    a *= -1
    b *= -1

X=t1*a
Y=t2*b


if X+Y==0:
    print('infinity')
elif X+Y>0:
    print(0)
else:
    T=X//abs(X+Y)
    if X%abs(X+Y)==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())

if a1 > b1 and a2 > b2:
    print(0)
    exit()

if b1 > a1 and b2 > a2:
    print(0)
    exit()

if a1 < b1 and a2 > b2:
    a1,b1 = b1,a1
    a2,b2 = b2,a2 


diff1 = abs(a1-b1)
diff2 = abs(a2-b2)

first_dist = diff1*t1
second_dist = diff2*t2

down = second_dist - first_dist
if down < 0:
    print(0)
    exit()
if down == 0:
    print('infinity')
    exit()

if first_dist%down != 0:
    ans = (first_dist//down) * 2 + 1
else:
    ans = ((first_dist//down)-1) * 2 + 2

print(ans)

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

a = (a1-b1)*t1
b = (a2-b2)*t2
if a < 0:
    a *= -1
    b *= -1

if a == -b:
    print("infinity")
    exit()
if a+b > 0:
    print(0)
else:
    c = -a-b
    print((a+c-1)//c + a//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:
    print("infinity")
    exit()
if (a1 < b1 and a1+a2 < b1+b2) or (b1 < a1 and b1+b2 < a1+a2):
    print(0)
    exit()

d2 = abs(a1+a2-b1-b2)
d1 = abs(a1-b1)
print(1 + 2*(d1//d2) - (d1 % d2 == 0))

Solution (Python):

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

d1 = t1 * (a1 - b1)
d2 = t2 * (a2 - b2)

if d1 > 0:
    d1 *= -1
    d2 *= -1

if d1 + d2 == 0:
    print("infinity")
elif d1 + d2 < 0:
    print(0)
else:
    cnt = -d1 // (d1 + d2)
    t = -d1 % (d1 + d2)
    ans = 2 * cnt + int(t != 0)
    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
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2
a = a1 + a2
b = b1 + b2
if a == b:
    print("infinity")
elif a > b:
    print(0)
else:
    d1 = a1 - b1
    d2 = b2 - a2
    if d1 % (d2 - d1) == 0:
        ans = d1 // (d2 - d1) * 2
    else:
        ans = d1 // (d2 - d1) * 2 + 1
    print(ans)

Solution (Python):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
atot1 = (a1 - b1) * t1
atot2 = (a2 - b2) * t2
if atot1 > 0:
    atot1 *= -1
    atot2 *= -1


if atot1 + atot2 < 0:
    print(0)
    exit()
if atot1 == - atot2:
    print('infinity')
    exit()
S = (-atot1) // (atot1 + atot2)
T = (-atot1) % (atot1 + atot2)
if T != 0:
    print(2 * S + 1)
else:
    print(2 * S)

Solution (Python):
import sys

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")
  sys.exit()

e1 = (a1-b1)*t1
e2 = e1 + (a2-b2)*t2

if e1*e2 > 0:
  print(0)
  sys.exit()

e1, e2 = abs(e1), abs(e2)

if e1%e2:
  print(1+2*(e1//e2))
else:
  print(2*(e1//e2))

Solution (Python):
s,t = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a = a1-b1
b = a2-b2
if a*b>0:print(0);exit()
if abs(a)*s ==abs(b)*t:print('infinity');exit()
elif abs(a)*s >abs(b)*t:print(0);exit()
if (abs(a)*s)%(abs(b)*t-abs(a)*s):
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2+1)
else:
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2)

Solution (Python):
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
p=a1-b1
q=a2-b2
if p*t1+q*t2==0:print('infinity');exit()
elif p<0:p,q=-p,-q

if p*t1+q*t2>0:print(0)
else:
    a=p*t1
    d=-(a+q*t2)
    print(2*(a//d)+int(not(not a%d)))

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

if A2>=B2:
    print(0)
else:
    sta=T1*(A1-B1)
    gen=T2*(A2-B2)
    if sta==-gen:
        print("infinity")
    elif sta+gen>0:
        print(0)        
    else:
        ans=sta//abs(sta+gen)*2+1
        if sta%abs(sta+gen)==0:
            ans-=1
        print(ans)

Solution (Python):
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


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

    len1 = T1 * A1 + T2 * A2
    len2 = T1 * B1 + T2 * B2
    first1 = T1 * A1
    first2 = T1 * B1
    second1 = T2 * A2
    second2 = T2 * B2

    if len1 == len2:
        print("infinity")
        exit()

    if len1 > len2:
        if first1 < first2:
            a, b = divmod(first2 - first1, len1 - len2)
            if b == 0:
                print(a * 2)
                exit()
            else:
                print(a * 2+1)
                exit()
        else:
            print(0)
            exit()

    if len2 > len1:
        if first2 < first1:
            a, b = divmod(first1 - first2, len2 - len1)
            if b == 0:
                print(a * 2 )
                exit()
            else:
                print(a * 2+1)
                exit()
        else:
            print(0)
            exit()



if __name__ == "__main__":
    main()

Solution (Python):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 - b1
b = a2 - b2
if a < 0:
    a = -a
    b = -b
p = t1 * a + t2 * b
if p > 0:
    print(0)
    exit()
if p == 0:
    print('infinity')
    exit()
top = a * t1
p = -p
ans = (top // p + 1) * 2 - 1 - (top % p == 0)
print(ans)

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

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

if T > A:
  if A1 > B1:
    print(0)
    exit()
  else:
    tdif = T-A 
    pdif = T1*(B1-A1) 
    if pdif%tdif == 0:
      ans = 2*(pdif//tdif)+1
    else:
      ans = 2*(1+pdif//tdif)
    ans -=1 
else:
  if B1 > A1:
    print(0)
    exit()
  else:
    tdif = A-T 
    pdif = T1*(A1-B1) 
    if pdif%tdif == 0:
      ans = 2*(pdif//tdif)+1
    else:
      ans = 2*(1+pdif//tdif)
    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 T1*A1+T2*A2==T1*B1+T2*B2:
    cnt="infinity"
elif T1*A1+T2*A2>T1*B1+T2*B2:
    L = T1*(B1-A1)
    d = T1*A1+T2*A2-(T1*B1+T2*B2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
elif T1*A1+T2*A2<T1*B1+T2*B2:
    L = T1*(A1-B1)
    d = (T1*B1+T2*B2)-(T1*A1+T2*A2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
print(cnt)

Solution (Python):
import math
t1,t2 = map(int,(input().split(' ')))
a1,a2 = map(int,(input().split(' ')))
b1,b2 = map(int,(input().split(' ')))
n = t1*a1+t2*a2
m = t1*b1+t2*b2
if(n==m):
    print("infinity")
    exit(0)
ans1 = max(0,math.ceil((b1-a1)*t1/(n-m)))
ans2 = max(0,math.ceil((t1*(b1-a1)+t2*(b2-a2))/(n-m))-1)




ans3 = max(0,math.floor(t1*(b1-a1)/(n-m))+1)
print(max(ans1+ans2+ans3-1,0))

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
D1 = B1-A1
D2 = B2-A2

if D1*T1 + D2*T2 > 0:
    print(0)
    exit()
if D1*T1 + D2*T2 == 0:
    print('infinity')
    exit()

p = D1*T1
q = -D2*T2
d = q-p
k = p//d
b = int(q*k == p*(k+1))
print(1 + k*2 - b)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

if not (A1-B1)*(A2-B2)<0:
    print(0)
else:
    if A1<B1:
        A1, B1 = B1, A1
        A2, B2 = B2, A2
    if A1*T1+A2*T2==B1*T1+B2*T2:
        print('infinity')
        exit(0)
    rest = (A1-B1)*T1
    come = (B2-A2)*T2
    if come<rest:
        print(0)
    else:
        ans = come//(come-rest)
        last = 1 if come%(come-rest)==0 else 0
        print(ans*2-1-last)