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 = input().split()
A1,A2 = input().split()
B1,B2 = input().split()

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

import math


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

Submission status: Wrong Answer

Solution code:
t = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

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

ans = 0
for i in range(1000000) :
	if dd > 0 :
		if d0 + i * dd <= 0 :
			ans += 1
	else :
		if d0 + i * dd >= 0 :
			ans += 1

print(2 * ans - 1)

Submission status: Wrong Answer

Solution code:
def main():
    t1,t2=map(int,input().split())
    a1,a2=map(int,input().split())
    b1,b2=map(int,input().split())
    if t1*a1+t2*a2==t1*b1+t2*b2:
        return 'infinity'
    if a1<b1:
        a1,b1=b1,a1
        a2,b2=b2,a2
    if a2>b2:
        return 0
    d1=(a1-b1)*t1
    d2=(b2-a2)*t2
    if d1>d2:
        return 0
    k=d1//(d2-d1)
    return 2*k+1
    
if __name__=='__main__':
    print(main())

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 - 1
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 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)*2)
        else:
            ans = abs(diff1/(diff1+diff2)*2)
        print(int(ans)+int(int(ans)==0))
    

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

Submission status: Wrong Answer

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

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

if d1 + d2 == 0:
    print('infinity')
else:
    a = d1//(d1+d2)
    ans = a*2-1
    print(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:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

df1 = T1*(A1-B1)
df2 = T2*(A2-B2)
now = 0
ans = 0
df3 = df1+df2
if df3 == 0:
    print("infinity")
else:
    if df3 > 0 and df1 > 0:
        ans = 0
    elif df3 < 0 and df1 < 0:
        ans = 0
    else:
        ans += 1
        df3 = abs(df3)
        df1 = abs(df1)
        if df1%df3==0:
            ans = 2*df1//df3
        else:
            ans += 2*int(df1/df3)
    mod = 10**9+7
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
import numpy

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

v1=b1-a1
v2=b2-a2

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

Submission status: Wrong Answer

Solution code:
import fractions
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
aa=[0]
bb=[0]
cc=[]
for i in range(200):
    if i%2==0:
        aa.append(aa[-1]+t1*a1);bb.append(bb[-1]+t1*b1)
    else:
        aa.append(aa[-1]+t2*a2);bb.append(bb[-1]+t2*b2)
    cc.append(aa[-1]-bb[-1])
#print(aa)
#print(bb)
#print(cc)
if cc[0]<=0:
    if cc[0]-cc[2]:
        ans=cc[0]//(cc[0]-cc[2])
        print(2*ans+1)
    else:
        print('infinity')
elif cc[1]<=0:
    if cc[1]-cc[3]:
        ans=cc[1]//(cc[1]-cc[3])
        print(2*ans+1)
    else:
        print('infinity')
else:
    print('infinity')

Submission status: Wrong Answer

Solution code:
time_1, time_2 = map(int, input().split())
speed_a_1, speed_a_2 = map(int, input().split())
speed_b_1, speed_b_2 = map(int, input().split())

delta_1 = (speed_a_1 - speed_b_1) * time_1
delta_2 = (speed_a_2 - speed_b_2) * time_2

if delta_1 == (-delta_2):
    print("infinity")
    exit(0)

if (delta_1 > 0 and delta_2 > 0) or (delta_1 < 0 and delta_2 < 0):
    print("0")
    exit(0)

i = 0
d = 0
while True:
    d1 = d + delta_1
    if (d1 > 0 > d) or (d1 < 0 < d):
        i += 1
        d = d1
    else:
        break

    d2 = d + delta_1
    if (d2 > 0 > d) or (d2 < 0 < d):
        i += 1
        d = d2
    else:
        break

print(i)

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

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

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

if A1+A2 == B1+B2:
    print("infinity")
    exit()

def nibu(l,r):
    if l >= r:
        return l
    c = (l+r+1)//2
    if (A1+A2)*(c-1)+A1 >= (B1+B2)*(c-1)+B1:
        return nibu(c,r)
    else:
        return(nibu(l,c-1))

ans = nibu(0,10**100)
if (A1+A2)*(ans-1)+A1 == (B1+B2)*(ans-1)+B1:
    print(ans*2-2)
else:
    print(ans*2-1)

Submission status: Wrong Answer

Solution code:
t = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

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

ans = 0
for i in range(100000) :
	if dd > 0 :
		if d0 + i * dd <= 0 :
			ans += 1
	else :
		if d0 + i * dd >= 0 :
			ans += 1

print(2 * ans - 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())

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

count = 0
a1 = A1 * T1
b1 = B1 * T1
while True:
  a2 = a1 + T2 * A2
  b2 = b1 + T2 * B2
  if (a1 > b1) != (a2 > b2):
    count += 1
  a1 = a2 + T1 * A1
  b1 = b2 + T1 * B1
  if (a1 > b1) != (a2 > b2):
    count += 1
  if ((a1 < b1) and (a2 < b2)) or ((a1 > b1) and (a2 > b2)):
    break
print(count)

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

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()
else:
  flg=True
  i=0
  th=0
  f='a' if A[0]*T[0]>B[0]*T[0] else 'b'
  ans=0
  Ax=0
  Bx=0
  while flg:
    Ax=A[i]*T[i]+Ax
    Bx=B[i]*T[i]+Bx
    fn='a' if Ax>Bx else 'b'
    if fn!=f:
      f=fn
      ans+=1
      th=0
    else:
      th+=1
    i+=1
    i%=2
    if th>100:
      flg=False
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import 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('infinity')
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())

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)
times = ((a1*t1) - (b1*t1)) / diff
ans = -((-((a1*t1) - (b1*t1))) // diff)
print(ans * 2 - 1)

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

m1 = a1*t1 + a2*t2
m2 = b1*t1 + b2*t2

if m1 == m2:
    print('infinity')
else:
    x = t1 + t2 - (m2-m1)/(b2-a2)

    y = b2*(x-t1-t2) + m2
    y = (a2*m2-b2*m1)/(a2-b2)
    print(floor(abs(t1*a1-t1*b1)/abs(m1-m2))*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:
  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))*2-1)

