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

#include <stdio.h>
#define NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// for DEBUG {{{
#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))
// }}}

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}
void merge_int(int *a, int *b, int lower, int sep, int upper) {// {{{
	int i_lower = lower;
	int i_upper = sep;
	int i_b = 0;
	while ((i_lower < sep) && (i_upper < upper)) {
		if (a[i_lower] < a[i_upper]) {
			b[i_b++] = a[i_lower++];
		} else {
			b[i_b++] = a[i_upper++];
		}
	}
	if (i_lower >= sep) {
		while (i_upper < upper) {
			b[i_b++] = a[i_upper++];
		}
	} else {
		while (i_lower < sep) {
			b[i_b++] = a[i_lower++];
		}
	}
	for (i_lower = 0; i_lower < i_b; i_lower++) {
		a[i_lower+lower] = b[i_lower];
	}
}// }}}
void merge_sort_int(int *a, int *b, int lower, int upper) {// {{{
	int sep;
	if ((lower == upper) || (lower + 1 == upper)) {
		return;
	}
	sep = (lower + upper) / 2;
	merge_sort_int(a,b,lower,sep);
	merge_sort_int(a,b,sep,upper);
	merge_int(a,b,lower,sep,upper);
}// }}}

#define S_MAX 30000
int main(int argc, char **argv) {
	long long t1, t2;
	long long a1, a2;
	long long b1, b2;
	fscanf(stdin,"%lld%lld",&t1,&t2) > 0;
	fscanf(stdin,"%lld%lld",&a1,&a2) > 0;
	fscanf(stdin,"%lld%lld",&b1,&b2) > 0;

	long long diff1 = (a1-b1)*t1;
	long long diff2 = (a2-b2)*t2;
	long long diff3 = diff1 + diff2;

	DEBUG_PRINT("%lld %lld %lld\n",diff1, diff2, diff3);
	if ((diff1 > 0) && (diff2 > 0)) {
		fprintf(stdout,"0\n");
		return 0;
	}
	if ((diff1 < 0) && (diff2 < 0)) {
		fprintf(stdout,"0\n");
		return 0;
	}
	if ((diff1 > 0) && (diff2 < 0)) {
		if (diff3 > 0) {
			fprintf(stdout,"0\n");
			return 0;
		}
		if (diff3 == 0) {
			fprintf(stdout,"infinity\n");
			return 0;
		}
		assert(diff3 < 0);
		long long  n = diff1 / llabs(diff3);
		if ((diff1 * n) == llabs(diff3)) {
			fprintf(stdout,"%lld\n",1+2*n-1);
		} else {
			fprintf(stdout,"%lld\n",1+2*n);
		}
		return 0;
	}
	if ((diff1 < 0) && (diff2 > 0)) {
		if (diff3 < 0) {
			fprintf(stdout,"0\n");
			return 0;
		}
		if (diff3 == 0) {
			fprintf(stdout,"infinity\n");
			return 0;
		}
		assert(diff3 > 0);
		long long n = llabs(diff1) / diff3;
		if ((llabs(diff1) * n) == diff3) {
			fprintf(stdout,"%lld\n",1+2*n-1);
		} else {
			fprintf(stdout,"%lld\n",1+2*n);
		}
		//
		return 0;
	}
	return 0;
}