Problem:


Score: 600 points

Problem Statement

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

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

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

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

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

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

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

If they meet infinitely many times, print infinity instead.  

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

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

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

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

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

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



Sample input:
1 2
10 10
12 4


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys

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


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


def main():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    A = A1 * T1 + A2 * T2
    B = B1 * T1 + B2 * T2

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

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

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

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

    a = 0
    b = 0
    ans = 0

    cnt = 1
    while True:
        flag = False
        # T1秒後
        # 大小が変わるか
        if (b - a) * (b + T1 * B1 - a - T1 * A1) < 0:
            ans += 1
            flag = True
        a += T1 * A1
        b += T1 * B1

        if (b - a) * (b + T2 * B2 - a - T2 * A2) < 0:
            ans += 1
            flag = True

        if not flag:
            break

        if A > B:
            b = -diff * cnt
            a = 0
        else:
            a = -diff * cnt
            b = 0

        cnt += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

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

if A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2:
    print(0)
    sys.exit()

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

N = (T1 * (A1 - B1) - 1) // (T1 * (B1 - A1) + T2 * (B2 - A2)) + 1

print(N * 2 - 1)

Submission status: Wrong Answer

Solution code:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if(A1 > B1 and A2 > B2):
  print(0)
elif(A1 < B1 and A2 < B2):
  print(0)
