#include<stdio.h>
int y1,y2,y3,y4,y5,y6,y7,y8,n=0,str[8][8];
int s(int a,int b,int c,int d,int e,int f,int g,int h)
{
int i,k;
for(i=1;i<=8;i++)
for(k=1;k<=8;k++)
str[i][k]='Y';
str[1][a]='O',str[2][b]='O',str[3][c]='O',str[4][d]='O',str[5][e]='O',str[6][f]='O',str[7][g]='O',str[8][h]='O';
for(i=1;i<=8;i++){printf("\n");
for(k=1;k<=8;k++)
printf(" %c",str[i][k]);}
}
int main()
{
for(y1=1;y1<=8;y1++)
for(y2=1;y2<=8;y2++)
if((y2-y1)*(y2+1-y1)*(y2-1-y1)!=0)
for(y3=1;y3<=8;y3++)
if((y3-y1)*(y3-y2)*(y3+2-y1)*(y3-2-y1)*(y3+1-y2)*(y3-1-y2)!=0)
for(y4=1;y4<=8;y4++)
if((y4-y1)*(y4-y2)*(y4-y3)*(y4+3-y1)*(y4-3-y1)*(y4+2-y2)*(y4-2-y2)*(y4+1-y3)*(y4-1-y3)!=0)
for(y5=1;y5<=8;y5++)
if((y5-y1)*(y5-y2)*(y5-y3)*(y5-y4)*(y5+4-y1)*(y5-4-y1)*(y5+3-y2)*(y5-3-y2)*(y5+2-y3)*(y5-2-y3)*(y5+1-y4)*(y5-1-y4)!=0)
for(y6=1;y6<=8;y6++)
if((y6-y1)*(y6-y2)*(y6-y3)*(y6-y4)*(y6-y5)*(y6+5-y1)*(y6-5-y1)*(y6+4-y2)*(y6-4-y2)*(y6+3-y3)*(y6-3-y3)*(y6+2-y4)*(y6-2-y4)*(y6+1-y5)*(y6-1-y5)!=0)
for(y7=1;y7<=8;y7++)
if((y7-y1)*(y7-y2)*(y7-y3)*(y7-y4)*(y7-y5)*(y7-y6)*(y7+6-y1)*(y7-6-y1)*(y7+5-y2)*(y7-5-y2)*(y7+4-y3)*(y7-4-y3)*(y7+3-y4)*(y7-3-y4)*(y7+2-y5)*(y7-2-y5)*(y7+1-y6)*(y7-1-y6)!=0)
for(y8=1;y8<=8;y8++)
if((y8-y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