#!/usr/bin/env perl
use strict;
use warnings;

my @groups;
open(my $fh, '<', 'input') or die "$!";
{
    local $/;
    my $content = <$fh>;
    @groups = split("\n\n", $content);
}

# reduce each group to a bag o words, then uniq, count
my $n;
for my $g (@groups) {
    my %yes;
    my @members = split("\n", $g);
    my $goal = scalar @members;
    for my $m (@members) {
        chomp($m);
        $yes{$_} += 1 for split('', $m);
    }
    $n += scalar grep { $yes{$_} == $goal } keys %yes;
}
print "$n\n";
