summaryrefslogtreecommitdiff
path: root/1.4/combo.c
blob: 7c5b3d1019e34ccad5a440b5ad1c9def525b8f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
ID: mytbk921
LANG: C
TASK: combo
*/

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

int matches(int a[], int b[], int N)
{
	int i;
	for (i = 0; i < 3; i++) {
		if (abs(a[i]-b[i]) <= 2 ||
				N - abs(a[i]-b[i]) <= 2)
			continue;
		else
			return 0;
	}
	return 1;
}

int main()
{
    FILE *fin, *fout;
	int farmer[3], master[3], test[3];
	int N, i, count = 0;
    
    fin = fopen("combo.in", "r");
    fout = fopen("combo.out", "w");
    
    fscanf(fin, "%d", &N);
	for (i = 0; i<3; i++)
		fscanf(fin, "%d", &farmer[i]);
	for (i = 0; i<3; i++)
		fscanf(fin, "%d", &master[i]);
    fclose(fin);
    
	for (test[0] = 1; test[0] <= N; test[0]++)
		for (test[1] = 1; test[1] <= N; test[1]++)
			for (test[2] = 1; test[2] <= N; test[2]++)
				if (matches(farmer, test, N) || matches(master, test, N))
					count++;

	fprintf(fout, "%d\n", count);
    fclose(fout);
    return 0;
}