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

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)//(x+y))*2+[0,1][abs(y)%(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])
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]]
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-1)
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]]
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-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]]
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(y//(x+y)*2-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]]
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+y>0) or (x>0 and x+y<0):
elif (x<0 and x+(x+y)>0) or (x>0 and x+(x+y)<0):
    print(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]]
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+y>0) or (x>0 and x+y<0):
    print(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)
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+y>0:
    print(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]]
if x+y==0:
    print("infinity")
elif (x<0 and y<0) or (x>0 and y>0):
    print(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]
w=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
if sum(w)==0:
    print(w[9])
    #print("infinity")
else:
    print("infinity")
    #print(w[9])

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]
w=[(a[0]-b[0])*t[0],(a[1]-b[1])*t[1]]
if sum(w)==0:
    print("infinity")
else:
    print(w[9])

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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if w[-1]==0:
        print("infinity")
        exit()
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]>0 and w[3]>0) or (w[0]<0 and w[1]>0 and w[2]<0 and w[3]<0):
            print(2)
            exit()
#print(w)
#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
#x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
x,y=(w[0]//abs(w[2]-w[0]),w[1]//abs(w[3]-w[1]))
#if w[0]<w[2] and w[1]<w[3] and w[0]<0:
if w[0]<w[2] and w[1]<w[3] and x<0:
    print(-x*2-1)
#elif w[0]<w[2] and w[1]<w[3] and w[0]>0:
elif w[0]<w[2] and w[1]<w[3] and y<0:
    print(-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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if w[-1]==0:
        print("infinity")
        exit()
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]>0 and w[3]>0) or (w[0]<0 and w[1]>0 and w[2]<0 and w[3]<0):
            print(2)
            exit()
#print(w)
#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
#x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
x,y=(w[0]//(w[2]-w[0]),w[1]//(w[3]-w[1]))
#if w[0]<w[2] and w[1]<w[3] and w[0]<0:
if w[0]<w[2] and w[1]<w[3] and x<0:
    print(-x*2-1)
#elif w[0]<w[2] and w[1]<w[3] and w[0]>0:
elif w[0]<w[2] and w[1]<w[3] and y<0:
    print(-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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if w[-1]==0:
        print("infinity")
        exit()
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]>0 and w[3]>0) or (w[0]<0 and w[1]>0 and w[2]<0 and w[3]<0):
            print(2)
            exit()
#print(w)
#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
if w[0]<w[2] and w[1]<w[3] and w[0]<0:
    print(x*2-1)
elif w[0]<w[2] and w[1]<w[3] and w[0]>0:
    print(x*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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if w[-1]==0:
        print("infinity")
        exit()
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]>0 and w[3]>0) or (w[0]<0 and w[1]>0 and w[2]<0 and w[3]<0):
            print(2)
            exit()
print(w)
#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
if w[0]<w[2] and w[1]<w[3] and w[0]<0:
    print(x*2-1)
elif w[0]<w[2] and w[1]<w[3] and w[0]>0:
    print(x*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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if w[-1]==0:
        print("infinity")
        exit()
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):
            print(0)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)
            exit()
        elif (w[0]>0 and w[1]<0 and w[2]>0 and w[3]>0) or (w[0]<0 and w[1]>0 and w[2]<0 and w[3]<0):
            print(2)
            exit()
#print(w)
#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
if w[0]<0 and x>y:
    print(x*2-1)