Submission status: Wrong Answer

Solution code:
import fractions
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
aa=[0]
bb=[0]
cc=[]
for i in range(200):
    if i%2==0:
        aa.append(aa[-1]+t1*a1);bb.append(bb[-1]+t1*b1)
    else:
        aa.append(aa[-1]+t2*a2);bb.append(bb[-1]+t2*b2)
    cc.append(aa[-1]-bb[-1])
#print(aa)
#print(bb)
#print(cc)
if cc[0]<=0:
    if cc[0]-cc[2]:
        ans=cc[0]//(cc[0]-cc[2])
        print(2*ans+1)
    else:
        print('infinity')
elif cc[1]<=0:
    if cc[1]-cc[3]:
        ans=cc[1]//(cc[1]-cc[3])
        print(2*ans+1)
    print('infinity')
else:
    print('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())
i=0
cnt=0
sa=0
m=A1*T1+A2*T2-B1*T1-B2*T2
if m==0:
  print("infinity")
  exit()
while i>-1:
  sa+=T1*(A1-B1)
  if sa/(B2-A2)<T2 and sa/(B2-A2)>0:
    cnt+=1
  else:
    break
  sa+=T2*(A2-B2)
  if sa/(B1-A1)<T1 and sa/(B1-A1)>0:
    cnt+=1
  else:
    break
  i+=1
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())

A_pos,B_pos = A1*T1,B1*T1
if A1*T1+A2*T2 == B1*T1+B2*T2: print("infinity")
else:
  n = 1
  N = 0
  f = True
  while True:
    if n%2 == 1:
      t = (B_pos - A_pos) / (A2 - B2)
      if t < T2: N+=1
      elif f:
        print(N)
        break
      else: f = True
      A_pos += A2*T2
      B_pos += B2*T2
      n+=1
    else:
      t = (B_pos - A_pos) / (A1 - B1)
      if t < T1: N+=1
      elif f:
        print(N)
        break
      else: f = True
      A_pos += A1*T1
      B_pos += B1*T1
      n+=1

Submission status: Wrong Answer

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

input = sys.stdin.readline

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

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

