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: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline 

#n = int(input())
#s = input()
#a = [int(i) for i in readline().split()]
#m = [[int(i) for i in readline().split()] for _ in range(n)]

t1,t2 = [int(i) for i in readline().split()]
a1,a2 = [int(i) for i in readline().split()]
b1,b2 = [int(i) for i in readline().split()]


if a1*t1 + a2*t2 == b1*t1 + b2*t2:
    print("infinity")
else:
    d = a1*t1 + a2*t2 - (b1*t1 + b2*t2)
    if d < 0:
        a1,b1 = b1,a1
        a2,b2 = b2,a2
        d = -d
    
    if a1 == b1:
        print("infinity")
    elif a1 > b1:
        print(0)
    else:
        c = (b1-a1)*t1
        r = c//d
        #print(r,c,d)
        if c%d == 0:
           print(2*r)
        else:
            print(2*r+1)

Submission status: Accepted

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

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


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

if d1+d2 == 0:
    print("infinity")
    sys.exit()
else:
    if d1 > 0 and d2 > 0:
        print(0)
        sys.exit()
    elif d1 < 0 and d2 < 0:
        print(0)
        sys.exit()

    if abs(d1) < abs(d2):
        S = d1 # 初期位置
        d1,d2 = d2,d1
    else:
        S = 0

    if d1 < 0:
        d1 *= -1
        d2 *= -1
        S  *= -1

    # print(S,d1,d2)

    d = d1 + d2
    OK = 0
    NG = 10**100
    while NG-OK > 1:
        mid = (NG+OK)//2
        if mid*d + S <= 0:
            OK = mid
        else:
            NG = mid

    if d*OK + S == 0:
        print(OK*2)
    else:
        print(OK*2+1)

Submission status: Accepted

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

a = (A1-B1)*T1
b = (A2-B2)*T2

if a<0:
  a,b = -a,-b
  
#print(a,b)
  
if a+b>0:
  print(0)

elif a+b ==0:
  print('infinity')

