#include <stdio.h>
const char q[] = "iiiii.i..ii...Pii..i...Piiii....";
void print_bit(unsigned long c, unsigned long g)
{
int i;
for (i = 0; i < 32; ++i)
printf("%c", (c
& 1UL
<< i
) ? 'i' : (g
& 1UL
<< i
) ? 'P' : '.'); }
unsigned long calc_move_R(unsigned long c, unsigned long g)
{
unsigned long mask = (g >> 1) | 0x80000000UL;
while (mask)
{
mask &= c;
c &= ~mask;
mask >>= 1;
}
return c;
}
unsigned long calc_move_L(unsigned long c, unsigned long g)
{
unsigned long mask = (g << 1) | 1UL;
while (mask)
{
mask &= c;
c &= ~mask;
mask <<= 1;
}
return c;
}
void solve(unsigned long c, unsigned long g)
{
unsigned long move_R = calc_move_R(c, g);
unsigned long move_L = calc_move_L(c, g);
if (~move_R & move_L) return;
if (!move_R) return;
int idx = __builtin_ctzl(move_R);
unsigned long min = 1UL << idx;
unsigned long b = move_R;
do
{
unsigned long moved;
unsigned long move_L;
unsigned long rev;
moved = c;
moved &= ~b;
moved |= b << 1;
move_L = calc_move_L(moved, g);
rev = moved;
rev &= ~move_L;
rev |= move_L >> 1;
if (rev == c) print_bit(moved, g);
} while (b = (b - min) & move_R);
}
int main(void)
{
unsigned long customer = 0;
unsigned long guard = 0;
int i;
for (i = 0; i < 32; ++i)
{
switch (q[i])
{
case 'i':
customer |= 1UL << i;
break;
case 'P':
guard |= 1UL << i;
break;
case '.':
default:
break;
}
}
print_bit(customer, guard);
solve(customer, guard);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpjb25zdCBjaGFyIHFbXSA9ICJpaWlpaS5pLi5paS4uLlBpaS4uaS4uLlBpaWlpLi4uLiI7Cgp2b2lkIHByaW50X2JpdCh1bnNpZ25lZCBsb25nIGMsIHVuc2lnbmVkIGxvbmcgZykKewoJaW50IGk7CgkKCWZvciAoaSA9IDA7IGkgPCAzMjsgKytpKQoJCXByaW50ZigiJWMiLCAoYyAmIDFVTCA8PCBpKSA/ICdpJyA6IChnICYgMVVMIDw8IGkp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