Problem:


Score: 600 points

Problem Statement

Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.

They start simultaneously at the same point and moves as follows towards the east:

Takahashi runs A_1 meters per minute for the first T_1 minutes,  then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

Aoki runs B_1 meters per minute for the first T_1 minutes,  then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

Print the number of times Takahashi and Aoki will meet each other.

If they meet infinitely many times, print infinity instead.  

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start.

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times.

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

The values in input may not fit into a 32-bit integer type.



Sample input:
1 2
10 10
12 4


Sample output:
1

Submission status: Wrong Answer

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if t[0]*a[0]+t[1]*a[1]==t[0]*b[0]+t[1]*b[1]:
  print("infinity")
else:
  if t[0]*a[0]>t[0]*b[0]:
    if t[0]*a[0]+t[1]*a[1]>t[0]*b[0]+t[1]*b[1]:
      print(0)
    else:
      d=(t[0]*b[0]+t[1]*b[1])-(t[0]*a[0]+t[1]*a[1])
      c=t[0]*a[0]-t[0]*b[0]
      if c//d==0:
        print(c//d*2)
      else:
        print(c//d*2+1)
  else:
    if t[0]*a[0]+t[1]*a[1]<t[0]*b[0]+t[1]*b[1]:
      print(0)
    else:
      d=(t[0]*a[0]+t[1]*a[1])-(t[0]*b[0]+t[1]*b[1])
      c=t[0]*b[0]-t[0]*a[0]
      if c//d==0:
        print(c//d*2)
      else:
        print(c//d*2+1)

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
a=t1*a1+t2*a2
b=t1*b1+t2*b2
if a==b:
    print('infinity')
    exit()
if a>b:
    if a1>b1:
        print(0)
    else:
        m=b1-a1
        k=m*t1
        p=a-b
        print(-1-(-k//p)*2)
if a<b:
    if a1<b1:
        print(0)
    else:
        m=a1-b1
        k=m*t1
        p=b-a
        print(-1-(-k//p)*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())

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

d = abs(A1*T1+A2*T2 - B1*T1-B2*T2)
L = abs(A1-B1)*T1
# print(d, L)

ans = 0
if L % d == 0:
    print(L//d*2)
    exit()
else:
    ans = L//d*2+1
    # if d*L//d <= L:
    #     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 (b1 - a1) * t1 == (a2 - b2) * t2:
    print("infinity")
    import sys
    sys.exit()

p1 = (b1 - a1) * t1 
p2 = (b1 - a1) * t1 + (b2 - a2) * t2

if p1 * p2 > 0:
    print(0)
    import sys
    sys.exit()

import math

print(2*math.ceil(abs(p1)/abs((p2)))-1)

Submission status: Wrong Answer

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

T = t1*(a1-b1)+t2*(a2-b2)
if T == 0:
    print('infinity')
    exit()
else:
    n = (b1-a1)/T*t1
    m = ((b2-a1)*t1+(b1-b2)*t1)/T
    print(math.floor(n)+math.ceil(m))

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
a=t1*a1+t2*a2
b=t1*b1+t2*b2
if a==b:
    print('infinity')
    exit()
if a>b:
    if a1>b1:
        print(0)
    else:
        m=b1-a1
        k=m*t1
        p=a-b
        print(1-(-k//p)*2)
if a<b:
    if a1<b1:
        print(0)
    else:
        m=a1-b1
        k=m*t1
        p=b-a
        print(1-(-k//p)*2)

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 a1*t1 + a2*t2 == b1*t1+b2*t2:
    print("infinity")
    exit()
if (a1-b1)*(a2-b2) > 0:
    print(0)
    exit()

if a1*t1 + a2*t2 - (b1*t1+b2*t2) > 0:
    x = t1*(b1-a1)/(t1*(a1-b1)+t2*(a2-b2))
    n = ceil(x)
    if n == x:
        print(2*n)
    else:
        print(2*n-1)
else:
    x = t1 * (a1 - b1) / (t1 * (a1 - b1) + t2 * (a2 - b2))
    n = ceil(x)
    if n == x:
        print(2*n)
    else:
        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())

delta1 = A1 - B1
delta2 = A2 - B2

d = delta1 * T1 + delta2 * T2
T = T1 + T2

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

if delta1 * delta2 > 0:
    print(0)
    exit()

#a = T1 * (T * delta1 - d) / T
Ta = T1 * (T * delta1 - d)
# t0 = a * (-1) * T / d
t0 = Ta * (-1) / d

Tnum = int((t0 - T1) // T)
ans = 2 * Tnum + 1

dt0 = Ta * (-1)

#if t0 == Tnum * T + T1:
if dt0 == d * (Tnum * T + T1):
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [t[0] * a[0] + t[1] * a[1], t[0] * b[0] + t[1] * b[1]]
if d[0] == d[1]:
	print('infinity')
	exit(0)
if d[0] > d[1]:
	a, b = b, a
	d[0], d[1] = d[1], d[0]
if a[0] < b[0]:
	print(0)
	exit(0)

l, r = 1, 1000000000000000  # номер периода, с которого пересечений не будет
while l < r:
	mid = (l + r) >> 1
	offset = d[1] * mid - d[0] * mid
	if t[0] * a[0] >= offset + t[0] * b[0]:
		l = mid + 1
	else:
		r = mid
print(l * 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=t1*a1+t2*a2
b=t1*b1+t2*b2
if a==b:
    print('infinity')
    exit()
if a>b:
    if a1>b1:
        print(0)
    else:
        m=b1-a1
        k=m*t1
        p=a-b
        print(1+(k//p)*2)
if a<b:
    if a1<b1:
        print(0)
    else:
        m=a1-b1
        k=m*t1
        p=b-a
        print(1+(k//p)*2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
#import numpy as np

# なんこか入力
a,b = map(int, input().split())
# なんこか入力
c,d = map(int, input().split())
# なんこか入力
e,f = map(int, input().split())

p = (e-c)*a
q = (f-d)*b
#print(p,q)
if p*q >0 or p*(p+q)>0:
    print("0")
elif p == -q:
    print("infinity")
else:
    print(-p//(p+q)*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())

d1=t1*a1+t2*a2
d2=t1*b1+t2*b2

import sys
if d1>d2:
    dif=d1-d2
    gap=(b1-a1)*t1
elif d1<d2:
    dif=d2-d1
    gap=(a1-b1)*t1
else:
    print('infinity')
    sys.exit()

if (b1-a1)*(b2-a2)>0:
    print(0)
    sys.exit()
if gap%dif!=0:
    print(gap//dif*2+1)
else:
    print(gap//dif*2)

Submission status: Wrong Answer

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


def waru(a, b):
    a = max(0, a)
    if b < 0:
        return 0
    if a % b == 0:
        return a // b+1
    else:
        return a//b+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:

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

if A1 + A2 == B1 + B2:
    print('infinity')
elif A1 + A2 < B1 + B2:
    print(0)
else:
    def check(c):
        return c * (A1 + A2) + A1 > c * (B1 + B2) + B1
    
    l = 0
    h = 1000* B1 + B2
    while l < h:
        mid = l + (h - l) // 2
        if check(mid):
            h = mid
        else:
            l = mid + 1
            
    print(2*l-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 a1 < b1:
        a1, b1 = b1, a1
        a2, b2 = b2, a2
    # now a1 >= b1
    if a2 > b2:
        print('0')
        return

    div = (a1 - b1) * t1 + (a2 - b2) * t2
    ans = (b1 - a1) * t1

    if div == 0:
        print('infinity')
        return
    else:
        print(2 * (ans // div) + 1)
        return

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

X1 = T1 * A1
X2 = T2 * A2
Y1 = T1 * B1
Y2 = T2 * B2

if X1 + X2 == Y1 + Y2:
	print("infinity")
else:
	if X1 < Y1:
		X1, X2, Y1, Y2 = [Y1, Y2, X1, X2]
	
	D = (Y1 + Y2) - (X1 + X2)
	if D < 0:
		print("0")
	else:
		if (X1 - Y1) % D == 0:
			print(((X1 - Y1) // D) * 2 - 1)
		else:
			print(((X1 - Y1) // D) * 2 + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
#import numpy as np

# なんこか入力
a,b = map(int, input().split())
# なんこか入力
c,d = map(int, input().split())
# なんこか入力
e,f = map(int, input().split())

p = (e-c)*a
q = (f-d)*b
print(p,q)
if p*q >0 or p*(p+q)>0:
    print("0")
elif p == -q:
    print("infinity")
else:
    print(-p//(p+q)*2+1)

Submission status: Wrong Answer

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


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


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


print(first1, first2, c)
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 meet(faster, slower):
  if slower[0] - faster[0] < 0:
    print(0)
  else:
    print(2 * (slower[0] - faster[0]) // (faster[1] - slower[1]) + 1)

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

at1 = a1 * t1
at2 = a2 * t2
bt1 = b1 * t1
bt2 = b2 * t2

if at1 + at2 < bt1 + bt2:
  faster = [bt1, bt1 + bt2]
  slower = [at1, at1 + at2]
  meet(faster, slower)
elif at1 + at2 > bt1 + bt2:
  faster = [at1, at1 + at2]
  slower = [bt1, bt1 + bt2]
  meet(faster, slower)
else:
  print('infinity')

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
if (c>e and d>f) or (c<e and d<f):
    print(0)
else:
    if c<e:
        c,d,e,f=e,f,c,d
    s=(c-e)*a
    t=(f-d)*b
    if s>t:
        print(0)
    elif s==t:
        print("infinity")
    else:
        print(int((s+t)/(t-s))-1-(1 if (s+t)%(t-s)==0 else 0))

Submission status: Wrong Answer

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

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

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

_b1 = b1 - a1
_a2 = a2 - b2

v1 = t1*_b1
v2 = t2*_a2

if v1 == v2:
    print('infinity')
    exit()

if v1 > v2:
    print(0)
    exit()

d = v2 - v1
k = v1 // d
print(k*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")
else:
  if (a1-b1)*(a2-b2)>0:print(0)
  else:
    if a1>b1:
      firstD=t1*(a1-b1)
      secondD=t2*(b2-a2)
      lead=secondD-firstD
    else:
      firstD=t1*(b1-a1)
      secondD=t2*(a2-b2)
      lead=secondD-firstD
    if lead<0:print(0);exit()
    if firstD<lead:print(1);exit()
    if firstD%lead==0:
      print((firstD//lead+1)*2)
    else:print((firstD//lead+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())

d1=t1*a1+t2*a2
d2=t1*b1+t2*b2

import sys
if d1>d2:
    dif=d1-d2
    gap=(b1-a1)*t1
elif d1<d2:
    dif=d2-d1
    gap=(a1-b1)*t1
else:
    print('infinity')
    sys.exit()

if dif*gap<0:
    print(0)
    sys.exit()
print(gap//dif*2+1)

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*t1+a2*t2==b1*t1+b2*t2:
  print("infinity")
  exit()

#print(a1*t1,a2*t2)
#print(b1*t1,b2*t2)
term = [0]*2
term[0] = a1*t1-b1*t1
term[1] = a2*t2-b2*t2
su = 0
for i in range(10**8):
  t = i%2
  if su < 0:
    c = 0
  else:
    c = 1
  su += term[t]
  if su < 0 and c == 0 and i != 0:
    print(i-1)
    exit()
  elif su > 0 and c == 1 and i != 0:
    print(i-1)
    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())
dist_lap1 = T1 * A1 + T2 * A2
dist_lap2 = T1 * B1 + T2 * B2
if dist_lap1 == dist_lap2:
    print("infinity")
else:
    if dist_lap1 > dist_lap2:
        diff = T1 * B1 - T1 * A1
        if diff < 0:
            print(0)
        else:
            print((diff // (dist_lap1 - dist_lap2)) * 2 + 1)
    else:
        diff = T1 * A1 - T1 * B1
        if diff < 0:
            print(0)
        else:
            print((diff // (dist_lap2 - dist_lap1)) * 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())

s1=a1*t1+a2*t2
s2=b1*t1+b2*t2
ts=t1+t2
if s1==s2:
    print("infinity")
    exit()
faster=1 if s1>s2 else 2

if (a1>b1 and faster==1) or ((a1<b1) and faster==2):
    print(0)
    exit()

if faster==2:
    a1,b1=b1,a1
    a2,b2=b2,a2

d=abs(s1-s2)
cnt=(a2*t2-b2*t2)//d
print(cnt*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()))
A1 = A[0]*T[0]
A2 = A[1]*T[1]
B1 = B[0]*T[0]
B2 = B[1]*T[1]
D1 = A1-B1
D2 = A2-B2
if D1*D2>0:
    output = "infinity"
elif (D1==0)and(D2==0):
    output = "infinity"
elif D1+D2==0:
    output = "infinity"
else:
    Z = abs(D1+D2)
    M = max(abs(D1),abs(D2))
    output = max((M//Z)*2-1,0)
print(output)

Submission status: Wrong Answer

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


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


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


print(first1, first2, c)
if c == 0:
    print("infinity")
    exit()

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

Submission status: Wrong Answer

Solution code:
t1,t2,a1,a2,b1,b2=map(int,open(0).read().split())
w,x,y,z=t1*a1,t2*a2,t1*b1,t2*b2
if w+x==y+z:
	print("infinity")
	exit()
if (w-y)*(w+x-y-z)>0:
	print(0)
	exit()
print(2*((max(w,y)-min(w,y))//(max(w+x,y+z)-min(w+x,y+z)))+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 > B1:
    A1, A2, B1, B2 = B1, B2, A1, A2

if A1 + A2 == B1 + B2 or A1 == B1:
    print('infinity')
elif A1 + A2 < B1 + B2:
    print(0)
else:
    def check(c):
        return c * (A1 + A2) + A1 > c * (B1 + B2) + B1
    
    l = 0
    h = 1000*(B1 + B2)
    while l < h:
        mid = l + (h - l) // 2
        if check(mid):
            h = mid
        else:
            l = mid + 1
            
    print(2*l-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    t1, t2 = mi()
    a1, a2 = mi()
    b1, b2 = mi()
    aoki = 0
    taka = 0
    meetF = False
    meetS = False
    # a の方が速くなるようにスワップ
    if t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2:
        x1, x2 = a1, a2
        a1, a2 = b1, b2
        b1, b2 = x1, x2
    # print(a1, a2, b1, b2)
    if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
        exit("infinity")
    if a1 > b1:
        meetF = False
    else:
        meetF = True
    # 1区間目も2区間目もaの法が速いなら合うことはない
    if not meetF:
        exit("!")
    sa = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2  # 1区切りごとにＡが速く，付いてしまう差
    # print(sa)
    # 何区切りすると追いつけない差になってしまうか
    ng = 10**18
    ok = 0
    while(ng - ok > 1):
        mid = (ng + ok) // 2
        # シミュレーション（mid区切りのあと追いつけるか）
        a = 0
        b = -mid * sa
        if(a + t1 * a1 < b + t1 * b1):
            ok = mid
        else:
            ng = mid
    exit(2 * ok + 1)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import floor,ceil
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

def f(t):
    if t<=T1:
        return (A1-B1)*t/((B1-A1)*T1+(B2-A2)*T2)
    else:
        return ((A1-B1)*T1+(A2-B2)*(t-T1))/((B1-A1)*T1+(B2-A2)*T2)

ans = 0
if ((B1-A1)*T1+(B2-A2)*T2) == 0 or A1==B1:
    ans = 'infinity'
else:
    if f(T1)>0:
        ans += floor(f(T1))
        if f(T1+T2)>0:
            ans += floor(max(f(T1),f(T1+T2)))-ceil(min(f(T1),f(T1+T2)))+1
        else:
            ans += floor(f(T1))+1
    else:
        if f(T1+T2)>0:
            ans += floor(f(T1+T2))+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

div = (a1 - b1) * t1 + (a2 - b2) * t2
ans = (b1 - a1) * t1

if div == 0:
    print('infinity')
else:
    print(2 * (ans // div) + 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
cont = True
flag = False
bigger = 0
ans = 0
while cont:
    A += t[0]*a[0]
    B += t[0]*b[0]
    #print(A,B)
    if flag:
        if A > B:
            if bigger == 2:
                ans += 1
            else:
                cont = False
            bigger = 1

        else:
            if bigger == 1:
                ans += 1
            else:
                cont = False
            bigger = 2

    else:
        flag = True
        if A > B:
            bigger = 1
        else:
            bigger = 2

    A += t[1]*a[1]
    B += t[1]*b[1]
    #print(A,B)

    if A > B:
        if bigger == 2:
            ans += 1
        else:
            cont = False
        bigger = 1

    elif B > A:
        if bigger == 1:
            ans += 1
        else:
            cont = False
        bigger = 2

    elif A == B:
        print('infinity')
        exit(0)
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())
a,b,c,d=T1*A1,T1*B1,T2*A2,T2*B2
if a+c==b+d:
    print('infinity')
else:
    if (a-b)*(c-d)>0:
        print(0)
    else:
        x,y=abs(a-b),abs(a+c-b-d)
        if x%y==0:
            print(x//y*2)
        else:
            print(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())
c1,c2 = b1-a1,b2-a2
d = t1*c1 + t2*c2
if d == 0:
  print('infinity')
elif c1 * c2 > 0:
  print(0)
else:
  top = abs(c1) * t1
  d = abs(d)
  #print(top,d)
  if top % d != 0:
    print(top//d*2+1)
  else:
    print(top//d*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 > B1:
    A1, A2, B1, B2 = B1, B2, A1, A2

if A1 + A2 == B1 + B2 or A1 == B1:
    print('infinity')
elif A1 + A2 < B1 + B2:
    print(0)
else:
    def check(c):
        return c * (A1 + A2) + A1 > c * (B1 + B2) + B1
    l = 0
    h = B1 + B2
    while l < h:
        mid = l + (h - l) // 2
        if check(mid):
            h = mid
        else:
            l = mid + 1
            
    print(2*l-1)

Submission status: Wrong Answer

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

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

if d1 > 0 and d2 > 0:
    print(0)
    exit()
if d1 < 0 and d2 < 0:
    print(0)
    exit()
if abs(d1) > abs(d2):
    print(0)
    exit()
d = abs(abs(d1) - abs(d2))
if d == 0:
    print("infinity")
    exit()

n = math.ceil(d1 / d)
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())

a1 = T1 * A1
a2 = T2 * A2
a = a1 + a2
b1 = T1 * B1
b2 = T2 * B2
b = b1 + b2


def bis(p, ok, ng):
    mid = (ok + ng) // 2
    return (
        ok if abs(ok - ng) == 1 else
        bis(p, mid, ng) if p(mid) else
        bis(p, ok, mid)
    )


def p(k):
    x = k * a
    y = k * b
    # print(f"k: {k}, x: {x}, y: {y}")
    #print(f"k: {k}, x+: {x + a1}, y+: {y + b1}")
    if x < y:
        return x + a1 >= y + b1
    else:
        return y + b1 >= x + a1


def p2(k):
    x = k * a + a1
    y = k * b + b1
    if x < y:
        return x + a2 >= y + b2
    else:
        return y + b2 >= x + a2

if a == b:
    ans = "infinity"
else:
    # print(bis(p, 0, 10**16))
    # print(bis(p2, 0, 10**16))
    ans = bis(p, 0, 10**16) + bis(p2, -1, 10**16) + 1

print(ans)

# print('-------')

# x = 0
# y = 0
# for i in range(114):
#     x += a1
#     y += b1
#     #print(x, y)
#     print(f"{i} {x < y}")
#     x += a2
#     y += b2
#     print(f"{i} {x < y}")
#     #print(x, y)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

da1 = a1*t1
da2 = da1 + a2*t2
db1 = b1*t1
db2 = db1 + b2*t2

if da2==db2:
	ans = 'infinity'
else:
	if (da1-db1)*(da2-db2)>0:
		ans = 0
	else:
		fdif = abs(da1-db1)
		sdif = abs(da2-db2)
		ans = (fdif//sdif)*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())

X1A = A1 * T1
X2A = X1A + B1 * T2
X1B = A2 * T1
X2B = X1B + B2 * T2

ans = 0
if X2A == X2B:
    print("infinity")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
dist_lap1 = T1 * A1 + T2 * A2
dist_lap2 = T1 * B1 + T2 * B2
if dist_lap1 == dist_lap2:
    print("infinity")
else:
    if dist_lap1 > dist_lap2:
        diff = T1 * B1 - T1 * A1
        print((diff // (dist_lap1 - dist_lap2)) * 2 + 1)
    else:
        diff = T1 * A1 - T1 * B1
        print((diff // (dist_lap2 - dist_lap1)) * 2 + 1)

Submission status: Wrong Answer

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

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

q = a1*t1-b1*t1
w = (b1*t1+b2*t2) - (a1*t1+a2*t2)
k = -(-q//w)
ans = 2*k-1
if q%w == 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 -= B1
A2 -= B2
if A1 < 0:
    A1 *= -1
    A2 *= -1

if A1*T1 > -A2*T2:
    print(0)
elif A1*T1 == -A2*T2:
    print("infinity")
else:
    dx = -A2*T2 -A1*T1
    ans = (A1*T1)//dx *2 +1
    if (A1*T1)%dx == 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 A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2:
    print (0)
    exit()
if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
    print ('infinity')
    exit()

mae = (A1 - B1) * T1 #A君が追いつける距離
ushiro = (B2 - A2) * T2
cicle = ushiro - mae #一回のサイクルでトータル離れる距離
# print (mae)
# print (ushiro)

count = mae // cicle * 2 + 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())
v1 = [a1,b1]
v2 = [a2,b2]
d = a1*t1 + a2*t2 - b1*t1 - b2*t2
if d == 0:
  print("infinity")
  exit()
if d > 0:
  f = 0
  s = 1
else:
  f = 1
  s = 0
l = t1*(v1[s]-v1[f])
if l < 0:
  print(0)
  exit()
if l == 0:
  print(1)
  exit()
tm = l//d
if l%d == 0:
  print(2*tm)
else:
  print(1+2*tm)

Submission status: Wrong Answer

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

X1 = T1 * A1
X2 = T2 * A2
Y1 = T1 * B1
Y2 = T2 * B2

if X1 + X2 == Y1 + Y2:
	print("infinity")
else:
	if X1 < Y1:
		X1, X2, Y1, Y2 = [Y1, Y2, X1, X2]
	
	D = (Y1 + Y2) - (X1 + X2)
	if D < 0:
		print("0")
	else:
		print(((X1 - Y1) // 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())

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


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


if A1 + A2 < B1 + B2:
    A1, A2, B1, B2 = B1, B2, A1, A2
D = (A1 + A2) - (B1 + B2)
Remain = B1 - A1
print(Remain // D * 2 + 1)

Submission status: Wrong Answer

Solution code:

import sys
T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())
a1, b1 = T1*A1, T1*B1
a2, b2 = T2*A2, T2*B2
sa, sb = a1+a2, b1+b2
if sa==sb:
    print("infinity")
    exit()
if sa < sb:
    a1, a2, b1, b2, sa, ab = b1, b2, a1, a2, sb, sa

# 2*n-1 回以上出会うか
ok = 0
ng = 10**1800
a = 0
while ok+1 < ng:
    c = (ok+ng)//2
    if (c-1)*sa+a1 <= (c-1)*sb+b1:
        if (c - 1) * sa + a1 == (c - 1) * sb + b1:
            a = -1
        ok = c
    else:
        ng = c
if ok > 10**1799:
    print("infinity")
else:
    print(max(ok*2-1+a, 0))

Submission status: Wrong Answer

Solution code:

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

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

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

if A1 + A2 == B1 + B2 or A1 == B1 or A2 == B2:
    print('infinity')
elif A1 + A2 < B1 + B2:
    print(0)
else:
    def check(c):
        return c * (A1 + A2) + A1 > c * (B1 + B2) + B1
    l = 0
    h = B1 + B2
    while l < h:
        mid = l + (h - l) // 2
        if check(mid):
            h = mid
        else:
            l = mid + 1
            
    print(2*l-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())

delta1 = A1 - B1
delta2 = A2 - B2

d = delta1 * T1 + delta2 * T2
T = T1 + T2

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

if delta1 * delta2 > 0:
    print(0)
    exit()

#a = T1 * (T * delta1 - d) / T
Ta = T1 * (T * delta1 - d)
# t0 = a * (-1) * T / d
t0 = Ta * (-1) / d

Tnum = (t0 - T1) // T
ans = 2 * Tnum + 1

dt0 = Ta * (-1)

#if t0 == Tnum * T + T1:
if dt0 == d * (Tnum * T + T1):
    ans -= 1

print(int(ans))

Submission status: Wrong Answer

Solution code:
def examF():
    T = LI()
    A = LI()
    B = LI()
    loop1 = T[0]*(A[0]-B[0])
    loop2 = T[1]*(A[1]-B[1])
    if loop1>0 and loop2>0:
        ans = 0
    elif loop1<0 and loop2<0:
        ans = 0
    else:
        now = loop1
        cur = loop1+loop2
#        print(now,cur)
        if cur!=0:
            ans = abs(now)//abs(cur)*2
            if abs(now)%abs(cur)!=0:
                judge = now + cur*ans//2
                if (now>0 and judge+loop1>0) or (now<0 and judge+loop1<0):
                    ans +=1
        else:
            ans = "infinity"
    print(ans)
    return

import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examF()

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 t[0]*a[0]+t[1]*a[1]==t[0]*b[0]+t[1]*b[1]:
    print('infinity')
    exit()
elif t[0]*a[0]==t[0]*b[0]:
    print('infinity')
    exit()

c = [t[0]*a[0],t[1]*a[1]]
d = [t[0]*b[0],t[1]*b[1]]

ans = 0

if sum(d)>sum(c):
    if d[0]>c[0]:
        print(ans)
        exit()
    elif d[0]<c[0]:
        x =sum(d)-sum(c)
        ans += (c[0]-d[0])//(sum(d)-sum(c))*2
        if sum(d)*(ans//2+1)+d[0]>=sum(c)*(ans//2+1)+c[0]:
            ans+=1
elif sum(c)>sum(d):
    if c[0]>d[0]:
        print(ans)
        exit()
    elif c[0]<d[0]:
        ans += (d[0]-c[0])//(sum(c)-sum(d))*2
        if sum(c)*(ans//2+1)+c[0]>=sum(d)*(ans//2+1)+d[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())
x1 = (a1 - b1) * t1
x2 = (a2 - b2) * t2
if (x1 > 0 and x2 > 0) or (x1 < 0 and x2 < 0) or abs(x1) > abs(x2):
  print(0)
elif x1 + x2 == 0:
  print('infinity')
else:
  diff = x1 + x2
  ans = 1 + abs(x1) // abs(diff) * 2
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

DA0 = 0
DB0 = 0

DA1 = DA0 + T1 * A1
DB1 = DB0 + T1 * B1

DA2 = DA1 + T2 * A2
DB2 = DB1 + T2 * B2

if (DA2 - DB2) == 0:
    print('infinity')
elif np.sign(DA1 - DB1) == np.sign(DA2 - DB2):
    print(0)
else:
    z = abs(DA1 - DB1) // abs(DA2 - DB2)
    z = z * 2 + 1
    print(z)