#include <stdlib.h>
#include <stdio.h>

const int test_value = 5;

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

long long count(int X, int Y)
{
	long long X1 = X, Y1 = Y;
	long long sol = 2 * (X1 * (Y1 - 1) + Y1 * (X1 - 1));

	for (int x = 1; x < X; x++)
		for (int y = 1; y < Y; y++)
			if (gcd(x, y) == 1)
			{
				sol += 4*(X1 - x)*(Y1 - y);
			}

	return sol;
}

int main() {

	FILE* out = fopen("vojnici.out", "r");
	FILE* sol = fopen("vojnici.sol", "r");
	FILE* score = fopen("score.tmp", "w");
	
	int x1, y1, x2, y2;
	long long s1, s2;
	bool ok;
	
	fscanf (sol, "%d%d%lld", &x1, &y1, &s1);
	if (! feof(out)) 
	{
		fscanf (out, "%d", &x2);
		if (! feof(out)) 
		{
			fscanf (out, "%d", &y2);
			if (! feof(out)) 
			{
				fscanf (out, "%lld", &s2);
				bool p = (s1 == s2);
				bool q = (x1 * y1 == x2 * y2);
				bool r = (s2 == count(x2, y2));
				ok = p && q && r;
			}
			else ok = false;
		}
		else ok = false;
	}
	else ok = false;

	fprintf (score, "%d\n", (ok ? test_value : 0));

	fclose(out);
	fclose(sol);
	fclose(score);

	return 0;
}