Submission status: Wrong Answer

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

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

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

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


    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- 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)<0 and (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:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

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


# print(T1 * A1 + T2 * A2)
# print(T1 * B1 + T2 * B2)

diff_dis = abs((T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2))
min_dis = min((T1 * A1 + T2 * A2),(T1 * B1 + T2 * B2))
if diff_dis == 0:
    print("infinity")
    sys.exit(0)

if A1 > B1 and A2 > B2 or A1 < B1 and A2 < B2:
    print(0)
    sys.exit(0)
set_cnt = math.ceil(min_dis / diff_dis)

# for i in range(set_cnt + 1):
#     if (max(A1, B1) - min(A1, B1)) * T1 > diff_dis * i:
#         ans += 2
if A1 < B1:
    ans = math.ceil((max(A1, B1) - min(A1, B1)) * T1 / diff_dis) * 2
else:
    ans = math.ceil((max(A2, B2) - min(A2, B2)) * T1 / diff_dis) * 2
print(ans -1)

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(100000-1):
    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
  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
from math import floor

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

diff1 = (a1 - b1) * t1
diff2 = (a2 - b2) * t2
diff = diff1 + diff2

if diff1 * diff > 0:
    print("0")

elif diff == 0:
    print("infinity")

else:
    diff1 = abs(diff1)
    diff2 = abs(diff2)
    n = diff2 / (diff2 - diff1)

    if n == floor(n):
        n = floor(n)
        ans = 2 * n - 3
    else:
        n = floor(n)
        ans = 2 * n - 1

    print(ans)

Submission status: Wrong Answer

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

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

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

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

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

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

    print(ans*2+1)

    # calc


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 = (A1 - B1) * T1
d2 = d1 + (A2 - B2) * T2
if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
    print(0)
    exit()
if d2 == 0:
    print('infinity')
    exit()
d1 = abs(d1)
d2 = abs(d2)
if d1 % d2 == 0:
    print(d1, d2)
    print(d1 // d2 * 2)
else:
    print(1 + 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 and c2>0):
	print("0")
	sys.exit()


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


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

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*diff2 <= diff else (x-1) * 2)

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)+1:
            break
    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())
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('Infinity')
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 = 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
if (A1*T1+A2*T2)*(high-1)+A1*T1==(B1*T1+B2*T2)*(high-1)+B1*T1:
    print(high*2-2)
else:
    print(high*2-1)

Submission status: Wrong Answer

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

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


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

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

if p1 + p2 == 0:
    print('infinity')
    sys.exit()

if p1 + p2 < 0:
    p1 *= -1
    p2 *= -1

if p1 > 0:
    print(0)
    sys.exit()

print(int((-1 * p1) / (p1+p2)) * 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 + 1
else:
    if not tmp[0][0] % (tmp[0][0] - tmp[1][0]):
        ans -= 1

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


print(max(ans,1))

Submission status: Wrong Answer

Solution code:
t1, t2 = [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
    else:
        return a//b+1


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()
    print(waru(first1 - first2, -c) * 2 - 1)
else:
    if c < 0:
        print(0)
        exit()
    print(waru(first2 - first1, c) * 2 - 1)

Submission status: Wrong Answer

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

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

    if dist1 > dist2:
        a = a1*t1
        b = a2*t2
        c = b1*t1
        d = b2*t2
    else:
        a = b1*t1
        b = b2*t2
        c = a1*t1
        d = a2*t2
    
    m = (c-a) // (a+b-c-d)
    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())

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

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

if A1+A2 == B1+B2:
    print("infinity")
    exit()

sa = -(A1+A2) + (B1+B2)
a = (A1-B1)//sa + int((A1-B1)%sa > 0)
ans = a*2-1
if (A1-B1)%sa == 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()]


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

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:
import numpy

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

v1=b1-a1
v2=b2-a2
#print(v1,v2)
x1=v1*t1
x2=v2*t2
#print(x1,x2)
if numpy.sign(x1)==numpy.sign(x2):
    #print("one")
    print(0)
elif abs(x2)<abs(x1):
    #print("two")
    print(0)
elif abs(x1)==abs(x2):
    print("infinity")
else:
    #print("hello")
    #print(x1,2*(abs(x2)-abs(x1)))
    di = abs(x2)-abs(x1)
    print(2*(x1//di)+1)