blob: 261d96b88576be6d309785a09595946c61b2beea (
plain) (
blame)
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
|
#include <stdio.h>
#include <stdlib.h>
static int compar(const void *_a, const void *_b) {
const int *a = _a;
const int *b = _b;
return *a - *b;
}
static int list[256];
static int len;
static long tail[256];
static long chains(int i) {
if (i == len - 1) tail[i] = 1;
if (tail[i]) return tail[i];
for (int j = i + 1; j <= i + 3 && j < len; ++j) {
if (list[j] - list[i] <= 3) tail[i] += chains(j);
}
return tail[i];
}
int main(void) {
while (EOF != scanf("%d\n", &list[len])) {
len++;
}
list[len++] = 0;
qsort(list, len, sizeof(int), compar);
list[len] = list[len-1] + 3;
len++;
int j1 = 0, j3 = 0;
for (int i = 1; i < len; ++i) {
if (list[i] - list[i-1] == 1) j1++;
if (list[i] - list[i-1] == 3) j3++;
}
printf("%d\n", j1 * j3);
printf("%ld\n", chains(0));
}
|