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

# 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(5000000):
    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:
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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

if (a[0] > b[0] and a[1] > b[1]) or (a[0] < b[0] and a[1] <b[1]):
    print(0)
    exit()

if a[0] < b[0]:
    tmp = a
    a = b
    b = tmp

if a[0]*t[0]+a[1]*t[1] > b[0]*t[0]+b[1]*t[1]:
    print(0)
    exit()

dist = b[0]*t[0]+b[1]*t[1] - a[0]*t[0]+a[1]*t[1]
print((((a[0]-b[0]) *t[0]) // dist) + 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()))
BXA = 0
BXB = 0
XA = 0
XB = 0
ans = 0
for i in range(10**6):
    XA = T1*A1 + BXA
    XB = T1*B1 + BXB
    if (XA-XB)*(BXA-BXB)<0:
        ans+=1
    if XA==XB:
        print("infinity")
        exit(0)
    BXA = XA
    BXB = XB
    XA = T2*A2 + BXA
    XB = T2*B2 + BXB
    if (XA-XB)*(BXA-BXB)<0:
        ans+=1
    if XA==XB:
        print("infinity")
        exit(0)
    BXA = XA
    BXB = XB
print(ans)

Submission status: Wrong Answer

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

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

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

if -d2 < d1:
    print(0)
elif -d2 == d1:
    print('infinity')
else:
    print(-(-d1//(-d2-d1))*2-1)

Submission status: Wrong Answer

Solution code:
#f

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

def sign(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    else:
        return 0
import math
ans=0
if t1*a1+t2*a2 == t1*b1+t2*b2:
    print("infinity")
else:
    xa=0
    xb=0
    s=0
    while True:
        xa+=t1*a1
        xb+=t1*b1
        if sign(xa-xb)*s==-1:
            ans+=1
        s=sign(xa-xb)
        
        xa+=t2*a2
        xb+=t2*b2
        if sign(xa-xb)*s==-1:
            ans+=1
        s=sign(xa-xb)
        
        if abs(xa-xb) > abs(t1*a1-t1*b1)+11:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    T1,T2 = MI()
    A1,A2 = MI()
    B1,B2 = MI()
    if T1*A1+T2*A2==T1*B1+T2*B2:
        print("infinity")
        exit()
    now_A=0
    now_B=0
    A1*=T1
    B1*=T1
    A2*=T2
    B2*=T2
    diff1 = A1-B1
    diff2 = A2-B2
    now = 0
    if diff1*diff2>0:
        print(0)
    else:
        # print(gcd(diff1,diff2),diff1/gcd(diff1,diff2),diff2/gcd(diff1,diff2))
        if diff1>diff2:
            ans = abs(diff2/(diff1+diff2))
        else:
            ans = abs(diff1/(diff1+diff2)*2)
        print(int(ans))
    

if __name__ == '__main__':
    main()

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-1)//diff)*2+1

if(pitch%diff==0):
	ans-=1
print(ans)

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()))
sum1=a1*t1+a2*t2
sum2=b1*t1+b2*t2
if sum1==sum2:
	print("infinity")
elif a1>b1 and sum1>sum2:
	print(0)
elif a1<b1 and sum1<sum2:
	print(0)
else:
	if a1>b1 and sum1<sum2:
		ans=(b2*t2-0.5)//(sum2-sum1)
			
	else:
		ans=(a2*t2-0.5)//(sum1-sum2)
	print(int(ans))

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 = d1//d2*2 + 1
    
    
print(ans)

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 = max([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:
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()]
c = a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2


def waru(a, b):
    a = max(0, a)
    if b < 0:
        return 0
    if a % b == 0:
        return a // b+1
    else:
        return a//b


first1 = a1 * t1
first2 = b1 * t1
last1 = a2 * t2
last2 = b2 * t2


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

if c > 0:
    if first1 > first2:
        print(0)
        exit()
    print(waru(first2 - first1, c)*2+1)
else:
    if first1 < first2:
        print(0)
        exit()
    print(waru(first1 - first2, -c)*2+1)

Submission status: Wrong Answer

Solution code:
import math

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

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  return (halfB - halfA) // (sumA - sumB) * 2 + 1

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

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

if P+Q==0:
    print("infinity")

else:
    #print(P,Q)
    print(max(-P//(P+Q)*2+1,-Q//(P+Q)*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())))
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:
import math
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())

al1=t1*a1
al2=t2*a2
bl1=t1*b1
bl2=t2*b2

if al1>bl1:
    l1=al1
    l2=al2
    l3=bl1
    l4=bl2
else:
    l1=bl1
    l2=bl2
    l3=al1
    l4=al2

if al1+al2==bl1+bl2:
    print("infinity")
else:
    if (l1-l3)%(l1+l2-l3-l4)==0:
        ans=2*math.floor((l1-l3)/(l3+l4-l1-l2))
        print(ans)
    else:
        ans=max(0,2*math.floor((l1-l3)/(l3+l4-l1-l2))+1)
        print(ans)

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だけ走った後離れている距離
    print(abs(T1*(A1-B1))//d*2+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())
A=[]
a=0
cnt = 0
l1=(a1-b1)*t1
l2=(a2-b2)*t2
#print(l1,l2)
#print(abs(l1-l2))
if (a1-b1)*t1>0 and (a2-b2)*t2>0:
    print('0')
elif (a1-b1)*t1<0 and (a2-b2)*t2<0:
    print('0')
elif l1+l2==0:
    print('infinity')
else:
    print(math.ceil(min(abs(l1),abs(l2))/abs(l1+l2))*2-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 :

			#for (ll i = 1 i < LLINF i++) 
			#	tikuseki += delta0 + delta1
			#	if (tikuseki > -delta0) 
			#		cout << i
			#		sys.exit()
			#	
			#


			print((((-2* delta0) // ((delta0 + delta1)))  + 1))
			
		

	else :

		if (delta0 < 0) :

			print(0)
			sys.exit()

			
		else :

			#for (ll i = 1 i < LLINF i++) 
			#	tikuseki += -(delta0 + delta1)
			#	if (tikuseki > delta0) 
			#		cout << i 
			#		sys.exit()
			#	
			#

			print(math.floor(2*delta0 // (-(delta0 + delta1)))  + 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 solve(mid):
    tmp_t1 = min(t1, mid)
    tmp_t2 = mid - tmp_t1
    kyori_a = a1*tmp_t1 + a2*tmp_t2
    kyori_b = b1*tmp_t1 + b2*tmp_t2
    if kyori_a <= kyori_b:
        return True
    else:
        return False

# aのほうが最初早い
if a1 < b1:
    a1, a2, b1, b2 = b1, b2, a1, a2

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

ng = 0
ok = t1 + t2
cnt = 0
while cnt <= 100:
    mid = (ok + ng) / 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
    cnt += 1
diff = (b1*t1 + b2*t2) - (a1*t1 + a2*t2)
ans = int(2 * ((a1*t1) - (b1*t1)) / diff + 1)

if ans %2 == 0:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from math import floor

def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    C1 = T1*(A1-B1)
    C = C1 + T2*(A2-B2)
    if C == 0 or (C1/C).is_integer():
        return 'infinity'
    elif C1/C > 0:
        return '0'
    elif C1/C > -1:
        return '1'
    else:
        res =  2*(floor(-C1/C)+1)-1
        return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  T1,T2=LI()
  A1,A2=LI()
  B1,B2=LI()
  x=A1*T1
  y=B1*T1
  
  if x<y:
    f=0
    ans=0
    inf_cnt=0
  elif x>y:
    f=1
    ans=0
    inf_cnt=0
  else:
    inf_cnt=1
    f=-1
    ans=1

  for i in range(2000010):
    if i%2==0:
      x+=A2*T2
      y+=B2*T2
    else:
      x+=A1*T1
      y+=B1*T1

    # print(f,x,y)
    if x==y:
      inf_cnt+=1

    if f==0 and (x>y):
      ans+=1
      f=1
    elif f==1 and (x<y):
      ans+=1
      f=0

  if inf_cnt==2000010 or inf_cnt==1000005:
    return 'infinity'
  return ans

# main()
print(main())

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)
    else:
        print(abs(d1//(d1+d2))*2-1)
    # print(d2/(d1+d2))
    # print((d1+d2)/d1)
    # print()
    # print((a1*t1+a2*t2) / (d1+d2))
    # print((b1 * t1 + b2 * t2) / (d1+d2))
    # print((a1 * t1 - b1*t1) / d1)
    # print(((a1*t1+a2*t2) - (b2*t2+b1*t1))/(d1+d2))
    #
    # print((a2*t2+a1*t1)/(d1+d2))
    #
    # if d1 < d2:
    #     print(1)
    # elif d1 > d2:
    #     print(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())

taka = t1*a1
aoki = t1*b1
ans = 0
if(t1*a1+t2*a2==t1*b1+t2*b2):
    print("infinity")
#diff = t1*a1+t2*a2-t1*b1+t2*b2
else:
    top = 0
    if(taka>aoki):
        top = 0
    else:
        top = 1
    for i in range(2,1000000):
    #    prev_taka = taka
    #    prev_aoki = aoki
        prev_top = top
        if(i%2==1):
            taka += t1*a1
            aoki += t1*b1
        else:
            taka += t2*a2
            aoki += t2*b2
        if(taka>aoki):
            top = 0
        else:
            top = 1
        if(prev_top != top):
            ans += 1
        
    #    print("taka",taka)
    #    print("aoki",aoki)
    
    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 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*((B1-A1)*T1+(B2-A2)*T2)==T1*A1-T1*B1:
  ans-=1
print(ans)

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だけ走った後離れている距離
    print(abs(T1*(A1-B1))//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())

A = 0
B = 0
ans = 0

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


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())
        
ans = ""

if A1*T1+A2*T2 == B1*T1+B2*T2:
    ans = "infinity"

elif (A1*T1> B1*T1) and (A2*T2< B2*T2):
    tmp1 = A1*T1 -B1*T1
    tmp2 = ( B1*T1 + B2*T2) -(A1*T1+A2*T2)

    ans = 2*(tmp1//tmp2 +1) - 1
    
elif (A1*T1< B1*T1) and (A2*T2> B2*T2):
    tmp1 = B1*T1- A1*T1
    tmp2 = A1*T1+A2*T2 - ( B1*T1 + B2*T2)

    ans = 2*(tmp1//tmp2 + 1) - 1
else:
    ans = 0

    
print(ans)

Submission status: Wrong Answer

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

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

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

if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:
    print('infinity')
    exit()
if (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
    print(0)
    exit()
diff = abs(A1-B1) * T1
diff2 = abs(T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2))
x, y = divmod(diff, diff2)
print(1 if diff2 > diff else x * 2 + 1 if y <= diff else x * 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(abs((b1-a1)//(a1+a2-b1-b2))*2+1)

Submission status: Wrong Answer

Solution code:
import sys

T1, T2 =map(int, input().split())

A1, A2 =map(int, input().split())

B1, B2 =map(int, input().split())

P1 , P2 = 0 , 0
count = 0
def step(P1,P2,cnt):
  end = False
  st1 = P1-P2
  P1 = P1 +T1*A1
  P2 = P2 +T1*B1
 
  #print([P1,P2])
  st2 = P1-P2
  #print([st1,st2])
  if st1 * st2 <=0:
    cnt += 1
  P1 = P1 +T2*A2
  P2 = P2 +T2*B2
  st3 = P1-P2
  #print([st2,st3])
  if st3 + st2 <=0:
    #print('a')
    cnt += 1
  if st1*st2>0 and st2*st3>0:
    end = True
  return P1-min(P1,P2),P2-min(P1,P2),cnt,end


test1,test2,testc,flag = step(P1,P2,0)

if test1 ==test2:
  if testc>1:
    print("infinity")
  else:
    print(0)
  sys.exit()
"""
print("start")

print([P1,P2,count])

P1,P2,count,flag = step(P1,P2,count)
print([P1,P2,count,flag])   
P1,P2,count ,flag= step(P1,P2,count)
print([P1,P2,count,flag])   

P1,P2,count,flag = step(P1,P2,count)
print([P1,P2,count,flag])   
P1,P2,count ,flag= step(P1,P2,count)
print([P1,P2,count,flag])   
"""



n = 0
while not flag:
  P1,P2,count,flag = step(P1,P2,count)
  n += 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())
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)
  print(-(-a//b)+a//b)

Submission status: Wrong Answer

Solution code:
import sys
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x=t1*a1-t1*b1
y=t2*a2-t2*b2
if x+y==0:
  print('Infinity')
  sys.exit()
if abs(x)%(x+y)==0:
  print((abs(x)//(x+y))*2)
else:
  print((abs(x)//(x+y))*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())

a=a1-b1
b=a2-b2
#print(a,b)

ans=0

if(a*b>0):
    ans=-1
else:
    go=a*t1+b*t2
    if(go*a>0):
        ans=0
    elif(go==0):
        ans=-10
    else:
        kai=a*t1
        if(go<0):
            go*=-1
        if(kai<0):
            kai*=-1
        #print(kai//go)
        ans=(kai//go)*2+1

if(ans==-1):
    print(0)
elif(ans==-10):
    print("infinity")
else:
    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 (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)
    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())

from math import *

x = A1*T1 + A2*T2 - (B1*T1 + B2*T2)
y = A1*T1 - B1*T1
if(x ==0 or y==0):
    print('infinity')
elif(y * x > 0):
    print(0)
else:
    print(floor(abs(y)/abs(x))*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 A1<B1:
  A1,B1=B1,A1
  A2,B2=B2,A2

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

x1,x2=(A1-B1)*T1,(B2-A2)*T2
#print(x1,x2)
if x1-x2>0:
  print(0)
elif x1-x2==0:
  print("infinity")
else:
  d=abs(x1-x2)
  print((x1//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())

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*((B1-A1)*T1+(B2-A2)*T2)==T1*A1-T1*B1:
  ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
T_1,T_2=map(int,input().split())
A_1,A_2=map(int,input().split())
B_1,B_2=map(int,input().split())

if (A_1==B_1 and A_2==B_2) or (T_1==T_2 and A_1==B_2 and A_2==B_1):
    print('infinity')
elif (A_1>B_1 and A_2>B_2) or (A_1<B_1 and A_2<B_2):
    print(str(0))
elif (A_1*T_1+A_2*T_2==B_1*T_1+B_2*T_2):
    print('infinity')
else:
    C=0
    T=T_1
    A=A_1*T
    B=B_1*T
    L_A=A
    L_B=B
    for i in range(2,100000):
        if i%2==0:
            T=T_2
            A=A+A_2*T
            B=B+B_2*T
        else:
            T=T_1
            A=A+A_1*T
            B=B+B_1*T
        if L_A>L_B and A<=B:
            C=C+1
            L_A=A
            L_B=B
        elif L_A<L_B and A>=B:
            C=C+1
            L_A=A
            L_B=B
        else:
            L_A=A
            L_B=B
    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())

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 (start%delta != 0):ans += 1
    print(ans)

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()]
c = a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2


def waru(a, b):
    a = max(0, a)
    if b < 0:
        return 0
    if a % b == 0:
        return a // b+1
    else:
        return a//b


first1 = a1 * t1
first2 = b1 * t1
last1 = a2 * t2
last2 = b2 * t2


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

if first1 > first2:
    if c > 0:
        print(0)
        exit()
    if (first1 - first2) % c == 0:
        print((first1 - first2) // (-c) * 2)
    else:
        print(waru(first1 - first2, -c) * 2 + 1)
else:
    if c < 0:
        print(0)
        exit()
    if (first1 - first2) % c == 0:
        print(waru(first2 - first1, c) * 2)
    else:
        print(waru(first2 - first1, c) * 2 + 1)

Submission status: Wrong Answer

Solution code:
import sys

T1, T2 =map(int, input().split())

A1, A2 =map(int, input().split())

B1, B2 =map(int, input().split())

P1 , P2 = 0 , 0
count = 0
def step(P1,P2,cnt):
  end = False
  st1 = P1-P2
  P1 = P1 +T1*A1
  P2 = P2 +T1*B1
 
  #print([P1,P2])
  st2 = P1-P2
  #print([st1,st2])
  if st1 * st2 <=0:
    cnt += 1
  P1 = P1 +T2*A2
  P2 = P2 +T2*B2
  st3 = P1-P2
  #print([st2,st3])
  if st3 + st2 <=0:
    #print('a')
    cnt += 1
  if st1*st2>0 and st2*st3>0:
    end = True
  return P1-min(P1,P2),P2-min(P1,P2),cnt,end


test1,test2,testc,flag = step(P1,P2,0)

if test1 ==test2:
  if testc>1:
    print("infinity")
  else:
    print(0)
  sys.exit()
"""
print("start")

print([P1,P2,count])

P1,P2,count,flag = step(P1,P2,count)
print([P1,P2,count,flag])   
P1,P2,count ,flag= step(P1,P2,count)
print([P1,P2,count,flag])   

P1,P2,count,flag = step(P1,P2,count)
print([P1,P2,count,flag])   
P1,P2,count ,flag= step(P1,P2,count)
print([P1,P2,count,flag])   
"""



n = 0
while n<59:
  P1,P2,count,flag = step(P1,P2,count)
  n += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

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

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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


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

    la = la1 + la2
    lb = lb1 + lb2

    if la == lb:
        return 'infinity'

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

    if la > lb and la1 > lb1:
        return 0

    if la < lb and la1 < lb1:
        return 0


    if la > lb:
        dd = lb1 - la1
    else:
        dd = la1 - lb1
    d = abs(la-lb)
    ans = int(dd/d * 2)

    return 1 if ans == 0 else ans

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  T1,T2=LI()
  A1,A2=LI()
  B1,B2=LI()
  x=A1*T1
  y=B1*T1
  
  if x<y:
    f=0
    ans=0
    inf_cnt=0
  elif x>y:
    f=1
    ans=0
    inf_cnt=0
  else:
    inf_cnt=1
    f=-1
    ans=1

  for i in range(1000010):
    if i%2==0:
      x+=A2*T2
      y+=B2*T2
    else:
      x+=A1*T1
      y+=B1*T1

    # print(f,x,y)
    if x==y:
      inf_cnt+=1

    if f==0 and (x>y):
      ans+=1
      f=1
    elif f==1 and (x<y):
      ans+=1
      f=0

  if inf_cnt==1000010 or inf_cnt==500005:
    return 'infinity'
  return ans

# main()
print(main())