elif w[0]<0 and x<y:
    print(x*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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if i==3:
        if len(set(w))!=4:
            #print("infinity")
            print(ans)
            exit()
        chk=0
        #print(ans)
        print("infinity")

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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        print(ans)
        exit()

Submission status: Runtime Error

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:
  A1=a
  A2=b
  B1=c
  B2=d
elif T1*a+T2*b<T1*c+T2*d:
  A1=c
  A2=d
  B1=a
  B2=b
else:ans="infinity"
t=-(T1+T2*(B2-A2)/(B1-A1))
if t<0 : ans=0
ans=(2*int(T1//t))+1
print(ans)

Submission status: Runtime Error

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:
  A1=a
  A2=b
  B1=c
  B2=d
elif T1*a+T2*b<T1*c+T2*d:
  A1=c
  A2=d
  B1=a
  B2=b
else:ans="infinity"
t=-(T1+T2*(B2-A2)/(B1-A1))
ans=2*int(T1//t)+1
print(ans)

Submission status: Runtime Error

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:
  A1=a
  A2=b
  B1=c
  B2=d
elif T1*a+T2*b<T1*c+T2*d:
  A1=c
  A2=d
  B1=a
  B2=b
else:ans="infinity"
t=-(T1+T2*(B2-A2)/(B1-A1))
if A1>B1 : x=0
else : x=1
ans=2*int(T1//t)+x
print(ans)

Submission status: Runtime Error

Solution code:
T1,T2 = map(int, input().split())
a,b = map(int, input().split())
c,d = map(int, input().split())
if T1*a+T2*c>T1*b+T2*d:
  A1=a
  B1=c
  A2=b
  B2=d
elif T1*a+T2*c<T1*b+T2*d:
  A1=b
  B1=d
  A2=a
  B2=c
else:ans="infinity"
t=-(T1+T2*(B2-A2)/(B1-A1))
if A1>A2 : x=0
else : x=1
ans=2*int(T1//t)+x
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())
#t1で生まれる差
P = (a1 - b1) * t1
#t2で生まれる差
Q = (a2 - b2) * t2
#P < 0 のことを仮定する
if P > 0:
    P *= -1
    Q *= -1

if P + Q < 0:
    print(0)
elif P == Q:
    print("infinity")
else:
    #つぎのPを足したときに、負にいくかどうか？
    if (-P) % (P + Q) == 0:
        print(2 * ((-P) // (P + Q)) + 2)
    else:
        print(2 * ((-P) // (P + Q)) + 1)

Submission status: Runtime Error

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





	
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:
            print(   (-2* delta0) // (delta0 + delta1)    + int(  (- delta0) / (delta0 + delta1) != 0)  )
            sys.exit()

    else:
        print(0)
        sys.exit()

Submission status: Runtime Error

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

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    if a-1 not in X:
        print(0)
        exit()
    idx = X.index(a-1)
    X[idx] += 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()))
x,y=(a1-b1)*t1 + (a2-b2)*t2, (a1-b1)*t1
if x == 0:
    print("infinity")
elif x*y > 0:
    print(0)
else:
    s,t = divmod(abs(y), abs(x))
    print(s*2+1 if t else 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())

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

import sys
if d1+d2 == 0:
    print('infinity')
    sys.exit()
elif d1*d2 > 0 or (abs(d1)-abs(d2)>0 and d1*d2<0):
    print(0)
    sys.exit()
    
else:
    start = abs(d1)
    delta = abs(d2+d1)
    ans = start//delta * 2
    elif (start%delta)!=0:
        ans += 1
    print(ans)

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 = (A[0]-B[0])*T[0]
y = (B[0]-A[0])*T[0] + (B[1]-A[1])*T[1]

if x < 0:
    x *= -1
    y *= -1
if y == 0:
    print('infinity')
ans = -(-x//y)*2-1
if x%y == 0:
    ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
T = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = (A[0]-B[0])*T[0]
y = (B[0]-A[0])*T[0] + (B[1]-A[1])*T[1]

if x < 0:
    x *= -1
    y *= -1

ans = -(-x//y)*2-1
if x%y == 0:
    ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, 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:
        if a % b == 0:
            print(((a//b)*2)
        else:
            print((a//b)*2 + 1)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, 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:
        if a % b == 0:
            print((a*2)//b)
        else:
            print(((a//b)*2 + 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())
if a1*t1+a2*t2==b1*t1+b2*t2:
  print('infinity')
elif (a1-b1)*(a2-b2)>0:
  print(0)
else:
  x=0
  a=abs(a1*t1-b1*t1)
  b=abs(a1*t1+a2*t2-b1*t1-b2*t2)
  if a%b=0:
    c=1
  else:
    c=0
  print(-(-a//b)+a//b-c)

Submission status: Runtime Error

Solution code:
import sys
def main():
    t1, t2, a1, a2, b1, b2 = map(int, sys.stdin.read().split())
    A1 = t1 * a1
    A2 = t2 * a2
    B1 = t1 * b1
    B2 = t2 * b2

    d = abs(A1 + A2 - B1 - B2)
    if A1 == B1:
        ans = 0
    elif A1 > B1:
        if A1 + A2 > B1 + B2:
            ans = 0
        elif A1 + A2 == B1 + B2:
            ans = 'infinity'
        else:
            (A1 - B1) // d * 2 + 1

    
    elif A1 < B1:
        if A1 + A2 < B1 + B2:
            ans = 0
        elif A1 + A2 == B1 + B2:
            ans = 'infinity'
        else:
            ans = (B1 - A1) // d * 2 + 1

    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
T1, T2 = input().split(" ")
T1, T2 = int(T1), int(T2)

A1, A2 = input().split(" ")
A1, A2 = int(A1), int(A2)

B1, B2 = input().split(" ")
B1, B2 = int(B1), int(B2)

from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

def doit(T1, T2, A1, A2, B1, B2):
	T = np.arange(0, lcm(T1, T2))
	VA = np.zeros_like(T)
	VB = np.zeros_like(T)
	for i in range(lcm(T1, T2) / T1):
		if i % 2 == 0:
			VA[T1 * i : T1 * (i+1)] = A1
		else:
			VA[T1 * i : T1 * (i+1)] = A2
	for i in range(lcm(T1, T2) / T2):
		if i % 2 == 0:
			VB[T2 * i : T2 * (i+1)] = B1
		else:
			VB[T2 * i : T2 * (i+1)] = B2

	counter = 0
	RelPos = np.zeros_like(T)
	for it, t in enumerate(T[:-1]):
		RelPos[it+1] = RelPos[it] + 1 * (VA[it] - VB[it])
		if RelPos[it] * RelPos[it+1] <= 0:
			counter += 1

	if RelPos[-1] == 0:
		counter = "infinity"
	else:
		if RelPos[-1] < 0:
			v = RelPos[-1] / lcm(T1, T2)
			if floor(np.max(RelPos) / v) != np.max(RelPos) / v:
				counter += counter * floor(np.max(RelPos) / v)
			else:
				conter += counter * floor(np.max(RelPos) / v) - 1
		elif RelPos[-1] > 0:
			v = RelPos[-1] / lcm(T1, T2)
			if floor(np.min(RelPos) / v) != np.min(RelPos) / v:
				counter += counter * floor(np.min(RelPos) / v)
			else:
				counter += counter * floor(np.min(RelPos) / v) - 1
	return counter

print(doit(T1, T2, A1, A2, B1, B2))

Submission status: Runtime Error

Solution code:
T1, T2 = input().split(" ")
T1, T2 = int(T1), int(T2)

A1, A2 = input().split(" ")
A1, A2 = int(A1), int(A2)

B1, B2 = input().split(" ")
B1, B2 = int(B1), int(B2)

from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

def doit(T1, T2, A1, A2, B1, B2):
	T = np.arange(0, lcm(T1, T2))
	VA = np.zeros_like(T)
	VB = np.zeros_like(T)
	for i in range(lcm(T1, T2) / T1):
		if i % 2 == 0:
			VA[T1 * i : T1 * (i+1)] = A1
		else:
			VA[T1 * i : T1 * (i+1)] = A2
	for i in range(lcm(T1, T2) / T2):
		if i % 2 == 0:
			VB[T2 * i : T2 * (i+1)] = B1
		else:
			VB[T2 * i : T2 * (i+1)] = B2

	counter = 0
	RelPos = np.zeros_like(T)
	for it, t in enumerate(T[:-1]):
		RelPos[it+1] = RelPos[it] + 1 * (VA[it] - VB[it])
		if RelPos[it] * RelPos[it+1] <= 0:
			counter += 1

	if RelPos[-1] == 0:
		return "infinity"
	else:
		if RelPos[-1] < 0:
			v = RelPos[-1] / lcm(T1, T2)
			if floor(np.max(RelPos) / v) != np.max(RelPos) / v:
				counter += counter * floor(np.max(RelPos) / v)
			else:
				conter += counter * floor(np.max(RelPos) / v) - 1
	return counter
  
print(doit(T1, T2, A1, A2, B1, B2))

Submission status: Runtime Error

Solution code:
import math

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

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod(halfB - halfA, sumA - sumB)
  if mod == 0
    return div * 2
  return div * 2 + 1

print(main())

Submission status: Runtime Error

Solution code:
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("infinity");exit()
if a*b>=0:print(0);exit()
x,y=abs(a-b),abs(a+b)
print(x,y)
print(int(0--(x)//y)-0.5)-1)

Submission status: Runtime Error

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((((-2* delta0) / ((delta0 + delta1)))  + int(((-2* delta0) / ((delta0 + delta1)) != 0)))
			
		

	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(2*delta0 / (-(delta0 + delta1)))  + int(((-2* delta0) / ((delta0 + delta1)) != 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())

len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
  print("infinity")
  quit()

ans = 0
subs = 0  
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
X = [1, 1]
i = 0
while (X != [0, 0]):
  i += 1
  if subs != 0:
    if (subs + sub1)(subs) <= 0:
      ans += 1
      X[0] = 1
    else:
      X[0] = 0
  subs = subs + sub1
  if subs != 0:
    if subs(subs + sub2) <= 0:
      ans += 1
      X[1] = 1
    else:
      X[1] = 0
  subs = subs + sub2

print(ans)

Submission status: Runtime Error

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

la1 = A[0] * T[0]
la2 = A[1] * T[1]
lb1 = B[0] * T[0]
lb2 = B[1] * T[1]
la = la1 + la2
lb = lb1 + lb2

if la == lb:
    print("infinity")

d = abs(la - lb)
l_count = abs(la1 - lb1) // d
print(l_count*2+1)

Submission status: Runtime Error

Solution code:
import math

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

  sumA = t1 * a1 + t2 * a2
  sumB = t1 * b1 + t2 * b2

  if sumA == sumB:
    return 'infinity'
  if sumA < sumB:
    sumA, sumB = sumB, sumA
    a1, b1 = b1, a1
    a2, b2 = b2, a2
  # A の方が sum が大きいとする

  halfA = t1 * a1
  halfB = t1 * b1
  if halfA > halfB:
    return 0
  div, mod = divmod((halfB - halfA) // (sumA - sumB))
  if mod == 0
    return div * 2
  return div * 2 + 1

print(main())

Submission status: Runtime Error

Solution code:
def main():
	t = map(int, input().split())
	a = map(int, input().split())
	b = map(int, input().split())
	
	d_0_a = a[0]*t[0]
	d_1_a = a[1]*t[1]
	d_0_b = b[0]*t[0]
	d_1_b = b[1]*t[1]
	
	d_ave_a = d_0_a+d_1_a
	d_ave_b = d_0_b+d_1_b
	
	if d_ave_a == d_ave_b:
		return 'infinity'
	
	diff_0 = d_0_a - d_0_b
	diff_1 = d_1_a - d_1_b
	diff_ave = d_ave_a - d_ave_b
	
	if diff_0*diff_1 > 0:
		return 0
		
	diff_diff_0 = diff_ave + diff_0
	diff_diff_1 = diff_ave + diff_1
	
	if diff_0*diff_ave < 0:
		return -diff_diff_0//diff_ave + 1
	else:
		return -diff_diff_1//diff_ave + 1
	
	
if __name__ == '__main__':
	print(main())

Submission status: Runtime Error

Solution code:
# your code goes here
import itertools
 
num = int(input())
arr = input()
 
lens = len(arr)
 
mat = []
 
c = list(itertools.combinations(list(arr), num-3))
 
mat = list(set(c))
 
print(len(mat))

Submission status: Runtime Error

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

count=0

X = T1*A1
Y = T1*B1

for i in 10000000000:
    if count%2 == 0:
        X1 = T2*A2
        Y1 = T2*B2
        X = X + X1
        Y = Y + Y1
        if X <= Y:
            count = count + 1   
        else:
            break
    elif count%2 == 1:
        X1 = T1*A1
        Y1 = T1*B1
        X = X + X1
        Y = Y + Y1
        if X >= Y:
            count = count + 1   
        else:
            break

if count == 10000000000:
    print('infinity')
else:
    print(count)

Submission status: Runtime Error

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

if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif ((A1>B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)>0)) or ((A1<B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)<0)):
    print(0)
else:
    d=T1*A1+T2*A2-(T1*B1+T2*B2)#T1+T2だけ走った後離れている距離
    if abs(T1*(A1-B1))%d==0:
        ss=1
    print(abs(T1*(A1-B1))//d*2-ss+1)

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]
w=[]
for i in range(4):
    p.append(p[-1]+a[i%2]*t[i%2])
    q.append(q[-1]+b[i%2]*t[i%2])
    w.append(p[i+1]-q[i+1])
    if i==3:
        if len(set(w))!=4:
            print("infinity")
            exit()
        chk=0
        if (w[0]>0 and w[1]>0) or (w[0]<0 and w[1]<0):]
            print(0)
        elif (w[0]>0 and w[1]<0 and w[2]<0) or (w[0]<0 and w[1]>0 and w[2]>0):
            print(1)

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())
dis=abs(a1-b1)*t1
oi=abs(a2-b2)*t2
if oi==0:
    print("infinity")
else:
    print(math.ceil(dis/abs(oi-dis))

Submission status: Runtime Error

Solution code:
t1,t2 = list(map(int, input().split()))
a1,a2 = list(map(int, input().split()))
b1,b2 = list(map(int, input().split()))
x=(a1-b1)*t1 + (a2-b2)*t2
if x == 0:
    print("infinity")
if x*(a1-b1) > 0:
    print(0)
else:
    s,t = divmod(abs((a1-b1)*t1), abs(x))
    if t:
        print(s*2+1)
    else:
        print(s*2)

Submission status: Runtime Error

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 = '11145147'
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: Runtime Error

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

count=0

X = T1*A1
Y = T1*B1

for i in 10000000000:
    if count%2 == 0:
        X1 = T2*A2
        Y1 = T2*B2
        X = X + X1
        Y = Y + Y1
        if X <= Y:
            count = count + 1   
        else:
            break
    if count%2 == 1:
        X1 = T1*A1
        Y1 = T1*B1
        X = X + X1
        Y = Y + Y1
        if X <= Y:
            count = count + 1   
        else:
            break

if count == 10000000000:
    print('infinity')
else:
    print(count)

Submission status: Runtime Error

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

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

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

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

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

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

    print(ans*2+1)

    # calc


if __name__ == '__main__':
    main()

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

count=0

X = T1*A1
Y = T1*B1

for i in math.inf:
    if count%2 == 0:
        X1 = T2*A2
        Y1 = T2*B2
        X = X + X1
        Y = Y + Y1
        if X <= Y:
            count = count + 1   
        else:
            break
    if count%2 == 1:
        X1 = T1*A1
        Y1 = T1*B1
        X = X + X1
        Y = Y + Y1
        if X <= Y:
            count = count + 1   
        else:
            break

if count == math.inf:
    print('infinity')
else:
    print(count)