--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+struct line { int x1; int y1; int x2; int y2; };
+
+#define max(x, y) ((x)>(y) ? (x) : (y))
+#define min(x, y) ((x)<(y) ? (x) : (y))
+#define between(a, a1, a2) ((a) >= min(a1, a2) && (a) <= max(a1, a2))
+
+int parse_lines(struct line lines[], int *maxx, int *maxy)
+{
+ int i = 0;
+ char buf[1000];
+ while (fgets(buf, 1000, stdin) != NULL) {
+ char *p = &buf[0];
+ lines[i].x1 = strtol(p, &p, 10);
+ p++;
+ lines[i].y1 = strtol(p, &p, 10);
+ p+=4;
+ lines[i].x2 = strtol(p, &p, 10);
+ p++;
+ lines[i].y2 = strtol(p, &p, 10);
+ *maxx = max(*maxx, lines[i].x1);
+ *maxx = max(*maxx, lines[i].x2);
+ *maxy = max(*maxy, lines[i].y1);
+ *maxy = max(*maxy, lines[i].y2);
+ i++;
+ }
+ return i;
+}
+
+bool online(int x, int y, struct line line)
+{
+ //Vertical
+ if (line.x1 == line.x2 && x == line.x1)
+ return between(y, line.y1, line.y2);
+ //Horizontal
+ if (line.y1 == line.y2 && y == line.y2)
+ return between(x, line.x1, line.x2);
+ return false;
+}
+
+int main()
+{
+ struct line lines[1000];
+ int maxx = 0, maxy = 0;
+ int nlines = parse_lines(lines, &maxx, &maxy);
+ int r = 0;
+ for (int x = 0; x<=maxx; x++) {
+ for (int y = 0; y<=maxy; y++) {
+ int matches = 0;
+ for (int line = 0; line<nlines && matches < 2; line++)
+ if (online(x, y, lines[line]))
+ matches++;
+ r = matches >= 2 ? r+1 : r;
+ }
+ }
+ printf("%d\n", r);
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+struct line { int x1; int y1; int x2; int y2; };
+
+#define max(x, y) ((x)>(y) ? (x) : (y))
+#define min(x, y) ((x)<(y) ? (x) : (y))
+#define between(a, a1, a2) ((a) >= min(a1, a2) && (a) <= max(a1, a2))
+
+int parse_lines(struct line lines[], int *maxx, int *maxy)
+{
+ int i = 0;
+ char buf[1000];
+ while (fgets(buf, 1000, stdin) != NULL) {
+ char *p = &buf[0];
+ lines[i].x1 = strtol(p, &p, 10);
+ p++;
+ lines[i].y1 = strtol(p, &p, 10);
+ p+=4;
+ lines[i].x2 = strtol(p, &p, 10);
+ p++;
+ lines[i].y2 = strtol(p, &p, 10);
+ *maxx = max(*maxx, lines[i].x1);
+ *maxx = max(*maxx, lines[i].x2);
+ *maxy = max(*maxy, lines[i].y1);
+ *maxy = max(*maxy, lines[i].y2);
+ i++;
+ }
+ return i;
+}
+
+bool online(int x, int y, struct line line)
+{
+ //Vertical
+ if (line.x1 == line.x2 && x == line.x1)
+ return between(y, line.y1, line.y2);
+ //Horizontal
+ if (line.y1 == line.y2 && y == line.y2)
+ return between(x, line.x1, line.x2);
+ //Diagonal
+ if (abs(line.y2-line.y1) == abs(line.x2-line.x1)) {
+ int slope = (line.y2 - line.y1) / (line.x2 - line.x1);
+ return y-line.y1 == slope*(x-line.x1)
+ && between(y, line.y1, line.y2) && between(x, line.x1, line.x2);
+ }
+ return false;
+}
+
+int main()
+{
+ struct line lines[1000];
+ int maxx = 0, maxy = 0;
+ int nlines = parse_lines(lines, &maxx, &maxy);
+ int r = 0;
+ for (int x = 0; x<=maxx; x++) {
+ for (int y = 0; y<=maxy; y++) {
+ int matches = 0;
+ for (int line = 0; line<nlines && matches < 2; line++)
+ if (online(x, y, lines[line]))
+ matches++;
+ r = matches >= 2 ? r+1 : r;
+ }
+ }
+ printf("%d\n", r);
+}