# 
# The adjustments make it take longer, but here we go:
# 
use strict;
use warnings;

my %strings;

while (<>) {
    chomp;
    next if length $_ < 4;
    undef my %uniq;
    for my $i (0..length($_) - 4) {
        my $substring = lc substr($_, $i, 4);
        $uniq{$substring}++;
        $strings{$substring}++ unless $uniq{$substring} > 1;
        $strings{$substring} .= ":$_";
    }
}

open Q_OUT, ">questions" or die "Cannot open questions: $!";
open A_OUT, ">answers" or die "Cannot open answers: $!";
for (sort keys %strings) {
    my ($count, $word) = split /:/, $strings{$_};
    next if $count > 1 or /[^a-z]/;
    print Q_OUT "$_\n";
    print A_OUT "$word\n";
}
close Q_OUT;
close A_OUT;


