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.

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use whiteread::Reader;

fn main() {
    let mut scan = Reader::from_stdin_naive();
    let t1 = scan.p::<i64>() as i128;
    let t2 = scan.p::<i64>() as i128;
    let a1 = scan.p::<i64>() as i128;
    let a2 = scan.p::<i64>() as i128;
    let b1 = scan.p::<i64>() as i128;
    let b2 = scan.p::<i64>() as i128;
    let d1 = a1-b1;
    let d2 = a2-b2;
    if d1*t1 + d2*t2 == 0 {
        println!("infinity");
    } else if d1<0 && d1*t1+d2*t2<0 || d1>0 && d1*t1+d2*t2>0 {
        println!("0");
    } else {
        let mut ok = 1i128 << 60;
        let mut ng = 0i128;
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            let pre = (mid - 1) * (d1*t1+d2*t2);
            if pre+d1*t1<0 && pre+d1*t1+d2*t2>0 || pre+d1*t1>0 && pre+d1*t1+d2*t2<0 {
                ng = mid;
            } else {
                ok = mid;
            }
        }
        let pre = (ok-1) * (d1*t1+d2*t2);
        println!("{}", 2 * (ok-1) - 1 + (pre+d1*t1 == 0 || pre+d1*t1+d2*t2 == 0) as i128);
    }
}
*/

fn main() {
    let exe = "/tmp/bin93d188c4";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";