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.



Sample input:
1 2
10 10
12 4


Sample output:
1

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if (d1<=0 and d2>=0) or (d1>=0 and d2<=0):
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if d1*d2<0:
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if (d1<0 and d2>0) or (d1>0 and d2<0):
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if d1==0:
        return True
    elif d2==0:
        return True
    elif (d1<0 and d2>0) or (d1>0 and d2<0):
        return True
    else:
        return False

if A1==B1 and A2==B2:
    print(1)
elif A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if d1==0:
        return True
    elif d2==0:
        return True
    elif (d1<0 and d2>0) or (d1>0 and d2<0):
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if d1==0:
        return True
    elif d2==0:
        return True
    elif (d1<0 and d2>0) or (d1>0 and d2<0):
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**12

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
elif A1==B1:
    print(1)
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    else:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))

Submission status: Wrong Answer

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

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

if d1==d2 or A1==B1:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    else:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    else:
        print(1+2*(abs(v1-v2)//abs(d1-d2)) if abs(v1-v2)%abs(d1-d2) else 2+2*(abs(v1-v2)//abs(d1-d2)))

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    elif v1-v2<0:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))
    else:
        print(1+2*(abs(d1-d2)//abs(v1-v2)))

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    elif v1-v2<0:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))
    else:
        print(2*(abs(d1-d2)//abs(v1-v2)))

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    elif v1-v2<0:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))
    else:
        print(2*(abs(v1-v2)//abs(d1-d2)))

Submission status: Wrong Answer

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

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

if d1==d2:
    print("infinity")
else:
    v1 = A1*T1
    v2 = B1*T1
    if (v1-v2<0 and d1-d2<0) or (v1-v2>0 and d1-d2>0):
        print(0)
    else:
        print(1+2*(abs(v1-v2)//abs(d1-d2)))

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
c = t1*abs(a1-b1)
d = abs(t1*(a1-b1)+t2*(a2-b2))
if a1==b1 and a2==b2:
  print(0)
elif d == 0:
  print("infinity")
elif (a1-b1)*(a2-b2) >= 0:
  print(0)
else:
  if c%d==0:
    print((c//d)*2)
  else:
    print((c//d)*2+1)

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
c = t1*abs(a1-b1)
d = abs(t1*(a1-b1)+t2*(a2-b2))
if  d == 0:
  print("infinity")
elif (a1-b1)*(a2-b2) >= 0:
  print(0)
else:
  if c%d==0:
    print((c//d)*2)
  else:
    print((c//d)*2+1)

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
c = t1*abs(a1-b1)
d = abs(t1*(a1-b1)+t2*(a2-b2))
if  d == 0:
  print("infinity")
elif (a1-b1)*(a2-b2) > 0:
  print(0)
else:
  if c%d==0:
    print((c//d)*2)
  else:
    print((c//d)*2+1)

Submission status: Wrong Answer

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

cycle = t[0] * (a[0] - b[0]) + t[1] * (a[1] - b[1])

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

after_t1 = t[0] * (a[0] - b[0])

if(cycle * after_t1 > 0):
    print(0)
    exit()

ans = -1 + -2 * (after_t1//cycle)  - (after_t1 % cycle == 0) * 1

print(ans)

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if (a1>b1 and a2>b2) or (b1>a1 and b2>a2):
  print(0)
#(a1>b1,a2>b2),(a1>b1,a2<b2),(a1<b1,a2>b2),(a1<b1,a2<b2)の内最初と最後が消えた
#以下(a1>b1,a2<b2),(a1<b1,a2>b2)の場合を区別せずに考える
elif abs(a1-b1)*t1>abs(a2-b2)*t2:
  print(0)
#最初の差が次の差より大きければ追いつきようがない
elif abs(a1-b1)*t1==abs(a2-b2)*t2:
  print('infinity')
#最初の差と次の差が同じならば無限回出会う
else:
  d1=abs(a1-b1)*t1
  d2=abs(a2-b2)*t2
  l=0
  r=10**18+1
  while r-l!=1:
    mid=(l+r)//2
    if d1*(mid+1)-d2*mid<0:
      r=mid
    else:
      l=mid
  print(2*l+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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:
	dist1 = t1 * a1 - t1 * b1
	dist2 = t2 * a2 - t2 * b2
	if(dist1*dist2>0):
		print(0)
	else:
		tdist = 0
		tmp = 0
		ans = 0
		while(True):
			##T1
			tdist += dist1
			if((tmp * tdist) <= 0):
				ans +=1
			else:
				break
			tmp = tdist
			tdist += dist2
			if((tmp * tdist) <= 0):
				ans += 1
			else:
				break
			tmp = tdist
		print(ans-1)

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print(2*round(((B1-A1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/dif))<1e-20:
            print(2*round(((A1-B1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif -round(((B1-A1)*T1)/dif))<1e-20:
            print(2*k)
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/dif))<1e-20:
            print(2*k)
        else:
            print(2*k+1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif -round(((B1-A1)*T1)/dif))<1e-6:
            print(2*k)
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/dif))<1e-6:
            print(2*k)
        else:
            print(2*k+1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        print(2*k+1)
    else:
        print(0)

Submission status: Wrong Answer

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

import math

if A1>B1 and A2>B2:
    print(0)
elif B1>A1 and B2>A2:
    print(0)
elif T1*(A1-B1)>0 and T1*(A1-B1)-T2*(B2-A2)>0:
    print(0)
elif T1*(B1-A1)>0 and T1*(B1-A1)-T2*(A2-B2)>0:
    print(0)
elif T1*(B1-A1)-T2*(A2-B2)==0:
    print("infinity")
else:
    X=abs(T1*(A1-B1))
    Y=abs(T1*(A1-B1)-T2*(B2-A2))
    print(math.ceil(X/Y)*2-1)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    t1,t2 = LI()
    a1,a2 = LI()
    b1,b2 = LI()

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

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

    if sa == sb:
        return "infinity"

    if sb > sa:
        return 0

    t = t1*b1 - t1*a1
    st = sa - sb
    r = math.ceil(t / st + 1 / inf)

    return r * 2 - 1


print(main())

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
runout = abs(T1 * A1 - T1 * B1)
TotalDiff = abs((T1 * A1 - T1 * B1) + (T2 * A2 - T2 * B2))
isUp = True

if TotalDiff == 0:
    print('infinity')
    sys.exit()
elif runout * TotalDiff > 0:
    print(0)
    sys.exit()
    
cnt = 0
cnt = (runout // TotalDiff) * 2
if runout % TotalDiff != 0:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
runout = abs(T1 * A1 - T1 * B1)
TotalDiff = abs((T1 * A1 - T1 * B1) + (T2 * A2 - T2 * B2))
isUp = True

if TotalDiff == 0:
    print('infinity')
    sys.exit()
cnt = 0
cnt = (runout // TotalDiff) * 2
if runout % TotalDiff != 0 and cnt > 0:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
runout = abs(T1 * A1 - T1 * B1)
TotalDiff = abs((T1 * A1 - T1 * B1) + (T2 * A2 - T2 * B2))
isUp = True

if TotalDiff == 0:
    print('infinity')
    sys.exit()
cnt = 0
cnt = (runout // TotalDiff) * 2
if runout % TotalDiff != 0:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
DifTup = max((T1 * A1) - (T1 * B1), (T2 * A2) - (T2 * B2))
DifTdown = min((T1 * A1) - (T1 * B1), (T2 * A2) - (T2 * B2))
TotalDiff = DifTup + DifTdown
isUp = True

if TotalDiff == 0:
    print('infinity')
    sys.exit()
elif TotalDiff < 0:
    isUp = False
cnt = 0
if isUp:
    cnt = ((DifTdown * -1) // TotalDiff) * 2
    if (DifTdown * -1) % TotalDiff != 0:
        cnt += 1
else:
    cnt = (DifTup // (TotalDiff * -1)) * 2
    if DifTup % (TotalDiff * -1) != 0:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
DifTup = max((T1 * A1) - (T1 * B1), (T2 * A2) - (T2 * B2))
DifTdown = min((T1 * A1) - (T1 * B1), (T2 * A2) - (T2 * B2))
TotalDiff = DifTup + DifTdown
isUp = True

if TotalDiff == 0:
    print('infinity')
    sys.exit()
elif TotalDiff < 0:
    isUp = False
cnt = 0
if isUp:
    cnt = ((DifTdown * -1) // TotalDiff) * 2
    if (DifTdown * -1) % TotalDiff != 0:
        cnt += 1
else:
    cnt = (DifTup // (TotalDiff * -1)) * 2
    if DifTup // (TotalDiff * -1) != 0:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
DifT1 = (T1 * A1) - (T1 * B1)
DifT2 = (T2 * A2) - (T2 * B2)

#  Main
if DifT1 + DifT2 == 0:
    print('infinity')
    sys.exit()

diffab, cnt = 0, 0

while True:
    cnt_ = 0
    diff1 = diffab + DifT1
    if diffab * diff1 < 0:
        cnt_ += 1
    diff2 = diff1 + DifT2
    if diff1 * diff2 < 0:
        cnt_ += 1
    if cnt_ == 0:
        break
    else:
        diffab = diff2
        cnt += cnt_

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
DifT1 = (T1 * A1) - (T1 * B1)
DifT2 = (T2 * A2) - (T2 * B2)


def Func(diff_, cnt_):
    diff1 = diff_ + DifT1
    if diff_ * diff1 <= 0:
        cnt_ += 1
    diff2 = diff1 + DifT2
    if diff1 * diff2 <= 0:
        cnt_ += 1
    return diff2, cnt_


#  Main
if DifT1 + DifT2 == 0:
    print('infinity')
    sys.exit()

diffab, cnt = 0, 0


while abs(diffab) < abs(DifT1) or abs(diffab) < abs(DifT2):
    diffab, cnt = Func(diffab, cnt)
print(cnt - 1)

Submission status: Wrong Answer

Solution code:
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")
    exit()
if a1 < b1:
    tnp = a1
    a1 = b1
    b1 = tnp
    tnp = a2
    a2 = b2
    b2 = tnp
if (a1-b1) * t1 + (a2-b2) * t2 > 0:
    print(0)
    exit()
num = -(a1-b1) * t1 - (a2-b2) * t2
ans = 1

ans += ((a1-b1)*t1 // num)*2
if (a1-b1) % num == 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 + s2 == 0:
    print('infinity')
elif s1*s2 >= 0:
    print(0)
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 + s2 == 0:
    print('infinity')
elif s1*s2 >= 0:
    print(0)
elif s1+s2 < 0:
    print(1)
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)

if s1 + s2 == 0:
    print('infinity')
elif s1*s2 > 0:
    print(0)
else:
    if s1 > 0:
        x,y = divmod(s1,(s1+s2))
        ans = 2*x - (y != 0)
        print(ans)
    else:
        x,y = divmod(s1,(s1+s2))
        ans = 2*abs(x) - (y != 0)
        print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)

if s1 + s2 == 0:
    print('infinity')
elif s1*s2 > 0:
    print(0)
else:
    if s1 > 0:
        x,y = divmod(s1,(s1+s2))
        ans = 2*x - (y != 0)
        print(ans)
    else:
        x,y = divmod(abs(s1),(s1+s2))
        ans = 2*x - (y != 0)
        print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)

if s1 + s2 == 0:
    print('infinity')
elif s1*s2 > 0:
    print(0)
else:
    if s1 > 0:
        x,y = divmod(s1,(s1+s2))
        ans = 2*x - (y != 0)
        print(ans)
    else:
        x,y = divmod(s2,(s1+s2))
        ans = 2*x - (y != 0)
        print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)

if s1 + s2 == 0:
    print('infinity')
elif s1*s2 > 0:
    print(0)
else:
        x,y = divmod(s1,(s1+s2))
        ans = 2*abs(x) - (y != 0)
        print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)

if s1 + s2 == 0:
    print('infinity')
elif s1*s2 > 0:
    print(0)
else:
        x,y = divmod(s1,(s1+s2))
        z,w = divmod(s2,(s1+s2))
        ans = abs(x) + abs(z) - (y != 0 and w != 0)
        print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1*s2 >= 0:
    print(0)
elif s1 == (-1)*s2:
    print('infinity')
else:
    if s1 < 0:
        x = math.ceil(abs(s1)/(s1+s2))
        y = abs(s1) % (s1+s2)
        ans = 2*x - (y != 0)
    else:
        x = math.ceil(abs(s2)/(s1+s2))
        y = abs(s2) % (s1 + s2)
        ans = 2*x - (y != 0)
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 == 0 and s2 == 0:
    print('infinity')
elif s1*s2 >= 0:
    print(0)
elif s1 == (-1)*s2:
    print('infinity')
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    x,y = divmod(abs(s2),(s1+s2))
    ans = ans1+ans2 - (y!=0)
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 > s2:
    print(0)
elif s1 + s2 == 0:
    print('infinity')
else:
    x,y = divmod(abs(-s1),(s1+s2))
    ans = 2*x + (y==0) + 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 + s2 == 0:
    print('infinity')

elif s1*s2 >= 0:
    print(0)

else:
    x,y = divmod(abs(s1),(s1+s2))
    ans = 2*x + (y != 0)    
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 + s2 < 0:
    print(0)
elif s1 + s2 == 0:
    print('infinity')
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1 == 0 and s2 == 0:
    print('infinity')
elif s1*s2 >= 0:
    print(0)
elif s1 == (-1)*s2:
    print('infinity')
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)