/* ID: mytbk921 LANG: C TASK: combo */ #include #include #include 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; }