P27003 [AtCoder] Interval Running
普及+
题目描述

Problem Description

Takahashi and Aoki are practicing long-distance running on a straight, endless running course that extends from west to east.

They start at the same point at the same time and move towards the east as follows:

  • Takahashi runs at a speed of $ A_1 $ meters per minute for the first $ T_1 $ minutes, then at a speed of $ A_2 $ meters per minute for the next $ T_2 $ minutes, and repeats this pattern indefinitely.
  • Aoki runs at a speed of $ B_1 $ meters per minute for the first $ T_1 $ minutes, then at a speed of $ B_2 $ meters per minute for the next $ T_2 $ minutes, and repeats this pattern indefinitely.

How many times will Takahashi and Aoki meet, i.e., come to the same position? Do not count the starting point. If they meet infinitely many times, report that fact.

Input Format

The input is given from the standard input in the following format:

$ T_1 $ $ T_2 $ $ A_1 $ $ A_2 $ $ B_1 $ $ B_2 $

Output Format

Output the number of times Takahashi and Aoki meet.
If they meet infinitely many times, output infinity instead.

Sample Input and Output

Sample Input #1

1 2
10 10
12 4

Sample Output #1

1

Sample Input #2

100 1
101 101
102 1

Sample Output #2

infinity

Sample Input #3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output #3

113

Notes/Hints

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 the input are integers

Sample Explanation 1

They meet once at $\frac{4}{3}$ minutes after starting, at a position $\frac{40}{3}$ meters from the starting point.

Sample Explanation 2

They meet at $ 101, 202, 303, 404, 505, 606, ... $ minutes after starting, so they meet infinitely many times.

Sample Explanation 3

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

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 2 10 10 12 4
样例输出
1