# codeforces 117C 拓扑排序 找三元环

ps:好像是个结论。。。竞赛图中只要有环，就肯定存在三元环

#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
void Max(double &a,double b){if(b>a) a=b;}
const int inf = ~0u>>2;
const int maxn = 5010;
char mp[maxn][maxn];
int n,m;
vector<int> edge[maxn];
int c[maxn];
int topo[maxn];
int T;
int ans;
int pre[maxn];
bool dfs(int u){
c[u]=-1;
for(int i=0;i<edge[u].size();i++){
int v=edge[u][i];
pre[v]=u;
if(c[v]<0) {ans=v;return false;  }
else if(!c[v] && !dfs(v)) return false;
}
c[u]=1;
topo[--T]=u;
return true;
}
bool topsort(int n){
T=n+1;
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++) if(!c[i]){
bool f=dfs(i);
if(!f) return false;
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++) edge[i].clear();
for(int i=1;i<=n;i++)
{
scanf("%s",mp[i]+1);
for(int j=1;j<=n;j++)
{
if(mp[i][j]=='1')
{
edge[i].push_back(j);
}
}
}
if(!topsort(n)) {
printf("%d %d %d\n",pre[pre[ans]],pre[ans],ans);
}
else printf("-1\n");
}
return 0;
}