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:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t1,t2 = LI()
a1,a2 = LI()
b1,b2 = LI()

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1*s2 >= 0:
    print(0)
elif s1 == (-1)*s2:
    print('infinity')
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t1,t2 = LI()
a1,a2 = LI()
b1,b2 = LI()

s1 = t1*(a1-b1)
s2 = t2*(a2-b2)
if s1*s2 > 0:
    print(0)
elif s1 == (-1)*s2:
    print('infinity')
else:
    ans1 = abs(s1//(s1+s2))
    ans2 = abs(s2//(s1+s2))
    ans = ans1+ans2 -1
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
t1, t2, a1, a2, b1, b2 = [int(_) for _ in open(0).read().split()]
c1 = (b1 - a1) * t1
c2 = c1 + (b2 - a2) * t2
if c1 * c2 > 0:
    print(0)
    exit()
if c2 == 0:
    print('infinity')
    exit()
if c1 < 0:
    c1 *= -1
    c2 *= -1
ans = 2 * math.ceil(c1 / (-c2)) - 1 - (c1 % c2 == 0)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
t1, t2, a1, a2, b1, b2 = [int(_) for _ in open(0).read().split()]
c1 = (b1 - a1) * t1
c2 = c1 + (b2 - a2) * t2
if c1 * c2 > 0:
    print(0)
    exit()
if c2 == 0:
    print('infinity')
    exit()
ans = 2 * math.ceil(abs(c1) / abs(c2)) - 1 - (abs(c1) % abs(c2) == 0)
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())

CA1=A1*T1
CB1=B1*T1
CA2=A2*T2
CB2=B2*T2
import math
if CA1+CA2==CB1+CB2:
    print("infinity")
elif (CA1-CB1)*((CA1+CA2)-(CB1+CB2))<0:
    print(math.ceil(abs(CA1-CB1)/abs((CA1+CA2)-(CB1+CB2)))*2-1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
if (a1 < b1 and a2 < b2) or (a1 > b1 and a2 > b2):
    print(0)
    exit()
p = abs((a1 - b1) * t1)
q = abs((b2 - a2) * t2)
if p == q:
    print('infinity')
else:
    print((p // abs(p - q)) * 2 + bool(p % abs(p - q)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
if (a1 < b1 and a2 < b2) or (a1 > b1 and a2 > b2):
    print(0)
    exit()
p = (a1 - b1) * t1
q = (b2 - a2) * t2
if p < 0:
    p = -p; q = -q
if p == q:
    print('infinity')
else:
    print((p // abs(p - q) + 1) * 2 - bool(p % abs(p - q)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
if (a1 < b1 and a2 < b2) or (a1 > b1 and a2 > b2):
    print(0)
    exit()
p = (a1 - b1) * t1
q = (b2 - a2) * t2
if p < 0:
    p = -p; q = -q
if p == q:
    print('infinity')
else:
    print(p // abs(p - q) * 2 + bool(p // abs(p - q)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
at1 = t1 * a1
bt1 = t1 * b1
at2 = t2 * a2
bt2 = t2 * b2
if (a1 < b1 and a2 < b2) or (a1 > b1 and a2 > b2):
    print(0)
elif at1 + at2 == bt1 + bt2:
    print('infinity')
else:
    print((at1 - bt1) // ((bt1 + bt2) - (at1 + at2)) * 2 + bool((at1 - bt1) % ((bt1 + bt2) - (at1 + at2))))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
at1 = t1 * a1
bt1 = t1 * b1
at2 = t2 * a2
bt2 = t2 * b2
if (at1 < bt1 and at2 < bt2) or (at1 > bt1 and at2 > bt2):
    print(0)
elif at1 + at2 == bt1 + bt2:
    print('infinity')
else:
    print((at1 - bt1) // ((bt1 + bt2) - (at1 + at2)) * 2 + \
          bool(abs((at1 - bt1) % ((bt1 + bt2) - (at1 + at2))) < abs(bt2 - at2)) \
          - (not bool(abs((at1 - bt1) % ((bt1 + bt2) - (at1 + at2))))))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
at1 = t1 * a1
bt1 = t1 * b1
at2 = t2 * a2
bt2 = t2 * b2
if (at1 < bt1 and at2 < bt2) or (at1 > bt1 and at2 > bt2):
    print(0)
elif at1 + at2 == bt1 + bt2:
    print('infinity')
else:
    print((at1 - bt1) // ((bt1 + bt2) - (at1 + at2)) * 2 + bool(abs((at1 - bt1) % ((bt1 + bt2) - (at1 + at2))) < abs(bt2 - at2)))

Submission status: Wrong Answer

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

C1 = A1 - B1
C2 = A2 - B2
if C1 > 0:
    C1, C2 = -C1, -C2

x1 = C1 * T1 + C2 * T2
x2 = x1 + C1 * T1

if x1 == 0:
    print('inifinity')
elif x1 < 0:
    print(0)
else:
    if 0 < x2:
        count = 1
    elif 0 == x2:
        count = 2
    else:
        n = (-x2 + x1 - 1) // x1
        count = 1 + 2 * n
        if x2 % x1 == 0:
            count += 1
    print(count)

Submission status: Wrong Answer

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

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

if sa==0:
    print("infinity")
else:
    if sa>0:
        if a1>b1:
            print(0)
        else:
            ganba=t1*b1-t1*a1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)
            #print(sa, ganba)
    else:
        if b1>a1:
            print(0)
        else:
            ganba=t1*a1-t1*b1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)

Submission status: Wrong Answer

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

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

if sa==0:
    print("infinity")
else:
    if sa>0:
        if a1>b1:
            print(0)
        else:
            ganba=t1*b1-t1*a1
            gyakuten=(ganba//sa)+1
            print(gyakuten*2-1)
            #print(sa, ganba)
    else:
        if b1>a1:
            print(0)
        else:
            ganba=t1*a1-t1*b1
            gyakuten=(ganba//sa)+1
            print(gyakuten*2-1)

Submission status: Wrong Answer

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

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

if sa==0:
    print("infinity")
else:
    if sa>0:
        if a1>b1:
            print(0)
        else:
            ganba=t1*b1-t1*a1
            gyakuten=(ganba//sa)+1
            print(gyakuten*2-1)
            #print(sa, ganba)
    else:
        if a2>a1:
            print(0)
        else:
            ganba=t1*a1-t1*b1
            gyakuten=(ganba//sa)+1
            print(gyakuten*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())
import time
start=time.time()
x=(a1-b1)*t1
y=(a2-b2)*t2
if x<0:
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    print((-1*x+(x+y)-1)//(x+y)*2-1)
else:
    x*=-1
    y*=-1
    if x+y<0:
        print(0)
        exit()
    if x+y==0:
        print("infinity")
        exit()
    print((-1*x+(x+y)-1)//(x+y)*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())
import time
start=time.time()
x1=a1*t1
x2=a2*t2
y1=b1*t1
y2=b2*t2
if x1+x2==y1+y2:
    print("infinity")
    exit()
T=x1
A=y1
now=1
ue="T" if T>A else "A"
ans=0
while True:
    if now%2==1:
        now+=1
        T+=x2
        A+=y2
        uuee="T" if T>A else "A"
        if ue==uuee:
            break
        ans+=1
        ue=uuee
    else:
        now+=1
        T+=x1
        A+=y1
        uuee="T" if T>A else "A"
        if ue==uuee:
            break
        ans+=1
        ue=uuee
    ima=time.time()
    if ima-start>1.5:
        break

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

x1=a1*t1
x2=a2*t2
y1=b1*t1
y2=b2*t2
if x1+x2==y1+y2:
    print("infinity")
    exit()
T=x1
A=y1
now=1
ue="T" if T>A else "A"
ans=0
while True:
    if now%2==1:
        now+=1
        T+=x2
        A+=y2
        uuee="T" if T>A else "A"
        if ue==uuee:
            break
        ans+=1
        ue=uuee
    else:
        now+=1
        T+=x1
        A+=y1
        uuee="T" if T>A else "A"
        if ue==uuee:
            break
        ans+=1
        ue=uuee

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

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

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

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

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

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

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

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

sum_a = t1 * a1 + t2 * a2
sum_b = t1 * b1 + t2 * b2

if sum_a == sum_b:
    print('infinity')
    exit()
    
if sum_a > sum_b:
    big_sum = sum_a
    big_1 = a1*t1
    big_2 = a2*t2
    sml_sum = sum_b
    sml_1 = b1*t1
    sml_2 = b2*t2
else:
    big_sum = sum_b
    big_1 = b1*t1
    big_2 = b2*t2
    sml_sum = sum_a
    sml_1 = a1*t1
    sml_2 = a2*t2
    
if sml_1 < big_1:
    print(0)
    exit()
    
#print(big_sum,sml_sum)
    
n = (big_1-sml_1) // (sml_sum-big_sum)
print(int(2*n+1))

Submission status: Wrong Answer

Solution code:
dummy="""
3 5
2 4
3 3
"""
if 0:
    def sub_get_line():
        for i in dummy.split("\n"):
            yield i
    get_line = sub_get_line().__next__
    get_line()
else:
    get_line = input

T1,T2 = [int(_) for _ in get_line().split(" ")]
A1,A2 = [int(_) for _ in get_line().split(" ")]
B1,B2 = [int(_) for _ in get_line().split(" ")]

"""
P1 = A1 * T1 
P2 = B1 * T1
T = -1
for i in range(10):
    print ("P1=%d\tP2=%d\t%d\t%d" %(P1, P2, P1<P2, P1-P2))
    if T > 0:
        P1 += T1*A1
        P2 += T1*B1
    else:
        P1 += T2*A2
        P2 += T2*B2
    T *= -1
"""

if T1*A1+T2*A2 == T1*B1+T2*B2:
    print ("infinity")
    exit()
elif T1*A1+T2*A2 > T1*B1+T2*B2:
    if A1 > B1:
        print (0)
        exit()
    diff1 = (B1 - A1)*T1
    diff2 = (T1*A1+T2*A2) - (T1*B1+T2*B2)
elif T1*A1+T2*A2 < T1*B1+T2*B2:
    if A1 < B1:
        print (0)
        exit()
    diff1 = (A1 - B1)*T1
    diff2 = (T1*B1+T2*B2) - (T1*A1+T2*A2)
#print (diff1, diff2, int(diff1/diff2)*2 + 1)
print (int(diff1/diff2)*2 + 1)

Submission status: Wrong Answer

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

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

if d1 + d2 == 0:
    print('infinity')

if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
    print(0)

if d1 * (d2 - d1) > 0:
    if d1 % (d2 - d1) != 0:
        print(2 * d1 // (d2 - d1) + 1)
    else:
        print(2 * d1 // (d2 - d1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
T1,T2 = [int(x) for x in stdin.readline().rstrip().split()]
A1,A2 = [int(x) for x in stdin.readline().rstrip().split()]
B1,B2 = [int(x) for x in stdin.readline().rstrip().split()]
f = (A1-B1)*T1
s = (A2-B2)*T2
 
if f + s == 0:
    print("infinity")

else:
    if (f > 0) and ((f + s) > 0):
        print(0)
    
    elif (f < 0) and ((f + s) < 0):
        print(0)
        
    elif f > 0 and f + s < 0:
        if (-(f + s)) % f == 0:
            print((f//-(f+s))*2)
        else:
            print((f//-(f+s))*2+1)
    
    elif f < 0 and f + s > 0:
        if (-f) % (f+s) == 0:
            print((-f//(f+s))*2)
        else:
            print((-f//(f+s))*2+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
T1,T2 = [int(x) for x in stdin.readline().rstrip().split()]
A1,A2 = [int(x) for x in stdin.readline().rstrip().split()]
B1,B2 = [int(x) for x in stdin.readline().rstrip().split()]
f = (A1-B1)*T1
s = (A2-B2)*T2

if f + s == 0:
    print("infinity")

else:
    if (f > 0) and ((f + s) > 0):
        print(0)
    
    elif (f < 0) and ((f + s) < 0):
        print(0)
        
    elif f > 0 and f + s < 0:
        if -(f + s) % f == 0:
            print((f//-(f+s)+2))
        else:
            print((f//-(f+s))*2+1)
    
    elif f < 0 and f + s > 0:
        if (-f % (f+s)) == 0:
            print((-f//(f+s))*2)
        else:
            print((-f//(f+s))*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())
d1=b1*t1-a1*t1
d2=a1*t1-b1*t1+a2*t2-b2*t2
if d2==0:
  print('infinity')
elif (a1>b1 and a2>b2) or (a1<b1 and a2<b2):
  print(0)
else:
  if d1%d2==0:
    print(d1/d2*2)
  else:
    print(d1//d2*2+1)

Submission status: Wrong Answer

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

c1,c2 = -1 * (a1-b1)*t1,-1 * (a2-b2)*t2

if c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c1 % (c1 + c2) == 0 else num * 2 + 1)

Submission status: Wrong Answer

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

c1,c2 = -1 * (a1-b1)*t1,-1 * (a2-b2)*t2

if c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c1 % (c1 + c2) == 0 else num * 2 + 1)

Submission status: Wrong Answer

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

c1,c2 = -1 * (a1-b1)*t1,-1 * (a2-b2)*t2

if c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c2 % (c1 + c2) == 1 else num * 2 + 1)

Submission status: Wrong Answer

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

c1,c2 = -1 * (a1-b1)*t1,-1 * (a2-b2)*t2

if c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c2 % (c1 + c2) == 0 else num * 2 + 1)

Submission status: Wrong Answer

Solution code:
a,b=[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()]
a1=a1*a
b1=b1*a
a2=a2*b
b2=b2*b
#print(b1-a1,((a2+a1)-(b1+b2))/(b1-a1))
ans=0
cnt=0
if (a1-b1)*(a2-b2)<0:
  if a1+a2==b1+b2:
    print("infinity")
    exit()
  if a1+a2>b1+b2:
    cnt=(max(b1-a1,b2-a2)+((a1+a2)-(b1+b2))+1)//((a1+a2)-(b1+b2))
  else:
    cnt=(max(a1-b1,a2-b2)+((b1+b2)-(a2+a1))+1)//((b1+b2)-(a2+a1))
    #print((max(a1-b1,a2-b2)+(b1+b2)-(a2+a1)+1),max(a1-b1,a2-b2))
    
  print((cnt-1)*2+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
a,b=[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()]
a1=a1*a
b1=b1*a
a2=a2*b
b2=b2*b
#print(b1-a1,((a2+a1)-(b1+b2))/(b1-a1))
ans=0
cnt=0
if (a1-b1)*(a2-b2)<0:
  if a1+a2==b1+b2:
    print("infinity")
    exit()
  if a1+a2>b1+b2:
    while ans<max(b1-a1,b2-a2):
      ans+=(a2+a1)-(b1+b2)
      cnt+=1
  else:
    while ans<max(a1-b1,a2-b2):
      ans+=(b1+b2)-(a2+a1)
      cnt+=1
    
  print((cnt-1)*2+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
a,b=[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()]
a1=a1*a
b1=b1*a
a2=a2*b
b2=b2*b
#print(b1-a1,((a2+a1)-(b1+b2))/(b1-a1))
ans=0
cnt=0
if (a1-b1)*(a2-b2)<0:
  if a1+a2==b1+b2:
    print("infinity")
    exit()
  while ans<b1-a1:
    ans+=(a2+a1)-(b1+b2)
    cnt+=1
  print((cnt-1)*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())

s1=a1-b1
s2=a2-b2

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

Submission status: Wrong Answer

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

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2
"""
if dis1 + dis2 <0:
    print(0)

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

if dis1 + dis2 == 0:
    print("infinity")

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

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2
"""
if dis1 + dis2 <0:
    print(0)

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

if dis1 + dis2 == 0:
    print("infinity")

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

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2
"""
if dis1 + dis2 <0:
    print(0)

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

if dis1 + dis2 == 0:
    print("infinity")

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

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

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

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

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

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

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

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

elif dis1*dis2 > 0:
    print(0)

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

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

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

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

else:
    S = dis1//(dis1+dis2)
    R = dis1%(dis1+dis2) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 1
    
    print(abs(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())

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

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

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

else:
    S = abs(dis1//(dis1+dis2))
    R = abs(dis1%(dis1+dis2)) 
    if R == 0:
        ans = S*2 
    else:
        ans = S*2 + 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())

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

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

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

else:
    tmp = abs(dis1/(dis1+dis2))
    S = int(tmp)
    rem = tmp - S
    if rem == 0:
        ans = S*2 
    else:
        ans = S*2 + 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())

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

if dis1 + dis2 == 0:
    print("infinity")

elif dis1*dis2 > 0:
    print("0")

else:
    tmp = abs(dis1/(dis1+dis2))
    S = int(tmp)
    rem = tmp - S
    if rem == 0:
        ans = S*2 
    else:
        ans = S*2 + 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())

s1=a1-b1
s2=a2-b2

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

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 s1*t1>0 and s1*t1+s2*t2>0:
    print(0)
elif s1*t1<0 and 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:
import sys
read = sys.stdin.read

T1, T2, A1, A2, B1, B2 = map(int, read().split())
answer = 0
v1 = A1 - B1
v2 = A2 - B2
d = abs(v1 * T1 + v2 * T2)

if d == 0:
    print('infinity')
    exit()
elif v1 * v2 > 0:
    print(0)
    exit()

print(abs(v1) * T1 // d + abs(v2) * T2 // d)