elif a+b<0:
  #print(a//(-b-a),a%(-b-a))
  print(2 *(a//(-b-a)) + bool(a%(-b-a)))

Submission status: Accepted

Solution code:
def main():
    t1,t2 = map(int,input().split())
    a1,a2 = map(int,input().split())
    b1,b2 = map(int,input().split())
    A1 = a1*t1
    A2 = a2*t2
    B1 = b1*t1
    B2 = b2*t2
    A3 = A1+A2
    B3 = B1+B2
    if A3 == B3:
        print("infinity")
    elif A1 < B1 and A3 < B3:
        print(0)
    elif A1 > B1 and A3 > B3:
        print(0)
    elif A3 < B3:
        gap = B3-A3
        x = A1-B1
        num = x//gap
        ans = num*2+1
        if x%gap == 0:
            ans -= 1
        print(ans)
    elif A3 > B3:
        gap = A3-B3
        x = B1-A1
        num = x//gap
        ans = num*2+1
        if x%gap == 0:
            ans -= 1
        print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a1 * t1 + a2 * t2 < b1 * t1 + b2 * t2:
    a1, a2, b1, b2 = b1, b2, a1, a2

if a1 > b1:
    print(0)
    exit()

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

if x % y == 0:
    print(x // y * 2)
else:
    print(x // y * 2 + 1)

Submission status: Accepted

Solution code:
t,T = map(int,input().split())
a,A = map(int,input().split())
b, B = map(int,input().split())
p = a*t+A*T
q = b*t+B*T
if p == q:
    print('infinity')
elif p > q:
    if a > b:
        print(0)
    else:
        ans = 1
        r = p - q
        s = b*t - a*t
        m = s//r
        ans += 2*m
        if s%r == 0:
            ans -= 1
        print(ans)
else:
    if b > a:
        print(0)
    else:
        ans = 1
        r = q - p
        s = a*t - b*t
        m = s//r
        ans += 2*m
        if s%r == 0:
            ans -= 1
        print(ans)

Submission status: Accepted

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

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return list(map(proc, rl().split()))
    else:
        return rl().split()

def main():
    t1, t2 = srl(int)
    a1, a2 = srl(int)
    b1, b2 = srl(int)
    if a1 < b1:
        a1, b1 = b1, a1
        a2, b2 = b2, a2
    if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
        print('infinity')
        return
    elif a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2:
        print('0')
        return
    s1 = a1*t1 - b1*t1
    s2 = a1 * t1 + a2 * t2 - b1 * t1 - b2 * t2
    s2 = -s2
    b = int(s1 % s2 == 0)
    k = s1 // s2 + 1
    print(2*k-1-b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
else:
    dis1 = t1 * (a1 - b1)
    dis2 = t1 * (a1 - b1) + t2 * (a2 - b2)
    if dis1 * dis2 > 0:
        print(0)
    else:
        if dis1 % dis2 == 0:
            print((-dis1 // dis2) * 2)
        else:
            print((-dis1 // dis2 + 1) * 2 - 1)

Submission status: Accepted

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

sa = a1 * t1 + a2 * t2
sb = b1 * t1 + b2 * t2

if sa == sb:
	print("infinity")
	exit()

# a is faster
if sa < sb:
	a1, a2, b1, b2 = b1, b2, a1, a2
	sa, sb = sb, sa
delta = sa - sb

# no meeting
if a1 > b1:
	print(0)
	exit()

# count the meeting in T1 period
cnt = (b1 - a1) * t1 // delta

# count the meeting in T2 period
cnt += (b1 - a1) * t1 // delta + 1

# common one
if (b1 - a1) * t1 % delta == 0:
	cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    min, max = 0, 1000000000000000
    while max - min > 1:
        mid = (min + max) // 2
        dest = w * mid
        ok = False
        for i in range(2):
            dest += d[i] * t[i]
            if dest <= 0:
                ok = True
        if ok:
            min = mid
        else:
            max = mid
    now = w * (min - 10)
    ans = 2 * (min - 10) - 1
    if ans < 0:
        ans = 0
        now = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)

Submission status: Accepted

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

if a1 < 0:
	a1 = -a1
	a2 = -a2

# assert a1 > 0

if a2 > 0:
	print(0)
	quit()

# assert a2 < 0

d = a1*t1+a2*t2

if d > 0:
	print(0)
	quit()

ans = ((a1*t1-1)//(-d)+1)*2-1
if a1*t1%(-d) == 0:
	ans += 1
print(ans)

Submission status: Accepted

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

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

DA=(T1*A1,T2*A2)
DB=(T1*B1,T2*B2)

if sum(DA)==sum(DB):
    print("infinity")
    sys.exit()

if DA[0]>DB[0]:
    DA,DB=DB,DA

if sum(DA)<sum(DB):
    print(0)
    sys.exit()

rep=(DB[0]-DA[0])//(sum(DA)-sum(DB))
minus=0
if (DB[0]-DA[0])%(sum(DA)-sum(DB))==0:
    minus=1
print(rep*2+1-minus)

Submission status: Accepted

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
    l = 0
    r = 10**100
    A = t[0]*a[0]+t[1]*a[1]
    while r-l > 1:
        m = (l+r) >> 1
        x = m*A
        y = x+t[0]*a[0]
        if x*y <= 0:
            l = m
        else:
            r = m
    ans = r*2-1
    if l*A+t[0]*a[0] == 0:
        ans -= 1
    print(ans)
    return

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

Submission status: Accepted

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

if A[0] > B[0]:
  A, B = B, A

if A[1] < B[1]:
  print(0)
  exit()

d = (B[0] - A[0]) * T[0]
k = (A[1] - B[1]) * T[1] - d

if k < 0:
  print(0)
  exit()

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

ans = 1 + (d // k) * 2
if d // k == d / k:
  ans -= 1

print(ans)

Submission status: Accepted

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

A, B = A1 * T1 + A2 * T2, B1 * T1 + B2 * T2
if A < B:
    print(0)
elif A == B:
    print("infinity")
else:
    c = 0
    l = 0
    r = 1<<100
    while r - l > 1:
        m = (l+r) // 2
        if B * (m-1) + B1 * T1 > A * (m-1) + A1 * T1:
            l = m
            c = 1
        elif B * (m-1) + B1 * T1 == A * (m-1) + A1 * T1:
            l = m
            c = 0
        else:
            r = m
    print((l-1) * 2 + c)

Submission status: Accepted

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

ng = "infinity"

first = t1 * a1 - t1 * b1
second = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2

if second == 0:
    print(ng)
    exit()

if first * second > 0:
    print(0)
    exit()

if first < 0:
    first *= -1
    second *= -1
second *= -1
ans = 2 * (first // second) + 1
if first % second == 0:ans -=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

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

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

if(d1*d2>0 or abs(d1)>abs(d2)):
    print(0)
elif(abs(d1)==abs(d2)):
    print('infinity')
else:
    if(d1 % (abs(d2)-abs(d1)) == 0):
        print(2*(abs(d1) // (abs(d2)-abs(d1))))
    else:
        print(1 + 2*(abs(d1) // (abs(d2)-abs(d1))  ))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

# 一人止める

def F(T1,T2,A1,A2):
    if A1 == 0:
        return 'infinity'
    if A1 < 0:
        A1 = -A1
        A2 = -A2
    if A2 >= 0:
        return 0
    R = T1 * A1
    L = T2 * (-A2)
    dx = R - L
    if dx == 0:
        return 'infinity'
    if dx > 0:
        return 0
    dx = -dx
    ret = 2 * (R//dx) + 1
    if R % dx == 0:
        ret -= 1
    return ret

answer = F(T1,T2,A1-B1,A2-B2)
print(answer)

Submission status: Accepted

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

P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
	P *= -1
	Q *= -1

if P + Q < 0:
	print(0)
elif P + Q == 0:
	print("infinity")
else:
	S = (-P) // (P + Q)
	T = (-P) % (P + Q)
	if T != 0:
		print(S * 2 + 1)
	else:
		print(S * 2)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = inpl()
b = inpl()
if (a[0] > b[0] and a[1] > b[1]) or (a[0] < b[0] and a[1] < b[1]):
    print(0)
    quit()
c = [0,0]
for i in range(2):
    c[i] = abs(a[i]-b[i]) * t[i]
if c[0] == c[1]:
    print('infinity')
    quit()
if c[0] > c[1]:
    print(0)
else:
    sa = c[1]-c[0]
    if c[1]%sa:
        tmp = 1
    print((c[1]-1)//(c[1]-c[0])*2 - tmp)

Submission status: Runtime Error

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


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D1+D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        assert 1==2

Submission status: Runtime Error

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


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        assert 1==2

Submission status: Runtime Error

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


if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2
D1=(A1-B1)*T1
D2=(A2-B2)*T2

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

Submission status: Runtime Error

Solution code:
from math import *
from cmath import rect

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=[0]*(K+1)
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  P+=knapsack(X)[K]
print(P)

Submission status: Runtime Error

Solution code:
ans = ''
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))

Submission status: Runtime Error

Solution code:
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: Runtime Error

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) or d1*d2>0
    print(0)
    exit()

dif = abs(d2) - abs(d1)

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

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  long long int T1, T2, A1, A2, B1, B2, tmp;
  scanf("%lld%lld", &T1, &T2);
  scanf("%lld%lld", &A1, &A2);
  scanf("%lld%lld", &B1, &B2);

  long long int Dt1=0, Dt2=0, ans=0;
  Dt1 = A1*T1 - B1*T1;
  Dt2 = Dt1 + A2*T2 - B2*T2;

  // do not meet
  if(Dt1*Dt2 > 0){
    std::cerr << "Answer: do not meet" << std::endl;
    std::cout << 0 << std::endl;
  }
  // meet infinite times
  else if(Dt1*Dt2 == 0){
    std::cerr << "Answer: meet infinite times" << std::endl;
    std::cout << "infinity";
  }
  // meet finite times
  else{
    Dt1 = std::abs(Dt1);
    Dt2 = std::abs(Dt2);

    tmp = Dt1/Dt2;
    if((Dt1%Dt2) == 0){
      ans = 2*tmp;
    }
    else{
      ans = 2*tmp+1;
    }

    std::cerr << "Answer: meet finite times" << std::endl;
    std::cout << ans << std::endl;
  }

  return 0;
  
}

Submission status: Runtime Error

Solution code:
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
     
    P = (A1 - B1) * T1
    Q = (A2 - B2) * T2
    if P > 0:
    	P *= -1
    	Q *= -1
     
    if P + Q < 0:
    	print(0)
    elif P + Q == 0:
    	print("infinity")
    else:
    	S = (-P) // (P + Q)
    	T = (-P) % (P + Q)
    	if T != 0:
    		print(S * 2 + 1)
    	else:
    		print(S * 2)

Submission status: Runtime Error

Solution code:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print(2*round(((B1-A1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif))<1e-20:
            print(2*round(((A1-B1)*T1)/abs(dif)))
        else:
            print(2*k+1)
    else:
        print(0)

Submission status: Runtime Error

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

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print('infinity')
elif (A1-B1)*T1/((A1-B1)*T1+(A2-B2)*T2) > 0:
    print(0)    
else:
    n = abs((A1-B1)*T1/((A1-B1)*T1+(A2-B2)*T2))
    meet = math.ceil(n) + int(n)
print(meet)

Submission status: Runtime Error

Solution code:
import math

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

if (A1 - B1) * T1 + (A2 - B2) * T2 == 0:
    print("infinity")
else:
    D1, D2 = (A1 - B1) * T1, (A2 - B2) * T2
    if (D1 > 0) == (D1 + D2 > 0):
        print(0)
    else:
        print(1 + 2 * math.floor(abs(D1) / (abs(D1 + D2) - 1)) + (D1 % D2 == 0))

Submission status: Runtime Error

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

#Bを固定すると、T1秒にT1(A1-B1)、T2秒にT2(A2-B2)メートルAが動く。
#何をもって無限回とするかが難しいポイント

met = [T1*(A1-B1), T2*(A2-B2)]
#met[0]とmet[1]の絶対値量が等しければ無限回
#met[0]の方がmet[1]より絶対値量が大きい時、0

absmet0 = abs(met[0])
c = abs(met[0] + met[1])
count = 0

if c == 0:
  print("infinity")
elif abs(met[0]) > abs(met[1]):
  print(0)
elif absmet0 // c == 0 and absmet0 > c:
  count == absmet0 * 2 / c 
  print(count)
else:
  count = (absmet0 // (c-1)) * 2 + 1
  print(count)

Submission status: Runtime Error

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

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2

if dis1 == -dis2:
    print("infinity")

elif (dis1<0 and dis2<0) or (dis1>0 and dis2>0):
    print("0")

else:
    S = abs(dis1//(dis1+dis2))
    R = abs(dis1%(dis1+dis2)) 
    if rem == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(ans)

Submission status: Runtime Error

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

s1=abs(a1-b1)
s2=abs(a2-b2)

if s1*t1==s2*t2:
    print("infinity")
elif s1*t1>s2*t2:
    print(0)
else:
    syokichi=s1*t1
    sabun=(s2*t2)-(s1*t1)
    if syokihi%sabun==0:
      print(2*syokichi//sabun)
    else:
      print(2*syokichi//sabun+1)

Submission status: Runtime Error

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

s1=abs(a1-b1)
s2=abs(a2-b2)

if s1*t1==s2*t2:
    print("infinity")
elif s1*t1>s2*t2:
    print(0)
else:
    syokichi=s1*t1
    sabun=(s2*t2)-(s1*t1)
    if syokihi%sabun==0:
      print(2*syokichi//sabun+1)
    else:
      print(2*syokichi//sabun)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]

if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
#    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0 and abs(y)%(x+y)==0:
    print((abs(y)//(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]

if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
#    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0 and abs(y)%(x+y)==0
    print((abs(y)//(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
#    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0:
    print((abs(y)//(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
#    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0:
    print((abs(y)//(x+y))*2+[0,3][abs(y)%(x+y)>0])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
#    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0:
    print((abs(y)//(x+y))*2+[0,2][abs(y)%(x+y)>0])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
#elif (x<0 and y<0) or (x>0 and y>0):
#    print(0)
#elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
#    print(1)

#elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
#elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
#elif x>0 and x+y<0:
#    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y>0:
    print((abs(y)//(x+y))*2[0,2][abs(y)%(x+y)>0])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>0])
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
elif x>0 and x+y<0:
    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
#elif x>0 and x+y>0:
#    print((abs(y)//(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
elif x>0 and x+y<0:
    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
elif x>0 and x+y<0:
    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
elif x>0 and x+y<0:
    print((x//abs(x+y))*2+[0,1][x%abs(x+y)>0])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
elif x<0 and x+y<0:
    print((y//abs(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
#elif x<0 and x+y>0: OKOK
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
elif x<0 and x+y<0:
    #print((y//abs(x+y))*2+[0,1][y%abs(x+y)>1])
    print((y//abs(x+y))*2)
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
#elif x<0 and x+y>0: OKOK
#    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
elif x<0 and x+y<0:
    print((y//abs(x+y))*2+[0,1][y%abs(x+y)>1])
else:
    print(hhh)

Submission status: Runtime Error

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
x,y=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
#print(x,y,abs(x)<abs(y))
#exit()
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(0)
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(1)
elif x<0 and x+y>0:
    print((abs(x)//(x+y))*2+[0,1][abs(x)%(x+y)>1])
#elif x>0 and x+y<0:
#    print((abs(y)//abs(x+y))*2+[0,1][abs(y)%abs(x+y)>1])
else:
    print(hhh)