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:
tt = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

a = tt[0] * aa[0] + tt[1] * aa[1]
b = tt[0] * bb[0] + tt[1] * bb[1]

if a == b:
	print("infinity")
elif (aa[0] - bb[0]) * (a - b) > 0:
	print(0)
else:
	f_dif = abs(aa[0] * tt[0] - bb[0] * tt[0])
	s_dif = abs(a - b)
	print(f_dif, s_dif)
	print((f_dif // s_dif) * 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()))
BXA = 0
BXB = 0
XA = 0
XB = 0
ans = 0
for i in range(10**6):
    XA = T1*A1 + BXA
    XB = T1*B1 + BXB
    if (XA-XB)*(BXA-BXB)<0 or XA==XB:
        ans+=1
    BXA = XA
    BXB = XB
    XA = T2*A2 + BXA
    XB = T2*B2 + BXB
    if (XA-XB)*(BXA-BXB)<0 or XA==XB:
        ans+=1
    BXA = XA
    BXB = XB
if ans >= 10**5:
    print("infinity")
else:
    print(ans)

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
ans = math.ceil((max(A1, B1) - min(A1, B1)) * T1 / diff_dis) * 2
print(ans -1)

Submission status: Wrong Answer

Solution code:
import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
    print("infinity")
else:
    # 速いほうをＡと仮定
    if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
        A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2
    if A_1 < B_1:
        sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2)  # 1サイクルでできる差
        sa_1 = -T_1 * A_1 + T_1 * B_1  # T_1でできる差
        if sa_1 % sa_12 == 0:
            ans = (sa_1 / sa_12)*2
        else:
            kari = math.ceil(sa_1 / sa_12)

            ans = (kari-1)*2+1
    print(ans)

Submission status: Wrong Answer

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

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

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

taka = t1*a1
aoki = t1*b1
ans = 0
if(t1*a1+t2*a2==t1*b1+t2*b2):
    print("infinity")
    sys.exit()
#diff = t1*a1+t2*a2-t1*b1+t2*b2

top = 0
if(taka>aoki):
    top = 0
else:
    top = 1
for i in range(2,1000000):
#    prev_taka = taka
#    prev_aoki = aoki
    prev_top = top
    if(i%2==1):
        taka += t1*a1
        aoki += t1*b1
    else:
        taka += t2*a2
        aoki += t2*b2
    if(taka>aoki):
        top = 0
    else:
        top = 1
    if(prev_top != top):
        ans += 1
    
#    print("taka",taka)
#    print("aoki",aoki)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
T = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = a[0]
y = b[0]
f = 0
res = 0
zx = 0
zy = 0
if y > x: f = 1
for t in range(1, sum(T) + 2):
  if f == 2:
    f = 0
    if y > x: f = 1
  if t <= T[0]:
    x += a[0]
    y += b[0]
  else:
    x += a[1]
    y += b[1]
  if f == 0 and (y >= x):
    res += 1
    f = 1
  elif f == 1 and (x >= y):
    res += 1
    f = 0
  if x == y: f = 2
  if t == T[0]:
    zx = x
    zy = y

if x - y == a[0] - b[0]: 
  print("infinity")
else:
  z = (a[0] - b[0]) - (x - y)
  w = abs(zx - zy) // abs(z)
  if (zx - zy) * z > 0:
    print(res)
    exit(0)
  print(w * 2 + res)

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=abs(t1*(a1-b1)),abs(t2*(b2-a2))
if a==b:
    print('infinity')

elif a1-b1>=0 and a2-b2>=0 or a1-b1<=0 and a2-b2<=0:
    print(0)
else:
    c=0
    if a<b:
        c+=1
    a,b=min(a,b),max(a,b)
    print(c+2*(a//(b-a)))

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

Submission status: Wrong Answer

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

    if A1 < B1 and A2 < B2:
        return 0
    elif A1 > B1 and A2 > B2:
        return 0

    C1, C2 = B1-A1, B2-A2

    if C1*T1 + C2*T2 == 0:
        return 'infinity'

    if C1*T1 + C2*T2 < 0:
        C1, C2 = -C1, -C2
#    print('C1:', C1, '/ C2:', C2)

    if abs(C1*T1) > abs(C2*T2):
        return 0

    x1, x2 = T1, 2*T1+T2
    y1, y2 = C1*T1, 2*C1*T1+C2*T2
#    print('x1:', x1, '/ y1:', y1)
#    print('x2:', x2, '/ y2:', y2)

    x = -y1 * (x2-x1) / (y2-y1) + x1
#    print('x:', x)

    z = x-T1
    T = T1+T2
    ans = z//T*2
    if z//T*T != z:
        ans += 1

    return int(ans)


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

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)
print(int(((a1*t1) - (b1*t1)) / diff) * 2 + 1)

Submission status: Wrong Answer

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

turn=0
ans=0
XA=T1*A1
XB=T1*B1
i=0
diff=[XA-XB]
A_cycle=T1*A1+T2*A2
B_cycle=T1*B1+T2*B2
if A_cycle==B_cycle:
    print("infinity")
else:
    while turn<2:
        i+=1
        XA+=T2*A2
        XB+=T2*B2
        diff.append(XA-XB)
        if diff[i-1]*diff[i]>0:
            turn+=1
        else:
            ans+=1
        i+=1
        XA+=T1*A1
        XB+=T1*B1
        diff.append(XA-XB)
        if diff[i-1]*diff[i]>0:
            turn+=1
        else:
            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 not (a1>b1)^(a2>b2):
    print(0)
    exit()

if a1+a2==b1+b2:
    print("infinity")
    exit()
if a1+a2>b1+b2:
    a1,a2,b1,b2 = b1,b2,a1,a2
if a1<b1:
    print(0)
    exit()
print(((b1-a1)//(a1+a2-b1-b2))*2+1)

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))
print(1 if diff2 > diff else diff // diff2 * 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 t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit()
x = 0
y = 0
check = 0
deai = 0
first = t1 * a1 - t1 * b1
second = t2 * a2 - t2 * b2
x += first
while True:
    y = x
    x += second
    if y < 0 and x > 0:
        check = 0
        deai += 1
    elif y > 0 and x < 0:
        check = 0
        deai += 1
    else:
        check += 1
    y = x
    x += first
    if y < 0 and x > 0:
        check = 0
        deai += 1
    elif y > 0 and x < 0:
        check = 0
        deai += 1
    else:
        check += 1

    if check > 2:
        print(deai)
        break

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_ave = (T1*A1+T2*A2)/(T1+T2)
a_ave = (T1*B1+T2*B2)/(T1+T2)
t_D1 = T1*A1
t_D2 = T2*A2
a_D1 = T1*B1
a_D2 = T2*B2
if t_D1+t_D2==a_D1+a_D2:
    print("infinity")
else:
    if (t_D1>a_D1 and t_D2>a_D2) or (t_D1<a_D2 and t_D2 <=a_D2 ):
        print(0)
    else:
        from math import ceil
        print(int(ceil(abs((t_D1-a_D1)/(t_ave-a_ave)))))

Submission status: Wrong Answer

Solution code:
Ts = list(map(lambda x: int(x), input().split(" ")))
As = list(map(lambda x: int(x), input().split(" ")))
Bs = list(map(lambda x: int(x), input().split(" ")))

t1 = Ts[0]
t2 = Ts[1]
a1 = As[0]
a2 = As[1]
b1 = Bs[0]
b2 = Bs[1]

result = 0
difference = 0

if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
else:
    while True:
        difference += t1*(a1-b1)

        if result > 0:
            if a1-b1 > 0 and difference <= 0:
                break
            elif a1-b1 < 0 and difference >= 0:
                break
        result += 1

        difference += t2*(a2-b2)

        if result > 0:
            if a2-b2 > 0 and difference <= 0:
                break
            elif a2-b2 < 0 and difference >= 0:
                break
        result += 1

    print(result-1)

Submission status: Wrong Answer

Solution code:
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
BXA = 0
BXB = 0
XA = 0
XB = 0
ans = 0
for i in range(10**6):
    XA = T1*A1 + BXA
    XB = T1*B1 + BXB
    if (XA-XB)*(BXA-BXB)<0 or XA==XB:
        ans+=1
    BXA = XA
    BXB = XB
    XA = T2*A2 + BXA
    XB = T2*B2 + BXB
    if (XA-XB)*(BXA-BXB)<0 or XA==XB:
        ans+=1
    BXA = XA
    BXB = XB
if ans >= 10**6:
    print("infinity")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
T = tuple(map(int, input().split()))

A = list(map(int, input().split()))
B = list(map(int, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])

if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("Infinity")
    else:
        print((a*2)//b)

Submission status: Wrong Answer

Solution code:
t1,t2 = map(int, input().split( ))
a1,a2 = map(int, input().split( ))
b1,b2 = map(int, input().split( ))
a1*=t1
b1*=t1
a2*=t2
b2*=t2
if not (a1>b1)^(a2>b2):
    print(-2)
    exit()

if a1+a2==b1+b2:
    print("infinity")
    exit()
if a1+a2>b1+b2:
    a1,a2,b1,b2 = b1,b2,a1,a2
if a1<b1:
    print(-9)
    exit()
print(((b1-a1)//(a1+a2-b1-b2))*2+1)

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)

ans =0
for i in range(set_cnt + 1):
    if (max(A1, B1) - min(A1, B1)) * T1 > diff_dis * i:
        ans += 2
print(ans -1)

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)

    n = floor(n)
    ans = 2 * n - 1

    if diff2 / (diff2 - diff1) == int(diff2 / (diff2 - diff1)):
        ans -= 2

    print(ans)

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

sa, sb = 0, 0
ta = a[0] * t[0] + a[1] * t[1]
tb = b[0] * t[0] + b[1] * t[1]

cnt = 0

if ta == tb:
    print("infinity")
else:
    while sa + ta < sb + tb + b[0] * t[0] and sa + ta + a[0] * t[0] > sb + tb:
        if sa < sb and sa + a[0] * t[0] >= sb + b[0] * t[0]:
            cnt += 1
        if sa > sb and sa + a[0] * t[0] <= sb + b[0] * t[0]:
            cnt += 1
        sa += a[0] * t[0]
        sb += b[0] * t[0]
        if sa < sb and sa + a[1] * t[1] >= sb + b[1] * t[1]:
            cnt += 1
        if sa > sb and sa + a[1] * t[1] <= sb + b[1] * t[1]:
            cnt += 1
        sa += a[1] * t[1]
        sb += b[1] * t[1]
    print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(T: "List[int]", A: "List[int]", B: "List[int]"):
    if T[0]*A[0] + T[1]*A[1] == T[0]*B[0] + T[1]*B[1]:
        print("infinity")
        return

    sa0=T[0]*(A[0]-B[0])
    sa1=T[1]*(A[1]-B[1])
    deai=0
    delta=sa0+sa1

    #a-senko
    if A[0]>B[0] and delta<0:
        print( ((sa0-delta-1) // (-delta) - 1)*2+1 )
        return

    #b-senko
    if A[0]<B[0] and delta>0:
        print( ((-sa0+delta-1) // delta - 1)*2+1 )
        return

    print(0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = [int(next(tokens)) for _ in range(2)]  # type: "List[int]"
    A = [int(next(tokens)) for _ in range(2)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(2)]  # type: "List[int]"
    solve(T, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
t1, t2 = [int(i) for i in sys.stdin.readline().split()]
a1, a2 = [int(i) for i in sys.stdin.readline().split()]
b1, b2 = [int(i) for i in sys.stdin.readline().split()]
def main(a1, a2, b1, b2, t1, t2):
    a_sum = a1 * t1 + a2 * t2
    b_sum = b1 * t1 + b2 * t2
    if ((a_sum > b_sum) and (a1 > b1)) or ((b_sum > a_sum) and (b1 > a1)):
        print(0)
        return 0
    if a_sum == b_sum:
        print("infinity")
        return 0
    if b_sum > a_sum:
        cnt = (a1 - b1) * t1 / (b_sum - a_sum)
    else:
        cnt = (b1 - a1) * t1 / (a_sum - b_sum)
    print(math.floor(cnt) * 2 + 1)
    return 0
main(a1, a2, b1, b2, t1, t2)

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(300010):
    if i%2==0:
      x+=A2*T2
      y+=B2*T2
    else:
      x+=A1*T1
      y+=B1*T1

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

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

  if inf_cnt==300010 or inf_cnt==150005:
    return 'infinity'
  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
tt = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

a = tt[0] * aa[0] + tt[1] * aa[1]
b = tt[0] * bb[0] + tt[1] * bb[1]

if a == b:
	print("infinity")
elif (aa[0] - bb[0]) * (aa[1] - bb[1]) > 0:
	print(0)
else:
	f_dif = abs(aa[0] * tt[0] - bb[0] * tt[0])
	s_dif = abs(a - b)
	#print(f_dif, s_dif)
	print((f_dif // s_dif) * 2 + 1)

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())
a1 -= b1
a2 -= b2

if t1*a1 + t2*a2 == 0:
    print("infinity")
    exit()
if a1*a2 > 0:
    print(0)
    exit()
a1 *= t1
a2 *= t2
if (a1 > 0 and a1+a2>0) or (a1<0 and a1+a2<0):
    print(0)
    exit()
if a1 > 0:
    x = -a1/(a1+a2)
    n = ceil(x)
    if n == x:
        print(2*n)
    else:
        print(2*n-1)
if a2 > 0:
    x = a1 / (-(a1 + a2))
    n = ceil(x)
    if n == int(x):
        print(2 * n-2)
    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())

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

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

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

Submission status: Wrong Answer

Solution code:
t = input().split(" ")
a = input().split(" ")
b = input().split(" ")
t1 = int(t[0])
t2 = int(t[1])
a1 = int(a[0])
a2 = int(a[1])
b1 = int(b[0])
b2 = int(b[1])
if t1*a1+t2*a2==t1*b1+t2*b2:
	print("infinity")
else:
	if t1*a1+t2*a2>t1*b1+t2*b2:
		s0 = t1*b1
		s1 = t2*b2
		f0 = t1*a1
		f1 = t2*a2
	else:
		f0 = t1*b1
		f1 = t2*b2
		s0 = t1*a1
		s1 = t2*a2
	if f0 > s0:
		print(0)
	else:
		x = s0 - f0 
		y = f1 - s1
		z = y - x
		a = int(y / z)
		print(a*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())

x = A1*T1 + A2*T2 - (B1*T1 + B2*T2)
y = A1*T1 - B1*T1
if(x ==0 or y==0):
    print('infinity')
elif(y * x > 0):
    print(0)
else:
    print(abs(y//x)*2-1)

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:
        return 'infinity'
    elif C1/C > 0:
        return '0'
    elif C1/C > -1:
        return '1'
    else:
        res =  2*(floor(-C1/C)+1)-1
        return str(res)

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

Submission status: Wrong Answer

Solution code:
import math

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

diff = sorted([(A[0] - B[0]) * T[0], (A[1] - B[1]) * T[1]])
if sum(diff) == 0:
    print("infinity")
elif diff[0] * diff[1] > 0:
    print(0)

else:
    if abs(diff[0]) > abs(diff[1]):
        if diff[0] % (diff[0] + diff[1]) == 0:
            print(2 * math.ceil(diff[0] / (diff[0] + diff[1])) - 2)
        else:
            print(2 * math.ceil(diff[0] / (diff[0] + diff[1])) - 3)

    else:
        if diff[1] % (diff[0] + diff[1]) == 0:
            print(2 * math.ceil(diff[1] / (diff[0] + diff[1])) - 2)
        else:
            print(2 * math.ceil(diff[1] / (diff[0] + diff[1])) - 3)

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

    
if (l1+l2)==0:
    print('infinity')
elif (l1>0)*(l1+l2)>0:
    print(0)
else:
    zure = abs(l1+l2)
    oitsuki = abs(l1)
    n = oitsuki//zure
    if n * zure == oitsuki:
        print(2*n)
    else:
        print(2*n+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
T = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = a[0]
y = b[0]
f = 0
res = 0
zx = 0
zy = 0
if y > x: f = 1
for t in range(1, sum(T) + 1):
  if f == 2:
    f = 0
    if y > x: f = 1
  if t <= T[0]:
    x += a[0]
    y += b[0]
  else:
    x += a[1]
    y += b[1]
  if f == 0 and (y >= x):
    res += 1
    f = 1
  elif f == 1 and (x >= y):
    res += 1
    f = 0
  if x == y: f = 2
  if t == T[0]:
    zx = x
    zy = y

if x - y == a[0] - b[0]: 
  print("infinity")
else:
  z = (a[0] - b[0]) - (x - y)
  w = abs(zx - zy) // abs(z)
  if (zx - zy) * z > 0:
    print(res)
    exit(0)
  print(w * 2 + res)

Submission status: Wrong Answer

Solution code:
import numpy as np
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
c1 = b1-a1
c2 = b2-a2
s = t1*c1+t2*c2
if s==0:
    print("infinity")
    exit()
mx = max([np.abs(t1*c1),np.abs(t2*c2)])
n = np.abs(int(mx/s))

if mx%s == 0:
    print(2*n-2)
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()

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

n = int(delta1 * T1 // d) * (-1)
ans = 2 * n - 1
if delta1 * T1 == n * d:
    ans += 1

print(max(ans, 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())

x = (a1-b1) * t1
y = x + (a2-b2) * t2
#print(x, y)

def p(x, y):
    if x%y == 0:
        return abs(x//y)
    else:
        return abs(x//y) + 1

if y == 0:
    ans = 'infinity'
else:
    if x%y != 0:
        if x < 0 and y > 0 :
            ans = (abs(x//y) + 1) * 2 - 3
        elif x > 0 and y < 0 :
            ans = (abs(x//y) + 1) * 2 - 2
        else:
            ans = 0
    else:
        if x < 0 and y > 0 :
            ans = (abs(x//y) + 1) * 2 - 1
        elif x > 0 and y < 0 :
            ans = (abs(x//y) + 1) * 2 - 1
        else:
            ans = 0


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math


T0, T1 = map(int,input().split())
A0, A1 = map(int,input().split())
B0, B1 = map(int,input().split())

delta0 = (A0 - B0) * T0
delta1 = (A1 - B1) * T1

if (delta0 * delta1 > 0) :
	print(0)
	sys.exit()
	
elif (delta0 == 0): 
	print("infinity")
	sys.exit()
	
elif (delta0 + delta1 == 0) :
	print("infinity")
	sys.exit()
	
else :

	tikuseki = 0

	# Aのほうがトータルでは速い
	if (delta0 + delta1 > 0) :

		# Aがリード　ー＞　近づく、、、、
		if (delta0 > 0) :
				
			print(0)
			sys.exit()

			
		else :

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


			print(math.floor((math.floor(- delta0) / ((delta0 + delta1)))  + 1))
			
		

	else :

		if (delta0 < 0) :

			print(0)
			sys.exit()

			
		else :

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

			print(math.floor(delta0 / (-(delta0 + delta1)))  + 1)

Submission status: Wrong Answer

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

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:
    v1,v2 = v2,v1

d = v2 - v1
k = v1 // d

ans = k*2 + 1
if v2*k == v1*(k+1):
    ans += 1
print(ans)

Submission status: Wrong Answer

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

if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
    print('infinity')
else:
    d1 = t1 * (b1 - a1)
    d2 = t2 * (b2 - a2)
    x = d1 / (d1 + d2)
    # print(x)
    # print(int(x))
    print(2 * int(abs(x)) + 1)

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)

    n = floor(n)
    ans = 2 * n - 1
    if diff2 * (n - 1) == diff1 * n:
        pass

    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

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

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

if A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2:
  print(0)
  exit()

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

t = int((B1 * T1 - A1 * T1) / ((A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)))
print(t * 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)

max_ = max([T1,T2,A1,A2,B1,B2])

T1/=max_
T2/=max_
A1/=max_
B1/=max_
A2/=max_
B2/=max_


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 math

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

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

if sum(c)==sum(d):
    print('infinity')
    exit()
elif c[0]==d[0]:
    print('infinity')
    exit()

if sum(d)>sum(c) and d[0]>c[0]:
    print(0)
    exit()
elif sum(c)>sum(d) and c[0]>d[0]:
    print(0)
    exit()



if sum(d)>sum(c):
    if d[0]>c[0]:
        print(0)
        exit()
    elif d[0]<c[0]:
        n = (c[0]-d[0])/(sum(d)-sum(c))
        if n==int(n):
            print(2*n)
        else:
            print(2*math.ceil(n)-1)
elif sum(c)>sum(d):
    if c[0]>d[0]:
        print(0)
        exit()
    elif c[0]<d[0]:
        n = (c[0]-d[0])/(sum(d)-sum(c))
        if n==int(n):
            print(2*n)
        else:
            print(2*math.ceil(n)-1)