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

a = 0
b = 0
big = "1"
counter = -1
eq = False
sbn = 10**9
for i in range(10**4):
    t = T[i % 2]
    if i % 2 == 0:
        a += t * A[0]
        b += t * B[0]
    elif i % 2 == 1:
        a += t * A[1]
        b += t * B[1]
    if a >= b:
        n_big = "a"
    else:
        n_big = "b"
    if n_big != big:
        counter += 1
    big = n_big
if counter == 10**4 - 1:
    print("infinity")

else:
    print(counter)

Submission status: Wrong Answer

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


d1 = (a1 - b1)*t1
d2 = (a2 - b2)*t2
if d1 + d2 == 0:
    print("infinity")
else:
    if a1 > b1 and a2 > b2:
        print(0)
    elif a1 < b1 and a2 < b2:
        print(0)
    elif d1 + d2 < 0:
        print(0)
    else:
        print(abs(d2//(d1+d2))*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()))

d0 = a[0] * t[0] - b[0] * t[0]
d1 = a[1] * t[1] - b[1] * t[1]
dd = d0 + d1
if dd == 0 :
	print("infinity")
	exit(0)

ans = 0
ok = 0
ng = 1000000000000000000
while abs(ok - ng) > 1 :
	mid = (ok + ng) // 2 
	if dd > 0 :
		if d0 + mid * dd <= 0 :
			ok = mid
		else :
			ng = mid
	else :
		if d0 + mid * dd >= 0 :
			ok = mid
		else :
			ng = mid

print(2 * ok + 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(2*(x1//di)-1)
        #di = abs(x2)-abs(x1)
    else:
        print(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())

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

if A1+A2 > B1+B2: # Aを遅く
    A1,B1 ,A2,B2 = B1,A1 ,B2,A2

if A1+A2 == B1+B2:
    print("infinity")
    exit()
A,B = 0,0
ans = -1
while 1:
    A += A1
    B += B1
    if A > B:
        ans += 2
    elif A == B:
        ans += 1
    else:
        break
    A += A2
    B += B2
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*t1+a2*t2==b1*t1+b2*t2:
  print('infinity')
elif (a1-b1)*(a2-b2)>0:
  print(0)
else:
  x=0
  a=abs(a1*t1-b1*t1)
  b=abs(a1*t1+a2*t2-b1*t1-b2*t2)
  if a%b==0:
    c=1
  else:
    c=0
  print(-(-a//b)+a//b-c)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    t1, t2, a1, a2, b1, b2 = map(int, sys.stdin.read().split())
    A1 = t1 * a1
    A2 = t2 * a2
    B1 = t1 * b1
    B2 = t2 * b2

    d = abs(A1 + A2 - B1 - B2)
    if A1 == B1:
        ans = 0
    elif A1 > B1:
        if A1 + A2 > B1 + B2:
            ans = 0
        elif A1 + A2 == B1 + B2:
            ans = 'infinity'
        else:
            ans = (A1 - B1) // d * 2 + 1

    
    elif A1 < B1:
        if A1 + A2 < B1 + B2:
            ans = 0
        elif A1 + A2 == B1 + B2:
            ans = 'infinity'
        else:
            ans = (B1 - A1) // d * 2 + 1

    print(ans)
    
if __name__ == '__main__':
    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())
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-b),abs(a+b)
print(x,y)
a=x//y
print(a-(a%2==0))

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:
        print((a*2)//b)

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:
        print((a*2)//b)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

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

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

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

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

x = B1 * T1 - A1 * T1
y = A2 * T2 - B2 * T2
n = int(x / (y - x) + 1)
print(n * 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())
if t1*a1+t2*a2==t1*b1+t2*b2:
  print("infinity")
else:
  m11=t1*a1
  m12=t2*a2
  m21=t1*b1
  m22=t2*b2
  d1=m11+m12
  d2=m21+m22
  if m11>m21 and d1>d2:
    print(0)
  elif m11<m21 and d2>d1:
    print(0)
  else:
    ans=0
    md1=abs(m11-m21)
    dd=abs(d1-d2)
    print(max(2*md1//dd+1,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()))
p,q=[0],[0]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(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())

chk = []

tmp = 0
odd = 1

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

ans = 0

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


if ans > 10000:
    print('infinity')
else:
    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:
import math

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")
else:
  if A1*T1+A2*T2<B1*T1+B2*T2:
    A1, A2, B1, B2=B1, B2, A1, A2
  if A1>=B1:
    print(0)
  else:
    print(math.ceil((B1*T1-A1*T1)/(A1*T1+A2*T2-B1*T1-B2*T2))*2-1)

Submission status: Wrong Answer

Solution code:
def hanten(bit):
    if bit == 0:
        return 1
    else:
        return 0


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

t = [t1, t2]
a = [a1, a2]
b = [b1, b2]

a_lst = []
b_lst = []
bit = 0
ans = 0
hozon = 0
gyakuten = 0
while True:
    a_lst.append(sum(a_lst) + t[bit]*a[bit])
    b_lst.append(sum(b_lst) + t[bit]*b[bit])
    if (a_lst[-1] - b_lst[-1]) * hozon < 0:
        ans += 1
        gyakuten = 0
    else:
        gyakuten += 1
    if gyakuten > 1:
        break
    hozon = a_lst[-1] - b_lst[-1]
    if bit == 1:
        if a_lst[-1] == b_lst[-1]:
            print('infinity')
            exit()
    bit = hanten(bit)

print(ans)

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


if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2 :
    print('infinity')
    
else :
    a = T1 * A1
    b = T1 * B1
   
    ok, ng = 0, 10 ** 12
    while ng - ok > 1 :
        m = (ng + ok) // 2
        if m % 2 == 0 :
            ca = (T1 * A1 + T2 * A2) * m // 2
            cb = (T1 * B1 + T2 * B2) * m // 2
            pa = ca - T2 * A2
            pb = cb - T2 * B2                
        else :
            ca = (T1 * A1 + T2 * A2) * m // 2 - T2 * A2
            cb = (T1 * B1 + T2 * B2) * m // 2 - T2 * B2
            pa = ca - T1 * A1
            pb = cb - T1 * B1
            
        if (ca - cb) * (pa - pb) < 0 :
            ok = m
        else :
            ng = m
            
    print(max(0, ok-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()
print((a1-b1)//(b1+b2-a1-a2)+(b2-a2)//(b1+b2-a1-a2))

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 B1>A1:
  A1,A2,B1,B2=B1,B2,A1,A2
  
if A2>B2:
  print(0)
  exit()
if A1*T1+A2*T2==B1*T1+B2*T2:
  print("infinity")
  exit()

ans=1
ba=B1*T1+B2*T2-(A1*T1+A2*T2)
x=((T1*A1-T1*B1)-ba)//((B1-A1)*T1+(B2-A2)*T2)
ans+=2*(x+1)
if ba+(x-1)*((B1-A1)*T1+(B2-A2)*T2)==T1*A1-T1*B1:
  ans+=1
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:
        print((a*2)//b)

Submission status: Wrong Answer

Solution code:
import numpy as np
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
c1 = b1-a1
c2 = b2-a2
s = t1*c1+t2*c2
if s==0:
    print("infinity")
    exit()
mx = min([np.abs(t1*c1),np.abs(t2*c2)])
n = np.abs(int(mx/s))
if np.abs(t1*c1) > np.abs(t2*c2):
    print(0)
    exit()
if mx%s == 0:
    print(2*n-2)
else:
    print(2*n-1)

Submission status: Wrong Answer

Solution code:
import sys

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

la1 = A[0] * T[0]
la2 = A[1] * T[1]
lb1 = B[0] * T[0]
lb2 = B[1] * T[1]
la = la1 + la2
lb = lb1 + lb2

if la == lb:
    print("infinity")
    sys.exit()

d = abs(la - lb)
l_count = abs(la1 - lb1) // d
print(l_count*2+1)

Submission status: Wrong Answer

Solution code:
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ls1 = [t[0]*a[0]]
ls2 = [t[0]*b[0]]
ans = 0

if t[0] * a[0] + t[1] * a[1] ==  t[0] * b[0] + t[1] * b[1]:
    print("infinity")
else:
    for i in range(100001):
        if i % 2 != 0:
            ls1.append(ls1[i]+t[0]*a[0])
            ls2.append(ls2[i]+t[0]*b[0])
        else:
            ls1.append(ls1[i]+t[1]*a[1])
            ls2.append(ls2[i]+t[1]*b[1])

    for i in range(100000):
        if ls1[i] > ls2[i] and ls1[i+1] < ls2[i+1] or ls1[i] < ls2[i] and ls1[i+1] > ls2[i+1]:
            ans += 1
        #if ls1[i] > ls2[i] and ls1[i+1] > ls2[i+1] or ls1[i] < ls2[i] and ls1[i+1] < ls2[i+1]:
        #    break


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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#mitsui f
import sys
import math
import collections
#sys.setrecursionlimit(100000)

#n=int(input())

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

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

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

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

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


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


ans=(pitch//diff +1)*2-1

if(pitch%diff==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())

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

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

Submission status: Wrong Answer

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

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

    C1, C2 = B1-A1, B2-A2

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

    if C1*T1 + C2*T2 < 0:
        C1, C2 = -C1, -C2
#    print('C1:', C1, '/ C2:', C2)

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

    x1, x2 = T1, 2*T1+T2
    y1, y2 = C1*T1, 2*C1*T1+C2*T2
#    print('x1:', x1, '/ y1:', y1)
#    print('x2:', x2, '/ y2:', y2)

    x = -y1 * (x2-x1) / (y2-y1) + x1
#    print('x:', x)

    z = x-T1
    T = T1+T2
    ans = z//T*2
#    print('ans:', ans)
#    print(int(z//T*T), z)
    if int(z//T*T) != z:
        ans += 1

    return int(ans)


print(solve())

Submission status: Wrong Answer

Solution code:
t = list(map(int,(input().split())))
a = list(map(int,(input().split())))
b = list(map(int,(input().split())))
A = 0
B = 0
ans = 0
tmp = [[0,0],[0,0]]
for i in range(2):
    a[i] *= t[i]
    b[i] *= t[i]

if a[0] + a[1] == b[0] + b[1]:
    print('infinity')
    exit(0)
elif a[0] > b[0] and a[1] > b[1]:
    print(0)
    exit(0)
elif a[0] < b[0] and a[1] < b[1]:
    print(0)
    exit(0)


for i in range(2):
    for j in range(2):
        A += a[j]
        B += b[j]
        tmp[i][j] = abs(A-B)
#print(tmp)
if tmp[0][0] - tmp[1][0] < 0:
    if not tmp[0][1] % (tmp[0][1] - tmp[1][1]):
        ans -= 1
    tmp[0][1] //= tmp[0][1] - tmp[1][1]
    ans += tmp[0][1] * 2 
else:
    if not tmp[0][0] % (tmp[0][0] - tmp[1][0]):
        ans -= 1

    tmp[0][0] //= tmp[0][0] - tmp[1][0]
    ans += tmp[0][0] * 2 +1


print(max(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())
if t1*a1+t2*a2==t1*b1+t2*b2:
  print("infinity")
else:
  m11=t1*a1
  m12=t2*a2
  m21=t1*b1
  m22=t2*b2
  d1=m11+m12
  d2=m21+m22
  if m11>m21 and d1>d2:
    print(0)
  elif m11<m21 and d2>d1:
    print(0)
  else:
    ans=0
    md1=abs(m11-m21)
    dd=abs(d1-d2)
    print(max(2*md1//dd,1))

Submission status: Wrong Answer

Solution code:
T1, T2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))

s1 = a1*T1
s2 = a2*T2
w1 = s1 + s2
t1 = b1*T1
t2 = b2*T2
w2 = t1 + t2
#print(s1, s2)
#print(t1, t2)
#print(w1, w2)

if w1==w2:
    print('infinity')
    exit()

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

if a1<b1:
    print(int((w1-s1)/(w1-w2)))
else:
    print(int((w2-t1)/(w2-w1)))

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

if d1 + d2 == 0:
    print('infinity')
else:
    a = abs(d1//(d1+d2))
    ans = a*2-1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b = m()

s= l()

t = l()

count = 0
if s[0]*a + s[1]*b ==t[0]*a + t[1]*b:
    print("infinity")
    exit()

if (s[0]*a - t[0]*a) * (s[1]*b - t[1]*b) >= 0:
    print(0)
else:
    aaa = (s[0]*a - t[0]*a) + (s[1]*b - t[1]*b)
    if aaa > 0:
        if (s[0]*a - t[0]*a) > 0:
            count += 2*((t[1]*b-s[1]*b) // aaa) + 1
        else:
            count += 2*((t[0]*a-s[0]*a) // aaa) + 1

    else:
        if (s[0]*a - t[0]*a) < 0:
            count += 2*((s[0]*a-t[0]*a) // aaa) + 1
        else:
            count += 2*((s[1]*b-t[1]*b) // aaa) + 1
        

print(count)

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
if T1*C1==T2*C2:
    print("infinity")

D1=T1*C1
D2=T2*C2
diff=0
x=-1
ans=0

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

while x<0:
    diff1=diff+D1
    diff2=diff+D1+D2
    x=diff1*diff2
    if x<0:
        ans+=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())
diff1 = A1 * T1 - B1 * T1
diff2 = A2 * T2 - B2 * T2
if diff1 * diff2 > 0:
    print(0)
elif diff1 + diff2 == 0:
    print('infinity')
else:
    n = abs(diff1) // abs(diff2 + diff1)
    if n == 0:
        print(1)
    else:
        print(2*(n+1) - 1 + (1 if abs(diff2 + diff1) * n == abs(diff1) else 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())

# 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 = abs(now_aoki-now_takahasi)
distant_count = 0
lazy_count = 0
for i in range(100):
    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()
        print(distant // abs(distant - abs(now_aoki-now_takahasi)))
        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=(int(i) for i in input().split())
A1, A2=(int(i) for i in input().split())
B1, B2=(int(i) for i in input().split())

if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif ((A1>B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)>0)) or ((A1<B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)<0)):
    print(0)
else:
    d=T1*A1+T2*A2-(T1*B1+T2*B2)#T1+T2だけ走った後離れている距離
    ss=0
    if abs(T1*(A1-B1))%d==0:
        ss=1
        
    print(abs(T1*(A1-B1))//d*2-ss+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())

firl=0
dfirl=0
if a1>b1:
    firl=0
    dfirl=t1*(a1-b1)

elif a1<b1:
     firl = 1
     dfirl = t1 * (a1 - b1)*(-1)
ttp=0
ans=0
if a2>b2  and firl==0:
    print(0)
    exit()
elif a2>b2 and firl==1:
    dairl=t2*(a2-b2)
    if dairl<dfirl:
        print(0)
        exit()
    elif dairl==dfirl:
        print("infinity")
        exit()
    elif dairl>dfirl:
        u=1
        while ttp-t2*u<t1:

            tp=dfirl/(a2-b2)
            ttp=(t2-tp)*(a2-b2)/(b1-a1)
            dfirl=(t1-ttp)*(b1-a1)
            u+=1
        print(u)
        exit()

if a2 < b2 and firl == 1:
    print(0)
    exit()
elif a2 < b2 and firl == 0:
    dairl = t2 * abs(a2 - b2)
    if dairl < dfirl:
        print(0)
        exit()
    elif dairl == dfirl:
        print("infinity")
        exit()
    elif dairl > dfirl:
        u = 1
        while ttp - t2 * u < t1:
            tp = dfirl / abs(a2 - b2)
            ttp = (t2 - tp) * abs(a2 - b2) / abs(b1 - a1)
            dfirl = (t1 - ttp) * abs(b1 - a1)
            u += 1
        print(u)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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")
elif A1*T1 < B1*T1 and A2*T2 < B2*T2:
    print(0)
elif A1*T1 > B1*T1 and A2*T2 > B2*T2:
    print(0)
else:
    A1*T1+A2*T2 - B1*T1+B2*T2

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-b),abs(a+b)
print(x,y)
print(int(0--(x+0.5)//y)-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

x1 = (a1 - b1) * t1
x2 = (a2 - b2) * t2

if (x1 < 0 and x2 < 0) or (x1 > 0 and x2 > 0):
    print(0)
elif x1 + x2 == 0:
    print('infinity')
else:
    diff = x1 + x2
    y = 0
    if diff > 0:
        y = abs(min(x1, x2))

    else:
        y = max(x1, x2)
    diff = abs(diff)
    print((y // diff)*2 + 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

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 a1*t1+a2*t2<b1*t1+b2*t2:
    print(0)
    exit()
elif a1*t1+a2*t2 == b1*t1+b2*t2:
    print("infinity")
    exit()
dis=t2*(a2-b2)+t1*(a1-b1)
ans=(t1*(b1-a1))//dis
print(ans*2+1)

Submission status: Wrong Answer

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

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

    # print(x)
    # print(y)
    # print(diff)

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

    if diff > 0: # aが先行
        if x<0:
            x = abs(x)
            ans = math.ceil(x/diff)
        else:
            y = abs(y)
            ans = math.ceil(y/diff)

    else: # bが先行
        diff = abs(diff)
        if x>0:
            ans = math.ceil(x/diff)
        else:
            ans = math.ceil(y/diff)

    print(ans*2-1)

    # calc


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

t = input().split(" ")
a = input().split(" ")
b = input().split(" ")

t = [int(i) for i in t]

rs = [int(a[0]) - int(b[0]), int(a[1]) - int(b[1])]
m = rs[0] * t[0]
s = rs[0] * t[0] + rs[1] * t[1]

if s == 0:
  print("infinity")
elif m * s > 0:
  print(0)
else: # 絶対値とる
  ma = max(m, -m)
  sa = max(s, -s)
  
  if ma % sa == 0:
    print(2 * (ma / sa))
  else:
    print(2 * math.ceil(ma/sa) - 1)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b = m()

s= l()

t = l()

count = 0
if s[0]*a + s[1]*b ==t[0]*a + t[1]*b:
    print("infinity")
    exit()

if (s[0]*a - t[0]*a) * (s[1]*b - t[1]*b) >= 0:
    print(0)
else:
    aaa = (s[0]*a - t[0]*a) + (s[1]*b - t[1]*b)
    if aaa > 0:
        if (s[0]*a - t[0]*a) > 0:
            count += 2*((t[1]*b-s[1]*b) // aaa) + 1
        else:
            count += 2*((t[0]*a-s[0]*a) // aaa) + 1

    else:
        if (s[0]*a - t[0]*a) < 0:
            count += 2*((s[1]*b-t[1]*b) // aaa) + 1
        else:
            count += 2*((s[0]*a-t[0]*a) // aaa) + 1
        

print(count)

Submission status: Wrong Answer

Solution code:

T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
  print(0);
  exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
  print("infinity")
  exit();
ans=(abs((B1-A1)*T1)/abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
  ans-=1
print(int(ans))

Submission status: Wrong Answer

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

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

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