#include #include static int h, w; static int paper[2048][2048]; static void foldY(int fold) { for (int y = 0; y < fold; ++y) for (int x = 0; x < w; ++x) { paper[y][x] |= paper[h-1-y][x]; } h = fold; } static void foldX(int fold) { for (int x = 0; x < fold; ++x) for (int y = 0; y < h; ++y) { paper[y][x] |= paper[y][w-1-x]; } w = fold; } static int sum(void) { int sum = 0; for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) { sum += paper[y][x]; } return sum; } int main(void) { int x, y; while (2 == scanf("%d,%d\n", &x, &y)) { paper[y][x] = 1; if (y >= h) h = y+1; if (x >= w) w = x+1; } char axis; int fold; int first = 1; while (EOF != scanf(" fold along %c=%d\n", &axis, &fold)) { if (axis == 'y') { foldY(fold); } else if (axis == 'x') { foldX(fold); } else { printf("??? %c\n", axis); } if (first) { printf("%d\n", sum()); first = 0; } } }