Problem:


Score: 600 points

Problem Statement

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

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

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

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

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

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

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

If they meet infinitely many times, print infinity instead.  

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

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

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

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

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

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



Sample input:
1 2
10 10
12 4


Sample output:
1

Submission status: Wrong Answer

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
w=[]
ans=0
r=-1
for i in range(100000):
    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 r==-1:
        if w[-1]>0: r=1
        else: r=0
    elif w[-1]>0 and r==1:
        break
    elif w[-1]>0 and r==0:
        r=1
        ans+=1
    elif w[-1]<0 and r==0:
        break
    elif w[-1]<0 and r==1:
        r=0
        ans+=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)
            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(ans)

Submission status: Wrong Answer

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
p,q=[0],[0]
w=[]
ans=0
r=-1
for i in range(10000):
    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 r==-1:
        if w[-1]>0: r=1
        else: r=0
    elif w[-1]>0 and r==1:
        break
    elif w[-1]>0 and r==0:
        r=1
        ans+=1
    elif w[-1]<0 and r==0:
        break
    elif w[-1]<0 and r==1:
        r=0
        ans+=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)
            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(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())

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)
    print(2*syokichi//sabun+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()))
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)
            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(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*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()))
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)
            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)
        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(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*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()))
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)
            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()


#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
#x=max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2
x,y=(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))
print(x*2-1 if x>y else y*2)

Submission status: Wrong Answer

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

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)
    print(2*syokichi//sabun)

Submission status: Wrong Answer

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


#print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)
x=max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2
print(x-1 if a[0]<b[0] else x)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:
    print('infinity')
    exit()
if (A1 > B1 and A1 + A2 > B1 + B2) or (A1 < B1 and A1 + A2 < B1 + B2):
    print(0)
    exit()
diff = abs(A1-B1) * T1
diff2 = abs(T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2))
x, y = divmod(diff, diff2)
print(x * 2 if y == 0 else x * 2 + 1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:
    print('infinity')
    exit()
if (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
    print(0)
    exit()
diff = abs(A1-B1) * T1
diff2 = abs(T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2))
x, y = divmod(diff, diff2)
print(x * 2 if y == 0 else x * 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()))
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)
            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()


print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*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()))
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)


