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:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())

s1=a1-b1
s2=a2-b2

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

Submission status: Wrong Answer

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

s1=a1-b1
s2=a2-b2

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2

if a1 + a2 == b1 + b2:
    print("infinity")
    exit()
if a1 + a2 > b1 + b2:
    a1, a2, b1, b2 = b1, b2, a1, a2

diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
    print(0)
else:
    ans = (abs(mid_diff) + diff-1) // diff * 2 - 1
    if abs(mid_diff) % diff == 0:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import combinations
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

t1, t2 = [int(item) for item in input().split()]
a1, a2 = [int(item) for item in input().split()]
b1, b2 = [int(item) for item in input().split()]
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2

if a1 + a2 == b1 + b2:
    print("infinity")
    exit()
if a1 + a2 > b1 + b2:
    a1, a2, b1, b2 = b1, b2, a1, a2

diff = (b1 + b2) - (a1 + a2)
mid_diff = b1 - a1
if mid_diff > 0:
    print(0)
else:
    print((abs(mid_diff) + diff-1) // diff * 2 -1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

loc_a1 = a[0]*t[0] #T1分後のA
loc_b1 = b[0]*t[0] #T1分後のB
loc_a2 = loc_a1 + a[1]*t[1] #T2分後のA
loc_b2 = loc_b1 + b[1]*t[1] #T2分後のB
d1 = loc_a1 - loc_b1
d2 = loc_a2 - loc_b2
if d1 * d2 > 0:
  print(0)
elif d1 * d2 == 0:
  print('infinity')
else:
  if d1 > 0:
    print(1 + 2*(abs(d2)//d1))
  else:
    print(1 + 2*(abs(d1)//d2))

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:
  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(2 * s)
  else:
    print(2*s + 1)

Submission status: Wrong Answer

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

p = (a1-b1)*t1
q = (a2-b2)*t2

if p > q:
  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(2 * s)
  else:
    print(2*s + 1)

Submission status: Wrong Answer

Solution code:
def main():
    # input
    import math
    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

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

    x = abs(x)
    ans = x//diff
    remainder = x%diff
    if remainder==0:
        print(ans*2)
    else:
        print(ans*2+1)

    # calc

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    # input
    import math
    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

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

    x = abs(x)
    ans = x//diff
    remainder = x%diff
    if remainder==0:
        print(ans*2)
    else:
        print(ans*2+1)

    # calc

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    # input
    import math
    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

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

    x = abs(x)
    ans = x//diff
    remainder = x%diff
    if remainder==0:
        print(ans*2)
    else:
        print((ans+1)*2-1)

    # calc

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    # input
    import math
    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

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

    x = abs(x)
    ans = x//diff
    remainder = x%diff
    if remainder==0:
        print(ans*2-2)
    else:
        print((ans+1)*2-1)

    # calc

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())
x = (a1 - b1) * t1
y = (a2 - b2) * t2
p, q = x // abs(x), y // abs(y)
#print(x, y)
if x + y == 0:
    print('infinity')
else:
    l, r = 0, 10 ** 40 + 1
    ans = 0
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if ((t - y < 0) ^ (t < 0)) or (t == 0):
            l = m
        else:
            r = m
    ans += l
    l, r = 0, 10 ** 40 + 1
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if ((t + x < 0) ^ (t < 0)) or (t + x == 0):
            l = m
        else:
            r = m
    ans += l
    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())
x = (a1 - b1) * t1
y = (a2 - b2) * t2
p, q = x // abs(x), y // abs(y)
#print(x, y)
if x + y == 0:
    print('infinity')
else:
    l, r = 0, 10 ** 10 + 1
    ans = 0
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if ((t - y < 0) ^ (t < 0)) or (t == 0):
            l = m
        else:
            r = m
    ans += l
    l, r = 0, 10 ** 10 + 1
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if ((t + x < 0) ^ (t < 0)) or (t + x == 0):
            l = m
        else:
            r = m
    ans += l
    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())
x = (a1 - b1) * t1
y = (a2 - b2) * t2
p, q = x // abs(x), y // abs(y)
#print(x, y)
if x + y == 0:
    print('infinity')
else:
    l, r = 0, 10 ** 10 + 1
    ans = 0
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if (t - y < 0) ^ (t <= 0):
            l = m
        else:
            r = m
    ans += l
    l, r = 0, 10 ** 10 + 1
    while r - l > 1:
        m = (l + r) // 2
        t = (x + y) * m
        if (t + x <= 0) ^ (t < 0):
            l = m
        else:
            r = m
    ans += l
    print(ans)

Submission status: Wrong Answer

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

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

if a1 + a2 == b1 + b2:
    print('infinity')
    exit(0)

elif a1 + a2 > b1 + b2:
    a1, b1 = b1, a1
    a2, b2 = b2, a2
    if b1 > a1:
        print(0)
        exit(0)

tmp00 = a1 - b1
tmp01 = b1 + b2 - a1 - a2

ans = tmp00 // tmp01 * 2 + 1
if tmp00 % tmp01 == 0:
    ans -= 1

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())))
A = 0
B = 0
ans = 0
tmp = [[0,0],[0,0]]
for i in range(2):
    a[i] *= t[i]
    b[i] *= t[i]

