#include <iostream>
using namespace std;
bool h_1(int arrayfic[3][3])
{
return (arrayfic[0][0]==arrayfic[0][1])&&(arrayfic[0][0]==arrayfic[0][2]);
}
bool h_2(int arrayfic[3][3])
{
return (arrayfic[1][0]==arrayfic[1][1])&&(arrayfic[1][0]==arrayfic[1][2]);
}
bool h_3(int arrayfic[3][3])
{
return (arrayfic[2][0]==arrayfic[2][1])&&(arrayfic[2][0]==arrayfic[2][2]);
}
bool v_1(int arrayfic[3][3])
{
return (arrayfic[0][0]==arrayfic[1][0])&&(arrayfic[0][0]==arrayfic[2][0]);
}
bool v_2(int arrayfic[3][3])
{
return (arrayfic[0][1]==arrayfic[1][1])&&(arrayfic[0][1]==arrayfic[2][1]);
}
bool v_3(int arrayfic[3][3])
{
return (arrayfic[0][2]==arrayfic[1][2])&&(arrayfic[0][2]==arrayfic[2][2]);
}
bool lt_br(int arrayfic[3][3])
{
return (arrayfic[0][0]==arrayfic[1][1])&&(arrayfic[0][0]==arrayfic[2][2]);
}
bool lb_tr(int arrayfic[3][3])
{
return (arrayfic[0][2]==arrayfic[1][1])&&(arrayfic[0][2]==arrayfic[2][0]);
}
bool win(int arrayfic[3][3]){
int count1 = 0, count2 = 0;
bool player1 = false;
for(int i=0; i<3; ++i)
for(int j=0; j<3; ++j)
(arrayfic[i][j]==1)?++count1:++count2;
count1<=count2?player1=true:player1=false;
for(int i=0; i<3; ++i)
{
for(int j=0; j<3; ++j)
{
if(!arrayfic[i][j])
{
arrayfic[i][j] = player1?1:2;
if(i==0&&j==0){ if(h_1(arrayfic)||v_1(arrayfic)||lt_br(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==0&&j==1){ if(h_1(arrayfic)||v_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==0&&j==2){ if(h_1(arrayfic)||v_3(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==1&&j==0){ if(v_1(arrayfic)||h_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==1&&j==1){ if(h_2(arrayfic)||v_2(arrayfic)||lt_br(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==1&&j==2){ if(h_2(arrayfic)||v_3(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==2&&j==0){ if(v_1(arrayfic)||h_3(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==2&&j==1){ if(h_3(arrayfic)||v_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
if(i==2&&j==2){ if(h_3(arrayfic)||v_3(arrayfic)||lt_br(arrayfic))return true; arrayfic[i][j] = 0;continue;}
}
}
}
return false;
}
int main () {
int arrayfic1[3][3]={{2,1,1},{2,0,0},{0,1,0}};
int arrayfic2[3][3]={{1,0,2},{0,2,0},{0,0,1}};
int arrayfic3[3][3]={{2,1,1},{2,0,0},{0,0,0}};
if(win(arrayfic1))
cout <<"YES"<<endl;
else
cout<<"NO"<<endl;
if(win(arrayfic2))
cout <<"YES"<<endl;
else
cout<<"NO"<<endl;
if(win(arrayfic3))
cout <<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBoXzEoaW50IGFycmF5ZmljWzNdWzNdKQp7CglyZXR1cm4gKGFycmF5ZmljWzBdWzBdPT1hcnJheWZpY1swXVsxXSkmJihhcnJheWZpY1swXVswXT09YXJyYXlmaWNbMF1bMl0pOwp9Cgpib29sIGhfMihpbnQgYXJyYXlmaWNbM11bM10pCnsKCXJldHVybiAoYXJyYXlmaWNbMV1bMF09PWFycmF5ZmljWzFdWzFdKSYmKGFycmF5ZmljWzFdWzBdPT1hcnJheWZpY1sxXVsyXSk7Cn0KCmJvb2wgaF8zKGludCBhcnJheWZpY1szXVszXSkKewoJcmV0dXJuIChhcnJheWZpY1syXVswXT09YXJyYXlmaWNbMl1bMV0pJiYoYXJyYXlmaWNb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