#!/usr/bin/perl
use 5.020;
use warnings;
use feature
qw(signatures
); no warnings
qw(experimental
);
sub f($s) {
my $c2;
my $n = 1;
when($c1){
$n++;
}
when($c2){
# nothing.
}
default {
$c2 = $_;
{ gp => 1, cg => 1, pc => 1 }->{$c1 . $c2} or next;
($c1, $c2) = ($c2, $c1);
$n = 1;
}
}
}
foreach(
"gpgpgppppg",
"ggggggggggggggg",
"ccpcpppcccpppcppcpcc",
"ggcgcgcggggcpgcggcgcggggcgcgcc",
){
say f($_);
}
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAyMDsKdXNlIHdhcm5pbmdzOwp1c2UgZmVhdHVyZSBxdyhzaWduYXR1cmVzKTsKbm8gd2FybmluZ3MgcXcoZXhwZXJpbWVudGFsKTsKCnN1YiBmKCRzKSB7CglteSAoJGMxLCBAcykgPSBzcGxpdCAvLywgJHM7CglteSAkYzI7CglteSAkbiA9IDE7CgoJZm9yZWFjaChAcyl7CgkJd2hlbigkYzEpewoJCQkkbisrOwoJCX0KCQl3aGVuKCRjMil7CgkJCSMgbm90aGluZy4KCQl9CgkJZGVmYXVsdCB7CgkJCWRlZmluZWQgJGMyIGFuZCByZXR1cm4gMDsKCQkJJGMyID0gJF87CgkJCXsgZ3AgPT4gMSwgY2cgPT4gMSwgcGMgPT4gMSB9LT57JGMxIC4gJGMyfSBvciBuZXh0OwoJCQkoJGMxLCAkYzIpID0gKCRjMiwgJGMxKTsKCQkJJG4gPSAxOwoJCX0KCX0KCglyZXR1cm4gKGRlZmluZWQgJGMyID8gJG4gOiAwKTsKfQoKZm9yZWFjaCgKCSJncGdwZ3BwcHBnIiwKCSJnZ2dnZ2dnZ2dnZ2dnZ2ciLAoJImNjcGNwcHBjY2NwcHBjcHBjcGNjIiwKCSJnZ2NnY2djZ2dnZ2NwZ2NnZ2NnY2dnZ2djZ2NnY2MiLAopewoJc2F5IGYoJF8pOwp9Cg==