if a[0] + a[1] == b[0] + b[1]:
    print('infinity')
    exit(0)
elif a[0] > b[0] and a[1] > b[1]:
    print(0)
    exit(0)
elif a[0] < b[0] and a[1] < b[1]:
    print(0)
    exit(0)


for i in range(2):
    for j in range(2):
        A += a[j]
        B += b[j]
        tmp[i][j] = abs(A-B)
#print(tmp)
if tmp[0][0] - tmp[1][0] < 0:
    if not tmp[0][1] % (tmp[0][1] - tmp[1][1]):
        ans += 1
    tmp[0][1] //= tmp[0][1] - tmp[1][1]
    ans += tmp[0][1] * 2 -1
else:
    if not tmp[0][0] % (tmp[0][0] - tmp[1][0]):
        ans -= 1

    tmp[0][0] //= tmp[0][0] - tmp[1][0]
    ans += tmp[0][0] * 2 +1


print(max(ans,1))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid,2):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid,n):
        dif=(d_0+d_1)*(mid-1)
        c=0
        c+=1 if dif*(dif+d_0) <= 0 else 0
        c+=1 if (dif+d_0)*(dif+d_0+d_1) <= 0 else 0
        if c==n:
            return True
        else:
            return False
        
    
    T=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    d_0=T[0]*(A[0]-B[0])
    d_1=T[1]*(A[1]-B[1])
    if d_0==-d_1:
        print('infinity')
    elif d_0*(d_0+d_1)<0:
        if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
            n=nibutan(2,10**40)
            ans=n*2-1
            ans+=solve(n+1,1)
            print(ans)
        else:
            print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid,2):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid,n):
        dif=(d_0+d_1)*(mid-1)
        c=0
        c+=1 if dif*(dif+d_0) < 0 else 0
        c+=1 if (dif+d_0)*(dif+d_0+d_1) < 0 else 0
        if c==n:
            return True
        else:
            return False
        
    
    T=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    prea=0
    preb=0
    ans=0
    d_0=T[0]*(A[0]-B[0])
    d_1=T[1]*(A[1]-B[1])
    if d_0==-d_1:
        print('infinity')
    elif d_0*(d_0+d_1)<0:
        if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
            n=nibutan(2,10**40)
            ans=n*2-1
            ans+=solve(n+1,1)
            print(ans)
        else:
            print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x = t[0] * (a[0] - b[0])
y = x + t[1] * (a[1] - b[1])
if x*y > 0:
	print(0)
elif x*y == 0:
	print('infinity')
elif abs(x) % abs(y) == 0:
	print(2 * abs(x) // abs(y))
else:
	print(2 * abs(x) // abs(y) + 1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid,2):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid,n):
        dif=(d_0+d_1)*(mid-1)
        c=0
        c+=1 if dif*(dif+d_0) < 0 else 0
        c+=1 if (dif+d_0)*(dif+d_0+d_1) < 0 else 0
        if c==n:
            return True
        else:
            return False
        
    
    T=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    prea=0
    preb=0
    ans=0
    d_0=T[0]*(A[0]-B[0])
    d_1=T[1]*(A[1]-B[1])
    if d_0==-d_1:
        print('infinity')
    elif d_0*d_1<0:
        if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
            n=nibutan(2,10**40)
            ans=n*2-1
            ans+=solve(n+1,1)
            print(ans)
        else:
            print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
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: 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]
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((abs(y)//abs(x+y))*2)
else:
    print(hhh)

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

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 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)
#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 x>0:
    print(x*2)
#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-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 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-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 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-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 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-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 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-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 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>y:
    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 x<y:
    print(y*2)
#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 x<y:
    print(x*2)
#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 x>y:
    print(y*2-1)

Submission status: Wrong Answer

Solution code:
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
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:
if w[0]<w[2] and w[1]<w[3] and x>y:
    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 x<y:
    print(y*2)
#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 x>y:
    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 x<y:
    print(y*2)

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 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:
if w[0]<w[2] and w[1]<w[3] and x>y:
    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 x<y:
    print(x*2)
#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 x>y:
    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 x<y:
    print(x*2)

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 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:
if w[0]<w[2] and w[1]<w[3] and x>y:
    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 x<y:
    print(x*2)
#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 x<y:
    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 x>y:
    print(x*2)

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

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

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 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)
elif w[0]>0 and x>y:
    print(x*2)
elif w[0]>0 and x<y:
    print(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 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)
elif w[0]>0 and x>y:
    print(x*2-1)
elif w[0]>0 and x<y:
    print(x*2)

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 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(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=[]
ans=0
r=-1
for i in range(3000000):
    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)