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())
if T1*A1 + T2*A2 == T1*B1 + T2*B2:
    print("infinity")
else:
    if T1*A1 + T2*A2 > T1*B1 + T2*B2:
        A1, B1 = B1, A1
        A2, B2 = B2, A2
    if T1*A1 < T1*B1:
        print("0")
    else:
        forward = T1*A1 - T1*B1
        shrink = (T1*B1 + T2*B2) - (T1*A1 + T2*A2)
        #print(str(forward))
        #print(str(shrink))
        if forward % shrink == 0:
            print(str(2*forward//shrink - 1 - 1))
        else:
            print(str((forward//shrink + 1)*2 - 1))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
import math

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

def get(start,step,period):
    if period>0:
        if step>0:
            x1= math.ceil( (-step-start)/period )
            x2= math.floor( -start/period - 1e-5 )
        else:
            x1= math.ceil( -start/period )
            x2= math.floor( (-step-start)/period - 1e-5 )
    elif period<0:
        if step>0:
            x1= math.ceil( -start/period + 1e-5 )
            x2= math.floor( (-step-start)/period )
        else:
            x1= math.ceil( (-step-start)/period + 1e-5 )
            x2= math.floor( -start/period )
            print(x1,x2)
        #
    if x2<0: return 0
    else: return max(0,x2-max(0,x1)+1)

    
def main():
    t1,t2 = _ia()
    a1,a2 = _ia()
    b1,b2 = _ia()
    
    a = t1 * a1 + t2 * a2
    b = t1 * b1 + t2 * b2
    if a==b: return "infinity"

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

    # during t1
    cnt = get(dsum,d1,dsum)
    
    # during t2
    cnt += get(d1,d2,dsum)
    return cnt

#
print(main())

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
T = T1 + T2
x = []
y = []
x.append(0)
y.append(0)
for i in range(1,T+1):
    x.append(A1*T1)
    x.append(A2*T2)
    y.append(B1*T1)
    y.append(B2*T2)
L = len(x)
for i in range(1,L):
    x[i] += x[i-1]
    y[i] += y[i-1]
if x[2]==y[2]:
    print("infinity")
    exit()
if x[L-1]>y[L-1]:
    x,y = y,x
ans = 0
for i in range(1,L):
    if x[i-1]>=y[i-1] and x[i] < y[i]:
        ans += 1
    if x[i-1]<y[i-1] and x[i] >= y[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy

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

v1=b1-a1
v2=b2-a2

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

Submission status: Wrong Answer

Solution code:
import numpy

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

v1=b1-a1
v2=b2-a2

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1



if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()


	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()

else :
    tikuseki = 0
    # Aのほうがトータルでは速い
    if delta0 + delta1 > 0  :
        # Aがリード ー＞ 近づく、、、、
        if delta0 > 0 :
            print(0)
            sys.exit()
        else:
            print(   (-2* delta0) // (delta0 + delta1)    + int(  (- delta0) / (delta0 + delta1) != 0)  )
            sys.exit()

    else:
        print(0)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1



if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()


	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()

else :
    tikuseki = 0
    # Aのほうがトータルでは速い
    if delta0 + delta1 > 0  :
        # Aがリード ー＞ 近づく、、、、

        print(   2*(- delta0) // (delta0 + delta1)    + int(  (-2* delta0) / (delta0 + delta1) != 0)  )
        sys.exit()

    else:
        print(0)
        sys.exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1



if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()


	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()

else :
    tikuseki = 0
    # Aのほうがトータルでは速い
    if delta0 + delta1 > 0  :
        # Aがリード ー＞ 近づく、、、、
        if delta0 > 0 :
            print(0)
            sys.exit()
        else:
            print(   (-2* delta0) // (delta0 + delta1)    + int(  (-2* delta0) / (delta0 + delta1) != 0)  )
            sys.exit()

    else:
        print(0)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1



if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()


	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()

else :
    tikuseki = 0
    # Aのほうがトータルでは速い
    if delta0 + delta1 > 0  :
        # Aがリード ー＞ 近づく、、、、
        if delta0 > 0 :
            print(0)
            sys.exit()
        else:
            print(   (-2* delta0) // (delta0 + delta1)    + int(  (-2* delta0) / (delta0 + delta1) != 0)  )
            sys.exit()

    else:
        if (delta0 < 0) :

            print(0)
            sys.exit()

        else:

            print(    (2*delta0) // (-delta0 - delta1)  + int(  (2* delta0) / (-delta0 - delta1)  != 0 )       )
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1



if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()


	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()

else :
    tikuseki = 0
    # Aのほうがトータルでは速い
    if delta0 + delta1 > 0  :
        # Aがリード ー＞ 近づく、、、、
        if delta0 > 0 :
            print(0)
            sys.exit()
        else:
            print(   (-2* delta0) // (delta0 + delta1)    + int(  (-2* delta0) / (delta0 + delta1) != 0)  )
            sys.exit()

    else:
        if (delta0 < 0) :

            print(0)
            sys.exit()

        else:

            print(    (2*delta0) // (-delta0 - delta1)  + int(  (2* delta0) / (delta0 + delta1)  != 0 )       )
            sys.exit()

Submission status: Wrong Answer

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

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

if a1*T1 + a2*T2 == b1*T1 + b2*T2:
  print("infinity")
elif a1*T1 >= b1*T1:
  print(0)
else:
  half = b1*T1 - a1*T1
  x = (a1*T1 + a2*T2 - (b1*T1 + b2*T2))
  loop = math.ceil(half/x)
  print(loop * 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())

D1 = T1 * (A1 - B1)
D2 = T2 * (A2 - B2)
li = [D1, D2]
li.sort()

pos = 0
cnt = 0
for _ in range(10000000):
  pos += li[0]
  pos1 = pos
  pos += li[1]
  pos2 = pos
  if pos1 < 0 and pos2 >= 0:
    cnt += 2
if cnt >= 1000000:
  print("infinity")
else:
  print(cnt-1)

Submission status: Wrong Answer

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

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

diff=0
x=-1
ans=0

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

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

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())
C1,C2=A1-B1,A2-B2
D1,D2=T1*C1,T2*C2

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

diff=0
x=-1
ans=0

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

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

print(ans)

Submission status: Wrong Answer

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

input = sys.stdin.readline

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

    dx = [0]*2
    dx[0] = t[0] * (b[0] - a[0])
    dx[1] = dx[0] + t[1] * (b[1] - a[1])
    if dx[1] == 0:
        print("infinity")
        return
    ans = 1 + (-dx[0] // dx[1]) * 2
    if ((-dx[0]) % dx[1] == 0):
        ans -= 1
    print(ans)
main()

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 = T1 * A1 - T1 * B1
D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2

if D1 * D2 > 0:
    print(0)
elif D2 == 0:
    print("infinity")
else:
    c = 1
    D2 = abs(D2)
    D1 = abs(D2 - D1)
    Dp = D2
    while True:
        Dp += D2
        if Dp > D1:
            break
        elif Dp == D1:
            c += 1
            break
        c += 2
    print(c)

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
a=t1*(a1-b1)
b=t2*(a2-b2)
if a+b==0:print("infinity");exit()
if a*b>=0:print(0);exit()
x,y=abs(a),abs(a+b)
a=x//y
print(a*2+(x%y!=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())

dif1 = (A1-B1)*T1
dif2 = (A2-B2)*T2
Dif = dif1 + dif2

if Dif == 0:
    print('infinity')
elif dif1*dif2 >= 0:
    print(0)
else:
    point = 0
    count = 0
    check = False
    while not check:
        if point > 0: 
            point = point + dif1
            if point <= 0:
                count += 1
        else:
            point = point + dif1
            if point >= 0:
                count += 1
        if dif2 > 0 and point + dif2 < 0:
            check = True
        elif dif2 < 0 and point + dif2 > 0:
            check = True
        if point > 0: 
            point = point + dif2
            if point <= 0:
                count += 1
        else:
            point = point + dif2
            if point >= 0:
                count += 1
        if dif1 > 0 and point + dif1 < 0:
            check = True
        elif dif1 < 0 and point + dif1 > 0:
            check = True
    print(count)

Submission status: Wrong Answer

Solution code:
T = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = (A[0]-B[0])*T[0]
y = (B[0]-A[0])*T[0] + (B[1]-A[1])*T[1]

if x < 0:
    x *= -1
    y *= -1
if y == 0:
    print('infinity')
    exit()
ans = -(-x//y)*2-1
if x%y == 0:
    ans -= 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())

dif_1 = T1*(A1-B1)
dif_2 = T2*(A2-B2)

if abs(dif_1) > abs(dif_2):
    output = 0
elif abs(dif_1) == abs(dif_2):
    if dif_1==0 or dif_2==0:
        output = 'infinity'
    elif dif_1 == -dif_2:
        output = 'infinity'
    else:
        output = 0
else:
  if dif_1*dif_2 > 0:
    output = 0
  else:
    output = 1+int(abs(dif_1)/(abs(dif_2)-abs(dif_1))*2)
print(output)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
d1 = (b1 - a1) * t1
d2 = (b2 - a2) * t2
if d1 + d2 == 0:
    print('infinity')
    exit()
if (d1 > 0) ^ (d2 < 0):
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
d1 = (b1 - a1) * t1
d2 = (b2 - a2) * t2
if d1 + d2 == 0:
    print('infinity')
    exit()
if (d1 > 0) ^ (d2 < 0):
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
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 not (a1>b1)^(a2>b2):
    print(0)
    exit()

if a1+a2==b1+b2:
    print("infinity")
    exit()
if a1+a2>b1+b2:
    a1,a2,b1,b2 = b1,b2,a1,a2
if a1<b1:
    print(0)
    exit()
if (a1-b1)//(b1+b2-a1-a2)==0:
    print(((a1-b1)//(b1+b2-a1-a2))*2)
else:
    print(((a1-b1)//(b1+b2-a1-a2))*2+1)

Submission status: Wrong Answer

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

    dist1 = a1*t1 + a2*t2
    dist2 = b1*t1 + b2*t2
    if dist1 == dist2:
        return "infinity"
    elif a1 == b1:
        return "infinity"
    elif a2 == b2:
        return 0
    elif (a1 < b1 and a2 < b2) or (b1 < a1 and b2 < a2): 
        return 0

    if dist1 > dist2:
        a = a1*t1
        b = a2*t2
        c = b1*t1
        d = b2*t2
    else:
        a = b1*t1
        b = b2*t2
        c = a1*t1
        d = a2*t2
    
    m = (c-a) // (a+b-c-d)
    q = (c-a) % (a+b-c-d)
    if q == 0:
        out = 2 * m 
    else:
        out = 2 * m + 1

    return out

out = main()
print(out)

Submission status: Wrong Answer

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

# T1, T2は共通している。
now_takahasi = T1*A1
now_aoki = T1*B1

ans = 0
streak = 0
takahasi = False
aoki = False
if now_takahasi >= now_aoki:
    takahasi = True
else:
    aoki = True

distant_count = 0
lazy_count = 0
for i in range(500000):
    if i % 2 == 0:
        now_takahasi += T2*A2
        now_aoki += T2*B2
        if now_takahasi >= now_aoki:
            if aoki:  # 前回青木の方が前にいたならば
                ans += 1
                streak += 1
                lazy_count = 0
            else:
                streak = 0
                lazy_count += 1
            takahasi = True
            aoki = False
        elif now_aoki >= now_takahasi:
            if takahasi:  # 前回青木の方が前にいたならば
                ans += 1
                streak += 1
                lazy_count = 0
                # if distant == abs(now_takahasi-now_aoki) and i == 0:
                #     print("infinity")
                #     exit()
            else:
                streak = 0
                lazy_count += 1
            aoki = True
            takahasi = False
        if now_takahasi == now_aoki and i == 0:
            print("infinity")
            exit()

    else:
        now_takahasi += T1*A1
        now_aoki += T1*B1
        if now_takahasi > now_aoki:
            if aoki:  # 前回青木の方が前にいたならば
                ans += 1
                streak += 1
                lazy_count = 0
            else:
                streak = 0
                lazy_count += 1
            takahasi = True
            aoki = False
        elif now_aoki > now_takahasi:
            if takahasi:  # 前回青木の方が前にいたならば
                ans += 1
                streak += 1
                lazy_count = 0
            else:
                streak = 0
                lazy_count += 1
            aoki = True
            takahasi = False
    if lazy_count > 1:
        print(ans)
        exit()

Submission status: Wrong Answer

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

chk = []

tmp = 0
odd = 1

for i in range(10**6):
    if odd == 1:
        tmp += (a1-b1)*t1
        chk.append(tmp)
        odd = 0
    else:
        tmp += (a2-b2)*t2
        chk.append(tmp)
        odd = 1

ans = 0

if chk[1] == 0:
    print('infinity')
    exit()

for i in range(len(chk)-1):
    if chk[i]*chk[i+1] <0 or chk[i] == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

    dist1 = a1*t1 + a2*t2
    dist2 = b1*t1 + b2*t2
    if dist1 == dist2:
        return "infinity"
    elif a1 == b1:
        return "infinity"
    elif a2 == b2:
        return 0
    elif (a1 < b1 and a2 < b2) or (b1 < a1 and b2 < a2): 
        return 0

    if dist1 > dist2:
        a = a1*t1
        b = a2*t2
        c = b1*t1
        d = b2*t2
    else:
        a = b1*t1
        b = b2*t2
        c = a1*t1
        d = a2*t2
    
    m = (c-a) // (a+b-c-d)
    q = m % (a+b-c-d)
    if q == 0:
        out = 2 * m 
    else:
        out = 2 * m + 1

    return out

out = main()
print(out)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
d1 = (b1 - a1) * t1
d2 = (b2 - a2) * t2
if d1 + d2 == 0:
    print('infinity')
    exit()
if (d1 > 0) ^ (d2 < 0):
    print(0)
    exit()

ok, ng = 0, 10**20
if d1 > 0:
    d1 = -d1
    d2 = -d2
while ng - ok > 1:
    m = (ok + ng) // 2
    if m * d2 + (m + 1) * d1 <= 0:
        ok = m
    else:
        ng = m
if ok * d2 + (ok + 1) * d1 == 0:
    print(2 * ok + 2)
else:
    print(2 * ok + 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())
flag = False
if ((T1*A1 > T1*B1) and (T1*A1 + T2*A2 <= T1*B1 + T2*B2)) or ((T1*A1 < T1*B1) and (T1*A1 + T2*A2 >= T1*B1 + T2*B2)):
  flag = True

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

Submission status: Wrong Answer

Solution code:
import sys


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


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
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 not (a1>b1)^(a2>b2):
    print(0)
    exit()

if a1+a2==b1+b2:
    print("infinity")
    exit()
if a1+a2>b1+b2:
    a1,a2,b1,b2 = b1,b2,a1,a2
if a1<b1:
    print(0)
    exit()
if (a1-b1)//(b1+b2-a1-a2)==0:
    print(((a1-b1)//(b1+b2-a1-a2))*2+1)
else:
    print(((a1-b1)//(b1+b2-a1-a2))*2)

Submission status: Wrong Answer

Solution code:
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 not (a1>b1)^(a2>b2):
    print(0)
    exit()

if a1+a2==b1+b2:
    print("infinity")
    exit()
if a1+a2>b1+b2:
    a1,a2,b1,b2 = b1,b2,a1,a2
if a1<b1:
    print(0)
    exit()
if a1-b1//(b1+b2-a1-a2)==0:
    print(((a1-b1)//(b1+b2-a1-a2))*2+1)
else:
    print(((a1-b1)//(b1+b2-a1-a2))*2)

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-B1*T1
d2 = A2*T2-B2*T2

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy

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

v1=b1-a1
v2=b2-a2

x1=v1*t1
x2=v2*t2
di = abs(x2)-abs(x1)
if numpy.sign(x1)==numpy.sign(x2):
    print(0)
elif abs(x2)<abs(x1):
    print(0)
elif abs(x1)==abs(x2):
    print("infinity")
else:
    if int(x1%di)==0:
        print(int(2*(x1/di)))
        #di = abs(x2)-abs(x1)
    else:
        print(int(2*(x1//di)+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())

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

import sys
if d1+d2 == 0:
    print('infinity')
    sys.exit()
elif d1*d2 > 0:
    print(0)
    sys.exit()
    
else:
    if abs(d1)<abs(d2):
        ans = 1
    elif abs(d1)>abs(d2):
        ans = 0
    start = abs(d1)
    delta = abs(d2+d1)
    ans += start//delta * 2
    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())

A = 0
B = 0
ans = 0

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

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

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

low = -1
high = 10**20

while high-low>1:
    mid = (low+high)//2
    if B1*T1+B2*T2<A1*T1+A2*T2:
        if (A1*T1+A2*T2)*mid+A1*T1<(B1*T1+B2*T2)*mid+B1*T1:
            low = mid
        else:
            high = mid
    if B1*T1+B2*T2>A1*T1+A2*T2:
        if (A1*T1+A2*T2)*mid+A1*T1>(B1*T1+B2*T2)*mid+B1*T1:
            low = mid
        else:
            high = mid
if (A1*T1+A2*T2)*(high-1)+A1*T1==(B1*T1+B2*T2)*(high-1)+B1*T1:
    print(high*2-2)
else:
    print(high*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())

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

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

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

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


if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a//b)*2)
        else:
            print((a//b)*2 + 1)

Submission status: Wrong Answer

Solution code:
import numpy

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

v1=b1-a1
v2=b2-a2

x1=v1*t1
x2=v2*t2
di = abs(x2)-abs(x1)
if numpy.sign(x1)==numpy.sign(x2):
    print(0)
elif abs(x2)<abs(x1):
    print(0)
elif abs(x1)==abs(x2):
    print("infinity")

else:
    if x1%di==0:
        print(int(2*(x1/di)))
        #di = abs(x2)-abs(x1)
    else:
        print(int(2*(x1//di)+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())

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

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

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

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


if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a*2)//b)
        else:
            print((a//b)*2 + 1)

Submission status: Wrong Answer

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

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

from decimal import *


if(((A1<B1)and(T1*A1+T2*A2>T1*B1+T2*B2)) or ((A1>B1)and(T1*A1+T2*A2<T1*B1+T2*B2))):
    
    sa = abs(T1*A1-T1*B1)
    sa2 = abs(T1*A1+T2*A2-T1*B1-T2*B2)
    count = (sa//sa2)*2+1
    
elif(T1*A1+T2*A2==T1*B1+T2*B2):
    count = "infinity"
else:
    count = 0
    
print(count)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys


def main():
    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 == d2:
        print('infinity')
        sys.exit()

    if (d1 < 0 and d2 + d1 < 0) or (d1 > 0 and d2 + d1 > 0):
        print(0)
        sys.exit()
    else:
        if abs(d1) > abs(d2):
            i = 0
            while (i + 1) * d1 + i * d2 >= 0:
                i += 1
        else:
            i = 0
            while (i + 1) * d1 + i * d2 <= 0:
                i += 1

    print(i * 2 - 1)


main()

Submission status: Wrong Answer

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

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

from decimal import *


if(((A1<B1)and(T1*A1+T2*A2>T1*B1+T2*B2)) or ((A1>B1)and(T1*A1+T2*A2<T1*B1+T2*B2))):
    
    sa = abs(T1*A1-T1*B1)
    sa2 = abs(T1*A1+T2*A2-T1*B1-T2*B2)
    count = int(sa/sa2)*2+1
    
elif(T1*A1+T2*A2==T1*B1+T2*B2):
    count = "infinity"
else:
    count = 0
    
print(count)