#!/usr/bin/perl -w

use v5.16;

my %dots;

while (<>) {
	chomp;
	my ($x, $y) = split /,/;
	last if !defined $y;
	$dots{$x}{$y}++;
}

my ($maxx, $maxy);
while (<>) {
	chomp;
	my ($axis, $val) = /fold along (.)=(\d+)/;

	for my $x (keys %dots) {
	for my $y (keys %{$dots{$x}}) {
		if ($axis eq 'x' && $x > $val) {
			$dots{2*$val - $x}{$y}++;
			delete $dots{$x}{$y};
		} elsif ($axis eq 'y' && $y > $val) {
			$dots{$x}{2*$val - $y}++;
			delete $dots{$x}{$y};
		}
	} }
	last;
}

my $sum;
for my $x (keys %dots) {
	$sum += keys %{$dots{$x}};
}

say $sum;

