#include #include int main(void) { int grid[1000][1000] = {0}; int x1, y1, x2, y2; while (scanf("%d,%d -> %d,%d\n", &x1, &y1, &x2, &y2) != EOF) { /* key: for vert/horiz lines doesn't matter which one you * start at (since you draw the same line either way */ if (x1 == x2) { int dist = abs(y1 - y2); int start = y1 < y2 ? y1 : y2; for (int i = start; i <= start + dist; i++) { grid[x1][i]++; } } else if (y1 == y2) { int dist = abs(x1 - x2); int start = x1 < x2 ? x1 : x2; for (int i = start; i <= start + dist; i++) { grid[i][y1]++; } } } int count = 0; for (int r = 0; r < 1000; r++) { for (int c = 0; c < 1000; c++) { if (grid[r][c] > 1) { count++; } } } printf("%d\n", count); return 0; }