elif(A1 > B1 and A2 < B2):
  dist_A = A1*T1+A2*T2
  dist_B = B1*T1+B2*T2
  if(dist_A == dist_B):
    print('infinity')
  elif(dist_A>dist_B):
    print(0)
  else:
    dif = dist_B-dist_A
    T1dif = A1*T1-B1*T1
    if(T1dif%dif == 0):
      print((T1dif//dif)*2)
    print((T1dif//dif)*2+1)
elif(A1 < B1 and A2 > B2):
  dist_A = A1*T1+A2*T2
  dist_B = B1*T1+B2*T2
  if(dist_A == dist_B):
    print('infinity')
  elif(dist_A < dist_B):
    print(0)
  else:
    dif = dist_A-dist_B
    T1dif = B1*T1-A1*T1
    if(T1dif%dif == 0):
      print((T1dif//dif)*2)
    print((T1dif//dif)*2+1)

Submission status: Wrong Answer

Solution code:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if(A1 > B1 and A2 > B2):
  print(0)
elif(A1 < B1 and A2 < B2):
  print(0)
elif(A1 > B1 and A2 < B2):
  dist_A = A1*T1+A2*T2
  dist_B = B1*T1+B2*T2
  if(dist_A == dist_B):
    print('infinity')
  elif(dist_A>dist_B):
    print(0)
  else:
    dif = dist_B-dist_A
    T1dif = A1*T1-B1*T1
    print((T1dif//dif)*2+1)
elif(A1 < B1 and A2 > B2):
  dist_A = A1*T1+A2*T2
  dist_B = B1*T1+B2*T2
  if(dist_A == dist_B):
    print('infinity')
  elif(dist_A<dist_B):
    print(0)
  else:
    dif = dist_A-dist_B
    T1dif = B1*T1-A1*T1
    print((T1dif//dif)*2+1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

a1 *= t1
a2 *= t2
b1 *= t1
b2 *= t2

if a1+a2==b1+b2:
    ans = "infinity"
else:
    if a1+a2 < b1+b2:
        a1,a2,b1,b2 = b1,b2,a1,a2
    # a1+a2が大きい
    if a1>b1:
        ans = 0
    else:
        ans = ((b1-a1) // (a1+a2-b1-b2)) * 2 + 1
        if (b1-a1) % (a1+a2-b1-b2) ==0:
            ans += 1
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    if abs(first) % abs(last) == 0:
        ans = (abs(first) // abs(last)) * 2
    elif abs(first) * 2 == abs(last):
        ans = 2
    else:
        ans = math.floor(2 * abs(first) / abs(last))
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    if abs(first) % abs(last) == 0:
        ans = (abs(first) // abs(last)) * 2
        ans = 'aaa'
    else:
        ans = math.floor(2 * abs(first) / abs(last))
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    if abs(first) % abs(last) == 0:
        ans = (abs(first) // abs(last)) * 2
    else:
        ans = math.floor(2 * abs(first) / abs(last))
        ans = 'aaa'
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    if abs(first) % abs(last) == 0:
        ans = (abs(first) // abs(last)) * 2
    else:
        ans = math.floor(2 * abs(first) / abs(last))
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    ans = math.floor(2 * abs(first) / abs(last)) - 1
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    ans = math.floor(2 * abs(first) / abs(last)) + 1
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
elif abs(first) * 2 < abs(second):
    ans = 1
else:
    ans = math.floor(2 * abs(first) / abs(last))
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    ans = math.floor(2 * abs(first) / abs(last))
print(ans)

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())
first = a1 * t1 - b1 * t1
second = (a2 * t2 - b2 * t2)
last = second + first
if first * last > 0:
    ans = 0
elif (abs(last) == 0):
    ans = 'infinity'
else:
    ans = math.ceil(abs(first) / abs(last))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

t, tt = map(int, input().split())
a, aa = map(int, input().split())
b, bb = map(int, input().split())

if a*t+aa*tt == b*t+bb*tt or a*t == b*t:
    print('infinity')
    exit()

diff1 = a*t-b*t

diff12 = a*t+aa*tt - (b*t+bb*tt)

if diff1*diff12>0:
    print(0)
    exit()

diff1 = abs(diff1)
diff12 = abs(diff12)

print(-(-diff1//diff12)*2-1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

t, tt = map(int, input().split())
a, aa = map(int, input().split())
b, bb = map(int, input().split())

if a*t+aa*tt == b*t+bb*tt or a*t == b*t:
    print('infinity')
    exit()

diff1 = a*t-b*t

diff12 = a*t+aa*tt - (b*t+bb*tt)

if diff1*diff12>0:
    print(0)
    exit()

print(-diff1//diff12*2+1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

t, tt = map(int, input().split())
a, aa = map(int, input().split())
b, bb = map(int, input().split())

if a*t+aa*tt == b*t+bb*tt:
    print('infinity')
    exit()

diff1 = a*t-b*t

diff12 = a*t+aa*tt - (b*t+bb*tt)

print(-diff1//diff12*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()))

f_a = t[0]*a[0]
f_b = t[0]*b[0]
if f_a < f_b:
    x = 1
else:
    x = -1

s_a = f_a + t[1]*a[1]
s_b = f_b + t[1]*b[1]
if s_a < s_b:
    y = 1
else:
    y = -1

if s_a==s_b:
    print('infinity')
else:
    if x==y:
        print(0)
    else: 
        s = abs(f_a-f_b)
        t = abs(s_a-s_b)
        print(1+(s//t*2)+(s%t==0))

Submission status: Wrong Answer

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

f_a = t[0]*a[0]
f_b = t[0]*b[0]
if f_a < f_b:
    x = 1
else:
    x = -1

s_a = f_a + t[1]*a[1]
s_b = f_b + t[1]*b[1]
if s_a < s_b:
    y = 1
else:
    y = -1

if s_a==s_b:
    print('infinity')
else:
    if x==y:
        print(0)
    else:
        s = abs(f_a-f_b)
        t = abs(s_a-s_b)
        print(1+(s//t*2))

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a,b=map(int,input().split())
c,d=map(int,input().split())
if t1*a+t2*b==t1*c+t2*d:
  print('infinity')
elif (c-a)*(d-b)>=0:
  print(0)
else:
  x=abs(t1*(c-a))
  y=abs(t2*(d-b))
  b,a=max(x,y),min(x,y)
  print(min(1,a%abs(a-b))+2*(a//abs(a-b)))

Submission status: Wrong Answer

Solution code:
t1,t2=map(int,input().split())
a,b=map(int,input().split())
c,d=map(int,input().split())
if t1*a+t2*b==t1*c+t2*d:
  print('infinity')
elif (c-a)*(d-b)>=0:
  print(0)
else:
  x=abs(t1*(c-a))
  y=abs(t2*(d-b))
  b,a=max(x,y),min(x,y)
  print(1+2*(a//abs(a-b)))

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    T = LI()
    A = LI()
    B = LI()

    p1 = (A[0] - B[0]) * T[0]
    p2 = p1 + (A[1] - B[1]) * T[1]
    if p1 * p2 > 0:
        print(0)
        return
    elif p2 == 0:
        print('infinity')
        return

    ans = 1
    if p2 + p1 == 0:
        print(2)
        return
    p2 = abs(p2)
    p1 = abs(p1)
    if p2 > p1:
        print(1)
        return
    if p1 % p2 == 0:
        ans += 1
    ans += (p1 // p2) * 2
    print(ans)

if __name__ == '__main__':
    main()

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())
a = t1 * (a1 - b1)
b = t2 * (a2 - b2)
if a + b < 0:
    print(0)
elif a + b > 0:
    if (-1 * a) % (a + b):
        print(((-1 * a) // (a + b)) * 2 + 1)
    else:
        print((-1 * a) // (a + b) * 2)
else:
    print("infinity")

Submission status: Wrong Answer

Solution code:
T = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

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

if a + b == 0:
    print('infinity')
else:
    if a < 0:
        a *= -1
        b *= -1
    i = a // -(a+b)
    if a % -(a+b) == 0:
        print(1+2*i-1)
    else:
        print(1+2*i)

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

a, b = A1 * T1, A2 * T2
c, d = B1 * T1, B2 * T2

if a + b == c+ d:
    print("infinity")
    exit()
if a + b < c+d:
    a,b,c,d = c,d,a,b
if a > c:
    print(0)
    exit()
else:
    print((c-a) // (a+b-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())

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

xa = A1*T1 + A2*T2
xb = B1*T1 + B2*T2
if xa > xb:
  print(0)
elif xa == xb:
  print('infinity')
else:
  d1 = (A1 - B1) * T1
  d2 = xb - xa
  n = d1 // d2
  print(2*n + 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()))

S = [0]*2
for i in range(2):
    S[0] += T[i]*A[i]
    S[1] += T[i]*B[i]
if S[0]==S[1]:
    print("infinity")
else:
    if S[0]<S[1]:
        A,B = B,A
        S = S[::-1]
    if A[0]==B[0] or A[1]==B[1]:
        print(0)
    elif A[0]>B[0] and A[1]>B[1]:
        print(0)
    elif A[0]>B[0] and A[1]<B[1]:
        print(0)
    elif A[0]<B[0] and A[1]>B[1]:
        absS = S[0]-S[1]
        absT = T[0]*(B[0]-A[0])
        print(absT//absS*2+1)

Submission status: Wrong Answer

Solution code:
t1,t2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
hosei = 1
if t1*c1>t1*d1:
    a1=c1
    a2=c2
    b1=d1
    b2=d2
else:
    a1,a2,b1,b2=d1,d2,c1,c2
print(a1,a2,b1,b2)
if t1*a1+t2*a2 > t1*b1+t2*b2:
    exit()
elif t1*a1+t2*a2 == t1*b1+t2*b2:
    print("infinity")
else:
    # print((t1*(a1-b1))//(t2*(b2-a2)) + 1,t1*(a1-b1),t2*(b2-a2))
    # if t2*(b2-a2) % (t2*(b2-a2)-t1*(a1-b1)) == 0:
    #     hosei = 0
    print((t2*(b2-a2)) // (t2*(b2-a2)-t1*(a1-b1))*2-hosei)
    # print((t2*(a2-b2)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    
    d1=(A[0]-B[0])*T[0]
    d2=(A[1]-B[1])*T[1]
    
    if d1>=0:
        #最初は必ず正の方向へいかないように調整
        d1*=-1
        d2*=-1
        
    
    if d1+d2==0:
        print("infinity")
    elif d1==0:#d1=0のパターンを排除した
        print(0)
    elif d2<=0:
        print("0")
    else:
        cnt=(-1*d1)//(d1+d2)
        ans=cnt*2+1
        if cnt*(d1+d2)==-1*d1:
            ans-=1
        print(ans)
        
        
        
    

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    SA=T[1]*A[1]+T[0]*A[0]
    SB=T[1]*B[1]+T[0]*B[0]
    
    if SA == SB:
        print("infinity")
    else:
        if SB>SA:
            SB,SA=SA,SB
            A,B=B,A
        #t1+t2分後に確実にAが先行するように．
        if A[0]>B[0]:
            print(0)
        else:
            diff1=(B[0]-A[0])*T[0]
            diff2=SA-SB
            cnt=(diff1//diff2+1)
            ans=(cnt)*2-1
            #基本，1ループで2回，初回は0,0のため-1
            #さらに，cnt回目のループでぎり1回だけという場合があるので，その場合は1ひく
            if diff2*(cnt-1) == diff1*cnt:
                ans-=1
            print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    SA=T[1]*A[1]+T[0]*A[0]
    SB=T[1]*B[1]+T[0]*B[0]
    
    if SA == SB:
        print("infinity")
    else:
        if SB>SA:
            SB,SA=SA,SB
            A,B=B,A
        #t1+t2分後に確実にAが先行するように．
        if A[0]>B[0]:
            print(0)
        else:
            diff1=(B[0]-A[0])*T[0]
            diff2=SA-SB
            ans=((diff1+diff2-1)//diff2)*2-1
            print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    SA=T[1]*A[1]+T[0]*A[0]
    SB=T[1]*B[1]+T[0]*B[0]
    
    if SA == SB:
        print("infinity")
    else:
        if SB>SA:
            SB,SA=SA,SB
            A,B=B,A
        #t1+t2分後に確実にAが先行するように．
        if A[0]>B[0]:
            print(0)
        else:
            diff1=(B[0]-A[0])*T[0]
            diff2=SA-SB
            ans=(diff1//diff2)*2+1
            print(ans)

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

d = [(A[i] - B[i])*T[i] for i in range(2)]
if d[0] < 0:
    d = [-d[0],-d[1]]
s = sum(d)
if s == 0:
    print('infinity')
elif s > 0:
    print(0)
else:
    print(d[0]//(-s)*2 + 1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

t1, t2 = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
v1 = t1 * (a[0] - b[0])
v2 = t2 * (a[1] - b[1])
if v1 + v2 == 0:
    print('infinity')
elif v1 + v2 < 0:
    print(0)
else:
    s, t = divmod(-v1, v1 + v2)
    ans = s * 2
    if t != 0:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

t1, t2 = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
va1 = t1 * a[0]
va2 = t2 * a[1]
vb1 = t1 * b[0]
vb2 = t2 * b[1]
ans = 0
if va1 + va2 == vb1 + vb2:
    print('infinity')
else:
    if va1 + va2 < vb1 + vb2 and va1 > vb1:
        v = vb1 + vb2 - va1 - va2
        ans = (va1 - vb1) // v * 2
        if va1 - vb1 <= ans * v + vb2 - va2:
            ans += 1
        print(ans)
    elif va1 + va2 > vb1 + vb2 and va1 < vb1:
        v = va1 + va2 - vb1 - vb2
        ans = (vb1 - va1) // v * 2
        if vb1 - va1 <= ans * v + va2 - vb2:
            ans += 1
        print(ans)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

t1, t2 = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
va1 = t1 * a[0]
va2 = t2 * a[1]
vb1 = t1 * b[0]
vb2 = t2 * b[1]
if va1 + va2 == vb1 + vb2:
    print('infinity')
else:
    if va1 + va2 < vb1 + vb2 and va1 > vb1:
        print((va1 - vb1) // (vb1 + vb2 - va1 - va2) * 2 + 1)
    elif va1 + va2 > vb1 + vb2 and va1 < vb1:
        print((vb1 - va1) // (va1 + va2 - vb1 - vb2) * 2 + 1)
    else:
        print(0)

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

f = (A_1 - B_1) * T_1
s = (A_2 - B_2) * T_2

if f * (f + s) > 0:
	ans = 0
elif f * (f + s) == 0:
	ans = 'infinity'
else:
	ans = 1
	if f < 0:
		f *= -1
		s *= -1
	d = f + s
	div, mod = (f, abs(d))
	ans += div * 2
	if mod == 0:
		ans -= 1

print(ans)

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

f = (A_1 - B_1) * T_1
s = (A_2 - B_2) * T_2

if f * (f + s) > 0:
	ans = 0
elif f * (f + s) == 0:
	ans = 'infinity'
else:
	ans = 1
	if f < 0:
		f *= -1
		s *= -1
	d = f + s
	ans += (f // abs(d)) * 2

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())
OU=T1*(A1-B1)
HUKU=T2*(A2-B2)
TOTAL=OU+HUKU
if TOTAL==0:
 print("infinity")
elif (OU>0 and HUKU>0) or (OU<0 and HUKU<0):
 print(0)
elif (OU>0 and TOTAL>0) or (OU<0 and TOTAL<0):
 print(1)
else:
 K=int(OU/TOTAL)*-1
 if (OU%TOTAL)==0:
  print(K*2)
 else:
  print(K*2+1)

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())
# まず大きい方にswap
if a1 <= b1:
    a1,b1 = b1,a1
    a2,b2 = b2,a2

# t1での距離
x1 = a1*t1 - b1*t1
# t2での距離
x2 = x1 + a2*t2 - b2*t2
if x2 == 0:
    print("infinity")
elif x2 > 0:
    print(0)
else:
    ans =  int(np.ceil(x1/abs(x2))*2-1)
    if x1 % abs(x2) == 0:
        ans -= 1
    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())
# まず大きい方にswap
if a1 <= b1:
    a1,b1 = b1,a1
    a2,b2 = b2,a2

# t1での距離
x1 = a1*t1 - b1*t1
# t2での距離
x2 = x1 + a2*t2 - b2*t2
if x2 == 0:
    print("infinity")
elif x2 > 0:
    print(0)
else:
    print(int(np.ceil(x1/abs(x2))*2-1))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = LI()
    a = LI()
    b = LI()
    a[0] -= b[0]
    a[1] -= b[1]
    if t[0]*a[0] == -t[1]*a[1]:
        print("infinity")
        return
    if a[0] < 0:
        a[0] *= -1
        a[1] *= -1
    if t[0]*a[0]+t[1]*a[1] > 0:
        print(0)
        return
    A = t[0]*a[0]+t[1]*a[1]
    k = t[0]*a[0]
    l = 0
    r = 10**20
    while r-l > 1:
        x = (l+r) >> 1
        if A*x+k > 0:
            l = x
        else:
            r = x
    ans = 2*l+1
    if A*r+k == 0:
        ans -= 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

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

if abs(d1) == abs(d2):
    print("infinity")
    exit()

if abs(d1) > abs(d2):
    print(0)
    exit()

dif = abs(d2) - abs(d1)

import math
ans=2*(math.ceil(abs(d1)//dif))
if abs(d1)%dif != 0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

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

if abs(d1) == abs(d2):
    print("infinity")
    exit()

if abs(d1) > abs(d2):
    print(0)
    exit()

dif = abs(d2) - abs(d1)

ans=2*(abs(d1)//dif)
if abs(d1)%dif != 0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

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

if abs(d1) == abs(d2):
    print("infinity")
    exit()

if abs(d1) > abs(d2):
    print(0)
    exit()

dif = abs(d2) - abs(d1)

ans=2*abs(d1)//dif
if abs(d1)%dif != 0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

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

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

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print(((B1-A1)//(A1+A2-(B1+B2)))*2 +1+(((B1-A1)%(A1+A2-(B1+B2)))==0)*2)

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

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

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

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print(((B1-A1)//(A1+A2-(B1+B2)))*2 +1+(((B1-A1)%(A1+A2-(B1+B2)))==0)*1)

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

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

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

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print(((B1-A1)//(A1+A2-(B1+B2)))*2 +1)

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

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

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

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print((B1-A1)//(A1+A2-(B1+B2))*2 +1)

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

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

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

if A1+A2==B1+B2:
    print("infinity")
else:
    if A1+A2<B1+B2:
        A1,B1=B1,A1
        A2,B2=B2,A2
    if A1>B1:
        print(0)
    else:
        print(A1,A2,B1,B2)
        print((B1-A1)//(A1+A2-(B1+B2))*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())
p1 = t1*a1
q1 = t1*b1
p2 = p1+t2*a2
q2 = q1+t2*b2
if p2 == q2:
  print("infinity")
  exit()
if (p1>q1 and p2>q2) or (p1<q1 and p2<q2):
  print(0)
  exit()
x = abs(p1-q1)
y = abs(q2-p2)
if x%y == 0:
  ans = (x//y)*2-2
else:
  ans = (x//y)*2+1
print(ans)

Submission status: Wrong Answer

Solution code:
def run(x, y):
    # すれ違わない場合
    if x * y > 0 or abs(x) > abs(y):
        return 0

    # mugen
    if abs(x) == abs(y):
        return "infinity"

    # 一回のT1+T2走ると軸がdずれる
    shift = abs(x + y)
    cnt = abs(x)//shift
    ans = 2 * cnt + 1
    if shift * cnt == abs(x):
        ans += 1
    return ans


if __name__ == "__main__":
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    d1 = (A1 - B1) * T1
    d2 = (A2 - B2) * T2

    ans = run(d1, d2)
    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

D1 = A1 * T1
D2 = A2 * T2

if D1 + D2 == 0:
    print("infinity")
    exit()

if D1 * D2 > 0:
    print(0)
    exit()

slope = (D1 + D2) / (T1 + T2)
incpt = D1 - slope * T1
T_leave = -incpt / slope

X = int(T_leave / (T1 + T2))
ans = 2*X - 1

rest = T_leave - X * (T1 + T2)
if rest == T1:
    ans += 1
elif rest > T1:
    ans += 2

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())
v1, v2 = A1 - B1, A2 - B2
d1, d2 = v1 * T1, v2 * T2

if d1 + d2 == 0:
    print("infinity")
elif d1 + d2 < 0:
    if d1 > 0:
        s, t = divmod(d1, d1+d2)
        ans = 2*s + (t!=0)
        print(ans)
    else:
        print(0)
elif d1 + d2 > 0:
    if d1 < 0:
        s, t = divmod(-d1, d1+d2)
        ans = 2*s + (t!=0)
        print(ans)
    else:
        print(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())

def check(k):
    v1 = A1 - B1
    v2 = A2 - B2

    a, b = k//2, k%2
    d1 = (a+b)*(v1*T1) + (a)*(v2*T2)

    k += 1

    a, b = k//2, k%2
    d2 = (a+b)*(v1*T1) + (a)*(v2*T2)

    if d1*d2<=0:
        return True
    else:
        return False

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print("infinity")
else:
    l = -1
    r = 10**20

    while r-l>1:
        m = (l+r)//2
        if check(m):
            l = m
        else:
            r = m
    
    print(l)