#!/usr/bin/perl -w

use strict;

local $/ = "\n\n";

my $sum = 0;

while (<>) {
	my $nper = 0;
	my %q;
	for (split /\n/) {
		$nper++;
		$q{$_}++ for split //;
	}
	$sum += grep { $q{$_} == $nper } keys %q;
}

print "$sum\n";

