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

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

if d1 > 0:
    d1 *= -1
    d2 *= -1

if d1 + d2 == 0:
    print("infinity")
elif d1 + d2 < 0:
    print(0)
else:
    cnt = -d1 // (d1 + d2)
    t = -d1 % (d1 + d2)
    ans = 1 + 2 * cnt + int(t == 0)
    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())

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

e1 = (a1-b1)*t1
e2 = e1 + (a2-b2)*t2
e1, e2 = abs(e1), abs(e2)
if e1%e2:
  print(1+2*(e1//e2))
else:
  print(2*(e1//e2))

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
atot1 = (a1 - b1) * t1
atot2 = atot1 + (a2 - b2) * t2
if atot1 * atot2 > 0:
    print(0)
    exit()
if atot1 == - atot2:
    print('infinity')
    exit()
d1 = abs(atot1)
d2 = abs(atot2)
ma = max(d1, d2)
mi = min(d1, d2)
ans = ma // (ma - mi)
print(ans)

Submission status: Wrong Answer

Solution code:
s,t = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a = a1-b1
b = a2-b2
if a*b>0:print(0);exit()
if abs(a)*s ==abs(b)*t:print('infinity');exit()
elif abs(a)*s >abs(b)*t:print(0);exit()
if int(abs(a)*s//(abs(b)*t-abs(a)*s)):
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2+1)
else:
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2)

Submission status: Wrong Answer

Solution code:
s,t = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a = a1-b1
b = a2-b2
if a*b>0:print(0);exit()
if abs(a)*s ==abs(b)*t:print('infinity');exit()
elif abs(a)*s >abs(b)*t:print(0);exit()
print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*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 and b2==a2:print(0)
elif t1*(a1-b1)+t2*(-b2+a2)==0:print('infinity')
else:
    if t1*(a1-b1)+t2*(-b2+a2)<0:a1,a2,b1,b2=b1,b2,a1,a2
    if t1*(a1-b1)>0:print(0)
    else:
        #(ng,ok]type
        ok,ng=10**40000,-1
        ng,ok=ok,ng
        eps=10**(-8)
        while abs(ok-ng)>1:
            mid=(ok+ng)//2
            if t1*(b1-a1)-mid>=0:ok=mid
            else:ng=mid
        print(2*(mid//(t1*(a1-b1)+t2*(-b2+a2))+1)-1-int(mid==t1*(b1-a1)))

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if a1==b1 and b2==a2:print(0)
elif t1*(a1-b1)+t2*(-b2+a2)==0:print('infinity')
else:
    if t1*(a1-b1)+t2*(-b2+a2)<0:a1,a2,b1,b2=b1,b2,a1,a2
    if t1*(a1-b1)>0:print(0)
    else:
        #(ng,ok]type
        ok,ng=10**40000,-1
        ng,ok=ok,ng
        eps=10**(-8)
        while abs(ok-ng)>1:
            mid=(ok+ng)//2
            if t1*(b1-a1)-mid>=0:ok=mid
            else:ng=mid
        print(2*(mid//(t1*(a1-b1)+t2*(-b2+a2))+1)-1-int(not mid%(t1*(a1-b1)+t2*(-b2+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 A1<B1:
    A1,B1=B1,A1
    A2,B2=B2,A2

if A2>=B2:
    print(0)
else:
    sta=T1*(A1-B1)
    gen=T2*(A2-B2)
    if sta==-gen:
        print("infinity")
    else:
        ans=sta//abs(sta+gen)*2+1
        if sta%abs(sta+gen)==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<B1:
    A1,B1=B1,A1
    A2,B2=B2,A2

if A2>B2:
    print(0)
else:
    sta=T1*(A1-B1)
    gen=T2*(A2-B2)
    if sta==-gen:
        print("infinity")
    else:
        ans=sta//abs(sta+gen)*2+1
        if sta%abs(sta+gen)==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<B1:
    A1,B1=B1,A1
    A2,B2=B2,A2

if A2>B2:
    print(0)
else:
    sta=T1*(A1-B1)
    gen=T2*(A2-B2)
    if sta==-gen:
        print("infinity")
    else:
        ans=sta//abs(sta+gen)*2-1
        if sta%abs(sta+gen)==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==b1 and b2==a2:print(0)
elif t1*(a1-b1)+t2*(-b2+a2)==0:print('infinity')
else:
    if t1*(a1-b1)+t2*(-b2+a2)<0:a1,a2,b1,b2=b1,b2,a1,a2
    if t1*(a1-b1)>0:print(0)
    else:
        #(ng,ok]type
        ok,ng=10**40000,-1
        ng,ok=ok,ng
        eps=10**(-8)
        while abs(ok-ng)>1:
            mid=(ok+ng)//2
            if t1*(b1-a1)-mid>=0:ok=mid
            else:ng=mid
        print(2*(mid//(t1*(a1-b1)+t2*(-b2+a2))+1)-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 and b2==a2:print(0)
elif t1*(a1-b1)+t2*(-b2+a2)==0:print('infinity')
else:
    if t1*(a1-b1)+t2*(-b2+a2)<0:a1,a2,b1,b2=b1,b2,a1,a2
    if t1*(a1-b1)>0:print(0)
    else:
        #(ng,ok]type
        ok,ng=10**10000,-1
        ng,ok=ok,ng
        eps=10**(-8)
        while abs(ok-ng)>1:
            mid=(ok+ng)//2
            if t1*(b1-a1)-mid>=0:ok=mid
            else:ng=mid
        print(2*(mid//(t1*(a1-b1)+t2*(-b2+a2))+1)-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 and b2==a2:print(0)
elif t1*(a1-b1)+t2*(-b2+a2)==0:print('infinity')
else:
    if t1*(a1-b1)+t2*(-b2+a2)<0:a1,a2,b1,b2=b1,b2,a1,a2
    if t1*(a1-b1)>0:print(0)
    else:
        #(ng,ok]type
        ok,ng=10**100,-1
        ng,ok=ok,ng
        eps=10**(-8)
        while abs(ok-ng)>1:
            mid=(ok+ng)//2
            if t1*(b1-a1)-mid>=0:ok=mid
            else:ng=mid
        print(2*(mid//(t1*(a1-b1)+t2*(-b2+a2))+1)-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

t1,t2=nii()
a1,a2=nii()
b1,b2=nii()

time1=t1*a1+t2*a2
time2=t1*b1+t2*b2

if time1==time2:
  print('infinity')
  exit()

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

if a1>b1 and a2<b2:
  if time1>time2:
    print(0)
  else:
    d=t1*(a1-b1)
    sa=time2-time1
    print((d//sa)*2+1)
else:
  if time2>time1:
    print(0)
  else:
    d=t1*(b1-a1)
    sa=time1-time2
    print((d//sa)*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())

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

if T > A:
  if A1 > B1:
    print(0)
    exit()
  else:
    tdif = T-A #7-5
    pdif = T1*(B1-A1) #5
    ans = 2*(1+pdif//tdif)
    if pdif%tdif == 0:
      ans += 1
    ans -=1 #原点の分を引く
else:
  if B1 > A1:
    print(0)
    exit()
  else:
    tdif = A-T #7-5
    pdif = T1*(A1-B1) #5
    ans = 2*(1+pdif//tdif)
    if pdif%tdif == 0:
      ans += 1
    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 T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif T1*A1+T2*A2>T1*B1+T2*B2:
    cnt = 0
    L1 = T1*A1
    L2 = T1*B1
    while L1<=L2:
        cnt += 2
        L1 += T1*A1+T2*A2
        L2 += T1*B1+T2*B2
    print(cnt-1)
elif T1*A1+T2*A2<T1*B1+T2*B2:
    cnt = 0
    L1 = T1*A1
    L2 = T1*B1
    while L1>=L2:
        cnt += 2
        L1 += T1*A1+T2*A2
        L2 += T1*B1+T2*B2
    print(cnt-1)

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif T1*A1+T2*A2>T1*B1+T2*B2:
    cnt = 0
    L1 = T1*A1
    L2 = T2*A2
    while L1<=L2:
        cnt += 1
        L1 = T1*A1+T2*A2
        L2 = T1*B1+T2*B2
    print(cnt)
elif T1*A1+T2*A2<T1*B1+T2*B2:
    cnt = 0
    L1 = T1*A1
    L2 = T2*A2
    while L1>=L2:
        cnt += 1
        L1 = T1*A1+T2*A2
        L2 = T1*B1+T2*B2
    print(cnt)

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(' ')))
n = t1*a1+t2*a2
m = t1*b1+t2*b2
if(n==m):
    print("infinity")
    exit(0)
ans1 = max(0,math.ceil((b1-a1)*t1/(n-m)))
ans2 = max(0,math.ceil((t1*(b1-a1)+t2*(b2-a2))/(n-m))-1)
#if((t1*(b1-a1))%(n-m) == 1):
#    ans3 = 1
#else:
#    ans3 = 0
ans3 = max(0,math.floor(t1*(b1-a1)/(n-m))+1)
print(ans1+ans2+ans3-1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

if not (A1-B1)*(A2-B2)<0:
    print(0)
else:
    if A1<B1:
        A1, B1 = B1, A1
        A2, B2 = B2, A2
    if A1*T1+A2*T2==B1*T1+B2*T2:
        print('infinity')
        exit(0)
    rest = (A1-B1)*T1
    come = (B2-A2)*T2
    if come<rest:
        print(0)
    else:
        ans = come//(come-rest)
        print(ans*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) // (a2 - b2) > 0 or abs(a1 - b1) * t1 > abs(a2 - b2) * t2:
  print(0)
elif abs(a1 - b1) * t1 == abs(a2 - b2) * t2:
  print("infinity")
else:
  d = (abs(a1 - b1) * t1) // (abs(a2 - b2) * t2 - abs(a1 - b1) * t1)
  print(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 - b1) // (a2 - b2) > 0 or abs(a1 - b1) * t1 > abs(a2 - b2) * t2:
  print(0)
elif abs(a1 - b1) * t1 == abs(a2 - b2) * t2:
  print("infinity")
else:
  d, m = divmod(abs(a1 - b1) * t1, abs(a2 - b2) * t2 - abs(a1 - b1) * t1)
  ans = d * 2
  if m > 0:
    ans += 1
  print(ans)

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


Ax = A1 * T1 + A2 * T2
Bx = B1 * T1 + B2 * T2
diff = abs(Ax - Bx)

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

if not ((A1 * T1 > B1 * T1 and Ax < Bx) or (A1 * T1 < B1 * T1 and Ax > Bx)):
    print(0)
    exit()

ans = ceil(2 * (abs(B1 - A1) * T1) / diff)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

# a1 が先行にする
if s1<0:
    s1*=-1
    s2*=-1

d = s1*t1 + s2*t2
mxd = s1*t1

if d>0:
    print(0)
elif d==0:
    print('infinity')
else:
    print(mxd//abs(d)*2+1)

Submission status: Wrong Answer

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

a0,b0 = T[0] * A[0], T[0] * B[0]
a1,b1 = T[1] * A[1], T[1] * B[1]
if a0 < b0:
  a0,b0,a1,b1 = b0,a0,b1,a1
# 常にa0 > b0, a1 < b1
if a0+a1 == b0+b1:
  print("infinity")
  exit(0)
  
if a0<b0 and a1<b1:
  print(0)
elif a0>b0 and a1>b1:
  print(0)
else:
  dff = a0+a1 - b0-b1
  cnt = 1
  for i in range(100000000):
    #print(dff)
    if dff + a0 - b0 >= 0:
      cnt += 1
    else:
      break
    dff += a0 - b0
    #print(dff)
    if dff + a1 - b1 <= 0:
      cnt += 1
    else:
      break
    dff += a1 - b1 
  print(cnt)

Submission status: Wrong Answer

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

a0,b0 = T[0] * A[0], T[0] * B[0]
a1,b1 = T[1] * A[1], T[1] * B[1]
if a0 < b0:
  a0,b0,a1,b1 = b0,a0,b1,a1
# 常にa0 > b0, a1 < b1
if a0+a1 == b0+b1:
  print("infinity")
  exit(0)
  
if a0<b0 and a1<b1:
  print(0)
elif a0>b0 and a1>b1:
  print(0)
else:
  dff = a0+a1 - b0-b1
  cnt = 1
  for i in range(1000000):
    #print(dff)
    if dff + a0 - b0 >= 0:
      cnt += 1
    else:
      break
    dff += a0 - b0
    #print(dff)
    if dff + a1 - b1 <= 0:
      cnt += 1
    else:
      break
    dff += a1 - b1 
  print(cnt)

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 = A1 - B1
C2 = A2 - B2

if C1 * C2 >= 0:
    print(0)

else:
    if C1 < 0:
        C1, C2 = -C1, -C2
    P = T1 * C1
    Q = P + T2 * C2
    if Q > 0:
        print(0)
    elif Q == 0:
        print('infinity')
    else:
        hi = 10**18
        lo = -1
        while hi - lo > 1:
            mid = (hi + lo) // 2
            if Q * mid + P <= 0:
                hi = mid
            else:
                lo = mid
        if P * hi + Q == 0:
            print(hi * 2)
        else:
            print(hi * 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:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2
D1=(A1-B1)*T1
D2=(A2-B2)*T2

if D1==-D2:
    print("infinity")
elif D1*D2>0:
    print("0")
else:
    assert D1>=0 and D2<=0
    diff = abs(D1+D2)
    D1=abs(D1)
    if D1%diff==0:
        print(D1//diff*2+1)
    else:
        print((D1//diff+1)*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:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2
D1=(A1-B1)*T1
D2=(A2-B2)*T2

if D1==-D2:
    print("infinity")
elif D1*D2>0:
    print("0")
else:
    assert D1>=0 and D2<=0
    diff = abs(D1+D2)
    D1=abs(D1)
    if D1%diff==0:
        print(D1//diff*2+1)
    else:
        print(D1//diff*2+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()))


L1 = T1 * (A1- B1)
L2 = L1 + T2 * (A2- B2)

if L1 * L2 > 0:
    print(0)
elif L2 == 0:
    print("infinity")
else:
    M = (-L1) / L2
    ans = 2 * M + 1
    if float(int(M)) == M:
        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()))


L1 = T1 * (A1- B1)
L2 = L1 + T2 * (A2- B2)

if L1 * L2 > 0:
    print(0)
elif L2 == 0:
    print("infinity")
else:
    ans = 2 * ( (-L1) // L2 ) + 1
    print(ans)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
T1,T2 = IL()
A1,A2 = IL()
B1,B2 = IL()
C1,C2 = B1-A1,B2-A2

if C1<0:
  C1,C2 = -C1,-C2

if T1*C1+T2*C2==0:
  print("infinity")
  exit()
elif T1*C1+T2*C2>0:
  print(0)
else:
  x = abs(T1*C1+T2*C2)
  print(T1*C1//x*2+1)

Submission status: Wrong Answer

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    t1,t2 = map(int,ipt().split())
    a1,a2 = map(int,ipt().split())
    b1,b2 = map(int,ipt().split())
    d1 = t1*(a1-b1)
    d2 = t2*(a2-b2)
    if d1*d2 > 0:
        print(0)
    elif d1+d2 == 0:
        print("infinity")
    else:
        dt = d1+d2
        if abs(d1)%abs(dt):
            print(abs(d1)//abs(dt)*2+1)
        else:
            print(abs(d1)//abs(dt)*2)

    return None

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())
c1,c2=a1-b1,a2-b2
if t1*c1+t2*c2==0:
  print('infinity')
else:
  # t1+t2でどれだけ二人が離れるか。
  d=t1*c1+t2*c2
  if c2*d<0:
    print(0)
  elif abs(t2*c2)<abs(d):
    print(0)
  else:
    tmp=((t2*c2)//d)
    print(2*tmp-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())
c1,c2=a1-b1,a2-b2
if t1*c1+t2*c2==0:
  print('infinity')
else:
  # t1+t2でどれだけ二人が離れるか。
  d=t1*c1+t2*c2
  if abs(t2*c2)<d:
    print(0)
  elif c2*d<0:
    print(0)
  else:
    tmp=((t2*c2)//d)
    print(2*tmp-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())
c1,c2=a1-b1,a2-b2
if t1*c1+t2*c2==0:
  print('infinity')
else:
  # t1+t2でどれだけ二人が離れるか。
  d=t1*c1+t2*c2
  ans=2*((t2*c2)//d)-1
  print(ans)

Submission status: Wrong Answer

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

if A1==B1:
    ans="infinity"
elif T1*(A1-B1)+T2*(A2-B2)==0:
    ans="infinity"
elif A1>B1 and A2>=B2:
    ans=0
elif A1<B1 and A2<=B2:
    ans=0
else:
    s = abs(A1-B1)*T1
    t = abs(A2-B2)*T2
    u = abs(s-t)
    ans=(s//u + t//u)

print(ans)

Submission status: Wrong Answer

Solution code:
t1, t2 = (int(x) for x in input().split())
a1, a2 = (int(x) for x in input().split())
b1, b2 = (int(x) for x in 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()

d1 = (a1 - b1) * t1
d2 = (b2 - a2) * t2
k = d1 // (d2 - d1)
print(2 * k + 1)

Submission status: Wrong Answer

Solution code:
# F - Interval Running
T,t = map(int,input().split())
A,a = map(int,input().split())
B,b = map(int,input().split())

if (A<B and a<b) or (A>B and a>b):
    print(0)
else:
    A,B = max(A,B),min(A,B)
    a,b = min(a,b),max(a,b)
    if A*T+a*t==B*T+b*t:
        print('infinity')
    else:
        ra,rb = A*T,B*T
        ans = 0
        while True:
            ra,rb = ra+a*t,rb+b*t
            if ra>rb:
                break
            ans += 1
            ra,rb = ra+A*T,rb+B*T
            if ra<rb:
                break
            ans += 1
        print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580


def solve():
    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 + X2 == 0:
        print("infinity")
        return
    
    P = X1
    cnt = 0
    while True:
        P1 = P + X2
        if(P1*P > 0):
            break
        cnt = cnt + 1
        P2 = P1 + X1
        if(P1*P2 > 0):
            break
        cnt = cnt + 1
        P = P2
    
    print(cnt)

    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
if a1*t1 + a2*t2 == b1*t1 + b2*t2:
    print("infinity")
else:
    A = a1*t1 + a2*t2
    B = b1*t1 + b2*t2
    M1,m1 = max(a1*t1,b1*t1),min(a1*t1,b1*t1)
    M2,m2 = max(A,B),min(A,B)
    gap1,gap2 = M1-m1,M2-m2
    Mv,mv = max(a1,b1),min(a1,b1)
    vgap = Mv-mv
    possible = vgap*t1
    count = possible//gap2
    if (a1*t1 > b1*t1 and A > B) or (a1*t1 < b1*t1 and A < B):
        print(0)
    elif (a1*t1 > b1*t1 and A < B) or (a1*t1 < b1*t1 and A > B):
        print(1+count*2)

Submission status: Wrong Answer

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
INF = -1
def main(T1, T2, A1, A2, B1, B2):
    D1 = T1 * (A1 - B1)
    D2 = D1 + T2 * (A2 - B2)

    if D1 * D2 > 0:
        return 0

    if abs(D1) == abs(D2) or D2 == 0:
        return INF

    return 1 + 2 * int(abs(D1) / abs(D2))


if __name__ == '__main__':
    input = sys.stdin.readline
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    ans = main(T1, T2, A1, A2, B1, B2)
    print(ans if ans >= 0 else 'infinity')

Submission status: Wrong Answer

Solution code:
T1,T2= map(int, input().split())
A1,A2= map(int, input().split())
B1,B2= map(int, input().split())
if A1>B1 and A2>B2:
  print(0)
elif A1<B1 and A2<B2:
  print(0)
elif T1*A1+T2*A2==T1*B1+T2*B2:
  print('infinity')
elif A1>B1 and A2<B2:
  if T1*A1+T2*A2>T1*B1+T2*B2:
    print(0)
  else:
    se=abs(T1*A1+T2*A2-(T1*B1+T2*B2))
    ad=T1*A1-T1*B1
    ans=1
    d=ad//se
    ans+=2*d
    if ad%se==0:
      ans+=1
    print(ans)
elif A1<B1 and A2>B2:
  if T1*A1+T2*A2<T1*B1+T2*B2:
    print(0)
  else:
    se=abs(T1*A1+T2*A2-(T1*B1+T2*B2))
    ad=T1*B1-T1*A1
    ans=1
    d=ad//se
    ans+=2*d
    if ad%se==0:
      ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

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

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

    if a1 * t1 > b1 * t1 and a2 * t2 > b2 * t2:
        print(0)
        exit(0)

    if a1 * t1 < b1 * t1 and a2 * t2 < b2 * t2:
        print(0)
        exit(0)

    tmp = abs(a1 * t1 - b1 * t1)
    tmp2 = abs(a1 * t1 - b1 * t1 + a2 * t2 - b2 * t2)
    ans = 2 * tmp // tmp2
    print(ans if tmp % tmp2 else ans + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

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

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

    if a1 * t1 > b1 * t1 and a2 * t2 > b2 * t2:
        print(0)
        exit(0)

    if a1 * t1 < b1 * t1 and a2 * t2 < b2 * t2:
        print(0)
        exit(0)

    tmp = abs(a1 * t1 - b1 * t1)
    tmp2 = abs(a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2)
    ans = 2*tmp//tmp2
    print(ans if ans != 0 else 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

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

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

    if a1 * t1 > b1 * t1 and a2 * t2 > b2 * t2:
        print(0)
        exit(0)

    if a1 * t1 < b1 * t1 and a2 * t2 < b2 * t2:
        print(0)
        exit(0)

    tmp = abs(a1 * t1 - b1 * t1)
    tmp2 = abs(a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2)
    print(2*(tmp//tmp2)+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())

d1 = T1*(A1-B1)
d2 = T2*(A2-B2)
if d1>d2:
    d1 *= -1
    d2 *= -1

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    if A1 < B1 and A2 < B2:
        print(0)
        return

    if A1 > B1 and A2 > B2:
        print(0)
        return

    if A == B:
        print("infinity")
        return

    # T1 + T2 分後にできる差
    diff = abs(A - B)

    if T1 * abs(A1 - B1) % diff == 0:
        ans = T1 * abs(A1 - B1) // diff * 2
    else:
        ans = T1 * abs(A1 - B1) // diff * 2 + 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    if A1 < B1 and A2 < B2:
        print(0)
        return

    if A1 > B1 and A2 > B2:
        print(0)
        return

    if A == B:
        print("infinity")
        return

    # T1 + T2 分後にできる差
    diff = abs(A - B)

    if T1 * abs(A1 - B1) % diff == 0:
        ans = 2 * T1 * abs(A1 - B1) // diff + 1
    else:
        ans = 2 * T1 * abs(A1 - B1) // diff

    print(ans)


if __name__ == "__main__":
    main()