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

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

# del0 * del1 > 0 -> inf?

if (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 == 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:
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())

#infの処理
if t1 * (a1 - b1) + t2 * (a2 - b2) == 0:
    print("infinity")
    exit()
#一回も交わらない時の処理、もしかしたらいらないかも
if ( a1 > b1 and a2 > b2 )or (a1 < b1 and a2 < b2):
    print(0)
    exit()

#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
change = True
for i in range(10**6):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
        change = True
    else:
        #二回連続で変わらなかったら終了
        if change == False:
            break
        change = False
    init = min(a,t)
    a -= init
    t -= init
    pre = (t - a)
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()
    A1*=T1
    B1*=T1
    A2*=T2
    B2*=T2
    diff1 = A1-B1
    diff2 = A2-B2
    # print(diff1,diff2)

    if diff1*diff2>0:
        print(0)
    else:
        if abs(diff1)>abs(diff2):
            ans = 2 * (abs(diff2) // abs(diff1+diff2))
            if diff2//(diff1+diff2) == diff2/(diff1+diff2):
                ans -= 1 ##ピッタリ原点
        else:
            ans = 2 * (abs(diff1) // abs(diff1+diff2))
            if diff1//(diff1+diff2) == diff1/(diff1+diff2):
                ans -= 1 ##ピッタリ原点
        print(ans + 1)
    

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

#infの処理
if t1 * (a1 - b1) + t2 * (a2 - b2) == 0:
    print("infinity")
    exit()
#一回も交わらない時の処理、もしかしたらいらないかも
if ( a1 > b1 and a2 > b2 )or (a1 < b1 and a2 < b2):
    print(0)
    exit()

#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
change = True
for i in range(10**10):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
        change = True
    else:
        #二回連続で変わらなかったら終了
        if change == False:
            break
        change = False
    init = min(a,t)
    a -= init
    t -= init
    pre = (t - a)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#+++++
		
def main():
	t1, t2 = map(int, input().split())
	a1, a2 = map(int, input().split())
	b1, b2 = map(int, input().split())
	
	a_d = t1*a1 + t2 * a2
	b_d = t1*b1 + t2 * b2
	
	if a_d == b_d:
		return 'infinity'
	
	pp=a_d-b_d
	pc=t1*(a1-b1)
	if pp*pc > 0:
		return 0
	
	#pa((pp,pc))
	return (-1 * (pc // pp))*2 -1
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

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:
    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+2)
else:
    print(((a1-b1)//(b1+b2-a1-a2))*2+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a >= b and a1 <= b1 or a <= b and a1 >= b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 >= b1 and a2 <= b2 or a1 <= b1 and a2 >= b2:
        cnt += 1
    if a == b and a2 == b2:
        print('infinity')
        exit()
    return a2, b2, cnt

a = b = 0
ans = 0
while True:
    a, b, cnt = calc(a, b)
    if cnt == 0:
        break
    ans += cnt
print(ans-1)

Submission status: Wrong Answer

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

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:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a >= b and a1 <= b1 or a <= b and a1 >= b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 >= b1 and a2 <= b2 or a1 <= b1 and a2 >= b2:
        cnt += 1
    return a2, b2, cnt

a = b = 0
ans = 0
while True:
    a, b, cnt = calc(a, b)
    if a == b:
        print('infinity')
        exit()
    if cnt == 0:
        break
    ans += cnt
print(ans-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

def calc(a, b):
    cnt = 0
    a1 = a + T1 * A1
    b1 = b + T1 * B1
    if a > b and a1 < b1 or a < b and a1 > b1:
        cnt += 1
    a2 = a1 + T2 * A2
    b2 = b1 + T2 * B2
    if a1 > b1 and a2 < b2 or a1 < b1 and a2 > b2:
        cnt += 1
    return a2, b2, cnt

a = b = 0
ans = 0
while True:
    a, b, cnt = calc(a, b)
    if a == b:
        print('infinity')
        exit()
    if cnt == 0:
        break
    ans += cnt
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()

x=(T1*A1-T1*B1)//((B1-A1)*T1+(B2-A2)*T2)+1
ans=2*x-1
if (T1*A1-T1*B1)%((B1-A1)*T1+(B2-A2)*T2)==0:
  ans-=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):
	print("0")
	sys.exit()

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

ans=pitch//diff*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())
d1 = a1*t1 - b1*t1
d2 = a2*t2 - b2*t2
if d1<0:
    d1*=-1
    d2*=-1
if d1+d2 == 0:
    print('inifinity')
elif d1+d2>0:
    print(0)
else:
    a = -d1//(d1+d2)
    b = -d1 % (d1+d2)
    if b!=0:
        print(a*2+1)
    else:
        print(a*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
if d1<0:
    d1*=-1
    d2*=-1
if d1+d2 == 0:
    print('inifinity')
elif d1+d2>0:
    print(0)
else:
    a = -d1//(d1+d2)
    b = -d1 % (d1+d2)
    if b:
        print(a*2+1)
    else:
        print(a*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())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    --sa1
    --sa2
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=((-sa1)//(sa2+sa1))*2+1
    if sa1%(sa1+sa2)==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
if d1<0:
    d1*=-1
    d2*=-1
if d1+d2 == 0:
    print('inifinity')
elif d1+d2>0:
    print(0)
else:
    if -d1%(d1+d2):
        print(abs(d1//(d1+d2)*2+1))
    else:
        print(abs(d1//(d1+d2)*2))

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

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

a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
  print ("infinity")
  sys.exit(0)

if a > b:
  a, b = b, a
  ha, hb = hb, ha

gap = b - a
hgap = ha - hb

if hgap < 0:
  print (0)
  sys.exit(0)

ans = 2 * ((hgap + gap-1) // gap) - 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())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    --sa1
    --sa2
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=(-sa1//(sa2+sa1))*2+1
    if sa1%(sa1+sa2)==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())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    --sa1
    --sa2
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=(-sa1//(sa2+sa1)+1)*2-1
    if sa1%(sa1+sa2)==0:
        ans-=1
    print(ans)

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

a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
  print ("infinity")
  sys.exit(0)

if a > b:
  a, b = b, a
  ha, hb = hb, ha

gap = b - a
hgap = ha - hb

if hgap < 0:
  print (0)
  sys.exit(0)

ans = 2 * (hgap // gap) + 1
print (hgap, gap)
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())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    --sa1
    --sa2
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=(-sa1//(sa2+sa1))*2-1
    if sa1%(sa1+sa2)==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())
if a1*t1+a2*t2>=b1*t1+b2*t2:
    a1,a2,b1,b2 = b1,b2,a1,a2
d = b1*t1+b2*t2 - (a1*t1+a2*t2)
if d == 0:
    print('inifinity')
else:
    if (a1*t1 - b1*t1)*2%d ==0:
        print(max(0,((a1*t1 - b1*t1)*2)//d))
    else:
        print(max(0,(a1*t1 - b1*t1)//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 a1*t1+a2*t2>=b1*t1+b2*t2:
    a1,a2,b1,b2 = b1,b2,a1,a2
d = b1*t1+b2*t2 - (a1*t1+a2*t2)
if d == 0:
    print('inifinity')
elif a1*t1<b1*t1:
    print(0)
else:
    if (a1*t1 - b1*t1)*2%d ==0:
        print(((a1*t1 - b1*t1)*2)//d)
    else:
        print((a1*t1 - b1*t1)//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())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    --sa1
    --sa2
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=-(sa1//(sa2+sa1))*2-1
    if sa1%(sa1+sa2)==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())
if a1*t1+a2*t2>=b1*t1+b2*t2:
    a1,a2,b1,b2 = b1,b2,a1,a2
d = b1*t1+b2*t2 - (a1*t1+a2*t2)
if d == 0:
    print('inifinity')

elif a1*t1<b1*t1:
    print(0)
else:
    if (a1*t1 - b1*t1)*2%d ==0:
        print(((a1*t1 - b1*t1)*2+d-1)//d)
    else:
        print((a1*t1 - b1*t1)//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 a1*t1+a2*t2>=b1*t1+b2*t2:
    a1,a2,b1,b2 = b1,b2,a1,a2
d = b1*t1+b2*t2 - (a1*t1+a2*t2)
print(d)
if d == 0:
    print('inifinity')

elif a1*t1<b1*t1:
    print(0)
else:
    if (a1*t1 - b1*t1)*2%d ==0:
        print(((a1*t1 - b1*t1)*2+d-1)//d)
    else:
        print((a1*t1 - b1*t1)//d*2+1)

Submission status: Wrong Answer

Solution code:
s,t,a,b,x,y=map(int,open(0).read().split())
if a*s+b*t==x*s+y*t:
  print('infinity')
  exit()
if a<x:a,b,x,y=x,y,a,b
if a*s+b*t>x*s+y*t:
  print(0)
  exit()
print((a*s-x*s)//(x*s+y*t-(a*s+b*t))*2+1)

Submission status: Wrong Answer

Solution code:
def sign(x):
    if x==0:
        return 0
    else:
        return abs(x)//x
def flag(x,y):
    return sign(x)==sign(y)
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")
    exit()
ans=0
X=(B1-A1)*T1
Y=(B2-A2)*T2

#0+n(X+Y)
#X+n(X+Y)
#nb>0
#a+nb
a=X*sign(X+Y)
b=abs(X+Y)
#print(a,b)
#a+nb<=0なるnの個数ただしnは0以上
#n<=-a/bよりn<=floor(-a/b)
#floor(-a/b)+1
k=(-a)//b+1
if k>0:
    print(2*k-1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def sign(x):
    if x==0:
        return 0
    else:
        return abs(x)//x
def flag(x,y):
    return sign(x)==sign(y)
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")
    exit()
ans=0
X=(B1-A1)*T1
Y=(B2-A2)*T2

#0+n(X+Y)
#X+n(X+Y)
#nb>0
#a+nb
a=X*sign(X+Y)
b=abs(X+Y)
#print(a,b)
#a+nb<=0なるnの個数ただしnは0以上
#n<=-a/bよりn<=floor(-a/b)
#floor(-a/b)+1
print(2*((-a)//b)+1)

Submission status: Wrong Answer

Solution code:
def f():
	from math import ceil
	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
	diff1 = (A1 - B1) * T1
	fac = (B2 - A2) * T2 - diff1
	if fac == 0:
		print("infinity")
	else:
		print(max(0,2 * ceil(diff1 / fac) - 1))
        
f()

Submission status: Wrong Answer

Solution code:
def f():
	from math import ceil
	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
	diff1 = (A1 - B1) * T1
	fac = (B2 - A2) * T2 - diff1
	if fac == 0:
		print("infinity")
	else:
		if B2 < A2:
			print(0)
		elif ceil(diff1 / fac) == 1:
			print(1)
		else:
			print(2 * ceil(diff1 / fac) - 1)

f()

Submission status: Wrong Answer

Solution code:
from math import ceil
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
diff1 = (A1 - B1) * T1
fac = (B2 - A2) * T2 - diff1
if fac == 0:
	print("infinity")
else:
	if diff1 / fac < 0:
		print(0)
	elif diff1 / fac <= 1:
		print(1)
	else:
		print(1 + 2 * ceil((diff1 - fac) / fac))

Submission status: Wrong Answer

Solution code:
from math import ceil
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
diff1 = (A1 - B1) * T1
t = diff1 / (B2 - A2)
fac = (B2 - A2) * (T2 - t)
if fac == 0:
	print("infinity")
else:
	if diff1 / fac < 0:
		print(0)
	elif diff1 / fac <= 1:
		print(1)
	else:
		print(1 + 2 * ceil((diff1 - fac) / fac))

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:
            if (t[1]*b-s[1]*b) % aaa == 0:
                count += 2*((t[1]*b-s[1]*b) // aaa)
            else:
                count += 2*((t[1]*b-s[1]*b) // aaa) + 1
        else:
            if (t[0]*a-s[0]*a) % aaa == 0:
                count += 2*((t[0]*a-s[0]*a) // aaa)
            else:
                count += 2*((t[0]*a-s[0]*a) // aaa) + 1

    else:
        if (s[0]*a - t[0]*a) < 0:
            if (s[0]*a-t[0]*a) % aaa == 0:
                count += 2*((s[0]*a-t[0]*a) // aaa)
            else:
                count += 2*((s[0]*a-t[0]*a) // aaa) + 1
        else:
            if (s[1]*b-t[1]*b) % aaa == 0:
                count += 2*((s[1]*b-t[1]*b) // aaa)
            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())
d1,d2 = (A1-B1)*T1,(A2-B2)*T2
if d1+d2 == 0: print("infinity")
elif abs(d1) > abs(d2): print(0)
elif abs(d1) % abs(d1+d2) == 0: print((abs(d1)//abs(d1+d2))*2)
else: print((abs(d1)//abs(d1+d2))*2+1)

Submission status: Wrong Answer

Solution code:
import math
t1,t2 = map(int, input().split())
c1,c2 = map(int, input().split())
d1,d2 = map(int, input().split())

x = [(c1*t1, c2*t2),(d1*t1, d2*t2)]

x.sort(reverse=True)

if x[0][0]+x[0][1] == x[1][0]+x[1][1]:
    print("infinity")
elif x[0][0]+x[0][1] > x[1][0]+x[1][1]:
    print(0)
else:
    n = (x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1])
    m = math.ceil(n)
    if math.floor(n) == m:
        print(2*m+1)
    else:
        print(2*m-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,d2 = (A1-B1)*T1,(A2-B2)*T2
if d1+d2 == 0: print("infinity")
elif abs(d1) > abs(d2): print(0)
elif abs(d1) % abs(d1+d2) == 0: print(abs(d1)//abs(d1+d2)*2)
else: print(abs(d1)//abs(d1+d2)*2+1)

Submission status: Wrong Answer

Solution code:
import math
t1,t2 = map(int, input().split())
c1,c2 = map(int, input().split())
d1,d2 = map(int, input().split())

x = [(c1*t1, c2*t2),(d1*t1, d2*t2)]

x.sort(reverse=True)

if x[0][0]+x[0][1] == x[1][0]+x[1][1]:
    print("infinity")
elif x[0][0]+x[0][1] > x[1][0]+x[1][1] or x[0][0]==x[1][0]:
    print(0)
else:
    n = math.ceil((x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1]))
    print(2*n-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,d2 = (A1-B1)*T1,(A2-B2)*T2
if d1+d2 == 0: print("infinity")
elif abs(d1) > abs(d2): print(0)
elif abs(d1) % abs(d1+d2) == 0: print(abs(d1//(d1+d2))*2)
else: print(abs(d1//(d1+d2))*2+1)

Submission status: Wrong Answer

Solution code:
import math
t1,t2 = map(int, input().split())
c1,c2 = map(int, input().split())
d1,d2 = map(int, input().split())

x = [(c1*t1, c2*t2),(d1*t1, d2*t2)]

x.sort(reverse=True)

if x[0][0]+x[0][1] == x[1][0]+x[1][1]:
    print("infinity")
elif x[0][0]+x[0][1] > x[1][0]+x[1][1]:
    print(0)
else:
    n = math.ceil((x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1]))
    print(2*n-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 * T1) + (A2 * T2) == (B1 * T1) + (B2 * T2):
    print('infinity')
    exit()
elif (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
    print(0)
    exit()
else:
    if A1 > B1:
        now_lead = 'A'
    else:
        now_lead = 'B'
    
    now_A = A1 * T1
    now_B = B1 * T1

    now_time = 2
    answer = 0

    while True:
        if now_time == 1:
            now_A += A1 * T1
            now_B += B1 * T1
        else:
            now_A += A2 * T2
            now_B += B2 * T2

        if now_lead == 'A':
            if now_A > now_B:
                break
            else:
                answer += 1
                now_lead = 'B'
        elif now_lead == 'B':
            if now_A < now_B:
                break
            else:
                answer += 1
                now_lead = 'A'

        if now_time == 1:
            now_time = 2
        else:
            now_time = 1
    print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 - B1
d2 = A2 - B2
if d1*T1 + d2*T2 == 0: print("infinity")
elif abs(d1*T1) > abs(d2*T2): print(0)
else: print(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:
    print(loop*2 -2)
  else:
    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())

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

if P + Q < 0:
    print(0)
elif P + Q == 0:
    print('infinity')
else:
    S, T = divmod(-P, P+Q)
    if T != 0:
        print(S * 2 + 1)
    else:
        print(S * 2)