print(max(abs(w[0]//(w[2]-w[0])),abs(w[1]//(w[3]-w[1])))*2-1)

Submission status: Wrong Answer

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


def main():
    T1, T2 = [int(x) for x in input().split()]
    A1, A2 = [int(x) for x in input().split()]
    B1, B2 = [int(x) for x in input().split()]

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

    if (T1 * A1) > (T1 * B1) and (T2 * A2) > (T2 * B2):
        print("0")
        return

    if (T1 * A1) < (T1 * B1) and (T2 * A2) < (T2 * B2):
        print("0")
        return

    x = abs((T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2))
    y = abs((T1 * A1) - (T1 * B1))
    count = (y // x) * 2
    if y % x != 0:
        count += 1
    print(count)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
T1,T2 = map(int, input().split())
A1,A2 = map(int, input().split())
B1,B2 = map(int, input().split())
t=abs(T1+T2*(B2-A2)/(B1-A1))
if t==0:ans="infinity"
else: ans=2*int(T1//t)+1
print(ans)

Submission status: Wrong Answer

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


def main():
    T1, T2 = [int(x) for x in input().split()]
    A1, A2 = [int(x) for x in input().split()]
    B1, B2 = [int(x) for x in input().split()]

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

    if (T1 * A1) > (T1 * B1) and (T2 * A2) > (T2 * B2):
        print("0")
        return

    if (T1 * A1) < (T1 * B1) and (T2 * A2) < (T2 * B2):
        print("0")
        return

    x = abs((T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2))
    y = abs((T1 * A1) - (T1 * B1))
    count = (y // x) * 2 + 1
    print(count)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p=(a1-b1)*t1
q=(a2-b2)*t2
if p+q<0:
  print(0)
elif p+q==0:
  print('infinity')
else:
  s,t=divmod(-p,p+q)
  if t!=0:
    print(s*2+1)
  else:
    print(s*2)

Submission status: Wrong Answer

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


def main():
    T1, T2 = [int(x) for x in input().split()]
    A1, A2 = [int(x) for x in input().split()]
    B1, B2 = [int(x) for x in input().split()]

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

    count = 0
    renzoku = 0
    takahashi = 0
    aoki = 0
    i = 0
    tlead = False
    while True:
        i += 1
        if i % 2 == 1:
            takahashi += T1 * A1
            aoki += T1 * B1
        else:
            takahashi += T2 * A2
            aoki += T2 * B2
        if i == 1:
            if takahashi > aoki:
                tlead = True
            continue
        else:
            if tlead and aoki > takahashi:
                count += 1
                tlead = False
            elif not tlead and takahashi > aoki:
                count += 1
                tlead = True
            else:
                renzoku += 1
        if renzoku == 10:
            break

    print(count)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    T1, T2 = [int(x) for x in input().split()]
    A1, A2 = [int(x) for x in input().split()]
    B1, B2 = [int(x) for x in input().split()]

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

    if (T1 * A1) > (T1 * B1) and (T2 * A2) > (T2 * B2):
        print("0")
        return

    if (T1 * A1) < (T1 * B1) and (T2 * A2) < (T2 * B2):
        print("0")
        return

    count = 0
    renzoku = 0
    takahashi = 0
    aoki = 0
    i = 0
    tlead = False
    while True:
        i += 1
        if i % 2 == 1:
            takahashi += T1 * A1
            aoki += T1 * B1
        else:
            takahashi += T2 * A2
            aoki += T2 * B2
        if i == 0:
            if takahashi > aoki:
                tlead = True
            continue
        else:
            if tlead and aoki > takahashi:
                count += 1
                tlead = False
            elif not tlead and takahashi > aoki:
                count += 1
                tlead = True
            else:
                renzoku += 1
        if renzoku == 10:
            break

    print(count)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print('infinity')

Submission status: Wrong Answer

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

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    M = (B1 - A1) * T1
    d = SA - SB
    cnt = (M - 1) // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(max(0, ans))
elif SB > SA and B1 < A1:
    M = (A1 - B1) * T1
    d = SB - SA
    cnt = (M -  1) // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(max(0, 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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    M = (B1 - A1) * T1
    d = SA - SB
    cnt = (M - 1) // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(ans)
elif SB > SA and B1 < A1:
    M = (A1 - B1) * T1
    d = SB - SA
    cnt = (M -  1) // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    M = (B1 - A1) * T1
    d = SA - SB
    cnt = (M - 1) // d
    ans = cnt * 2

    if M % d != 0:
        ans += 1

    print(ans)
elif SB > SA and B1 < A1:
    M = (A1 - B1) * T1
    d = SB - SA
    cnt = (M -  1) // d
    ans = cnt * 2
    if M % d != 0:
        ans += 1
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s,t,a,b,x,y=map(int,open(0).read().split())
i=(x-a)*s
j=(b-y)*t-i
print(i//j*2+(i%j!=0)if j else'infinity')

Submission status: Wrong Answer

Solution code:
s,t,a,b,x,y=map(int,open(0).read().split())
i=(x-a)*s
j=(b-y)*t-i
print(max(0,i//j*2+(i%j>0))if j else'infinity')

Submission status: Wrong Answer

Solution code:
s,t,a,b,x,y=map(int,open(0).read().split())
i=(x-a)*s
j=(b-y)*t-i
print(j and max(0,i//j*2+(i%j>0))or'infinity')

Submission status: Wrong Answer

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

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    ans = -(-((B1 - A1) * T1) // (SA - SB)) * 2 - 1
    if (B1 - A1) % (SA - SB) == 0:
        ans -= 1
    print(ans)
elif SB > SA and B1 < A1:
    ans = -(-((A1 - B1) * T1) // (SB - SA)) * 2 - 1
    if (A1 - B1) % (SB - SA) == 0:
        ans -= 1
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB and A1 < B1:
    ans = -(-((B1 - A1) * T1) // (SA - SB)) * 2 - 1
    if (B1 - A1) % (SA - SB) == 0:
        ans -= 1
    print(ans)
elif SB > SA and B1 < A1:
    ans = -(-((A1 - B1) * T1) // (SB - SA)) * 2 - 1
    if (A1 - B1) % (SB - SA) == 0:
        ans -= 1
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB:
    if A1 < B1:
        M = (B1 - A1) * T1
        d = SA - SB
        cnt = -(-M // d)
        print(cnt * 2 - 1)
    else:
        print(0)
else:
    if A1 > B1:
        M = (A1 - B1) * T1
        d = SB - SA
        cnt = -(-M // d)
        print(cnt * 2 - 1)
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB:
    if A1 < B1:
        ans = (B1 - A1) * T1 // (SA - SB) - (1 if (B1 - A1) * T1 % (SA - SB) == 0 else 0)
        print(ans * 2 + 1)
    else:
        print(0)
else:
    if A1 > B1:
        ans = (A1 - B1) * T1 // (SB - SA) - (1 if (A1 - B1) * T1 % (SB - SA) == 0 else 0)
        print(ans * 2 + 1)
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB:
    print('infinity')
    exit()

if SA > SB:
    if A1 < B1:
        ans = (B1 - A1) * T1 // (SA - SB)
        print(ans * 2 + 1)
    else:
        print(0)
else:
    if A1 > B1:
        ans = (A1 - B1) * T1 // (SB - SA)
        print(ans * 2 + 1)
    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())

SA = T1 * A1 + T2 * A2
SB = T1 * B1 + T2 * B2

if SA == SB or A1 == B1:
    print('infinity')
    exit()

if SA > SB:
    if A1 < B1:
        ans = (B1 - A1) * T1 // (SA - SB)
        print(ans * 2 + 1)
    else:
        print(0)
else:
    if A1 > B1:
        ans = (A1 - B1) * T1 // (SB - SA)
        print(ans * 2 + 1)
    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())
Ad = A1 * T1 + A2 * T2
Bd = B1 * T1 + B2 * T2
if Ad == Bd:
    print('infinity')
else:
    if Bd > Ad:
        Ad, Bd = Bd, Ad
        A1, A2, B1, B2 = B1, B2, A1, A2
    if A1 > B1:
        print(0)
    else:
        ans = ((B1 - A1) * T1 // (Ad - Bd)) * 2 + 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())
A=[]
a=0
cnt = 0
l1=(a1-b1)*t1
l2=(a2-b2)*t2
#print(l1,l2)
#print(abs(l1-l2))
if (a1-b1)*t1>0 and (a2-b2)*t2>0:
    print('0')
elif (a1-b1)*t1<0 and (a2-b2)*t2<0:
    print('0')
elif l1+l2==0:
    print('infinity')
else:
    n=min(abs(l1),abs(l2))
    while n>=0:
        n-=abs(l1+l2)
        cnt+=1
print(cnt*2-1)
    #print(math.ceil(min(abs(l1),abs(l2))/abs(l1+l2))*2-1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

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

    s1 = T1*A1+T2*A2
    s2 = T1*B1+T2*B2

    #inf?
    if s1 == s2:
        print('infinity')
        return
    
    


    time = 0
    a = 0
    b = 0
    isT1 = True
    # 1セット
    beforewina = True if A1 > B1 else False
    afterwina = True if s1 > s2 else False
    ans = 0
    if beforewina == afterwina:
        print(0)
        return
    else:
        while True:
            preans = ans
            prea = a
            preb = b
            a += T1*A1
            b += T1*B1
            if (prea < preb and  a >= b) or (prea > preb and a <= b):
                ans += 1
            prea = a
            preb = b
            a += T2*A2
            b += T2*B2
            if (prea <= preb and  a > b) or (prea >= preb and a < b):
                ans += 1
            if ans == preans:
                break
        print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())
#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 == 0:
    print("infinity")
else:
    #つぎのPを足したときに、負にいくかどうか？
    if (-P) % (P + Q) == 0:
        print(2 * ((-P) // (P + Q)) + 2)
    else:
        print(2 * ((-P) // (P + Q)) + 1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline


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

    P = t1 * abs(b1 - a1)
    Q = t2 * abs(b2 - a2)
    if P + Q == 0:
        print("infinity")
        return
    if P * (P + Q) > 0:
        print(0)
        return
    T = P % (Q - P)
    S = P // (Q - P)
    if T == 0:
        ans = 2 * S
    else:
        ans = 2 * S + 1
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline


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

    P = t1 * abs(b1 - a1)
    Q = t2 * abs(b2 - a2)
    if P == Q:
        print("infinity")
        return
    if P * (P + Q) > 0:
        print(0)
        return
    T = P % (Q - P)
    S = P // (Q - P)
    if T == 0:
        ans = 2 * S
    else:
        ans = 2 * S + 1
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline


def main():
    t1, t2 = map(int, input().split())
    a1, a2 = map(int, input().split())
    b1, b2 = map(int, input().split())
    if (a1 - b1) * (a2 - b2) > 0:
        print(0)
        return

    P = t1 * abs(b1 - a1)
    Q = t2 * abs(b2 - a2)
    if P == Q:
        print("infinity")
        return
    T = P % (Q - P)
    S = P // (Q - P)
    if T == 0:
        ans = 2 * S
    else:
        ans = 2 * S + 1
    print(ans)


main()

Submission status: Wrong Answer

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

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

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

C1,C2=(A1-B1)*T1,(A2-B2)*T2
C3=C1+C2
#print(C1,C2,C3,C1%abs(C3))

if C3>0:
  print(0)
elif C3==0:
  print(1)
else:
  C3=abs(C3)
  if C1%C3==0:
    print(2*(C1//C3))
  else:
    print(2*(C1//C3)+1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

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

    s1 = T1*A1+T2*A2
    s2 = T1*B1+T2*B2

    #inf?
    if s1 == s2:
        print('infinity')
        return
    
    


    time = 0
    a = 0
    b = 0
    isT1 = True
    # 1セット
    beforewina = True if A1 > B1 else False
    afterwina = True if s1 > s2 else False
    ans = 0
    if beforewina == afterwina:
        print(0)
        return
    else:
        while True:
            preans = ans
            prea = a
            preb = b
            a += T1*A1
            b += T1*B1
            if (prea < preb and  a > b) or (prea > preb and a < b):
                ans += 1
            prea = a
            preb = b
            a += T2*A2
            b += T2*B2
            if (prea < preb and  a > b) or (prea > preb and a < b):
                ans += 1
            if ans == preans:
                break
        print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit()
#infの処理
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#切片
pre = 0
i = 0
change = 0
#高橋を基準にする。高橋の式は常にy = ti * ai
#青木はy = ti * bi + pre
while True:
    if i % 2 == 0:
        t = inc_ta_1
        a = inc_ao_1
    else:
        t = inc_ta_2
        a = inc_ao_2
    if pre * (a + pre - t) < 0:
        ans += 1
        change = 0
    else:
        change += 1
    if change >= 3:
        print(ans)
        exit()
    pre = (a - t + pre)
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit()
#infの処理
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
i = 0
change = 1
while True:
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
        change = 1
    else:
        if change == 0:
            print(ans)
            exit()
        change = 0
    pre = t - a
    i += 1
    i %= 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())

#infの処理
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
for i in range(10 ** 8):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
    pre = (t - a)
    if pre == 0:
        print("infinity")
        exit()
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())

#infの処理
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
for i in range(10 ** 9):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
    pre = (t - a)
    if pre == 0:
        print("infinity")
        exit()
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())

#infの処理
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit()
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
for i in range(t1 + t2 + 2):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
    #init = min(a,t)
    #a -= init
    #t -= init
    pre = (t - a)
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())

#infの処理
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit()
#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
change = True
for i in range(t1 + t2 + 2):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
    init = min(a,t)
    a -= init
    t -= init
    pre = (t - a)
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())

#infの処理
if t1 * (a1 - b1) + t2 * (a2 - b2) == 0:
    print("infinity")
    exit()
#一回も交わらない時の処理、もしかしたらいらないかも
if ( a1 > b1 and a2 > b2 )or (a1 < b1 and a2 < b2):
    print(0)
    exit()

#それ以外の処理
#増える値の設定
inc_ta_1 = t1 * a1
inc_ao_1 = t1 * b1
inc_ta_2 = t2 * a2
inc_ao_2 = t2 * b2
t = 0
a = 0
ans = 0
#さっきの高橋‐青木を計算しておく
pre = 0
change = True
for i in range(t1 + t2 + 2):
    if i % 2 == 0:
        t += inc_ta_1
        a += inc_ao_1
    else:
        t += inc_ta_2
        a += inc_ao_2
    #さっきと今の符号が違ったら交点がある
    if pre * (t - a) < 0:
        ans += 1
        change = True
    else:
        #二回連続で変わらなかったら終了
        if change == False:
            break
        change = False
    init = min(a,t)
    a -= init
    t -= init
    pre = (t - a)
print(ans)