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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#define int ll
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define ln(a) cout << (a) << endl
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define EPS 0.0000001

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a, int mod) {
    int x, y;
    extgcd(a, mod, x, y);
    return (x + mod) % mod;
}

template<int mod> struct modint {
    int val;

    modint() {
        val = 0;
    }
    modint(int _val) {
        if(_val < 0) _val += mod * (-_val / mod + 1);
        val = _val % mod;
    }

    modint &operator=(const modint &x) {
        val = x.val;
        return *this;
    }
    bool operator==(const modint &rhs) const {return val == rhs.val;}
    bool operator<(const modint &rhs) const {return val < rhs.val;}
    bool operator>(const modint &rhs) const {return val > rhs.val;}
    bool operator<=(const modint &rhs) const {return val <= rhs.val;}
    bool operator>=(const modint &rhs) const {return val >= rhs.val;}
    bool operator!=(const modint &rhs) const {return val != rhs.val;}
    modint operator+(const modint &rhs) const {return modint<mod>(val + rhs.val);}
    modint operator-(const modint &rhs) const {return modint<mod>(val - rhs.val);}
    modint operator*(const modint &rhs) const {return modint<mod>((int)((ll)val * rhs.val % mod));}
    modint operator/(const modint &rhs) const {return modint<mod>((int)((ll)val * inv(rhs.val, mod) % mod));}
    modint &operator+=(const modint &rhs) {
        val = modint<mod>(val + rhs.val).val;
        return *this;
    }
    modint &operator-=(const modint &rhs) {
        val = modint<mod>(val - rhs.val).val;
        return *this;
    }
    modint &operator*=(const modint &rhs) {
        val = (int)((ll)val * rhs.val % mod);
        return *this;
    }
    modint &operator/=(const modint &rhs) {
        val = (int)((ll)val * inv(rhs.val, mod) % mod);
        return *this;
    }
};

struct unitree {
    int *par, *rank, *sz;

    unitree(int n) {
        par = new int[n];
        rank = new int[n];
        sz = new int[n];
        for(int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int root(int x) {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        }else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            sz[x] += sz[y];
        }
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int siz(int x) {
        return sz[root(x)];
    }
};

bool check(ll mid) {
    return true;
}

ll bin(ll left, ll right) {
    while(right - left > 1) {
        ll mid = (left + right) / 2;
        if(check(mid)) left = mid;
        else right = mid;
    }
    return left;
}

struct vect {
    ll x, y;
    vect() {
        x = 0;
        y = 0;
    }
    vect(ll x, ll y) {
        this->x = x;
        this->y = y;
    }

    int posi() const {
        if(x == 0 && y == 0) exit(1);
        if(x > 0 && y == 0) return 0;
        if(x > 0 && y > 0) return 1;
        if(x == 0 && y > 0) return 2;
        if(x < 0 && y > 0) return 3;
        if(x < 0 && y == 0) return 4;
        if(x < 0 && y < 0) return 5;
        if(x == 0 && y < 0) return 6;
        if(x > 0 && y < 0) return 7;
    }

    int posi(const vect& v) const {
        ll s = x * v.y - y * v.x;
        ll c = x * v.x + y * v.y;
        if(s == 0 && c == 0) exit(1);
        if(s == 0 && c > 0) return 0;
        if(s > 0 && c > 0) return 1;
        if(s > 0 && c == 0) return 2;
        if(s > 0 && c < 0) return 3;
        if(s == 0 && c < 0) return 4;
        if(s < 0 && c < 0) return 5;
        if(s < 0 && c == 0) return 6;
        if(s < 0 && c > 0) return 7;
    }

    bool operator<(const vect& rhs) {
        int p1 = posi();
        int p2 = rhs.posi();
        if(p1 != p2) return p1 < p2;
        return rhs.x * y < x * rhs.y;
    }
};

signed main() {
    ll t1, t2;
    cin >> t1 >> t2;
    ll a1, a2, b1, b2;
    cin >> a1 >> a2 >> b1 >> b2;
    ll d1 = (a1 - b1) * t1;
    ll d2 = (a2 - b2) * t2;
    if(d1 + d2 == 0) {
        ln("infinity");
        return 0;
    }
    if(d1 > 0 && d2 > 0 || d1 < 0 && d2 < 0) {
        ln(0);
        return 0;
    }
    if(d1 > 0 && d1 + d2 > 0 || d1 < 0 && d1 + d2 < 0) {
        ln(0);
        return 0;
    }
    if(d1 + d2 < 0) {
        d1 = -d1;
        d2 = -d2;
    }
    if(d1 + d2 > 0) {
        if((d1 + d2) % d2 == 0) ln(d2 / (d1 + d2) * 2 - 2);
        else ln(d2 / (d1 + d2) * 2 - 1);
        return 0;
    }
}